diff options
Diffstat (limited to 'js/src/tests/test262/language/expressions/template-literal')
59 files changed, 1513 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/template-literal/browser.js b/js/src/tests/test262/language/expressions/template-literal/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/browser.js diff --git a/js/src/tests/test262/language/expressions/template-literal/evaluation-order.js b/js/src/tests/test262/language/expressions/template-literal/evaluation-order.js new file mode 100644 index 0000000000..753726e715 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/evaluation-order.js @@ -0,0 +1,26 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8 +description: Expressions should be evaluated in left-to-right order. +---*/ + +var tag = function(templateObject, a, b, c) { + callCount++; + assert.sameValue(a, 0); + assert.sameValue(b, 1); + assert.sameValue(c, 2); +}; +var i = 0; +var callCount; + +assert.sameValue(`a${ i++ }b${ i++ }c${ i++ }d`, 'a0b1c2d'); + +i = 0; +callCount = 0; + +tag`a${ i++ }b${ i++ }c${ i++ }d`; + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-hexidecimal-character-escape-sequence-truncated-1.js b/js/src/tests/test262/language/expressions/template-literal/invalid-hexidecimal-character-escape-sequence-truncated-1.js new file mode 100644 index 0000000000..fe2f0a44ea --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-hexidecimal-character-escape-sequence-truncated-1.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid hexidecimal character escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\x0`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-hexidecimal-character-escape-sequence-truncated-2.js b/js/src/tests/test262/language/expressions/template-literal/invalid-hexidecimal-character-escape-sequence-truncated-2.js new file mode 100644 index 0000000000..443c186ea3 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-hexidecimal-character-escape-sequence-truncated-2.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Tim Disney. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid hexidecimal character escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\x0G`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-hexidecimal-character-escape-sequence-truncated-3.js b/js/src/tests/test262/language/expressions/template-literal/invalid-hexidecimal-character-escape-sequence-truncated-3.js new file mode 100644 index 0000000000..6795e2bdd9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-hexidecimal-character-escape-sequence-truncated-3.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Tim Disney. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid hexidecimal character escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\xG`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-legacy-octal-escape-sequence-8.js b/js/src/tests/test262/language/expressions/template-literal/invalid-legacy-octal-escape-sequence-8.js new file mode 100644 index 0000000000..862ea33b48 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-legacy-octal-escape-sequence-8.js @@ -0,0 +1,28 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2020 Sony Interactive Entertainment Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: > + Invalid octal escape sequence (regardless of the presence of Annex B) +info: | + TemplateCharacter :: + $ [lookahead ≠ {] + \ TemplateEscapeSequence + \ NotEscapeSequence + LineContinuation + LineTerminatorSequence + SourceCharacter but not one of ` or \ or $ or LineTerminator + TemplateEscapeSequence :: + CharacterEscapeSequence + 0 [lookahead ∉ DecimalDigit] + HexEscapeSequence + UnicodeEscapeSequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\8`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-legacy-octal-escape-sequence-9.js b/js/src/tests/test262/language/expressions/template-literal/invalid-legacy-octal-escape-sequence-9.js new file mode 100644 index 0000000000..56fda2d44d --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-legacy-octal-escape-sequence-9.js @@ -0,0 +1,28 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2020 Sony Interactive Entertainment Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: > + Invalid octal escape sequence (regardless of the presence of Annex B) +info: | + TemplateCharacter :: + $ [lookahead ≠ {] + \ TemplateEscapeSequence + \ NotEscapeSequence + LineContinuation + LineTerminatorSequence + SourceCharacter but not one of ` or \ or $ or LineTerminator + TemplateEscapeSequence :: + CharacterEscapeSequence + 0 [lookahead ∉ DecimalDigit] + HexEscapeSequence + UnicodeEscapeSequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\9`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-legacy-octal-escape-sequence.js b/js/src/tests/test262/language/expressions/template-literal/invalid-legacy-octal-escape-sequence.js new file mode 100644 index 0000000000..66b4742731 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-legacy-octal-escape-sequence.js @@ -0,0 +1,27 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 16.1 +description: Invalid octal escape sequence +info: | + TemplateCharacter :: + $ [lookahead ≠ {] + \ TemplateEscapeSequence + \ NotEscapeSequence + LineContinuation + LineTerminatorSequence + SourceCharacter but not one of ` or \ or $ or LineTerminator + TemplateEscapeSequence :: + CharacterEscapeSequence + 0 [lookahead ∉ DecimalDigit] + HexEscapeSequence + UnicodeEscapeSequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\00`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-1.js b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-1.js new file mode 100644 index 0000000000..29907753fe --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-1.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid unicode escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\u0`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-2.js b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-2.js new file mode 100644 index 0000000000..b2f3ddf758 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-2.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Tim Disney. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid unicode escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\u0g`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-3.js b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-3.js new file mode 100644 index 0000000000..cc77d03b8b --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-3.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Tim Disney. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid unicode escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\u00g`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-4.js b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-4.js new file mode 100644 index 0000000000..280d629968 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-4.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Tim Disney. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid unicode escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\u000g`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-5.js b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-5.js new file mode 100644 index 0000000000..27241d13ad --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-5.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Tim Disney. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid unicode escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\u{g`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-6.js b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-6.js new file mode 100644 index 0000000000..846cbf625e --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-6.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Tim Disney. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid unicode escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\u{0`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-7.js b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-7.js new file mode 100644 index 0000000000..78346d2f78 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-7.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Tim Disney. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid unicode escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\u{10FFFFF}`; diff --git a/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-8.js b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-8.js new file mode 100644 index 0000000000..1dc2d20316 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/invalid-unicode-escape-sequence-8.js @@ -0,0 +1,14 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Tim Disney. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-template-literal-lexical-components +description: Invalid unicode escape sequence +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\u{10FFFFF}${'inner'}right`; diff --git a/js/src/tests/test262/language/expressions/template-literal/literal-expr-abrupt.js b/js/src/tests/test262/language/expressions/template-literal/literal-expr-abrupt.js new file mode 100644 index 0000000000..a149a26682 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/literal-expr-abrupt.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: 12.2.8.5 +description: Abrupt completion when evaluating expression of TemplateLiteral +info: | + TemplateLiteral : TemplateHead Expression TemplateSpans + + 1. Let head be the TV of TemplateHead as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). + 4. ReturnIfAbrupt(middle). +---*/ + +assert.throws(Test262Error, function() { + `${function() { throw new Test262Error(); }()}`; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/literal-expr-function.js b/js/src/tests/test262/language/expressions/template-literal/literal-expr-function.js new file mode 100644 index 0000000000..3801f8a72c --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/literal-expr-function.js @@ -0,0 +1,18 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Function invocation in expression position of TemplateLiteral +info: | + TemplateLiteral : TemplateHead Expression TemplateSpans + + 1. Let head be the TV of TemplateHead as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). +---*/ + +function fn() { return 'result'; } + +assert.sameValue(`foo ${fn()} bar`, 'foo result bar'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/literal-expr-member-expr.js b/js/src/tests/test262/language/expressions/template-literal/literal-expr-member-expr.js new file mode 100644 index 0000000000..00410aa84e --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/literal-expr-member-expr.js @@ -0,0 +1,36 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: MemberExpression in expression position of TemplateLiteral +info: | + TemplateLiteral : TemplateHead Expression TemplateSpans + + 1. Let head be the TV of TemplateHead as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). +---*/ + +var object = { + number: 5, + string: 'stringValue' +}; + +assert.sameValue( + `foo ${object.number} bar`, 'foo 5 bar', 'number value property' +); +assert.sameValue( + `foo ${object.string} bar`, 'foo stringValue bar', 'string value property' +); +assert.sameValue( + `foo ${object['string']} bar`, + 'foo stringValue bar', + 'string value property (single-quote string dereference)' +); +assert.sameValue( + `foo ${object["string"]} bar`, + 'foo stringValue bar', + 'string value property (double-quote string dereference)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/literal-expr-method.js b/js/src/tests/test262/language/expressions/template-literal/literal-expr-method.js new file mode 100644 index 0000000000..fc1ccec648 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/literal-expr-method.js @@ -0,0 +1,19 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Method invocation in expression position of TemplateLiteral +info: | + TemplateLiteral : TemplateHead Expression TemplateSpans + + 1. Let head be the TV of TemplateHead as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). +---*/ +var object = { + fn: function() { return 'result'; } +}; + +assert.sameValue(`foo ${object.fn()} bar`, 'foo result bar'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/literal-expr-obj.js b/js/src/tests/test262/language/expressions/template-literal/literal-expr-obj.js new file mode 100644 index 0000000000..8eeb2fc503 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/literal-expr-obj.js @@ -0,0 +1,31 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Object reference in expression position of TemplateLiteral +info: | + TemplateLiteral : TemplateHead Expression TemplateSpans + + 1. Let head be the TV of TemplateHead as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). +---*/ + +var plain = {}; +var custom = { + toString: function() { + return '"own" toString'; + } +}; + +assert.sameValue(`${plain}`, '[object Object]'); +assert.sameValue(`1${plain}`, '1[object Object]'); +assert.sameValue(`${plain}2`, '[object Object]2'); +assert.sameValue(`1${plain}2`, '1[object Object]2'); + +assert.sameValue(`${custom}`, '"own" toString'); +assert.sameValue(`1${custom}`, '1"own" toString'); +assert.sameValue(`${custom}2`, '"own" toString2'); +assert.sameValue(`1${custom}2`, '1"own" toString2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/literal-expr-primitive.js b/js/src/tests/test262/language/expressions/template-literal/literal-expr-primitive.js new file mode 100644 index 0000000000..589bc8edba --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/literal-expr-primitive.js @@ -0,0 +1,17 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Primitive value in expression position of TemplateLiteral +info: | + TemplateLiteral : TemplateHead Expression TemplateSpans + + 1. Let head be the TV of TemplateHead as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). +---*/ + +assert.sameValue(`foo ${5} bar`, 'foo 5 bar', 'number value'); +assert.sameValue(`foo ${'string'} bar`, 'foo string bar', 'string value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/literal-expr-template.js b/js/src/tests/test262/language/expressions/template-literal/literal-expr-template.js new file mode 100644 index 0000000000..9a4fa20eb6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/literal-expr-template.js @@ -0,0 +1,16 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Template literal in expression position of TemplateLiteral +info: | + TemplateLiteral : TemplateHead Expression TemplateSpans + + 1. Let head be the TV of TemplateHead as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). +---*/ + +assert.sameValue(`foo ${`bar ${5} baz`} qux`, 'foo bar 5 baz qux'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/literal-expr-tostr-error.js b/js/src/tests/test262/language/expressions/template-literal/literal-expr-tostr-error.js new file mode 100644 index 0000000000..48d049d5e7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/literal-expr-tostr-error.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: 12.2.8.5 +description: Abrupt completion when converting expression value of TemplateLiteral +info: | + TemplateLiteral : TemplateHead Expression TemplateSpans + + 1. Let head be the TV of TemplateHead as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). + 4. ReturnIfAbrupt(middle). +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + `${obj}`; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-abrupt.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-abrupt.js new file mode 100644 index 0000000000..9ebcca2c43 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-abrupt.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: 12.2.8.5 +description: Abrupt completion when evaluating expression of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddleList TemplateMiddle Expression + + 1. Let rest be the result of evaluating TemplateMiddleList . + 2. ReturnIfAbrupt(rest). + 3. Let middle be the TV of TemplateMiddle as defined in 11.8.6. + 4. Let sub be the result of evaluating Expression. + 5. Let last be ToString(sub). + 6. ReturnIfAbrupt(last). +---*/ + +assert.throws(Test262Error, function() { + `${0}${1}${function() { throw new Test262Error(); }()}`; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-function.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-function.js new file mode 100644 index 0000000000..e3da7b4e74 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-function.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Function invocation in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddleList TemplateMiddle Expression + + 1. Let rest be the result of evaluating TemplateMiddleList . + 2. ReturnIfAbrupt(rest). + 3. Let middle be the TV of TemplateMiddle as defined in 11.8.6. + 4. Let sub be the result of evaluating Expression. + 5. Let last be ToString(sub). +---*/ + +function fn() { return 'result'; } + +assert.sameValue(`${0} ${1} ${fn()}`, '0 1 result'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-member-expr.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-member-expr.js new file mode 100644 index 0000000000..5d47e017c0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-member-expr.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: MemberExpression in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddleList TemplateMiddle Expression + + 1. Let rest be the result of evaluating TemplateMiddleList . + 2. ReturnIfAbrupt(rest). + 3. Let middle be the TV of TemplateMiddle as defined in 11.8.6. + 4. Let sub be the result of evaluating Expression. + 5. Let last be ToString(sub). +---*/ + +var object = { + number: 5, + string: 'stringValue' +}; + +assert.sameValue( + `${0} ${1} ${object.number} bar`, '0 1 5 bar', 'number value property' +); +assert.sameValue( + `${0} ${1} ${object.string} bar`, + '0 1 stringValue bar', + 'string value property' +); +assert.sameValue( + `${0} ${1} ${object['string']} bar`, + '0 1 stringValue bar', + 'string value property (single-quote string dereference)' +); +assert.sameValue( + `${0} ${1} ${object["string"]} bar`, + '0 1 stringValue bar', + 'string value property (double-quote string dereference)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-method.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-method.js new file mode 100644 index 0000000000..609a1b5d1d --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-method.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: 12.2.8.5 +description: Method invocation in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddleList TemplateMiddle Expression + + 1. Let rest be the result of evaluating TemplateMiddleList . + 2. ReturnIfAbrupt(rest). + 3. Let middle be the TV of TemplateMiddle as defined in 11.8.6. + 4. Let sub be the result of evaluating Expression. + 5. Let last be ToString(sub). +---*/ +var object = { + fn: function() { return 'result'; } +}; + +assert.sameValue(`${0} ${1} ${object.fn()} bar`, '0 1 result bar'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-obj.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-obj.js new file mode 100644 index 0000000000..9757199311 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-obj.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: 12.2.8.5 +description: Object reference in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddleList TemplateMiddle Expression + + 1. Let rest be the result of evaluating TemplateMiddleList . + 2. ReturnIfAbrupt(rest). + 3. Let middle be the TV of TemplateMiddle as defined in 11.8.6. + 4. Let sub be the result of evaluating Expression. + 5. Let last be ToString(sub). +---*/ + +var plain = {}; +var custom = { + toString: function() { + return '"own" toString'; + } +}; + +assert.sameValue(`${0} ${1} ${plain}`, '0 1 [object Object]'); +assert.sameValue(`${0} ${1} ${plain}`, '0 1 [object Object]'); +assert.sameValue(`${0} ${1} ${plain}2`, '0 1 [object Object]2'); +assert.sameValue(`${0} ${1} ${plain}2`, '0 1 [object Object]2'); + +assert.sameValue(`${0} ${1} ${custom}`, '0 1 "own" toString'); +assert.sameValue(`${0} ${1} ${custom}`, '0 1 "own" toString'); +assert.sameValue(`${0} ${1} ${custom}2`, '0 1 "own" toString2'); +assert.sameValue(`${0} ${1} ${custom}2`, '0 1 "own" toString2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-primitive.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-primitive.js new file mode 100644 index 0000000000..6b6de83834 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-primitive.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: 12.2.8.5 +description: Primitive value in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddleList TemplateMiddle Expression + + 1. Let rest be the result of evaluating TemplateMiddleList . + 2. ReturnIfAbrupt(rest). + 3. Let middle be the TV of TemplateMiddle as defined in 11.8.6. + 4. Let sub be the result of evaluating Expression. + 5. Let last be ToString(sub). +---*/ + +assert.sameValue(`${0} ${1} ${5} bar`, '0 1 5 bar', 'number value'); +assert.sameValue(`${0} ${1} ${'string'} bar`, '0 1 string bar', 'string value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-template.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-template.js new file mode 100644 index 0000000000..703e390c68 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-template.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Template literal in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddleList TemplateMiddle Expression + + 1. Let rest be the result of evaluating TemplateMiddleList . + 2. ReturnIfAbrupt(rest). + 3. Let middle be the TV of TemplateMiddle as defined in 11.8.6. + 4. Let sub be the result of evaluating Expression. + 5. Let last be ToString(sub). +---*/ + +assert.sameValue(`${0} ${1} ${`bar ${5} baz`} qux`, '0 1 bar 5 baz qux'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-tostr-error.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-tostr-error.js new file mode 100644 index 0000000000..fee24208af --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-many-expr-tostr-error.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Abrupt completion when converting expression value of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddleList TemplateMiddle Expression + + 1. Let rest be the result of evaluating TemplateMiddleList . + 2. ReturnIfAbrupt(rest). + 3. Let middle be the TV of TemplateMiddle as defined in 11.8.6. + 4. Let sub be the result of evaluating Expression. + 5. Let last be ToString(sub). + 6. ReturnIfAbrupt(last). +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + `${0} ${1} ${obj}`; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-abrupt.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-abrupt.js new file mode 100644 index 0000000000..438a0422f8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-abrupt.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: 12.2.8.5 +description: Abrupt completion when evaluating expression of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddle Expression + + 1. Let head be the TV of TemplateMiddle as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). + 4. ReturnIfAbrupt(middle). +---*/ + +assert.throws(Test262Error, function() { + `${0}${function() { throw new Test262Error(); }()}`; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-function.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-function.js new file mode 100644 index 0000000000..7421d6972b --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-function.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Function invocation in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddle Expression + + 1. Let head be the TV of TemplateMiddle as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). +---*/ + +function fn() { return 'result'; } + +assert.sameValue(`${0} ${fn()}`, '0 result'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-member-expr.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-member-expr.js new file mode 100644 index 0000000000..9cc76f637c --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-member-expr.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: 12.2.8.5 +description: MemberExpression in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddle Expression + + 1. Let head be the TV of TemplateMiddle as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). + 4. ReturnIfAbrupt(middle). +---*/ + +var object = { + number: 5, + string: 'stringValue' +}; + +assert.sameValue( + `${0} ${object.number} bar`, '0 5 bar', 'number value property' +); +assert.sameValue( + `${0} ${object.string} bar`, '0 stringValue bar', 'string value property' +); +assert.sameValue( + `${0} ${object['string']} bar`, + '0 stringValue bar', + 'string value property (single-quote string dereference)' +); +assert.sameValue( + `${0} ${object["string"]} bar`, + '0 stringValue bar', + 'string value property (double-quote string dereference)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-method.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-method.js new file mode 100644 index 0000000000..78e3df887d --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-method.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Method invocation in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddle Expression + + 1. Let head be the TV of TemplateMiddle as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). + 4. ReturnIfAbrupt(middle). +---*/ +var object = { + fn: function() { return 'result'; } +}; + +assert.sameValue(`${0} ${object.fn()} bar`, '0 result bar'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-obj.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-obj.js new file mode 100644 index 0000000000..457f9d649a --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-obj.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: 12.2.8.5 +description: Object reference in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddle Expression + + 1. Let head be the TV of TemplateMiddle as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). + 4. ReturnIfAbrupt(middle). +---*/ + +var plain = {}; +var custom = { + toString: function() { + return '"own" toString'; + } +}; + +assert.sameValue(`${0} ${plain}`, '0 [object Object]'); +assert.sameValue(`${0} ${plain}`, '0 [object Object]'); +assert.sameValue(`${0} ${plain}2`, '0 [object Object]2'); +assert.sameValue(`${0} ${plain}2`, '0 [object Object]2'); + +assert.sameValue(`${0} ${custom}`, '0 "own" toString'); +assert.sameValue(`${0} ${custom}`, '0 "own" toString'); +assert.sameValue(`${0} ${custom}2`, '0 "own" toString2'); +assert.sameValue(`${0} ${custom}2`, '0 "own" toString2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-primitive.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-primitive.js new file mode 100644 index 0000000000..94298ac0f6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-primitive.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: 12.2.8.5 +description: Primitive value in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddle Expression + + 1. Let head be the TV of TemplateMiddle as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). +---*/ + +assert.sameValue(`${0} ${5} bar`, '0 5 bar', 'number value'); +assert.sameValue(`${0} ${'string'} bar`, '0 string bar', 'string value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-template.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-template.js new file mode 100644 index 0000000000..394322c17c --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-template.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Template literal in expression position of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddle Expression + + 1. Let head be the TV of TemplateMiddle as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). +---*/ + +assert.sameValue(`${0} ${`bar ${5} baz`} qux`, '0 bar 5 baz qux'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-tostr-error.js b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-tostr-error.js new file mode 100644 index 0000000000..1630d2df5a --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/middle-list-one-expr-tostr-error.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: 12.2.8.5 +description: Abrupt completion when converting expression value of TemplateMiddleList +info: | + TemplateMiddleList : TemplateMiddle Expression + + 1. Let head be the TV of TemplateMiddle as defined in 11.8.6. + 2. Let sub be the result of evaluating Expression. + 3. Let middle be ToString(sub). + 4. ReturnIfAbrupt(middle). +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + `${0} ${obj}`; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/mongolian-vowel-separator-eval.js b/js/src/tests/test262/language/expressions/template-literal/mongolian-vowel-separator-eval.js new file mode 100644 index 0000000000..eb379893c4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/mongolian-vowel-separator-eval.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-unicode-format-control-characters +description: > + Mongolian Vowel Separator can appear in template literals (eval code). +info: | + 11.1 Unicode Format-Control Characters + + The Unicode format-control characters (i.e., the characters in category “Cf” + in the Unicode Character Database such as LEFT-TO-RIGHT MARK or RIGHT-TO-LEFT + MARK) are control codes used to control the formatting of a range of text in + the absence of higher-level protocols for this (such as mark-up languages). + + It is useful to allow format-control characters in source text to facilitate + editing and display. All format control characters may be used within comments, + and within string literals, template literals, and regular expression literals. +features: [u180e] +---*/ + +assert.sameValue(eval("`\u180E`"), "\u180E"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/mongolian-vowel-separator.js b/js/src/tests/test262/language/expressions/template-literal/mongolian-vowel-separator.js new file mode 100644 index 0000000000..b0acc7f31a --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/mongolian-vowel-separator.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-unicode-format-control-characters +description: > + Mongolian Vowel Separator can appear in template literals. +info: | + 11.1 Unicode Format-Control Characters + + The Unicode format-control characters (i.e., the characters in category “Cf” + in the Unicode Character Database such as LEFT-TO-RIGHT MARK or RIGHT-TO-LEFT + MARK) are control codes used to control the formatting of a range of text in + the absence of higher-level protocols for this (such as mark-up languages). + + It is useful to allow format-control characters in source text to facilitate + editing and display. All format control characters may be used within comments, + and within string literals, template literals, and regular expression literals. +features: [u180e] +---*/ + +// U+180E in template literals; UTF8(0x180E) = 0xE1 0xA0 0x8E +assert.sameValue(``, "\u180E"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/no-sub.js b/js/src/tests/test262/language/expressions/template-literal/no-sub.js new file mode 100644 index 0000000000..3b12d123af --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/no-sub.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.8.5 +description: Evaluation of NoSubstitutionTemplate +info: | + 12.2.8.5 Runtime Semantics: Evaluation + TemplateLiteral : NoSubstitutionTemplate + + 1. Return the string value whose code units are the elements of the TV of + NoSubstitutionTemplate as defined in 11.8.6. +---*/ + +assert.sameValue(`NoSubstitutionTemplate`, 'NoSubstitutionTemplate'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/shell.js b/js/src/tests/test262/language/expressions/template-literal/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/shell.js diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-character-escape-sequence.js b/js/src/tests/test262/language/expressions/template-literal/tv-character-escape-sequence.js new file mode 100644 index 0000000000..56d27f20a5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-character-escape-sequence.js @@ -0,0 +1,119 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 11.8.6.1 +description: Template values of character escape sequences +info: | + The TV of TemplateCharacter :: \ EscapeSequence is the SV of + EscapeSequence. + The TRV of TemplateCharacter :: \ EscapeSequence is the sequence consisting + of the code unit value 0x005C followed by the code units of TRV of + EscapeSequence. + The TRV of CharacterEscapeSequence :: SingleEscapeCharacter is the TRV of + the SingleEscapeCharacter. + The TRV of CharacterEscapeSequence :: NonEscapeCharacter is the SV of the + NonEscapeCharacter. +---*/ +var calls; + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], "'", "TV of NonEscapeCharacter"); + assert.sameValue(s.raw[0], "\u005C\u0027", "TRV of NonEscapeCharacter"); +})`\'`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], "\"", "TV of SingleEscapeCharacter (double quote)"); + assert.sameValue( + s.raw[0], "\u005C\u0022", "TRV of SingleEscapeCharacter (double quote)" + ); +})`\"`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], "\\", "TV of SingleEscapeCharacter (backslash)"); + assert.sameValue( + s.raw[0], "\u005C\u005C", "TRV of SingleEscapeCharacter (backslash)" + ); +})`\\`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], "\b", "TV of SingleEscapeCharacter (backspace)"); + assert.sameValue( + s.raw[0], "\u005Cb", "TRV of SingleEscapeCharacter (backspace)" + ); +})`\b`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], "\f", "TV of SingleEscapeCharacter (form feed)"); + assert.sameValue( + s.raw[0], "\u005Cf", "TRV of SingleEscapeCharacter (form feed)" + ); +})`\f`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], "\n", "TV of SingleEscapeCharacter (new line)"); + assert.sameValue( + s.raw[0], "\u005Cn", "TRV of SingleEscapeCharacter (new line)" + ); +})`\n`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue( + s[0], "\r", "TV of SingleEscapeCharacter (carriage return)" + ); + assert.sameValue( + s.raw[0], "\u005Cr", "TRV of SingleEscapeCharacter (carriage return)" + ); +})`\r`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], " ", "TV of SingleEscapeCharacter (tab)"); + assert.sameValue(s.raw[0], "\u005Ct", "TRV of SingleEscapeCharacter (tab)"); +})`\t`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue( + s[0], "\v", "TV of SingleEscapeCharacter (line tabulation)" + ); + assert.sameValue( + s.raw[0], "\u005Cv", "TRV of SingleEscapeCharacter (line tabulation)" + ); +})`\v`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], "`", "TV of SingleEscapeCharacter (backtick)"); + assert.sameValue( + s.raw[0], "\u005C`", "TRV of SingleEscapeCharacter (backtick)" + ); +})`\``; +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-hex-escape-sequence.js b/js/src/tests/test262/language/expressions/template-literal/tv-hex-escape-sequence.js new file mode 100644 index 0000000000..f3e2b2250b --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-hex-escape-sequence.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: 11.8.6.1 +description: Template values of hex escape sequences +info: | + The TV of TemplateCharacter :: \ EscapeSequence is the SV of + EscapeSequence. + The SV of UnicodeEscapeSequence :: u{ HexDigits } is the UTF16Encoding + (10.1.1) of the MV of HexDigits. + The TRV of UnicodeEscapeSequence :: u{ HexDigits } is the sequence + consisting of code unit value 0x0075 followed by code unit value 0x007B + followed by TRV of HexDigits followed by code unit value 0x007D. +---*/ + +var calls; + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], 'A', 'TV'); + assert.sameValue(s.raw[0], '\\x41', 'TRV'); +})`\x41`; +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-line-continuation.js b/js/src/tests/test262/language/expressions/template-literal/tv-line-continuation.js new file mode 100644 index 0000000000..5179573aa2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-line-continuation.js @@ -0,0 +1,44 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 11.8.6.1 +description: Template values of line continuations +info: | + The TV of LineContinuation :: \ LineTerminatorSequence is the empty code + unit sequence. + The TRV of LineContinuation :: \ LineTerminatorSequence is the sequence + consisting of the code unit value 0x005C followed by the code units of TRV + of LineTerminatorSequence. +---*/ + +var calls; + +calls = 0; +(function(cs) { + calls++; + assert.sameValue(cs[0], '', 'Line Feed and Carriage Return'); + assert.sameValue( + cs.raw[0], '\u005C\n\u005C\n\u005C\n', 'Line Feed and Carriage Return' + ); +})`\
+\ +\
` +assert.sameValue(calls, 1); + +calls = 0; +(function(cs) { + calls++; + assert.sameValue(cs[0], '', 'Line Separator'); + assert.sameValue(cs.raw[0], '\\\u2028', 'Line Separator'); +})`\
` +assert.sameValue(calls, 1); + +calls = 0; +(function(cs) { + calls++; + assert.sameValue(cs[0], '', 'Paragraph Separater'); + assert.sameValue(cs.raw[0], '\\\u2029', 'Paragraph Separator'); +})`\
` +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-line-terminator-sequence.js b/js/src/tests/test262/language/expressions/template-literal/tv-line-terminator-sequence.js new file mode 100644 index 0000000000..bf3fb07887 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-line-terminator-sequence.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: 11.8.6.1 +description: Template values of line terminator sequences +info: | + The TV of TemplateCharacter :: LineTerminatorSequence is the TRV of + LineTerminatorSequence. + The TRV of LineTerminatorSequence :: <LF> is the code unit value 0x000A. + The TRV of LineTerminatorSequence :: <CR> is the code unit value 0x000A. + The TRV of LineTerminatorSequence :: <LS> is the code unit value 0x2028. + The TRV of LineTerminatorSequence :: <PS> is the code unit value 0x2029. + The TRV of LineTerminatorSequence :: <CR><LF> is the sequence consisting of + the code unit value 0x000A. +---*/ + + +var calls; + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], '\n\n\n', 'Line Feed and Carriage Return'); + assert.sameValue(s.raw[0], '\n\n\n', 'Line Feed and Carriage Return'); +})`
+ +
`; +assert.sameValue(calls, 1); + +calls = 0; +(function(cs) { + calls++; + assert.sameValue(cs[0], '\u2028', 'Line Separator'); + assert.sameValue(cs.raw[0], '\u2028', 'Line Separator'); +})`
` +assert.sameValue(calls, 1); + +calls = 0; +(function(cs) { + calls++; + assert.sameValue(cs[0], '\u2029', 'Paragraph Separator'); + assert.sameValue(cs.raw[0], '\u2029', 'Paragraph Separator'); +})`
` +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-no-substitution.js b/js/src/tests/test262/language/expressions/template-literal/tv-no-substitution.js new file mode 100644 index 0000000000..13cc94369a --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-no-substitution.js @@ -0,0 +1,33 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 11.8.6.1 +description: Template values of templates without substitution patterns +info: | + The TV and TRV of NoSubstitutionTemplate :: `` is the empty code unit + sequence. + The TV of NoSubstitutionTemplate :: ` TemplateCharacters ` is the TV of + TemplateCharacters. + The TRV of NoSubstitutionTemplate :: ` TemplateCharacters ` is the TRV of + TemplateCharacters. +---*/ + +var calls; + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], '', 'Template value (empty)'); + assert.sameValue(s.raw[0], '', 'Template raw value (empty)'); +})``; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], 'foo', 'Template value (with content)'); + assert.sameValue(s.raw[0], 'foo', 'Template raw value (with content)'); +})`foo`; +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-null-character-escape-sequence.js b/js/src/tests/test262/language/expressions/template-literal/tv-null-character-escape-sequence.js Binary files differnew file mode 100644 index 0000000000..4ff6974579 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-null-character-escape-sequence.js diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-template-character.js b/js/src/tests/test262/language/expressions/template-literal/tv-template-character.js new file mode 100644 index 0000000000..d58d21ad1e --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-template-character.js @@ -0,0 +1,40 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 11.8.6.1 +description: Template values of single characters +info: | + The TV of TemplateCharacters :: TemplateCharacter is the TV of + TemplateCharacter. + The TV of TemplateCharacter :: SourceCharacter but not one of ` or \ or $ + or LineTerminator is the UTF16Encoding (10.1.1) of the code point value of + SourceCharacter. + The TV of TemplateCharacter :: $ is the code unit value 0x0024. + + The TRV of TemplateCharacters :: TemplateCharacter is the TRV of + TemplateCharacter. + The TRV of TemplateCharacter :: SourceCharacter but not one of ` or \ or $ + or LineTerminator is the UTF16Encoding (10.1.1) of the code point value of + SourceCharacter. + The TRV of TemplateCharacter :: $ is the code unit value 0x0024. +---*/ + +var calls; + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], 'a', '`a` character TV'); + assert.sameValue(s.raw[0], 'a', '`a` character TRV'); +})`a`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], '$', '`$` character TV'); + assert.sameValue(s.raw[0], '$', '`$` character TRV'); +})`$`; +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-template-characters.js b/js/src/tests/test262/language/expressions/template-literal/tv-template-characters.js new file mode 100644 index 0000000000..30e838ba59 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-template-characters.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. +/*--- +es6id: 11.8.6.1 +description: Template values of multiple template characters +info: | + The TV of TemplateCharacters :: TemplateCharacter TemplateCharacters is a + sequence consisting of the code units in the TV of TemplateCharacter + followed by all the code units in the TV of TemplateCharacters in order. + The TRV of TemplateCharacters :: TemplateCharacter TemplateCharacters is a + sequence consisting of the code units in the TRV of TemplateCharacter + followed by all the code units in the TRV of TemplateCharacters, in order. +---*/ + +var calls = 0; + +(function(s) { + calls++; + assert.sameValue(s.raw[0], 'test'); +})`test`; + +assert.sameValue(calls, 1); +assert.sameValue(`test`, 'test'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-template-head.js b/js/src/tests/test262/language/expressions/template-literal/tv-template-head.js new file mode 100644 index 0000000000..3a3d7df5e1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-template-head.js @@ -0,0 +1,32 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 11.8.6.1 +description: Template values of the template head pattern +info: | + The TV and TRV of TemplateHead :: `${ is the empty code unit sequence. + The TV of TemplateHead :: ` TemplateCharacters ${ is the TV of + TemplateCharacters. + The TRV of TemplateHead :: ` TemplateCharacters ${ is the TRV of + TemplateCharacters. +---*/ + +var calls; + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], '', 'Template value (empty)'); + assert.sameValue(s.raw[0], '', 'Template raw value (empty)'); +})`${1}`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], 'foo', 'Template value (with content)'); + assert.sameValue(s.raw[0], 'foo', 'Template raw value (with content)'); +})`foo${1}`; +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-template-middle.js b/js/src/tests/test262/language/expressions/template-literal/tv-template-middle.js new file mode 100644 index 0000000000..56e0b167aa --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-template-middle.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. +/*--- +es6id: 11.8.6.1 +description: Template values of the template middle pattern +info: | + The TV and TRV of TemplateMiddle :: }${ is the empty code unit sequence. + The TRV of TemplateMiddle :: } TemplateCharacters ${ is the TRV of + TemplateCharacters. +---*/ + +var calls; + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[1], '', 'Template value (empty)'); + assert.sameValue(s.raw[1], '', 'Template raw value (empty)'); +})`${1}${2}`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[1], 'foo', 'Template value (with content)'); + assert.sameValue(s.raw[1], 'foo', 'Template raw value (with content)'); +})`${1}foo${2}`; +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-template-tail.js b/js/src/tests/test262/language/expressions/template-literal/tv-template-tail.js new file mode 100644 index 0000000000..e04e089e44 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-template-tail.js @@ -0,0 +1,32 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 11.8.6.1 +description: Template values of the template tail pattern +info: | + The TV and TRV of TemplateTail :: }` is the empty code unit sequence. + The TV of TemplateTail :: } TemplateCharacters ` is the TV of + TemplateCharacters. + The TRV of TemplateTail :: } TemplateCharacters ` is the TRV of + TemplateCharacters. +---*/ + +var calls; + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[1], '', 'Template value (empty)'); + assert.sameValue(s.raw[1], '', 'Template raw value (empty)'); +})`${1}`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[1], 'foo', 'Template value (with content)'); + assert.sameValue(s.raw[1], 'foo', 'Template raw value (with content)'); +})`${1}foo`; +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-utf16-escape-sequence.js b/js/src/tests/test262/language/expressions/template-literal/tv-utf16-escape-sequence.js new file mode 100644 index 0000000000..d89be2fa1d --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-utf16-escape-sequence.js @@ -0,0 +1,52 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 11.8.6.1 +description: Template values of UTF-16 escape sequences +info: | + The TV of TemplateCharacter :: \ EscapeSequence is the SV of + EscapeSequence. + The SV of UnicodeEscapeSequence :: u{ HexDigits } is the UTF16Encoding + (10.1.1) of the MV of HexDigits. + The TRV of UnicodeEscapeSequence :: u Hex4Digits is the sequence consisting + of code unit value 0x0075 followed by TRV of Hex4Digits. + The TRV of UnicodeEscapeSequence :: u{ HexDigits } is the sequence + consisting of code unit value 0x0075 followed by code unit value 0x007B + followed by TRV of HexDigits followed by code unit value 0x007D. +---*/ + +var calls; + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], 'b', 'u Hex4Digits template value'); + assert.sameValue(s.raw[0], '\\u0062', 'u Hex4Digits template raw value'); +})`\u0062`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue(s[0], 'b', 'u{ HexDigits } template value'); + assert.sameValue( + s.raw[0], '\\u{62}', 'u{ Hex4Digits } template raw value' + ); +})`\u{62}`; +assert.sameValue(calls, 1); + +calls = 0; +(function(s) { + calls++; + assert.sameValue( + s[0], 'b', 'u{ HexDigits } template value (with leading zeros)' + ); + assert.sameValue( + s.raw[0], + '\\u{000062}', + 'u{ HexDigits } template raw value (with leading zeros)' + ); +})`\u{000062}`; +assert.sameValue(calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/tv-zwnbsp.js b/js/src/tests/test262/language/expressions/template-literal/tv-zwnbsp.js new file mode 100644 index 0000000000..e5bf735745 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/tv-zwnbsp.js @@ -0,0 +1,35 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 11.1.8.6.1 +description: Template values of the zero width no-break space character +info: | + The zero width no-break space format-control character may be used within + template literals. +---*/ + +var callCount; + +callCount = 0; +(function(s) { + callCount++; + assert.sameValue( + s[0], 'test', 'TV (specified via unicode escape sequence)' + ); + assert.sameValue( + s.raw[0], '\\uFEFFtest', 'TV (specified via unicode escape sequence)' + ); +})`\uFEFFtest`; +assert.sameValue(callCount, 1); + +callCount = 0; +(function(s) { + callCount++; + assert.sameValue(s[0], 'test', 'TV (specified via literal character)'); + assert.sameValue( + s.raw[0], 'test', 'TV (specified via literal character)' + ); +})`test`; +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/template-literal/unicode-escape-nls-err.js b/js/src/tests/test262/language/expressions/template-literal/unicode-escape-nls-err.js new file mode 100644 index 0000000000..57f7f3e4de --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/unicode-escape-nls-err.js @@ -0,0 +1,56 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2017 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: prod-Template +description: NumericLiteralSeperator disallowed in unicode CodePoint sequence +info: | + Template :: + NoSubstitutionTemplate + TemplateHead + + NoSubstitutionTemplate :: + `TemplateCharactersopt` + + TemplateCharacters :: + TemplateCharacterTemplateCharactersopt + + TemplateCharacter :: + $[lookahead ≠ {] + \EscapeSequence + \NotEscapeSequence + LineContinuation + LineTerminatorSequence + SourceCharacterbut not one of ` or \ or $ or LineTerminator + + EscapeSequence :: + CharacterEscapeSequence + 0 [lookahead ∉ DecimalDigit] + HexEscapeSequence + UnicodeEscapeSequence + + UnicodeEscapeSequence :: + uHex4Digits + u{CodePoint} + + CodePoint :: + HexDigit but only if MV of HexDigits ≤ 0x10FFFF + CodePointDigits but only if MV of HexDigits ≤ 0x10FFFF + + CodePointDigits :: + HexDigit + CodePointDigitsHexDigit + + HexDigit :: one of + 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F + +features: [numeric-separator-literal] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\u{1F_639}`; diff --git a/js/src/tests/test262/language/expressions/template-literal/unicode-escape-no-hex-err.js b/js/src/tests/test262/language/expressions/template-literal/unicode-escape-no-hex-err.js new file mode 100644 index 0000000000..8f39d220f6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/template-literal/unicode-escape-no-hex-err.js @@ -0,0 +1,51 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: prod-Template +description: > + \u is at the end of string, Hex4Digits is required. +info: | + Template :: + NoSubstitutionTemplate + TemplateHead + + NoSubstitutionTemplate :: + ` TemplateCharacters_opt ` + + TemplateCharacters :: + TemplateCharacter TemplateCharacters_opt + + TemplateCharacter :: + $ [lookahead ≠ {] + \ EscapeSequence + \ NotEscapeSequence + LineContinuation + LineTerminatorSequence + SourceCharacter but not one of ` or \ or $ or LineTerminator + + EscapeSequence :: + CharacterEscapeSequence + 0 [lookahead ∉ DecimalDigit] + HexEscapeSequence + UnicodeEscapeSequence + + UnicodeEscapeSequence :: + u Hex4Digits + u{ CodePoint } + + Hex4Digits :: + HexDigit HexDigit HexDigit HexDigit + + HexDigit :: one of + 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F + +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +`\u` |