forked from BrowserWorks/Waterfox-Classic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1484948 - Parse dynamic module import syntax but throw SyntaxErro…
…r if used r=jorendorff
- Loading branch information
Showing
12 changed files
with
187 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
js/src/jit-test/tests/modules/dynamic-import-expression.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
load(libdir + "match.js"); | ||
load(libdir + "asserts.js"); | ||
|
||
var { Pattern, MatchError } = Match; | ||
|
||
program = (elts) => Pattern({ | ||
type: "Program", | ||
body: elts | ||
}); | ||
expressionStatement = (expression) => Pattern({ | ||
type: "ExpressionStatement", | ||
expression: expression | ||
}); | ||
assignmentExpression = (left, operator, right) => Pattern({ | ||
type: "AssignmentExpression", | ||
operator: operator, | ||
left: left, | ||
right: right | ||
}); | ||
ident = (name) => Pattern({ | ||
type: "Identifier", | ||
name: name | ||
}); | ||
importCall = (ident, singleArg) => Pattern({ | ||
type: "CallImport", | ||
ident: ident, | ||
arg: singleArg | ||
}); | ||
|
||
function parseAsClassicScript(source) | ||
{ | ||
return Reflect.parse(source); | ||
} | ||
|
||
function parseAsModuleScript(source) | ||
{ | ||
return Reflect.parse(source, {target: "module"}); | ||
} | ||
|
||
for (let parse of [parseAsModuleScript, parseAsClassicScript]) { | ||
program([ | ||
expressionStatement( | ||
importCall( | ||
ident("import"), | ||
ident("foo") | ||
) | ||
) | ||
]).assert(parse("import(foo);")); | ||
|
||
program([ | ||
expressionStatement( | ||
assignmentExpression( | ||
ident("x"), | ||
"=", | ||
importCall( | ||
ident("import"), | ||
ident("foo") | ||
) | ||
) | ||
) | ||
]).assert(parse("x = import(foo);")); | ||
} | ||
|
||
function assertParseThrowsSyntaxError(source) | ||
{ | ||
assertThrowsInstanceOf(() => parseAsClassicScript(source), SyntaxError); | ||
assertThrowsInstanceOf(() => parseAsModuleScript(source), SyntaxError); | ||
} | ||
|
||
assertParseThrowsSyntaxError("import"); | ||
assertParseThrowsSyntaxError("import("); | ||
assertParseThrowsSyntaxError("import(1,"); | ||
assertParseThrowsSyntaxError("import(1, 2"); | ||
assertParseThrowsSyntaxError("import(1, 2)"); | ||
assertParseThrowsSyntaxError("x = import"); | ||
assertParseThrowsSyntaxError("x = import("); | ||
assertParseThrowsSyntaxError("x = import(1,"); | ||
assertParseThrowsSyntaxError("x = import(1, 2"); | ||
assertParseThrowsSyntaxError("x = import(1, 2)"); | ||
|
||
// import() is not implemented. | ||
assertThrowsInstanceOf(() => eval("import('foo')"), | ||
SyntaxError); | ||
assertThrowsInstanceOf(() => parseModule("import('foo')"), | ||
SyntaxError); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters