From 8143ae6e242e977fae1f855953e9d368d2677d3f Mon Sep 17 00:00:00 2001 From: Justin Dorfman Date: Thu, 12 Dec 2024 15:55:28 -0800 Subject: [PATCH 01/16] Add tests for Function.prototype.caller and arguments properties --- .../caller-arguments/accessor-properties.js | 18 ++++++++++++++++++ .../caller-arguments/cross-realm-behavior.js | 13 +++++++++++++ .../caller-arguments/module-context.js | 12 ++++++++++++ .../caller-arguments/strict-vs-nonstrict.js | 18 ++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 test/built-ins/Function/prototype/caller-arguments/accessor-properties.js create mode 100644 test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js create mode 100644 test/built-ins/Function/prototype/caller-arguments/module-context.js create mode 100644 test/built-ins/Function/prototype/caller-arguments/strict-vs-nonstrict.js diff --git a/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js b/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js new file mode 100644 index 00000000000..b58d2bc562f --- /dev/null +++ b/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js @@ -0,0 +1,18 @@ +/*--- +description: Function.prototype caller and arguments properties are accessor properties with ThrowTypeError +esid: sec-function.prototype.caller +info: | + Function instances do not inherit the "caller" and "arguments" accessors + from Function.prototype. The accessors exist only on Function.prototype. +---*/ + +const callerDesc = Object.getOwnPropertyDescriptor(Function.prototype, "caller"); +const argumentsDesc = Object.getOwnPropertyDescriptor(Function.prototype, "arguments"); + +assert.sameValue(typeof callerDesc.get, "function"); +assert.sameValue(typeof callerDesc.set, "function"); +assert.sameValue(callerDesc.get, callerDesc.set, "caller getter/setter should be same function"); + +assert.sameValue(typeof argumentsDesc.get, "function"); +assert.sameValue(typeof argumentsDesc.set, "function"); +assert.sameValue(argumentsDesc.get, argumentsDesc.set, "arguments getter/setter should be same function"); diff --git a/test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js b/test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js new file mode 100644 index 00000000000..925ea5e4866 --- /dev/null +++ b/test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js @@ -0,0 +1,13 @@ +/*--- +description: Function.prototype caller and arguments properties use the same ThrowTypeError across realms +features: [cross-realm] +---*/ + +const otherRealm = $262.createRealm(); +const otherFunctionProto = otherRealm.evaluate('Function.prototype'); + +const mainCallerDesc = Object.getOwnPropertyDescriptor(Function.prototype, "caller"); +const otherCallerDesc = Object.getOwnPropertyDescriptor(otherFunctionProto, "caller"); + +assert.sameValue(mainCallerDesc.get, otherCallerDesc.get, "caller getter should be same across realms"); +assert.sameValue(mainCallerDesc.set, otherCallerDesc.set, "caller setter should be same across realms"); diff --git a/test/built-ins/Function/prototype/caller-arguments/module-context.js b/test/built-ins/Function/prototype/caller-arguments/module-context.js new file mode 100644 index 00000000000..18944c3c3d3 --- /dev/null +++ b/test/built-ins/Function/prototype/caller-arguments/module-context.js @@ -0,0 +1,12 @@ +/*--- +description: Function properties behave consistently in module context +flags: [module] +---*/ + +function normalFunc() {} +function strictFunc() { } + +assert(!Object.hasOwnProperty.call(normalFunc, "caller"), "normal function should not have caller"); +assert(!Object.hasOwnProperty.call(strictFunc, "caller"), "strict function should not have caller"); +assert(!Object.hasOwnProperty.call(normalFunc, "arguments"), "normal function should not have arguments"); +assert(!Object.hasOwnProperty.call(strictFunc, "arguments"), "strict function should not have arguments"); diff --git a/test/built-ins/Function/prototype/caller-arguments/strict-vs-nonstrict.js b/test/built-ins/Function/prototype/caller-arguments/strict-vs-nonstrict.js new file mode 100644 index 00000000000..e9c99b400a5 --- /dev/null +++ b/test/built-ins/Function/prototype/caller-arguments/strict-vs-nonstrict.js @@ -0,0 +1,18 @@ +/*--- +description: Function properties behavior in strict vs non-strict contexts +flags: [noStrict] +---*/ + +function nonStrictFunc() { + return nonStrictFunc.caller; +} + +function strictFunc() { + return strictFunc.caller; +} + +assert(!Object.hasOwnProperty.call(nonStrictFunc, "caller"), "non-strict function should not have own caller property"); +assert(!Object.hasOwnProperty.call(strictFunc, "caller"), "strict function should not have own caller property"); + +assert.throws(TypeError, () => nonStrictFunc(), "accessing caller should throw"); +assert.throws(TypeError, () => strictFunc(), "accessing caller should throw in strict mode"); From c3f82b52ef88105bb098eea01ed978342a811a9a Mon Sep 17 00:00:00 2001 From: Justin Dorfman Date: Fri, 20 Dec 2024 15:12:57 -0800 Subject: [PATCH 02/16] Add tests for Function.prototype.caller and arguments properties --- .../Function/prototype/arguments/prop-desc.js | 25 +++++++++++++++++++ .../Function/prototype/caller/prop-desc.js | 25 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 test/built-ins/Function/prototype/arguments/prop-desc.js create mode 100644 test/built-ins/Function/prototype/caller/prop-desc.js diff --git a/test/built-ins/Function/prototype/arguments/prop-desc.js b/test/built-ins/Function/prototype/arguments/prop-desc.js new file mode 100644 index 00000000000..42b8ad3821e --- /dev/null +++ b/test/built-ins/Function/prototype/arguments/prop-desc.js @@ -0,0 +1,25 @@ +// Copyright (C) 2024 Justin Dorfman. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-function.prototype.arguments +description: > + Function.prototype.arguments property descriptor +info: | + Function.prototype.arguments is an accessor property whose set and get + accessor functions are both %ThrowTypeError%. +includes: [propertyHelper.js] +---*/ + +const argumentsDesc = Object.getOwnPropertyDescriptor(Function.prototype, 'arguments'); + +verifyProperty(Function.prototype, "arguments", { + enumerable: false, + configurable: true +}); + +assert.sameValue(typeof argumentsDesc.get, "function", + "Function.prototype.arguments has function getter"); +assert.sameValue(typeof argumentsDesc.set, "function", + "Function.prototype.arguments has function setter"); +assert.sameValue(argumentsDesc.get, argumentsDesc.set, + "Arguments property getter/setter are the same function"); diff --git a/test/built-ins/Function/prototype/caller/prop-desc.js b/test/built-ins/Function/prototype/caller/prop-desc.js new file mode 100644 index 00000000000..3ab9a02780e --- /dev/null +++ b/test/built-ins/Function/prototype/caller/prop-desc.js @@ -0,0 +1,25 @@ +// Copyright (C) 2024 Justin Dorfman. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-function.prototype.caller +description: > + Function.prototype.caller property descriptor +info: | + Function.prototype.caller is an accessor property whose set and get + accessor functions are both %ThrowTypeError%. +includes: [propertyHelper.js] +---*/ + +const callerDesc = Object.getOwnPropertyDescriptor(Function.prototype, 'caller'); + +verifyProperty(Function.prototype, "caller", { + enumerable: false, + configurable: true +}); + +assert.sameValue(typeof callerDesc.get, "function", + "Function.prototype.caller has function getter"); +assert.sameValue(typeof callerDesc.set, "function", + "Function.prototype.caller has function setter"); +assert.sameValue(callerDesc.get, callerDesc.set, + "Caller property getter/setter are the same function"); From 5790fd4173d5bb19b1889b6c541ed9ca22757bfc Mon Sep 17 00:00:00 2001 From: Justin Dorfman Date: Mon, 13 Jan 2025 08:45:10 -0800 Subject: [PATCH 03/16] Update test/built-ins/Function/prototype/arguments/prop-desc.js Co-authored-by: Richard Gibson --- .../Function/prototype/arguments/prop-desc.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/built-ins/Function/prototype/arguments/prop-desc.js b/test/built-ins/Function/prototype/arguments/prop-desc.js index 42b8ad3821e..12e04f512bb 100644 --- a/test/built-ins/Function/prototype/arguments/prop-desc.js +++ b/test/built-ins/Function/prototype/arguments/prop-desc.js @@ -1,12 +1,14 @@ // Copyright (C) 2024 Justin Dorfman. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-function.prototype.arguments +esid: sec-addrestrictedfunctionproperties description: > - Function.prototype.arguments property descriptor -info: | Function.prototype.arguments is an accessor property whose set and get - accessor functions are both %ThrowTypeError%. + functions are both %ThrowTypeError%. +info: | + 2. Let _thrower_ be _realm_.[[Intrinsics]].[[%ThrowTypeError%]]. + 3. Perform ! DefinePropertyOrThrow(_F_, *"caller"*, PropertyDescriptor { [[Get]]: _thrower_, [[Set]]: _thrower_, [[Enumerable]]: *false*, [[Configurable]]: *true* }). + 4. Perform ! DefinePropertyOrThrow(_F_, *"arguments"*, PropertyDescriptor { [[Get]]: _thrower_, [[Set]]: _thrower_, [[Enumerable]]: *false*, [[Configurable]]: *true* }). includes: [propertyHelper.js] ---*/ From 6964e50d734e832310430c41e0181c328d18be00 Mon Sep 17 00:00:00 2001 From: Justin Dorfman Date: Mon, 13 Jan 2025 08:45:20 -0800 Subject: [PATCH 04/16] Update test/built-ins/Function/prototype/arguments/prop-desc.js Co-authored-by: Richard Gibson --- test/built-ins/Function/prototype/arguments/prop-desc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/built-ins/Function/prototype/arguments/prop-desc.js b/test/built-ins/Function/prototype/arguments/prop-desc.js index 12e04f512bb..aa08554e8b3 100644 --- a/test/built-ins/Function/prototype/arguments/prop-desc.js +++ b/test/built-ins/Function/prototype/arguments/prop-desc.js @@ -24,4 +24,4 @@ assert.sameValue(typeof argumentsDesc.get, "function", assert.sameValue(typeof argumentsDesc.set, "function", "Function.prototype.arguments has function setter"); assert.sameValue(argumentsDesc.get, argumentsDesc.set, - "Arguments property getter/setter are the same function"); + "Function.prototype.arguments property getter/setter are the same function"); From 52c319a4447486f07ba898ab8bb95593b2face11 Mon Sep 17 00:00:00 2001 From: Justin Dorfman Date: Sun, 19 Jan 2025 16:53:22 -0800 Subject: [PATCH 05/16] Update test/built-ins/Function/prototype/arguments/prop-desc.js Co-authored-by: Richard Gibson --- .../Function/prototype/arguments/prop-desc.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/built-ins/Function/prototype/arguments/prop-desc.js b/test/built-ins/Function/prototype/arguments/prop-desc.js index aa08554e8b3..9f411825948 100644 --- a/test/built-ins/Function/prototype/arguments/prop-desc.js +++ b/test/built-ins/Function/prototype/arguments/prop-desc.js @@ -25,3 +25,19 @@ assert.sameValue(typeof argumentsDesc.set, "function", "Function.prototype.arguments has function setter"); assert.sameValue(argumentsDesc.get, argumentsDesc.set, "Function.prototype.arguments property getter/setter are the same function"); + +var throwTypeError; +WellKnownIntrinsicObjects.forEach(function(record) { + if (record.name === "%ThrowTypeError%") { + throwTypeError = record.value; + } +}); +if (throwTypeError) { + assert.sameValue(descriptor.set, throwTypeError, "Function.prototype.arguments getter is %ThrowTypeError%"); +} +assert.throws(TypeError, function() { + return Function.prototype.arguments; +}); +assert.throws(TypeError, function() { + Function.prototype.arguments = {}; +}); From 947ca822d6bbdad36c31a9e24cdf8428f1f98e90 Mon Sep 17 00:00:00 2001 From: Justin Dorfman Date: Sun, 19 Jan 2025 16:53:30 -0800 Subject: [PATCH 06/16] Update test/built-ins/Function/prototype/caller-arguments/accessor-properties.js Co-authored-by: Richard Gibson --- .../prototype/caller-arguments/accessor-properties.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js b/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js index b58d2bc562f..fd5c4bf45e5 100644 --- a/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js +++ b/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js @@ -1,9 +1,12 @@ /*--- -description: Function.prototype caller and arguments properties are accessor properties with ThrowTypeError -esid: sec-function.prototype.caller +esid: sec-addrestrictedfunctionproperties +description: > + Function.prototype.arguments and Function.prototype.arguments are both + accessor properties whose set and get functions are both %ThrowTypeError%. info: | - Function instances do not inherit the "caller" and "arguments" accessors - from Function.prototype. The accessors exist only on Function.prototype. + 2. Let _thrower_ be _realm_.[[Intrinsics]].[[%ThrowTypeError%]]. + 3. Perform ! DefinePropertyOrThrow(_F_, *"caller"*, PropertyDescriptor { [[Get]]: _thrower_, [[Set]]: _thrower_, [[Enumerable]]: *false*, [[Configurable]]: *true* }). + 4. Perform ! DefinePropertyOrThrow(_F_, *"arguments"*, PropertyDescriptor { [[Get]]: _thrower_, [[Set]]: _thrower_, [[Enumerable]]: *false*, [[Configurable]]: *true* }). ---*/ const callerDesc = Object.getOwnPropertyDescriptor(Function.prototype, "caller"); From 3db22180896ea890fe956097d468c838ff41e5df Mon Sep 17 00:00:00 2001 From: Justin Dorfman Date: Sun, 19 Jan 2025 16:53:40 -0800 Subject: [PATCH 07/16] Update test/built-ins/Function/prototype/caller-arguments/accessor-properties.js Co-authored-by: Richard Gibson --- .../caller-arguments/accessor-properties.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js b/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js index fd5c4bf45e5..7803fa06d31 100644 --- a/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js +++ b/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js @@ -12,10 +12,9 @@ info: | const callerDesc = Object.getOwnPropertyDescriptor(Function.prototype, "caller"); const argumentsDesc = Object.getOwnPropertyDescriptor(Function.prototype, "arguments"); -assert.sameValue(typeof callerDesc.get, "function"); -assert.sameValue(typeof callerDesc.set, "function"); -assert.sameValue(callerDesc.get, callerDesc.set, "caller getter/setter should be same function"); - -assert.sameValue(typeof argumentsDesc.get, "function"); -assert.sameValue(typeof argumentsDesc.set, "function"); -assert.sameValue(argumentsDesc.get, argumentsDesc.set, "arguments getter/setter should be same function"); +// Other tests at ../{arguments,caller}/prop-desc.js already assert that each +// getter/setter pair use a single function (and when possible, that the +// function is %ThrowTypeError%), so this test only needs to assert equality +// *across* the pairs. +assert.sameValue(callerDesc.get, argumentsDesc.get, + "Function.prototype.arguments and Function.prototype.caller accessor functions should match (%ThrowTypeError%)"); From 616eb0eb696511a98df8c034809f7e4af415a5c8 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 29 Jan 2025 12:25:31 -0500 Subject: [PATCH 08/16] Function.prototype: Remove redundant tests --- .../restricted-property-arguments.js | 27 ------------------ .../prototype/restricted-property-caller.js | 28 ------------------- 2 files changed, 55 deletions(-) delete mode 100644 test/built-ins/Function/prototype/restricted-property-arguments.js delete mode 100644 test/built-ins/Function/prototype/restricted-property-caller.js diff --git a/test/built-ins/Function/prototype/restricted-property-arguments.js b/test/built-ins/Function/prototype/restricted-property-arguments.js deleted file mode 100644 index d1719a5b5af..00000000000 --- a/test/built-ins/Function/prototype/restricted-property-arguments.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2015 Caitlin Potter. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Intrinsic %FunctionPrototype% has poisoned own property "arguments" -includes: [propertyHelper.js] -es6id: 8.2.2 S12, 9.2.7 ----*/ - -var FunctionPrototype = Function.prototype; - -assert.sameValue(FunctionPrototype.hasOwnProperty('arguments'), true, 'The result of %FunctionPrototype%.hasOwnProperty("arguments") is true'); -var descriptor = Object.getOwnPropertyDescriptor(FunctionPrototype, 'arguments'); -assert.sameValue(typeof descriptor.get, 'function', '%FunctionPrototype%.arguments is an accessor property'); -assert.sameValue(typeof descriptor.set, 'function', '%FunctionPrototype%.arguments is an accessor property'); -assert.sameValue(descriptor.get, descriptor.set, '%FunctionPrototype%.arguments getter/setter are both %ThrowTypeError%'); - -assert.throws(TypeError, function() { - return FunctionPrototype.arguments; -}); - -assert.throws(TypeError, function() { - FunctionPrototype.arguments = {}; -}); - -verifyNotEnumerable(FunctionPrototype, 'arguments'); -verifyConfigurable(FunctionPrototype, 'arguments'); diff --git a/test/built-ins/Function/prototype/restricted-property-caller.js b/test/built-ins/Function/prototype/restricted-property-caller.js deleted file mode 100644 index e4c3eb50a6f..00000000000 --- a/test/built-ins/Function/prototype/restricted-property-caller.js +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2015 Caitlin Potter. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Intrinsic %FunctionPrototype% has poisoned own property "caller" -includes: [propertyHelper.js] -es6id: 8.2.2 S12, 9.2.7 ----*/ - -var FunctionPrototype = Function.prototype; - -assert.sameValue(FunctionPrototype.hasOwnProperty('caller'), true, 'The result of %FunctionPrototype%.hasOwnProperty("caller") is true'); - -var descriptor = Object.getOwnPropertyDescriptor(FunctionPrototype, 'caller'); -assert.sameValue(typeof descriptor.get, 'function', '%FunctionPrototype%.caller is an accessor property'); -assert.sameValue(typeof descriptor.set, 'function', '%FunctionPrototype%.caller is an accessor property'); -assert.sameValue(descriptor.get, descriptor.set, '%FunctionPrototype%.caller getter/setter are both %ThrowTypeError%'); - -assert.throws(TypeError, function() { - return FunctionPrototype.caller; -}); - -assert.throws(TypeError, function() { - FunctionPrototype.caller = {}; -}); - -verifyNotEnumerable(FunctionPrototype, 'caller'); -verifyConfigurable(FunctionPrototype, 'caller'); From baac1f028176e39ca92115a900d1adf54587e4cf Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 29 Jan 2025 12:26:37 -0500 Subject: [PATCH 09/16] Function.prototype: Add missing include --- test/built-ins/Function/prototype/arguments/prop-desc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/built-ins/Function/prototype/arguments/prop-desc.js b/test/built-ins/Function/prototype/arguments/prop-desc.js index 9f411825948..193c5b1d2fc 100644 --- a/test/built-ins/Function/prototype/arguments/prop-desc.js +++ b/test/built-ins/Function/prototype/arguments/prop-desc.js @@ -9,7 +9,7 @@ info: | 2. Let _thrower_ be _realm_.[[Intrinsics]].[[%ThrowTypeError%]]. 3. Perform ! DefinePropertyOrThrow(_F_, *"caller"*, PropertyDescriptor { [[Get]]: _thrower_, [[Set]]: _thrower_, [[Enumerable]]: *false*, [[Configurable]]: *true* }). 4. Perform ! DefinePropertyOrThrow(_F_, *"arguments"*, PropertyDescriptor { [[Get]]: _thrower_, [[Set]]: _thrower_, [[Enumerable]]: *false*, [[Configurable]]: *true* }). -includes: [propertyHelper.js] +includes: [propertyHelper.js, wellKnownIntrinsicObjects.js] ---*/ const argumentsDesc = Object.getOwnPropertyDescriptor(Function.prototype, 'arguments'); From e47d4b1cb6646164c32d5b006c73a7cad6040551 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 29 Jan 2025 12:36:19 -0500 Subject: [PATCH 10/16] fixup! e9b49ded97a7a510ef8dbdc87a76b747edfe4718 --- test/built-ins/Function/prototype/arguments/prop-desc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/built-ins/Function/prototype/arguments/prop-desc.js b/test/built-ins/Function/prototype/arguments/prop-desc.js index 193c5b1d2fc..a0124f484f2 100644 --- a/test/built-ins/Function/prototype/arguments/prop-desc.js +++ b/test/built-ins/Function/prototype/arguments/prop-desc.js @@ -39,5 +39,5 @@ assert.throws(TypeError, function() { return Function.prototype.arguments; }); assert.throws(TypeError, function() { - Function.prototype.arguments = {}; -}); + Function.prototype.arguments = arguments; +}); From 405f7cac195ca0b3819a586d902167b9f277e10e Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 29 Jan 2025 12:41:23 -0500 Subject: [PATCH 11/16] Function.prototype.caller: Add coverage --- .../Function/prototype/caller/prop-desc.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/built-ins/Function/prototype/caller/prop-desc.js b/test/built-ins/Function/prototype/caller/prop-desc.js index 3ab9a02780e..ce85e5e2c68 100644 --- a/test/built-ins/Function/prototype/caller/prop-desc.js +++ b/test/built-ins/Function/prototype/caller/prop-desc.js @@ -7,7 +7,7 @@ description: > info: | Function.prototype.caller is an accessor property whose set and get accessor functions are both %ThrowTypeError%. -includes: [propertyHelper.js] +includes: [propertyHelper.js, wellKnownIntrinsicObjects.js] ---*/ const callerDesc = Object.getOwnPropertyDescriptor(Function.prototype, 'caller'); @@ -23,3 +23,19 @@ assert.sameValue(typeof callerDesc.set, "function", "Function.prototype.caller has function setter"); assert.sameValue(callerDesc.get, callerDesc.set, "Caller property getter/setter are the same function"); + +var throwTypeError; +WellKnownIntrinsicObjects.forEach(function(record) { + if (record.name === "%ThrowTypeError%") { + throwTypeError = record.value; + } +}); +if (throwTypeError) { + assert.sameValue(descriptor.set, throwTypeError, "Function.prototype.caller getter is %ThrowTypeError%"); +} +assert.throws(TypeError, function() { + return Function.prototype.caller; +}); +assert.throws(TypeError, function fn() { + Function.prototype.caller = fn; +}); From 5b2c130e632aa5b243db84a0578530a01aba6afe Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 29 Jan 2025 12:44:21 -0500 Subject: [PATCH 12/16] Function.prototype: Remove incorrect test --- .../caller-arguments/cross-realm-behavior.js | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js diff --git a/test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js b/test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js deleted file mode 100644 index 925ea5e4866..00000000000 --- a/test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js +++ /dev/null @@ -1,13 +0,0 @@ -/*--- -description: Function.prototype caller and arguments properties use the same ThrowTypeError across realms -features: [cross-realm] ----*/ - -const otherRealm = $262.createRealm(); -const otherFunctionProto = otherRealm.evaluate('Function.prototype'); - -const mainCallerDesc = Object.getOwnPropertyDescriptor(Function.prototype, "caller"); -const otherCallerDesc = Object.getOwnPropertyDescriptor(otherFunctionProto, "caller"); - -assert.sameValue(mainCallerDesc.get, otherCallerDesc.get, "caller getter should be same across realms"); -assert.sameValue(mainCallerDesc.set, otherCallerDesc.set, "caller setter should be same across realms"); From fa64ddadfeb829d73e407d68d320e28189f8f94f Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 29 Jan 2025 13:11:25 -0500 Subject: [PATCH 13/16] Function.prototype: Remove overreaching tests --- .../caller-arguments/module-context.js | 12 ------------ .../caller-arguments/strict-vs-nonstrict.js | 18 ------------------ 2 files changed, 30 deletions(-) delete mode 100644 test/built-ins/Function/prototype/caller-arguments/module-context.js delete mode 100644 test/built-ins/Function/prototype/caller-arguments/strict-vs-nonstrict.js diff --git a/test/built-ins/Function/prototype/caller-arguments/module-context.js b/test/built-ins/Function/prototype/caller-arguments/module-context.js deleted file mode 100644 index 18944c3c3d3..00000000000 --- a/test/built-ins/Function/prototype/caller-arguments/module-context.js +++ /dev/null @@ -1,12 +0,0 @@ -/*--- -description: Function properties behave consistently in module context -flags: [module] ----*/ - -function normalFunc() {} -function strictFunc() { } - -assert(!Object.hasOwnProperty.call(normalFunc, "caller"), "normal function should not have caller"); -assert(!Object.hasOwnProperty.call(strictFunc, "caller"), "strict function should not have caller"); -assert(!Object.hasOwnProperty.call(normalFunc, "arguments"), "normal function should not have arguments"); -assert(!Object.hasOwnProperty.call(strictFunc, "arguments"), "strict function should not have arguments"); diff --git a/test/built-ins/Function/prototype/caller-arguments/strict-vs-nonstrict.js b/test/built-ins/Function/prototype/caller-arguments/strict-vs-nonstrict.js deleted file mode 100644 index e9c99b400a5..00000000000 --- a/test/built-ins/Function/prototype/caller-arguments/strict-vs-nonstrict.js +++ /dev/null @@ -1,18 +0,0 @@ -/*--- -description: Function properties behavior in strict vs non-strict contexts -flags: [noStrict] ----*/ - -function nonStrictFunc() { - return nonStrictFunc.caller; -} - -function strictFunc() { - return strictFunc.caller; -} - -assert(!Object.hasOwnProperty.call(nonStrictFunc, "caller"), "non-strict function should not have own caller property"); -assert(!Object.hasOwnProperty.call(strictFunc, "caller"), "strict function should not have own caller property"); - -assert.throws(TypeError, () => nonStrictFunc(), "accessing caller should throw"); -assert.throws(TypeError, () => strictFunc(), "accessing caller should throw in strict mode"); From c8dc1f6351c1ce4d38fbc78abe4cd6ec98d47206 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 29 Jan 2025 13:19:16 -0500 Subject: [PATCH 14/16] fixup! 1c42cfc33a6fea01d24aec61229b0d9663041b21 --- .../Function/prototype/caller-arguments/accessor-properties.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js b/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js index 7803fa06d31..4bf1d52f1ef 100644 --- a/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js +++ b/test/built-ins/Function/prototype/caller-arguments/accessor-properties.js @@ -1,3 +1,5 @@ +// Copyright (C) 2024 Justin Dorfman. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-addrestrictedfunctionproperties description: > From c91941bc3e07a42548abea1c6fed3804963f7f63 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 29 Jan 2025 13:23:19 -0500 Subject: [PATCH 15/16] Function.prototype: Fix typos --- test/built-ins/Function/prototype/arguments/prop-desc.js | 2 +- test/built-ins/Function/prototype/caller/prop-desc.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/built-ins/Function/prototype/arguments/prop-desc.js b/test/built-ins/Function/prototype/arguments/prop-desc.js index a0124f484f2..0630c5e9423 100644 --- a/test/built-ins/Function/prototype/arguments/prop-desc.js +++ b/test/built-ins/Function/prototype/arguments/prop-desc.js @@ -33,7 +33,7 @@ WellKnownIntrinsicObjects.forEach(function(record) { } }); if (throwTypeError) { - assert.sameValue(descriptor.set, throwTypeError, "Function.prototype.arguments getter is %ThrowTypeError%"); + assert.sameValue(argumentsDesc.set, throwTypeError, "Function.prototype.arguments getter is %ThrowTypeError%"); } assert.throws(TypeError, function() { return Function.prototype.arguments; diff --git a/test/built-ins/Function/prototype/caller/prop-desc.js b/test/built-ins/Function/prototype/caller/prop-desc.js index ce85e5e2c68..f5a6ca4166a 100644 --- a/test/built-ins/Function/prototype/caller/prop-desc.js +++ b/test/built-ins/Function/prototype/caller/prop-desc.js @@ -31,7 +31,7 @@ WellKnownIntrinsicObjects.forEach(function(record) { } }); if (throwTypeError) { - assert.sameValue(descriptor.set, throwTypeError, "Function.prototype.caller getter is %ThrowTypeError%"); + assert.sameValue(callerDesc.set, throwTypeError, "Function.prototype.caller getter is %ThrowTypeError%"); } assert.throws(TypeError, function() { return Function.prototype.caller; From 09b03e8666d38d340705b305c1e2c2eacee05227 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 29 Jan 2025 13:23:19 -0500 Subject: [PATCH 16/16] Function.prototype: Restore arguments/caller properties before use --- .../Function/prototype/arguments/prop-desc.js | 10 ++++++---- test/built-ins/Function/prototype/caller/prop-desc.js | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/test/built-ins/Function/prototype/arguments/prop-desc.js b/test/built-ins/Function/prototype/arguments/prop-desc.js index 0630c5e9423..5c981dfa903 100644 --- a/test/built-ins/Function/prototype/arguments/prop-desc.js +++ b/test/built-ins/Function/prototype/arguments/prop-desc.js @@ -14,10 +14,12 @@ includes: [propertyHelper.js, wellKnownIntrinsicObjects.js] const argumentsDesc = Object.getOwnPropertyDescriptor(Function.prototype, 'arguments'); -verifyProperty(Function.prototype, "arguments", { - enumerable: false, - configurable: true -}); +verifyProperty( + Function.prototype, + "arguments", + { enumerable: false, configurable: true }, + { restore: true } +); assert.sameValue(typeof argumentsDesc.get, "function", "Function.prototype.arguments has function getter"); diff --git a/test/built-ins/Function/prototype/caller/prop-desc.js b/test/built-ins/Function/prototype/caller/prop-desc.js index f5a6ca4166a..b9b3b82cfd9 100644 --- a/test/built-ins/Function/prototype/caller/prop-desc.js +++ b/test/built-ins/Function/prototype/caller/prop-desc.js @@ -12,10 +12,12 @@ includes: [propertyHelper.js, wellKnownIntrinsicObjects.js] const callerDesc = Object.getOwnPropertyDescriptor(Function.prototype, 'caller'); -verifyProperty(Function.prototype, "caller", { - enumerable: false, - configurable: true -}); +verifyProperty( + Function.prototype, + "caller", + { enumerable: false, configurable: true }, + { restore: true } +); assert.sameValue(typeof callerDesc.get, "function", "Function.prototype.caller has function getter");