haikuwebkit/LayoutTests/js/kde
Alexey Shvayka 48894e59b1 Partly implement Function.prototype.{caller,arguments} reflection proposal
https://bugs.webkit.org/show_bug.cgi?id=158116

Reviewed by Yusuke Suzuki.

JSTests:

* ChakraCore/test/strict/19.function.baseline:
* ChakraCore/test/strict/22.callerCalleeArguments.baseline-jsc:
* microbenchmarks/function-prototype-get.js: Added.
* microbenchmarks/reflect-own-keys-function.js: Added.
* stress/for-in-shadow-non-enumerable.js:
* stress/function-hidden-as-caller.js:
* stress/has-own-property-arguments.js:
* stress/object-assign-fast-path.js:
* stress/put-to-proto-chain-overrides-put.js:
* stress/reflect-set.js:
* test262/config.yaml: Skip 3 test cases that are now incorrect.
* test262/expectations.yaml: Mark 2 test cases as passing.

Source/JavaScriptCore:

To ensure web-compatibility, only the safe subset of Function.prototype.{caller,arguments}
reflection proposal [1] is implemented, which is currently shipped in SpiderMonkey.

Complete list of differences from the proposed spec:

  1. Cross-realm receiver function is allowed instead of throwing a TypeError.

     Throwing is likely safe to ship, but #225997 needs to be fixed first for
     custom properties to receive correct global object.

  2. Cross-realm caller function is returned instead of `null`.

     Hiding cross-realm caller may break things: we currently have a test for
     the opposite behavior.

  3. Defines "caller" and "arguments" setters that throw for disallowed receivers,
     instead failing silently in sloppy mode.

     This is actually more restrictive than the spec, which is preferable,
     and aligns with V8 and SM.

Most importantly, this patch removes own "caller" and "arguments" properties from
sloppy mode ES5 functions. They were non-configurable, making it harder to use
their holder as a [[ProxyTarget]]. They were also non-writable, with a constantly
changing [[Value]], which violated the invariants of internal methods [2].

As a result, JSFunction methods are greatly simplified, especially defineOwnProperty()
and getOwnSpecialPropertyNames(). The latter is now 2.1x faster according to the
provided microbenchmark. Also, removes double "prototype" lookup from [[Get]],
which is a 10% progression.

[1]: https://github.com/claudepache/es-legacy-function-reflection
[2]: https://tc39.es/ecma262/#sec-invariants-of-the-essential-internal-methods

* runtime/ClonedArguments.cpp:
(JSC::ClonedArguments::getOwnPropertySlot):
(JSC::ClonedArguments::materializeSpecials):
* runtime/FunctionExecutable.h:
* runtime/FunctionPrototype.cpp:
(JSC::FunctionPrototype::addFunctionProperties):
(JSC::isAllowedReceiverFunctionForCallerAndArguments):
(JSC::RetrieveArgumentsFunctor::RetrieveArgumentsFunctor):
(JSC::RetrieveArgumentsFunctor::result const):
(JSC::RetrieveArgumentsFunctor::operator() const):
(JSC::retrieveArguments):
(JSC::JSC_DEFINE_CUSTOM_GETTER):
(JSC::RetrieveCallerFunctionFunctor::RetrieveCallerFunctionFunctor):
(JSC::RetrieveCallerFunctionFunctor::result const):
(JSC::RetrieveCallerFunctionFunctor::operator() const):
(JSC::retrieveCallerFunction):
(JSC::JSC_DEFINE_CUSTOM_SETTER):
(JSC::FunctionPrototype::initRestrictedProperties): Deleted.
* runtime/FunctionPrototype.h:
* runtime/JSFunction.cpp:
(JSC::JSFunction::getOwnPropertySlot):
(JSC::JSFunction::getOwnSpecialPropertyNames):
(JSC::JSFunction::put):
(JSC::JSFunction::deleteProperty):
(JSC::JSFunction::defineOwnProperty):
(JSC::RetrieveArgumentsFunctor::RetrieveArgumentsFunctor): Deleted.
(JSC::RetrieveArgumentsFunctor::result const): Deleted.
(JSC::RetrieveArgumentsFunctor::operator() const): Deleted.
(JSC::retrieveArguments): Deleted.
(JSC::JSC_DEFINE_CUSTOM_GETTER): Deleted.
(JSC::RetrieveCallerFunctionFunctor::RetrieveCallerFunctionFunctor): Deleted.
(JSC::RetrieveCallerFunctionFunctor::result const): Deleted.
(JSC::RetrieveCallerFunctionFunctor::operator() const): Deleted.
(JSC::retrieveCallerFunction): Deleted.
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildrenImpl):
* runtime/JSGlobalObject.h:
Remove unused m_throwTypeErrorGetterSetter and make [[ThrowTypeError]] lazily-created.

* runtime/JSGlobalObjectFunctions.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/JSGlobalObjectFunctions.h:
* runtime/JSObject.cpp:
(JSC::JSObject::putDirectCustomGetterSetterWithoutTransition):
* runtime/JSObject.h:

