From ab3a86d9b31ad996eddc72d491765abc4c806a54 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Thu, 3 Sep 2020 15:34:01 -0700 Subject: [PATCH] Move tests from https://source.chromium.org/chromium/chromium/src/+/master:v8/test/test262/local-tests/ --- ...terator-close-failure-after-set-failure.js | 27 ++++++++++++++ test/intl402/DateTimeFormat/12.1.1_1.js | 35 +++++++++++++++++++ test/intl402/NumberFormat/11.1.1_1.js | 35 +++++++++++++++++++ ...efault-currency-maximum-fraction-digits.js | 17 +++++++++ ...elds-inner-arrow-err-contains-arguments.js | 26 ++++++++++++++ ...inner-arrow-eval-err-contains-arguments.js | 33 +++++++++++++++++ ...inner-eval-arrow-err-contains-arguments.js | 30 ++++++++++++++++ ...line-html-close-comment-before-function.js | 16 +++++++++ ...l-close-comment-newline-before-function.js | 15 ++++++++ ...elds-inner-arrow-err-contains-arguments.js | 26 ++++++++++++++ ...inner-arrow-eval-err-contains-arguments.js | 34 ++++++++++++++++++ ...inner-eval-arrow-err-contains-arguments.js | 30 ++++++++++++++++ 12 files changed, 324 insertions(+) create mode 100644 test/built-ins/Map/iterator-close-failure-after-set-failure.js create mode 100644 test/intl402/DateTimeFormat/12.1.1_1.js create mode 100644 test/intl402/NumberFormat/11.1.1_1.js create mode 100644 test/intl402/NumberFormat/default-currency-maximum-fraction-digits.js create mode 100644 test/language/expressions/class/fields-inner-arrow-err-contains-arguments.js create mode 100644 test/language/expressions/class/fields-inner-arrow-eval-err-contains-arguments.js create mode 100644 test/language/expressions/class/fields-inner-eval-arrow-err-contains-arguments.js create mode 100644 test/language/module-code/comment-single-line-html-close-comment-before-function.js create mode 100644 test/language/module-code/comment-single-line-html-close-comment-newline-before-function.js create mode 100644 test/language/statements/class/fields-inner-arrow-err-contains-arguments.js create mode 100644 test/language/statements/class/fields-inner-arrow-eval-err-contains-arguments.js create mode 100644 test/language/statements/class/fields-inner-eval-arrow-err-contains-arguments.js diff --git a/test/built-ins/Map/iterator-close-failure-after-set-failure.js b/test/built-ins/Map/iterator-close-failure-after-set-failure.js new file mode 100644 index 0000000000..e695600ddf --- /dev/null +++ b/test/built-ins/Map/iterator-close-failure-after-set-failure.js @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.1.1.1 +description: > + The correct error is thrown `Map.prototype.set` throws an error and + the IteratorClose throws an error. +features: [Symbol.iterator] +---*/ + +var count = 0; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { value: [], done: false }; + }, + return: function() { + throw new TypeError('ignore'); + } + }; +}; +Map.prototype.set = function() { throw new Test262Error(); } + +assert.throws(Test262Error, function() { + new Map(iterable); +}); diff --git a/test/intl402/DateTimeFormat/12.1.1_1.js b/test/intl402/DateTimeFormat/12.1.1_1.js new file mode 100644 index 0000000000..9cabc6e50b --- /dev/null +++ b/test/intl402/DateTimeFormat/12.1.1_1.js @@ -0,0 +1,35 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.1.1_1 +description: Tests that the this-value is ignored in DateTimeFormat. +author: Norbert Lindenberg +includes: [testIntl.js] +---*/ + +testWithIntlConstructors(function (Constructor) { + var obj, newObj; + + if (Constructor === Intl.DateTimeFormat) { + obj = new Constructor(); + newObj = Intl.DateTimeFormat.call(obj); + if (obj !== newObj) { + $ERROR("Should have modified existing object."); + } + var key = Object.getOwnPropertySymbols(newObj)[0]; + if (!(newObj[key] instanceof Intl.DateTimeFormat)) { + $ERROR("Should have installed a DateTimeFormat instance."); + } + return true; + } + + // variant 1: use constructor in a "new" expression + obj = new Constructor(); + newObj = Intl.DateTimeFormat.call(obj); + if (obj === newObj) { + $ERROR("DateTimeFormat object created with \"new\" was not ignored as this-value."); + } + + return true; +}); diff --git a/test/intl402/NumberFormat/11.1.1_1.js b/test/intl402/NumberFormat/11.1.1_1.js new file mode 100644 index 0000000000..b492a41183 --- /dev/null +++ b/test/intl402/NumberFormat/11.1.1_1.js @@ -0,0 +1,35 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 11.1.1_1 +description: Tests that the this-value is ignored in NumberFormat. +author: Norbert Lindenberg +includes: [testIntl.js] +---*/ + +testWithIntlConstructors(function (Constructor) { + var obj, newObj; + + if (Constructor === Intl.NumberFormat) { + obj = new Constructor(); + newObj = Intl.NumberFormat.call(obj); + if (obj !== newObj) { + $ERROR("Should have modified existing object."); + } + var key = Object.getOwnPropertySymbols(newObj)[0]; + if (!(newObj[key] instanceof Intl.NumberFormat)) { + $ERROR("Should have installed a NumberFormat instance."); + } + return true; + } + + // variant 1: use constructor in a "new" expression + obj = new Constructor(); + newObj = Intl.NumberFormat.call(obj); + if (obj === newObj) { + $ERROR("NumberFormat object created with \"new\" was not ignored as this-value."); + } + + return true; +}); diff --git a/test/intl402/NumberFormat/default-currency-maximum-fraction-digits.js b/test/intl402/NumberFormat/default-currency-maximum-fraction-digits.js new file mode 100644 index 0000000000..9ca6ffe2b9 --- /dev/null +++ b/test/intl402/NumberFormat/default-currency-maximum-fraction-digits.js @@ -0,0 +1,17 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: ECMA-402 #sec-setnfdigitoptions +description: > + When a currency is used in Intl.NumberFormat and minimumFractionDigits is + not provided, maximumFractionDigits should be range-checked against it. +include: [assert.js] +---*/ + +assert.throws(RangeError, + () => new Intl.NumberFormat('en', { + style: 'currency', + currency: 'USD', + maximumFractionDigits: 1 + })); diff --git a/test/language/expressions/class/fields-inner-arrow-err-contains-arguments.js b/test/language/expressions/class/fields-inner-arrow-err-contains-arguments.js new file mode 100644 index 0000000000..a260f59de7 --- /dev/null +++ b/test/language/expressions/class/fields-inner-arrow-err-contains-arguments.js @@ -0,0 +1,26 @@ +/*--- +description: Syntax error if `arguments` used in class field (arrow function expression) +esid: sec-class-definitions-static-semantics-early-errors +features: [class, class-fields-public, arrow-function] +flags: [generated] +negative: + phase: early + type: SyntaxError +info: | + Static Semantics: Early Errors + FieldDefinition: + PropertyNameInitializeropt + - It is a Syntax Error if ContainsArguments of Initializer is true. + Static Semantics: ContainsArguments + IdentifierReference : Identifier + 1. If the StringValue of Identifier is "arguments", return true. + ... + For all other grammatical productions, recurse on all nonterminals. If any piece returns true, then return true. Otherwise return false. +---*/ +throw "Test262: This statement should not be evaluated."; +var C = class { + x = () => { + var t = () => { arguments; }; + t(); + } +} diff --git a/test/language/expressions/class/fields-inner-arrow-eval-err-contains-arguments.js b/test/language/expressions/class/fields-inner-arrow-eval-err-contains-arguments.js new file mode 100644 index 0000000000..20e2bac839 --- /dev/null +++ b/test/language/expressions/class/fields-inner-arrow-eval-err-contains-arguments.js @@ -0,0 +1,33 @@ +/*--- +description: error if `arguments` in StatementList of eval (direct eval) +esid: sec-performeval-rules-in-initializer +features: [class, class-fields-public, arrow-function] +flags: [generated] +info: | + Static Semantics: Early Errors + + FieldDefinition: + PropertyNameInitializeropt + + - It is a Syntax Error if ContainsArguments of Initializer is true. + + Static Semantics: ContainsArguments + IdentifierReference : Identifier + + 1. If the StringValue of Identifier is "arguments", return true. + ... + For all other grammatical productions, recurse on all nonterminals. If any piece returns true, then return true. Otherwise return false. + +---*/ + +var C = class { + x = () => { + var t = () => { eval("arguments"); }; + t(); + } +} + +assert.throws(SyntaxError, function() { + var c = new C(); + c.x(); +}); diff --git a/test/language/expressions/class/fields-inner-eval-arrow-err-contains-arguments.js b/test/language/expressions/class/fields-inner-eval-arrow-err-contains-arguments.js new file mode 100644 index 0000000000..28ae79ed94 --- /dev/null +++ b/test/language/expressions/class/fields-inner-eval-arrow-err-contains-arguments.js @@ -0,0 +1,30 @@ +/*--- +description: error if `arguments` in StatementList of eval (direct eval) +esid: sec-performeval-rules-in-initializer +features: [class, class-fields-public, arrow-function] +flags: [generated] +info: | + Static Semantics: Early Errors + + FieldDefinition: + PropertyNameInitializeropt + + - It is a Syntax Error if ContainsArguments of Initializer is true. + + Static Semantics: ContainsArguments + IdentifierReference : Identifier + + 1. If the StringValue of Identifier is "arguments", return true. + ... + For all other grammatical productions, recurse on all nonterminals. If any piece returns true, then return true. Otherwise return false. + +---*/ + +var C = class { + x = eval("() => arguments"); +} + +assert.throws(SyntaxError, function() { + var c = new C(); + c.x(); +}); diff --git a/test/language/module-code/comment-single-line-html-close-comment-before-function.js b/test/language/module-code/comment-single-line-html-close-comment-before-function.js new file mode 100644 index 0000000000..92d7507cff --- /dev/null +++ b/test/language/module-code/comment-single-line-html-close-comment-before-function.js @@ -0,0 +1,16 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + HTML-like comments are not available in module code + (SingleLineHTMLCloseComment) +esid: sec-html-like-comments +es6id: B1.3 +negative: + phase: early + type: SyntaxError +flags: [module] +---*/ + +--> +function f(){} diff --git a/test/language/module-code/comment-single-line-html-close-comment-newline-before-function.js b/test/language/module-code/comment-single-line-html-close-comment-newline-before-function.js new file mode 100644 index 0000000000..19b0c99250 --- /dev/null +++ b/test/language/module-code/comment-single-line-html-close-comment-newline-before-function.js @@ -0,0 +1,15 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + HTML-like comments are not available in module code + (SingleLineHTMLCloseComment) +esid: sec-html-like-comments +es6id: B1.3 +negative: + phase: early + type: SyntaxError +flags: [module] +---*/ +--> +function f(){} diff --git a/test/language/statements/class/fields-inner-arrow-err-contains-arguments.js b/test/language/statements/class/fields-inner-arrow-err-contains-arguments.js new file mode 100644 index 0000000000..2ce086c612 --- /dev/null +++ b/test/language/statements/class/fields-inner-arrow-err-contains-arguments.js @@ -0,0 +1,26 @@ +/*--- +description: Syntax error if `arguments` used in class field (arrow function expression) +esid: sec-class-definitions-static-semantics-early-errors +features: [class, class-fields-public, arrow-function] +flags: [generated] +negative: + phase: early + type: SyntaxError +info: | + Static Semantics: Early Errors + FieldDefinition: + PropertyNameInitializeropt + - It is a Syntax Error if ContainsArguments of Initializer is true. + Static Semantics: ContainsArguments + IdentifierReference : Identifier + 1. If the StringValue of Identifier is "arguments", return true. + ... + For all other grammatical productions, recurse on all nonterminals. If any piece returns true, then return true. Otherwise return false. +---*/ +throw "Test262: This statement should not be evaluated."; +class C { + x = () => { + var t = () => { arguments; }; + t(); + } +} diff --git a/test/language/statements/class/fields-inner-arrow-eval-err-contains-arguments.js b/test/language/statements/class/fields-inner-arrow-eval-err-contains-arguments.js new file mode 100644 index 0000000000..9b29503256 --- /dev/null +++ b/test/language/statements/class/fields-inner-arrow-eval-err-contains-arguments.js @@ -0,0 +1,34 @@ +/*--- +description: error if `arguments` in StatementList of eval (direct eval) +esid: sec-performeval-rules-in-initializer +features: [class, class-fields-public, arrow-function] +flags: [generated] +info: | + Static Semantics: Early Errors + + FieldDefinition: + PropertyNameInitializeropt + + - It is a Syntax Error if ContainsArguments of Initializer is true. + + Static Semantics: ContainsArguments + IdentifierReference : Identifier + + 1. If the StringValue of Identifier is "arguments", return true. + ... + For all other grammatical productions, recurse on all nonterminals. If any piece returns true, then return true. Otherwise return false. + +---*/ + + +class C { + x = () => { + var t = () => { eval("arguments"); }; + t(); + } +} + +assert.throws(SyntaxError, function() { + var c = new C(); + c.x(); +}); diff --git a/test/language/statements/class/fields-inner-eval-arrow-err-contains-arguments.js b/test/language/statements/class/fields-inner-eval-arrow-err-contains-arguments.js new file mode 100644 index 0000000000..f2680e4b67 --- /dev/null +++ b/test/language/statements/class/fields-inner-eval-arrow-err-contains-arguments.js @@ -0,0 +1,30 @@ +/*--- +description: error if `arguments` in StatementList of eval (direct eval) +esid: sec-performeval-rules-in-initializer +features: [class, class-fields-public, arrow-function] +flags: [generated] +info: | + Static Semantics: Early Errors + + FieldDefinition: + PropertyNameInitializeropt + + - It is a Syntax Error if ContainsArguments of Initializer is true. + + Static Semantics: ContainsArguments + IdentifierReference : Identifier + + 1. If the StringValue of Identifier is "arguments", return true. + ... + For all other grammatical productions, recurse on all nonterminals. If any piece returns true, then return true. Otherwise return false. + +---*/ + +class C { + x = eval("() => arguments"); +} + +assert.throws(SyntaxError, function() { + var c = new C(); + c.x(); +});