mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 632030 - Reflect.parse handling of duplicate var declarations (r=jorendorff)
This commit is contained in:
parent
197cb3d127
commit
da7f1d70a8
@ -128,10 +128,14 @@ JS_BEGIN_EXTERN_C
|
||||
* TOK_CONTINUE name pn_atom: label or null
|
||||
* TOK_WITH binary pn_left: head expr, pn_right: body
|
||||
* TOK_VAR list pn_head: list of TOK_NAME or TOK_ASSIGN nodes
|
||||
* each name node has
|
||||
* each name node has either
|
||||
* pn_used: false
|
||||
* pn_atom: variable name
|
||||
* pn_expr: initializer or null
|
||||
* or
|
||||
* pn_used: true
|
||||
* pn_atom: variable name
|
||||
* pn_lexdef: def node
|
||||
* each assignment node has
|
||||
* pn_left: TOK_NAME with pn_used true and
|
||||
* pn_lexdef (NOT pn_expr) set
|
||||
|
@ -1970,7 +1970,7 @@ ASTSerializer::variableDeclarator(JSParseNode *pn, VarDeclKind *pkind, Value *ds
|
||||
|
||||
if (PN_TYPE(pn) == TOK_NAME) {
|
||||
pnleft = pn;
|
||||
pnright = pn->pn_expr;
|
||||
pnright = pn->pn_used ? NULL : pn->pn_expr;
|
||||
} else {
|
||||
JS_ASSERT(PN_TYPE(pn) == TOK_ASSIGN);
|
||||
pnleft = pn->pn_left;
|
||||
|
@ -60,6 +60,7 @@ const JSMSG_GENEXP_ARGUMENTS = error("(function(){(arguments for (x in []))})").
|
||||
const JSMSG_TOP_YIELD = error("yield").message;
|
||||
const JSMSG_YIELD_PAREN = error("(function(){yield, 1})").message;
|
||||
const JSMSG_GENERIC = error("(for)").message;
|
||||
const JSMSG_GENEXP_PAREN = error("print(1, x for (x in []))").message;
|
||||
|
||||
const cases = [
|
||||
// yield expressions
|
||||
@ -93,7 +94,8 @@ const cases = [
|
||||
{ expr: "(yield, 1 for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list in genexp" },
|
||||
{ expr: "(yield 1, 2 for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list in genexp" },
|
||||
{ expr: "(1, yield for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENERIC, gen: JSMSG_GENERIC, desc: "simple yield at end of list in genexp" },
|
||||
{ expr: "(1, yield 2 for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list in genexp" },
|
||||
{ expr: "(1, yield 2 for (x in []))", top: JSMSG_TOP_YIELD, fun: { simple: JSMSG_GENEXP_YIELD, call: JSMSG_GENEXP_PAREN },
|
||||
gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list in genexp" },
|
||||
{ expr: "((yield) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "simple yield, parenthesized in genexp" },
|
||||
{ expr: "((yield 1) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg, parenthesized in genexp" },
|
||||
{ expr: "(1, (yield) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "simple yield, parenthesized in list in genexp" },
|
||||
@ -147,10 +149,13 @@ function expectError1(err, ctx, msg) {
|
||||
reportCompare(2, err.lineNumber, 'exn token for: ' + msg);
|
||||
}
|
||||
|
||||
function expectError(expr, call, wrapCtx, ctx, msg) {
|
||||
expectError1(error(wrapCtx(expr)), ctx, msg);
|
||||
function expectError(expr, call, wrapCtx, expect, msg) {
|
||||
let exps = (typeof expect === "string")
|
||||
? { simple: expect, call: expect }
|
||||
: expect;
|
||||
expectError1(error(wrapCtx(expr)), exps.simple, msg);
|
||||
if (call)
|
||||
expectError1(error(wrapCtx(call)), ctx, 'call argument in ' + msg);
|
||||
expectError1(error(wrapCtx(call)), exps.call, 'call argument in ' + msg);
|
||||
}
|
||||
|
||||
function expectSuccess(err, msg) {
|
||||
|
@ -154,6 +154,10 @@ function assertGlobalDecl(src, patt) {
|
||||
program([patt]).assert(Reflect.parse(src));
|
||||
}
|
||||
|
||||
function assertProg(src, patt) {
|
||||
program(patt).assert(Reflect.parse(src));
|
||||
}
|
||||
|
||||
function assertStmt(src, patt) {
|
||||
assertLocalStmt(src, patt);
|
||||
assertGlobalStmt(src, patt);
|
||||
@ -444,6 +448,15 @@ assertStmt("function f() { var x = 42; var x = 43; }",
|
||||
assertDecl("var {x:y} = foo;", varDecl([{ id: objPatt([{ key: ident("x"), value: ident("y") }]),
|
||||
init: ident("foo") }]));
|
||||
|
||||
// Bug 632030: redeclarations between var and funargs, var and function
|
||||
assertStmt("function g(x) { var x }",
|
||||
funDecl(ident("g"), [ident("x")], blockStmt([varDecl[{ id: ident("x"), init: null }]])));
|
||||
assertProg("f.p = 1; var f; f.p; function f(){}",
|
||||
[exprStmt(aExpr("=", dotExpr(ident("f"), ident("p")), lit(1))),
|
||||
varDecl([{ id: ident("f"), init: null }]),
|
||||
exprStmt(dotExpr(ident("f"), ident("p"))),
|
||||
funDecl(ident("f"), [], blockStmt([]))]);
|
||||
|
||||
// global let is var
|
||||
assertGlobalDecl("let {x:y} = foo;", varDecl([{ id: objPatt([{ key: ident("x"), value: ident("y") }]),
|
||||
init: ident("foo") }]));
|
||||
|
Loading…
Reference in New Issue
Block a user