Skip to content
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

[JSC] Function.prototype.toString should print set / get for accessor properties #26660

Conversation

sosukesuzuki
Copy link
Member

@sosukesuzuki sosukesuzuki commented Mar 31, 2024

1ff045b

[JSC] `Function.prototype.toString` should print `set` / `get` for accessor properties
https://bugs.webkit.org/show_bug.cgi?id=271946

Reviewed by Alexey Shvayka.

`Function.prototype.toString` should output strings like `function get foo() { [native code] }` or `function set foo() { [native code] }` for accessor properties[1].
However, for some properties such as `RegExp.input`, JSC currently outputs `function foo() { [native code] }` as if it were a regular function.
This patch changes `Function.prototype.toString` to output `get` or `set` for those accessor properties.

[1]: https://tc39.es/ecma262/#sec-function.prototype.tostring

* JSTests/stress/function-toString-for-accessor-properties.js: Added.
(assertNativeGetter):
(assertNativeSetter):
(wellKnownIntrinsicObjects.forEach):
* LayoutTests/imported/w3c/web-platform-tests/html/dom/idlharness.https_include=(Document_Window)-expected.txt:
* LayoutTests/js/basic-strict-mode-expected.txt:
* LayoutTests/js/dom/native-bindings-descriptors-expected.txt:
* LayoutTests/js/dom/native-bindings-descriptors.html:
* LayoutTests/js/script-tests/basic-strict-mode.js:
* LayoutTests/js/script-tests/function-toString-vs-name.js:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/dom/idlharness.https_include=(Document_Window)-expected.txt:
* LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt:
* LayoutTests/platform/ipad/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt:
* LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt:
* Source/JavaScriptCore/runtime/JSCustomGetterFunction.cpp:
(JSC::JSCustomGetterFunction::create):
* Source/JavaScriptCore/runtime/JSCustomSetterFunction.cpp:
(JSC::JSCustomSetterFunction::create):

Canonical link: https://commits.webkit.org/276904@main

d686be2

Misc iOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-skia
✅ 🛠 🧪 jsc ✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-arm64 ✅ 🛠 tv ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 tv-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 watch ✅ 🛠 jsc-armv7
✅ 🛠 watch-sim ✅ 🧪 jsc-armv7-tests

@sosukesuzuki sosukesuzuki requested a review from a team as a code owner March 31, 2024 07:11
@webkit-early-warning-system
Copy link
Collaborator

webkit-early-warning-system commented Mar 31, 2024

EWS run on previous version of this PR (hash 7a3b207)

