diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/annexB/built-ins | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/annexB/built-ins')
343 files changed, 8313 insertions, 0 deletions
diff --git a/js/src/tests/test262/annexB/built-ins/Array/browser.js b/js/src/tests/test262/annexB/built-ins/Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Array/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/Array/from/browser.js b/js/src/tests/test262/annexB/built-ins/Array/from/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Array/from/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/Array/from/iterator-method-emulates-undefined.js b/js/src/tests/test262/annexB/built-ins/Array/from/iterator-method-emulates-undefined.js new file mode 100644 index 0000000000..5ee69df755 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Array/from/iterator-method-emulates-undefined.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.from +description: > + [[IsHTMLDDA]] object as @@iterator method gets called. +info: | + Array.from ( items [ , mapfn [ , thisArg ] ] ) + + [...] + 4. Let usingIterator be ? GetMethod(items, @@iterator). + 5. If usingIterator is not undefined, then + [...] + c. Let iteratorRecord be ? GetIterator(items, sync, usingIterator). + + GetIterator ( obj [ , hint [ , method ] ] ) + + [...] + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. +features: [Symbol.iterator, IsHTMLDDA] +---*/ + +var items = {}; +items[Symbol.iterator] = $262.IsHTMLDDA; + +assert.throws(TypeError, function() { + Array.from(items); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Array/from/shell.js b/js/src/tests/test262/annexB/built-ins/Array/from/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Array/from/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/Array/shell.js b/js/src/tests/test262/annexB/built-ins/Array/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Array/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/Date/browser.js b/js/src/tests/test262/annexB/built-ins/Date/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/browser.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/B.2.4.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/B.2.4.js new file mode 100644 index 0000000000..4e6091dd06 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/B.2.4.js @@ -0,0 +1,18 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: B.2.4 +description: > + Object.getOwnPropertyDescriptor returns data desc for functions on + built-ins (Date.prototype.getYear) +includes: [propertyHelper.js] +---*/ + +verifyProperty(Date.prototype, "getYear", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/browser.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/length.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/length.js new file mode 100644 index 0000000000..72bb65b0e7 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.4.1 +description: > + Date.prototype.getYear.length is 0. +info: | + Date.prototype.getYear ( ) + + 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] +---*/ + +verifyProperty(Date.prototype.getYear, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/name.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/name.js new file mode 100644 index 0000000000..6a3db43a9f --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.4.1 +description: > + Date.prototype.getYear.name is "getYear". +info: | + Date.prototype.getYear ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(Date.prototype.getYear, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "getYear" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/nan.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/nan.js new file mode 100644 index 0000000000..121c54fcd5 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/nan.js @@ -0,0 +1,17 @@ +// 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-date.prototype.getyear +es6id: B.2.4.1 +es5id: B.2.4 +description: NaN time value +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +var date = new Date({}); + +assert.sameValue(date.getYear(), NaN); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/not-a-constructor.js new file mode 100644 index 0000000000..a3936a335e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Date.prototype.getYear does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Date.prototype.getYear), + false, + 'isConstructor(Date.prototype.getYear) must return false' +); + +assert.throws(TypeError, () => { + let date = new Date(Date.now()); new date.getYear(); +}, '`let date = new Date(Date.now()); new date.getYear()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/return-value.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/return-value.js new file mode 100644 index 0000000000..1df44ae303 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/return-value.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-date.prototype.getyear +es6id: B.2.4.1 +es5id: B.2.4 +description: > + Return value for objects with numeric value in [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return YearFromTime(LocalTime(t)) - 1900. +---*/ + +assert.sameValue(new Date(1899, 0).getYear(), -1, '1899: first millisecond'); +assert.sameValue( + new Date(1899, 11, 31, 23, 59, 59, 999).getYear(), + -1, + '1899: final millisecond' +); + +assert.sameValue(new Date(1900, 0).getYear(), 0, '1900: first millisecond'); +assert.sameValue( + new Date(1900, 11, 31, 23, 59, 59, 999).getYear(), + 0, + '1900: final millisecond' +); + +assert.sameValue(new Date(1970, 0).getYear(), 70, '1970: first millisecond'); +assert.sameValue( + new Date(1970, 11, 31, 23, 59, 59, 999).getYear(), + 70, + '1970: final millisecond' +); + +assert.sameValue(new Date(2000, 0).getYear(), 100, '2000: first millisecond'); +assert.sameValue( + new Date(2000, 11, 31, 23, 59, 59, 999).getYear(), + 100, + '2000: final millisecond' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/shell.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/this-not-date.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/this-not-date.js new file mode 100644 index 0000000000..cb6888f80a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/getYear/this-not-date.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-date.prototype.getyear +es6id: B.2.4.1 +es5id: B.2.4 +description: Behavior when `this` value has no [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). +---*/ + +var getYear = Date.prototype.getYear; + +assert.sameValue(typeof getYear, 'function'); + +assert.throws(TypeError, function() { + getYear.call({}); +}, 'object'); + +assert.throws(TypeError, function() { + getYear.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getYear.call(null); +}, 'null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/B.2.5.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/B.2.5.js new file mode 100644 index 0000000000..91eb6f7451 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/B.2.5.js @@ -0,0 +1,18 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: B.2.5 +description: > + Object.getOwnPropertyDescriptor returns data desc for functions on + built-ins (Date.prototype.setYear) +includes: [propertyHelper.js] +---*/ + +verifyProperty(Date.prototype, "setYear", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/browser.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/length.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/length.js new file mode 100644 index 0000000000..946c22d3d1 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.4.2 +description: > + Date.prototype.setYear.length is 1. +info: | + Date.prototype.setYear ( ) + + 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] +---*/ + +verifyProperty(Date.prototype.setYear, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/name.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/name.js new file mode 100644 index 0000000000..f35e39d327 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.4.2 +description: > + Date.prototype.setYear.name is "setYear". +info: | + Date.prototype.setYear ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(Date.prototype.setYear, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "setYear" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/not-a-constructor.js new file mode 100644 index 0000000000..906214fde4 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Date.prototype.setYear does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Date.prototype.setYear), + false, + 'isConstructor(Date.prototype.setYear) must return false' +); + +assert.throws(TypeError, () => { + let date = new Date(Date.now()); new date.setYear(); +}, '`let date = new Date(Date.now()); new date.setYear()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/shell.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/this-not-date.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/this-not-date.js new file mode 100644 index 0000000000..15614f98e3 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/this-not-date.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-date.prototype.setyear +es6id: B.2.4.2 +es5id: B.2.5 +description: Behavior when "this" value has no [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). +---*/ + +var setYear = Date.prototype.setYear; + +assert.sameValue(typeof setYear, 'function'); + +assert.throws(TypeError, function() { + setYear.call({}, 1); +}, 'object'); + +assert.throws(TypeError, function() { + setYear.call(undefined, 1); +}, 'undefined'); + +assert.throws(TypeError, function() { + setYear.call(null, 1); +}, 'null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/this-time-nan.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/this-time-nan.js new file mode 100644 index 0000000000..fb99ad3765 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/this-time-nan.js @@ -0,0 +1,20 @@ +// 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-date.prototype.setyear +es6id: B.2.4.2 +es5id: B.2.5 +description: > + Behavior when the [[DateValue]] internal slot of "this" value is NaN +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). +---*/ + +var date = new Date({}); +var expected = new Date(1971, 0).valueOf(); + +assert.sameValue(date.setYear(71), expected, 'method return value'); +assert.sameValue(date.valueOf(), expected, '[[DateValue]] internal slot'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/this-time-valid.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/this-time-valid.js new file mode 100644 index 0000000000..35ccee0fbf --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/this-time-valid.js @@ -0,0 +1,21 @@ +// 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-date.prototype.setyear +es6id: B.2.4.2 +es5id: B.2.5 +description: > + Behavior when the [[DateValue]] internal slot of "this" value is an integer + value +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). +---*/ + +var date = new Date(1970, 1, 2, 3, 4, 5); +var expected = new Date(1971, 1, 2, 3, 4, 5).valueOf(); + +assert.sameValue(date.setYear(71), expected, 'method return value'); +assert.sameValue(date.valueOf(), expected, '[[DateValue]] internal slot'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/time-clip.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/time-clip.js new file mode 100644 index 0000000000..f296e204ab --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/time-clip.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-date.prototype.setyear +es6id: B.2.4.2 +es5id: B.2.5 +description: Clipping of new time value +info: | + [...] + 9. Set the [[DateValue]] internal slot of this Date object to + TimeClip(date). + 10. Return the value of the [[DateValue]] internal slot of this Date + object. +---*/ + +var date; + +date = new Date(1970, 8, 10, 0, 0, 0, 0); + +assert.notSameValue( + date.setYear(275760), NaN, 'method return value (valid date)' +); +assert.notSameValue( + date.valueOf(), NaN, '[[DateValue]] internal slot (valid date)' +); + +date = new Date(1970, 8, 14, 0, 0, 0, 0); + +assert.sameValue( + date.setYear(275760), NaN, 'method return value (invalid date)' +); +assert.sameValue( + date.valueOf(), NaN, '[[DateValue]] internal slot (invalid date)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-nan.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-nan.js new file mode 100644 index 0000000000..9a14f8f777 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-nan.js @@ -0,0 +1,38 @@ +// 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-date.prototype.setyear +es6id: B.2.4.2 +es5id: B.2.5 +description: Behavior when year value coerces to NaN +info: | + [...] + 3. Let y be ? ToNumber(year). + 4. If y is NaN, set the [[DateValue]] internal slot of this Date object to + NaN and return NaN. +features: [Symbol] +---*/ + +var date; + +date = new Date(); +assert.sameValue(date.setYear(), NaN, 'return value (no argument)'); +assert.sameValue( + date.valueOf(), NaN, '[[DateValue]] internal slot (no argument)' +); + +date = new Date(); +assert.sameValue(date.setYear(NaN), NaN, 'return value (literal NaN)'); +assert.sameValue( + date.valueOf(), NaN, '[[DateValue]] internal slot (literal NaN)' +); + +date = new Date(); +assert.sameValue( + date.setYear('not a number'), NaN, 'return value (NaN from ToNumber)' +); +assert.sameValue( + date.valueOf(), NaN, '[[DateValue]] internal slot (NaN from ToNumber)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-number-absolute.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-number-absolute.js new file mode 100644 index 0000000000..61cc1d91a3 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-number-absolute.js @@ -0,0 +1,44 @@ +// 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-date.prototype.setyear +es6id: B.2.4.2 +es5id: B.2.5 +description: > + Behavior when the integer representation of the specified `year` is not + relative to 1900 +info: | + [...] + 5. If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, let yyyy be ToInteger(y) + + 1900. + 6. Else, let yyyy be y. + [...] +---*/ + +var date; + +date = new Date(1970, 0); +date.setYear(-1); +assert.sameValue(date.getFullYear(), -1); + +date = new Date(1970, 0); +date.setYear(100); +assert.sameValue(date.getFullYear(), 100); + +date = new Date(1970, 0); +date.setYear(1899); +assert.sameValue(date.getFullYear(), 1899); + +date = new Date(1970, 0); +date.setYear(1900); +assert.sameValue(date.getFullYear(), 1900); + +date = new Date(1970, 0); +date.setYear(1999); +assert.sameValue(date.getFullYear(), 1999); + +date = new Date(1970, 0); +date.setYear(2000); +assert.sameValue(date.getFullYear(), 2000); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-number-relative.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-number-relative.js new file mode 100644 index 0000000000..632acfa129 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-number-relative.js @@ -0,0 +1,47 @@ +// 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-date.prototype.setyear +es6id: B.2.4.2 +es5id: B.2.5 +description: > + Behavior when the integer representation of the specified `year` is + relative to 1900 +info: | + [...] + 5. If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, let yyyy be ToInteger(y) + + 1900. + [...] +---*/ + +var date; + +date = new Date(1970, 0); +date.setYear(-0.9999999); +assert.sameValue(date.getFullYear(), 1900, 'y = -0.999999'); + +date = new Date(1970, 0); +date.setYear(-0); +assert.sameValue(date.getFullYear(), 1900, 'y = -0'); + +date = new Date(1970, 0); +date.setYear(0); +assert.sameValue(date.getFullYear(), 1900, 'y = 0'); + +date = new Date(1970, 0); +date.setYear(50); +assert.sameValue(date.getFullYear(), 1950, 'y = 50'); + +date = new Date(1970, 0); +date.setYear(50.999999); +assert.sameValue(date.getFullYear(), 1950, 'y = 50.999999'); + +date = new Date(1970, 0); +date.setYear(99); +assert.sameValue(date.getFullYear(), 1999, 'y = 99'); + +date = new Date(1970, 0); +date.setYear(99.999999); +assert.sameValue(date.getFullYear(), 1999, 'y = 99.999999'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-to-number-err.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-to-number-err.js new file mode 100644 index 0000000000..d7e318f571 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/setYear/year-to-number-err.js @@ -0,0 +1,31 @@ +// 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-date.prototype.setyear +es6id: B.2.4.2 +es5id: B.2.5 +description: > + Behavior when calling ToNumber on year value returns an abrupt completion +info: | + [...] + 3. Let y be ? ToNumber(year). +features: [Symbol] +---*/ + +var date = new Date(); +var symbol = Symbol(''); +var year = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + date.setYear(year); +}); + +assert.throws(TypeError, function() { + date.setYear(symbol); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/shell.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/browser.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/not-a-constructor.js new file mode 100644 index 0000000000..bb6c5f412f --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Date.prototype.toGMTString does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Date.prototype.toGMTString), + false, + 'isConstructor(Date.prototype.toGMTString) must return false' +); + +assert.throws(TypeError, () => { + let date = new Date(Date.now()); new date.toGMTString(); +}, '`let date = new Date(Date.now()); new date.toGMTString()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/prop-desc.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/prop-desc.js new file mode 100644 index 0000000000..c7f55f91a1 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/prop-desc.js @@ -0,0 +1,19 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: B.2.6 +description: > + Object.getOwnPropertyDescriptor returns data desc for functions on + built-ins (Date.prototype.toGMTString) +includes: [propertyHelper.js] + +---*/ + +verifyProperty(Date.prototype, "toGMTString", { + enumerable: false, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/shell.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/value.js b/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/value.js new file mode 100644 index 0000000000..27e9f98edd --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/prototype/toGMTString/value.js @@ -0,0 +1,16 @@ +// 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-date.prototype.togmtstring +es6id: B.2.4.3 +es5id: B.2.6 +description: Value of `Date.prototype.toGMTString` +info: | + The function object that is the initial value of Date.prototype.toGMTString + is the same function object that is the initial value of + Date.prototype.toUTCString. +---*/ + +assert.sameValue(Date.prototype.toGMTString, Date.prototype.toUTCString); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Date/shell.js b/js/src/tests/test262/annexB/built-ins/Date/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Date/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/Function/browser.js b/js/src/tests/test262/annexB/built-ins/Function/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Function/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-close-comment-body.js b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-close-comment-body.js new file mode 100644 index 0000000000..49a409b8a6 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-close-comment-body.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-createdynamicfunction +description: > + Create a Function with the function body being a html close comment. +info: | + 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction(constructor, newTarget, kind, args) + ... + 7. If kind is "normal", then + a. Let goal be the grammar symbol FunctionBody[~Yield, ~Await]. + ... + 11. Let body be the result of parsing bodyText, interpreted as UTF-16 encoded Unicode text + as described in 6.1.4, using goal as the goal symbol. Throw a SyntaxError exception if + the parse fails. + ... +---*/ + +Function("\n-->"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-close-comment-params.js b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-close-comment-params.js new file mode 100644 index 0000000000..c97834d6f4 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-close-comment-params.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-createdynamicfunction +description: > + Create a Function with the function parameters being a html close comment. +info: | + 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction(constructor, newTarget, kind, args) + ... + 7. If kind is "normal", then + ... + b. Let parameterGoal be the grammar symbol FormalParameters[~Yield, ~Await]. + ... + 10. Let parameters be the result of parsing P, interpreted as UTF-16 encoded Unicode text + as described in 6.1.4, using parameterGoal as the goal symbol. Throw a SyntaxError + exception if the parse fails. + ... +---*/ + +Function("\n-->", ""); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-open-comment-body.js b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-open-comment-body.js new file mode 100644 index 0000000000..3dc973128b --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-open-comment-body.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-createdynamicfunction +description: > + Create a Function with the function body being a html open comment. +info: | + 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction(constructor, newTarget, kind, args) + ... + 7. If kind is "normal", then + a. Let goal be the grammar symbol FunctionBody[~Yield, ~Await]. + ... + 11. Let body be the result of parsing bodyText, interpreted as UTF-16 encoded Unicode text + as described in 6.1.4, using goal as the goal symbol. Throw a SyntaxError exception if + the parse fails. + ... +---*/ + +Function("<!--"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-open-comment-params.js b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-open-comment-params.js new file mode 100644 index 0000000000..ea22bf96b6 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-html-open-comment-params.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-createdynamicfunction +description: > + Create a Function with the function parameters being a html open comment. +info: | + 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction(constructor, newTarget, kind, args) + ... + 7. If kind is "normal", then + ... + b. Let parameterGoal be the grammar symbol FormalParameters[~Yield, ~Await]. + ... + 10. Let parameters be the result of parsing P, interpreted as UTF-16 encoded Unicode text + as described in 6.1.4, using parameterGoal as the goal symbol. Throw a SyntaxError + exception if the parse fails. + ... +---*/ + +Function("<!--", ""); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-body.js b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-body.js new file mode 100644 index 0000000000..36e6a5bb25 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-body.js @@ -0,0 +1,24 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-createdynamicfunction +description: > + Function body is wrapped with new lines before being parsed +info: | + The HTMLCloseComment requires a preceding line terminator. + + Runtime Semantics: CreateDynamicFunction(constructor, newTarget, kind, args) + ... + Set bodyText to ? ToString(bodyText). + Let parameters be the result of parsing P, interpreted as UTF-16 encoded Unicode text as + described in 6.1.4, using parameterGoal as the goal symbol. Throw a SyntaxError exception if the + parse fails. + Let body be the result of parsing bodyText, interpreted as UTF-16 encoded Unicode text as + described in 6.1.4, using goal as the goal symbol. Throw a SyntaxError exception if the parse + fails. +---*/ + +Function("-->"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-params.js b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-params.js new file mode 100644 index 0000000000..73fea90809 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-params.js @@ -0,0 +1,27 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-createdynamicfunction +description: > + Function parses the parameters text before forming the sourceText with the proper line feed. +info: | + The HTMLCloseComment requires a preceding line terminator. + + Runtime Semantics: CreateDynamicFunction(constructor, newTarget, kind, args) + ... + 16. Set bodyText to ? ToString(bodyText). + 17. Let parameters be the result of parsing P, interpreted as UTF-16 encoded Unicode text as + described in 6.1.4, using parameterGoal as the goal symbol. Throw a SyntaxError exception if the + parse fails. + 18. Let body be the result of parsing bodyText, interpreted as UTF-16 encoded Unicode text as + described in 6.1.4, using goal as the goal symbol. Throw a SyntaxError exception if the parse + fails. + ... + 41. Let sourceText be the string-concatenation of prefix, " anonymous(", P, 0x000A (LINE FEED), + ") {", 0x000A (LINE FEED), bodyText, 0x000A (LINE FEED), and "}". +---*/ + +assert.throws(SyntaxError, () => Function("-->", "")); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Function/shell.js b/js/src/tests/test262/annexB/built-ins/Function/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Function/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/Object/browser.js b/js/src/tests/test262/annexB/built-ins/Object/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Object/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/Object/is/browser.js b/js/src/tests/test262/annexB/built-ins/Object/is/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Object/is/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/Object/is/emulates-undefined.js b/js/src/tests/test262/annexB/built-ins/Object/is/emulates-undefined.js new file mode 100644 index 0000000000..c6b4bb8417 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Object/is/emulates-undefined.js @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-object.is +description: > + SameValue abstract op doesn't special-case [[IsHTMLDDA]] objects. +info: | + Object.is ( value1, value2 ) + + 1. Return SameValue(value1, value2). + + SameValue ( x, y ) + + 1. If Type(x) is different from Type(y), return false. +features: [IsHTMLDDA] +---*/ + +var IsHTMLDDA = $262.IsHTMLDDA; + +assert.sameValue(Object.is(IsHTMLDDA, undefined), false, "SameValue with `undefined`"); +assert.sameValue(Object.is(undefined, IsHTMLDDA), false, "SameValue with `undefined`"); + +assert.sameValue(Object.is(IsHTMLDDA, null), false, "SameValue with `null`"); +assert.sameValue(Object.is(null, IsHTMLDDA), false, "SameValue with `null`"); + +assert(Object.is(IsHTMLDDA, IsHTMLDDA)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/Object/is/shell.js b/js/src/tests/test262/annexB/built-ins/Object/is/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Object/is/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/Object/shell.js b/js/src/tests/test262/annexB/built-ins/Object/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/Object/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-control-escape-russian-letter.js b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-control-escape-russian-letter.js new file mode 100644 index 0000000000..b7caeb42a5 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-control-escape-russian-letter.js @@ -0,0 +1,55 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: "CharacterEscape :: c ControlLetter" +es5id: 15.10.2.10_A2.1_T3 +es6id: B.1.4 +description: > + "ControlLetter :: RUSSIAN ALPHABET is incorrect" + Instead, fall back to semantics to match literal "\\c" +features: [generators] +---*/ + +function* invalidControls() { + // Check upper case Cyrillic + for (var alpha = 0x0410; alpha <= 0x042F; alpha++) { + yield String.fromCharCode(alpha); + } + + // Check lower case Cyrillic + for (alpha = 0x0430; alpha <= 0x044F; alpha++) { + yield String.fromCharCode(alpha); + } + + // Check ASCII characters which are not in the extended range or syntax + // characters + for (alpha = 0x00; alpha <= 0x7F; alpha++) { + let letter = String.fromCharCode(alpha); + if (!letter.match(/[0-9A-Za-z_\$(|)\[\]\/\\^]/)) { + yield letter; + } + } + + // Check for end of string + yield ""; +} + +for (let letter of invalidControls()) { + var source = "\\c" + letter; + var re = new RegExp(source); + + if (letter.length > 0) { + var char = letter.charCodeAt(0); + var str = String.fromCharCode(char % 32); + var arr = re.exec(str); + assert.sameValue(arr, null, `Character ${letter} unreasonably wrapped around as a control character`); + } + arr = re.exec(source.substring(1)); + assert.sameValue(arr, null, `invalid \\c escape matched c rather than \\c when followed by ${letter}`); + + arr = re.exec(source); + assert.notSameValue(arr, null, `invalid \\c escape failed to match \\c when followed by ${letter}`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-decimal-escape-class-range.js b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-decimal-escape-class-range.js new file mode 100644 index 0000000000..4d49de4ea4 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-decimal-escape-class-range.js @@ -0,0 +1,31 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The production CharacterClass :: [ [lookahead \notin {^}] ClassRanges ] + evaluates by evaluating ClassRanges to obtain a CharSet and returning + that CharSet and the boolean false +es5id: 15.10.2.13_A1_T16 +es6id: B.1.4 +description: > + Execute /[\d][\12-\14]{1,}[^\d]/.exec("line1\n\n\n\n\nline2") and + check results +---*/ + +var __executed = /[\d][\12-\14]{1,}[^\d]/.exec("line1\n\n\n\n\nline2"); + +var __expected = ["1\n\n\n\n\nl"]; +__expected.index = 4; +__expected.input = "line1\n\n\n\n\nline2"; + +assert.sameValue(__executed.length, __expected.length, '.length'); +assert.sameValue(__executed.index, __expected.index, '.index'); +assert.sameValue(__executed.input, __expected.input, '.input'); + +//CHECK#4 +for(var index=0; index < __expected.length; index++) { + assert.sameValue(__executed[index], __expected[index], 'index: ' + index); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-decimal-escape-not-capturing.js b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-decimal-escape-not-capturing.js new file mode 100644 index 0000000000..cd0bf7ed7e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-decimal-escape-not-capturing.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + An escape sequence of the form \ followed by a nonzero decimal number n + matches the result of the nth set of capturing parentheses (see + 15.10.2.11) +es5id: 15.10.2.9_A1_T4 +es6id: B.1.4 +description: > + Execute /\b(\w+) \2\b/.test("do you listen the the band") and + check results +---*/ + +var executed = /\b(\w+) \2\b/.test("do you listen the the band"); + +assert.sameValue(executed, false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-invalid-control-escape-character-class-range.js b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-invalid-control-escape-character-class-range.js new file mode 100644 index 0000000000..011790acdf --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-invalid-control-escape-character-class-range.js @@ -0,0 +1,26 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: prod-annexB-ClassAtomNoDash +description: > + Invalid \c in a range behaves like [\\c-_] +info: | + ClassAtomNoDash :: `\` + + The production ClassAtomNoDash :: `\` evaluates as follows: + 1. Return the CharSet containing the single character `\`. +---*/ + +let re = /[\\c-f]/ + +assert(re.test("\\")) +assert(!re.test("b")) +assert(re.test("c")) +assert(re.test("d")) +assert(re.test("e")) +assert(re.test("f")) +assert(!re.test("g")) +assert(!re.test("-")) + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-invalid-control-escape-character-class.js b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-invalid-control-escape-character-class.js new file mode 100644 index 0000000000..0e9451e537 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-invalid-control-escape-character-class.js @@ -0,0 +1,56 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: prod-annexB-ClassAtomNoDash +description: > + Character classes containing an invalid control escape behave like [\\c] +info: | + ClassAtomNoDash :: `\` + + The production ClassAtomNoDash :: `\` evaluates as follows: + 1. Return the CharSet containing the single character `\`. +features: [generators] +---*/ + +function* invalidControls() { + // Check ASCII characters which are not in the extended range or syntax + // characters + for (let alpha = 0x00; alpha <= 0x7F; alpha++) { + let letter = String.fromCharCode(alpha); + if (!letter.match(/[0-9A-Za-z_\$(|)\[\]\/\\^]/)) { + yield letter; + } + } + yield ""; +} + +for (let letter of invalidControls()) { + var source = "[\\c" + letter + "]"; + var re = new RegExp(source); + + if (letter.length > 0) { + var char = letter.charCodeAt(0); + var str = String.fromCharCode(char % 32); + var arr = re.exec(str); + if (str !== letter && arr !== null) { + throw new Test262Error(`Character ${letter} unreasonably wrapped around as a control character`); + } + + arr = re.exec(letter); + if (arr === null) { + throw new Test262Error(`Character ${letter} missing from character class ${source}`); + } + } + arr = re.exec("\\") + if (arr === null) { + throw new Test262Error(`Character \\ missing from character class ${source}`); + } + arr = re.exec("c") + if (arr === null) { + throw new Test262Error(`Character c missing from character class ${source}`); + } +} + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-leading-escape-BMP.js b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-leading-escape-BMP.js new file mode 100644 index 0000000000..011e7aeac6 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-leading-escape-BMP.js @@ -0,0 +1,31 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegularExpressionFirstChar :: BackslashSequence :: \NonTerminator, + RegularExpressionChars :: [empty], RegularExpressionFlags :: [empty] +es5id: 7.8.5_A1.4_T2 +es6id: 11.8.5 +description: Complex test with eval, using syntax pattern +---*/ + +for (var cu = 0; cu <= 0xffff; ++cu) { + var Elimination = + ((cu === 0x002A) || (cu === 0x002F) || (cu === 0x005C) || (cu === 0x002B) || + (cu === 0x003F) || (cu === 0x0028) || (cu === 0x0029) || + (cu === 0x005B) || (cu === 0x005D) || (cu === 0x007B) || (cu === 0x007D)); + /* + * \u002A / \u002F \ \u005C + \u002B + ? \u003F ( \u0028 ) \u0029 + [ \u005B ] \u005D { \u007B } \u007D + */ + var LineTerminator = ((cu === 0x000A) || (cu === 0x000D) || (cu === 0x2028) || (cu === 0x2029)); + if ((Elimination || LineTerminator ) === false) { + var xx = "\\" + String.fromCharCode(cu); + var pattern = eval("/" + xx + "/"); + assert.sameValue(pattern.source, xx, "Code unit: " + cu.toString(16)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-leading-escape.js b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-leading-escape.js new file mode 100644 index 0000000000..4b6c50fb00 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-leading-escape.js @@ -0,0 +1,16 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegularExpressionFirstChar :: BackslashSequence :: \NonTerminator, + RegularExpressionChars :: [empty], RegularExpressionFlags :: [empty] +es5id: 7.8.5_A1.4_T1 +es6id: 11.8.5 +description: Check similar to (/\1/.source === "\\1") +---*/ + +assert.sameValue(/\1/.source, "\\1"); +assert.sameValue(/\a/.source, "\\a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-trailing-escape-BMP.js b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-trailing-escape-BMP.js new file mode 100644 index 0000000000..76ad15761d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-trailing-escape-BMP.js @@ -0,0 +1,31 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegularExpressionChar :: BackslashSequence :: \NonTerminator, + RegularExpressionFlags :: [empty] +es5id: 7.8.5_A2.4_T2 +es6id: 11.8.5 +description: Complex test with eval, using syntax pattern +---*/ + +for (var cu = 0; cu <= 0xffff; ++cu) { + var Elimination = + ((cu === 0x002A) || (cu === 0x002F) || (cu === 0x005C) || (cu === 0x002B) || + (cu === 0x003F) || (cu === 0x0028) || (cu === 0x0029) || + (cu === 0x005B) || (cu === 0x005D) || (cu === 0x007B) || (cu === 0x007D)); + /* + * \u002A / \u002F \ \u005C + \u002B + ? \u003F ( \u0028 ) \u0029 + [ \u005B ] \u005D { \u007B } \u007D + */ + var LineTerminator = ((cu === 0x000A) || (cu === 0x000D) || (cu === 0x2028) || (cu === 0x2029)); + if ((Elimination || LineTerminator ) === false) { + var xx = "a\\" + String.fromCharCode(cu); + var pattern = eval("/" + xx + "/"); + assert.sameValue(pattern.source, xx, "Code unit: " + cu.toString(16)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-trailing-escape.js b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-trailing-escape.js new file mode 100644 index 0000000000..9af5e0ccf9 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/RegExp-trailing-escape.js @@ -0,0 +1,16 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegularExpressionChar :: BackslashSequence :: \NonTerminator, + RegularExpressionFlags :: [empty] +es5id: 7.8.5_A2.4_T1 +es6id: 11.8.5 +description: Check similar to (/a\1/.source === "a\\1") +---*/ + +assert.sameValue(/a\1/.source, "a\\1"); +assert.sameValue(/a\a/.source, "a\\a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/incomplete_hex_unicode_escape.js b/js/src/tests/test262/annexB/built-ins/RegExp/incomplete_hex_unicode_escape.js new file mode 100644 index 0000000000..915c303f3f --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/incomplete_hex_unicode_escape.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 Zirak. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: An incomplete HexEscape or UnicodeEscape should be treated as an Identity Escape +info: | + An incomplete HexEscape (e.g. /\x/) or UnicodeEscape (/\u/) should fall + through to IdentityEscape +esid: prod-AtomEscape +---*/ + +// Hex escape +assert(/\x/.test("x"), "/\\x/"); +assert(/\xa/.test("xa"), "/\\xa/"); + +// Unicode escape +assert(/\u/.test("u"), "/\\u/"); +assert(/\ua/.test("ua"), "/\\ua/"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/prop-desc.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/prop-desc.js new file mode 100644 index 0000000000..7f11026dbc --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/prop-desc.js @@ -0,0 +1,35 @@ +// |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.$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 + }); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/this-cross-realm-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/this-cross-realm-constructor.js new file mode 100644 index 0000000000..885e64fcc0 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/this-cross-realm-constructor.js @@ -0,0 +1,33 @@ +// |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.$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" + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/this-not-regexp-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/this-not-regexp-constructor.js new file mode 100644 index 0000000000..5afd16c0fb --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/this-not-regexp-constructor.js @@ -0,0 +1,63 @@ +// |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.$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' + ); + }); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/this-subclass-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/this-subclass-constructor.js new file mode 100644 index 0000000000..99970a8332 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/this-subclass-constructor.js @@ -0,0 +1,33 @@ +// |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.$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" + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/prop-desc.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/prop-desc.js new file mode 100644 index 0000000000..e5f0c85603 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/prop-desc.js @@ -0,0 +1,45 @@ +// |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.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 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/this-cross-realm-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/this-cross-realm-constructor.js new file mode 100644 index 0000000000..a7f0446619 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/this-cross-realm-constructor.js @@ -0,0 +1,64 @@ +// |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.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" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/this-not-regexp-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/this-not-regexp-constructor.js new file mode 100644 index 0000000000..4a8a7ff3c6 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/this-not-regexp-constructor.js @@ -0,0 +1,76 @@ +// |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.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' + ); + }); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/this-subclass-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/this-subclass-constructor.js new file mode 100644 index 0000000000..beb7c8c66d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/this-subclass-constructor.js @@ -0,0 +1,64 @@ +// |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.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" +); + +reportCompare(0, 0); 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); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/prop-desc.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/prop-desc.js new file mode 100644 index 0000000000..cc8c0adc10 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/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.lastParen +info: | + RegExp.lastParen is an accessor property with attributes: + { + [[Enumerable]]: false, + [[Configurable]]: true, + [[Set]]: undefined, + } + + get RegExp.lastParen + + 1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLastParen]]). +includes: [propertyHelper.js] +features: [legacy-regexp] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp, "lastParen"); + +assert.sameValue(desc.set, undefined, "`set` property"); +assert.sameValue(typeof desc.get, "function", "`get` property"); + +verifyProperty(RegExp, "lastParen", { + 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/lastParen/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/this-cross-realm-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/this-cross-realm-constructor.js new file mode 100644 index 0000000000..39b723d8d9 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/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.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" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/this-not-regexp-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/this-not-regexp-constructor.js new file mode 100644 index 0000000000..bd36699732 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/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.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' + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/this-subclass-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/this-subclass-constructor.js new file mode 100644 index 0000000000..36fdf2cd3c --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/lastParen/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.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" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/prop-desc.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/prop-desc.js new file mode 100644 index 0000000000..7504bdab79 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/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.leftContext +info: | + RegExp.leftContext is an accessor property with attributes: + { + [[Enumerable]]: false, + [[Configurable]]: true, + [[Set]]: undefined, + } + + get RegExp.leftContext + + 1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLeftContext]]). +includes: [propertyHelper.js] +features: [legacy-regexp] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp, "leftContext"); + +assert.sameValue(desc.set, undefined, "`set` property"); +assert.sameValue(typeof desc.get, "function", "`get` property"); + +verifyProperty(RegExp, "leftContext", { + 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/leftContext/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/this-cross-realm-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/this-cross-realm-constructor.js new file mode 100644 index 0000000000..ba4d23f90e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/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.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" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/this-not-regexp-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/this-not-regexp-constructor.js new file mode 100644 index 0000000000..a25bd49cad --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/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.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' + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/this-subclass-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/this-subclass-constructor.js new file mode 100644 index 0000000000..7eba961283 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/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.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" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/prop-desc.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/prop-desc.js new file mode 100644 index 0000000000..748a09a522 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/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.rightContext +info: | + RegExp.rightContext is an accessor property with attributes: + { + [[Enumerable]]: false, + [[Configurable]]: true, + [[Set]]: undefined, + } + + get RegExp.rightContext + + 1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpRightContext]]). +includes: [propertyHelper.js] +features: [legacy-regexp] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp, "rightContext"); + +assert.sameValue(desc.set, undefined, "`set` property"); +assert.sameValue(typeof desc.get, "function", "`get` property"); + +verifyProperty(RegExp, "rightContext", { + 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/rightContext/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/this-cross-realm-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/this-cross-realm-constructor.js new file mode 100644 index 0000000000..321f8d6707 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/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.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" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/this-not-regexp-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/this-not-regexp-constructor.js new file mode 100644 index 0000000000..01b5c065c9 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/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.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' + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/this-subclass-constructor.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/this-subclass-constructor.js new file mode 100644 index 0000000000..4dbc82e23c --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/rightContext/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.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" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/non-unicode-malformed-lookbehind.js b/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/non-unicode-malformed-lookbehind.js new file mode 100644 index 0000000000..9c8ab7ba6b --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/non-unicode-malformed-lookbehind.js @@ -0,0 +1,17 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: prod-GroupSpecifier +description: > + \k is parsed as IdentityEscape as look-behind assertion is not a GroupName. +features: [regexp-named-groups, regexp-lookbehind] +---*/ + +assert(/\k<a>(?<=>)a/.test("k<a>a")); +assert(/(?<=>)\k<a>/.test(">k<a>")); + +assert(/\k<a>(?<!a)a/.test("k<a>a")); +assert(/(?<!a>)\k<a>/.test("k<a>")); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/non-unicode-malformed.js b/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/non-unicode-malformed.js new file mode 100644 index 0000000000..b7dd55db09 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/non-unicode-malformed.js @@ -0,0 +1,27 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Named groups in Unicode RegExps have some syntax errors and some + compatibility escape fallback behavior. +esid: prod-GroupSpecifier +features: [regexp-named-groups] +includes: [compareArray.js] +---*/ + +assert(/\k<a>/.test("k<a>")); +assert(/\k<4>/.test("k<4>")); +assert(/\k<a/.test("k<a")); +assert(/\k/.test("k")); + +assert(/(?<a>\a)/.test("a")); + +assert.compareArray(["k<a>"], "xxxk<a>xxx".match(/\k<a>/)); +assert.compareArray(["k<a"], "xxxk<a>xxx".match(/\k<a/)); + +assert(/\k<a>(<a>x)/.test("k<a><a>x")); +assert(/\k<a>\1/.test("k<a>\x01")); +assert(/\1(b)\k<a>/.test("bk<a>")); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/named-groups/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/Symbol.match-getter-recompiles-source.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/Symbol.match-getter-recompiles-source.js new file mode 100644 index 0000000000..41e8cbaf19 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/Symbol.match-getter-recompiles-source.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@split +description: > + Side-effects in IsRegExp may recompile the regular expression. +info: | + 21.2.5.11 RegExp.prototype [ @@split ] ( string, limit ) + ... + 4. Let C be ? SpeciesConstructor(rx, %RegExp%). + ... + 10. Let splitter be ? Construct(C, « rx, newFlags »). + ... + + 21.2.3.1 RegExp ( pattern, flags ) + 1. Let patternIsRegExp be ? IsRegExp(pattern). + ... + +features: [Symbol.match, Symbol.split] +---*/ + +var regExp = /a/; +Object.defineProperty(regExp, Symbol.match, { + get: function() { + regExp.compile("b"); + } +}); + +var result = regExp[Symbol.split]("abba"); + +assert.sameValue(result.length, 3); +assert.sameValue(result[0], "a"); +assert.sameValue(result[1], ""); +assert.sameValue(result[2], "a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/toint32-limit-recompiles-source.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/toint32-limit-recompiles-source.js new file mode 100644 index 0000000000..351407cf65 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/Symbol.split/toint32-limit-recompiles-source.js @@ -0,0 +1,34 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@split +description: > + Side-effects in ToUint32 may recompile the regular expression. +info: | + 21.2.5.11 RegExp.prototype [ @@split ] ( string, limit ) + ... + 10. Let splitter be ? Construct(C, « rx, newFlags »). + ... + 13. If limit is undefined, let lim be 2^32-1; else let lim be ? ToUint32(limit). + ... + +features: [Symbol.split] +---*/ + +var regExp = /a/; +var limit = { + valueOf: function() { + regExp.compile("b"); + return -1; + } +}; + +var result = regExp[Symbol.split]("abba", limit); + +assert.sameValue(result.length, 3); +assert.sameValue(result[0], ""); +assert.sameValue(result[1], "bb"); +assert.sameValue(result[2], ""); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/B.RegExp.prototype.compile.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/B.RegExp.prototype.compile.js new file mode 100644 index 0000000000..52b6cfa331 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/B.RegExp.prototype.compile.js @@ -0,0 +1,18 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.5.1 +description: > + Object.getOwnPropertyDescriptor returns data desc for functions on + built-ins (RegExp.prototype.compile) +includes: [propertyHelper.js] +---*/ + +verifyProperty(RegExp.prototype, "compile", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/duplicate-named-capturing-groups-syntax.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/duplicate-named-capturing-groups-syntax.js new file mode 100644 index 0000000000..a1ac2676a1 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/duplicate-named-capturing-groups-syntax.js @@ -0,0 +1,23 @@ +// |reftest| skip -- regexp-duplicate-named-groups is not supported +// Copyright 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype.compile +description: Runtime parsing of syntax for duplicate named capturing groups +features: [regexp-duplicate-named-groups] +---*/ + +let r = /[ab]/; + +assert.throws( + SyntaxError, + () => r.compile("(?<x>a)(?<x>b)"), + "Duplicate named capturing groups in the same alternative do not parse" +); + +let source = "(?<x>a)|(?<x>b)"; +r.compile(source); +assert.sameValue(r.source, source, "Duplicate named capturing groups in separate alternatives parse correctly"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-string-invalid.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-string-invalid.js new file mode 100644 index 0000000000..a7c8493656 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-string-invalid.js @@ -0,0 +1,45 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: Behavior when flags is a string describing an invalid flag set +info: | + [...] + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + [...] + 3. If flags is undefined, let F be the empty String. + 4. Else, let F be ? ToString(flags). + 5. If F contains any code unit other than "g", "i", "m", "u", or "y" or if + it contains the same code unit more than once, throw a SyntaxError + exception. +---*/ + +var subject = /abcd/ig; + +assert.throws(SyntaxError, function() { + subject.compile('', 'igi'); +}, 'invalid flags: igi'); + +assert.throws(SyntaxError, function() { + subject.compile('', 'gI'); +}, 'invalid flags: gI'); + +assert.throws(SyntaxError, function() { + subject.compile('', 'w'); +}, 'invalid flags: w'); + +assert.sameValue( + subject.toString(), + new RegExp('abcd', 'ig').toString(), + '[[OriginalSource]] internal slot' +); + +assert.sameValue( + subject.test('AbCD'), true, '[[RegExpMatcher]] internal slot' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-to-string-err.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-to-string-err.js new file mode 100644 index 0000000000..1fad177bd1 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-to-string-err.js @@ -0,0 +1,45 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: Behavior when provided flags cannot be coerced to a string +info: | + [...] + 3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal + slot, then + a. If flags is not undefined, throw a TypeError exception. + b. Let P be the value of pattern's [[OriginalSource]] internal slot. + c. Let F be the value of pattern's [[OriginalFlags]] internal slot. + 4. Else, + [...] + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + [...] + 3. If flags is undefined, let F be the empty String. + 4. Else, let F be ? ToString(flags). +features: [Symbol] +---*/ + +var symbol = Symbol(''); +var subject = /./; +var badToString = { + toString: function() { + throw new Test262Error(); + } +}; +subject.lastIndex = 99; + +assert.throws(Test262Error, function() { + /./.compile('', badToString); +}); + +assert.throws(TypeError, function() { + /./.compile('', symbol); +}); + +assert.sameValue(subject.lastIndex, 99); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-to-string.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-to-string.js new file mode 100644 index 0000000000..7044462a56 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-to-string.js @@ -0,0 +1,41 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: Behavior when flags is a string describing a valid flag set +info: | + [...] + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + [...] + 3. If flags is undefined, let F be the empty String. + 4. Else, let F be ? ToString(flags). + [...] +---*/ + +var subject = /a/g; + +subject.compile('a', 'i'); + +assert.sameValue( + subject.flags, + new RegExp('a', 'i').flags, + '[[OriginalFlags]] internal slot' +); +assert.sameValue( + subject.test('A'), + true, + '[[RegExpMatcher]] internal slot (addition of `i` flag)' +); + +subject.lastIndex = 1; +assert.sameValue( + subject.test('A'), + true, + '[[RegExpMatcher]] internal slot (removal of `g` flag)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-undefined.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-undefined.js new file mode 100644 index 0000000000..29cb3b3fb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/flags-undefined.js @@ -0,0 +1,54 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: Behavior when flags is undefined +info: | + [...] + 3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal + slot, then + [...] + 4. Else, + a. Let P be pattern. + b. Let F be flags. + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + [...] + 3. If flags is undefined, let F be the empty String. + [...] +---*/ + +var subject, result; + +subject = /abc/ig; + +result = subject.compile('def'); + +assert.sameValue(result, subject, 'method return value (unspecified)'); +assert.sameValue( + subject.flags, new RegExp('def').flags, '[[OriginalFlags]] (unspecified)' +); +assert.sameValue( + subject.test('DEF'), false, '[[RegExpMatcher]] internal slot (unspecified)' +); + +subject = /abc/gi; + +result = subject.compile('def', undefined); + +assert.sameValue(result, subject, 'method return value (explicit undefined)'); +assert.sameValue( + subject.flags, + new RegExp('def').flags, + '[[OriginalSource]] (explicit undefined)' +); +assert.sameValue( + subject.test('DEF'), + false, + '[[RegExpMatcher]] internal slot (explicit undefined)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/length.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/length.js new file mode 100644 index 0000000000..ce648e692c --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.5.1 +description: > + RegExp.prototype.compile.length is 2. +info: | + RegExp.prototype.compile (pattern, flags ) + + 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] +---*/ + +verifyProperty(RegExp.prototype.compile, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 2 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/name.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/name.js new file mode 100644 index 0000000000..2e35d280e3 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.5.1 +description: > + RegExp.prototype.compile.name is "compile". +info: | + RegExp.prototype.compile (pattern, flags ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(RegExp.prototype.compile, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "compile" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-distinct.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-distinct.js new file mode 100644 index 0000000000..fed4f82364 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-distinct.js @@ -0,0 +1,39 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: RegExp is re-initialized when invoked with a distinct instance +info: | + [...] + 3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal + slot, then + a. If flags is not undefined, throw a TypeError exception. + b. Let P be the value of pattern's [[OriginalSource]] internal slot. + c. Let F be the value of pattern's [[OriginalFlags]] internal slot. + 4. Else, + [...] + 5. Return ? RegExpInitialize(O, P, F). +---*/ + +var subject = /abc/gim; +var pattern = /def/; +var result; +subject.lastIndex = 23; +pattern.lastIndex = 45; + +result = subject.compile(pattern); + +assert.sameValue(result, subject, 'method return value'); +assert.sameValue(subject.lastIndex, 0); +assert.sameValue(pattern.lastIndex, 45); + +assert.sameValue(subject.toString(), new RegExp('def').toString()); +assert.sameValue( + subject.test('def'), true, '[[RegExpMatcher]] internal slot (source)' +); +assert.sameValue( + subject.test('DEF'), false, '[[RegExpMatch]] internal slot (flags)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-flags-defined.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-flags-defined.js new file mode 100644 index 0000000000..6ea536960c --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-flags-defined.js @@ -0,0 +1,46 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: > + Behavior when provided pattern is a RegExp instance and flags are specified +info: | + [...] + 3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal + slot, then + a. If flags is not undefined, throw a TypeError exception. +---*/ + +var re = /./; +re.lastIndex = 23; + +assert.sameValue(typeof RegExp.prototype.compile, 'function'); + +assert.throws(TypeError, function() { + re.compile(re, null); +}, 'null'); + +assert.throws(TypeError, function() { + re.compile(re, 0); +}, 'numeric primitive'); + +assert.throws(TypeError, function() { + re.compile(re, ''); +}, 'string primitive'); + +assert.throws(TypeError, function() { + re.compile(re, false); +}, 'boolean primitive'); + +assert.throws(TypeError, function() { + re.compile(re, {}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + re.compile(re, []); +}, 'array exotic object'); + +assert.sameValue(re.lastIndex, 23); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-immutable-lastindex.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-immutable-lastindex.js new file mode 100644 index 0000000000..cb69aaa439 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-immutable-lastindex.js @@ -0,0 +1,38 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: Behavior when `lastIndex` property of "this" value is non-writable +info: | + [...] + 3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal + slot, then + a. If flags is not undefined, throw a TypeError exception. + b. Let P be the value of pattern's [[OriginalSource]] internal slot. + c. Let F be the value of pattern's [[OriginalFlags]] internal slot. + 4. Else, + [...] + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + [...] + 12. Perform ? Set(obj, "lastIndex", 0, true). +---*/ + +var subject = /initial/; +Object.defineProperty(subject, 'lastIndex', { value: 45, writable: false }); + +assert.throws(TypeError, function() { + subject.compile(/updated/gi); +}); + +assert.sameValue( + subject.toString(), + new RegExp('updated', 'gi').toString(), + '[[OriginalSource]] internal slot' +); +assert.sameValue(subject.lastIndex, 45); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-props.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-props.js new file mode 100644 index 0000000000..f723c00174 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-props.js @@ -0,0 +1,75 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: > + Properties are not referenced when provided pattern is a RegExp instance +info: | + [...] + 3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal + slot, then + a. If flags is not undefined, throw a TypeError exception. + b. Let P be the value of pattern's [[OriginalSource]] internal slot. + c. Let F be the value of pattern's [[OriginalFlags]] internal slot. + 4. Else, + [...] + 5. Return ? RegExpInitialize(O, P, F). +---*/ + +var thisValue = /abc/gim; +var pattern = /def/mig; +var flagsCount = 0; +var globalCount = 0; +var ignoreCaseCount = 0; +var multilineCount = 0; +var stickyCount = 0; +var unicodeCount = 0; +var counters = { + flags: { + get: function() { + flagsCount += 1; + } + }, + global: { + get: function() { + globalCount += 1; + } + }, + ignoreCase: { + get: function() { + ignoreCaseCount += 1; + } + }, + multiline: { + get: function() { + multilineCount += 1; + } + }, + sticky: { + get: function() { + stickyCount += 1; + } + }, + unicode: { + get: function() { + unicodeCount += 1; + } + } +}; + +Object.defineProperties(thisValue, counters); +Object.defineProperties(pattern, counters); + +thisValue.compile(thisValue); +thisValue.compile(pattern); +thisValue.compile(thisValue); + +assert.sameValue(flagsCount, 0, '`flags` property not accessed'); +assert.sameValue(globalCount, 0, '`global` property not accessed'); +assert.sameValue(ignoreCaseCount, 0, '`ignoreCase` property not accessed'); +assert.sameValue(multilineCount, 0, '`multiline` property not accessed'); +assert.sameValue(stickyCount, 0, '`sticky` property not accessed'); +assert.sameValue(unicodeCount, 0, '`unicode` property not accessed'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-same.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-same.js new file mode 100644 index 0000000000..b239e0e48b --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-regexp-same.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-regexp.prototype.compile +es6id: B.2.5.1 +description: RegExp is re-initialized when invoked with the same instance +info: | + [...] + 3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal + slot, then + a. If flags is not undefined, throw a TypeError exception. + b. Let P be the value of pattern's [[OriginalSource]] internal slot. + c. Let F be the value of pattern's [[OriginalFlags]] internal slot. + 4. Else, + [...] + 5. Return ? RegExpInitialize(O, P, F). +---*/ + +var subject = /abc/gim; +var result; +subject.lastIndex = 23; + +result = subject.compile(subject); + +assert.sameValue(result, subject, 'method return value'); +assert.sameValue( + subject.toString(), + new RegExp('abc', 'gim').toString(), + '[[OriginalSource]] internal slot' +); +assert.sameValue(subject.lastIndex, 0); +assert.sameValue(subject.test('aBc'), true, '[[RegExpMatcher]] internal slot'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid-u.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid-u.js new file mode 100644 index 0000000000..d0c3cd6d5f --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid-u.js @@ -0,0 +1,44 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: > + Behavior when pattern is a string describing an invalid pattern (unicode) +info: | + [...] + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + 6. If F contains "u", let BMP be false; else let BMP be true. + 7. If BMP is true, then + a. Parse P using the grammars in 21.2.1 and interpreting each of its + 16-bit elements as a Unicode BMP code point. UTF-16 decoding is not + applied to the elements. The goal symbol for the parse is Pattern. + Throw a SyntaxError exception if P did not conform to the grammar, if + any elements of P were not matched by the parse, or if any Early + Error conditions exist. + [...] +---*/ + +var subject = /test262/ig; + +assert.throws(SyntaxError, function() { + subject.compile('{', 'u'); +}, 'invalid pattern: {'); + +assert.throws(SyntaxError, function() { + subject.compile('\\2', 'u'); +}, 'invalid pattern: \\2'); + +assert.sameValue( + subject.toString(), + new RegExp('test262', 'ig').toString(), + '[[OriginalSource]] internal slot' +); +assert.sameValue( + subject.test('tEsT262'), true, '[[RegExpMatcher]] internal slot' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid.js new file mode 100644 index 0000000000..471e8da688 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid.js @@ -0,0 +1,46 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: > + Behavior when pattern is a string describing an invalid pattern + (non-unicode) +info: | + [...] + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + 6. If F contains "u", let BMP be false; else let BMP be true. + 7. If BMP is true, then + [...] + 8. Else, + a. Parse P using the grammars in 21.2.1 and interpreting P as UTF-16 + encoded Unicode code points (6.1.4). The goal symbol for the parse is + Pattern[U]. Throw a SyntaxError exception if P did not conform to the + grammar, if any elements of P were not matched by the parse, or if + any Early Error conditions exist. +---*/ + +var subject = /test262/ig; + +assert.throws(SyntaxError, function() { + subject.compile('?'); +}, 'invalid pattern: ?'); + +assert.throws(SyntaxError, function() { + subject.compile('.{2,1}'); +}, 'invalid pattern: .{2,1}'); + +assert.sameValue( + subject.toString(), + new RegExp('test262', 'ig').toString(), + '[[OriginalSource]] internal slot' +); + +assert.sameValue( + subject.test('TEsT262'), true, '[[RegExpMatcher]] internal slot' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string-u.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string-u.js new file mode 100644 index 0000000000..e3840230fb --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string-u.js @@ -0,0 +1,53 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: > + Behavior when pattern is a string describing a valid pattern (unicode) +info: | + [...] + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + 6. If F contains "u", let BMP be false; else let BMP be true. + 7. If BMP is true, then + a. Parse P using the grammars in 21.2.1 and interpreting each of its + 16-bit elements as a Unicode BMP code point. UTF-16 decoding is not + applied to the elements. The goal symbol for the parse is Pattern. + Throw a SyntaxError exception if P did not conform to the grammar, if + any elements of P were not matched by the parse, or if any Early + Error conditions exist. + b. Let patternCharacters be a List whose elements are the code unit + elements of P. + [...] +---*/ + +var subject = /original value/ig; + +subject.compile('[\ud834\udf06]', 'u'); + +assert.sameValue( + subject.source, + new RegExp('[\ud834\udf06]', 'u').source, + '[[OriginalSource]] internal slot' +); +assert.sameValue( + subject.test('original value'), + false, + '[[RegExpMatcher]] internal slot (source)' +); +assert.sameValue( + subject.test('\ud834'), false, '[[RegExpMatcher]] internal slot (flags #1)' +); +assert.sameValue( + subject.test('\udf06'), false, '[[RegExpMatcher]] internal slot (flags #2)' +); +assert.sameValue( + subject.test('\ud834\udf06'), + true, + '[[RegExpMatcher]] internal slot (flags #3)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string.js new file mode 100644 index 0000000000..57c9a82e41 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-string.js @@ -0,0 +1,44 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: > + Behavior when pattern is a string describing a valid pattern (non-unicode) +info: | + [...] + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + 6. If F contains "u", let BMP be false; else let BMP be true. + 7. If BMP is true, then + [...] + 8. Else, + a. Parse P using the grammars in 21.2.1 and interpreting P as UTF-16 + encoded Unicode code points (6.1.4). The goal symbol for the parse is + Pattern[U]. Throw a SyntaxError exception if P did not conform to the + grammar, if any elements of P were not matched by the parse, or if + any Early Error conditions exist. + b. Let patternCharacters be a List whose elements are the code points + resulting from applying UTF-16 decoding to P's sequence of elements. + [...] +---*/ + +var subject = /original value/ig; + +subject.compile('new value'); + +assert.sameValue( + subject.source, + new RegExp('new value').source, + '[[OriginalSource]] internal slot' +); +assert.sameValue( + subject.test('original value'), false, '[[RegExpMatcher]] internal slot' +); +assert.sameValue( + subject.test('new value'), true, '[[RegExpMatcher]] internal slot' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-to-string-err.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-to-string-err.js new file mode 100644 index 0000000000..64df03654a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-to-string-err.js @@ -0,0 +1,44 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: Behavior when provided pattern cannot be coerced to a string +info: | + [...] + 3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal + slot, then + a. If flags is not undefined, throw a TypeError exception. + b. Let P be the value of pattern's [[OriginalSource]] internal slot. + c. Let F be the value of pattern's [[OriginalFlags]] internal slot. + 4. Else, + [...] + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + 1. If pattern is undefined, let P be the empty String. + 2. Else, let P be ? ToString(pattern). +features: [Symbol] +---*/ + +var symbol = Symbol(''); +var subject = /./; +var badToString = { + toString: function() { + throw new Test262Error(); + } +}; +subject.lastIndex = 99; + +assert.throws(Test262Error, function() { + /./.compile(badToString); +}); + +assert.throws(TypeError, function() { + /./.compile(symbol); +}); + +assert.sameValue(subject.lastIndex, 99); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-undefined.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-undefined.js new file mode 100644 index 0000000000..52328d262d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/pattern-undefined.js @@ -0,0 +1,53 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: Behavior when pattern is undefined +info: | + [...] + 3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal + slot, then + [...] + 4. Else, + a. Let P be pattern. + b. Let F be flags. + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.3.2.2 Runtime Semantics: RegExpInitialize + + 1. If pattern is undefined, let P be the empty String. + [...] +---*/ + +var subject; + +subject = /abc/; +assert.sameValue( + subject.compile(), subject, 'method return value (unspecified)' +); +assert.sameValue( + subject.source, new RegExp('').source, '[[OriginalSource]] (unspecified)' +); +assert.sameValue( + subject.test(''), true, '[[RegExpMatcher]] internal slot (unspecified)' +); + +subject = /abc/; +assert.sameValue( + subject.compile(undefined), + subject, + 'method return value (explicit undefined)' +); +assert.sameValue( + subject.source, + new RegExp('').source, + '[[OriginalSource]] (explicit undefined)' +); +assert.sameValue( + subject.test(''), + true, + '[[RegExpMatcher]] internal slot (explicit undefined)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-cross-realm-instance.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-cross-realm-instance.js new file mode 100644 index 0000000000..5c4f9a8234 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-cross-realm-instance.js @@ -0,0 +1,37 @@ +// |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: sec-regexp.prototype.compile +description: RegExp.prototype.compile throws a TypeError for cross-realm calls +features: [legacy-regexp,cross-realm] +---*/ + +const other = $262.createRealm().global; + +const regexp = new RegExp(""); +const otherRealm_regexp = new other.RegExp(""); + +assert.throws( + TypeError, + function () { + RegExp.prototype.compile.call(otherRealm_regexp); + }, + "`RegExp.prototype.compile.call(otherRealm_regexp)` throws TypeError" +); + +assert.throws( + other.TypeError, + function () { + other.RegExp.prototype.compile.call(regexp); + }, + "`other.RegExp.prototype.compile.call(regexp)` throws TypeError" +); + +assert.sameValue( + otherRealm_regexp.compile(), + otherRealm_regexp, + "`otherRealm_regexp.compile()` is SameValue with `otherRealm_regexp`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-not-object.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-not-object.js new file mode 100644 index 0000000000..77424a0062 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-not-object.js @@ -0,0 +1,44 @@ +// 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-regexp.prototype.compile +es6id: B.2.5.1 +description: Behavior when "this" value is not an Object +info: | + 1. Let O be the this value. + 2. If Type(O) is not Object or Type(O) is Object and O does not have a + [[RegExpMatcher]] internal slot, then + a. Throw a TypeError exception. +features: [Symbol] +---*/ + +var compile = RegExp.prototype.compile; +var symbol = Symbol(''); + +assert.sameValue(typeof compile, 'function'); + +assert.throws(TypeError, function() { + compile.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + compile.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + compile.call(23); +}, 'number'); + +assert.throws(TypeError, function() { + compile.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + compile.call('/string/'); +}, 'string'); + +assert.throws(TypeError, function() { + compile.call(symbol); +}, 'symbol'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-obj-not-regexp.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-obj-not-regexp.js new file mode 100644 index 0000000000..785fccacff --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-obj-not-regexp.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-regexp.prototype.compile +es6id: B.2.5.1 +description: > + Behavior when "this" value is an Object without a [[RegExpMatcher]] + internal slot +info: | + 1. Let O be the this value. + 2. If Type(O) is not Object or Type(O) is Object and O does not have a + [[RegExpMatcher]] internal slot, then + a. Throw a TypeError exception. +---*/ + +var compile = RegExp.prototype.compile; + +assert.sameValue(typeof compile, 'function'); + +assert.throws(TypeError, function() { + compile.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + compile.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + compile.call(arguments); +}, 'arguments exotic object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-subclass-instance.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-subclass-instance.js new file mode 100644 index 0000000000..66f6e3f5a6 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/compile/this-subclass-instance.js @@ -0,0 +1,28 @@ +// |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: sec-regexp.prototype.compile +description: RegExp.prototype.compile throws a TypeError for calls on subclasses +features: [legacy-regexp,class] +---*/ + +const subclass_regexp = new (class extends RegExp {})(""); + +assert.throws( + TypeError, + function () { + subclass_regexp.compile(); + }, + "`subclass_regexp.compile()` throws TypeError" +); + +assert.throws( + TypeError, + function () { + RegExp.prototype.compile.call(subclass_regexp); + }, + "`RegExp.prototype.compile.call(subclass_regexp)` throws TypeError" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/flags/browser.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/flags/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/flags/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/flags/order-after-compile.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/flags/order-after-compile.js new file mode 100644 index 0000000000..c445800923 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/flags/order-after-compile.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 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.flags +description: > + The flags come in the same order in a new instance produced by RegExp.prototype.compile +info: | + B.2.5.1 RegExp.prototype.compile ( pattern, flags ) + + ... + 5. Return ? RegExpInitialize(O, P, F). + + 21.2.5.3 get RegExp.prototype.flags + + ... + 4. Let global be ToBoolean(? Get(R, "global")). + 5. If global is true, append "g" as the last code unit of result. + 6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + 7. If ignoreCase is true, append "i" as the last code unit of result. + 8. Let multiline be ToBoolean(? Get(R, "multiline")). + 9. If multiline is true, append "m" as the last code unit of result. + 10. Let dotAll be ToBoolean(? Get(R, "dotAll")). + 11. If dotAll is true, append "s" as the last code unit of result. + 12. Let unicode be ToBoolean(? Get(R, "unicode")). + 13. If unicode is true, append "u" as the last code unit of result. + 14. Let sticky be ToBoolean(? Get(R, "sticky")). + 15. If sticky is true, append "y" as the last code unit of result. + 14. Return result. +features: [regexp-dotall] +---*/ + +let re = /(?:)/; +re.compile("(?:)", "imsuyg"); +assert.sameValue(re.flags, "gimsuy"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/flags/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/flags/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/flags/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/prototype/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/prototype/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/RegExp/shell.js b/js/src/tests/test262/annexB/built-ins/RegExp/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/RegExp/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/String/browser.js b/js/src/tests/test262/annexB/built-ins/String/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/B.2.3.2.js b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/B.2.3.2.js new file mode 100644 index 0000000000..6b8511876e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/B.2.3.2.js @@ -0,0 +1,28 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.anchor returns a string of HTML describing a single HTML + anchor element. The element's content is the `this` value of the function + invocation, coerced to a string. If specified, the first argument will be + coerced to a string, escaped, and set as the element's `name` attribute. + es6id: B.2.3.2 +---*/ + +assert.sameValue('_'.anchor('b'), '<a name="b">_</a>'); +assert.sameValue('<'.anchor('<'), '<a name="<"><</a>'); +assert.sameValue('_'.anchor(0x2A), '<a name="42">_</a>'); +assert.sameValue('_'.anchor('\x22'), '<a name=""">_</a>'); +assert.sameValue(String.prototype.anchor.call(0x2A, 0x2A), '<a name="42">42</a>'); +assert.throws(TypeError, function() { + String.prototype.anchor.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.anchor.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/attr-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/attr-tostring-err.js new file mode 100644 index 0000000000..bf6a3eae21 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/attr-tostring-err.js @@ -0,0 +1,25 @@ +// 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-string.prototype.anchor +es6id: B.2.3.2 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + [...] + 4. If attribute is not the empty String, then + a. Let V be ? ToString(value). +---*/ + +var attr = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.anchor(attr); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/length.js new file mode 100644 index 0000000000..9df190d4a3 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.2 +description: > + String.prototype.anchor.length is 1. +info: | + String.prototype.anchor ( name ) + + 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] +---*/ + +verifyProperty(String.prototype.anchor, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/name.js new file mode 100644 index 0000000000..4d961bd1a9 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.2 +description: > + String.prototype.anchor.name is "anchor". +info: | + String.prototype.anchor ( name ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.anchor, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "anchor" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/not-a-constructor.js new file mode 100644 index 0000000000..ca59226cbf --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.anchor does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.anchor), + false, + 'isConstructor(String.prototype.anchor) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.anchor(); +}, '`new String.prototype.anchor()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/prop-desc.js new file mode 100644 index 0000000000..b1412c4a1c --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.anchor +es6id: B.2.3.2 +description: Property descriptor for String.prototype.anchor +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "anchor", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/this-val-tostring-err.js new file mode 100644 index 0000000000..c6d9d25d41 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/anchor/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.anchor +es6id: B.2.3.2 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.anchor.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/big/B.2.3.3.js b/js/src/tests/test262/annexB/built-ins/String/prototype/big/B.2.3.3.js new file mode 100644 index 0000000000..16a179283f --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/big/B.2.3.3.js @@ -0,0 +1,25 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.big returns a string of HTML describing a single HTML + big element. The element's content is the `this` value of the function + invocation, coerced to a string. + es6id: B.2.3.3 +---*/ + +assert.sameValue('_'.big(), '<big>_</big>'); +assert.sameValue('<'.big(), '<big><</big>'); +assert.sameValue(String.prototype.big.call(0x2A), '<big>42</big>'); +assert.throws(TypeError, function() { + String.prototype.big.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.big.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/big/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/big/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/big/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/big/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/big/length.js new file mode 100644 index 0000000000..bc94e5fdc4 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/big/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.3 +description: > + String.prototype.big.length is 0. +info: | + String.prototype.big ( ) + + 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] +---*/ + +verifyProperty(String.prototype.big, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/big/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/big/name.js new file mode 100644 index 0000000000..29dad81234 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/big/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.3 +description: > + String.prototype.big.name is "big". +info: | + String.prototype.big ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.big, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "big" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/big/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/big/not-a-constructor.js new file mode 100644 index 0000000000..f2e5f3bfc7 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/big/not-a-constructor.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.big does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(String.prototype.big), false, 'isConstructor(String.prototype.big) must return false'); + +assert.throws(TypeError, () => { + new String.prototype.big(); +}, '`new String.prototype.big()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/big/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/big/prop-desc.js new file mode 100644 index 0000000000..80a2b7ef72 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/big/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.big +es6id: B.2.3.3 +description: Property descriptor for String.prototype.big +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "big", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/big/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/big/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/big/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/big/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/big/this-val-tostring-err.js new file mode 100644 index 0000000000..63326e834a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/big/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.big +es6id: B.2.3.3 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.big.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/blink/B.2.3.4.js b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/B.2.3.4.js new file mode 100644 index 0000000000..5aa5620c82 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/B.2.3.4.js @@ -0,0 +1,25 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.blink returns a string of HTML describing a single HTML + blink element. The element's content is the `this` value of the function + invocation, coerced to a string. + es6id: B.2.3.4 +---*/ + +assert.sameValue('_'.blink(), '<blink>_</blink>'); +assert.sameValue('<'.blink(), '<blink><</blink>'); +assert.sameValue(String.prototype.blink.call(0x2A), '<blink>42</blink>'); +assert.throws(TypeError, function() { + String.prototype.blink.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.blink.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/blink/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/blink/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/length.js new file mode 100644 index 0000000000..06c85b49dc --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.4 +description: > + String.prototype.blink.length is 0. +info: | + String.prototype.blink ( ) + + 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] +---*/ + +verifyProperty(String.prototype.blink, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/blink/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/name.js new file mode 100644 index 0000000000..617b2d6993 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.4 +description: > + String.prototype.blink.name is "blink". +info: | + String.prototype.blink ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.blink, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "blink" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/blink/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/not-a-constructor.js new file mode 100644 index 0000000000..73d5488203 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.blink does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.blink), + false, + 'isConstructor(String.prototype.blink) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.blink(); +}, '`new String.prototype.blink()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/blink/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/prop-desc.js new file mode 100644 index 0000000000..8c875db468 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.blink +es6id: B.2.3.4 +description: Property descriptor for String.prototype.blink +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "blink", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/blink/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/blink/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/this-val-tostring-err.js new file mode 100644 index 0000000000..4a2f900e23 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/blink/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.blink +es6id: B.2.3.4 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.blink.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/bold/B.2.3.5.js b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/B.2.3.5.js new file mode 100644 index 0000000000..3a9a73052e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/B.2.3.5.js @@ -0,0 +1,25 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.bold returns a string of HTML describing a single HTML + bold element. The element's content is the `this` value of the function + invocation, coerced to a string. + es6id: B.2.3.5 +---*/ + +assert.sameValue('_'.bold(), '<b>_</b>'); +assert.sameValue('<'.bold(), '<b><</b>'); +assert.sameValue(String.prototype.bold.call(0x2A), '<b>42</b>'); +assert.throws(TypeError, function() { + String.prototype.bold.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.bold.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/bold/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/bold/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/length.js new file mode 100644 index 0000000000..151964b7ec --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.5 +description: > + String.prototype.bold.length is 0. +info: | + String.prototype.bold ( ) + + 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] +---*/ + +verifyProperty(String.prototype.bold, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/bold/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/name.js new file mode 100644 index 0000000000..21c7beafd0 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.5 +description: > + String.prototype.bold.name is "bold". +info: | + String.prototype.bold ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.bold, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "bold" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/bold/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/not-a-constructor.js new file mode 100644 index 0000000000..1f8a7a155d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.bold does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.bold), + false, + 'isConstructor(String.prototype.bold) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.bold(); +}, '`new String.prototype.bold()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/bold/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/prop-desc.js new file mode 100644 index 0000000000..1eb27ef8bc --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.bold +es6id: B.2.3.5 +description: Property descriptor for String.prototype.bold +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "bold", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/bold/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/bold/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/this-val-tostring-err.js new file mode 100644 index 0000000000..7f1fdd05ec --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/bold/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.bold +es6id: B.2.3.5 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.bold.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/B.2.3.6.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/B.2.3.6.js new file mode 100644 index 0000000000..2c20e91f4c --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/B.2.3.6.js @@ -0,0 +1,25 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.fixed returns a string of HTML describing a single HTML + teletype text element. The element's content is the `this` value of the + function invocation, coerced to a string. + es6id: B.2.3.6 +---*/ + +assert.sameValue('_'.fixed(), '<tt>_</tt>'); +assert.sameValue('<'.fixed(), '<tt><</tt>'); +assert.sameValue(String.prototype.fixed.call(0x2A), '<tt>42</tt>'); +assert.throws(TypeError, function() { + String.prototype.fixed.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.fixed.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/length.js new file mode 100644 index 0000000000..bc2d83974b --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.6 +description: > + String.prototype.fixed.length is 0. +info: | + String.prototype.fixed ( ) + + 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] +---*/ + +verifyProperty(String.prototype.fixed, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/name.js new file mode 100644 index 0000000000..a5b546cd76 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.6 +description: > + String.prototype.fixed.name is "fixed". +info: | + String.prototype.fixed ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.fixed, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "fixed" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/not-a-constructor.js new file mode 100644 index 0000000000..64fa0c534d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.fixed does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.fixed), + false, + 'isConstructor(String.prototype.fixed) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.fixed(); +}, '`new String.prototype.fixed()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/prop-desc.js new file mode 100644 index 0000000000..c6691e668b --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.fixed +es6id: B.2.3.6 +description: Property descriptor for String.prototype.fixed +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "fixed", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/this-val-tostring-err.js new file mode 100644 index 0000000000..96b339a0f0 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fixed/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.fixed +es6id: B.2.3.6 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.fixed.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/B.2.3.7.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/B.2.3.7.js new file mode 100644 index 0000000000..497e24654d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/B.2.3.7.js @@ -0,0 +1,30 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.fontcolor returns a string of HTML describing a single + HTML font element. The element's content is the `this` value of the + function invocation, coerced to a string. If specified, the first argument + will be coerced to a string, escaped, and set as the element's `color` + attribute. + es6id: B.2.3.7 +---*/ + +assert.sameValue('_'.fontcolor('b'), '<font color="b">_</font>'); +assert.sameValue('<'.fontcolor('<'), '<font color="<"><</font>'); +assert.sameValue('_'.fontcolor(0x2A), '<font color="42">_</font>'); +assert.sameValue('_'.fontcolor('\x22'), '<font color=""">_</font>'); +assert.sameValue(String.prototype.fontcolor.call(0x2A, 0x2A), + '<font color="42">42</font>'); +assert.throws(TypeError, function() { + String.prototype.fontcolor.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.fontcolor.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/attr-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/attr-tostring-err.js new file mode 100644 index 0000000000..bc4604f7b9 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/attr-tostring-err.js @@ -0,0 +1,25 @@ +// 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-string.prototype.fontcolor +es6id: B.2.3.7 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + [...] + 4. If attribute is not the empty String, then + a. Let V be ? ToString(value). +---*/ + +var attr = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.fontcolor(attr); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/length.js new file mode 100644 index 0000000000..d12fa78837 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.7 +description: > + String.prototype.fontcolor.length is 1. +info: | + String.prototype.fontcolor ( color ) + + 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] +---*/ + +verifyProperty(String.prototype.fontcolor, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/name.js new file mode 100644 index 0000000000..237ce1debc --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.7 +description: > + String.prototype.fontcolor.name is "fontcolor". +info: | + String.prototype.fontcolor ( color ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.fontcolor, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "fontcolor" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/not-a-constructor.js new file mode 100644 index 0000000000..a5bfa4415c --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.fontcolor does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.fontcolor), + false, + 'isConstructor(String.prototype.fontcolor) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.fontcolor(); +}, '`new String.prototype.fontcolor()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/prop-desc.js new file mode 100644 index 0000000000..0473c209ce --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.fontcolor +es6id: B.2.3.7 +description: Property descriptor for String.prototype.fontcolor +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "fontcolor", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/this-val-tostring-err.js new file mode 100644 index 0000000000..2fdacd804b --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontcolor/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.fontcolor +es6id: B.2.3.7 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.fontcolor.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/B.2.3.8.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/B.2.3.8.js new file mode 100644 index 0000000000..b6f51d9f3b --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/B.2.3.8.js @@ -0,0 +1,30 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.fontsize returns a string of HTML describing a single + HTML font element. The element's content is the `this` value of the + function invocation, coerced to a string. If specified, the first argument + will be coerced to a string, escaped, and set as the element's `size` + attribute. + es6id: B.2.3.8 +---*/ + +assert.sameValue('_'.fontsize('b'), '<font size="b">_</font>'); +assert.sameValue('<'.fontsize('<'), '<font size="<"><</font>'); +assert.sameValue('_'.fontsize(0x2A), '<font size="42">_</font>'); +assert.sameValue('_'.fontsize('\x22'), '<font size=""">_</font>'); +assert.sameValue(String.prototype.fontsize.call(0x2A, 0x2A), + '<font size="42">42</font>'); +assert.throws(TypeError, function() { + String.prototype.fontsize.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.fontsize.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/attr-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/attr-tostring-err.js new file mode 100644 index 0000000000..be60430f40 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/attr-tostring-err.js @@ -0,0 +1,25 @@ +// 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-string.prototype.fontsize +es6id: B.2.3.8 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + [...] + 4. If attribute is not the empty String, then + a. Let V be ? ToString(value). +---*/ + +var attr = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.fontsize(attr); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/length.js new file mode 100644 index 0000000000..94cf9e7f4e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.8 +description: > + String.prototype.fontsize.length is 1. +info: | + String.prototype.fontsize ( size ) + + 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] +---*/ + +verifyProperty(String.prototype.fontsize, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/name.js new file mode 100644 index 0000000000..42d7b00105 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.8 +description: > + String.prototype.fontsize.name is "fontsize". +info: | + String.prototype.fontsize ( color ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.fontsize, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "fontsize" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/not-a-constructor.js new file mode 100644 index 0000000000..d221a1348a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.fontsize does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.fontsize), + false, + 'isConstructor(String.prototype.fontsize) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.fontsize(); +}, '`new String.prototype.fontsize()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/prop-desc.js new file mode 100644 index 0000000000..d25aceb2e8 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.fontsize +es6id: B.2.3.8 +description: Property descriptor for String.prototype.fontsize +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "fontsize", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/this-val-tostring-err.js new file mode 100644 index 0000000000..9bb7b11da6 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/fontsize/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.fontsize +es6id: B.2.3.8 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.fontsize.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/italics/B.2.3.9.js b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/B.2.3.9.js new file mode 100644 index 0000000000..5421037edb --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/B.2.3.9.js @@ -0,0 +1,25 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.italics returns a string of HTML describing a single HTML + italic element. The element's content is the `this` value of the function + invocation, coerced to a string. + es6id: B.2.3.9 +---*/ + +assert.sameValue('_'.italics(), '<i>_</i>'); +assert.sameValue('<'.italics(), '<i><</i>'); +assert.sameValue(String.prototype.italics.call(0x2A), '<i>42</i>'); +assert.throws(TypeError, function() { + String.prototype.italics.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.italics.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/italics/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/italics/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/length.js new file mode 100644 index 0000000000..1c2a517ffa --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.9 +description: > + String.prototype.italics.length is 0. +info: | + String.prototype.italics ( ) + + 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] +---*/ + +verifyProperty(String.prototype.italics, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/italics/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/name.js new file mode 100644 index 0000000000..56139bf62b --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.9 +description: > + String.prototype.italics.name is "italics". +info: | + String.prototype.italics ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.italics, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "italics" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/italics/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/not-a-constructor.js new file mode 100644 index 0000000000..4833d9b0e5 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.italics does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.italics), + false, + 'isConstructor(String.prototype.italics) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.italics(); +}, '`new String.prototype.italics()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/italics/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/prop-desc.js new file mode 100644 index 0000000000..041b5ad7f4 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.italics +es6id: B.2.3.9 +description: Property descriptor for String.prototype.italics +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "italics", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/italics/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/italics/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/this-val-tostring-err.js new file mode 100644 index 0000000000..db693918dd --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/italics/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.italics +es6id: B.2.3.9 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.italics.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/link/B.2.3.10.js b/js/src/tests/test262/annexB/built-ins/String/prototype/link/B.2.3.10.js new file mode 100644 index 0000000000..01d0268cdd --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/link/B.2.3.10.js @@ -0,0 +1,28 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.link returns a string of HTML describing a single HTML + link element. The element's content is the `this` value of the function + invocation, coerced to a string. If specified, the first argument will be + coerced to a string, escaped, and set as the element's `href` attribute. + es6id: B.2.3.10 +---*/ + +assert.sameValue('_'.link('b'), '<a href="b">_</a>'); +assert.sameValue('<'.link('<'), '<a href="<"><</a>'); +assert.sameValue('_'.link(0x2A), '<a href="42">_</a>'); +assert.sameValue('_'.link('\x22'), '<a href=""">_</a>'); +assert.sameValue(String.prototype.link.call(0x2A, 0x2A), '<a href="42">42</a>'); +assert.throws(TypeError, function() { + String.prototype.link.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.link.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/link/attr-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/link/attr-tostring-err.js new file mode 100644 index 0000000000..88b6d3e301 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/link/attr-tostring-err.js @@ -0,0 +1,25 @@ +// 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-string.prototype.link +es6id: B.2.3.10 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + [...] + 4. If attribute is not the empty String, then + a. Let V be ? ToString(value). +---*/ + +var attr = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.link(attr); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/link/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/link/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/link/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/link/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/link/length.js new file mode 100644 index 0000000000..f51904e982 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/link/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.10 +description: > + String.prototype.link.length is 1. +info: | + String.prototype.link ( url ) + + 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] +---*/ + +verifyProperty(String.prototype.link, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/link/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/link/name.js new file mode 100644 index 0000000000..fb7ea3ee2a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/link/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.10 +description: > + String.prototype.link.name is "link". +info: | + String.prototype.link ( url ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.link, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "link" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/link/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/link/not-a-constructor.js new file mode 100644 index 0000000000..afd8d81733 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/link/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.link does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.link), + false, + 'isConstructor(String.prototype.link) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.link(); +}, '`new String.prototype.link()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/link/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/link/prop-desc.js new file mode 100644 index 0000000000..75bf7df731 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/link/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.link +es6id: B.2.3.10 +description: Property descriptor for String.prototype.link +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "link", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/link/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/link/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/link/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/link/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/link/this-val-tostring-err.js new file mode 100644 index 0000000000..b14c932f59 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/link/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.link +es6id: B.2.3.10 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.link.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/match/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/match/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/match/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/match/custom-matcher-emulates-undefined.js b/js/src/tests/test262/annexB/built-ins/String/prototype/match/custom-matcher-emulates-undefined.js new file mode 100644 index 0000000000..55e6d28feb --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/match/custom-matcher-emulates-undefined.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.match +description: > + [[IsHTMLDDA]] object as @@match method gets called. +info: | + String.prototype.match ( regexp ) + + [...] + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@match). + b. If matcher is not undefined, then + i. Return ? Call(matcher, regexp, « O »). +features: [Symbol.match, IsHTMLDDA] +---*/ + +var regexp = $262.IsHTMLDDA; +var matcherGets = 0; +Object.defineProperty(regexp, Symbol.match, { + get: function() { + matcherGets += 1; + return regexp; + }, + configurable: true, +}); + +assert.sameValue("".match(regexp), null); +assert.sameValue(matcherGets, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/match/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/match/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/match/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/matchAll/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/matchAll/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/matchAll/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/matchAll/custom-matcher-emulates-undefined.js b/js/src/tests/test262/annexB/built-ins/String/prototype/matchAll/custom-matcher-emulates-undefined.js new file mode 100644 index 0000000000..5abb9d10d3 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/matchAll/custom-matcher-emulates-undefined.js @@ -0,0 +1,32 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.matchall +description: > + [[IsHTMLDDA]] object as @@matchAll method gets called. +info: | + String.prototype.matchAll ( regexp ) + + [...] + 2. If regexp is neither undefined nor null, then + [...] + c. Let matcher be ? GetMethod(regexp, @@matchAll). + d. If matcher is not undefined, then + i. Return ? Call(matcher, regexp, « O »). +features: [Symbol.matchAll, String.prototype.matchAll, IsHTMLDDA] +---*/ + +var regexp = $262.IsHTMLDDA; +var matcherGets = 0; +Object.defineProperty(regexp, Symbol.matchAll, { + get: function() { + matcherGets += 1; + return regexp; + }, + configurable: true, +}); + +assert.sameValue("".matchAll(regexp), null); +assert.sameValue(matcherGets, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/matchAll/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/matchAll/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/matchAll/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/replace/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/replace/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/replace/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/replace/custom-replacer-emulates-undefined.js b/js/src/tests/test262/annexB/built-ins/String/prototype/replace/custom-replacer-emulates-undefined.js new file mode 100644 index 0000000000..07c5ad606f --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/replace/custom-replacer-emulates-undefined.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.replace +description: > + [[IsHTMLDDA]] object as @@replace method gets called. +info: | + String.prototype.replace ( searchValue, replaceValue ) + + [...] + 2. If searchValue is neither undefined nor null, then + a. Let replacer be ? GetMethod(searchValue, @@replace). + b. If replacer is not undefined, then + i. Return ? Call(replacer, searchValue, « O, replaceValue »). +features: [Symbol.replace, IsHTMLDDA] +---*/ + +var searchValue = $262.IsHTMLDDA; +var replacerGets = 0; +Object.defineProperty(searchValue, Symbol.replace, { + get: function() { + replacerGets += 1; + return searchValue; + }, + configurable: true, +}); + +assert.sameValue("".replace(searchValue), null); +assert.sameValue(replacerGets, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/replace/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/replace/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/replace/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/replaceAll/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/replaceAll/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/replaceAll/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/replaceAll/custom-replacer-emulates-undefined.js b/js/src/tests/test262/annexB/built-ins/String/prototype/replaceAll/custom-replacer-emulates-undefined.js new file mode 100644 index 0000000000..7fec73440a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/replaceAll/custom-replacer-emulates-undefined.js @@ -0,0 +1,32 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.replaceall +description: > + [[IsHTMLDDA]] object as @@replace method gets called. +info: | + String.prototype.replaceAll ( searchValue, replaceValue ) + + [...] + 2. If searchValue is neither undefined nor null, then + [...] + c. Let replacer be ? GetMethod(searchValue, @@replace). + d. If replacer is not undefined, then + i. Return ? Call(replacer, searchValue, « O, replaceValue »). +features: [Symbol.replace, String.prototype.replaceAll, IsHTMLDDA] +---*/ + +var searchValue = $262.IsHTMLDDA; +var replacerGets = 0; +Object.defineProperty(searchValue, Symbol.replace, { + get: function() { + replacerGets += 1; + return searchValue; + }, + configurable: true, +}); + +assert.sameValue("".replaceAll(searchValue), null); +assert.sameValue(replacerGets, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/replaceAll/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/replaceAll/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/replaceAll/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/search/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/search/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/search/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/search/custom-searcher-emulates-undefined.js b/js/src/tests/test262/annexB/built-ins/String/prototype/search/custom-searcher-emulates-undefined.js new file mode 100644 index 0000000000..d96bbb1ff7 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/search/custom-searcher-emulates-undefined.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.search +description: > + [[IsHTMLDDA]] object as @@search method gets called. +info: | + String.prototype.search ( regexp ) + + [...] + 2. If regexp is neither undefined nor null, then + a. Let searcher be ? GetMethod(regexp, @@search). + b. If searcher is not undefined, then + i. Return ? Call(searcher, regexp, « O »). +features: [Symbol.search, IsHTMLDDA] +---*/ + +var regexp = $262.IsHTMLDDA; +var searcherGets = 0; +Object.defineProperty(regexp, Symbol.search, { + get: function() { + searcherGets += 1; + return regexp; + }, + configurable: true, +}); + +assert.sameValue("".search(regexp), null); +assert.sameValue(searcherGets, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/search/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/search/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/search/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/small/B.2.3.11.js b/js/src/tests/test262/annexB/built-ins/String/prototype/small/B.2.3.11.js new file mode 100644 index 0000000000..52274f8b0a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/small/B.2.3.11.js @@ -0,0 +1,25 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.small returns a string of HTML describing a single HTML + small print element. The element's content is the `this` value of the + function invocation, coerced to a string. + es6id: B.2.3.11 +---*/ + +assert.sameValue('_'.small(), '<small>_</small>'); +assert.sameValue('<'.small(), '<small><</small>'); +assert.sameValue(String.prototype.small.call(0x2A), '<small>42</small>'); +assert.throws(TypeError, function() { + String.prototype.small.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.small.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/small/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/small/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/small/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/small/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/small/length.js new file mode 100644 index 0000000000..0809743f95 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/small/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.11 +description: > + String.prototype.small.length is 0. +info: | + String.prototype.small ( ) + + 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] +---*/ + +verifyProperty(String.prototype.small, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/small/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/small/name.js new file mode 100644 index 0000000000..cc439add06 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/small/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.11 +description: > + String.prototype.small.name is "small". +info: | + String.prototype.small ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.small, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "small" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/small/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/small/not-a-constructor.js new file mode 100644 index 0000000000..a0a9aa6090 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/small/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.small does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.small), + false, + 'isConstructor(String.prototype.small) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.small(); +}, '`new String.prototype.small()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/small/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/small/prop-desc.js new file mode 100644 index 0000000000..631b31349d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/small/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.small +es6id: B.2.3.11 +description: Property descriptor for String.prototype.small +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "small", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/small/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/small/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/small/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/small/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/small/this-val-tostring-err.js new file mode 100644 index 0000000000..b546cc6ea7 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/small/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.small +es6id: B.2.3.11 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.small.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/split/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/split/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/split/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/split/custom-splitter-emulates-undefined.js b/js/src/tests/test262/annexB/built-ins/String/prototype/split/custom-splitter-emulates-undefined.js new file mode 100644 index 0000000000..fe120958cd --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/split/custom-splitter-emulates-undefined.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.split +description: > + [[IsHTMLDDA]] object as @@split method gets called. +info: | + String.prototype.split ( separator, limit ) + + [...] + 2. If separator is neither undefined nor null, then + a. Let splitter be ? GetMethod(separator, @@split). + b. If splitter is not undefined, then + i. Return ? Call(splitter, separator, « O, limit »). +features: [Symbol.split, IsHTMLDDA] +---*/ + +var separator = $262.IsHTMLDDA; +var splitterGets = 0; +Object.defineProperty(separator, Symbol.split, { + get: function() { + splitterGets += 1; + return separator; + }, + configurable: true, +}); + +assert.sameValue("".split(separator), null); +assert.sameValue(splitterGets, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/split/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/split/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/split/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/strike/B.2.3.12.js b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/B.2.3.12.js new file mode 100644 index 0000000000..7fef1de75d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/B.2.3.12.js @@ -0,0 +1,25 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.strike returns a string of HTML describing a single HTML + strikethrough element. The element's content is the `this` value of the + function invocation, coerced to a string. + es6id: B.2.3.12 +---*/ + +assert.sameValue('_'.strike(), '<strike>_</strike>'); +assert.sameValue('<'.strike(), '<strike><</strike>'); +assert.sameValue(String.prototype.strike.call(0x2A), '<strike>42</strike>'); +assert.throws(TypeError, function() { + String.prototype.strike.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.strike.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/strike/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/strike/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/length.js new file mode 100644 index 0000000000..7fc3ac2ff0 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.12 +description: > + String.prototype.strike.length is 0. +info: | + String.prototype.strike ( ) + + 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] +---*/ + +verifyProperty(String.prototype.strike, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/strike/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/name.js new file mode 100644 index 0000000000..ed8b2cc4d9 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.12 +description: > + String.prototype.strike.name is "strike". +info: | + String.prototype.strike ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.strike, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "strike" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/strike/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/not-a-constructor.js new file mode 100644 index 0000000000..5f7bc6cbd1 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.strike does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.strike), + false, + 'isConstructor(String.prototype.strike) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.strike(); +}, '`new String.prototype.strike()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/strike/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/prop-desc.js new file mode 100644 index 0000000000..61061060d1 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.strike +es6id: B.2.3.12 +description: Property descriptor for String.prototype.strike +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "strike", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/strike/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/strike/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/this-val-tostring-err.js new file mode 100644 index 0000000000..77cd44264e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/strike/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.strike +es6id: B.2.3.12 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.strike.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sub/B.2.3.13.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/B.2.3.13.js new file mode 100644 index 0000000000..53f0bcda58 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/B.2.3.13.js @@ -0,0 +1,25 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.sub returns a string of HTML describing a single HTML + subscript element. The element's content is the `this` value of the + function invocation, coerced to a string. + es6id: B.2.3.13 +---*/ + +assert.sameValue('_'.sub(), '<sub>_</sub>'); +assert.sameValue('<'.sub(), '<sub><</sub>'); +assert.sameValue(String.prototype.sub.call(0x2A), '<sub>42</sub>'); +assert.throws(TypeError, function() { + String.prototype.sub.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.sub.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sub/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sub/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/length.js new file mode 100644 index 0000000000..974cc7036a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.13 +description: > + String.prototype.sub.length is 0. +info: | + String.prototype.sub ( ) + + 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] +---*/ + +verifyProperty(String.prototype.sub, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sub/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/name.js new file mode 100644 index 0000000000..4b2ed6a5d4 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.13 +description: > + String.prototype.sub.name is "sub". +info: | + String.prototype.sub ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.sub, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "sub" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sub/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/not-a-constructor.js new file mode 100644 index 0000000000..3c8b054e9a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/not-a-constructor.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.sub does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(String.prototype.sub), false, 'isConstructor(String.prototype.sub) must return false'); + +assert.throws(TypeError, () => { + new String.prototype.sub(); +}, '`new String.prototype.sub()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sub/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/prop-desc.js new file mode 100644 index 0000000000..775210ff41 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.sub +es6id: B.2.3.13 +description: Property descriptor for String.prototype.sub +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "sub", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sub/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sub/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/this-val-tostring-err.js new file mode 100644 index 0000000000..1b91b44e57 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sub/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.sub +es6id: B.2.3.13 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.sub.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/B.2.3.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/B.2.3.js new file mode 100644 index 0000000000..fb9eb065b8 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/B.2.3.js @@ -0,0 +1,18 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: B.2.3 +description: > + Object.getOwnPropertyDescriptor returns data desc for functions on + built-ins (String.prototype.substr) +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "substr", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-falsey.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-falsey.js new file mode 100644 index 0000000000..3de74fd5cf --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-falsey.js @@ -0,0 +1,39 @@ +// 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-string.prototype.substr +es6id: B.2.3.1 +description: > + Behavior when "length" is a false-converting value other than `undefined` +info: | + [...] + 4. If length is undefined, let end be +∞; otherwise let end be ? + ToInteger(length). + [...] + 7. Let resultLength be min(max(end, 0), size - intStart). + 8. If resultLength ≤ 0, return the empty String "". + 9. Return a String containing resultLength consecutive code units from S + beginning with the code unit at index intStart. +---*/ + +assert.sameValue('abc'.substr(0, false), '', 'start: 0, length: false'); +assert.sameValue('abc'.substr(1, false), '', 'start: 1, length: false'); +assert.sameValue('abc'.substr(2, false), '', 'start: 2, length: false'); +assert.sameValue('abc'.substr(3, false), '', 'start: 3, length: false'); + +assert.sameValue('abc'.substr(0, NaN), '', 'start: 0, length: NaN'); +assert.sameValue('abc'.substr(1, NaN), '', 'start: 1, length: NaN'); +assert.sameValue('abc'.substr(2, NaN), '', 'start: 2, length: NaN'); +assert.sameValue('abc'.substr(3, NaN), '', 'start: 3, length: NaN'); + +assert.sameValue('abc'.substr(0, ''), '', 'start: 0, length: ""'); +assert.sameValue('abc'.substr(1, ''), '', 'start: 1, length: ""'); +assert.sameValue('abc'.substr(2, ''), '', 'start: 2, length: ""'); +assert.sameValue('abc'.substr(3, ''), '', 'start: 3, length: ""'); + +assert.sameValue('abc'.substr(0, null), '', 'start: 0, length: null'); +assert.sameValue('abc'.substr(1, null), '', 'start: 1, length: null'); +assert.sameValue('abc'.substr(2, null), '', 'start: 2, length: null'); +assert.sameValue('abc'.substr(3, null), '', 'start: 3, length: null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-negative.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-negative.js new file mode 100644 index 0000000000..48e90b1aac --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-negative.js @@ -0,0 +1,33 @@ +// 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-string.prototype.substr +es6id: B.2.3.1 +description: Behavior when "length" is a negative number +info: | + [...] + 7. Let resultLength be min(max(end, 0), size - intStart). + 8. If resultLength ≤ 0, return the empty String "". +---*/ + +assert.sameValue('abc'.substr(0, -1), '', '0, -1'); +assert.sameValue('abc'.substr(0, -2), '', '0, -2'); +assert.sameValue('abc'.substr(0, -3), '', '0, -3'); +assert.sameValue('abc'.substr(0, -4), '', '0, -4'); + +assert.sameValue('abc'.substr(1, -1), '', '1, -1'); +assert.sameValue('abc'.substr(1, -2), '', '1, -2'); +assert.sameValue('abc'.substr(1, -3), '', '1, -3'); +assert.sameValue('abc'.substr(1, -4), '', '1, -4'); + +assert.sameValue('abc'.substr(2, -1), '', '2, -1'); +assert.sameValue('abc'.substr(2, -2), '', '2, -2'); +assert.sameValue('abc'.substr(2, -3), '', '2, -3'); +assert.sameValue('abc'.substr(2, -4), '', '2, -4'); + +assert.sameValue('abc'.substr(3, -1), '', '3, -1'); +assert.sameValue('abc'.substr(3, -2), '', '3, -2'); +assert.sameValue('abc'.substr(3, -3), '', '3, -3'); +assert.sameValue('abc'.substr(3, -4), '', '3, -4'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-positive.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-positive.js new file mode 100644 index 0000000000..e95b688bd7 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-positive.js @@ -0,0 +1,38 @@ +// 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-string.prototype.substr +es6id: B.2.3.1 +description: Behavior when "length" is a positive number +info: | + [...] + 4. If length is undefined, let end be +∞; otherwise let end be ? + ToInteger(length). + [...] + 7. Let resultLength be min(max(end, 0), size - intStart). + 8. If resultLength ≤ 0, return the empty String "". + 9. Return a String containing resultLength consecutive code units from S + beginning with the code unit at index intStart. +---*/ + +assert.sameValue('abc'.substr(0, 1), 'a', '0, 1'); +assert.sameValue('abc'.substr(0, 2), 'ab', '0, 1'); +assert.sameValue('abc'.substr(0, 3), 'abc', '0, 1'); +assert.sameValue('abc'.substr(0, 4), 'abc', '0, 1'); + +assert.sameValue('abc'.substr(1, 1), 'b', '1, 1'); +assert.sameValue('abc'.substr(1, 2), 'bc', '1, 1'); +assert.sameValue('abc'.substr(1, 3), 'bc', '1, 1'); +assert.sameValue('abc'.substr(1, 4), 'bc', '1, 1'); + +assert.sameValue('abc'.substr(2, 1), 'c', '2, 1'); +assert.sameValue('abc'.substr(2, 2), 'c', '2, 1'); +assert.sameValue('abc'.substr(2, 3), 'c', '2, 1'); +assert.sameValue('abc'.substr(2, 4), 'c', '2, 1'); + +assert.sameValue('abc'.substr(3, 1), '', '3, 1'); +assert.sameValue('abc'.substr(3, 2), '', '3, 1'); +assert.sameValue('abc'.substr(3, 3), '', '3, 1'); +assert.sameValue('abc'.substr(3, 4), '', '3, 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-to-int-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-to-int-err.js new file mode 100644 index 0000000000..fe367827b0 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-to-int-err.js @@ -0,0 +1,29 @@ +// 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-string.prototype.substr +es6id: B.2.3.1 +description: > + Behavior when "length" integer conversion triggers an abrupt completion +info: | + [...] + 3. Let intStart be ? ToInteger(start). +features: [Symbol] +---*/ + +var symbol = Symbol(''); +var len = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.substr(0, len); +}); + +assert.throws(TypeError, function() { + ''.substr(0, symbol); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-undef.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-undef.js new file mode 100644 index 0000000000..abaee99f0e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length-undef.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-string.prototype.substr +es6id: B.2.3.1 +description: Behavior when "length" is not defined +info: | + [...] + 4. If length is undefined, let end be +∞; otherwise let end be ? + ToInteger(length). + [...] + 7. Let resultLength be min(max(end, 0), size - intStart). + 8. If resultLength ≤ 0, return the empty String "". + 9. Return a String containing resultLength consecutive code units from S + beginning with the code unit at index intStart. +---*/ + +assert.sameValue('abc'.substr(0), 'abc', 'start: 0, length: unspecified'); +assert.sameValue('abc'.substr(1), 'bc', 'start: 1, length: unspecified'); +assert.sameValue('abc'.substr(2), 'c', 'start: 2, length: unspecified'); +assert.sameValue('abc'.substr(3), '', 'start: 3, length: unspecified'); + +assert.sameValue( + 'abc'.substr(0, undefined), 'abc', 'start: 0, length: undefined' +); +assert.sameValue( + 'abc'.substr(1, undefined), 'bc', 'start: 1, length: undefined' +); +assert.sameValue( + 'abc'.substr(2, undefined), 'c', 'start: 2, length: undefined' +); +assert.sameValue( + 'abc'.substr(3, undefined), '', 'start: 3, length: undefined' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length.js new file mode 100644 index 0000000000..93654798c4 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.1 +description: > + String.prototype.substr.length is 2. +info: | + String.prototype.substr (start, length) + + 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] +---*/ + +verifyProperty(String.prototype.substr, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 2 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/name.js new file mode 100644 index 0000000000..d9b3306250 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.1 +description: > + String.prototype.substr.name is "substr". +info: | + String.prototype.substr (start, length) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.substr, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "substr" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/not-a-constructor.js new file mode 100644 index 0000000000..821d6473a4 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/not-a-constructor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.substr does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.substr), + false, + 'isConstructor(String.prototype.substr) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.substr(); +}, '`new String.prototype.substr()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/start-and-length-as-numbers.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/start-and-length-as-numbers.js new file mode 100644 index 0000000000..0b0df5427a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/start-and-length-as-numbers.js @@ -0,0 +1,94 @@ +// Copyright (C) 2022 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.substr +description: > + Test String.prototype.substr with number inputs for start and length. +---*/ + +function ToIntegerOrInfinity(arg) { + assert.sameValue(typeof arg, "number"); + + return Number.isNaN(arg) ? 0 : Math.trunc(arg); +} + +// Basic reference implementation. Expects all inputs have the correct type. +function StringSubstr(string, start, length) { + // Steps 1-2. + assert.sameValue(typeof string, "string"); + + // Step 3. + let size = string.length; + + // Step 4. + let intStart = ToIntegerOrInfinity(start); + + // Steps 5-7. + if (intStart === -Infinity) { + intStart = 0; + } else if (intStart < 0) { + intStart = Math.max(size + intStart, 0); + } else { + intStart = Math.min(intStart, size) + } + + // |0 <= intStart <= size| now holds. + assert(0 <= intStart && intStart <= size); + + // Step 8. + let intLength = length === undefined ? size : ToIntegerOrInfinity(length); + + // Step 9. + intLength = Math.min(Math.max(intLength, 0), size); + + // |0 <= intLength <= size| now holds. + assert(0 <= intLength && intLength <= size); + + // Step 10. + let intEnd = Math.min(intStart + intLength, size); + + // |intStart <= intEnd <= size| now holds. + assert(intStart <= intEnd && intEnd <= size); + + // Step 11. + // + // Call `substring` and check the result is correct. + let result = string.substring(intStart, intEnd); + + assert.sameValue(result.length, intEnd - intStart); + + for (let i = 0; i < result.length; ++i) { + assert.sameValue(result[i], string[intStart + i]); + } + + return result; +} + +const positiveIntegers = [ + 0, 1, 2, 3, 4, 5, 10, 100, +]; + +const integers = [ + ...positiveIntegers, + ...positiveIntegers.map(v => -v), +]; + +const numbers = [ + ...integers, + ...integers.map(v => v + 0.5), + -Infinity, Infinity, NaN, +]; + +for (let string of ["", "a", "ab", "abc"]) { + for (let start of numbers) { + for (let length of [...numbers, undefined]) { + let actual = string.substr(start, length); + let expected = StringSubstr(string, start, length); + + assert.sameValue(actual, expected, `"${string}".substr(${start}, ${length})`); + } + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/start-negative.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/start-negative.js new file mode 100644 index 0000000000..de56b29e68 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/start-negative.js @@ -0,0 +1,19 @@ +// 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-string.prototype.substr +es6id: B.2.3.1 +description: Behavior when "start" is a negative number +info: | + [...] + 6. If intStart < 0, let intStart be max(size + intStart, 0). +---*/ + +assert.sameValue('abc'.substr(-1), 'c'); +assert.sameValue('abc'.substr(-2), 'bc'); +assert.sameValue('abc'.substr(-3), 'abc'); +assert.sameValue('abc'.substr(-4), 'abc', 'size + intStart < 0'); + +assert.sameValue('abc'.substr(-1.1), 'c', 'floating point rounding semantics'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/start-to-int-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/start-to-int-err.js new file mode 100644 index 0000000000..4511de91ba --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/start-to-int-err.js @@ -0,0 +1,37 @@ +// 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-string.prototype.substr +es6id: B.2.3.1 +description: > + Behavior when "start" integer conversion triggers an abrupt completion +info: | + [...] + 3. Let intStart be ? ToInteger(start). +features: [Symbol] +---*/ + +var lengthCallCount = 0; +var symbol = Symbol(''); +var start = { + valueOf: function() { + throw new Test262Error(); + } +}; +var len = { + valueOf: function() { + lengthCallCount += 1; + } +}; + +assert.throws(Test262Error, function() { + ''.substr(start, len); +}); + +assert.throws(TypeError, function() { + ''.substr(symbol, len); +}); + +assert.sameValue(lengthCallCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/surrogate-pairs.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/surrogate-pairs.js new file mode 100644 index 0000000000..605596d335 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/surrogate-pairs.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-string.prototype.substr +es6id: B.2.3.1 +description: > + Behavior when input string contains a surrogate pair +info: | + [...] + 4. If length is undefined, let end be +∞; otherwise let end be ? + ToInteger(length). + [...] + 7. Let resultLength be min(max(end, 0), size - intStart). + 8. If resultLength ≤ 0, return the empty String "". + 9. Return a String containing resultLength consecutive code units from S + beginning with the code unit at index intStart. +---*/ + +assert.sameValue('\ud834\udf06'.substr(0), '\ud834\udf06', 'start: 0'); +assert.sameValue('\ud834\udf06'.substr(1), '\udf06', 'start: 1'); +assert.sameValue('\ud834\udf06'.substr(2), '', 'start: 2'); +assert.sameValue('\ud834\udf06'.substr(0, 0), '', 'end: 0'); +assert.sameValue('\ud834\udf06'.substr(0, 1), '\ud834', 'end: 1'); +assert.sameValue('\ud834\udf06'.substr(0, 2), '\ud834\udf06', 'end: 2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/this-non-obj-coerce.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/this-non-obj-coerce.js new file mode 100644 index 0000000000..7036c9e250 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/this-non-obj-coerce.js @@ -0,0 +1,23 @@ +// 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-string.prototype.substr +es6id: B.2.3.1 +description: Behavior when "this" value is not Object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var substr = String.prototype.substr; + +assert.sameValue(typeof substr, 'function'); + +assert.throws(TypeError, function() { + substr.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + substr.call(null); +}, 'null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/substr/this-to-str-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/this-to-str-err.js new file mode 100644 index 0000000000..669f572a04 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/substr/this-to-str-err.js @@ -0,0 +1,23 @@ +// 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-string.prototype.substr +es6id: B.2.3.1 +description: Behavior when string conversion triggers an abrupt completion +info: | + 1. Let O be ? RequireObjectCoercible(this value). + 2. Let S be ? ToString(O). +---*/ + +var substr = String.prototype.substr; +var thisValue = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + substr.call(thisValue); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sup/B.2.3.14.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/B.2.3.14.js new file mode 100644 index 0000000000..a54131b658 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/B.2.3.14.js @@ -0,0 +1,25 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +// Tests taken from: +// http://mathias.html5.org/tests/javascript/string/ + +/*--- + description: > + String.prototype.sup returns a string of HTML describing a single HTML + superscript element. The element's content is the `this` value of the + function invocation, coerced to a string. + es6id: B.2.3.14 +---*/ + +assert.sameValue('_'.sup(), '<sup>_</sup>'); +assert.sameValue('<'.sup(), '<sup><</sup>'); +assert.sameValue(String.prototype.sup.call(0x2A), '<sup>42</sup>'); +assert.throws(TypeError, function() { + String.prototype.sup.call(undefined); +}); +assert.throws(TypeError, function() { + String.prototype.sup.call(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sup/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sup/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/length.js new file mode 100644 index 0000000000..d05dc61b42 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.14 +description: > + String.prototype.sup.length is 0. +info: | + String.prototype.sup ( ) + + 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] +---*/ + +verifyProperty(String.prototype.sup, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sup/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/name.js new file mode 100644 index 0000000000..054d5484ef --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.3.14 +description: > + String.prototype.sup.name is "sup". +info: | + String.prototype.sup ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(String.prototype.sup, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "sup" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sup/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/not-a-constructor.js new file mode 100644 index 0000000000..461a34d60e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/not-a-constructor.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.sup does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(String.prototype.sup), false, 'isConstructor(String.prototype.sup) must return false'); + +assert.throws(TypeError, () => { + new String.prototype.sup(); +}, '`new String.prototype.sup()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sup/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/prop-desc.js new file mode 100644 index 0000000000..c22448d3fb --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/prop-desc.js @@ -0,0 +1,20 @@ +// 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-string.prototype.sup +es6id: B.2.3.14 +description: Property descriptor for String.prototype.sup +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(String.prototype, "sup", { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sup/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/sup/this-val-tostring-err.js b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/this-val-tostring-err.js new file mode 100644 index 0000000000..ef2669921f --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/sup/this-val-tostring-err.js @@ -0,0 +1,24 @@ +// 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-string.prototype.sup +es6id: B.2.3.14 +description: Abrupt completion when coercing "this" value to string +info: | + B.2.3.2.1 Runtime Semantics: CreateHTML + + 1. Let str be ? RequireObjectCoercible(string). + 2. Let S be ? ToString(str). +---*/ + +var thisVal = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.sup.call(thisVal); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/length.js new file mode 100644 index 0000000000..76d4b87fc5 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.trimLeft +description: > + String.prototype.trimLeft.length is 0. +info: > + String.prototype.trimLeft ( ) + + 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] +features: [string-trimming] +---*/ + +verifyProperty(String.prototype.trimLeft, "length", { + value: 0, + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/name.js new file mode 100644 index 0000000000..277da5d95f --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/name.js @@ -0,0 +1,24 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.trimLeft +description: > + String.prototype.trimLeft.name is "trimStart". +info: > + String.prototype.trimLeft ( ) + + The function object that is the initial value of String.prototype.trimLeft is the same function object that is the initial value of String.prototype.trimStart. + +includes: [propertyHelper.js] +features: [string-trimming, String.prototype.trimStart] +---*/ + +verifyProperty(String.prototype.trimLeft, "name", { + value: "trimStart", + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/prop-desc.js new file mode 100644 index 0000000000..f1589dbacc --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/prop-desc.js @@ -0,0 +1,24 @@ +// Copyright (C) 2017 The Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.trimLeft +description: > + "trimLeft" property of String.prototype +info: > + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [string-trimming] +---*/ + +verifyProperty(String.prototype, "trimLeft", { + enumerable: false, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/reference-trimStart.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/reference-trimStart.js new file mode 100644 index 0000000000..d9c709aff1 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/reference-trimStart.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.trimLeft +description: > + String.prototype.trimLeft is a reference to String.prototype.trimStart. +info: > + String.prototype.trimLeft ( ) + + The function object that is the initial value of String.prototype.trimLeft + is the same function object that is the initial value of + String.prototype.trimStart. +features: [string-trimming] +---*/ + +assert.sameValue(String.prototype.trimLeft, String.prototype.trimStart); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimLeft/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/browser.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/length.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/length.js new file mode 100644 index 0000000000..53ece40072 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.trimRight +description: > + String.prototype.trimRight.length is 0. +info: > + String.prototype.trimRight ( ) + + 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] +features: [string-trimming] +---*/ + +verifyProperty(String.prototype.trimRight, "length", { + value: 0, + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/name.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/name.js new file mode 100644 index 0000000000..43f7b94849 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/name.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.trimRight +description: > + String.prototype.trimRight.name is "trimEnd". +info: > + String.prototype.trimRight ( )# + + The function object that is the initial value of String.prototype.trimRight is the same function object that is the initial value of String.prototype.trimEnd. +includes: [propertyHelper.js] +features: [string-trimming, String.prototype.trimEnd] +---*/ + +verifyProperty(String.prototype.trimRight, "name", { + value: "trimEnd", + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/prop-desc.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/prop-desc.js new file mode 100644 index 0000000000..a2b1e52c90 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/prop-desc.js @@ -0,0 +1,24 @@ +// Copyright (C) 2017 The Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.trimRight +description: > + "trimRight" property of String.prototype +info: > + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [string-trimming] +---*/ + +verifyProperty(String.prototype, "trimRight", { + enumerable: false, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/reference-trimEnd.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/reference-trimEnd.js new file mode 100644 index 0000000000..23a375af15 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/reference-trimEnd.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.trimRight +description: > + String.prototype.trimRight is a reference to String.prototype.trimEnd. +info: > + String.prototype.trimRight ( ) + + The function object that is the initial value of String.prototype.trimRight + is the same function object that is the initial value of + String.prototype.trimEnd. +features: [string-trimming] +---*/ + +assert.sameValue(String.prototype.trimRight, String.prototype.trimEnd); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/shell.js b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/prototype/trimRight/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/String/shell.js b/js/src/tests/test262/annexB/built-ins/String/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/String/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/browser.js b/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/from/browser.js b/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/from/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/from/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/from/iterator-method-emulates-undefined.js b/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/from/iterator-method-emulates-undefined.js new file mode 100644 index 0000000000..5e41a374eb --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/from/iterator-method-emulates-undefined.js @@ -0,0 +1,37 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + [[IsHTMLDDA]] object as @@iterator method gets called. +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + [...] + 5. Let usingIterator be ? GetMethod(items, @@iterator). + 6. If usingIterator is not undefined, then + a. Let values be ? IterableToList(source, usingIterator). + + IterableToList ( items, method ) + + 1. Let iteratorRecord be ? GetIterator(items, sync, method). + + GetIterator ( obj [ , hint [ , method ] ] ) + + [...] + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. +includes: [testTypedArray.js] +features: [Symbol.iterator, TypedArray, IsHTMLDDA] +---*/ + +var items = {}; +items[Symbol.iterator] = $262.IsHTMLDDA; + +testWithTypedArrayConstructors(function(TypedArray) { + assert.throws(TypeError, function() { + TypedArray.from(items); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/from/shell.js b/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/from/shell.js new file mode 100644 index 0000000000..e9580b3113 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/from/shell.js @@ -0,0 +1,124 @@ +// GENERATED, DO NOT EDIT +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} diff --git a/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/shell.js b/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/TypedArrayConstructors/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/browser.js b/js/src/tests/test262/annexB/built-ins/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/escape/argument_bigint.js b/js/src/tests/test262/annexB/built-ins/escape/argument_bigint.js new file mode 100644 index 0000000000..20a0340cce --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/argument_bigint.js @@ -0,0 +1,18 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-escape-string +description: Input is a BigInt +info: | + B.2.1.1 escape ( string ) + + 1. Let string be ? ToString(string). + ... +features: [BigInt] +---*/ + +assert.sameValue(escape(1n), '1'); + +assert.sameValue(escape(-1n), '-1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/argument_types.js b/js/src/tests/test262/annexB/built-ins/escape/argument_types.js new file mode 100644 index 0000000000..cb04677445 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/argument_types.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-escape-string +description: Input is a null, undefined, boolean or Number +info: | + B.2.1.1 escape ( string ) + + 1. Let string be ? ToString(string). + ... +---*/ + +assert.sameValue(escape(null), 'null'); + +assert.sameValue(escape(undefined), 'undefined'); + +assert.sameValue(escape(), 'undefined'); + +assert.sameValue(escape(true), 'true'); + +assert.sameValue(escape(false), 'false'); + +assert.sameValue(escape(-0), '0'); + +assert.sameValue(escape(0), '0'); + +assert.sameValue(escape(1), '1'); + +assert.sameValue(escape(NaN), 'NaN'); + +assert.sameValue(escape(Number.POSITIVE_INFINITY), 'Infinity'); + +assert.sameValue(escape(Number.NEGATIVE_INFINITY), '-Infinity'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/browser.js b/js/src/tests/test262/annexB/built-ins/escape/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/escape/empty-string.js b/js/src/tests/test262/annexB/built-ins/escape/empty-string.js new file mode 100644 index 0000000000..65143c90d1 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/empty-string.js @@ -0,0 +1,19 @@ +// 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-escape-string +es6id: B.2.1.1 +description: Input is the empty string +info: | + 1. Let string be ? ToString(string). + 2. Let length be the number of code units in string. + 3. Let R be the empty string. + 4. Let k be 0. + 5. Repeat, while k < length, + [...] + 6. Return R. +---*/ + +assert.sameValue(escape(''), ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/escape-above-astral.js b/js/src/tests/test262/annexB/built-ins/escape/escape-above-astral.js new file mode 100644 index 0000000000..7ab8e7ed0d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/escape-above-astral.js @@ -0,0 +1,24 @@ +// Copyright (C) 2017 Microsoft Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-escape-string +es6id: B.2.1.1 +description: Escaping of code units above 255 from string with extended Unicode escape sequence +info: | + [...] + 5. Repeat, while k < length, + a. Let char be the code unit (represented as a 16-bit unsigned integer) + at index k within string. + [...] + c. Else if char ≥ 256, then + i. Let S be a String containing six code units "%uwxyz" where wxyz + are the code units of the four uppercase hexadecimal digits + encoding the value of char. + [...] +---*/ + +assert.sameValue( + escape('\u{10401}'), '%uD801%uDC01', '\\u{10401} => \\uD801\\uDC01 (surrogate pairs encoded in string)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/escape-above.js b/js/src/tests/test262/annexB/built-ins/escape/escape-above.js new file mode 100644 index 0000000000..347530476e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/escape-above.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-escape-string +es6id: B.2.1.1 +description: Escaping of code units above 255 +info: | + [...] + 5. Repeat, while k < length, + a. Let char be the code unit (represented as a 16-bit unsigned integer) + at index k within string. + [...] + c. Else if char ≥ 256, then + i. Let S be a String containing six code units "%uwxyz" where wxyz + are the code units of the four uppercase hexadecimal digits + encoding the value of char. + [...] +---*/ + +assert.sameValue( + escape('\u0100\u0101\u0102'), '%u0100%u0101%u0102', '\\u0100\\u0101\\u0102' +); + +assert.sameValue( + escape('\ufffd\ufffe\uffff'), '%uFFFD%uFFFE%uFFFF', '\\ufffd\\ufffd\\ufffd' +); + +assert.sameValue( + escape('\ud834\udf06'), '%uD834%uDF06', '\\ud834\\udf06 (surrogate pairs)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/escape-below.js b/js/src/tests/test262/annexB/built-ins/escape/escape-below.js new file mode 100644 index 0000000000..197fcf70e8 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/escape-below.js @@ -0,0 +1,56 @@ +// 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-escape-string +es6id: B.2.1.1 +description: Escaping of code units below 255 +info: | + [...] + 5. Repeat, while k < length, + a. Let char be the code unit (represented as a 16-bit unsigned integer) + at index k within string. + [...] + d. Else char < 256, + i. Let S be a String containing three code units "%xy" where xy are + the code units of two uppercase hexadecimal digits encoding the + value of char. + [...] +---*/ + +assert.sameValue( + escape('\x00\x01\x02\x03'), + '%00%01%02%03', + 'characters: \\x00\\x01\\x02\\x03' +); + +assert.sameValue( + escape('!"#$%&\'()'), + '%21%22%23%24%25%26%27%28%29', + 'characters preceding "*": !"#$%&\'()' +); + +assert.sameValue(escape(','), '%2C', 'character between "+" and "-": ,'); + +assert.sameValue( + escape(':;<=>?'), + '%3A%3B%3C%3D%3E%3F', + 'characters between "9" and "@": :;<=>?' +); + +assert.sameValue( + escape('[\\]^'), '%5B%5C%5D%5E', 'characters between "Z" and "_": [\\]^' +); + +assert.sameValue(escape('`'), '%60', 'character between "_" and "a": `'); + +assert.sameValue( + escape('{|}~\x7f\x80'), + '%7B%7C%7D%7E%7F%80', + 'characters following "z": {|}~\\x7f\\x80' +); + +assert.sameValue( + escape('\xfd\xfe\xff'), '%FD%FE%FF', '\\xfd\\xfe\\xff' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/length.js b/js/src/tests/test262/annexB/built-ins/escape/length.js new file mode 100644 index 0000000000..6d8c672f6e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.1.1 +description: > + escape.length is 1. +info: | + escape (string) + + 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] +---*/ + +verifyProperty(escape, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/name.js b/js/src/tests/test262/annexB/built-ins/escape/name.js new file mode 100644 index 0000000000..6a3cf986a1 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.1.1 +description: > + escape.name is "escape". +info: | + escape (string) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(escape, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "escape" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/escape/not-a-constructor.js new file mode 100644 index 0000000000..9fd1e0deb7 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/not-a-constructor.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + escape does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(escape), false, 'isConstructor(escape) must return false'); + +assert.throws(TypeError, () => { + new escape(''); +}, '`new escape(\'\')` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/prop-desc.js b/js/src/tests/test262/annexB/built-ins/escape/prop-desc.js new file mode 100644 index 0000000000..6669166aae --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/prop-desc.js @@ -0,0 +1,21 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: B.2.1 +description: > + Object.getOwnPropertyDescriptor returns data desc for functions on + built-ins (Global.escape) +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof this.escape, "function"); +assert.sameValue(typeof this["escape"], "function"); + +verifyProperty(this, "escape", { + writable: true, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/shell.js b/js/src/tests/test262/annexB/built-ins/escape/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/escape/to-primitive-err.js b/js/src/tests/test262/annexB/built-ins/escape/to-primitive-err.js new file mode 100644 index 0000000000..b172fe2b28 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/to-primitive-err.js @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-escape-string +description: If [Symbol.toPrimitive] method returned an object, it should throw a TypeError +info: | + B.2.1.1 escape ( string ) + + 1. Let string be ? ToString(string). + ... +features: [Symbol.toPrimitive] +---*/ + +var obj = { + toString() { throw new Test262Error('this should be unreachable'); }, + valueOf() { throw new Test262Error('this should be unreachable'); }, + [Symbol.toPrimitive]() { return function(){}; } +}; + +assert.throws(TypeError, function() { + escape(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/to-primitive-observe.js b/js/src/tests/test262/annexB/built-ins/escape/to-primitive-observe.js new file mode 100644 index 0000000000..4b0cc7935c --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/to-primitive-observe.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-escape-string +description: Observable operations from string coercion +info: | + B.2.1.1 escape ( string ) + + 1. Let string be ? ToString(string). + ... +features: [Symbol.toPrimitive] +---*/ + +var obj = { + toString() { throw new Test262Error('this should be unreachable'); }, + valueOf() { throw new Test262Error('this should be unreachable'); }, + [Symbol.toPrimitive]() { return 'success'; } +}; + +assert.sameValue(escape(obj), 'success'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/to-string-err-symbol.js b/js/src/tests/test262/annexB/built-ins/escape/to-string-err-symbol.js new file mode 100644 index 0000000000..6cd2663e3f --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/to-string-err-symbol.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-escape-string +es6id: B.2.1.1 +description: Abrupt completion from `ToString` operation (Symbol value) +info: | + 1. Let string be ? ToString(string). +features: [Symbol] +---*/ + +var s = Symbol(''); + +assert.throws(TypeError, function() { + escape(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/to-string-err.js b/js/src/tests/test262/annexB/built-ins/escape/to-string-err.js new file mode 100644 index 0000000000..5d5aaa8b2f --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/to-string-err.js @@ -0,0 +1,21 @@ +// 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-escape-string +es6id: B.2.1.1 +description: Abrupt completion from `ToString` operation +info: | + 1. Let string be ? ToString(string). +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + escape(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/to-string-observe.js b/js/src/tests/test262/annexB/built-ins/escape/to-string-observe.js new file mode 100644 index 0000000000..c9dcd49f99 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/to-string-observe.js @@ -0,0 +1,54 @@ +// 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-escape-string +es6id: B.2.1.1 +description: Observable operations from string coercion +info: | + 1. Let string be ? ToString(string). +---*/ + +var log, obj; + +log = ''; +obj = { + toString: function() { + log += 'toString'; + }, + valueOf: function() { + log += 'valueOf'; + } +}; + +escape(obj); + +assert.sameValue(log, 'toString'); + +log = ''; +obj = { + toString: null, + valueOf: function() { + log += 'valueOf'; + } +}; + +escape(obj); + +assert.sameValue(log, 'valueOf'); + +log = ''; +obj = { + toString: function() { + log += 'toString'; + return {}; + }, + valueOf: function() { + log += 'valueOf'; + } +}; + +escape(obj); + +assert.sameValue(log, 'toStringvalueOf'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/escape/unmodified.js b/js/src/tests/test262/annexB/built-ins/escape/unmodified.js new file mode 100644 index 0000000000..0f8e82c4ae --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/escape/unmodified.js @@ -0,0 +1,23 @@ +// 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-escape-string +es6id: B.2.1.1 +description: Do not escape a specific set of characters +info: | + [...] + 5. Repeat, while k < length, + a. Let char be the code unit (represented as a 16-bit unsigned integer) + at index k within string. + b. If char is one of the code units in + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./", + then + i. Let S be a String containing the single code unit char. + [...] +---*/ + +var passthrough = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./'; + +assert.sameValue(escape(passthrough), passthrough); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/shell.js b/js/src/tests/test262/annexB/built-ins/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/shell.js diff --git a/js/src/tests/test262/annexB/built-ins/unescape/argument_bigint.js b/js/src/tests/test262/annexB/built-ins/unescape/argument_bigint.js new file mode 100644 index 0000000000..00f17cb5e7 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/argument_bigint.js @@ -0,0 +1,18 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-unescape-string +description: Input is a BigInt +info: | + B.2.1.2 unescape ( string ) + + 1. Set string to ? ToString(string). + .... +features: [BigInt] +---*/ + +assert.sameValue(unescape(1n), '1'); + +assert.sameValue(unescape(-1n), '-1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/argument_types.js b/js/src/tests/test262/annexB/built-ins/unescape/argument_types.js new file mode 100644 index 0000000000..008e1a1bdb --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/argument_types.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-unescape-string +description: Input is a null, undefined, boolean or Number +info: | + B.2.1.2 unescape ( string ) + + 1. Set string to ? ToString(string). + ... +---*/ + +assert.sameValue(unescape(null), 'null'); + +assert.sameValue(unescape(undefined), 'undefined'); + +assert.sameValue(unescape(), 'undefined'); + +assert.sameValue(unescape(true), 'true'); + +assert.sameValue(unescape(false), 'false'); + +assert.sameValue(unescape(-0), '0'); + +assert.sameValue(unescape(0), '0'); + +assert.sameValue(unescape(1), '1'); + +assert.sameValue(unescape(NaN), 'NaN'); + +assert.sameValue(unescape(Number.POSITIVE_INFINITY), 'Infinity'); + +assert.sameValue(unescape(Number.NEGATIVE_INFINITY), '-Infinity'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/browser.js b/js/src/tests/test262/annexB/built-ins/unescape/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/browser.js diff --git a/js/src/tests/test262/annexB/built-ins/unescape/empty-string.js b/js/src/tests/test262/annexB/built-ins/unescape/empty-string.js new file mode 100644 index 0000000000..41c491239e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/empty-string.js @@ -0,0 +1,19 @@ +// 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-unescape-string +es6id: B.2.1.2 +description: Input is the empty string +info: | + 1. Let string be ? ToString(string). + 2. Let length be the number of code units in string. + 3. Let R be the empty string. + 4. Let k be 0. + 5. Repeat, while k ≠ length, + [...] + 6. Return R. +---*/ + +assert.sameValue(unescape(''), ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/four-ignore-bad-u.js b/js/src/tests/test262/annexB/built-ins/unescape/four-ignore-bad-u.js new file mode 100644 index 0000000000..09b9fd30f3 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/four-ignore-bad-u.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-unescape-string +es6id: B.2.1.2 +description: > + Does not transform four-character patterns that are not prefixed with the + character "u" +info: | + [...] + 5. Repeat, while k ≠ length, + [...] + a. Let c be the code unit at index k within string. + b. If c is %, then + i. If k ≤ length-6 and the code unit at index k+1 within string is u + and the four code units at indices k+2, k+3, k+4, and k+5 within + string are all hexadecimal digits, then + 1. Let c be the code unit whose value is the integer represented + by the four hexadecimal digits at indices k+2, k+3, k+4, and + k+5 within string. + 2. Increase k by 5. + [...] +---*/ + +assert.sameValue(unescape('%U0000'), '%U0000'); +assert.sameValue(unescape('%t0000'), '%t0000'); +assert.sameValue(unescape('%v0000'), '%v0000'); +assert.sameValue(unescape('%%0000'), '%\x0000'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/four-ignore-end-str.js b/js/src/tests/test262/annexB/built-ins/unescape/four-ignore-end-str.js new file mode 100644 index 0000000000..da1a016bc4 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/four-ignore-end-str.js @@ -0,0 +1,96 @@ +// 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-unescape-string +es6id: B.2.1.2 +description: > + Does not transform four-character patterns that are interrupted by the end + of the string +info: | + [...] + 5. Repeat, while k ≠ length, + [...] + a. Let c be the code unit at index k within string. + b. If c is %, then + i. If k ≤ length-6 and the code unit at index k+1 within string is u + and the four code units at indices k+2, k+3, k+4, and k+5 within + string are all hexadecimal digits, then + 1. Let c be the code unit whose value is the integer represented + by the four hexadecimal digits at indices k+2, k+3, k+4, and + k+5 within string. + 2. Increase k by 5. + [...] +---*/ + +assert.sameValue(unescape('%u'), '%u'); + +assert.sameValue(unescape('%u0'), '%u0'); +assert.sameValue(unescape('%u1'), '%u1'); +assert.sameValue(unescape('%u2'), '%u2'); +assert.sameValue(unescape('%u3'), '%u3'); +assert.sameValue(unescape('%u4'), '%u4'); +assert.sameValue(unescape('%u5'), '%u5'); +assert.sameValue(unescape('%u6'), '%u6'); +assert.sameValue(unescape('%u7'), '%u7'); +assert.sameValue(unescape('%u8'), '%u8'); +assert.sameValue(unescape('%u9'), '%u9'); +assert.sameValue(unescape('%ua'), '%ua'); +assert.sameValue(unescape('%uA'), '%uA'); +assert.sameValue(unescape('%ub'), '%ub'); +assert.sameValue(unescape('%uB'), '%uB'); +assert.sameValue(unescape('%uc'), '%uc'); +assert.sameValue(unescape('%uC'), '%uC'); +assert.sameValue(unescape('%ud'), '%ud'); +assert.sameValue(unescape('%uD'), '%uD'); +assert.sameValue(unescape('%ue'), '%ue'); +assert.sameValue(unescape('%uE'), '%uE'); +assert.sameValue(unescape('%uf'), '%uf'); +assert.sameValue(unescape('%uF'), '%uF'); + +assert.sameValue(unescape('%u00'), '%u00'); +assert.sameValue(unescape('%u01'), '%u01'); +assert.sameValue(unescape('%u02'), '%u02'); +assert.sameValue(unescape('%u03'), '%u03'); +assert.sameValue(unescape('%u04'), '%u04'); +assert.sameValue(unescape('%u05'), '%u05'); +assert.sameValue(unescape('%u06'), '%u06'); +assert.sameValue(unescape('%u07'), '%u07'); +assert.sameValue(unescape('%u08'), '%u08'); +assert.sameValue(unescape('%u09'), '%u09'); +assert.sameValue(unescape('%u0a'), '%u0a'); +assert.sameValue(unescape('%u0A'), '%u0A'); +assert.sameValue(unescape('%u0b'), '%u0b'); +assert.sameValue(unescape('%u0B'), '%u0B'); +assert.sameValue(unescape('%u0c'), '%u0c'); +assert.sameValue(unescape('%u0C'), '%u0C'); +assert.sameValue(unescape('%u0d'), '%u0d'); +assert.sameValue(unescape('%u0D'), '%u0D'); +assert.sameValue(unescape('%u0e'), '%u0e'); +assert.sameValue(unescape('%u0E'), '%u0E'); +assert.sameValue(unescape('%u0f'), '%u0f'); +assert.sameValue(unescape('%u0F'), '%u0F'); + +assert.sameValue(unescape('%u000'), '%u000'); +assert.sameValue(unescape('%u001'), '%u001'); +assert.sameValue(unescape('%u002'), '%u002'); +assert.sameValue(unescape('%u003'), '%u003'); +assert.sameValue(unescape('%u004'), '%u004'); +assert.sameValue(unescape('%u005'), '%u005'); +assert.sameValue(unescape('%u006'), '%u006'); +assert.sameValue(unescape('%u007'), '%u007'); +assert.sameValue(unescape('%u008'), '%u008'); +assert.sameValue(unescape('%u009'), '%u009'); +assert.sameValue(unescape('%u00a'), '%u00a'); +assert.sameValue(unescape('%u00A'), '%u00A'); +assert.sameValue(unescape('%u00b'), '%u00b'); +assert.sameValue(unescape('%u00B'), '%u00B'); +assert.sameValue(unescape('%u00c'), '%u00c'); +assert.sameValue(unescape('%u00C'), '%u00C'); +assert.sameValue(unescape('%u00d'), '%u00d'); +assert.sameValue(unescape('%u00D'), '%u00D'); +assert.sameValue(unescape('%u00e'), '%u00e'); +assert.sameValue(unescape('%u00E'), '%u00E'); +assert.sameValue(unescape('%u00f'), '%u00f'); +assert.sameValue(unescape('%u00F'), '%u00F'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/four-ignore-non-hex.js b/js/src/tests/test262/annexB/built-ins/unescape/four-ignore-non-hex.js new file mode 100644 index 0000000000..411a62c551 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/four-ignore-non-hex.js @@ -0,0 +1,45 @@ +// 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-unescape-string +es6id: B.2.1.2 +description: > + Does not transform four-character patterns that contain non-hexadecimal + digits +info: | + [...] + 5. Repeat, while k ≠ length, + [...] + a. Let c be the code unit at index k within string. + b. If c is %, then + i. If k ≤ length-6 and the code unit at index k+1 within string is u + and the four code units at indices k+2, k+3, k+4, and k+5 within + string are all hexadecimal digits, then + 1. Let c be the code unit whose value is the integer represented + by the four hexadecimal digits at indices k+2, k+3, k+4, and + k+5 within string. + 2. Increase k by 5. + [...] +---*/ + +assert.sameValue(unescape('%u000%0'), '%u000%0'); + +assert.sameValue(unescape('%u000g0'), '%u000g0'); +assert.sameValue(unescape('%u000G0'), '%u000G0'); +assert.sameValue(unescape('%u00g00'), '%u00g00'); +assert.sameValue(unescape('%u00G00'), '%u00G00'); +assert.sameValue(unescape('%u0g000'), '%u0g000'); +assert.sameValue(unescape('%u0G000'), '%u0G000'); +assert.sameValue(unescape('%ug0000'), '%ug0000'); +assert.sameValue(unescape('%uG0000'), '%uG0000'); + +assert.sameValue(unescape('%u000u0'), '%u000u0'); +assert.sameValue(unescape('%u000U0'), '%u000U0'); +assert.sameValue(unescape('%u00u00'), '%u00u00'); +assert.sameValue(unescape('%u00U00'), '%u00U00'); +assert.sameValue(unescape('%u0u000'), '%u0u000'); +assert.sameValue(unescape('%u0U000'), '%u0U000'); +assert.sameValue(unescape('%uu0000'), '%uu0000'); +assert.sameValue(unescape('%uU0000'), '%uU0000'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/four.js b/js/src/tests/test262/annexB/built-ins/unescape/four.js new file mode 100644 index 0000000000..35aeb4f74e --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/four.js @@ -0,0 +1,75 @@ +// 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-unescape-string +es6id: B.2.1.2 +description: Translation of patterns with four digits +info: | + [...] + 5. Repeat, while k ≠ length, + [...] + a. Let c be the code unit at index k within string. + b. If c is %, then + i. If k ≤ length-6 and the code unit at index k+1 within string is u + and the four code units at indices k+2, k+3, k+4, and k+5 within + string are all hexadecimal digits, then + 1. Let c be the code unit whose value is the integer represented + by the four hexadecimal digits at indices k+2, k+3, k+4, and + k+5 within string. + 2. Increase k by 5. + [...] +---*/ + +assert.sameValue(unescape('%0%u00000'), '%0\x000', '%u0000'); +assert.sameValue(unescape('%0%u00010'), '%0\x010', '%u0001'); + +assert.sameValue(unescape('%0%u00290'), '%0)0', '%002900'); +assert.sameValue(unescape('%0%u002a0'), '%0*0', '%002a00'); +assert.sameValue(unescape('%0%u002A0'), '%0*0', '%002A00'); +assert.sameValue(unescape('%0%u002b0'), '%0+0', '%002b00'); +assert.sameValue(unescape('%0%u002B0'), '%0+0', '%002B00'); +assert.sameValue(unescape('%0%u002c0'), '%0,0', '%002c00'); +assert.sameValue(unescape('%0%u002C0'), '%0,0', '%002C00'); +assert.sameValue(unescape('%0%u002d0'), '%0-0', '%002d00'); +assert.sameValue(unescape('%0%u002D0'), '%0-0', '%002D00'); + +assert.sameValue(unescape('%0%u00390'), '%090', '%003900'); +assert.sameValue(unescape('%0%u003a0'), '%0:0', '%003A00'); +assert.sameValue(unescape('%0%u003A0'), '%0:0', '%003A00'); + +assert.sameValue(unescape('%0%u003f0'), '%0?0', '%003f00'); +assert.sameValue(unescape('%0%u003F0'), '%0?0', '%003F00'); +assert.sameValue(unescape('%0%u00400'), '%0@0', '%004000'); + +assert.sameValue(unescape('%0%u005a0'), '%0Z0', '%005a00'); +assert.sameValue(unescape('%0%u005A0'), '%0Z0', '%005A00'); +assert.sameValue(unescape('%0%u005b0'), '%0[0', '%005b00'); +assert.sameValue(unescape('%0%u005B0'), '%0[0', '%005B00'); + +assert.sameValue(unescape('%0%u005e0'), '%0^0', '%005e00'); +assert.sameValue(unescape('%0%u005E0'), '%0^0', '%005E00'); +assert.sameValue(unescape('%0%u005f0'), '%0_0', '%005f00'); +assert.sameValue(unescape('%0%u005F0'), '%0_0', '%005F00'); +assert.sameValue(unescape('%0%u00600'), '%0`0', '%006000'); +assert.sameValue(unescape('%0%u00610'), '%0a0', '%006100'); + +assert.sameValue(unescape('%0%u007a0'), '%0z0', '%007a00'); +assert.sameValue(unescape('%0%u007A0'), '%0z0', '%007A00'); +assert.sameValue(unescape('%0%u007b0'), '%0{0', '%007b00'); +assert.sameValue(unescape('%0%u007B0'), '%0{0', '%007B00'); + +assert.sameValue(unescape('%0%ufffe0'), '%0\ufffe0', '%ufffe'); +assert.sameValue(unescape('%0%uFffe0'), '%0\ufffe0', '%uFffe'); +assert.sameValue(unescape('%0%ufFfe0'), '%0\ufffe0', '%ufFfe'); +assert.sameValue(unescape('%0%uffFe0'), '%0\ufffe0', '%uffFe'); +assert.sameValue(unescape('%0%ufffE0'), '%0\ufffe0', '%ufffE'); +assert.sameValue(unescape('%0%uFFFE0'), '%0\ufffe0', '%uFFFE'); + +assert.sameValue(unescape('%0%uffff0'), '%0\uffff0', '%uffff'); +assert.sameValue(unescape('%0%uFfff0'), '%0\uffff0', '%uFfff'); +assert.sameValue(unescape('%0%ufFff0'), '%0\uffff0', '%ufFff'); +assert.sameValue(unescape('%0%uffFf0'), '%0\uffff0', '%uffFf'); +assert.sameValue(unescape('%0%ufffF0'), '%0\uffff0', '%ufffF'); +assert.sameValue(unescape('%0%uFFFF0'), '%0\uffff0', '%uFFFF'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/length.js b/js/src/tests/test262/annexB/built-ins/unescape/length.js new file mode 100644 index 0000000000..2bd578f6ec --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.1.2 +description: > + unescape.length is 1. +info: | + unescape (string) + + 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] +---*/ + +verifyProperty(unescape, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/name.js b/js/src/tests/test262/annexB/built-ins/unescape/name.js new file mode 100644 index 0000000000..e356381754 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.2.1.2 +description: > + unescape.name is "unescape". +info: | + unescape (string) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a 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] +---*/ + +verifyProperty(unescape, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "unescape" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/not-a-constructor.js b/js/src/tests/test262/annexB/built-ins/unescape/not-a-constructor.js new file mode 100644 index 0000000000..71c32f22c2 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/not-a-constructor.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + unescape does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(unescape), false, 'isConstructor(unescape) must return false'); + +assert.throws(TypeError, () => { + new unescape(''); +}, '`new unescape(\'\')` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/prop-desc.js b/js/src/tests/test262/annexB/built-ins/unescape/prop-desc.js new file mode 100644 index 0000000000..67a88bc87a --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/prop-desc.js @@ -0,0 +1,21 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: B.2.2 +description: > + Object.getOwnPropertyDescriptor returns data desc for functions on + built-ins (Global.unescape) +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof this.unescape, "function"); +assert.sameValue(typeof this["unescape"], "function"); + +verifyProperty(this, "unescape", { + writable: true, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/shell.js b/js/src/tests/test262/annexB/built-ins/unescape/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/annexB/built-ins/unescape/to-primitive-err.js b/js/src/tests/test262/annexB/built-ins/unescape/to-primitive-err.js new file mode 100644 index 0000000000..57b1f1d621 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/to-primitive-err.js @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-unescape-string +description: If [Symbol.toPrimitive] method returned an object, it should throw a TypeError +info: | + B.2.1.2 unescape ( string ) + + 1. Set string to ? ToString(string). + .... +features: [Symbol.toPrimitive] +---*/ + +var obj = { + toString() { throw new Test262Error('this should be unreachable'); }, + valueOf() { throw new Test262Error('this should be unreachable'); }, + [Symbol.toPrimitive]() { return function(){}; } +}; + +assert.throws(TypeError, function() { + unescape(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/to-primitive-observe.js b/js/src/tests/test262/annexB/built-ins/unescape/to-primitive-observe.js new file mode 100644 index 0000000000..3c6c2068e1 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/to-primitive-observe.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Qu Xing. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-unescape-string +description: Observable operations from string coercion +info: | + B.2.1.2 unescape ( string ) + + 1. Set string to ? ToString(string). + .... +features: [Symbol.toPrimitive] +---*/ + +var obj = { + toString() { throw new Test262Error('this should be unreachable'); }, + valueOf() { throw new Test262Error('this should be unreachable'); }, + [Symbol.toPrimitive]() { return 'success'; } +}; + +assert.sameValue(unescape(obj), 'success'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/to-string-err-symbol.js b/js/src/tests/test262/annexB/built-ins/unescape/to-string-err-symbol.js new file mode 100644 index 0000000000..b09654e049 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/to-string-err-symbol.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-unescape-string +es6id: B.2.1.2 +description: Abrupt completion from `ToString` operation (Symbol value) +info: | + 1. Let string be ? ToString(string). +features: [Symbol] +---*/ + +var s = Symbol(''); + +assert.throws(TypeError, function() { + unescape(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/to-string-err.js b/js/src/tests/test262/annexB/built-ins/unescape/to-string-err.js new file mode 100644 index 0000000000..6bb51700c9 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/to-string-err.js @@ -0,0 +1,21 @@ +// 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-unescape-string +es6id: B.2.1.2 +description: Abrupt completion from `ToString` operation +info: | + 1. Let string be ? ToString(string). +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + unescape(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/to-string-observe.js b/js/src/tests/test262/annexB/built-ins/unescape/to-string-observe.js new file mode 100644 index 0000000000..bfba45da2d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/to-string-observe.js @@ -0,0 +1,54 @@ +// 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-unescape-string +es6id: B.2.1.2 +description: Observable operations from string coercion +info: | + 1. Let string be ? ToString(string). +---*/ + +var log, obj; + +log = ''; +obj = { + toString: function() { + log += 'toString'; + }, + valueOf: function() { + log += 'valueOf'; + } +}; + +unescape(obj); + +assert.sameValue(log, 'toString'); + +log = ''; +obj = { + toString: null, + valueOf: function() { + log += 'valueOf'; + } +}; + +unescape(obj); + +assert.sameValue(log, 'valueOf'); + +log = ''; +obj = { + toString: function() { + log += 'toString'; + return {}; + }, + valueOf: function() { + log += 'valueOf'; + } +}; + +unescape(obj); + +assert.sameValue(log, 'toStringvalueOf'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/two-ignore-end-str.js b/js/src/tests/test262/annexB/built-ins/unescape/two-ignore-end-str.js new file mode 100644 index 0000000000..faabd5a50d --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/two-ignore-end-str.js @@ -0,0 +1,49 @@ +// 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-unescape-string +es6id: B.2.1.2 +description: > + Does not transform two-character patterns that are interrupted by the end + of the string +info: | + [...] + 5. Repeat, while k ≠ length, + [...] + a. Let c be the code unit at index k within string. + b. If c is %, then + [...] + ii. Else if k ≤ length-3 and the two code units at indices k+1 and + k+2 within string are both hexadecimal digits, then + 1. Let c be the code unit whose value is the integer represented + by two zeroes plus the two hexadecimal digits at indices k+1 + and k+2 within string. + 2. Increase k by 2. + [...] +---*/ + +assert.sameValue(unescape('%'), '%'); +assert.sameValue(unescape('%0'), '%0'); +assert.sameValue(unescape('%1'), '%1'); +assert.sameValue(unescape('%2'), '%2'); +assert.sameValue(unescape('%3'), '%3'); +assert.sameValue(unescape('%4'), '%4'); +assert.sameValue(unescape('%5'), '%5'); +assert.sameValue(unescape('%6'), '%6'); +assert.sameValue(unescape('%7'), '%7'); +assert.sameValue(unescape('%8'), '%8'); +assert.sameValue(unescape('%9'), '%9'); +assert.sameValue(unescape('%a'), '%a'); +assert.sameValue(unescape('%A'), '%A'); +assert.sameValue(unescape('%b'), '%b'); +assert.sameValue(unescape('%B'), '%B'); +assert.sameValue(unescape('%c'), '%c'); +assert.sameValue(unescape('%C'), '%C'); +assert.sameValue(unescape('%d'), '%d'); +assert.sameValue(unescape('%D'), '%D'); +assert.sameValue(unescape('%e'), '%e'); +assert.sameValue(unescape('%E'), '%E'); +assert.sameValue(unescape('%f'), '%f'); +assert.sameValue(unescape('%F'), '%F'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/two-ignore-non-hex.js b/js/src/tests/test262/annexB/built-ins/unescape/two-ignore-non-hex.js new file mode 100644 index 0000000000..04d8948211 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/two-ignore-non-hex.js @@ -0,0 +1,37 @@ +// 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-unescape-string +es6id: B.2.1.2 +description: > + Does not transform two-character patterns that contain non-hexadecimal + digits +info: | + [...] + 5. Repeat, while k ≠ length, + [...] + a. Let c be the code unit at index k within string. + b. If c is %, then + [...] + ii. Else if k ≤ length-3 and the two code units at indices k+1 and + k+2 within string are both hexadecimal digits, then + 1. Let c be the code unit whose value is the integer represented + by two zeroes plus the two hexadecimal digits at indices k+1 + and k+2 within string. + 2. Increase k by 2. + [...] +---*/ + +assert.sameValue(unescape('%0%0'), '%0%0'); + +assert.sameValue(unescape('%0g0'), '%0g0'); +assert.sameValue(unescape('%0G0'), '%0G0'); +assert.sameValue(unescape('%g00'), '%g00'); +assert.sameValue(unescape('%G00'), '%G00'); + +assert.sameValue(unescape('%0u0'), '%0u0'); +assert.sameValue(unescape('%0U0'), '%0U0'); +assert.sameValue(unescape('%u00'), '%u00'); +assert.sameValue(unescape('%U00'), '%U00'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/built-ins/unescape/two.js b/js/src/tests/test262/annexB/built-ins/unescape/two.js new file mode 100644 index 0000000000..5f28cdd0c9 --- /dev/null +++ b/js/src/tests/test262/annexB/built-ins/unescape/two.js @@ -0,0 +1,71 @@ +// 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-unescape-string +es6id: B.2.1.2 +description: Translation of patterns with two digits +info: | + [...] + 5. Repeat, while k ≠ length, + [...] + a. Let c be the code unit at index k within string. + b. If c is %, then + [...] + ii. Else if k ≤ length-3 and the two code units at indices k+1 and + k+2 within string are both hexadecimal digits, then + 1. Let c be the code unit whose value is the integer represented + by two zeroes plus the two hexadecimal digits at indices k+1 + and k+2 within string. + 2. Increase k by 2. + [...] +---*/ + +assert.sameValue(unescape('%0%0000'), '%0\x0000', '%00'); +assert.sameValue(unescape('%0%0100'), '%0\x0100', '%01'); + +assert.sameValue(unescape('%0%2900'), '%0)00', '%29'); +assert.sameValue(unescape('%0%2a00'), '%0*00', '%2a'); +assert.sameValue(unescape('%0%2A00'), '%0*00', '%2A'); +assert.sameValue(unescape('%0%2b00'), '%0+00', '%2b'); +assert.sameValue(unescape('%0%2B00'), '%0+00', '%2B'); +assert.sameValue(unescape('%0%2c00'), '%0,00', '%2c'); +assert.sameValue(unescape('%0%2C00'), '%0,00', '%2C'); +assert.sameValue(unescape('%0%2d00'), '%0-00', '%2d'); +assert.sameValue(unescape('%0%2D00'), '%0-00', '%2D'); + +assert.sameValue(unescape('%0%3900'), '%0900', '%39'); +assert.sameValue(unescape('%0%3a00'), '%0:00', '%3A'); +assert.sameValue(unescape('%0%3A00'), '%0:00', '%3A'); + +assert.sameValue(unescape('%0%3f00'), '%0?00', '%3f'); +assert.sameValue(unescape('%0%3F00'), '%0?00', '%3F'); +assert.sameValue(unescape('%0%4000'), '%0@00', '%40'); + +assert.sameValue(unescape('%0%5a00'), '%0Z00', '%5a'); +assert.sameValue(unescape('%0%5A00'), '%0Z00', '%5A'); +assert.sameValue(unescape('%0%5b00'), '%0[00', '%5b'); +assert.sameValue(unescape('%0%5B00'), '%0[00', '%5B'); + +assert.sameValue(unescape('%0%5e00'), '%0^00', '%5e'); +assert.sameValue(unescape('%0%5E00'), '%0^00', '%5E'); +assert.sameValue(unescape('%0%5f00'), '%0_00', '%5f'); +assert.sameValue(unescape('%0%5F00'), '%0_00', '%5F'); +assert.sameValue(unescape('%0%6000'), '%0`00', '%60'); +assert.sameValue(unescape('%0%6100'), '%0a00', '%61'); + +assert.sameValue(unescape('%0%7a00'), '%0z00', '%7a'); +assert.sameValue(unescape('%0%7A00'), '%0z00', '%7A'); +assert.sameValue(unescape('%0%7b00'), '%0{00', '%7b'); +assert.sameValue(unescape('%0%7B00'), '%0{00', '%7B'); + +assert.sameValue(unescape('%0%fe00'), '%0\xfe00', '%fe'); +assert.sameValue(unescape('%0%Fe00'), '%0\xfe00', '%Fe'); +assert.sameValue(unescape('%0%fE00'), '%0\xfe00', '%fE'); +assert.sameValue(unescape('%0%FE00'), '%0\xfe00', '%FE'); + +assert.sameValue(unescape('%0%ff00'), '%0\xff00', '%ff'); +assert.sameValue(unescape('%0%Ff00'), '%0\xff00', '%Ff'); +assert.sameValue(unescape('%0%fF00'), '%0\xff00', '%fF'); +assert.sameValue(unescape('%0%FF00'), '%0\xff00', '%FF'); + +reportCompare(0, 0); |