diff options
Diffstat (limited to 'js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch')
6 files changed, 180 insertions, 0 deletions
diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/prop-desc.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/prop-desc.js new file mode 100644 index 0000000000..62854362c5 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/prop-desc.js @@ -0,0 +1,42 @@ +// |reftest| skip -- legacy-regexp is not supported +// 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.lastMatch +info: | + RegExp.lastMatch is an accessor property with attributes: + { + [[Enumerable]]: false, + [[Configurable]]: true, + [[Set]]: undefined, + } + + get RegExp.lastMatch + + 1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLastMatch]]). +includes: [propertyHelper.js] +features: [legacy-regexp] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp, "lastMatch"); + +assert.sameValue(desc.set, undefined, "`set` property"); +assert.sameValue(typeof desc.get, "function", "`get` property"); + +verifyProperty(RegExp, "lastMatch", { + enumerable: false, + configurable: true +}); + +desc = Object.getOwnPropertyDescriptor(RegExp, "$&"); + +assert.sameValue(desc.set, undefined, "`set` property"); +assert.sameValue(typeof desc.get, "function", "`get` property"); + +verifyProperty(RegExp, "$&", { + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/this-cross-realm-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/this-cross-realm-constructor.js new file mode 100644 index 0000000000..c9b7c97abc --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/this-cross-realm-constructor.js @@ -0,0 +1,38 @@ +// |reftest| skip -- legacy-regexp is not supported +// 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" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/this-not-regexp-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/this-not-regexp-constructor.js new file mode 100644 index 0000000000..35ad7711f6 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/this-not-regexp-constructor.js @@ -0,0 +1,62 @@ +// |reftest| skip -- legacy-regexp is not supported +// 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' + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/this-subclass-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/this-subclass-constructor.js new file mode 100644 index 0000000000..510697fd06 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastMatch/this-subclass-constructor.js @@ -0,0 +1,38 @@ +// |reftest| skip -- legacy-regexp is not supported +// 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" +); + +reportCompare(0, 0); |