From cfd7e1f61dad23f6ee9960389510066a1a61190e Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Tue, 29 Mar 2016 11:48:19 -0400 Subject: [PATCH] Module code: early errors Assert that relevant early errors are reported following the parsing of module code. --- .../module-code/early-dup-export-dflt-id.js | 15 +++++++++ .../module-code/early-export-global.js | 15 +++++++++ .../module-code/early-import-arguments.js | 31 +++++++++++++++++++ .../module-code/early-import-as-arguments.js | 31 +++++++++++++++++++ .../module-code/early-import-as-eval.js | 31 +++++++++++++++++++ .../language/module-code/early-import-eval.js | 31 +++++++++++++++++++ 6 files changed, 154 insertions(+) create mode 100644 test/language/module-code/early-dup-export-dflt-id.js create mode 100644 test/language/module-code/early-export-global.js create mode 100644 test/language/module-code/early-import-arguments.js create mode 100644 test/language/module-code/early-import-as-arguments.js create mode 100644 test/language/module-code/early-import-as-eval.js create mode 100644 test/language/module-code/early-import-eval.js diff --git a/test/language/module-code/early-dup-export-dflt-id.js b/test/language/module-code/early-dup-export-dflt-id.js new file mode 100644 index 0000000000..a82ae96fe3 --- /dev/null +++ b/test/language/module-code/early-dup-export-dflt-id.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +es6id: 15.2.1.1 +description: > + It is a Syntax Error if the ExportedNames of ModuleItemList contains any + duplicate entries. +flags: [module] +negative: SyntaxError +---*/ + +var x, y; +export default x; +export { y as default }; diff --git a/test/language/module-code/early-export-global.js b/test/language/module-code/early-export-global.js new file mode 100644 index 0000000000..2e02038bb2 --- /dev/null +++ b/test/language/module-code/early-export-global.js @@ -0,0 +1,15 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-module-semantics-static-semantics-early-errors +es6id: 15.2.1.1 +description: Exporting a global binding +info: > + It is a Syntax Error if any element of the ExportedBindings of + ModuleItemList does not also occur in either the VarDeclaredNames of + ModuleItemList, or the LexicallyDeclaredNames of ModuleItemList. +flags: [module] +negative: SyntaxError +---*/ + +export { Number }; diff --git a/test/language/module-code/early-import-arguments.js b/test/language/module-code/early-import-arguments.js new file mode 100644 index 0000000000..0885a7ee66 --- /dev/null +++ b/test/language/module-code/early-import-arguments.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ImportedBinding is a BindingIdentifier and cannot be "arguments" +esid: sec-imports +info: | + ImportSpecifier : + ImportedBinding + IdentifierName as ImportedBinding + + ImportedBinding : + BindingIdentifier + + 12.1.1 Static Semantics : Early Errors + + BindingIdentifier : Identifier + + - It is a Syntax Error if the code matched by this production is contained + in strict mode code and the StringValue of Identifier is "arguments" or + "eval". +negative: SyntaxError +flags: [module] +---*/ + +// Create an appropriately-named ExportEntry in order to avoid false positives +// (e.g. cases where the implementation does not generate the expected early +// error but does produce a SyntaxError for unresolvable bindings). +var x; +export { x as arguments }; + +import { arguments } from './early-import-arguments.js'; diff --git a/test/language/module-code/early-import-as-arguments.js b/test/language/module-code/early-import-as-arguments.js new file mode 100644 index 0000000000..f5250a38ca --- /dev/null +++ b/test/language/module-code/early-import-as-arguments.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ImportedBinding is a BindingIdentifier and cannot be "arguments" +esid: sec-imports +info: | + ImportSpecifier : + ImportedBinding + IdentifierName as ImportedBinding + + ImportedBinding : + BindingIdentifier + + 12.1.1 Static Semantics : Early Errors + + BindingIdentifier : Identifier + + - It is a Syntax Error if the code matched by this production is contained + in strict mode code and the StringValue of Identifier is "arguments" or + "eval". +negative: SyntaxError +flags: [module] +---*/ + +// Create an appropriately-named ExportEntry in order to avoid false positives +// (e.g. cases where the implementation does not generate the expected early +// error but does produce a SyntaxError for unresolvable bindings). +var x; +export { x }; + +import { x as arguments } from './early-import-as-arguments.js'; diff --git a/test/language/module-code/early-import-as-eval.js b/test/language/module-code/early-import-as-eval.js new file mode 100644 index 0000000000..2b732cebec --- /dev/null +++ b/test/language/module-code/early-import-as-eval.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ImportedBinding is a BindingIdentifier and cannot be "eval" +esid: sec-imports +info: | + ImportSpecifier : + ImportedBinding + IdentifierName as ImportedBinding + + ImportedBinding : + BindingIdentifier + + 12.1.1 Static Semantics : Early Errors + + BindingIdentifier : Identifier + + - It is a Syntax Error if the code matched by this production is contained + in strict mode code and the StringValue of Identifier is "arguments" or + "eval". +negative: SyntaxError +flags: [module] +---*/ + +// Create an appropriately-named ExportEntry in order to avoid false positives +// (e.g. cases where the implementation does not generate the expected early +// error but does produce a SyntaxError for unresolvable bindings). +var x; +export { x }; + +import { x as eval } from './early-import-as-eval.js'; diff --git a/test/language/module-code/early-import-eval.js b/test/language/module-code/early-import-eval.js new file mode 100644 index 0000000000..c8ba3d20f7 --- /dev/null +++ b/test/language/module-code/early-import-eval.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ImportedBinding is a BindingIdentifier and cannot be "eval" +esid: sec-imports +info: | + ImportSpecifier : + ImportedBinding + IdentifierName as ImportedBinding + + ImportedBinding : + BindingIdentifier + + 12.1.1 Static Semantics : Early Errors + + BindingIdentifier : Identifier + + - It is a Syntax Error if the code matched by this production is contained + in strict mode code and the StringValue of Identifier is "arguments" or + "eval". +negative: SyntaxError +flags: [module] +---*/ + +// Create an appropriately-named ExportEntry in order to avoid false positives +// (e.g. cases where the implementation does not generate the expected early +// error but does produce a SyntaxError for unresolvable bindings). +var x; +export { x as eval }; + +import { eval } from './early-import-eval.js';