Bug 1147005 - Change JSAddPropertyOp signature. r=jorendorff,peterv

This commit is contained in:
Tom Schuster 2015-03-28 14:47:02 +01:00
Родитель c7b7ac7920
Коммит 8a5dbf7c06
15 изменённых файлов: 43 добавлений и 57 удалений

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

@ -912,7 +912,7 @@ nsDOMClassInfo::PreCreate(nsISupports *nativeObj, JSContext *cx,
NS_IMETHODIMP
nsDOMClassInfo::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp,
JSObject *obj, jsid id, JS::Handle<JS::Value> val,
bool *_retval)
{
NS_WARNING("nsDOMClassInfo::AddProperty Don't call me!");
@ -2420,7 +2420,8 @@ nsEventTargetSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
NS_IMETHODIMP
nsEventTargetSH::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, bool *_retval)
JSObject *obj, jsid id, JS::Handle<JS::Value> val,
bool *_retval)
{
nsEventTargetSH::PreserveWrapper(GetNative(wrapper, obj));

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

@ -208,7 +208,8 @@ public:
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj) override;
NS_IMETHOD AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, JS::Value *vp, bool *_retval) override;
JSObject *obj, jsid id, JS::Handle<JS::Value> val,
bool *_retval) override;
virtual void PreserveWrapper(nsISupports *aNative) override;

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

@ -1503,7 +1503,7 @@ class CGAddPropertyHook(CGAbstractClassHook):
args = [Argument('JSContext*', 'cx'),
Argument('JS::Handle<JSObject*>', 'obj'),
Argument('JS::Handle<jsid>', 'id'),
Argument('JS::MutableHandle<JS::Value>', 'vp')]
Argument('JS::Handle<JS::Value>', 'val')]
CGAbstractClassHook.__init__(self, descriptor, ADDPROPERTY_HOOK_NAME,
'bool', args)

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

