diff --git a/runtimes/jsc.js b/runtimes/jsc.js index 80f6261..95d75ea 100644 --- a/runtimes/jsc.js +++ b/runtimes/jsc.js @@ -3,7 +3,14 @@ const jsc = globalThis["\x24"]; const DollarCreateRealm = jsc.createRealm; const DollarEvalScript = jsc.evalScript.bind(jsc); -var $262 = Object.assign({}, jsc); +var $262 = {}; +// Copy "own" properties from the JSC-defined object to the normalized `$262` +// object. Neither `Object.assign` nor the object "spread" syntax can be used +// for this task because not all properties on the source object are +// enumerable. +Object.getOwnPropertyNames(jsc).forEach(function(name) { + $262[name] = jsc[name]; +}); $262.global = globalThis; $262.source = $SOURCE; $262.destroy = function() {}; diff --git a/test/runify.js b/test/runify.js index 9f492f1..f9e741e 100644 --- a/test/runify.js +++ b/test/runify.js @@ -958,5 +958,26 @@ hosts.forEach(function (record) { await agent.destroy(); }); }); + + describe("agent", () => { + if (!["jsc", "jsshell", "d8"].includes(type)) { + return; + } + + const read = async (expression) => { + const result = await agent.evalScript(`print(${expression});`); + expect(result.error).toBe(null); + return result.stdout; + }; + + it("exposes the complete Test262-defined API", async () => { + expect(await read("typeof $262.agent")).toMatch(/^object/); + expect(await read("typeof $262.agent.start")).toMatch(/^function/); + expect(await read("typeof $262.agent.broadcast")).toMatch(/^function/); + expect(await read("typeof $262.agent.getReport")).toMatch(/^function/); + expect(await read("typeof $262.agent.sleep")).toMatch(/^function/); + expect(await read("typeof $262.agent.monotonicNow")).toMatch(/^function/); + }); + }); }); });