Bug 1107673 - add WrappedJSToDictionary that doesn't require a JSContext. r=bholly
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -20,16 +20,17 @@
#include "mozilla/dom/Exceptions.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/RootedDictionary.h"
#include "mozilla/dom/workers/Workers.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/Likely.h"
#include "mozilla/MemoryReporting.h"
+#include "mozilla/CycleCollectedJSRuntime.h"
#include "nsCycleCollector.h"
#include "nsIXPConnect.h"
#include "nsJSUtils.h"
#include "nsISupportsImpl.h"
#include "qsObjectHelper.h"
#include "xpcpublic.h"
#include "nsIVariant.h"
#include "pldhash.h" // For PLDHashOperator
@@ -3074,16 +3075,38 @@ WrappedJSToDictionary(JSContext* aCx, ns
return false;
}
JSAutoCompartment ac(aCx, obj);
JS::Rooted<JS::Value> v(aCx, JS::ObjectValue(*obj));
return aDictionary.Init(aCx, v);
}
+template<class T>
+inline bool
+WrappedJSToDictionary(nsISupports* aObject, T& aDictionary)
+{
+ nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(aObject);
+ NS_ENSURE_TRUE(wrappedObj, false);
+ JS::Rooted<JSObject*> obj(CycleCollectedJSRuntime::Get()->Runtime(),
+ wrappedObj->GetJSObject());
+ NS_ENSURE_TRUE(obj, false);
+
+ nsIGlobalObject* global = xpc::NativeGlobal(obj);
+ NS_ENSURE_TRUE(global, false);
+
+ // we need this AutoEntryScript here because the spec requires us to execute
+ // getters when parsing a dictionary
+ AutoEntryScript aes(global);
+ aes.TakeOwnershipOfErrorReporting();
+
+ JS::Rooted<JS::Value> v(aes.cx(), JS::ObjectValue(*obj));
+ return aDictionary.Init(aes.cx(), v);
+}
+
template<class T, class S>
inline nsRefPtr<T>
StrongOrRawPtr(already_AddRefed<S>&& aPtr)
{
return aPtr.template downcast<T>();
}