diff options
Diffstat (limited to 'js/src/jsfun.cpp')
-rw-r--r-- | js/src/jsfun.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index b4aeee51c2..fc243fab66 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -942,24 +942,24 @@ const Class JSFunction::class_ = { const Class* const js::FunctionClassPtr = &JSFunction::class_; JSString* -js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) +js::FunctionToString(JSContext* cx, HandleFunction fun, bool isToSource) { if (fun->isInterpretedLazy() && !JSFunction::getOrCreateScript(cx, fun)) return nullptr; if (IsAsmJSModule(fun)) - return AsmJSModuleToString(cx, fun, !prettyPrint); + return AsmJSModuleToString(cx, fun, isToSource); if (IsAsmJSFunction(fun)) return AsmJSFunctionToString(cx, fun); if (IsWrappedAsyncFunction(fun)) { RootedFunction unwrapped(cx, GetUnwrappedAsyncFunction(fun)); - return FunctionToString(cx, unwrapped, prettyPrint); + return FunctionToString(cx, unwrapped, isToSource); } if (IsWrappedAsyncGenerator(fun)) { RootedFunction unwrapped(cx, GetUnwrappedAsyncGenerator(fun)); - return FunctionToString(cx, unwrapped, prettyPrint); + return FunctionToString(cx, unwrapped, isToSource); } StringBuffer out(cx); @@ -985,9 +985,9 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) bool haveSource = fun->isInterpreted() && (fun->isClassConstructor() || !fun->isSelfHostedBuiltin()); - // If we're not in pretty mode, put parentheses around lambda functions - // so that eval returns lambda, not function statement. - bool addParentheses = haveSource && !prettyPrint && (fun->isLambda() && !fun->isArrow()); + // If we're in toSource mode, put parentheses around lambda functions so + // that eval returns lambda, not function statement. + bool addParentheses = haveSource && isToSource && (fun->isLambda() && !fun->isArrow()); if (haveSource && !script->scriptSource()->hasSourceData() && !JSScript::loadSource(cx, script->scriptSource(), &haveSource)) @@ -1066,11 +1066,11 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) } JSString* -fun_toStringHelper(JSContext* cx, HandleObject obj, unsigned indent) +fun_toStringHelper(JSContext* cx, HandleObject obj, bool isToSource) { if (!obj->is<JSFunction>()) { if (JSFunToStringOp op = obj->getOpsFunToString()) - return op(cx, obj, indent); + return op(cx, obj, isToSource); JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, @@ -1079,7 +1079,7 @@ fun_toStringHelper(JSContext* cx, HandleObject obj, unsigned indent) } RootedFunction fun(cx, &obj->as<JSFunction>()); - return FunctionToString(cx, fun, indent != JS_DONT_PRETTY_PRINT); + return FunctionToString(cx, fun, isToSource); } bool @@ -1102,16 +1102,11 @@ js::fun_toString(JSContext* cx, unsigned argc, Value* vp) CallArgs args = CallArgsFromVp(argc, vp); MOZ_ASSERT(IsFunctionObject(args.calleev())); - uint32_t indent = 0; - - if (args.length() != 0 && !ToUint32(cx, args[0], &indent)) - return false; - RootedObject obj(cx, ToObject(cx, args.thisv())); if (!obj) return false; - RootedString str(cx, fun_toStringHelper(cx, obj, indent)); + JSString* str = fun_toStringHelper(cx, obj, /* isToSource = */ false); if (!str) return false; @@ -1132,12 +1127,12 @@ fun_toSource(JSContext* cx, unsigned argc, Value* vp) RootedString str(cx); if (obj->isCallable()) - str = fun_toStringHelper(cx, obj, JS_DONT_PRETTY_PRINT); + str = fun_toStringHelper(cx, obj, /* isToSource = */ true); else str = ObjectToSource(cx, obj); - if (!str) return false; + args.rval().setString(str); return true; } |