Bug 1540301, part 2 - Make nsXPCWrappedJSClass::CallMethod() into a static method. r=bzbarsky

The first idea here is that |this| is actually the GetClass() of the
|wrapper| argument (the one call site looks like
"GetClass()->CallMethod(this, ...)"), so we can locally reconstruct it
when CallMethod is a static method.

The second idea here is that the only real use of the
nsXPCWrappedJSClass is to grab some data from the nsXPTInterfaceInfo
in a few places. This means that we can take a pointer to the info
early on in the function and use that rather than go through the
nsXPCWrappedJSClass. This in turn means that because the info is
statically allocated we no longer need to do a kungFuDeathGrip on the
wrapper's nsXPCWrappedJSClass.

Differential Revision: https://phabricator.services.mozilla.com/D26215

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew McCreight 2019-04-06 12:56:51 +00:00
Родитель 5d994e0f0e
Коммит d320f01e48
3 изменённых файлов: 11 добавлений и 10 удалений

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

@ -596,7 +596,7 @@ nsXPCWrappedJS::CallMethod(uint16_t methodIndex, const nsXPTMethodInfo* info,
if (!IsValid()) {
return NS_ERROR_UNEXPECTED;
}
return GetClass()->CallMethod(this, methodIndex, info, params);
return nsXPCWrappedJSClass::CallMethod(this, methodIndex, info, params);
}
NS_IMETHODIMP

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

@ -780,6 +780,8 @@ nsresult nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper,
return NS_ERROR_FAILURE;
}
const nsXPTInterfaceInfo* interfaceInfo =
wrapper->GetClass()->GetInterfaceInfo();
JS::RootedId id(cx);
const char* name;
nsAutoCString symbolName;
@ -808,7 +810,7 @@ nsresult nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper,
// Throw and warn for good measure.
JS_ReportErrorASCII(cx, "%s", str);
NS_WARNING(str);
return CheckForException(ccx, aes, obj, name, GetInterfaceName());
return CheckForException(ccx, aes, obj, name, interfaceInfo->Name());
}
RootedValue fval(cx);
@ -860,7 +862,8 @@ nsresult nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper,
// pass this along to the caller as an exception/result code.
fval = ObjectValue(*obj);
if (!mInfo->IsFunction() || JS_TypeOfValue(ccx, fval) != JSTYPE_FUNCTION) {
if (!interfaceInfo->IsFunction() ||
JS_TypeOfValue(ccx, fval) != JSTYPE_FUNCTION) {
if (!JS_GetPropertyById(cx, obj, id, &fval)) {
goto pre_call_clean_up;
}
@ -943,9 +946,6 @@ pre_call_clean_up:
// clean up any 'out' params handed in
CleanupOutparams(info, nativeParams, /* inOutOnly = */ true, paramCount);
// Make sure "this" doesn't get deleted during this call.
nsCOMPtr<nsIXPCWrappedJSClass> kungFuDeathGrip(this);
if (!readyToDoTheCall) {
return retval;
}
@ -979,14 +979,14 @@ pre_call_clean_up:
}
XPCConvert::ConstructException(
code, sz.get(), GetInterfaceName(), name, nullptr,
code, sz.get(), interfaceInfo->Name(), name, nullptr,
getter_AddRefs(syntheticException), nullptr, nullptr);
success = false;
}
}
if (!success) {
return CheckForException(ccx, aes, obj, name, GetInterfaceName(),
return CheckForException(ccx, aes, obj, name, interfaceInfo->Name(),
syntheticException);
}

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

@ -1634,8 +1634,9 @@ class nsXPCWrappedJSClass final : public nsIXPCWrappedJSClass {
static JSObject* GetRootJSObject(JSContext* cx, JSObject* aJSObj);
nsresult CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
const nsXPTMethodInfo* info, nsXPTCMiniVariant* params);
static nsresult CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params);
static JSObject* CallQueryInterfaceOnJSObject(JSContext* cx, JSObject* jsobj,
JS::HandleObject scope,