@ -163,7 +163,7 @@ NPClass nsJSObjWrapper::sJSObjWrapperNPClass =
};
static bool
NPObjWrapper_AddProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp);
NPObjWrapper_AddProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> v);
static bool
NPObjWrapper_DelProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
@ -1250,7 +1250,7 @@ GetNPObject(JSContext *cx, JSObject *obj)
// Does not actually add a property because this is always followed by a
// SetProperty call.
static bool
NPObjWrapper_AddProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp)
NPObjWrapper_AddProperty(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> v)
{
NPObject *npobj = GetNPObject(cx, obj);

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

@ -214,14 +214,16 @@ class ObjectOpResult
// JSClass operation signatures.
// Add or get a property named by id in obj. Note the jsid id type -- id may
// Get a property named by id in obj. Note the jsid id type -- id may
// be a string (Unicode property identifier) or an int (element index). The
// *vp out parameter, on success, is the new property value after the action.
typedef bool
(* JSGetterOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
JS::MutableHandleValue vp);
typedef JSGetterOp JSAddPropertyOp;
// Add a property named by id to obj.
typedef bool
(* JSAddPropertyOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v);
// Set a property named by id in obj, treating the assignment as strict
// mode code if strict is true. Note the jsid id type -- id may be a string

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

@ -10,7 +10,7 @@
static int callCount = 0;
static bool
AddProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
AddProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v)
{
callCount++;
return true;

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

@ -10,7 +10,7 @@
static int g_counter;
static bool
CounterAdd(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
CounterAdd(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v)
{
g_counter++;
return true;

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

@ -749,7 +749,7 @@ js::WouldDefinePastNonwritableLength(HandleNativeObject obj, uint32_t index)
}
static bool
array_addProperty(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp)
array_addProperty(JSContext* cx, HandleObject obj, HandleId id, HandleValue v)
{
Rooted<ArrayObject*> arr(cx, &obj->as<ArrayObject>());

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

@ -320,6 +320,16 @@ CallJSSetterOp(JSContext* cx, SetterOp op, HandleObject obj, HandleId id, Mutabl
return op(cx, obj, id, vp, result);
}
inline bool
CallJSAddPropertyOp(JSContext* cx, JSAddPropertyOp op, HandleObject obj, HandleId id,
HandleValue v)
{
JS_CHECK_RECURSION(cx, return false);
assertSameCompartment(cx, obj, id, v);
return op(cx, obj, id, v);
}
inline bool
CallJSDeletePropertyOp(JSContext* cx, JSDeletePropertyOp op, HandleObject receiver, HandleId id,
ObjectOpResult& result)

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

@ -2497,7 +2497,6 @@ js::InitClass(JSContext* cx, HandleObject obj, HandleObject protoProto_,
RootedObject protoProto(cx, protoProto_);
/* Check function pointer members. */
MOZ_ASSERT(clasp->addProperty != JS_PropertyStub);
MOZ_ASSERT(clasp->getProperty != JS_PropertyStub);
MOZ_ASSERT(clasp->setProperty != JS_StrictPropertyStub);

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

@ -1034,43 +1034,26 @@ js::NativeLookupElement(JSContext* cx, HandleNativeObject obj, uint32_t index,
/*** [[DefineOwnProperty]] ***********************************************************************/
/*
* Backward compatibility requires allowing addProperty hooks to mutate the
* nominal initial value of a slotful property, while GC safety wants that
* value to be stored before the call-out through the hook. Optimize to do
* both while saving cycles for classes that stub their addProperty hook.
*/
static inline bool
CallAddPropertyHook(ExclusiveContext* cx, HandleNativeObject obj, HandleShape shape,
HandleValue nominal)
HandleValue value)
{
if (JSAddPropertyOp addProperty = obj->getClass()->addProperty) {
MOZ_ASSERT(addProperty != JS_PropertyStub);
if (!cx->shouldBeJSContext())
return false;
// Make a local copy of value so addProperty can mutate its inout parameter.
RootedValue value(cx, nominal);
// Use CallJSGetterOp, since JSGetterOp and JSAddPropertyOp happen to
// have all the same argument types.
Rooted<jsid> id(cx, shape->propid());
if (!CallJSGetterOp(cx->asJSContext(), addProperty, obj, id, &value)) {
RootedId id(cx, shape->propid());
if (!CallJSAddPropertyOp(cx->asJSContext(), addProperty, obj, id, value)) {
obj->removeProperty(cx, shape->propid());
return false;
}
if (value.get() != nominal) {
if (shape->hasSlot())
obj->setSlotWithType(cx, shape, value);
}
}
return true;
}
static inline bool
CallAddPropertyHookDense(ExclusiveContext* cx, HandleNativeObject obj, uint32_t index,
HandleValue nominal)
HandleValue value)
{
// Inline addProperty for array objects.
if (obj->is<ArrayObject>()) {
@ -1082,28 +1065,18 @@ CallAddPropertyHookDense(ExclusiveContext* cx, HandleNativeObject obj, uint32_t
}
if (JSAddPropertyOp addProperty = obj->getClass()->addProperty) {
MOZ_ASSERT(addProperty != JS_PropertyStub);
if (!cx->shouldBeJSContext())
return false;
if (!obj->maybeCopyElementsForWrite(cx))
return false;
// Make a local copy of value so addProperty can mutate its inout parameter.
RootedValue value(cx, nominal);
// Use CallJSGetterOp, since JSGetterOp and JSAddPropertyOp happen to
// have all the same argument types.
Rooted<jsid> id(cx, INT_TO_JSID(index));
if (!CallJSGetterOp(cx->asJSContext(), addProperty, obj, id, &value)) {
RootedId id(cx, INT_TO_JSID(index));
if (!CallJSAddPropertyOp(cx->asJSContext(), addProperty, obj, id, value)) {
obj->setDenseElementHole(cx, index);
return false;
}
if (value.get() != nominal)
obj->setDenseElementWithType(cx, index, value);
}
return true;
}

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

@ -32,7 +32,7 @@ interface nsIXPConnectWrappedNative;
* boolean to PR_TRUE before making the call. Implementations may skip writing
* to *_retval unless they want to return PR_FALSE.
*/
[uuid(402bf112-6d3b-431f-bb0f-d05ec183ee7b)]
[uuid(19b70b26-7c3f-437f-a04a-2a8f9e28b617)]
interface nsIXPCScriptable : nsISupports
{
/* bitflags used for 'flags' (only 32 bits available!) */
@ -79,7 +79,7 @@ interface nsIXPCScriptable : nsISupports
boolean addProperty(in nsIXPConnectWrappedNative wrapper,
in JSContextPtr cx, in JSObjectPtr obj, in jsid id,
in JSValPtr vp);
in jsval val);
// The returnCode should be set to NS_SUCCESS_I_DID_SOMETHING if
// this method does something.

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

@ -79,7 +79,7 @@ NS_IMETHODIMP XPC_MAP_CLASSNAME::PreCreate(nsISupports* nativeObj, JSContext * c
#endif
#ifndef XPC_MAP_WANT_ADDPROPERTY
NS_IMETHODIMP XPC_MAP_CLASSNAME::AddProperty(nsIXPConnectWrappedNative* wrapper, JSContext * cx, JSObject * obj, jsid id, JS::Value * vp, bool* _retval)
NS_IMETHODIMP XPC_MAP_CLASSNAME::AddProperty(nsIXPConnectWrappedNative* wrapper, JSContext * cx, JSObject * obj, jsid id, JS::HandleValue val, bool* _retval)
{NS_ERROR("never called"); return NS_ERROR_NOT_IMPLEMENTED;}
#endif

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

@ -398,7 +398,7 @@ struct AutoSkipPropertyMirroring
// add-ons in a separate compartment while still giving them access to the
// chrome window.
static bool
sandbox_addProperty(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp)
sandbox_addProperty(JSContext* cx, HandleObject obj, HandleId id, HandleValue v)
{
CompartmentPrivate* priv = CompartmentPrivate::Get(obj);
MOZ_ASSERT(priv->writeToGlobalPrototype);
@ -441,7 +441,7 @@ sandbox_addProperty(JSContext* cx, HandleObject obj, HandleId id, MutableHandleV
// readonly attribute (as it calls JSObject::defineProperty). See bug
// 1019181.
if (pd.object() && !pd.configurable()) {
if (!JS_SetPropertyById(cx, proto, id, vp))
if (!JS_SetPropertyById(cx, proto, id, v))
return false;
} else {
if (!JS_CopyPropertyFrom(cx, id, unwrappedProto, obj,
@ -452,7 +452,7 @@ sandbox_addProperty(JSContext* cx, HandleObject obj, HandleId id, MutableHandleV
if (!JS_GetPropertyDescriptorById(cx, obj, id, &pd))
return false;
unsigned attrs = pd.attributes() & ~(JSPROP_GETTER | JSPROP_SETTER);
if (!JS_DefinePropertyById(cx, obj, id, vp,
if (!JS_DefinePropertyById(cx, obj, id, v,
attrs | JSPROP_PROPOP_ACCESSORS | JSPROP_REDEFINE_NONCONFIGURABLE,
JS_PROPERTYOP_GETTER(writeToProto_getProperty),
JS_PROPERTYOP_SETTER(writeToProto_setProperty)))

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

@ -413,7 +413,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
/***************************************************************************/
static bool
XPC_WN_OnlyIWrite_AddPropertyStub(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp)
XPC_WN_OnlyIWrite_AddPropertyStub(JSContext* cx, HandleObject obj, HandleId id, HandleValue v)
{
XPCCallContext ccx(JS_CALLER, cx, obj, NullPtr(), id);
XPCWrappedNative* wrapper = ccx.GetWrapper();
@ -428,7 +428,7 @@ XPC_WN_OnlyIWrite_AddPropertyStub(JSContext* cx, HandleObject obj, HandleId id,
static bool
XPC_WN_CannotModifyPropertyStub(JSContext* cx, HandleObject obj, HandleId id,
MutableHandleValue vp)
HandleValue v)
{
return Throw(NS_ERROR_XPC_CANT_MODIFY_PROP_ON_WN, cx);
}
@ -688,7 +688,7 @@ const XPCWrappedNativeJSClass XPC_WN_NoHelper_JSClass = {
/***************************************************************************/
static bool
XPC_WN_MaybeResolvingPropertyStub(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp)
XPC_WN_MaybeResolvingPropertyStub(JSContext* cx, HandleObject obj, HandleId id, HandleValue v)
{
XPCCallContext ccx(JS_CALLER, cx, obj);
XPCWrappedNative* wrapper = ccx.GetWrapper();
@ -748,10 +748,10 @@ XPC_WN_MaybeResolvingDeletePropertyStub(JSContext* cx, HandleObject obj, HandleI
static bool
XPC_WN_Helper_AddProperty(JSContext* cx, HandleObject obj, HandleId id,
MutableHandleValue vp)
HandleValue v)
{
PRE_HELPER_STUB
AddProperty(wrapper, cx, obj, id, vp.address(), &retval);
AddProperty(wrapper, cx, obj, id, v, &retval);
POST_HELPER_STUB
}
@ -1331,7 +1331,7 @@ const js::Class XPC_WN_ModsAllowed_NoCall_Proto_JSClass = {
static bool
XPC_WN_OnlyIWrite_Proto_AddPropertyStub(JSContext* cx, HandleObject obj, HandleId id,
MutableHandleValue vp)
HandleValue v)
{
MOZ_ASSERT(js::GetObjectClass(obj) == &XPC_WN_NoMods_WithCall_Proto_JSClass ||
js::GetObjectClass(obj) == &XPC_WN_NoMods_NoCall_Proto_JSClass,