Fix native Function.prototype.toString() format to match V8/Node.js - #155
Merged
robobun merged 1 commit intoFeb 2, 2026
Merged
Conversation
Change the native function toString representation from:
function Function() {
[native code]
}
to:
function Function() { [native code] }
This matches the format used by V8 and ensures compatibility with packages
that depend on the specific output format of toString() for native functions.
Fixes oven-sh/bun#26698
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. WalkthroughModified the native code representation in Changes
Comment |
robobun
added a commit
to oven-sh/bun
that referenced
this pull request
Sep 1, 2026
oven-sh/WebKit#545 completes oven-sh/WebKit#155. NativeExecutable, builtin functions written in JavaScript, bound functions and remote functions now print `function name() { [native code] }`, the same one-line shape as InternalFunction constructors and V8. lodash's isNative() builds a RegExp from hasOwnProperty's source and tests Map against it. With one shape the RegExp matches, so cloneDeep, memoize, uniq and isEqual use a native Map instead of a linear-scan ListCache under Bun. cloneDeep of 8 000 objects: 1 971 ms before, linear after. The pin moves from the oven-sh/WebKit#541 preview to the fork's main at 01de4c1d, which also carries oven-sh/WebKit#529, #542 and #543. #543 moved the dynamic-import TLA deadlock check into the engine and removed JSModuleLoader::asyncEvaluationOrderForKey and the referrerAsyncOrder parameter of JSC::importModule, so moduleLoaderImportModule no longer computes or passes it. Tests: test/js/bun/jsc/function-prototype-tostring.test.ts and the oven-sh/WebKit#545 stress file as a jsc-stress fixture. Both fail on Bun 1.4.1.
pull Bot
pushed a commit
to coleleavitt/WebKit
that referenced
this pull request
Sep 1, 2026
oven-sh#155 changed the InternalFunction and callable-object branches of Function.prototype.toString to the V8 shape: function Map() { [native code] } Host functions (NativeExecutable::toStringSlow), builtin functions written in JavaScript (FunctionExecutable::toStringSlow), bound functions and remote functions (JSFunction::toString) still printed the old three-line shape: function hasOwnProperty() { [native code] } lodash's isNative() builds a RegExp from the source of Object.prototype.hasOwnProperty and tests Map, Set, WeakMap, DataView and Promise against it. With two shapes in one engine, the RegExp did not match, lodash decided Map was not native, and MapCache and Stack fell back to ListCache, a linear scan. cloneDeep, memoize, uniq and isEqual became quadratic under Bun. json-schema-to-typescript measured cloneDeep of a 10 000 definition schema at 11 s under Bun and 76 ms under node (bcherny/json-schema-to-typescript#871). This changes the remaining four sites to the one-line shape, so all native functions print the same way, and updates the inspector's native-getter sniff and the testapi.mm expectation to match. JSTests/stress/function-toString-native-one-line.js pins the shape for each kind of function, re-runs lodash's RegExp, and walks the global object to check that no native function prints on more than one line.
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.
Summary
toString()representation to use single-line format matching V8/Node.jsDetails
Change the native function toString representation from:
to:
This matches the format used by V8/Node.js and ensures compatibility with packages that depend on the specific output format of
toString()for native functions.Test plan
function fn() {}; console.log(fn.constructor.toString());function Function() { [native code] }Fixes oven-sh/bun#26698
🤖 Generated with Claude Code