Skip to content

Commit

Permalink
import changes from tenfourfox for replacing patch from classilla/ten…
Browse files Browse the repository at this point in the history
…fourfox#521 (comment):

- #521: baseline parser support for async/await, with toggle, without bytecode (passes tests) (0e5746aaf)
- #521: fix yield handling (includes M1305566 pts 4-7) (2d25f717b)
- #521: make async functions throw for compatibility when enabled (46b01b5d4)
  • Loading branch information
roytam1 committed Aug 26, 2019
1 parent bf4cbb4 commit 9819e33
Show file tree
Hide file tree
Showing 50 changed files with 916 additions and 1,010 deletions.
1 change: 1 addition & 0 deletions js/src/builtin/AsyncFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ function AsyncFunction_resume(gen, v, method) {
return AsyncFunction_resume(gen, err, gen.throw);
});
}

1 change: 1 addition & 0 deletions js/src/builtin/Promise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,4 @@ const Class ShellPromiseObject::protoClass_ = {
ClassSpec::IsDelegated
}
};

7 changes: 3 additions & 4 deletions js/src/builtin/ReflectParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,9 +1604,7 @@ bool
NodeBuilder::function(ASTType type, TokenPos* pos,
HandleValue id, NodeVector& args, NodeVector& defaults,
HandleValue body, HandleValue rest,
GeneratorStyle generatorStyle,
bool isAsync,
bool isExpression,
GeneratorStyle generatorStyle, bool isAsync, bool isExpression,
MutableHandleValue dst)
{
RootedValue array(cx), defarray(cx);
Expand Down Expand Up @@ -2973,7 +2971,7 @@ ASTSerializer::expression(ParseNode* pn, MutableHandleValue dst)
return leftAssociate(pn, dst);

case PNK_POW:
return rightAssociate(pn, dst);
return rightAssociate(pn, dst);

case PNK_DELETENAME:
case PNK_DELETEPROP:
Expand Down Expand Up @@ -3475,6 +3473,7 @@ ASTSerializer::function(ParseNode* pn, ASTType type, MutableHandleValue dst)
? GeneratorStyle::Legacy
: GeneratorStyle::ES6)
: GeneratorStyle::None;

bool isAsync = pn->pn_funbox->isAsync();
bool isExpression =
#if JS_HAS_EXPR_CLOSURES
Expand Down
62 changes: 21 additions & 41 deletions js/src/frontend/BytecodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ bool
BytecodeEmitter::emit1(JSOp op)
{
MOZ_ASSERT(checkStrictOrSloppy(op));

ptrdiff_t offset;
if (!emitCheck(1, &offset))
return false;
Expand Down Expand Up @@ -3597,6 +3598,20 @@ BytecodeEmitter::emitFunctionScript(ParseNode* body)
switchToMain();
}

if (funbox->isAsync()) {
// Currently short-circuit async functions with a throw.
// TenFourFox issue 521.
if (!emit1(JSOP_NULL))
return false;
if (!emit1(JSOP_THROW))
return false;
if (!emit1(JSOP_NULL))
return false;
if (!emit1(JSOP_RETURN))
return false;
goto asyncout;
}

if (!emitTree(body))
return false;

Expand Down Expand Up @@ -3647,6 +3662,7 @@ BytecodeEmitter::emitFunctionScript(ParseNode* body)
if (!emit1(JSOP_CHECKRETURN))
return false;
}
asyncout:

// Always end the script with a JSOP_RETRVAL. Some other parts of the codebase
// depend on this opcode, e.g. InterpreterRegs::setToEndOfScript.
Expand Down Expand Up @@ -6408,9 +6424,6 @@ BytecodeEmitter::emitFunction(ParseNode* pn, bool needsProto)
pn->setOp(JSOP_FUNWITHPROTO);
}

if (funbox->isAsync())
return emitAsyncWrapper(index, funbox->needsHomeObject());

