Skip to content

Commit

Permalink
Add tests for cross‑realm and subclass calls of legacy static accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss authored and rwaldron committed Sep 10, 2020
1 parent 391f799 commit 9c754bc
Show file tree
Hide file tree
Showing 18 changed files with 831 additions and 0 deletions.
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"
);
}
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'
);
});
}
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"
);
}
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"
);
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'
);
});
});
});
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"
);
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"
);
Loading

0 comments on commit 9c754bc

Please sign in to comment.