mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Function.prototype: Add tests "caller" and "arguments" properties (#4355)
Fixes #4340 Fixes #674
This commit is contained in:
parent
e99213a96e
commit
7c37969378
45
test/built-ins/Function/prototype/arguments/prop-desc.js
vendored
Normal file
45
test/built-ins/Function/prototype/arguments/prop-desc.js
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// 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: >
|
||||
Function.prototype.arguments is an accessor property whose set and get
|
||||
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, wellKnownIntrinsicObjects.js]
|
||||
---*/
|
||||
|
||||
const argumentsDesc = Object.getOwnPropertyDescriptor(Function.prototype, 'arguments');
|
||||
|
||||
verifyProperty(
|
||||
Function.prototype,
|
||||
"arguments",
|
||||
{ enumerable: false, configurable: true },
|
||||
{ restore: 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,
|
||||
"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(argumentsDesc.set, throwTypeError, "Function.prototype.arguments getter is %ThrowTypeError%");
|
||||
}
|
||||
assert.throws(TypeError, function() {
|
||||
return Function.prototype.arguments;
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Function.prototype.arguments = arguments;
|
||||
});
|
22
test/built-ins/Function/prototype/caller-arguments/accessor-properties.js
vendored
Normal file
22
test/built-ins/Function/prototype/caller-arguments/accessor-properties.js
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// 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: >
|
||||
Function.prototype.arguments and Function.prototype.arguments are both
|
||||
accessor properties whose set and get 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* }).
|
||||
---*/
|
||||
|
||||
const callerDesc = Object.getOwnPropertyDescriptor(Function.prototype, "caller");
|
||||
const argumentsDesc = Object.getOwnPropertyDescriptor(Function.prototype, "arguments");
|
||||
|
||||
// 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%)");
|
43
test/built-ins/Function/prototype/caller/prop-desc.js
vendored
Normal file
43
test/built-ins/Function/prototype/caller/prop-desc.js
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
// 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, wellKnownIntrinsicObjects.js]
|
||||
---*/
|
||||
|
||||
const callerDesc = Object.getOwnPropertyDescriptor(Function.prototype, 'caller');
|
||||
|
||||
verifyProperty(
|
||||
Function.prototype,
|
||||
"caller",
|
||||
{ enumerable: false, configurable: true },
|
||||
{ restore: 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");
|
||||
|
||||
var throwTypeError;
|
||||
WellKnownIntrinsicObjects.forEach(function(record) {
|
||||
if (record.name === "%ThrowTypeError%") {
|
||||
throwTypeError = record.value;
|
||||
}
|
||||
});
|
||||
if (throwTypeError) {
|
||||
assert.sameValue(callerDesc.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;
|
||||
});
|
@ -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');
|
@ -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');
|
Loading…
x
Reference in New Issue
Block a user