refactor(codemode): move built-ins onto real prototypes with native function objects - #48608
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fourth step of the value-model rewrite (after #48527, #48541, #48559): built-in methods live on real prototype objects, built-in functions are program objects, and member access is one ordinary property lookup for every value. Internals only: no new syntax, no
thisin program functions, no classes.Before / after
Slotis{ value, writable, enumerable, configurable }or{ get, set, enumerable, configurable }. Built-in methods are installedhidden(non-enumerable),Math.PIandC.prototypearefrozen, functionname/lengtharereadonly.[[Set]]anddeleterespect them, soMath.PI = 3anddelete arr.lengththrow as in strict mode — today they were silently ignored or returnedfalse.Realm
Every prototype is allocated once per run, empty, in dependency order; the globals then populate them and attach constructors. Nothing prototype-related is module-level anymore, so two programs can never see each other's
Number.x = ….Runner.prototypesreplacesRunner.intrinsics;toProgram/fromDatatake the prototypes so no object is ever allocated without one (ProgramObject's constructor requires aproto).thisA member callee keeps its base object as the receiver (EvaluateCall); everything else calls with
undefined. Natives check their receiver, so a detached built-in method behaves like JS:["a","z"].filter("abc".includes) -// ["a"] — IntrinsicReference carried the string +// TypeError: String.prototype.includes called on null or undefinedAccessors on prototypes cover what used to be special-cased in member access:
map.size,regex.flags/.global/…,url.href(with setters),url.searchParams.regex.lastIndexis an own non-configurable data property.newandinstanceofWhat moved
Program-visible changes
All already listed as
[ ]gaps ininterpreter-support.md, now checked:({}).hasOwnProperty("a"),({}).toString()"[object Object]"Array.prototype,Object.prototype.hasOwnProperty === ({}).hasOwnPropertyundefinedtrueMath.max.length,Array.prototype.push.nameundefined2,"push"Object.keys(new Error("m"))["message"][](message non-enumerable, as in JS)const { slice } = [1]; slice(0)Math.PI = 3,delete arr.lengthfalseObject.groupBy(...)Promise.withResolvers()x instanceof Fnfor any function with aprototypeResults
Tests updated to the JS behaviors above; new assertions cover prototype identity,
name/length, non-enumerability, and per-run confinement of prototype mutation (Object.prototype.polluted = 1in one program is invisible to the next).