mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 802155 - Reflect.parse: Add "of" field to comprehension block. r=jorendorff.
--HG-- extra : rebase_source : 72e925e62c102ffcd094a5e5f92bfd28f16f3a0b
This commit is contained in:
parent
6be3b9ce2a
commit
e52b5b7a9a
@ -584,7 +584,7 @@ class NodeBuilder
|
||||
|
||||
bool yieldExpression(HandleValue arg, TokenPos *pos, MutableHandleValue dst);
|
||||
|
||||
bool comprehensionBlock(HandleValue patt, HandleValue src, bool isForEach, TokenPos *pos,
|
||||
bool comprehensionBlock(HandleValue patt, HandleValue src, bool isForEach, bool isForOf, TokenPos *pos,
|
||||
MutableHandleValue dst);
|
||||
|
||||
bool comprehensionExpression(HandleValue body, NodeVector &blocks, HandleValue filter,
|
||||
@ -1272,19 +1272,21 @@ NodeBuilder::yieldExpression(HandleValue arg, TokenPos *pos, MutableHandleValue
|
||||
}
|
||||
|
||||
bool
|
||||
NodeBuilder::comprehensionBlock(HandleValue patt, HandleValue src, bool isForEach, TokenPos *pos,
|
||||
NodeBuilder::comprehensionBlock(HandleValue patt, HandleValue src, bool isForEach, bool isForOf, TokenPos *pos,
|
||||
MutableHandleValue dst)
|
||||
{
|
||||
RootedValue isForEachVal(cx, BooleanValue(isForEach));
|
||||
RootedValue isForOfVal(cx, BooleanValue(isForOf));
|
||||
|
||||
RootedValue cb(cx, callbacks[AST_COMP_BLOCK]);
|
||||
if (!cb.isNull())
|
||||
return callback(cb, patt, src, isForEachVal, pos, dst);
|
||||
return callback(cb, patt, src, isForEachVal, isForOfVal, pos, dst);
|
||||
|
||||
return newNode(AST_COMP_BLOCK, pos,
|
||||
"left", patt,
|
||||
"right", src,
|
||||
"each", isForEachVal,
|
||||
"of", isForOfVal,
|
||||
dst);
|
||||
}
|
||||
|
||||
@ -2486,11 +2488,12 @@ ASTSerializer::comprehensionBlock(ParseNode *pn, MutableHandleValue dst)
|
||||
LOCAL_ASSERT(in && in->isKind(PNK_FORIN));
|
||||
|
||||
bool isForEach = pn->pn_iflags & JSITER_FOREACH;
|
||||
bool isForOf = pn->pn_iflags & JSITER_FOR_OF;
|
||||
|
||||
RootedValue patt(cx), src(cx);
|
||||
return pattern(in->pn_kid2, NULL, &patt) &&
|
||||
expression(in->pn_kid3, &src) &&
|
||||
builder.comprehensionBlock(patt, src, isForEach, &in->pn_pos, dst);
|
||||
builder.comprehensionBlock(patt, src, isForEach, isForOf, &in->pn_pos, dst);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -94,8 +94,9 @@ function graphExpr(idx, body) Pattern({ type: "GraphExpression", index: idx, exp
|
||||
function letExpr(head, body) Pattern({ type: "LetExpression", head: head, body: body })
|
||||
function idxExpr(idx) Pattern({ type: "GraphIndexExpression", index: idx })
|
||||
|
||||
function compBlock(left, right) Pattern({ type: "ComprehensionBlock", left: left, right: right, each: false })
|
||||
function compEachBlock(left, right) Pattern({ type: "ComprehensionBlock", left: left, right: right, each: true })
|
||||
function compBlock(left, right) Pattern({ type: "ComprehensionBlock", left: left, right: right, each: false, of: false })
|
||||
function compEachBlock(left, right) Pattern({ type: "ComprehensionBlock", left: left, right: right, each: true, of: false })
|
||||
function compOfBlock(left, right) Pattern({ type: "ComprehensionBlock", left: left, right: right, each: false, of: true })
|
||||
|
||||
function arrPatt(elts) Pattern({ type: "ArrayPattern", elements: elts })
|
||||
function objPatt(elts) Pattern({ type: "ObjectPattern", properties: elts })
|
||||
@ -764,6 +765,24 @@ assertExpr("[ [x,y,z] for each (x in foo) for each (y in bar) for each (z in baz
|
||||
[compEachBlock(ident("x"), ident("foo")), compEachBlock(ident("y"), ident("bar")), compEachBlock(ident("z"), ident("baz"))],
|
||||
ident("p")));
|
||||
|
||||
assertExpr("[ x for (x of foo)]",
|
||||
compExpr(ident("x"), [compOfBlock(ident("x"), ident("foo"))], null));
|
||||
assertExpr("[ [x,y] for (x of foo) for (y of bar)]",
|
||||
compExpr(arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], null));
|
||||
assertExpr("[ [x,y,z] for (x of foo) for (y of bar) for (z of baz)]",
|
||||
compExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
|
||||
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
|
||||
null));
|
||||
|
||||
assertExpr("[ x for (x of foo) if (p)]",
|
||||
compExpr(ident("x"), [compOfBlock(ident("x"), ident("foo"))], ident("p")));
|
||||
assertExpr("[ [x,y] for (x of foo) for (y of bar) if (p)]",
|
||||
compExpr(arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], ident("p")));
|
||||
assertExpr("[ [x,y,z] for (x of foo) for (y of bar) for (z of baz) if (p) ]",
|
||||
compExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
|
||||
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
|
||||
ident("p")));
|
||||
|
||||
// generator expressions
|
||||
|
||||
assertExpr("( x for (x in foo))",
|
||||
@ -802,6 +821,24 @@ assertExpr("( [x,y,z] for each (x in foo) for each (y in bar) for each (z in baz
|
||||
[compEachBlock(ident("x"), ident("foo")), compEachBlock(ident("y"), ident("bar")), compEachBlock(ident("z"), ident("baz"))],
|
||||
ident("p")));
|
||||
|
||||
assertExpr("( x for (x of foo))",
|
||||
genExpr(ident("x"), [compOfBlock(ident("x"), ident("foo"))], null));
|
||||
assertExpr("( [x,y] for (x of foo) for (y of bar))",
|
||||
genExpr(arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], null));
|
||||
assertExpr("( [x,y,z] for (x of foo) for (y of bar) for (z of baz))",
|
||||
genExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
|
||||
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
|
||||
null));
|
||||
|
||||
assertExpr("( x for (x of foo) if (p))",
|
||||
genExpr(ident("x"), [compOfBlock(ident("x"), ident("foo"))], ident("p")));
|
||||
assertExpr("( [x,y] for (x of foo) for (y of bar) if (p))",
|
||||
genExpr(arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], ident("p")));
|
||||
assertExpr("( [x,y,z] for (x of foo) for (y of bar) for (z of baz) if (p) )",
|
||||
genExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
|
||||
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
|
||||
ident("p")));
|
||||
|
||||
// NOTE: it would be good to test generator expressions both with and without upvars, just like functions above.
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user