Skip to content

Commit 6b2f14f

Browse files
jugglinmikerwaldron
authored andcommitted
Correct definition of JSC "runtime" object
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
1 parent 42ba3a8 commit 6b2f14f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

runtimes/jsc.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ const jsc = globalThis["\x24"];
33
const DollarCreateRealm = jsc.createRealm;
44
const DollarEvalScript = jsc.evalScript.bind(jsc);
55

6-
var $262 = Object.assign({}, jsc);
6+
var $262 = {};
7+
// Copy "own" properties from the JSC-defined object to the normalized `$262`
8+
// object. Neither `Object.assign` nor the object "spread" syntax can be used
9+
// for this task because not all properties on the source object are
10+
// enumerable.
11+
Object.getOwnPropertyNames(jsc).forEach(function(name) {
12+
$262[name] = jsc[name];
13+
});
714
$262.global = globalThis;
815
$262.source = $SOURCE;
916
$262.destroy = function() {};

test/runify.js

+21
Original file line numberDiff line numberDiff line change
@@ -958,5 +958,26 @@ hosts.forEach(function (record) {
958958
await agent.destroy();
959959
});
960960
});
961+
962+
describe("agent", () => {
963+
if (!["jsc", "jsshell", "d8"].includes(type)) {
964+
return;
965+
}
966+
967+
const read = async (expression) => {
968+
const result = await agent.evalScript(`print(${expression});`);
969+
expect(result.error).toBe(null);
970+
return result.stdout;
971+
};
972+
973+
it("exposes the complete Test262-defined API", async () => {
974+
expect(await read("typeof $262.agent")).toMatch(/^object/);
975+
expect(await read("typeof $262.agent.start")).toMatch(/^function/);
976+
expect(await read("typeof $262.agent.broadcast")).toMatch(/^function/);
977+
expect(await read("typeof $262.agent.getReport")).toMatch(/^function/);
978+
expect(await read("typeof $262.agent.sleep")).toMatch(/^function/);
979+
expect(await read("typeof $262.agent.monotonicNow")).toMatch(/^function/);
980+
});
981+
});
961982
});
962983
});

0 commit comments

Comments
 (0)