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/built-ins/String/raw | |
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/built-ins/String/raw')
32 files changed, 926 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/raw/browser.js b/js/src/tests/test262/built-ins/String/raw/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/browser.js diff --git a/js/src/tests/test262/built-ins/String/raw/length.js b/js/src/tests/test262/built-ins/String/raw/length.js new file mode 100644 index 0000000000..deb433fde5 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/length.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + String.raw.length value and property descriptor +info: | + String.raw ( template , ...substitutions ) + + The length property of the raw function is 1. +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + String.raw.length, 1, + 'The value of `String.raw.length` is `1`' +); + +verifyNotEnumerable(String.raw, 'length'); +verifyNotWritable(String.raw, 'length'); +verifyConfigurable(String.raw, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/name.js b/js/src/tests/test262/built-ins/String/raw/name.js new file mode 100644 index 0000000000..c7533e923b --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/name.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + String.raw.name value and property descriptor +info: | + String.raw ( template , ...substitutions ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + String.raw.name, 'raw', + 'The value of `String.raw.name` is `"raw"`' +); + +verifyNotEnumerable(String.raw, 'name'); +verifyNotWritable(String.raw, 'name'); +verifyConfigurable(String.raw, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/nextkey-is-symbol-throws.js b/js/src/tests/test262/built-ins/String/raw/nextkey-is-symbol-throws.js new file mode 100644 index 0000000000..3a670b367e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/nextkey-is-symbol-throws.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Throws a TypeError if nextKey is Symbol +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 10. Let stringElements be a new List. + 11. Let nextIndex be 0. + 12. Repeat + a. Let nextKey be ToString(nextIndex). + b. Let nextSeg be ToString(Get(raw, nextKey)). + c. ReturnIfAbrupt(nextSeg). + ... +features: [Symbol] +---*/ + +var obj = { + raw: { + length: 1, + '0': Symbol('') + } +}; + +assert.throws(TypeError, function() { + String.raw(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/not-a-constructor.js b/js/src/tests/test262/built-ins/String/raw/not-a-constructor.js new file mode 100644 index 0000000000..6beda7f32f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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.raw 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.raw), false, 'isConstructor(String.raw) must return false'); + +assert.throws(TypeError, () => { + new String.raw({raw: []}, []); +}, '`new String.raw({raw: []}, [])` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/raw.js b/js/src/tests/test262/built-ins/String/raw/raw.js new file mode 100644 index 0000000000..c36ee8484a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/raw.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + String.raw property descriptor +info: | + String.raw ( template , ...substitutions ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(String, 'raw'); +verifyWritable(String, 'raw'); +verifyConfigurable(String, 'raw'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-empty-string-from-empty-array-length.js b/js/src/tests/test262/built-ins/String/raw/return-empty-string-from-empty-array-length.js new file mode 100644 index 0000000000..7d286f958d --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-empty-string-from-empty-array-length.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns empty string if template.raw an empty Array +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). + 9. If literalSegments ≤ 0, return the empty string. + ... +---*/ + +var result = String.raw({ + raw: [] +}); + +assert.sameValue(result, ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-negative-infinity.js b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-negative-infinity.js new file mode 100644 index 0000000000..099e52e5d0 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-negative-infinity.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns empty string if template.raw.length is -Infinity +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). + 9. If literalSegments ≤ 0, return the empty string. + ... +---*/ + +var result = String.raw({ + raw: { + length: -Infinity + } +}); + +assert.sameValue(result, ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-not-defined.js b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-not-defined.js new file mode 100644 index 0000000000..c3ebe55b92 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-not-defined.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns empty string if template.raw.length isn't defined. +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). + 9. If literalSegments ≤ 0, return the empty string. + ... +---*/ + +var result = String.raw({ + raw: {} +}); + +assert.sameValue(result, ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-undefined.js b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-undefined.js new file mode 100644 index 0000000000..1a4041535f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-undefined.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns empty string if template.raw.length isn't defined. +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). + 9. If literalSegments ≤ 0, return the empty string. + ... +---*/ + +var result = String.raw({ + raw: { + length: undefined + } +}); + +assert.sameValue(result, ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-NaN.js b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-NaN.js new file mode 100644 index 0000000000..e129f9e968 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-NaN.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns empty string if template.raw.length is NaN +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). + 9. If literalSegments ≤ 0, return the empty string. + ... +---*/ + +var result = String.raw({ + raw: { + length: NaN + } +}); + +assert.sameValue(result, ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-boolean.js b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-boolean.js new file mode 100644 index 0000000000..9eb98d7f0f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-boolean.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns empty string if template.raw.length is false +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). + 9. If literalSegments ≤ 0, return the empty string. + ... +---*/ + +var result = String.raw({ + raw: { + length: false + } +}); + +assert.sameValue(result, ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-null.js b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-null.js new file mode 100644 index 0000000000..e31a22b9bd --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-null.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns empty string if template.raw.length is null +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). + 9. If literalSegments ≤ 0, return the empty string. + ... +---*/ + +var result = String.raw({ + raw: { + length: null + } +}); + +assert.sameValue(result, ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-number.js b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-number.js new file mode 100644 index 0000000000..14d3cfad11 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-number.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns empty string if template.raw.length is <= 0 +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). + 9. If literalSegments ≤ 0, return the empty string. + ... +---*/ + +var result = String.raw({ + raw: { + length: 0 + } +}); +assert.sameValue(result, '', 'result is an empty string when length == 0'); + +result = String.raw({ + raw: { + length: -1 + } +}); +assert.sameValue(result, '', 'result is an empty string when length == -1'); + +result = String.raw({ + raw: { + length: -0 + } +}); +assert.sameValue(result, '', 'result is an empty string when length == -0'); + +result = String.raw({ + raw: { + length: 0.32 + } +}); +assert.sameValue(result, '', 'result is an empty string when length == 0.32'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-string.js b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-string.js new file mode 100644 index 0000000000..c0190abb2f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-string.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns empty string if template.raw.length is <= 0 +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). + 9. If literalSegments ≤ 0, return the empty string. + ... +---*/ + +var result = String.raw({ + raw: { + length: '0' + } +}); +assert.sameValue(result, '', 'result is an empty string when length == "0"'); + +result = String.raw({ + raw: { + length: '-1' + } +}); +assert.sameValue(result, '', 'result is an empty string when length == "-1"'); + +result = String.raw({ + raw: { + length: '' + } +}); +assert.sameValue(result, '', 'result is an empty string when length == ""'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-the-string-value-from-template.js b/js/src/tests/test262/built-ins/String/raw/return-the-string-value-from-template.js new file mode 100644 index 0000000000..c8a8c5175c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-the-string-value-from-template.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns the string value. +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 10. Let stringElements be a new List. + 11. Let nextIndex be 0. + 12. Repeat + a. Let nextKey be ToString(nextIndex). + b. Let nextSeg be ToString(Get(raw, nextKey)). + c. ReturnIfAbrupt(nextSeg). + d. Append in order the code unit elements of nextSeg to the end of + stringElements. + e. If nextIndex + 1 = literalSegments, then + i. Return the String value whose code units are, in order, the elements in + the List stringElements. If stringElements has no elements, the empty + string is returned. + ... +---*/ + +assert.sameValue(String.raw`123\u0065`, '123\\u0065'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/return-the-string-value.js b/js/src/tests/test262/built-ins/String/raw/return-the-string-value.js new file mode 100644 index 0000000000..48ca631777 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/return-the-string-value.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns the string value without substitutions arguments and limited to the + given length. +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 10. Let stringElements be a new List. + 11. Let nextIndex be 0. + 12. Repeat + a. Let nextKey be ToString(nextIndex). + b. Let nextSeg be ToString(Get(raw, nextKey)). + c. ReturnIfAbrupt(nextSeg). + d. Append in order the code unit elements of nextSeg to the end of + stringElements. + e. If nextIndex + 1 = literalSegments, then + i. Return the String value whose code units are, in order, the elements in + the List stringElements. If stringElements has no elements, the empty + string is returned. + ... +---*/ + +var obj = { + raw: { + length: 5, + 0: '\u0065', + 1: '', + 2: null, + 3: undefined, + 4: 123, + 5: 'overpass the length' + } +}; + +assert.sameValue(String.raw(obj), 'enullundefined123'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-next-key-toString.js b/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-next-key-toString.js new file mode 100644 index 0000000000..5d39385342 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-next-key-toString.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns abrupt from nextKey. +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 10. Let stringElements be a new List. + 11. Let nextIndex be 0. + 12. Repeat + a. Let nextKey be ToString(nextIndex). + b. Let nextSeg be ToString(Get(raw, nextKey)). + c. ReturnIfAbrupt(nextSeg). + ... +---*/ + +var obj = { + raw: { + length: 1, + '0': { + toString: function() { + throw new Test262Error(); + } + } + } +}; + +assert.throws(Test262Error, function() { + String.raw(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-next-key.js b/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-next-key.js new file mode 100644 index 0000000000..e044e2c222 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-next-key.js @@ -0,0 +1,48 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns abrupt from nextKey. +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 10. Let stringElements be a new List. + 11. Let nextIndex be 0. + 12. Repeat + a. Let nextKey be ToString(nextIndex). + b. Let nextSeg be ToString(Get(raw, nextKey)). + c. ReturnIfAbrupt(nextSeg). + ... +---*/ + +var obj = { + raw: { + length: 2 + } +}; + +Object.defineProperty(obj.raw, '0', { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); + +assert.throws(Test262Error, function() { + String.raw(obj); +}); + +delete obj.raw['0']; +obj.raw['0'] = 'a'; +Object.defineProperty(obj.raw, '1', { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + String.raw(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-substitution-symbol.js b/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-substitution-symbol.js new file mode 100644 index 0000000000..5c3590880e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-substitution-symbol.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns the abrupt from ToString(substitutions[nextIndex]) using a Symbol + value. +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 10. Let stringElements be a new List. + 11. Let nextIndex be 0. + 12. Repeat + a. Let nextKey be ToString(nextIndex). + b. Let nextSeg be ToString(Get(raw, nextKey)). + c. ReturnIfAbrupt(nextSeg). + d. Append in order the code unit elements of nextSeg to the end of + stringElements. + e. If nextIndex + 1 = literalSegments, then + i. Return the String value whose code units are, in order, the elements in + the List stringElements. If stringElements has no elements, the empty + string is returned. + f. If nextIndex < numberOfSubstitutions, let next be substitutions[nextIndex]. + g. Else, let next be the empty String. + h. Let nextSub be ToString(next). + i. ReturnIfAbrupt(nextSub). + j. Append in order the code unit elements of nextSub to the end of stringElements. + k. Let nextIndex be nextIndex + 1. +features: [Symbol] +---*/ + +var template = { + raw: ['a', 'b', 'c'] +}; + +assert.throws(TypeError, function() { + String.raw(template, '', Symbol('')); +}); + +assert.throws(TypeError, function() { + String.raw(template, Symbol(''), ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-substitution.js b/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-substitution.js new file mode 100644 index 0000000000..42c2ad7f90 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/returns-abrupt-from-substitution.js @@ -0,0 +1,48 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns the abrupt from ToString(substitutions[nextIndex]). +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 10. Let stringElements be a new List. + 11. Let nextIndex be 0. + 12. Repeat + a. Let nextKey be ToString(nextIndex). + b. Let nextSeg be ToString(Get(raw, nextKey)). + c. ReturnIfAbrupt(nextSeg). + d. Append in order the code unit elements of nextSeg to the end of + stringElements. + e. If nextIndex + 1 = literalSegments, then + i. Return the String value whose code units are, in order, the elements in + the List stringElements. If stringElements has no elements, the empty + string is returned. + f. If nextIndex < numberOfSubstitutions, let next be substitutions[nextIndex]. + g. Else, let next be the empty String. + h. Let nextSub be ToString(next). + i. ReturnIfAbrupt(nextSub). + j. Append in order the code unit elements of nextSub to the end of stringElements. + k. Let nextIndex be nextIndex + 1. +---*/ + +var template = { + raw: ['a', 'b', 'c'] +}; +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.raw(template, '', obj); +}); + +assert.throws(Test262Error, function() { + String.raw(template, obj, ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/shell.js b/js/src/tests/test262/built-ins/String/raw/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/shell.js diff --git a/js/src/tests/test262/built-ins/String/raw/special-characters.js b/js/src/tests/test262/built-ins/String/raw/special-characters.js new file mode 100644 index 0000000000..c2c2696e5a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/special-characters.js @@ -0,0 +1,23 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + When used as a tag function of a tagged template, `String.raw` should + return the "raw" representation of the template. +---*/ + +assert.sameValue( + String.raw`\u0065\`\r\r\n\n${'test'}check`, + '\\u0065\\`\\r\\r\\n\\ntestcheck', + 'Unicode escape sequences' +); +assert.sameValue( + String.raw`\
\
+\ +`, + '\\\n\\\n\\\n', + 'Literal characters' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/substitutions-are-appended-on-same-index.js b/js/src/tests/test262/built-ins/String/raw/substitutions-are-appended-on-same-index.js new file mode 100644 index 0000000000..96e8839422 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/substitutions-are-appended-on-same-index.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns the string value appending the substitutions on the same index order. +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 10. Let stringElements be a new List. + 11. Let nextIndex be 0. + 12. Repeat + a. Let nextKey be ToString(nextIndex). + b. Let nextSeg be ToString(Get(raw, nextKey)). + c. ReturnIfAbrupt(nextSeg). + d. Append in order the code unit elements of nextSeg to the end of + stringElements. + e. If nextIndex + 1 = literalSegments, then + i. Return the String value whose code units are, in order, the elements in + the List stringElements. If stringElements has no elements, the empty + string is returned. + f. If nextIndex < numberOfSubstitutions, let next be substitutions[nextIndex]. + g. Else, let next be the empty String. + h. Let nextSub be ToString(next). + i. ReturnIfAbrupt(nextSub). + j. Append in order the code unit elements of nextSub to the end of stringElements. + k. Let nextIndex be nextIndex + 1. +---*/ + +var template = { + raw: ['a', 'b', 'd', 'f'] +}; + +assert.sameValue(String.raw(template, '', 'c', 'e'), 'abcdef'); +assert.sameValue(String.raw(template, 1), 'a1bdf'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/substitutions-are-limited-to-template-raw-length.js b/js/src/tests/test262/built-ins/String/raw/substitutions-are-limited-to-template-raw-length.js new file mode 100644 index 0000000000..95e54cc048 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/substitutions-are-limited-to-template-raw-length.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Limit appended substitutions arguments to template.raw.length - 1. +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 10. Let stringElements be a new List. + 11. Let nextIndex be 0. + 12. Repeat + a. Let nextKey be ToString(nextIndex). + b. Let nextSeg be ToString(Get(raw, nextKey)). + c. ReturnIfAbrupt(nextSeg). + d. Append in order the code unit elements of nextSeg to the end of + stringElements. + e. If nextIndex + 1 = literalSegments, then + i. Return the String value whose code units are, in order, the elements in + the List stringElements. If stringElements has no elements, the empty + string is returned. + ... +---*/ + +var template = { + raw: ['a', 'c', 'e'] +}; +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.sameValue(String.raw(template, 'b', 'd', obj), 'abcde'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/template-length-is-symbol-throws.js b/js/src/tests/test262/built-ins/String/raw/template-length-is-symbol-throws.js new file mode 100644 index 0000000000..eda07012cc --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/template-length-is-symbol-throws.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns abrupt completion from ToLength(template.raw.length). +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + 1. Let substitutions be a List consisting of all of the arguments passed to + this function, starting with the second argument. If fewer than two arguments + were passed, the List is empty. + 2. Let numberOfSubstitutions be the number of elements in substitutions. + 3. Let cooked be ToObject(template). + 4. ReturnIfAbrupt(cooked). + 5. Let raw be ToObject(Get(cooked, "raw")). + 6. ReturnIfAbrupt(raw). + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + String.raw({ + raw: { + length: Symbol(1) + } + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/template-length-throws.js b/js/src/tests/test262/built-ins/String/raw/template-length-throws.js new file mode 100644 index 0000000000..eed53e6406 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/template-length-throws.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns abrupt completion from ToObject(template.raw.length). +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + 1. Let substitutions be a List consisting of all of the arguments passed to + this function, starting with the second argument. If fewer than two arguments + were passed, the List is empty. + 2. Let numberOfSubstitutions be the number of elements in substitutions. + 3. Let cooked be ToObject(template). + 4. ReturnIfAbrupt(cooked). + 5. Let raw be ToObject(Get(cooked, "raw")). + 6. ReturnIfAbrupt(raw). + 7. Let literalSegments be ToLength(Get(raw, "length")). + 8. ReturnIfAbrupt(literalSegments). +---*/ + +var obj = { + raw: {} +}; +Object.defineProperty(obj.raw, 'length', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + String.raw(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/template-not-object-throws.js b/js/src/tests/test262/built-ins/String/raw/template-not-object-throws.js new file mode 100644 index 0000000000..7be8b829fb --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/template-not-object-throws.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns abrupt completion from ToObject(template). +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + 1. Let substitutions be a List consisting of all of the arguments passed to + this function, starting with the second argument. If fewer than two arguments + were passed, the List is empty. + 2. Let numberOfSubstitutions be the number of elements in substitutions. + 3. Let cooked be ToObject(template). + 4. ReturnIfAbrupt(cooked). +---*/ + +assert.throws(TypeError, function() { + String.raw(null); +}); + +assert.throws(TypeError, function() { + String.raw(undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/template-raw-not-object-throws.js b/js/src/tests/test262/built-ins/String/raw/template-raw-not-object-throws.js new file mode 100644 index 0000000000..9bb391d907 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/template-raw-not-object-throws.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns abrupt completion from ToObject(template.raw). +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + 1. Let substitutions be a List consisting of all of the arguments passed to + this function, starting with the second argument. If fewer than two arguments + were passed, the List is empty. + 2. Let numberOfSubstitutions be the number of elements in substitutions. + 3. Let cooked be ToObject(template). + 4. ReturnIfAbrupt(cooked). + 5. Let raw be ToObject(Get(cooked, "raw")). + 6. ReturnIfAbrupt(raw). +---*/ + +assert.throws(TypeError, function() { + String.raw({ + raw: undefined + }); +}); + +assert.throws(TypeError, function() { + String.raw({ + raw: null + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/template-raw-throws.js b/js/src/tests/test262/built-ins/String/raw/template-raw-throws.js new file mode 100644 index 0000000000..b53ad01b5b --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/template-raw-throws.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns abrupt completion from ToObject(template.raw). +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + 1. Let substitutions be a List consisting of all of the arguments passed to + this function, starting with the second argument. If fewer than two arguments + were passed, the List is empty. + 2. Let numberOfSubstitutions be the number of elements in substitutions. + 3. Let cooked be ToObject(template). + 4. ReturnIfAbrupt(cooked). + 5. Let raw be ToObject(Get(cooked, "raw")). + 6. ReturnIfAbrupt(raw). +---*/ + +var obj = {}; +Object.defineProperty(obj, 'raw', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + String.raw(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/template-substitutions-are-appended-on-same-index.js b/js/src/tests/test262/built-ins/String/raw/template-substitutions-are-appended-on-same-index.js new file mode 100644 index 0000000000..d956f17d9f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/template-substitutions-are-appended-on-same-index.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + Returns the string value appending from the same index order using String.raw + as a tag function. +info: | + 21.1.2.4 String.raw ( template , ...substitutions ) + + ... + 10. Let stringElements be a new List. + 11. Let nextIndex be 0. + 12. Repeat + a. Let nextKey be ToString(nextIndex). + b. Let nextSeg be ToString(Get(raw, nextKey)). + c. ReturnIfAbrupt(nextSeg). + d. Append in order the code unit elements of nextSeg to the end of + stringElements. + e. If nextIndex + 1 = literalSegments, then + i. Return the String value whose code units are, in order, the elements in + the List stringElements. If stringElements has no elements, the empty + string is returned. + f. If nextIndex < numberOfSubstitutions, let next be substitutions[nextIndex]. + g. Else, let next be the empty String. + h. Let nextSub be ToString(next). + i. ReturnIfAbrupt(nextSub). + j. Append in order the code unit elements of nextSub to the end of stringElements. + k. Let nextIndex be nextIndex + 1. +---*/ + +assert.sameValue(String.raw`1${2}3${4}5`, '12345'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/raw/zero-literal-segments.js b/js/src/tests/test262/built-ins/String/raw/zero-literal-segments.js new file mode 100644 index 0000000000..5960e26120 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/raw/zero-literal-segments.js @@ -0,0 +1,11 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.2.4 +description: > + If literalSegments ≤ 0, return the empty string. +---*/ + +assert.sameValue(String.raw``, ''); + +reportCompare(0, 0); |