Bug 1390147 - Remove getProperty Class hook from StatementJSHelper and AsyncStatementJSHelper. r=mrbkap
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 15 Aug 2017 16:16:07 +0200
changeset 424349 35622c347169c77eb68f8f62c7f4b4ecd0e2a60f
parent 424348 c8a1fb34d90906002946ec7e1a336e494eda55a3
child 424350 3d02042a6c56d1f21faab255a797f8682352f1a6
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1390147
milestone57.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 1390147 - Remove getProperty Class hook from StatementJSHelper and AsyncStatementJSHelper. r=mrbkap
storage/mozStorageAsyncStatementJSHelper.cpp
storage/mozStorageStatementJSHelper.cpp
--- a/storage/mozStorageAsyncStatementJSHelper.cpp
+++ b/storage/mozStorageAsyncStatementJSHelper.cpp
@@ -80,27 +80,27 @@ NS_INTERFACE_MAP_BEGIN(AsyncStatementJSH
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 ////////////////////////////////////////////////////////////////////////////////
 //// nsIXPCScriptable
 
 #define XPC_MAP_CLASSNAME         AsyncStatementJSHelper
 #define XPC_MAP_QUOTED_CLASSNAME "AsyncStatementJSHelper"
-#define XPC_MAP_FLAGS (XPC_SCRIPTABLE_WANT_GETPROPERTY | \
+#define XPC_MAP_FLAGS (XPC_SCRIPTABLE_WANT_RESOLVE | \
                        XPC_SCRIPTABLE_ALLOW_PROP_MODS_DURING_RESOLVE)
 #include "xpc_map_end.h"
 
 NS_IMETHODIMP
-AsyncStatementJSHelper::GetProperty(nsIXPConnectWrappedNative *aWrapper,
-                                    JSContext *aCtx,
-                                    JSObject *aScopeObj,
-                                    jsid aId,
-                                    JS::Value *_result,
-                                    bool *_retval)
+AsyncStatementJSHelper::Resolve(nsIXPConnectWrappedNative *aWrapper,
+                                JSContext *aCtx,
+                                JSObject *aScopeObj,
+                                jsid aId,
+                                bool *resolvedp,
+                                bool *_retval)
 {
   if (!JSID_IS_STRING(aId))
     return NS_OK;
 
   // Cast to async via mozI* since direct from nsISupports is ambiguous.
   JS::RootedObject scope(aCtx, aScopeObj);
   JS::RootedId id(aCtx, aId);
   mozIStorageAsyncStatement *iAsyncStmt =
@@ -110,18 +110,24 @@ AsyncStatementJSHelper::GetProperty(nsIX
 #ifdef DEBUG
   {
     nsISupports *supp = aWrapper->Native();
     nsCOMPtr<mozIStorageAsyncStatement> isStatement(do_QueryInterface(supp));
     NS_ASSERTION(isStatement, "How is this not an async statement?!");
   }
 #endif
 
-  if (::JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(id), "params"))
-    return getParams(stmt, aCtx, scope, _result);
+  if (::JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(id), "params")) {
+    JS::RootedValue val(aCtx);
+    nsresult rv = getParams(stmt, aCtx, scope, val.address());
+    NS_ENSURE_SUCCESS(rv, rv);
+    *_retval = ::JS_DefinePropertyById(aCtx, scope, id, val, JSPROP_RESOLVING);
+    *resolvedp = true;
+    return NS_OK;
+  }
 
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //// AsyncStatementParamsHolder
 
 NS_IMPL_ISUPPORTS(AsyncStatementParamsHolder, nsIXPConnectJSObjectHolder);
