#521: make async functions throw for compatibility when enabled

This commit is contained in:
Cameron Kaiser 2019-08-19 16:45:53 -07:00
parent 2d25f717b9
commit 46b01b5d42
2 changed files with 18 additions and 2 deletions

View File

@ -3598,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;
@ -3648,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.

View File

@ -27,11 +27,12 @@ function okok(x, y, z) { return (typeof y === "function"); }
assertEq(okok(5, async function(w) { await w+w; }, "ok"), true);
assertEq(okok(6, (async(w)=>{await w+w}), "ok"), true);
assertEq(okok(7, ()=>{!async function(){ }}, "ok"), true);
assertEq(okok(8, async event => { }, "ok"), true);
function yoyo(k) { return new Promise(resolve => { resolve(k+1); }); }
async function dodo(k) { return await yoyo(k+1); }
// Just make sure this executes. It currently returns ({ }) in the shell.
dodo(5);
// Just make sure this executes. Right now this throws.
try { dodo(5); } catch(e) { }
if (typeof reportCompare === "function")
reportCompare(true, true);