From 91900ab646edbaaf393b87dd8db0e9c4b5270397 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Wed, 8 Jul 2015 11:57:50 -0400 Subject: [PATCH] String.raw --- test/built-ins/String/raw/length.js | 21 +++++++++ test/built-ins/String/raw/name.js | 22 +++++++++ .../String/raw/nextkey-is-symbol-throws.js | 30 ++++++++++++ test/built-ins/String/raw/raw.js | 17 +++++++ ...rn-empty-string-from-empty-array-length.js | 21 +++++++++ ...y-string-if-length-is-negative-infinity.js | 23 ++++++++++ ...n-empty-string-if-length-is-not-defined.js | 21 +++++++++ ...urn-empty-string-if-length-is-undefined.js | 23 ++++++++++ ...turn-empty-string-if-length-is-zero-NaN.js | 23 ++++++++++ ...-empty-string-if-length-is-zero-boolean.js | 23 ++++++++++ ...urn-empty-string-if-length-is-zero-null.js | 23 ++++++++++ ...string-if-length-is-zero-or-less-number.js | 43 +++++++++++++++++ ...string-if-length-is-zero-or-less-string.js | 36 +++++++++++++++ .../return-the-string-value-from-template.js | 26 +++++++++++ .../String/raw/return-the-string-value.js | 39 ++++++++++++++++ .../returns-abrupt-from-next-key-toString.js | 33 +++++++++++++ .../raw/returns-abrupt-from-next-key.js | 46 +++++++++++++++++++ ...returns-abrupt-from-substitution-symbol.js | 43 +++++++++++++++++ .../raw/returns-abrupt-from-substitution.js | 46 +++++++++++++++++++ ...ubstitutions-are-appended-on-same-index.js | 36 +++++++++++++++ ...ions-are-limited-to-template-raw-length.js | 35 ++++++++++++++ .../raw/template-length-is-symbol-throws.js | 29 ++++++++++++ .../String/raw/template-length-throws.js | 33 +++++++++++++ .../String/raw/template-not-object-throws.js | 24 ++++++++++ .../raw/template-raw-not-object-throws.js | 30 ++++++++++++ .../String/raw/template-raw-throws.js | 29 ++++++++++++ ...ubstitutions-are-appended-on-same-index.js | 32 +++++++++++++ 27 files changed, 807 insertions(+) create mode 100644 test/built-ins/String/raw/length.js create mode 100644 test/built-ins/String/raw/name.js create mode 100644 test/built-ins/String/raw/nextkey-is-symbol-throws.js create mode 100644 test/built-ins/String/raw/raw.js create mode 100644 test/built-ins/String/raw/return-empty-string-from-empty-array-length.js create mode 100644 test/built-ins/String/raw/return-empty-string-if-length-is-negative-infinity.js create mode 100644 test/built-ins/String/raw/return-empty-string-if-length-is-not-defined.js create mode 100644 test/built-ins/String/raw/return-empty-string-if-length-is-undefined.js create mode 100644 test/built-ins/String/raw/return-empty-string-if-length-is-zero-NaN.js create mode 100644 test/built-ins/String/raw/return-empty-string-if-length-is-zero-boolean.js create mode 100644 test/built-ins/String/raw/return-empty-string-if-length-is-zero-null.js create mode 100644 test/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-number.js create mode 100644 test/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-string.js create mode 100644 test/built-ins/String/raw/return-the-string-value-from-template.js create mode 100644 test/built-ins/String/raw/return-the-string-value.js create mode 100644 test/built-ins/String/raw/returns-abrupt-from-next-key-toString.js create mode 100644 test/built-ins/String/raw/returns-abrupt-from-next-key.js create mode 100644 test/built-ins/String/raw/returns-abrupt-from-substitution-symbol.js create mode 100644 test/built-ins/String/raw/returns-abrupt-from-substitution.js create mode 100644 test/built-ins/String/raw/substitutions-are-appended-on-same-index.js create mode 100644 test/built-ins/String/raw/substitutions-are-limited-to-template-raw-length.js create mode 100644 test/built-ins/String/raw/template-length-is-symbol-throws.js create mode 100644 test/built-ins/String/raw/template-length-throws.js create mode 100644 test/built-ins/String/raw/template-not-object-throws.js create mode 100644 test/built-ins/String/raw/template-raw-not-object-throws.js create mode 100644 test/built-ins/String/raw/template-raw-throws.js create mode 100644 test/built-ins/String/raw/template-substitutions-are-appended-on-same-index.js diff --git a/test/built-ins/String/raw/length.js b/test/built-ins/String/raw/length.js new file mode 100644 index 0000000000..93d63a7d9c --- /dev/null +++ b/test/built-ins/String/raw/length.js @@ -0,0 +1,21 @@ +// 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'); diff --git a/test/built-ins/String/raw/name.js b/test/built-ins/String/raw/name.js new file mode 100644 index 0000000000..92f9a9ae6f --- /dev/null +++ b/test/built-ins/String/raw/name.js @@ -0,0 +1,22 @@ +// 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'); diff --git a/test/built-ins/String/raw/nextkey-is-symbol-throws.js b/test/built-ins/String/raw/nextkey-is-symbol-throws.js new file mode 100644 index 0000000000..5d9a3b5df3 --- /dev/null +++ b/test/built-ins/String/raw/nextkey-is-symbol-throws.js @@ -0,0 +1,30 @@ +// 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); +}); diff --git a/test/built-ins/String/raw/raw.js b/test/built-ins/String/raw/raw.js new file mode 100644 index 0000000000..64f99944a0 --- /dev/null +++ b/test/built-ins/String/raw/raw.js @@ -0,0 +1,17 @@ +// 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'); diff --git a/test/built-ins/String/raw/return-empty-string-from-empty-array-length.js b/test/built-ins/String/raw/return-empty-string-from-empty-array-length.js new file mode 100644 index 0000000000..8295768961 --- /dev/null +++ b/test/built-ins/String/raw/return-empty-string-from-empty-array-length.js @@ -0,0 +1,21 @@ +// 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, ''); diff --git a/test/built-ins/String/raw/return-empty-string-if-length-is-negative-infinity.js b/test/built-ins/String/raw/return-empty-string-if-length-is-negative-infinity.js new file mode 100644 index 0000000000..d2f199ea52 --- /dev/null +++ b/test/built-ins/String/raw/return-empty-string-if-length-is-negative-infinity.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 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, ''); diff --git a/test/built-ins/String/raw/return-empty-string-if-length-is-not-defined.js b/test/built-ins/String/raw/return-empty-string-if-length-is-not-defined.js new file mode 100644 index 0000000000..00d726ce82 --- /dev/null +++ b/test/built-ins/String/raw/return-empty-string-if-length-is-not-defined.js @@ -0,0 +1,21 @@ +// 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, ''); diff --git a/test/built-ins/String/raw/return-empty-string-if-length-is-undefined.js b/test/built-ins/String/raw/return-empty-string-if-length-is-undefined.js new file mode 100644 index 0000000000..b2bed9bc3d --- /dev/null +++ b/test/built-ins/String/raw/return-empty-string-if-length-is-undefined.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: { + length: undefined + } +}); + +assert.sameValue(result, ''); diff --git a/test/built-ins/String/raw/return-empty-string-if-length-is-zero-NaN.js b/test/built-ins/String/raw/return-empty-string-if-length-is-zero-NaN.js new file mode 100644 index 0000000000..74a6ffe7b6 --- /dev/null +++ b/test/built-ins/String/raw/return-empty-string-if-length-is-zero-NaN.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 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, ''); diff --git a/test/built-ins/String/raw/return-empty-string-if-length-is-zero-boolean.js b/test/built-ins/String/raw/return-empty-string-if-length-is-zero-boolean.js new file mode 100644 index 0000000000..e1b82ac427 --- /dev/null +++ b/test/built-ins/String/raw/return-empty-string-if-length-is-zero-boolean.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 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, ''); diff --git a/test/built-ins/String/raw/return-empty-string-if-length-is-zero-null.js b/test/built-ins/String/raw/return-empty-string-if-length-is-zero-null.js new file mode 100644 index 0000000000..6ab757b6fe --- /dev/null +++ b/test/built-ins/String/raw/return-empty-string-if-length-is-zero-null.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 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, ''); diff --git a/test/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-number.js b/test/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-number.js new file mode 100644 index 0000000000..5203c1eb8e --- /dev/null +++ b/test/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-number.js @@ -0,0 +1,43 @@ +// 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'); diff --git a/test/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-string.js b/test/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-string.js new file mode 100644 index 0000000000..f4d93d823a --- /dev/null +++ b/test/built-ins/String/raw/return-empty-string-if-length-is-zero-or-less-string.js @@ -0,0 +1,36 @@ +// 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 == ""'); diff --git a/test/built-ins/String/raw/return-the-string-value-from-template.js b/test/built-ins/String/raw/return-the-string-value-from-template.js new file mode 100644 index 0000000000..4651266d94 --- /dev/null +++ b/test/built-ins/String/raw/return-the-string-value-from-template.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 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'); diff --git a/test/built-ins/String/raw/return-the-string-value.js b/test/built-ins/String/raw/return-the-string-value.js new file mode 100644 index 0000000000..7fa4da77ce --- /dev/null +++ b/test/built-ins/String/raw/return-the-string-value.js @@ -0,0 +1,39 @@ +// 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'); diff --git a/test/built-ins/String/raw/returns-abrupt-from-next-key-toString.js b/test/built-ins/String/raw/returns-abrupt-from-next-key-toString.js new file mode 100644 index 0000000000..704f796bab --- /dev/null +++ b/test/built-ins/String/raw/returns-abrupt-from-next-key-toString.js @@ -0,0 +1,33 @@ +// 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); +}); diff --git a/test/built-ins/String/raw/returns-abrupt-from-next-key.js b/test/built-ins/String/raw/returns-abrupt-from-next-key.js new file mode 100644 index 0000000000..a79a4ceb57 --- /dev/null +++ b/test/built-ins/String/raw/returns-abrupt-from-next-key.js @@ -0,0 +1,46 @@ +// 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); +}); diff --git a/test/built-ins/String/raw/returns-abrupt-from-substitution-symbol.js b/test/built-ins/String/raw/returns-abrupt-from-substitution-symbol.js new file mode 100644 index 0000000000..a08a9fdf96 --- /dev/null +++ b/test/built-ins/String/raw/returns-abrupt-from-substitution-symbol.js @@ -0,0 +1,43 @@ +// 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(''), ''); +}); diff --git a/test/built-ins/String/raw/returns-abrupt-from-substitution.js b/test/built-ins/String/raw/returns-abrupt-from-substitution.js new file mode 100644 index 0000000000..a41a9d348f --- /dev/null +++ b/test/built-ins/String/raw/returns-abrupt-from-substitution.js @@ -0,0 +1,46 @@ +// 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, ''); +}); diff --git a/test/built-ins/String/raw/substitutions-are-appended-on-same-index.js b/test/built-ins/String/raw/substitutions-are-appended-on-same-index.js new file mode 100644 index 0000000000..fb9e31c117 --- /dev/null +++ b/test/built-ins/String/raw/substitutions-are-appended-on-same-index.js @@ -0,0 +1,36 @@ +// 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'); diff --git a/test/built-ins/String/raw/substitutions-are-limited-to-template-raw-length.js b/test/built-ins/String/raw/substitutions-are-limited-to-template-raw-length.js new file mode 100644 index 0000000000..e2a2a8c061 --- /dev/null +++ b/test/built-ins/String/raw/substitutions-are-limited-to-template-raw-length.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: > + 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'); diff --git a/test/built-ins/String/raw/template-length-is-symbol-throws.js b/test/built-ins/String/raw/template-length-is-symbol-throws.js new file mode 100644 index 0000000000..9ef8d1f757 --- /dev/null +++ b/test/built-ins/String/raw/template-length-is-symbol-throws.js @@ -0,0 +1,29 @@ +// 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) + } + }); +}); diff --git a/test/built-ins/String/raw/template-length-throws.js b/test/built-ins/String/raw/template-length-throws.js new file mode 100644 index 0000000000..7fe2c5b9f2 --- /dev/null +++ b/test/built-ins/String/raw/template-length-throws.js @@ -0,0 +1,33 @@ +// 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); +}); diff --git a/test/built-ins/String/raw/template-not-object-throws.js b/test/built-ins/String/raw/template-not-object-throws.js new file mode 100644 index 0000000000..18760f82ec --- /dev/null +++ b/test/built-ins/String/raw/template-not-object-throws.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: > + 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); +}); diff --git a/test/built-ins/String/raw/template-raw-not-object-throws.js b/test/built-ins/String/raw/template-raw-not-object-throws.js new file mode 100644 index 0000000000..c27ea363c2 --- /dev/null +++ b/test/built-ins/String/raw/template-raw-not-object-throws.js @@ -0,0 +1,30 @@ +// 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 + }); +}); diff --git a/test/built-ins/String/raw/template-raw-throws.js b/test/built-ins/String/raw/template-raw-throws.js new file mode 100644 index 0000000000..273826cc2e --- /dev/null +++ b/test/built-ins/String/raw/template-raw-throws.js @@ -0,0 +1,29 @@ +// 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); +}); diff --git a/test/built-ins/String/raw/template-substitutions-are-appended-on-same-index.js b/test/built-ins/String/raw/template-substitutions-are-appended-on-same-index.js new file mode 100644 index 0000000000..bb97761bcb --- /dev/null +++ b/test/built-ins/String/raw/template-substitutions-are-appended-on-same-index.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 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');