-
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 cross‑realm and subclass calls of legacy static accessors
- Loading branch information
Showing
18 changed files
with
831 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
test/annexB/built-ins/RegExp/legacy-accessors/index/this-cross-realm-constructor.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,30 @@ | ||
// Copyright (C) 2020 ExE Boss. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: RegExp.$1-$9 throw a TypeError for cross-realm receiver | ||
info: | | ||
get RegExp.$1-$9 | ||
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpParen1-9]]). | ||
GetLegacyRegExpStaticProperty( C, thisValue, internalSlotName ). | ||
1. Assert C is an object that has an internal slot named internalSlotName. | ||
2. If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
3. ... | ||
features: [legacy-regexp,cross-realm,Reflect] | ||
---*/ | ||
|
||
const other = $262.createRealm().global; | ||
|
||
for (let i = 1; i <= 9; i++) { | ||
const property = "$" + i; | ||
assert.throws( | ||
TypeError, | ||
function () { | ||
Reflect.get(RegExp, property, other.RegExp); | ||
}, | ||
"RegExp." + property + " getter throws for cross-realm receiver" | ||
); | ||
} |
60 changes: 60 additions & 0 deletions
60
test/annexB/built-ins/RegExp/legacy-accessors/index/this-not-regexp-constructor.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,60 @@ | ||
// Copyright (C) 2020 ExE Boss. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: RegExp.$1-$9 throw a TypeError for non-%RegExp% receiver | ||
info: | | ||
get RegExp.$1-$9 | ||
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpParen1-9]]). | ||
GetLegacyRegExpStaticProperty( C, thisValue, internalSlotName ). | ||
1. Assert C is an object that has an internal slot named internalSlotName. | ||
2. If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
3. ... | ||
features: [legacy-regexp] | ||
---*/ | ||
|
||
for (let i = 1; i <= 9; i++) { | ||
const property = "$" + i; | ||
const desc = Object.getOwnPropertyDescriptor(RegExp, property); | ||
|
||
// Similar to the other test verifying the descriptor, but split as properties can be removed or changed | ||
assert.sameValue(typeof desc.get, "function", property + " getter"); | ||
|
||
// If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
assert.throws( | ||
TypeError, | ||
function () { | ||
desc.get(); | ||
}, | ||
"RegExp." + property + " getter throws for property descriptor receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
desc.get.call(/ /); | ||
}, | ||
"RegExp." + property + " getter throws for RegExp instance receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
desc.get.call(RegExp.prototype); | ||
}, | ||
"RegExp." + property + " getter throws for %RegExp.prototype% receiver" | ||
); | ||
|
||
[undefined, null, {}, true, false, 0, 1, "string"].forEach(function (value) { | ||
assert.throws( | ||
TypeError, | ||
function () { | ||
desc.get.call(value); | ||
}, | ||
"RegExp." + property + ' getter throws for primitive "' + value + '" receiver' | ||
); | ||
}); | ||
} |
30 changes: 30 additions & 0 deletions
30
test/annexB/built-ins/RegExp/legacy-accessors/index/this-subclass-constructor.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,30 @@ | ||
// Copyright (C) 2020 ExE Boss. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: RegExp.$1-$9 throw a TypeError for subclass receiver | ||
info: | | ||
get RegExp.$1-$9 | ||
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpParen1-9]]). | ||
GetLegacyRegExpStaticProperty( C, thisValue, internalSlotName ). | ||
1. Assert C is an object that has an internal slot named internalSlotName. | ||
2. If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
3. ... | ||
features: [legacy-regexp,class] | ||
---*/ | ||
|
||
class MyRegExp extends RegExp {} | ||
|
||
for (let i = 1; i <= 9; i++) { | ||
const property = "$" + i; | ||
assert.throws( | ||
TypeError, | ||
function () { | ||
MyRegExp[property]; | ||
}, | ||
"RegExp." + property + " getter throws for subclass receiver" | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
test/annexB/built-ins/RegExp/legacy-accessors/input/this-cross-realm-constructor.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,61 @@ | ||
// Copyright (C) 2020 ExE Boss. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: RegExp.input throws a TypeError for cross-realm receiver | ||
info: | | ||
get RegExp.input | ||
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpInput]]). | ||
set RegExp.input = val | ||
1. Return ? SetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpInput]], val). | ||
GetLegacyRegExpStaticProperty( C, thisValue, internalSlotName ). | ||
1. Assert C is an object that has an internal slot named internalSlotName. | ||
2. If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
3. ... | ||
SetLegacyRegExpStaticProperty( C, thisValue, internalSlotName, val ). | ||
1. Assert C is an object that has an internal slot named internalSlotName. | ||
2. If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
3. ... | ||
features: [legacy-regexp,cross-realm,Reflect,Reflect.set] | ||
---*/ | ||
|
||
const other = $262.createRealm().global; | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
Reflect.get(RegExp, "input", other.RegExp); | ||
}, | ||
"RegExp.input getter throws for cross-realm receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
Reflect.set(RegExp, "input", "", other.RegExp); | ||
}, | ||
"RegExp.input setter throws for cross-realm receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
Reflect.get(RegExp, "$_", other.RegExp); | ||
}, | ||
"RegExp.$_ getter throws for cross-realm receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
Reflect.set(RegExp, "$_", "", other.RegExp); | ||
}, | ||
"RegExp.$_ setter throws for cross-realm receiver" | ||
); |
73 changes: 73 additions & 0 deletions
73
test/annexB/built-ins/RegExp/legacy-accessors/input/this-not-regexp-constructor.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,73 @@ | ||
// Copyright (C) 2020 ExE Boss. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: RegExp.input throws a TypeError for non-%RegExp% receiver | ||
info: | | ||
get RegExp.input | ||
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpInput]]). | ||
set RegExp.input = val | ||
1. Return ? SetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpInput]], val). | ||
GetLegacyRegExpStaticProperty( C, thisValue, internalSlotName ). | ||
1. Assert C is an object that has an internal slot named internalSlotName. | ||
2. If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
3. ... | ||
SetLegacyRegExpStaticProperty( C, thisValue, internalSlotName, val ). | ||
1. Assert C is an object that has an internal slot named internalSlotName. | ||
2. If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
3. ... | ||
features: [legacy-regexp] | ||
---*/ | ||
|
||
["input", "$_"].forEach(function (property) { | ||
const desc = Object.getOwnPropertyDescriptor(RegExp, property); | ||
|
||
["get", "set"].forEach(function (accessor) { | ||
const messagePrefix = "RegExp." + property + " " + accessor + "ter"; | ||
|
||
// Similar to the other test verifying the descriptor, but split as properties can be removed or changed | ||
assert.sameValue(typeof desc[accessor], "function", messagePrefix); | ||
|
||
// If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
assert.throws( | ||
TypeError, | ||
function () { | ||
desc[accessor](); | ||
}, | ||
messagePrefix + " throws for property descriptor receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
desc[accessor].call(/ /); | ||
}, | ||
messagePrefix + " throws for RegExp instance receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
desc[accessor].call(RegExp.prototype); | ||
}, | ||
messagePrefix + " throws for %RegExp.prototype% receiver" | ||
); | ||
|
||
[undefined, null, {}, true, false, 0, 1, "string"].forEach(function (value) { | ||
assert.throws( | ||
TypeError, | ||
function () { | ||
desc[accessor].call(value); | ||
}, | ||
messagePrefix + ' throws for primitive "' + value + '" receiver' | ||
); | ||
}); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
test/annexB/built-ins/RegExp/legacy-accessors/input/this-subclass-constructor.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,61 @@ | ||
// Copyright (C) 2020 ExE Boss. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: RegExp.input throws a TypeError for subclass receiver | ||
info: | | ||
get RegExp.input | ||
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpInput]]). | ||
set RegExp.input = val | ||
1. Return ? SetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpInput]], val). | ||
GetLegacyRegExpStaticProperty( C, thisValue, internalSlotName ). | ||
1. Assert C is an object that has an internal slot named internalSlotName. | ||
2. If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
3. ... | ||
SetLegacyRegExpStaticProperty( C, thisValue, internalSlotName, val ). | ||
1. Assert C is an object that has an internal slot named internalSlotName. | ||
2. If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
3. ... | ||
features: [legacy-regexp,class] | ||
---*/ | ||
|
||
class MyRegExp extends RegExp {} | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
MyRegExp.input; | ||
}, | ||
"RegExp.input getter throws for subclass receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
MyRegExp.input = ""; | ||
}, | ||
"RegExp.input setter throws for subclass receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
MyRegExp.$_; | ||
}, | ||
"RegExp.$_ getter throws for subclass receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
MyRegExp.$_ = ""; | ||
}, | ||
"RegExp.$_ setter throws for subclass receiver" | ||
); |
35 changes: 35 additions & 0 deletions
35
test/annexB/built-ins/RegExp/legacy-accessors/lastMatch/this-cross-realm-constructor.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,35 @@ | ||
// Copyright (C) 2020 ExE Boss. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: RegExp.lastMatch throws a TypeError for cross-realm receiver | ||
info: | | ||
get RegExp.lastMatch | ||
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLastMatch]]). | ||
GetLegacyRegExpStaticProperty( C, thisValue, internalSlotName ). | ||
1. Assert C is an object that has an internal slot named internalSlotName. | ||
2. If SameValue(C, thisValue) is false, throw a TypeError exception. | ||
3. ... | ||
features: [legacy-regexp,cross-realm,Reflect] | ||
---*/ | ||
|
||
const other = $262.createRealm().global; | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
Reflect.get(RegExp, "lastMatch", other.RegExp); | ||
}, | ||
"RegExp.lastMatch getter throws for cross-realm receiver" | ||
); | ||
|
||
assert.throws( | ||
TypeError, | ||
function () { | ||
Reflect.get(RegExp, "$&", other.RegExp); | ||
}, | ||
"RegExp.$& getter throws for cross-realm receiver" | ||
); |
Oops, something went wrong.