Files
scriptc/tests/corpus/7186-namespace-object-values.js
T
Chris Tate e2db1ef344 Hold Reflect.ownKeys's function value in the Reflect namespace object
Reading `ownKeys` from Reflect read as a value (`const r = Reflect;
r.ownKeys`) gave the member function that throws SC1090 when called,
although the spelled `Reflect.ownKeys` read already has a function
value. The namespace object now holds that function value, so calls
through the alias run and `r.ownKeys === Reflect.ownKeys` is true, as in
Node. The spelled read and the namespace member share one lowering
(reflectMemberValue).
2026-10-24 20:07:36 -05:00

28 lines
1.2 KiB
JavaScript

// Math, JSON and Reflect read as values are objects with Node's own
// properties: typeof, String, `in`, aliasing and member calls through
// the value behave as in Node, and every spelling is the same object.
function describe(value) {
return [typeof value, String(value), Object.prototype.toString.call(value)].join(" ");
}
console.log(describe(Math), "|", describe(JSON), "|", describe(Reflect));
const m = Math;
console.log(m.abs(-2), m.max(1, 5, 3), m.PI.toFixed(5), "trunc" in m, m === Math);
console.log(m === globalThis.Math, JSON === globalThis.JSON);
const { Math: fromGlobal } = globalThis;
console.log(fromGlobal === Math, fromGlobal.sqrt(81));
const known = new Set([Math, JSON, Reflect]);
console.log(known.has(Math), known.has(globalThis.JSON), known.size);
const parse = JSON.parse;
console.log(parse("[1,2]").length, JSON.stringify({ a: [1] }));
console.log(typeof Math === "object" && typeof Reflect === "object");
console.log(Math.max.length, Math.min.length, Math.hypot.length, Math.abs.length);
const r = Reflect;
const ownKeys = r.ownKeys;
console.log(ownKeys === Reflect.ownKeys, r.ownKeys === Reflect.ownKeys, typeof ownKeys);
console.log(r.ownKeys({ a: 1, b: 2 }).length, ownKeys({ c: 3 })[0], ownKeys.name, ownKeys.length);