if (pn->getOp() == JSOP_DEFFUN) {
if (!emitIndex32(JSOP_LAMBDA, index))
return false;
Expand Down Expand Up @@ -6457,13 +6470,8 @@ BytecodeEmitter::emitFunction(ParseNode* pn, bool needsProto)
MOZ_ASSERT(pn->pn_scopecoord.isFree());
MOZ_ASSERT(pn->getOp() == JSOP_NOP);
switchToPrologue();
if (funbox->isAsync()) {
if (!emitAsyncWrapper(index, fun->isMethod()))
return false;
} else {
if (!emitIndex32(JSOP_LAMBDA, index))
return false;
}
if (!emitIndex32(JSOP_LAMBDA, index))
return false;
if (!emit1(JSOP_DEFFUN))
return false;
if (!updateSourceCoordNotes(pn->pn_pos.begin))
Expand All @@ -6478,11 +6486,7 @@ BytecodeEmitter::emitFunction(ParseNode* pn, bool needsProto)
bi->kind() == Binding::ARGUMENT);
MOZ_ASSERT(bi.argOrLocalIndex() < JS_BIT(20));
#endif
if (funbox->isAsync()) {
if (!emitAsyncWrapper(index, false))
return false;
}
else if (!emitIndexOp(JSOP_LAMBDA, index))
if (!emitIndexOp(JSOP_LAMBDA, index))
return false;
MOZ_ASSERT(pn->getOp() == JSOP_GETLOCAL || pn->getOp() == JSOP_GETARG);
JSOp setOp = pn->getOp() == JSOP_GETLOCAL ? JSOP_SETLOCAL : JSOP_SETARG;
Expand All @@ -6502,26 +6506,7 @@ BytecodeEmitter::emitFunction(ParseNode* pn, bool needsProto)

bool
BytecodeEmitter::emitAsyncWrapper(unsigned index, bool needsHomeObject) {
JSAtom* atom = Atomize(cx, "AsyncFunction_wrap", 18);
if (!atom)
return false;
/* TODO Comment */
if (needsHomeObject && !emitIndex32(JSOP_LAMBDA, index))
return false;
if (!emitAtomOp(atom, JSOP_GETINTRINSIC))
return false;
if (!emit1(JSOP_UNDEFINED))
return false;
if (needsHomeObject) {
if (!emitDupAt(2))
return false;
} else {
if (!emitIndex32(JSOP_LAMBDA, index))
return false;
}
if (!emitCall(JSOP_CALL, 1))
return false;
return true;
MOZ_CRASH("NYI");
}

bool
Expand Down Expand Up @@ -7818,12 +7803,7 @@ BytecodeEmitter::emitPropertyList(ParseNode* pn, MutableHandlePlainObject objp,
propdef->pn_right->pn_funbox->needsHomeObject())
{
MOZ_ASSERT(propdef->pn_right->pn_funbox->function()->allowSuperProperty());
bool isAsync = propdef->pn_right->pn_funbox->isAsync();
if (isAsync && !emit1(JSOP_SWAP))
return false;
if (!emit2(JSOP_INITHOMEOBJECT, isIndex + isAsync))
return false;
if (isAsync && !emit1(JSOP_POP))
if (!emit2(JSOP_INITHOMEOBJECT, isIndex))
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions js/src/frontend/FullParseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,16 @@ class FullParseHandler
return new_<BinaryNode>(PNK_YIELD, op, pos, value, gen);
}

ParseNode* newAwaitExpression(uint32_t begin, ParseNode* value, ParseNode* gen) {
TokenPos pos(begin, value ? value->pn_pos.end : begin + 1);
return new_<BinaryNode>(PNK_AWAIT, JSOP_YIELD, pos, value, gen);
}

ParseNode* newYieldStarExpression(uint32_t begin, ParseNode* value, ParseNode* gen) {
TokenPos pos(begin, value->pn_pos.end);
return new_<BinaryNode>(PNK_YIELD_STAR, JSOP_NOP, pos, value, gen);
}

ParseNode* newAwaitExpression(uint32_t begin, ParseNode* value, ParseNode* gen) {
TokenPos pos(begin, value ? value->pn_pos.end : begin + 1);
return new_<BinaryNode>(PNK_AWAIT, JSOP_YIELD, pos, value, gen);
}

// Statements

ParseNode* newStatementList(unsigned blockid, const TokenPos& pos) {
Expand Down
3 changes: 2 additions & 1 deletion js/src/frontend/ParseNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ IsTypeofKind(ParseNodeKind kind)
* PNK_NEG
* PNK_VOID, unary pn_kid: UNARY expr
* PNK_NOT,
* PNK_BITNOT
* PNK_BITNOT,
* PNK_AWAIT
* PNK_TYPEOFNAME, unary pn_kid: UNARY expr
* PNK_TYPEOFEXPR
* PNK_PREINCREMENT, unary pn_kid: MEMBER expr
Expand Down
Loading

0 comments on commit 9819e33

Please sign in to comment.