Bug 959787 - Handlify some JS friend APIs r=sfink

This commit is contained in:
Jon Coppeard 2014-01-29 10:01:33 +00:00
parent d0ac1956cc
commit 4bd291ee00
9 changed files with 60 additions and 61 deletions

View File

@ -293,20 +293,20 @@ jsval
jsd_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval)
{
AutoSafeJSContext cx;
JS::RootedObject obj(cx);
JS::RootedValue val(cx, jsdval->val);
if (!JSVAL_IS_PRIMITIVE(val)) {
JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(val));
obj = JS_ObjectToOuterObject(cx, JSVAL_TO_OBJECT(val));
if (!val.isPrimitive()) {
JS::RootedObject obj(cx, &val.toObject());
JSAutoCompartment ac(cx, obj);
obj = JS_ObjectToOuterObject(cx, obj);
if (!obj)
{
JS_ClearPendingException(cx);
val = JSVAL_NULL;
}
else
val = OBJECT_TO_JSVAL(obj);
val = JS::ObjectValue(*obj);
}
return val;
}

View File

@ -86,8 +86,8 @@ TestPlainTypedArray(JSContext *cx)
return true;
}
template<JSObject *CreateWithBuffer(JSContext *, JSObject *, uint32_t, int32_t),
JSObject *CreateFromArray(JSContext *, JSObject *),
template<JSObject *CreateWithBuffer(JSContext *, JS::HandleObject, uint32_t, int32_t),
JSObject *CreateFromArray(JSContext *, JS::HandleObject),
typename Element,
Element *GetData(JSObject *)>
bool

View File