LayoutTests:

* inspector/model/remote-object-get-properties-expected.txt:
* inspector/runtime/getDisplayableProperties-expected.txt:
* inspector/runtime/getProperties-expected.txt:
* js/Object-getOwnPropertyNames-expected.txt:
* js/basic-strict-mode-expected.txt:
* js/kde/function_arguments-expected.txt:
* js/kde/script-tests/function_arguments.js:
* js/non-strict-function-properties-expected.txt:
* js/script-tests/Object-getOwnPropertyNames.js:
* js/script-tests/basic-strict-mode.js:
* js/script-tests/non-strict-function-properties.js:
* js/script-tests/throw-type-error-is-unique.js:


Canonical link: https://commits.webkit.org/239947@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@280289 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-07-25 22:32:20 +00:00
..
resources [LayoutTests] Delete unused LayoutTests/js resources 2021-06-11 23:26:54 +00:00
script-tests Partly implement Function.prototype.{caller,arguments} reflection proposal 2021-07-25 22:32:20 +00:00
Array-expected.txt
Array.html
Boolean-expected.txt
Boolean.html
Date-setYear-expected.txt
Date-setYear.html
Date.html
Error-expected.txt
Error.html
GlobalObject-expected.txt
GlobalObject.html
Number-expected.txt Increase NumberToStringBuffer to account for negative number 2021-05-27 21:34:06 +00:00
Number.html
Object-expected.txt
Object.html
Prototype-expected.txt
Prototype.html
RegExp-expected.txt Update treatment of invoking RegExp.prototype methods on RegExp.prototype. 2016-04-14 18:16:35 +00:00
RegExp.html
StringObject-expected.txt
StringObject.html
arguments-scope-expected.txt
arguments-scope.html
assignments-expected.txt
assignments.html
cast-expected.txt
cast.html
comment-1-expected.txt
comment-1.html
comment-2-expected.txt
comment-2.html
completion-expected.txt test262: Completion values for control flow do not match the spec 2017-09-05 17:43:51 +00:00
completion.html
conditional-expected.txt
conditional.html
const-expected.txt [ES6] Add support for block scope const 2015-07-19 16:57:44 +00:00
const.html
constructor_length-expected.txt
constructor_length.html
crash-1-expected.txt
crash-1.html
crash-2-expected.txt
crash-2.html
delete-expected.txt
delete.html
empty-expected.txt
empty.html
encode_decode_uri-expected.txt
encode_decode_uri.html
eval-expected.txt
eval.html
evil-n-expected.txt
evil-n.html
exception_propagation-expected.txt
exception_propagation.html
exceptions-expected.txt
exceptions.html
func-decl-expected.txt Implement Annex B.3.3 function hoisting rules for function code 2016-04-03 19:45:05 +00:00
func-decl.html
function-expected.txt Move LayoutTests/fast/js to LayoutTests/js. 2013-09-10 16:54:23 +00:00
function.html
function_arguments-expected.txt Partly implement Function.prototype.{caller,arguments} reflection proposal 2021-07-25 22:32:20 +00:00
function_arguments.html
function_constructor-expected.txt
function_constructor.html
function_length-expected.txt
function_length.html
garbage-n-expected.txt Changes to shared testing JS files should not cause test failures due to console message line numbers changing 2020-04-10 21:10:11 +00:00
garbage-n.html
inbuilt_function_proto-expected.txt
inbuilt_function_proto.html
inbuilt_function_tostring-expected.txt [JSC] Date.toGMTString should be the Date.toUTCString function 2016-07-01 20:49:31 +00:00
inbuilt_function_tostring.html
iteration-expected.txt
iteration.html
j-comment-3-expected.txt
j-comment-3.html
j-comment-4-expected.txt
j-comment-4.html
literals-expected.txt
literals.html
lval-exceptions-expected.txt ES6: Object Literal Methods toString is missing method name 2015-03-24 20:07:26 +00:00
lval-exceptions.html
math-expected.txt
math.html
md5-1-expected.txt
md5-1.html
md5-2-expected.txt
md5-2.html
object_prototype-expected.txt
object_prototype.html
object_prototype_tostring-expected.txt
object_prototype_tostring.html
operators-expected.txt
operators.html
parse-expected.txt Wrong radix used in Unicode Escape in invalid character error message 2017-07-12 15:57:14 +00:00
parse.html
prototype_length-expected.txt Align "length" properties of function prototypes with the spec 2020-08-21 23:07:40 +00:00
prototype_length.html
prototype_proto-expected.txt
prototype_proto.html
scope-expected.txt
scope.html
statements-expected.txt
statements.html
string-1-n-expected.txt Changes to shared testing JS files should not cause test failures due to console message line numbers changing 2020-04-10 21:10:11 +00:00
string-1-n.html
string-2-n-expected.txt Changes to shared testing JS files should not cause test failures due to console message line numbers changing 2020-04-10 21:10:11 +00:00
string-2-n.html
var_decl_init-expected.txt
var_decl_init.html