Bug 902718 - Stop taking an nsIScriptContext in XBL serialization routines. r=bz

This commit is contained in:
Bobby Holley 2013-08-09 09:25:13 -07:00
Родитель b34c37010a
Коммит 9f7ed59515
4 изменённых файлов: 23 добавлений и 19 удалений

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

@ -239,8 +239,9 @@ nsXBLProtoImplMethod::Read(nsIScriptContext* aContext,
{
MOZ_ASSERT(!IsCompiled() && !GetUncompiledMethod());
JS::Rooted<JSObject*> methodObject(aContext->GetNativeContext());
nsresult rv = XBL_DeserializeFunction(aContext, aStream, &methodObject);
AutoPushJSContext cx(aContext->GetNativeContext());
JS::Rooted<JSObject*> methodObject(cx);
nsresult rv = XBL_DeserializeFunction(aStream, &methodObject);
if (NS_FAILED(rv)) {
SetUncompiledMethod(nullptr);
return rv;
@ -257,6 +258,7 @@ nsXBLProtoImplMethod::Write(nsIScriptContext* aContext,
{
MOZ_ASSERT(IsCompiled());
if (GetCompiledMethod()) {
AutoPushJSContext cx(aContext->GetNativeContext());
nsresult rv = aStream->Write8(XBLBinding_Serialize_Method);
NS_ENSURE_SUCCESS(rv, rv);
@ -268,7 +270,7 @@ nsXBLProtoImplMethod::Write(nsIScriptContext* aContext,
// been set to a compiled method.
JS::Handle<JSObject*> method =
JS::Handle<JSObject*>::fromMarkedLocation(mMethod.AsHeapObject().address());
return XBL_SerializeFunction(aContext, aStream, method);
return XBL_SerializeFunction(aStream, method);
}
return NS_OK;
@ -368,6 +370,7 @@ nsXBLProtoImplAnonymousMethod::Write(nsIScriptContext* aContext,
{
MOZ_ASSERT(IsCompiled());
if (GetCompiledMethod()) {
AutoPushJSContext cx(aContext->GetNativeContext());
nsresult rv = aStream->Write8(aType);
NS_ENSURE_SUCCESS(rv, rv);
@ -376,7 +379,7 @@ nsXBLProtoImplAnonymousMethod::Write(nsIScriptContext* aContext,
// been set to a compiled method.
JS::Handle<JSObject*> method =
JS::Handle<JSObject*>::fromMarkedLocation(mMethod.AsHeapObject().address());
rv = XBL_SerializeFunction(aContext, aStream, method);
rv = XBL_SerializeFunction(aStream, method);
NS_ENSURE_SUCCESS(rv, rv);
}

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

@ -304,12 +304,12 @@ nsXBLProtoImplProperty::Read(nsIScriptContext* aContext,
MOZ_ASSERT(!mIsCompiled);
MOZ_ASSERT(!mGetter.GetUncompiled() && !mSetter.GetUncompiled());
JSContext *cx = aContext->GetNativeContext();
AutoPushJSContext cx(aContext->GetNativeContext());
JS::Rooted<JSObject*> getterObject(cx);
if (aType == XBLBinding_Serialize_GetterProperty ||
aType == XBLBinding_Serialize_GetterSetterProperty) {
nsresult rv = XBL_DeserializeFunction(aContext, aStream, &getterObject);
nsresult rv = XBL_DeserializeFunction(aStream, &getterObject);
NS_ENSURE_SUCCESS(rv, rv);
mJSAttributes |= JSPROP_GETTER | JSPROP_SHARED;
@ -319,7 +319,7 @@ nsXBLProtoImplProperty::Read(nsIScriptContext* aContext,
JS::Rooted<JSObject*> setterObject(cx);
if (aType == XBLBinding_Serialize_SetterProperty ||
aType == XBLBinding_Serialize_GetterSetterProperty) {
nsresult rv = XBL_DeserializeFunction(aContext, aStream, &setterObject);
nsresult rv = XBL_DeserializeFunction(aStream, &setterObject);
NS_ENSURE_SUCCESS(rv, rv);
mJSAttributes |= JSPROP_SETTER | JSPROP_SHARED;
@ -338,6 +338,7 @@ nsXBLProtoImplProperty::Write(nsIScriptContext* aContext,
nsIObjectOutputStream* aStream)
{
XBLBindingSerializeDetails type;
AutoPushJSContext cx(aContext->GetNativeContext());
if (mJSAttributes & JSPROP_GETTER) {
type = mJSAttributes & JSPROP_SETTER ?
@ -365,14 +366,14 @@ nsXBLProtoImplProperty::Write(nsIScriptContext* aContext,
if (mJSAttributes & JSPROP_GETTER) {
JS::Handle<JSObject*> function =
JS::Handle<JSObject*>::fromMarkedLocation(mGetter.AsHeapObject().address());
rv = XBL_SerializeFunction(aContext, aStream, function);
rv = XBL_SerializeFunction(aStream, function);
NS_ENSURE_SUCCESS(rv, rv);
}
if (mJSAttributes & JSPROP_SETTER) {
JS::Handle<JSObject*> function =
JS::Handle<JSObject*>::fromMarkedLocation(mSetter.AsHeapObject().address());
rv = XBL_SerializeFunction(aContext, aStream, function);
rv = XBL_SerializeFunction(aStream, function);
NS_ENSURE_SUCCESS(rv, rv);
}

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

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsXBLSerialize.h"
#include "nsXBLPrototypeBinding.h"
#include "nsIXPConnect.h"
#include "nsContentUtils.h"
#include "nsCxPusher.h"
@ -12,20 +13,21 @@
using namespace mozilla;
nsresult
XBL_SerializeFunction(nsIScriptContext* aContext,
nsIObjectOutputStream* aStream,
XBL_SerializeFunction(nsIObjectOutputStream* aStream,
JS::Handle<JSObject*> aFunction)
{
AutoPushJSContext cx(aContext->GetNativeContext());
AssertInCompilationScope();
AutoJSContext cx;
MOZ_ASSERT(js::GetContextCompartment(cx) == js::GetObjectCompartment(aFunction));
return nsContentUtils::XPConnect()->WriteFunction(aStream, cx, aFunction);
}
nsresult
XBL_DeserializeFunction(nsIScriptContext* aContext,
nsIObjectInputStream* aStream,
XBL_DeserializeFunction(nsIObjectInputStream* aStream,
JS::MutableHandle<JSObject*> aFunctionObjectp)
{
AutoPushJSContext cx(aContext->GetNativeContext());
AssertInCompilationScope();
AutoJSContext cx;
return nsContentUtils::XPConnect()->ReadFunction(aStream, cx,
aFunctionObjectp.address());
}

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

@ -77,13 +77,11 @@ typedef uint8_t XBLBindingSerializeDetails;
PR_STATIC_ASSERT(XBLBinding_Serialize_CustomNamespace >= kNameSpaceID_LastBuiltin);
nsresult
XBL_SerializeFunction(nsIScriptContext* aContext,
nsIObjectOutputStream* aStream,
XBL_SerializeFunction(nsIObjectOutputStream* aStream,
JS::Handle<JSObject*> aFunctionObject);
nsresult
XBL_DeserializeFunction(nsIScriptContext* aContext,
nsIObjectInputStream* aStream,
XBL_DeserializeFunction(nsIObjectInputStream* aStream,
JS::MutableHandle<JSObject*> aFunctionObject);
#endif // nsXBLSerialize_h__