diff --git a/js/xpconnect/idl/xpccomponents.idl b/js/xpconnect/idl/xpccomponents.idl index e3ce56ab48f..f94428cdffe 100644 --- a/js/xpconnect/idl/xpccomponents.idl +++ b/js/xpconnect/idl/xpccomponents.idl @@ -120,7 +120,7 @@ interface ScheduledGCCallback : nsISupports /** * interface of Components.utils */ -[scriptable, uuid(ef621cac-c818-464a-9fb1-9a35731a7f32)] +[scriptable, uuid(e14f588b-63aa-4091-be82-a459a52f8ca6)] interface nsIXPCComponents_Utils : nsISupports { @@ -507,6 +507,17 @@ interface nsIXPCComponents_Utils : nsISupports */ nsIClassInfo getDOMClassInfo(in AString aClassName); + /** + * Gets the incument global for the execution of this function. For internal + * and testing use only. + * + * If |callback| is passed, it is invoked with the incumbent global as its + * sole argument. This allows the incumbent global to be measured in callback + * environments with no scripted frames on the stack. + */ + [implicit_jscontext] + jsval getIncumbentGlobal([optional] in jsval callback); + /** * Retrieve the last time, in microseconds since epoch, that a given * watchdog-related event occured. diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index fc8f9ffa3a3..c71d2cb86fe 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -3487,6 +3487,33 @@ nsXPCComponents_Utils::GetDOMClassInfo(const nsAString& aClassName, return NS_ERROR_NOT_AVAILABLE; } +NS_IMETHODIMP +nsXPCComponents_Utils::GetIncumbentGlobal(const Value &aCallback, + JSContext *aCx, Value *aOut) +{ + nsCOMPtr global = mozilla::dom::GetIncumbentGlobal(); + RootedValue globalVal(aCx); + + if (!global) { + globalVal = NullValue(); + } else { + // Note: We rely on the wrap call for outerization. + globalVal = ObjectValue(*global->GetGlobalJSObject()); + if (!JS_WrapValue(aCx, &globalVal)) + return NS_ERROR_FAILURE; + } + + // Invoke the callback, if passed. + if (aCallback.isObject()) { + Value ignored; + if (!JS_CallFunctionValue(aCx, nullptr, aCallback, 1, globalVal.address(), &ignored)) + return NS_ERROR_FAILURE; + } + + *aOut = globalVal; + return NS_OK; +} + NS_IMETHODIMP nsXPCComponents_Utils::GetWatchdogTimestamp(const nsAString& aCategory, PRTime *aOut) { diff --git a/js/xpconnect/tests/chrome/chrome.ini b/js/xpconnect/tests/chrome/chrome.ini index fd8a6a5a891..c8a587797ed 100644 --- a/js/xpconnect/tests/chrome/chrome.ini +++ b/js/xpconnect/tests/chrome/chrome.ini @@ -67,6 +67,7 @@ support-files = [test_paris_weakmap_keys.xul] [test_precisegc.xul] [test_sandboxImport.xul] +[test_scriptSettings.xul] [test_weakmap_keys_preserved.xul] [test_weakmap_keys_preserved2.xul] [test_weakref.xul] diff --git a/js/xpconnect/tests/chrome/test_scriptSettings.xul b/js/xpconnect/tests/chrome/test_scriptSettings.xul new file mode 100644 index 00000000000..20c0ebf34ca --- /dev/null +++ b/js/xpconnect/tests/chrome/test_scriptSettings.xul @@ -0,0 +1,125 @@ + + + + + + +