-
Notifications
You must be signed in to change notification settings - Fork 494
Add tests for Function.prototype.caller and arguments properties #4355
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8143ae6
Add tests for Function.prototype.caller and arguments properties
jdorfman c3f82b5
Add tests for Function.prototype.caller and arguments properties
jdorfman 5790fd4
Update test/built-ins/Function/prototype/arguments/prop-desc.js
jdorfman 6964e50
Update test/built-ins/Function/prototype/arguments/prop-desc.js
jdorfman 52c319a
Update test/built-ins/Function/prototype/arguments/prop-desc.js
jdorfman 947ca82
Update test/built-ins/Function/prototype/caller-arguments/accessor-pr…
jdorfman 3db2218
Update test/built-ins/Function/prototype/caller-arguments/accessor-pr…
jdorfman 616eb0e
Function.prototype: Remove redundant tests
gibson042 baac1f0
Function.prototype: Add missing include
gibson042 e47d4b1
fixup! e9b49ded97a7a510ef8dbdc87a76b747edfe4718
gibson042 405f7ca
Function.prototype.caller: Add coverage
gibson042 5b2c130
Function.prototype: Remove incorrect test
gibson042 fa64dda
Function.prototype: Remove overreaching tests
gibson042 c8dc1f6
fixup! 1c42cfc33a6fea01d24aec61229b0d9663041b21
gibson042 c91941b
Function.prototype: Fix typos
gibson042 09b03e8
Function.prototype: Restore arguments/caller properties before use
gibson042 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 22 additions & 0 deletions
22
test/built-ins/Function/prototype/caller-arguments/accessor-properties.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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%)"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); |
27 changes: 0 additions & 27 deletions
27
test/built-ins/Function/prototype/restricted-property-arguments.js
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
test/built-ins/Function/prototype/restricted-property-caller.js
This file was deleted.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.