Clone engine262 in /engine262

This commit is contained in:
2020-09-07 10:19:00 +05:30
parent 7688de2e5c
commit 66c1aeb9e0
313 changed files with 46014 additions and 0 deletions
+105
View File
@@ -0,0 +1,105 @@
'use strict';
const engine262 = require('..');
const { getContext } = require('./context');
module.exports = {
Debugger: {
enable() {
return { debuggerId: 'debugger.0' };
},
setAsyncCallStackDepth() {},
setBlackboxPatterns() {},
setPauseOnExceptions() {},
},
Profiler: {
enable() {},
},
Runtime: {
enable() {},
compileScript() {
return { scriptId: 'script.0' };
},
callFunctionOn(options) {
const context = getContext(options.executionContextId);
const { Value: F } = context.realm.evaluateScript(`(${options.functionDeclaration})`);
const thisValue = options.objectId
? context.getObject(options.objectId)
: engine262.Value.undefined;
const args = options.arguments.map((a) => {
if ('value' in a) {
return new engine262.Value(context.realm, a.value);
}
if ('objectId' in a) {
return context.getObject(a.objectId);
}
if ('unserializableValue' in a) {
throw new RangeError();
}
return engine262.Value.undefined;
});
const r = engine262.Call(F, thisValue, args);
return context.createEvaluationResult(r, options);
},
evaluate(options) {
if (options.throwOnSideEffect || options.awaitPromise) {
return {
exceptionDetails: {
text: 'unsupported',
lineNumber: 0,
columnNumber: 0,
},
};
}
const context = getContext(options.contextId);
const r = context.realm.evaluateScript(options.expression);
return context.createEvaluationResult(r, options);
},
getHeapUsage() {
return { usedSize: 0, totalSize: 0 };
},
getIsolateId() {
return { id: 'isolate.0' };
},
getProperties(options) {
const context = getContext();
const object = context.getObject(options.objectId);
const properties = context.getProperties(object, options);
if (properties instanceof engine262.AbruptCompletion) {
return context.createEvaluationResult(properties, options);
}
return {
result: properties.properties,
internalProperties: properties.internalProperties,
};
},
globalLexicalScopeNames({ executionContextId }) {
const context = getContext(executionContextId);
const envRec = context.realm.realm.GlobalEnv.EnvironmentRecord;
const names = Map.prototype.keys.call(envRec.DeclarativeRecord.bindings);
return {
names: [...names],
};
},
releaseObjectGroup({ objectGroup }) {
getContext().releaseObjectGroup(objectGroup);
},
runIfWaitingForDebugger(params, ctx) {
ctx.sendEvent('Runtime.executionContextCreated', {
context: {
id: '0',
origin: 'file://',
name: 'context.0',
auxData: {},
},
});
},
},
HeapProfiler: {
enable() {},
collectGarbage() {},
},
};