diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/RegExp/prototype/source | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/RegExp/prototype/source')
14 files changed, 362 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/cross-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/cross-realm.js new file mode 100644 index 0000000000..faf9123f36 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/cross-realm.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.source +description: A TypeError is thrown when the "this" value is an invalid cross-realm Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return "(?:)". + b. Otherwise, throw a TypeError exception. +features: [cross-realm] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; +var other = $262.createRealm().global; +var otherRegExpProto = other.RegExp.prototype; +var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'source').get; + +assert.throws(TypeError, function() { + get.call(otherRegExpProto); +}, 'cross-realm RegExp.prototype'); + +assert.throws(other.TypeError, function() { + otherRegExpGetter.call(RegExp.prototype); +}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/length.js new file mode 100644 index 0000000000..522f81227d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/length.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.source +description: > + get RegExp.prototype.source.length is 0. +info: | + get RegExp.prototype.source + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; + +verifyProperty(get, 'length', { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/name.js new file mode 100644 index 0000000000..501762bb55 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/name.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.source +description: > + get RegExp.prototype.source.name is "get source". +info: | + get RegExp.prototype.source + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + + Unless otherwise specified, the name property of a built-in function object, + if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; + +verifyProperty(get, 'name', { + value: 'get source', + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/prop-desc.js new file mode 100644 index 0000000000..00d66114f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/prop-desc.js @@ -0,0 +1,22 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.source +description: > + RegExp.prototype.source is an accessor property whose set accessor + function is undefined +includes: [propertyHelper.js] +---*/ + +var d = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source'); + +assert.sameValue(typeof d.get, 'function', 'typeof d.get'); +assert.sameValue(d.set, undefined, 'd.set'); + +verifyProperty(RegExp.prototype, 'source', { + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-invalid-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-invalid-obj.js new file mode 100644 index 0000000000..862a2d354e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-invalid-obj.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.source +description: A TypeError is thrown when the "this" value is an invalid Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return "(?:)". + b. Otherwise, throw a TypeError exception. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; + +assert.throws(TypeError, function() { + get.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + get.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + get.call(arguments); +}, 'arguments object'); + +assert.throws(TypeError, function() { + get.call(() => {}); +}, 'function object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-non-obj.js new file mode 100644 index 0000000000..9b0cbec7f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-non-obj.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.source +description: A TypeError is thrown when the "this" value is not an Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; +var symbol = Symbol(); + +assert.throws(TypeError, function() { + get.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + get.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + get.call(3); +}, 'number'); + +assert.throws(TypeError, function() { + get.call('string'); +}, 'string'); + +assert.throws(TypeError, function() { + get.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + get.call(symbol); +}, 'symbol'); + +assert.throws(TypeError, function() { + get.call(4n); +}, 'bigint'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-regexp-prototype.js new file mode 100644 index 0000000000..ca630d5f12 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-regexp-prototype.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.source +description: > + Return "(?:)" when the `this` value is the RegExp.prototype object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return "(?:)". +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; + +assert.sameValue(get.call(RegExp.prototype), '(?:)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/value-empty.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-empty.js new file mode 100644 index 0000000000..50dbaf263d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-empty.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.source +description: > + Return value can be used to create an equivalent RegExp when the + [[OriginalSource]] internal slot is the empty string + + 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern + + [...] the internal procedure that would result from evaluating S as a + Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the + internal procedure given by the constructed object's [[RegExpMatcher]] + internal slot. +info: | + [...] + 5. Let src be R.[[OriginalSource]]. + 6. Let flags be R.[[OriginalFlags]]. + 7. Return EscapeRegExpPattern(src, flags). +---*/ + +var re = eval('/' + new RegExp('').source + '/'); + +assert.sameValue(re.test(''), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/value-line-terminator.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-line-terminator.js new file mode 100644 index 0000000000..bc52096f4d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-line-terminator.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.source +description: > + Return value can be used to create an equivalent RegExp when the + [[OriginalSource]] internal slot contains a LineTerminator +info: | + [...] + 5. Let src be R.[[OriginalSource]]. + 6. Let flags be R.[[OriginalFlags]]. + 7. Return EscapeRegExpPattern(src, flags). + + 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern + + [...] the internal procedure that would result from evaluating S as a + Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the + internal procedure given by the constructed object's [[RegExpMatcher]] + internal slot. +---*/ + +var re = eval('/' + new RegExp('\n').source + '/'); + +assert.sameValue(re.test('\n'), true, 'input: "\\n"'); +assert.sameValue(re.test('_\n_'), true, 'input: "_\\n_"'); +assert.sameValue(re.test('\\n'), false, 'input: "\\\\n"'); +assert.sameValue(re.test('\r'), false, 'input: "\\r"'); +assert.sameValue(re.test('n'), false, 'input: "n"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/value-slash.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-slash.js new file mode 100644 index 0000000000..e0a6f23492 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-slash.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.source +description: Return value can be used to create an equivalent RegExp +info: | + [...] + 5. Let src be R.[[OriginalSource]]. + 6. Let flags be R.[[OriginalFlags]]. + 7. Return EscapeRegExpPattern(src, flags). + + 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern + + [...] The code points / or any LineTerminator occurring in the pattern + shall be escaped in S as necessary to ensure that the String value + formed by concatenating the Strings "/", S, "/", and F can be parsed + (in an appropriate lexical context) as a RegularExpressionLiteral that + behaves identically to the constructed regular expression. +---*/ + +var re = eval('/' + new RegExp('/').source + '/'); + +assert(re.test('/'), 'input: "/"'); +assert(re.test('_/_'), 'input: "_/_"'); +assert(!re.test('\\'), 'input: "\\"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/value-u.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-u.js new file mode 100644 index 0000000000..e7847b7287 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-u.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.source +description: > + Return value can be used to create an equivalent RegExp when the + [[OriginalFlags]] internal slot contains the `u` flag +info: | + [...] + 5. Let src be R.[[OriginalSource]]. + 6. Let flags be R.[[OriginalFlags]]. + 7. Return EscapeRegExpPattern(src, flags). + + 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern + + [...] the internal procedure that would result from evaluating S as a + Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the + internal procedure given by the constructed object's [[RegExpMatcher]] + internal slot. +---*/ + +var re; + +re = eval('/' + /\ud834\udf06/u.source + '/u'); + +assert.sameValue(re.test('\ud834\udf06'), true); +assert.sameValue(re.test('𝌆'), true); + +re = eval('/' + /\u{1d306}/u.source + '/u'); + +assert.sameValue(re.test('\ud834\udf06'), true); +assert.sameValue(re.test('𝌆'), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/value.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/value.js new file mode 100644 index 0000000000..5fdb1df936 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/value.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.source +description: Return value can be used to create an equivalent RegExp +info: | + [...] + 5. Let src be R.[[OriginalSource]]. + 6. Let flags be R.[[OriginalFlags]]. + 7. Return EscapeRegExpPattern(src, flags). + + 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern + + [...] the internal procedure that would result from evaluating S as a + Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the + internal procedure given by the constructed object's [[RegExpMatcher]] + internal slot. +---*/ + +var re = eval('/' + /ab{2,4}c$/.source + '/'); + +assert(re.test('abbc'), 'input: abbc'); +assert(re.test('abbbc'), 'input: abbbc'); +assert(re.test('abbbbc'), 'input: abbbbc'); +assert(re.test('xabbc'), 'input: xabbc'); +assert(re.test('xabbbc'), 'input: xabbbc'); +assert(re.test('xabbbbc'), 'input: xabbbbc'); + +assert.sameValue(re.test('ac'), false, 'input: ac'); +assert.sameValue(re.test('abc'), false, 'input: abc'); +assert.sameValue(re.test('abbcx'), false, 'input: abbcx'); +assert.sameValue(re.test('bbc'), false, 'input: bbc'); +assert.sameValue(re.test('abb'), false, 'input: abb'); +assert.sameValue(re.test('abbbbbc'), false, 'input: abbbbbc'); + +reportCompare(0, 0); |