diff --git a/js/src/jit-test/tests/arrow-functions/bug-885219.js b/js/src/jit-test/tests/arrow-functions/bug-885219.js new file mode 100644 index 000000000000..70544bde8d27 --- /dev/null +++ b/js/src/jit-test/tests/arrow-functions/bug-885219.js @@ -0,0 +1,2 @@ +if (typeof disassemble === "function") + disassemble("-r", Function("()=>e,d")); diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 545fd67108ee..d53ed6adc593 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -628,12 +628,19 @@ js::FunctionToString(JSContext *cx, HandleFunction fun, bool bodyOnly, bool lamb StableCharPtr chars = src->chars(); bool exprBody = fun->isExprClosure(); - // The source data for functions created by calling the Function - // constructor is only the function's body. - bool funCon = script->sourceStart == 0 && script->scriptSource()->argumentsNotIncluded(); - // Functions created with the constructor should not be using the - // expression body extension. + // The source data for functions created by calling the Function + // constructor is only the function's body. This depends on the fact, + // asserted below, that in Function("function f() {}"), the inner + // function's sourceStart points to the '(', not the 'f'. + bool funCon = !fun->isArrow() && + script->sourceStart == 0 && + script->sourceEnd == script->scriptSource()->length() && + script->scriptSource()->argumentsNotIncluded(); + + // Functions created with the constructor can't be arrow functions or + // expression closures. + JS_ASSERT_IF(funCon, !fun->isArrow()); JS_ASSERT_IF(funCon, !exprBody); JS_ASSERT_IF(!funCon && !fun->isArrow(), src->length() > 0 && chars[0] == '(');