Skip to content
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

Add tests for legacy RegExp features #2650

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ String.prototype.replaceAll
# https://github.com/tc39/proposal-for-in-order
for-in-order

ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
# Legacy RegExp features
# https://github.com/tc39/proposal-regexp-legacy-features
legacy-regexp

# Logical Assignment Operators
# https://github.com/tc39/proposal-logical-assignment
logical-assignment-operators
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2020 ExE Boss. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
description: Property descriptor for RegExp.$1-$9
info: |
RegExp.$1-$9 are accessor properties with attributes
{
[[Enumerable]]: false,
[[Configurable]]: true,
[[Set]]: undefined,
}

get RegExp.$1-$9

1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpParen1-9]]).
includes: [propertyHelper.js]
features: [legacy-regexp]
---*/

for (let i = 1; i <= 9; i++) {
const property = "$" + i;
const desc = Object.getOwnPropertyDescriptor(RegExp, property);

assert.sameValue(desc.set, undefined, property + " setter");
assert.sameValue(typeof desc.get, "function", property + " getter");

verifyProperty(RegExp, property, {
enumerable: false,
configurable: true
});
}
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,42 @@
// Copyright (C) 2020 ExE Boss. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
description: Property descriptor for RegExp.input
info: |
RegExp.input is an accessor property with attributes:
{
[[Enumerable]]: false,
[[Configurable]]: true,
}

get RegExp.input

1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpInput]]).

set RegExp.input = val

1. Return ? SetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpInput]], val).
includes: [propertyHelper.js]
features: [legacy-regexp]
---*/

var desc = Object.getOwnPropertyDescriptor(RegExp, "input");

assert.sameValue(typeof desc.get, "function", "`get` property");
assert.sameValue(typeof desc.set, "function", "`set` property");

verifyProperty(RegExp, "input", {
enumerable: false,
configurable: true
});

desc = Object.getOwnPropertyDescriptor(RegExp, "$_");

assert.sameValue(typeof desc.get, "function", "`get` property");
assert.sameValue(typeof desc.set, "function", "`set` property");

verifyProperty(RegExp, "$_", {
enumerable: false,
configurable: true
});
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'
);
});
});
});
Loading