-
Notifications
You must be signed in to change notification settings - Fork 5k
internal/primordials: Node.js parity, generated and engine-backed #35567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
25
commits into
main
Choose a base branch
from
farm/caec3ad2/primordials-link-time-constants
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
70591cb
jsc: expose Node.js-style primordials as link-time constants
robobun 795d638
build: point WEBKIT_VERSION at preview release for oven-sh/WebKit#341
robobun c244774
shorten primordials comments
robobun e56d298
test(primordials): gate tamper via env, keep harness on captured buil…
robobun 1a9e9d4
ci: retrigger
robobun e3f28fe
test(primordials): poison getter-backed primordials and assert tamper…
robobun 8ea828c
[autofix.ci] apply automated fixes
autofix-ci[bot] e4b4873
primordials: audit binding, generated typedefs, exhaustive tamper tests
dylan-conway f22c668
[autofix.ci] apply automated fixes
autofix-ci[bot] 5173759
bump WebKit preview pin to d0f433e1
dylan-conway f5a9397
primordials: oxlint-disable in generated .d.ts, tamper canary in exha…
robobun b8e0b84
primordials: address review nits in internal-for-testing + tamper suite
robobun 8af6966
test(primordials): wire worker exit handler so a crash surfaces immed…
robobun d7c3488
test(primordials): capture Reflect.set in prelude; reportAndExit in p…
robobun 9abbbf9
Full Node.js primordials parity, generated
dylan-conway f7db891
bump WebKit preview pin to 39d7bcfd
dylan-conway cee3704
[autofix.ci] apply automated fixes
autofix-ci[bot] f08a7ea
primordials: address review feedback
dylan-conway 46ae65d
primordials: keep Node's explicit Safe* constructors
dylan-conway e3a4639
Merge remote-tracking branch 'origin/main' into farm/caec3ad2/primord…
robobun 2b93ac8
build: restore webkitTestFFIPath export dropped in merge
robobun 22d75df
bump WebKit preview pin to 01de5fd4
robobun c6a0d3d
Merge remote-tracking branch 'origin/main' into farm/caec3ad2/primord…
robobun f153789
primordials: fix CI lint + Float16Array inspect crash; regenerate
dylan-conway 75292f8
bump WebKit preview pin to 291ee11e
dylan-conway File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| // Probe half of src/codegen/generate-primordials.ts. Runs inside a pristine target | ||
| // bun binary and reports, for every member Node's primordials construction would | ||
| // produce from this engine's intrinsics, where the pristine value comes from. | ||
| // Output: JSON { entries: [...], missing: [...] } on stdout. | ||
| // | ||
| // This mirrors lib/internal/per_context/primordials.js's enumeration exactly; only | ||
| // what is recorded differs (provenance instead of values). | ||
|
|
||
| const varargsMethods = [ | ||
| "ArrayOf", | ||
| "ArrayPrototypePush", | ||
| "ArrayPrototypeUnshift", | ||
| "MathHypot", | ||
| "MathMax", | ||
| "MathMin", | ||
| "StringFromCharCode", | ||
| "StringFromCodePoint", | ||
| "StringPrototypeConcat", | ||
| "TypedArrayOf", | ||
| ]; | ||
|
|
||
| const entries = []; | ||
| const missing = []; | ||
|
|
||
| function keyDescription(key) { | ||
| // Well-known symbols are named by their identifier ("iterator", "toStringTag"). | ||
| return typeof key === "symbol" ? key.description.replace(/^Symbol\./, "") : key; | ||
| } | ||
|
|
||
| // Same renaming Node applies: symbol keys become SymbolX, string keys get their | ||
| // first character upper-cased. | ||
|
dylan-conway marked this conversation as resolved.
|
||
| function getNewKey(key) { | ||
| return typeof key === "symbol" | ||
| ? `Symbol${key.description[7].toUpperCase()}${key.description.slice(8)}` | ||
| : `${key[0].toUpperCase()}${key.slice(1)}`; | ||
| } | ||
|
|
||
| function record(entry) { | ||
| entries.push(entry); | ||
| } | ||
|
|
||
| function copyOwnProperties(object, holder, prefix, mode) { | ||
| if (object === undefined || object === null) { | ||
| missing.push(holder); | ||
| return; | ||
| } | ||
| for (const key of Reflect.ownKeys(object)) { | ||
| const newKey = getNewKey(key); | ||
| const desc = Reflect.getOwnPropertyDescriptor(object, key); | ||
| const symbolKey = typeof key === "symbol"; | ||
| // Original attributes, so a descriptor can be rebuilt pristinely by the generator. | ||
| const attributes = { enumerable: desc.enumerable, configurable: desc.configurable, writable: desc.writable }; | ||
| if ("get" in desc) { | ||
| record({ | ||
| name: `${prefix}Get${newKey}`, | ||
| holder, | ||
| key: keyDescription(key), | ||
| symbolKey, | ||
| kind: "Getter", | ||
| attributes, | ||
| }); | ||
| if (desc.set) | ||
| record({ | ||
| name: `${prefix}Set${newKey}`, | ||
| holder, | ||
| key: keyDescription(key), | ||
| symbolKey, | ||
| kind: "Setter", | ||
| attributes, | ||
| }); | ||
| continue; | ||
| } | ||
| const name = `${prefix}${newKey}`; | ||
| const value = desc.value; | ||
| const type = value === null ? "null" : typeof value; | ||
| if (type === "function") { | ||
| // mode: "uncurried" (prototype methods), "static", or "bound" (receiver-bound statics). | ||
| record({ name, holder, key: keyDescription(key), symbolKey, kind: "Method", call: mode, attributes }); | ||
| } else if (type === "object" || type === "symbol") { | ||
| record({ name, holder, key: keyDescription(key), symbolKey, kind: "Value", valueType: type, attributes }); | ||
| } else { | ||
| // Spec constants (constructor length/name, Math/Number constants, BYTES_PER_ELEMENT, | ||
| // Symbol.toStringTag strings): inlined as literals rather than read at runtime. | ||
|
dylan-conway marked this conversation as resolved.
|
||
| const literal = type === "string" ? JSON.stringify(value) : String(value); | ||
| record({ name, holder, key: keyDescription(key), symbolKey, kind: "Literal", literal, attributes }); | ||
| } | ||
| if (varargsMethods.includes(name)) record({ name: `${name}Apply`, kind: "ApplyVariant", base: name }); | ||
| } | ||
| } | ||
|
|
||
| const G = globalThis; | ||
|
|
||
| // Configurable value properties of the global object. | ||
| record({ name: "Proxy", kind: "HolderSelf", holder: "ProxyObject" }); | ||
| // The `globalThis` user code observes is the global's own globalThis property | ||
| // (an accessor to the global-this object), not the global object itself. | ||
|
dylan-conway marked this conversation as resolved.
|
||
| record({ | ||
| name: "globalThis", | ||
| holder: "GlobalObject", | ||
| key: "globalThis", | ||
| symbolKey: false, | ||
| kind: "Value", | ||
| valueType: "object", | ||
| }); | ||
| for (const name of ["decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "escape", "eval", "unescape"]) | ||
| record({ name, holder: "GlobalObject", key: name, symbolKey: false, kind: "Method", call: "static" }); | ||
|
|
||
| // Namespace objects. | ||
| for (const name of ["Atomics", "JSON", "Math", "Reflect"]) copyOwnProperties(G[name], `${name}Object`, name, "static"); | ||
| copyOwnProperties(G.Proxy, "ProxyObject", "Proxy", "static"); | ||
|
|
||
| // Intrinsic constructors: the constructor itself, its own properties, and its prototype's. | ||
| for (const name of [ | ||
| "AggregateError", | ||
| "Array", | ||
| "ArrayBuffer", | ||
| "BigInt", | ||
| "BigInt64Array", | ||
| "BigUint64Array", | ||
| "Boolean", | ||
| "DataView", | ||
| "Date", | ||
| "Error", | ||
| "EvalError", | ||
| "FinalizationRegistry", | ||
| "Float16Array", | ||
| "Float32Array", | ||
| "Float64Array", | ||
|
claude[bot] marked this conversation as resolved.
|
||
| "Function", | ||
| "Int16Array", | ||
| "Int32Array", | ||
|
claude[bot] marked this conversation as resolved.
|
||
| "Int8Array", | ||
| "Iterator", | ||
| "Map", | ||
| "Number", | ||
| "Object", | ||
| "RangeError", | ||
| "ReferenceError", | ||
| "RegExp", | ||
| "Set", | ||
| "String", | ||
| "Symbol", | ||
| "SyntaxError", | ||
| "TypeError", | ||
| "URIError", | ||
| "Uint16Array", | ||
| "Uint32Array", | ||
| "Uint8Array", | ||
| "Uint8ClampedArray", | ||
| "WeakMap", | ||
| "WeakRef", | ||
| "WeakSet", | ||
| ]) { | ||
| record({ name, kind: "HolderSelf", holder: `${name}Constructor` }); | ||
| copyOwnProperties(G[name], `${name}Constructor`, name, "static"); | ||
| copyOwnProperties(G[name]?.prototype, `${name}Prototype`, `${name}Prototype`, "uncurried"); | ||
| } | ||
|
|
||
| // Constructors whose statics need the constructor as receiver (Promise.all etc.). | ||
| for (const name of ["Promise"]) { | ||
| record({ name, kind: "HolderSelf", holder: `${name}Constructor` }); | ||
| copyOwnProperties(G[name], `${name}Constructor`, name, "bound"); | ||
| copyOwnProperties(G[name].prototype, `${name}Prototype`, `${name}Prototype`, "uncurried"); | ||
| } | ||
|
|
||
| // %TypedArray%: not on the global object; statics need a concrete constructor receiver. | ||
| { | ||
| const TypedArray = Reflect.getPrototypeOf(Uint8Array); | ||
| record({ name: "TypedArray", kind: "HolderSelf", holder: "TypedArrayConstructor" }); | ||
| copyOwnProperties(TypedArray, "TypedArrayConstructor", "TypedArray", "uncurried"); | ||
| copyOwnProperties(TypedArray.prototype, "TypedArrayPrototype", "TypedArrayPrototype", "uncurried"); | ||
| } | ||
|
|
||
| // Abstract prototypes with no exposed constructor. | ||
| for (const [name, object] of [ | ||
| ["ArrayIteratorPrototype", Reflect.getPrototypeOf([][Symbol.iterator]())], | ||
| ["AsyncFunctionPrototype", Reflect.getPrototypeOf(async function () {})], | ||
| ["AsyncGeneratorFunctionPrototype", Reflect.getPrototypeOf(async function* () {})], | ||
| ["AsyncIteratorPrototype", Reflect.getPrototypeOf(Reflect.getPrototypeOf(async function* () {}).prototype)], | ||
| ["GeneratorFunctionPrototype", Reflect.getPrototypeOf(function* () {})], | ||
| ["IteratorHelperPrototype", Reflect.getPrototypeOf([].values().drop(0))], | ||
| ["MapIteratorPrototype", Reflect.getPrototypeOf(new Map()[Symbol.iterator]())], | ||
| ["RegExpStringIteratorPrototype", Reflect.getPrototypeOf(RegExp.prototype[Symbol.matchAll].call(/a/g, "a"))], | ||
| ["SetIteratorPrototype", Reflect.getPrototypeOf(new Set()[Symbol.iterator]())], | ||
| ["StringIteratorPrototype", Reflect.getPrototypeOf(""[Symbol.iterator]())], | ||
| [ | ||
| "WrapForValidIteratorPrototype", | ||
| Reflect.getPrototypeOf( | ||
| Iterator.from({ | ||
| next() { | ||
| return { done: true }; | ||
| }, | ||
| }), | ||
| ), | ||
| ], | ||
| ]) { | ||
| record({ name, kind: "HolderSelf", holder: name }); | ||
| copyOwnProperties(object, name, name, "uncurried"); | ||
| } | ||
|
|
||
| // Bun.write is native: the probe must not depend on the module it generates. | ||
| await Bun.write(Bun.stdout, JSON.stringify({ entries, missing })); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.