1
0
mirror of https://github.com/tc39/test262.git synced 2025-04-08 19:35:28 +02:00

Add tests for cross‑realm and subclass calls of legacy static accessors

This commit is contained in:
ExE Boss 2020-06-07 19:30:00 +02:00 committed by Rick Waldron
parent 391f799152
commit 9c754bc3ce
18 changed files with 831 additions and 0 deletions

@ -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"
);
}

@ -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'
);
});
}

@ -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"
);
}

@ -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"
);

@ -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'
);
});
});
});

@ -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"
);

@ -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"
);

@ -0,0 +1,59 @@
// 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 non-%RegExp% 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]
---*/
["lastMatch", "$&"].forEach(function (property) {
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'
);
});
});

@ -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 subclass 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,class]
---*/
class MyRegExp extends RegExp {}
assert.throws(
TypeError,
function () {
MyRegExp.lastMatch;
},
"RegExp.lastMatch getter throws for subclass receiver"
);
assert.throws(
TypeError,
function () {
MyRegExp["$&"];
},
"RegExp.$& getter throws for subclass receiver"
);

@ -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.lastParen throws a TypeError for cross-realm receiver
info: |
get RegExp.lastParen
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLastParen]]).
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, "lastParen", other.RegExp);
},
"RegExp.lastParen getter throws for cross-realm receiver"
);
assert.throws(
TypeError,
function () {
Reflect.get(RegExp, "$+", other.RegExp);
},
"RegExp.$+ getter throws for cross-realm receiver"
);

@ -0,0 +1,59 @@
// 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.lastParen throws a TypeError for non-%RegExp% receiver
info: |
get RegExp.lastParen
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLastParen]]).
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]
---*/
["lastParen", "$+"].forEach(function (property) {
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'
);
});
});

@ -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.lastParen throws a TypeError for subclass receiver
info: |
get RegExp.lastParen
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLastParen]]).
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 {}
assert.throws(
TypeError,
function () {
MyRegExp.lastParen;
},
"RegExp.lastParen getter throws for subclass receiver"
);
assert.throws(
TypeError,
function () {
MyRegExp["$+"];
},
"RegExp.$+ getter throws for subclass receiver"
);

@ -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.leftContext throws a TypeError for cross-realm receiver
info: |
get RegExp.leftContext
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLeftContext]]).
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, "leftContext", other.RegExp);
},
"RegExp.leftContext getter throws for cross-realm receiver"
);
assert.throws(
TypeError,
function () {
Reflect.get(RegExp, "$`", other.RegExp);
},
"RegExp.$` getter throws for cross-realm receiver"
);

@ -0,0 +1,59 @@
// 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.leftContext throws a TypeError for non-%RegExp% receiver
info: |
get RegExp.leftContext
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLeftContext]]).
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]
---*/
["leftContext", "$`"].forEach(function (property) {
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'
);
});
});

@ -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.leftContext throws a TypeError for subclass receiver
info: |
get RegExp.leftContext
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLeftContext]]).
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 {}
assert.throws(
TypeError,
function () {
MyRegExp.leftContext;
},
"RegExp.leftContext getter throws for subclass receiver"
);
assert.throws(
TypeError,
function () {
MyRegExp["$`"];
},
"RegExp.$` getter throws for subclass receiver"
);

@ -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.rightContext throws a TypeError for cross-realm receiver
info: |
get RegExp.rightContext
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpRightContext]]).
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, "rightContext", other.RegExp);
},
"RegExp.rightContext getter throws for cross-realm receiver"
);
assert.throws(
TypeError,
function () {
Reflect.get(RegExp, "$'", other.RegExp);
},
"RegExp.$' getter throws for cross-realm receiver"
);

@ -0,0 +1,59 @@
// 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.rightContext throws a TypeError for non-%RegExp% receiver
info: |
get RegExp.rightContext
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpRightContext]]).
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]
---*/
["rightContext", "$'"].forEach(function (property) {
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'
);
});
});

@ -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.rightContext throws a TypeError for subclass receiver
info: |
get RegExp.rightContext
1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpRightContext]]).
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 {}
assert.throws(
TypeError,
function () {
MyRegExp.rightContext;
},
"RegExp.rightContext getter throws for subclass receiver"
);
assert.throws(
TypeError,
function () {
MyRegExp["$'"];
},
"RegExp.$' getter throws for subclass receiver"
);