feat: Node-style primordials for runtime builtins - #1990
Open
edusperoni wants to merge 1 commit into
Open
Conversation
Runtime builtins install closures that outlive init and are then reachable from app code, so every intrinsic they use at call time is something the app can replace. internal/primordials.js snapshots exactly the intrinsics the builtins need into a frozen null-prototype namespace, taken on the first RunBuiltin of an isolate (during runtime init) and cached per isolate; builtins now compile with a fourth fixed parameter, `primordials`. Instance methods are uncurried Node-style, so the receiver becomes the first argument. ESLint fails the lint on direct use of the captured statics and constructors. Mirrors NativeScript/ios#415.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Description
Android mirror of NativeScript/ios#415. Stacked on #1989 (
feat/js-builtins) — review only the last commit.The runtime's builtin JavaScript installs globals and leaves closures behind that run for the lifetime of the app: event dispatch, the URL/blob glue, console's stringify, the JS→
org.jsonserializer. Until now those closures reached for intrinsics (Array.prototype.slice,JSON.stringify,Object.defineProperty, …) through the live globals, so app code replacing one could break runtime internals or observe them.internal/primordials.jscaptures exactly the intrinsics the other builtins need into a frozen, null-prototype namespace, Node-style — trimmed to what the Android builtins actually reach (not a mirror of Node's or iOS's list).The
(binding, primordials)contractexports,module,binding,primordials.RunBuiltinof an isolate — during runtime init, before any user code — and cached per isolate (mutex-guarded, released on isolate disposal; worker isolates snapshot their own realm's intrinsics automatically).ArrayPrototypeSlice(list, 1), viaFunction.prototype.bind.bind(Function.prototype.call)); statics keep their path (JSONStringify). Plain constructor calls made once at init time stay direct — the rule targets closures that outlive init.Blob/Fileinblob-url.js(app-layer provided),global.__requireOverrideinrequire-factory.js(app-layer hook),org.json.*injson-helper.js(metadata interceptor, not an intrinsic).Enforcement: ESLint
no-restricted-propertiesfor every captured static andno-restricted-globalsfor every captured constructor, each message naming the replacement;primordials.jsitself is exempted. Both rule classes verified to fire.Tests: new
tests/testPrimordials.js(8 specs) tampers with the intrinsics and checks the runtime keeps working — a guard spec proving the tampering is observable, globaldispatchEvent/add/remove/onceunder brokenArray.prototype.*+Function.prototype.call,reportErrordelivering a correctErrorEvent, circularconsole.logstaying non-fatal, plus Android-specific specs for thesearchParamsre-sync, the blob store under brokenMap.prototype.*, andorg.jsonserialization under brokenArray/Object/Dateintrinsics. Each spec keeps the tampered window synchronous and assertion-free, restoring originals infinally.Related Pull Requests
Does your pull request have unit tests?
Yes — 8 new device specs. Full suite: 613 specs, 0 failures (605 baseline + 8), including worker suites, which exercise per-isolate snapshot creation and disposal on worker threads.