mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 483751 - Switch to use the new JSPropertyDescriptor API. Also fix it to return values on the prototype chain (which was sort of the point of its existance...). r+sr=jst
This commit is contained in:
parent
43f3187b5b
commit
a5b61f895b
@ -3580,7 +3580,7 @@ JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, uintN flags,
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
|
||||
return GetPropertyAttributesById(cx, obj, id, flags, JS_TRUE, desc);
|
||||
return GetPropertyAttributesById(cx, obj, id, flags, JS_FALSE, desc);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
|
@ -206,21 +206,17 @@ XPCWrapper::AddProperty(JSContext *cx, JSObject *wrapperObj,
|
||||
|
||||
JSBool isXOW = (STOBJ_GET_CLASS(wrapperObj) == &sXPC_XOW_JSClass.base);
|
||||
|
||||
JSObject *wrapperObjp;
|
||||
uintN attrs = JSPROP_ENUMERATE;
|
||||
JSPropertyOp getter = nsnull;
|
||||
JSPropertyOp setter = nsnull;
|
||||
|
||||
if (!GetPropertyAttrs(cx, wrapperObj, interned_id, &wrapperObjp, isXOW,
|
||||
JSRESOLVE_QUALIFIED, &attrs, &getter, &setter, vp)) {
|
||||
JSPropertyDescriptor desc;
|
||||
if (!GetPropertyAttrs(cx, wrapperObj, interned_id, JSRESOLVE_QUALIFIED,
|
||||
isXOW, &desc)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
NS_ASSERTION(wrapperObjp == wrapperObj,
|
||||
NS_ASSERTION(desc.obj == wrapperObj,
|
||||
"What weird wrapper are we using?");
|
||||
|
||||
return DefineProperty(cx, innerObj, interned_id, isXOW, *vp,
|
||||
getter, setter, attrs);
|
||||
return JS_DefinePropertyById(cx, innerObj, interned_id, desc.value,
|
||||
desc.getter, desc.setter, desc.attrs);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -296,31 +292,25 @@ XPCWrapper::NewResolve(JSContext *cx, JSObject *wrapperObj,
|
||||
JSObject *innerObj, jsval id, uintN flags,
|
||||
JSObject **objp, JSBool preserveVal)
|
||||
{
|
||||
jsval v = JSVAL_VOID;
|
||||
|
||||
jsid interned_id;
|
||||
if (!::JS_ValueToId(cx, id, &interned_id)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSBool isXOW = (STOBJ_GET_CLASS(wrapperObj) == &sXPC_XOW_JSClass.base);
|
||||
JSObject *innerObjp;
|
||||
uintN attrs = JSPROP_ENUMERATE;
|
||||
JSPropertyOp getter = nsnull;
|
||||
JSPropertyOp setter = nsnull;
|
||||
|
||||
if (!GetPropertyAttrs(cx, innerObj, interned_id, &innerObjp, isXOW, flags,
|
||||
&attrs, &getter, &setter, &v)) {
|
||||
JSPropertyDescriptor desc;
|
||||
if (!GetPropertyAttrs(cx, innerObj, interned_id, flags, isXOW, &desc)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if (!innerObjp) {
|
||||
if (!desc.obj) {
|
||||
// Nothing to define.
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (!preserveVal) {
|
||||
v = JSVAL_VOID;
|
||||
desc.value = JSVAL_VOID;
|
||||
}
|
||||
|
||||
jsval oldSlotVal;
|
||||
@ -329,8 +319,8 @@ XPCWrapper::NewResolve(JSContext *cx, JSObject *wrapperObj,
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSBool ok = DefineProperty(cx, wrapperObj, interned_id, isXOW, v,
|
||||
getter, setter, attrs);
|
||||
JSBool ok = JS_DefinePropertyById(cx, wrapperObj, interned_id, desc.value,
|
||||
desc.getter, desc.setter, desc.attrs);
|
||||
|
||||
if (ok && (ok = ::JS_SetReservedSlot(cx, wrapperObj, sResolvingSlot,
|
||||
oldSlotVal))) {
|
||||
@ -778,55 +768,15 @@ XPCWrapper::NativeToString(JSContext *cx, XPCWrappedNative *wrappedNative,
|
||||
|
||||
// static
|
||||
JSBool
|
||||
XPCWrapper::GetPropertyAttrs(JSContext *cx, JSObject *obj,
|
||||
jsid interned_id, JSObject **objp,
|
||||
JSBool wantDetails, uintN flags, uintN *attrsp,
|
||||
JSPropertyOp *getterp, JSPropertyOp *setterp,
|
||||
jsval *vp)
|
||||
XPCWrapper::GetPropertyAttrs(JSContext *cx, JSObject *obj, jsid interned_id,
|
||||
uintN flags, JSBool wantDetails,
|
||||
JSPropertyDescriptor *desc)
|
||||
{
|
||||
// NB: All parameters must be initialized by this point.
|
||||
if (!JS_LookupPropertyWithFlagsById(cx, obj, interned_id, flags,
|
||||
objp, vp)) {
|
||||
if (!JS_GetPropertyDescriptorById(cx, obj, interned_id, flags, desc)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if (!*objp) {
|
||||
// Nothing to define.
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (!wantDetails) {
|
||||
*vp = JSVAL_VOID;
|
||||
} else {
|
||||
JSBool found;
|
||||
if (!JS_GetPropertyAttrsGetterAndSetterById(cx, *objp, interned_id,
|
||||
attrsp, &found,
|
||||
getterp, setterp)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// JS_GetPropertyAttrsGetterAndSetterById returns non scripted getters and
|
||||
// setters, we don't want those.
|
||||
uintN attrs = *attrsp;
|
||||
if (!(attrs & JSPROP_GETTER)) {
|
||||
*getterp = nsnull;
|
||||
}
|
||||
if (!(attrs & JSPROP_SETTER)) {
|
||||
*setterp = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
// static
|
||||
JSBool
|
||||
XPCWrapper::DefineProperty(JSContext *cx, JSObject *obj, jsid interned_id,
|
||||
JSBool haveDetails, jsval v,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs)
|
||||
{
|
||||
const uintN interesting_attrs = haveDetails
|
||||
const uintN interesting_attrs = wantDetails
|
||||
? (JSPROP_ENUMERATE |
|
||||
JSPROP_READONLY |
|
||||
JSPROP_PERMANENT |
|
||||
@ -834,6 +784,22 @@ XPCWrapper::DefineProperty(JSContext *cx, JSObject *obj, jsid interned_id,
|
||||
JSPROP_GETTER |
|
||||
JSPROP_SETTER)
|
||||
: JSPROP_ENUMERATE;
|
||||
return JS_DefinePropertyById(cx, obj, interned_id, v, getter, setter,
|
||||
(attrs & interesting_attrs));
|
||||
desc->attrs &= interesting_attrs;
|
||||
|
||||
if (wantDetails) {
|
||||
// JS_GetPropertyDescriptorById returns non scripted getters and setters.
|
||||
// If wantDetails is true, then we need to censor them.
|
||||
if (!(desc->attrs & JSPROP_GETTER)) {
|
||||
desc->getter = nsnull;
|
||||
}
|
||||
if (!(desc->attrs & JSPROP_SETTER)) {
|
||||
desc->setter = nsnull;
|
||||
}
|
||||
} else {
|
||||
// Clear out all but attrs and obj.
|
||||
desc->getter = desc->setter = nsnull;
|
||||
desc->value = JSVAL_VOID;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -340,20 +340,9 @@ private:
|
||||
* NB: All parameters must be initialized before the call.
|
||||
*/
|
||||
static JSBool GetPropertyAttrs(JSContext *cx, JSObject *obj,
|
||||
jsid interned_id, JSObject **objp,
|
||||
JSBool wantDetails, uintN flags, uintN *attrsp,
|
||||
JSPropertyOp *getterp, JSPropertyOp *setterp,
|
||||
jsval *vp);
|
||||
|
||||
/**
|
||||
* Works in conjunction with GetPropertyAttrs to define the looked-up
|
||||
* property on another object, preserving interesting attributes, if
|
||||
* desired.
|
||||
*/
|
||||
static JSBool DefineProperty(JSContext *cx, JSObject *obj, jsid interned_id,
|
||||
JSBool haveDetails, jsval v,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs);
|
||||
jsid interned_id, uintN flags,
|
||||
JSBool wantDetails,
|
||||
JSPropertyDescriptor *desc);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user