Bug 1470558: Use Completion type in DebuggerObject::{set,get}Property. r=jorendorff
authorJim Blandy <jimb@mozilla.com>
Sun, 07 Jul 2019 09:47:56 +0000
changeset 544418 3f47b78ffdc0e9cd4db77302d7f4143447f84be5
parent 544417 f0aa53a43409f79f50fdb92aed3ec164749c3bee
child 544419 f82f7c40443dc5fe196a73a7eb972e332321051e
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1470558
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1470558: Use Completion type in DebuggerObject::{set,get}Property. r=jorendorff Use the `Completion` type to report the result of the `DebuggerObject::setProperty` and `getProperty` methods. Differential Revision: https://phabricator.services.mozilla.com/D25097
js/src/vm/Debugger.cpp
js/src/vm/Debugger.h
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -11523,53 +11523,51 @@ bool DebuggerObject::callMethod(JSContex
 
   return object->call(cx, object, thisv, args, callArgs.rval());
 }
 
 /* static */
 bool DebuggerObject::getPropertyMethod(JSContext* cx, unsigned argc,
                                        Value* vp) {
   THIS_DEBUGOBJECT(cx, argc, vp, "getProperty", args, object)
+  Debugger* dbg = Debugger::fromChildJSObject(object);
 
   RootedId id(cx);
   if (!ValueToId<CanGC>(cx, args.get(0), &id)) {
     return false;
   }
 
   RootedValue receiver(cx,
                        args.length() < 2 ? ObjectValue(*object) : args.get(1));
 
-  if (!DebuggerObject::getProperty(cx, object, id, receiver, args.rval())) {
-    return false;
-  }
-
-  return true;
+  Rooted<Completion> comp(cx);
+  JS_TRY_VAR_OR_RETURN_FALSE(cx, comp, getProperty(cx, object, id, receiver));
+  return comp.get().buildCompletionValue(cx, dbg, args.rval());
 }
 
 /* static */
 bool DebuggerObject::setPropertyMethod(JSContext* cx, unsigned argc,
                                        Value* vp) {
   THIS_DEBUGOBJECT(cx, argc, vp, "setProperty", args, object)
+  Debugger* dbg = Debugger::fromChildJSObject(object);
 
   RootedId id(cx);
   if (!ValueToId<CanGC>(cx, args.get(0), &id)) {
     return false;
   }
 
   RootedValue value(cx, args.get(1));
 
   RootedValue receiver(cx,
                        args.length() < 3 ? ObjectValue(*object) : args.get(2));
 
-  if (!DebuggerObject::setProperty(cx, object, id, value, receiver,
-                                   args.rval())) {
-    return false;
-  }
-
-  return true;
+  Rooted<Completion> comp(cx);
+  JS_TRY_VAR_OR_RETURN_FALSE(cx, comp,
+                             setProperty(cx, object, id, value, receiver));
+  return comp.get().buildCompletionValue(cx, dbg, args.rval());
 }
 
 /* static */
 bool DebuggerObject::applyMethod(JSContext* cx, unsigned argc, Value* vp) {
   THIS_DEBUGOBJECT(cx, argc, vp, "apply", callArgs, object);
 
   RootedValue thisv(cx, callArgs.get(0));
 
@@ -12517,83 +12515,84 @@ bool DebuggerObject::deleteProperty(JSCo
 
   cx->markId(id);
 
   ErrorCopier ec(ar);
   return DeleteProperty(cx, referent, id, result);
 }
 
 /* static */
-bool DebuggerObject::getProperty(JSContext* cx, HandleDebuggerObject object,
-                                 HandleId id, HandleValue receiver_,
-                                 MutableHandleValue result) {
+Result<Completion> DebuggerObject::getProperty(JSContext* cx,
+                                               HandleDebuggerObject object,
+                                               HandleId id,
+                                               HandleValue receiver_) {
   RootedObject referent(cx, object->referent());
   Debugger* dbg = object->owner();
 
   // Unwrap Debugger.Objects. This happens in the debugger's compartment since
   // that is where any exceptions must be reported.
   RootedValue receiver(cx, receiver_);
   if (!dbg->unwrapDebuggeeValue(cx, &receiver)) {
-    return false;
+    return cx->alreadyReportedError();
   }
 
   // Enter the debuggee compartment and rewrap all input value for that
   // compartment. (Rewrapping always takes place in the destination
   // compartment.)
   Maybe<AutoRealm> ar;
   EnterDebuggeeObjectRealm(cx, ar, referent);
   if (!cx->compartment()->wrap(cx, &referent) ||
       !cx->compartment()->wrap(cx, &receiver)) {
-    return false;
+    return cx->alreadyReportedError();
   }
   cx->markId(id);
 
   LeaveDebuggeeNoExecute nnx(cx);
 
-  bool ok = GetProperty(cx, referent, receiver, id, result);
-
-  return dbg->receiveCompletionValue(ar, ok, result, result);
-}
-
-/* static */
-bool DebuggerObject::setProperty(JSContext* cx, HandleDebuggerObject object,
-                                 HandleId id, HandleValue value_,
-                                 HandleValue receiver_,
-                                 MutableHandleValue result) {
+  RootedValue result(cx);
+  bool ok = GetProperty(cx, referent, receiver, id, &result);
+  return Completion::fromJSResult(cx, ok, result);
+}
+
+/* static */
+Result<Completion> DebuggerObject::setProperty(JSContext* cx,
+                                               HandleDebuggerObject object,
+                                               HandleId id, HandleValue value_,
+                                               HandleValue receiver_) {
   RootedObject referent(cx, object->referent());
   Debugger* dbg = object->owner();
 
   // Unwrap Debugger.Objects. This happens in the debugger's compartment since
   // that is where any exceptions must be reported.
   RootedValue value(cx, value_);
   RootedValue receiver(cx, receiver_);
   if (!dbg->unwrapDebuggeeValue(cx, &value) ||
       !dbg->unwrapDebuggeeValue(cx, &receiver)) {
-    return false;
+    return cx->alreadyReportedError();
   }
 
   // Enter the debuggee compartment and rewrap all input value for that
   // compartment. (Rewrapping always takes place in the destination
   // compartment.)
   Maybe<AutoRealm> ar;
   EnterDebuggeeObjectRealm(cx, ar, referent);
   if (!cx->compartment()->wrap(cx, &referent) ||
       !cx->compartment()->wrap(cx, &value) ||
       !cx->compartment()->wrap(cx, &receiver)) {
-    return false;
+    return cx->alreadyReportedError();
   }
   cx->markId(id);
 
   LeaveDebuggeeNoExecute nnx(cx);
 
   ObjectOpResult opResult;
   bool ok = SetProperty(cx, referent, id, value, receiver, opResult);
 
-  result.setBoolean(ok && opResult.reallyOk());
-  return dbg->receiveCompletionValue(ar, ok, result, result);
+  return Completion::fromJSResult(cx, ok,
+                                  BooleanValue(ok && opResult.reallyOk()));
 }
 
 /* static */
 bool DebuggerObject::call(JSContext* cx, HandleDebuggerObject object,
                           HandleValue thisv_, Handle<ValueVector> args,
                           MutableHandleValue result) {
   RootedObject referent(cx, object->referent());
   Debugger* dbg = object->owner();
--- a/js/src/vm/Debugger.h
+++ b/js/src/vm/Debugger.h
@@ -16,16 +16,17 @@
 
 #include "ds/TraceableFifo.h"
 #include "gc/Barrier.h"
 #include "gc/WeakMap.h"
 #include "js/Debug.h"
 #include "js/GCVariant.h"
 #include "js/HashTable.h"
 #include "js/Promise.h"
+#include "js/Result.h"
 #include "js/RootingAPI.h"
 #include "js/Utility.h"
 #include "js/Wrapper.h"
 #include "proxy/DeadObjectProxy.h"
 #include "vm/GeneratorObject.h"
 #include "vm/GlobalObject.h"
 #include "vm/JSContext.h"
 #include "vm/Realm.h"
@@ -1834,24 +1835,22 @@ class DebuggerObject : public NativeObje
   // Methods
   static MOZ_MUST_USE bool isExtensible(JSContext* cx,
                                         HandleDebuggerObject object,
                                         bool& result);
   static MOZ_MUST_USE bool isSealed(JSContext* cx, HandleDebuggerObject object,
                                     bool& result);
   static MOZ_MUST_USE bool isFrozen(JSContext* cx, HandleDebuggerObject object,
                                     bool& result);
-  static MOZ_MUST_USE bool getProperty(JSContext* cx,
-                                       HandleDebuggerObject object, HandleId id,
-                                       HandleValue receiver,
-                                       MutableHandleValue result);
-  static MOZ_MUST_USE bool setProperty(JSContext* cx,
-                                       HandleDebuggerObject object, HandleId id,
-                                       HandleValue value, HandleValue receiver,
-                                       MutableHandleValue result);
+  static MOZ_MUST_USE JS::Result<Completion> getProperty(
+      JSContext* cx, HandleDebuggerObject object, HandleId id,
+      HandleValue receiver);
+  static MOZ_MUST_USE JS::Result<Completion> setProperty(
+      JSContext* cx, HandleDebuggerObject object, HandleId id,
+      HandleValue value, HandleValue receiver);
   static MOZ_MUST_USE bool getPrototypeOf(JSContext* cx,
                                           HandleDebuggerObject object,
                                           MutableHandleDebuggerObject result);
   static MOZ_MUST_USE bool getOwnPropertyNames(JSContext* cx,
                                                HandleDebuggerObject object,
                                                MutableHandle<IdVector> result);
   static MOZ_MUST_USE bool getOwnPropertySymbols(
       JSContext* cx, HandleDebuggerObject object,