mirror of
https://github.com/bendtherules/completion-viz.git
synced 2026-08-18 13:42:51 +00:00
runEngine - Use old setup code
This commit is contained in:
+20
-29
@@ -1,12 +1,12 @@
|
|||||||
import { Node } from "acorn";
|
import { Node } from "acorn";
|
||||||
import {
|
import {
|
||||||
Agent,
|
Agent,
|
||||||
setSurroundingAgent,
|
Realm,
|
||||||
ManagedRealm,
|
Abstract,
|
||||||
Value,
|
Value,
|
||||||
CreateDataProperty,
|
|
||||||
inspect,
|
inspect,
|
||||||
} from "../../engine262/dist/engine262";
|
Completion
|
||||||
|
} from "../engine262/dist/engine262";
|
||||||
|
|
||||||
import { CompletionRecord } from "../types/engine262-stubs";
|
import { CompletionRecord } from "../types/engine262-stubs";
|
||||||
import { completionMapping } from "./completionMapping";
|
import { completionMapping } from "./completionMapping";
|
||||||
@@ -16,14 +16,16 @@ export function runEngine(code: string) {
|
|||||||
|
|
||||||
const agent = new Agent({
|
const agent = new Agent({
|
||||||
onNodeEvaluationComplete({
|
onNodeEvaluationComplete({
|
||||||
node,
|
Production: node,
|
||||||
result,
|
Result: result,
|
||||||
}: {
|
}: {
|
||||||
node: Node;
|
Production: Node;
|
||||||
result: CompletionRecord;
|
Result: CompletionRecord;
|
||||||
}) {
|
}) {
|
||||||
console.log({ node, result });
|
if (result instanceof Completion) {
|
||||||
completionMapping.addCompletion({ node, result });
|
console.log({ node, result });
|
||||||
|
completionMapping.addCompletion({ node, result });
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// onDebugger() {},
|
// onDebugger() {},
|
||||||
// ensureCanCompileStrings() {},
|
// ensureCanCompileStrings() {},
|
||||||
@@ -31,28 +33,17 @@ export function runEngine(code: string) {
|
|||||||
// onNodeEvaluation() {},
|
// onNodeEvaluation() {},
|
||||||
// features: [],
|
// features: [],
|
||||||
});
|
});
|
||||||
setSurroundingAgent(agent);
|
agent.enter();
|
||||||
|
|
||||||
const realm = new ManagedRealm({
|
const realm = new Realm({});
|
||||||
// promiseRejectionTracker() {},
|
|
||||||
// resolveImportedModule() {},
|
|
||||||
// getImportMetaProperties() {},
|
|
||||||
// finalizeImportMeta() {},
|
|
||||||
// randomSeed() {},
|
|
||||||
});
|
|
||||||
|
|
||||||
realm.scope(() => {
|
// Add print function from host
|
||||||
// Add print function from host
|
const print = new Value(realm, (args: any[]) => {
|
||||||
|
console.log(...args.map((tmp) => inspect(tmp)));
|
||||||
// @ts-ignore: new Value has type any
|
return (Value as any).undefined;
|
||||||
const print = new Value((args) => {
|
|
||||||
console.log(...args.map((tmp: any) => inspect(tmp)));
|
|
||||||
return (Value as any).undefined;
|
|
||||||
});
|
|
||||||
|
|
||||||
// @ts-ignore: new Value has type any
|
|
||||||
CreateDataProperty(realm.GlobalObject, new Value("print"), print);
|
|
||||||
});
|
});
|
||||||
|
Abstract.CreateDataProperty(realm.global, new Value(realm, "print"), print);
|
||||||
|
|
||||||
|
/* Actual code here */
|
||||||
realm.evaluateScript(code);
|
realm.evaluateScript(code);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user