@ -125,11 +125,11 @@ JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals
/* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */
extern JS_FRIEND_API(JSObject *)
JS_ObjectToInnerObject(JSContext *cx, JSObject *obj);
JS_ObjectToInnerObject(JSContext *cx, JS::HandleObject obj);
/* Requires obj != nullptr. */
extern JS_FRIEND_API(JSObject *)
JS_ObjectToOuterObject(JSContext *cx, JSObject *obj);
JS_ObjectToOuterObject(JSContext *cx, JS::HandleObject obj);
extern JS_FRIEND_API(JSObject *)
JS_CloneObject(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent);
@ -1020,23 +1020,23 @@ JS_NewFloat64Array(JSContext *cx, uint32_t nelements);
*/
extern JS_FRIEND_API(JSObject *)
JS_NewInt8ArrayFromArray(JSContext *cx, JSObject *array);
JS_NewInt8ArrayFromArray(JSContext *cx, JS::HandleObject array);
extern JS_FRIEND_API(JSObject *)
JS_NewUint8ArrayFromArray(JSContext *cx, JSObject *array);
JS_NewUint8ArrayFromArray(JSContext *cx, JS::HandleObject array);
extern JS_FRIEND_API(JSObject *)
JS_NewUint8ClampedArrayFromArray(JSContext *cx, JSObject *array);
JS_NewUint8ClampedArrayFromArray(JSContext *cx, JS::HandleObject array);
extern JS_FRIEND_API(JSObject *)
JS_NewInt16ArrayFromArray(JSContext *cx, JSObject *array);
JS_NewInt16ArrayFromArray(JSContext *cx, JS::HandleObject array);
extern JS_FRIEND_API(JSObject *)
JS_NewUint16ArrayFromArray(JSContext *cx, JSObject *array);
JS_NewUint16ArrayFromArray(JSContext *cx, JS::HandleObject array);
extern JS_FRIEND_API(JSObject *)
JS_NewInt32ArrayFromArray(JSContext *cx, JSObject *array);
JS_NewInt32ArrayFromArray(JSContext *cx, JS::HandleObject array);
extern JS_FRIEND_API(JSObject *)
JS_NewUint32ArrayFromArray(JSContext *cx, JSObject *array);
JS_NewUint32ArrayFromArray(JSContext *cx, JS::HandleObject array);
extern JS_FRIEND_API(JSObject *)
JS_NewFloat32ArrayFromArray(JSContext *cx, JSObject *array);
JS_NewFloat32ArrayFromArray(JSContext *cx, JS::HandleObject array);
extern JS_FRIEND_API(JSObject *)
JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array);
JS_NewFloat64ArrayFromArray(JSContext *cx, JS::HandleObject array);
/*
* Create a new typed array using the given ArrayBuffer for storage. The
@ -1045,31 +1045,31 @@ JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array);
*/
extern JS_FRIEND_API(JSObject *)
JS_NewInt8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
JS_NewInt8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, int32_t length);
extern JS_FRIEND_API(JSObject *)
JS_NewUint8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
JS_NewUint8ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, int32_t length);
extern JS_FRIEND_API(JSObject *)
JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, int32_t length);
extern JS_FRIEND_API(JSObject *)
JS_NewInt16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
JS_NewInt16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, int32_t length);
extern JS_FRIEND_API(JSObject *)
JS_NewUint16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
JS_NewUint16ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, int32_t length);
extern JS_FRIEND_API(JSObject *)
JS_NewInt32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
JS_NewInt32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, int32_t length);
extern JS_FRIEND_API(JSObject *)
JS_NewUint32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
JS_NewUint32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, int32_t length);
extern JS_FRIEND_API(JSObject *)
JS_NewFloat32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
JS_NewFloat32ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, int32_t length);
extern JS_FRIEND_API(JSObject *)
JS_NewFloat64ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
JS_NewFloat64ArrayWithBuffer(JSContext *cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, int32_t length);
/*

View File

@ -89,9 +89,8 @@ const Class JSObject::class_ = {
const Class* const js::ObjectClassPtr = &JSObject::class_;
JS_FRIEND_API(JSObject *)
JS_ObjectToInnerObject(JSContext *cx, JSObject *objArg)
JS_ObjectToInnerObject(JSContext *cx, HandleObject obj)
{
RootedObject obj(cx, objArg);
if (!obj) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INACTIVE);
return nullptr;
@ -100,9 +99,8 @@ JS_ObjectToInnerObject(JSContext *cx, JSObject *objArg)
}
JS_FRIEND_API(JSObject *)
JS_ObjectToOuterObject(JSContext *cx, JSObject *obj_)
JS_ObjectToOuterObject(JSContext *cx, HandleObject obj)
{
Rooted<JSObject*> obj(cx, obj_);
assertSameCompartment(cx, obj);
return GetOuterObject(cx, obj);
}

View File

@ -224,7 +224,7 @@ GetPM(JSContext* cx, JS::HandleValue value, const char* fname)
namespace JS {
JSObject*
RegisterPerfMeasurement(JSContext *cx, JSObject *globalArg)
RegisterPerfMeasurement(JSContext *cx, HandleObject globalArg)
{
RootedObject global(cx, globalArg);
RootedObject prototype(cx);

View File

@ -118,7 +118,7 @@ class JS_FRIEND_API(PerfMeasurement)
* global object). The JS-visible API is identical to the C++ API.
*/
extern JS_FRIEND_API(JSObject*)
RegisterPerfMeasurement(JSContext *cx, JSObject *global);
RegisterPerfMeasurement(JSContext *cx, JS::HandleObject global);
/*
* Given a Value which contains an instance of the aforementioned

View File

@ -3529,29 +3529,26 @@ const JSFunctionSpec _typedArray##Object::jsfuncs[] = {
}
#endif
#define IMPL_TYPED_ARRAY_JSAPI_CONSTRUCTORS(Name,NativeType) \
JS_FRIEND_API(JSObject *) JS_New ## Name ## Array(JSContext *cx, uint32_t nelements) \
{ \
return TypedArrayObjectTemplate<NativeType>::fromLength(cx, nelements); \
} \
JS_FRIEND_API(JSObject *) JS_New ## Name ## ArrayFromArray(JSContext *cx, JSObject *other_)\
{ \
Rooted<JSObject*> other(cx, other_); \
return TypedArrayObjectTemplate<NativeType>::fromArray(cx, other); \
} \
JS_FRIEND_API(JSObject *) JS_New ## Name ## ArrayWithBuffer(JSContext *cx, \
JSObject *arrayBuffer_, uint32_t byteOffset, int32_t length) \
{ \
Rooted<JSObject*> arrayBuffer(cx, arrayBuffer_); \
Rooted<JSObject*> proto(cx, nullptr); \
return TypedArrayObjectTemplate<NativeType>::fromBuffer(cx, arrayBuffer, byteOffset, \
length, proto); \
} \
JS_FRIEND_API(bool) JS_Is ## Name ## Array(JSObject *obj) \
{ \
if (!(obj = CheckedUnwrap(obj))) \
return false; \
const Class *clasp = obj->getClass(); \
#define IMPL_TYPED_ARRAY_JSAPI_CONSTRUCTORS(Name,NativeType) \
JS_FRIEND_API(JSObject *) JS_New ## Name ## Array(JSContext *cx, uint32_t nelements) \
{ \
return TypedArrayObjectTemplate<NativeType>::fromLength(cx, nelements); \
} \
JS_FRIEND_API(JSObject *) JS_New ## Name ## ArrayFromArray(JSContext *cx, HandleObject other) \
{ \
return TypedArrayObjectTemplate<NativeType>::fromArray(cx, other); \
} \
JS_FRIEND_API(JSObject *) JS_New ## Name ## ArrayWithBuffer(JSContext *cx, \
HandleObject arrayBuffer, uint32_t byteOffset, int32_t length) \
{ \
return TypedArrayObjectTemplate<NativeType>::fromBuffer(cx, arrayBuffer, byteOffset, \
length, js::NullPtr()); \
} \
JS_FRIEND_API(bool) JS_Is ## Name ## Array(JSObject *obj) \
{ \
if (!(obj = CheckedUnwrap(obj))) \
return false; \
const Class *clasp = obj->getClass(); \
return (clasp == &TypedArrayObject::classes[TypedArrayObjectTemplate<NativeType>::ArrayTypeID()]); \
}

View File

@ -355,7 +355,10 @@ XPCCallContext::UnwrapThisIfAllowed(HandleObject obj, HandleObject fun, unsigned
// here, potentially an outer window proxy, and then an XPCWN.
MOZ_ASSERT(js::IsWrapper(obj));
RootedObject unwrapped(mJSContext, js::UncheckedUnwrap(obj, /* stopAtOuter = */ false));
MOZ_ASSERT(unwrapped == JS_ObjectToInnerObject(mJSContext, js::Wrapper::wrappedObject(obj)));
#ifdef DEBUG
JS::Rooted<JSObject*> wrappedObj(mJSContext, js::Wrapper::wrappedObject(obj));
MOZ_ASSERT(unwrapped == JS_ObjectToInnerObject(mJSContext, wrappedObj));
#endif
// Make sure we have an XPCWN, and grab it.
if (!IS_WN_REFLECTOR(unwrapped))

View File

@ -32,7 +32,7 @@ XPCVariant::XPCVariant(JSContext* cx, jsval aJSVal)
: mJSVal(aJSVal), mCCGeneration(0)
{
nsVariant::Initialize(&mData);
if (!JSVAL_IS_PRIMITIVE(mJSVal)) {
if (!mJSVal.isPrimitive()) {
// XXXbholley - The innerization here was from bug 638026. Blake says
// the basic problem was that we were storing the C++ inner but the JS
// outer, which meant that, after navigation, the JS inner could be
@ -42,8 +42,9 @@ XPCVariant::XPCVariant(JSContext* cx, jsval aJSVal)
// thing, but I'm saving the cleanup here for another day. Blake thinks
// that we should just not store the WN if we're creating a variant for
// an outer window.
JSObject *obj = JS_ObjectToInnerObject(cx, JSVAL_TO_OBJECT(mJSVal));
mJSVal = OBJECT_TO_JSVAL(obj);
JS::RootedObject obj(cx, &mJSVal.toObject());
obj = JS_ObjectToInnerObject(cx, obj);
mJSVal = JS::ObjectValue(*obj);
JSObject *unwrapped = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
mReturnRawObject = !(unwrapped && IS_WN_REFLECTOR(unwrapped));