diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 664b926d0..335319c01 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -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. diff --git a/js/src/tests/ecma_7/AsyncFunctions/104_basic.js b/js/src/tests/ecma_7/AsyncFunctions/104_basic.js index 9a06599b0..97733ee7f 100644 --- a/js/src/tests/ecma_7/AsyncFunctions/104_basic.js +++ b/js/src/tests/ecma_7/AsyncFunctions/104_basic.js @@ -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);