From 4a891fa5c51628c1a830be0068f8cb580c16ff2b Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sat, 6 Jul 2019 21:26:45 +0000 Subject: [PATCH] Bug 1470558: Use Completion in Debugger.Object 'call' and 'apply' methods. r=jorendorff Differential Revision: https://phabricator.services.mozilla.com/D33078 --HG-- extra : moz-landing-system : lando --- js/src/vm/Debugger.cpp | 45 ++++++++++++++++++++++++++++-------------- js/src/vm/Debugger.h | 6 +++--- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index b89fcbd34474..711ac4974641 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -11502,7 +11502,13 @@ bool DebuggerObject::callMethod(JSContext* cx, unsigned argc, Value* vp) { } } - return object->call(cx, object, thisv, args, callArgs.rval()); + Rooted> completion( + cx, DebuggerObject::call(cx, object, thisv, args)); + if (!completion.get()) { + return false; + } + + return completion->buildCompletionValue(cx, object->owner(), callArgs.rval()); } /* static */ @@ -11573,7 +11579,13 @@ bool DebuggerObject::applyMethod(JSContext* cx, unsigned argc, Value* vp) { } } - return object->call(cx, object, thisv, args, callArgs.rval()); + Rooted> completion( + cx, DebuggerObject::call(cx, object, thisv, args)); + if (!completion.get()) { + return false; + } + + return completion->buildCompletionValue(cx, object->owner(), callArgs.rval()); } static void EnterDebuggeeObjectRealm(JSContext* cx, Maybe& ar, @@ -12562,9 +12574,10 @@ Result DebuggerObject::setProperty(JSContext* cx, } /* static */ -bool DebuggerObject::call(JSContext* cx, HandleDebuggerObject object, - HandleValue thisv_, Handle args, - MutableHandleValue result) { +Maybe DebuggerObject::call(JSContext* cx, + HandleDebuggerObject object, + HandleValue thisv_, + Handle args) { RootedObject referent(cx, object->referent()); Debugger* dbg = object->owner(); @@ -12572,7 +12585,7 @@ bool DebuggerObject::call(JSContext* cx, HandleDebuggerObject object, JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, "Debugger.Object", "call", referent->getClass()->name); - return false; + return Nothing(); } RootedValue calleev(cx, ObjectValue(*referent)); @@ -12581,15 +12594,15 @@ bool DebuggerObject::call(JSContext* cx, HandleDebuggerObject object, // that is where any exceptions must be reported. RootedValue thisv(cx, thisv_); if (!dbg->unwrapDebuggeeValue(cx, &thisv)) { - return false; + return Nothing(); } Rooted args2(cx, ValueVector(cx)); if (!args2.append(args.begin(), args.end())) { - return false; + return Nothing(); } for (unsigned i = 0; i < args2.length(); ++i) { if (!dbg->unwrapDebuggeeValue(cx, args2[i])) { - return false; + return Nothing(); } } @@ -12600,18 +12613,18 @@ bool DebuggerObject::call(JSContext* cx, HandleDebuggerObject object, EnterDebuggeeObjectRealm(cx, ar, referent); if (!cx->compartment()->wrap(cx, &calleev) || !cx->compartment()->wrap(cx, &thisv)) { - return false; + return Nothing(); } for (unsigned i = 0; i < args2.length(); ++i) { if (!cx->compartment()->wrap(cx, args2[i])) { - return false; + return Nothing(); } } - // Call the function. Use receiveCompletionValue to return to the debugger - // compartment and populate args.rval(). + // Call the function. LeaveDebuggeeNoExecute nnx(cx); + RootedValue result(cx); bool ok; { InvokeArgs invokeArgs(cx); @@ -12622,11 +12635,13 @@ bool DebuggerObject::call(JSContext* cx, HandleDebuggerObject object, invokeArgs[i].set(args2[i]); } - ok = js::Call(cx, calleev, thisv, invokeArgs, result); + ok = js::Call(cx, calleev, thisv, invokeArgs, &result); } } - return dbg->receiveCompletionValue(ar, ok, result, result); + Rooted completion(cx, Completion::fromJSResult(cx, ok, result)); + ar.reset(); + return Some(std::move(completion.get())); } /* static */ diff --git a/js/src/vm/Debugger.h b/js/src/vm/Debugger.h index 589ad93147f7..1b534eceead8 100644 --- a/js/src/vm/Debugger.h +++ b/js/src/vm/Debugger.h @@ -1869,9 +1869,9 @@ class DebuggerObject : public NativeObject { static MOZ_MUST_USE bool deleteProperty(JSContext* cx, HandleDebuggerObject object, HandleId id, ObjectOpResult& result); - static MOZ_MUST_USE bool call(JSContext* cx, HandleDebuggerObject object, - HandleValue thisv, Handle args, - MutableHandleValue result); + static MOZ_MUST_USE mozilla::Maybe call( + JSContext* cx, HandleDebuggerObject object, HandleValue thisv, + Handle args); static MOZ_MUST_USE bool forceLexicalInitializationByName( JSContext* cx, HandleDebuggerObject object, HandleId id, bool& result); static MOZ_MUST_USE JS::Result executeInGlobal(