Skip to content

Commit

Permalink
Correct definition of JSC "runtime" object
Browse files Browse the repository at this point in the history
A recent commit [1] regressed support for JavaScriptCore by changing the
way the "runtime" object is defined for that engine. Restore the
intended behavior and add an automated test.

[1] 4e9c3ee
  • Loading branch information
jugglinmike authored and rwaldron committed Jun 24, 2021
1 parent 42ba3a8 commit 6b2f14f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 8 additions & 1 deletion runtimes/jsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {};
Expand Down
21 changes: 21 additions & 0 deletions test/runify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});
});
});

0 comments on commit 6b2f14f

Please sign in to comment.