Add funcsAreBuiltins flag to show [native code] for JS builtins #1864
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.
Summary:
ECMAScript requires that builtin functions return "[native code]" from
toString(). Many libraries (e.g., Babel) check for this string to detect
builtins and alter their behavior accordingly.
Previously, JS-implemented builtins from InternalJavaScript and extensions
would return "[bytecode]" (since their source is not available), causing
these library heuristics to fail.
Add a new funcsAreBuiltins flag to RuntimeModuleFlags that causes
Function.prototype.toString() to return "[native code]" for all functions
in the module. Set the flag when loading internal bytecode and extensions
bytecode.
Subtle logic for InternalJavaScript (Promise):
The funcsAreBuiltins flag for InternalJavaScript is set conditionally based
on hasMicrotaskQueue(). This is intentional:
Some React Native versions detect whether to use the VM's microtask queue by
checking Promise.toString().includes("[native code]"). When microtask queue
is disabled but Promise still reports as "[native code]", RN incorrectly
assumes the engine queue is enabled and skips its own queue implementation.
By making funcsAreBuiltins conditional:
This ensures the RN heuristic produces correct results.
Note: The hermes CLI defaults to microtask queue enabled, so existing tests
continue to pass without modification.
Extensions always have funcsAreBuiltins=true since they don't affect the
microtask queue detection logic.
Differential Revision: D89523668