Bug 1391405: Part 1 - Add WebIDL versions of much used Components.utils helpers. r=gabor,qdot

In the code that I'm profiling, the XPC WrappedNative overhead of calling
these functions adds up to about a quarter of the time spent executing the
code. The overhead of the WebIDL versions is negligible.

MozReview-Commit-ID: 30qJy5RtP9d

--HG--
extra : rebase_source : 4fe73f4b9bde052a0eadf7d5634f792e16ca1c94
extra : histedit_source : ec61152a0181f3b0e28023c951e7181c43216d2f
This commit is contained in:
Kris Maglione 2017-08-18 11:10:10 -07:00
Родитель be9d9ede6d
Коммит 85754fb12a
3 изменённых файлов: 86 добавлений и 0 удалений

Просмотреть файл

@ -5,6 +5,9 @@
#include "ChromeUtils.h"
#include "jsfriendapi.h"
#include "WrapperFactory.h"
#include "mozilla/Base64.h"
#include "mozilla/BasePrincipal.h"
@ -126,6 +129,53 @@ ThreadSafeChromeUtils::Base64URLDecode(GlobalObject& aGlobal,
aRetval.set(buffer);
}
/* static */ void
ChromeUtils::WaiveXrays(GlobalObject& aGlobal,
JS::HandleValue aVal,
JS::MutableHandleValue aRetval,
ErrorResult& aRv)
{
JS::RootedValue value(aGlobal.Context(), aVal);
if (!xpc::WrapperFactory::WaiveXrayAndWrap(aGlobal.Context(), &value)) {
aRv.NoteJSContextException(aGlobal.Context());
} else {
aRetval.set(value);
}
}
/* static */ void
ChromeUtils::UnwaiveXrays(GlobalObject& aGlobal,
JS::HandleValue aVal,
JS::MutableHandleValue aRetval,
ErrorResult& aRv)
{
if (!aVal.isObject()) {
aRetval.set(aVal);
return;
}
JS::RootedObject obj(aGlobal.Context(), js::UncheckedUnwrap(&aVal.toObject()));
if (!JS_WrapObject(aGlobal.Context(), &obj)) {
aRv.NoteJSContextException(aGlobal.Context());
} else {
aRetval.setObject(*obj);
}
}
/* static */ void
ChromeUtils::GetClassName(GlobalObject& aGlobal,
JS::HandleObject aObj,
bool aUnwrap,
nsAString& aRetval)
{
JS::RootedObject obj(aGlobal.Context(), aObj);
if (aUnwrap) {
obj = js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false);
}
aRetval = NS_ConvertUTF8toUTF16(nsDependentCString(js::GetObjectClass(obj)->name));
}
/* static */ void
ChromeUtils::OriginAttributesToSuffix(dom::GlobalObject& aGlobal,
const dom::OriginAttributesDictionary& aAttrs,

Просмотреть файл

@ -124,6 +124,21 @@ public:
const nsAString& aUrl,
const dom::CompileScriptOptionsDictionary& aOptions,
ErrorResult& aRv);
static void WaiveXrays(GlobalObject& aGlobal,
JS::HandleValue aVal,
JS::MutableHandleValue aRetval,
ErrorResult& aRv);
static void UnwaiveXrays(GlobalObject& aGlobal,
JS::HandleValue aVal,
JS::MutableHandleValue aRetval,
ErrorResult& aRv);
static void GetClassName(GlobalObject& aGlobal,
JS::HandleObject aObj,
bool aUnwrap,
nsAString& aRetval);
};
} // namespace dom

Просмотреть файл

@ -69,6 +69,27 @@ interface ChromeUtils : ThreadSafeChromeUtils {
[NewObject, Throws]
static Promise<PrecompiledScript>
compileScript(DOMString url, optional CompileScriptOptionsDictionary options);
/**
* Waive Xray on a given value. Identity op for primitives.
*/
[Throws]
static any waiveXrays(any val);
/**
* Strip off Xray waivers on a given value. Identity op for primitives.
*/
[Throws]
static any unwaiveXrays(any val);
/**
* Gets the name of the JSClass of the object.
*
* if |unwrap| is true, all wrappers are unwrapped first. Unless you're
* specifically trying to detect whether the object is a proxy, this is
* probably what you want.
*/
static DOMString getClassName(object obj, optional boolean unwrap = true);
};
/**