--- a/storage/mozStorageStatementJSHelper.cpp
+++ b/storage/mozStorageStatementJSHelper.cpp
@@ -179,28 +179,25 @@ NS_INTERFACE_MAP_BEGIN(StatementJSHelper
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 ////////////////////////////////////////////////////////////////////////////////
 //// nsIXPCScriptable
 
 #define XPC_MAP_CLASSNAME         StatementJSHelper
 #define XPC_MAP_QUOTED_CLASSNAME "StatementJSHelper"
-#define XPC_MAP_FLAGS (XPC_SCRIPTABLE_WANT_GETPROPERTY | \
-                       XPC_SCRIPTABLE_WANT_RESOLVE | \
+#define XPC_MAP_FLAGS (XPC_SCRIPTABLE_WANT_RESOLVE | \
                        XPC_SCRIPTABLE_ALLOW_PROP_MODS_DURING_RESOLVE)
 #include "xpc_map_end.h"
 
 NS_IMETHODIMP
-StatementJSHelper::GetProperty(nsIXPConnectWrappedNative *aWrapper,
-                               JSContext *aCtx,
-                               JSObject *aScopeObj,
-                               jsid aId,
-                               JS::Value *_result,
-                               bool *_retval)
+StatementJSHelper::Resolve(nsIXPConnectWrappedNative *aWrapper,
+                           JSContext *aCtx, JSObject *aScopeObj,
+                           jsid aId, bool *aResolvedp,
+                           bool *_retval)
 {
   if (!JSID_IS_STRING(aId))
     return NS_OK;
 
   JS::Rooted<JSObject*> scope(aCtx, aScopeObj);
   JS::Rooted<jsid> id(aCtx, aId);
 
 #ifdef DEBUG
@@ -210,43 +207,42 @@ StatementJSHelper::GetProperty(nsIXPConn
     NS_ASSERTION(isStatement, "How is this not a statement?!");
   }
 #endif
 
   Statement *stmt = static_cast<Statement *>(
     static_cast<mozIStorageStatement *>(aWrapper->Native())
   );
 
-  JSFlatString *str = JSID_TO_FLAT_STRING(id);
-  if (::JS_FlatStringEqualsAscii(str, "row"))
-    return getRow(stmt, aCtx, scope, _result);
-
-  if (::JS_FlatStringEqualsAscii(str, "params"))
-    return getParams(stmt, aCtx, scope, _result);
-
-  return NS_OK;
-}
-
-
-NS_IMETHODIMP
-StatementJSHelper::Resolve(nsIXPConnectWrappedNative *aWrapper,
-                           JSContext *aCtx, JSObject *aScopeObj,
-                           jsid aId, bool *aResolvedp,
-                           bool *_retval)
-{
-  if (!JSID_IS_STRING(aId))
-    return NS_OK;
-
-  JS::RootedObject scope(aCtx, aScopeObj);
-  if (::JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(aId), "step")) {
+  JSFlatString* str = JSID_TO_FLAT_STRING(id);
+  if (::JS_FlatStringEqualsAscii(str, "step")) {
     *_retval = ::JS_DefineFunction(aCtx, scope, "step", stepFunc,
                                    0, JSPROP_RESOLVING) != nullptr;
     *aResolvedp = true;
     return NS_OK;
   }
+
+  JS::RootedValue val(aCtx);
+
+  if (::JS_FlatStringEqualsAscii(str, "row")) {
+    nsresult rv = getRow(stmt, aCtx, scope, val.address());
+    NS_ENSURE_SUCCESS(rv, rv);
+    *_retval = ::JS_DefinePropertyById(aCtx, scope, id, val, JSPROP_RESOLVING);
+    *aResolvedp = true;
+    return NS_OK;
+  }
+
+  if (::JS_FlatStringEqualsAscii(str, "params")) {
+    nsresult rv = getParams(stmt, aCtx, scope, val.address());
+    NS_ENSURE_SUCCESS(rv, rv);
+    *_retval = ::JS_DefinePropertyById(aCtx, scope, id, val, JSPROP_RESOLVING);
+    *aResolvedp = true;
+    return NS_OK;
+  }
+
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //// StatementJSObjectHolder
 
 NS_IMPL_ISUPPORTS(StatementJSObjectHolder, nsIXPConnectJSObjectHolder);