-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Function.prototype.caller and arguments properties
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
test/built-ins/Function/prototype/caller-arguments/accessor-properties.js
This file contains 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,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"); |
13 changes: 13 additions & 0 deletions
13
test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js
This file contains 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,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"); |
12 changes: 12 additions & 0 deletions
12
test/built-ins/Function/prototype/caller-arguments/module-context.js
This file contains 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,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"); |
18 changes: 18 additions & 0 deletions
18
test/built-ins/Function/prototype/caller-arguments/strict-vs-nonstrict.js
This file contains 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,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"); |