Misc iOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ❌ 🧪 wpe-wk2
✅ 🧪 webkitperl ❌ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
[❌ 🧪 ios-wk2-wpt](https://ews-build.webkit.org/#/builders/42/builds/19633 "Found 3 new test failures: imported/w3c/web-platform-tests/css/css-transforms/transform3d-preserve3d-001.html, imported/w3c/web-platform-tests/html/dom/idlharness.https.html?include=(Document Window), imported/w3c/web-platform-tests/mathml/relations/html5-tree/dynamic-childlist-002.html (failure)") 🧪 mac-wk1 ✅ 🛠 wpe-skia
❌ 🛠 🧪 jsc ✅ 🧪 api-ios 🧪 mac-wk2 ✅ 🛠 gtk
❌ 🛠 🧪 jsc-arm64 ✅ 🛠 tv [❌ 🧪 mac-AS-debug-wk2](https://ews-build.webkit.org/#/builders/50/builds/17503 "Found 4 new test failures: imported/w3c/web-platform-tests/html/dom/idlharness.https.html?include=(Document Window), js/basic-strict-mode.html, js/dom/native-bindings-descriptors.html, js/function-toString-vs-name.html (failure)") [❌ 🧪 gtk-wk2](https://ews-build.webkit.org/#/builders/1/builds/44788 "Found 4 new test failures: imported/w3c/web-platform-tests/html/dom/idlharness.https.html?include=(Document
✅ 🛠 tv-sim ✅ 🧪 api-gtk
✅ 🛠 watch ✅ 🛠 jsc-armv7
✅ 🛠 watch-sim ✅ 🧪 jsc-armv7-tests

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 31, 2024
@sosukesuzuki sosukesuzuki force-pushed the eng/function-tostring-for-accessor branch from 7a3b207 to dc1b87a Compare March 31, 2024 09:45
@webkit-early-warning-system
Copy link
Collaborator

webkit-early-warning-system commented Mar 31, 2024

EWS run on previous version of this PR (hash dc1b87a)

Misc iOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ❌ 🧪 wpe-wk2
✅ 🧪 webkitperl ❌ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt 🧪 mac-wk1 ✅ 🛠 wpe-skia
❌ 🛠 🧪 jsc ✅ 🧪 api-ios 🧪 mac-wk2 ✅ 🛠 gtk
❌ 🛠 🧪 jsc-arm64 ✅ 🛠 tv [❌ 🧪 mac-AS-debug-wk2](https://ews-build.webkit.org/#/builders/50/builds/17507 "Found 4 new test failures: imported/w3c/web-platform-tests/html/dom/idlharness.https.html?include=(Document Window), js/basic-strict-mode.html, js/dom/native-bindings-descriptors.html, js/function-toString-vs-name.html (failure)") [❌ 🧪 gtk-wk2](https://ews-build.webkit.org/#/builders/1/builds/44789 "Found 4 new test failures: imported/w3c/web-platform-tests/html/dom/idlharness.https.html?include=(Document
✅ 🛠 tv-sim ✅ 🧪 api-gtk
✅ 🛠 watch ✅ 🛠 jsc-armv7
✅ 🛠 watch-sim ❌ 🧪 jsc-armv7-tests

@sosukesuzuki sosukesuzuki force-pushed the eng/function-tostring-for-accessor branch from dc1b87a to 9cb6d97 Compare March 31, 2024 12:04
@webkit-early-warning-system
Copy link
Collaborator

webkit-early-warning-system commented Mar 31, 2024

EWS run on previous version of this PR (hash 9cb6d97)

Misc iOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ❌ 🧪 wpe-wk2
✅ 🧪 webkitperl 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
🧪 ios-wk2-wpt 🧪 mac-wk1 ✅ 🛠 wpe-skia
✅ 🛠 🧪 jsc 🧪 api-ios 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-arm64 ✅ 🛠 tv [❌ 🧪 mac-AS-debug-wk2](https://ews-build.webkit.org/#/builders/50/builds/17510 "Found 3 new test failures: imported/w3c/web-platform-tests/html/dom/idlharness.https.html?include=(Document Window), js/dom/native-bindings-descriptors.html, js/function-toString-vs-name.html (failure)") [❌ 🧪 gtk-wk2](https://ews-build.webkit.org/#/builders/1/builds/44790 "Found 3 new test failures: imported/w3c/web-platform-tests/html/dom/idlharness.https.html?include=(Document
✅ 🛠 tv-sim ✅ 🧪 api-gtk
✅ 🛠 watch ✅ 🛠 jsc-armv7
✅ 🛠 watch-sim ✅ 🧪 jsc-armv7-tests

@sosukesuzuki sosukesuzuki force-pushed the eng/function-tostring-for-accessor branch from 9cb6d97 to d4b6933 Compare March 31, 2024 14:31
@sosukesuzuki sosukesuzuki force-pushed the eng/function-tostring-for-accessor branch from d4b6933 to d686be2 Compare March 31, 2024 16:06
@Ahmad-S792 Ahmad-S792 added JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. and removed merging-blocked Applied to prevent a change from being merged labels Mar 31, 2024
Copy link
Member

@shvaikalesh shvaikalesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely, thank you Sosuke!

One thing: could you please Tools/Scripts/test262-runner --release -o test/built-ins/Function/prototype/toString? We might have a new passing test there to remove from JSTests/test262/expectations.yaml.

@sosukesuzuki
Copy link
Member Author

@shvaikalesh Thanks for the review!
The reason that test is failing is probably a different issue than this patch, see tc39/test262#4039, so I don't think we can enable this test yet.

@shvaikalesh
Copy link
Member

@sosukesuzuki Oh wow, thank you for your analysis & raising the issue further!

@shvaikalesh shvaikalesh added the merge-queue Applied to send a pull request to merge-queue label Apr 1, 2024
@webkit-commit-queue webkit-commit-queue force-pushed the eng/function-tostring-for-accessor branch from d686be2 to f67880d Compare April 1, 2024 21:37
…cessor properties

https://bugs.webkit.org/show_bug.cgi?id=271946

Reviewed by Alexey Shvayka.

`Function.prototype.toString` should output strings like `function get foo() { [native code] }` or `function set foo() { [native code] }` for accessor properties[1].
However, for some properties such as `RegExp.input`, JSC currently outputs `function foo() { [native code] }` as if it were a regular function.
This patch changes `Function.prototype.toString` to output `get` or `set` for those accessor properties.

[1]: https://tc39.es/ecma262/#sec-function.prototype.tostring

* JSTests/stress/function-toString-for-accessor-properties.js: Added.
(assertNativeGetter):
(assertNativeSetter):
(wellKnownIntrinsicObjects.forEach):
* LayoutTests/imported/w3c/web-platform-tests/html/dom/idlharness.https_include=(Document_Window)-expected.txt:
* LayoutTests/js/basic-strict-mode-expected.txt:
* LayoutTests/js/dom/native-bindings-descriptors-expected.txt:
* LayoutTests/js/dom/native-bindings-descriptors.html:
* LayoutTests/js/script-tests/basic-strict-mode.js:
* LayoutTests/js/script-tests/function-toString-vs-name.js:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/dom/idlharness.https_include=(Document_Window)-expected.txt:
* LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt:
* LayoutTests/platform/ipad/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt:
* LayoutTests/platform/wpe/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt:
* Source/JavaScriptCore/runtime/JSCustomGetterFunction.cpp:
(JSC::JSCustomGetterFunction::create):
* Source/JavaScriptCore/runtime/JSCustomSetterFunction.cpp:
(JSC::JSCustomSetterFunction::create):

Canonical link: https://commits.webkit.org/276904@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/function-tostring-for-accessor branch from f67880d to 1ff045b Compare April 1, 2024 21:39
@webkit-commit-queue
Copy link
Collaborator

Committed 276904@main (1ff045b): https://commits.webkit.org/276904@main

Reviewed commits have been landed. Closing PR #26660 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 1ff045b into WebKit:main Apr 1, 2024
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Apr 1, 2024
@sosukesuzuki sosukesuzuki deleted the eng/function-tostring-for-accessor branch April 2, 2024 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants