Bug 480185 - 'XPConnect shouldn't poke JS objects manually, should use JSAPI.' patch by Blake Kaplan <mrbkap@gmail.com> and myself. r+sr=jst.

This commit is contained in:
Ben Turner 2009-03-14 20:45:20 -07:00
parent 5f8d7f7069
commit 2a8109bd42
18 changed files with 245 additions and 240 deletions

View File

@ -68,7 +68,6 @@
#include "jscntxt.h"
#include "jsdbgapi.h"
#include "jsnum.h"
#include "jsscope.h"
// General helper includes
#include "nsGlobalWindow.h"
@ -4917,29 +4916,22 @@ nsWindowSH::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
#endif
jsid interned_id;
if (!::JS_ValueToId(cx, id, &interned_id)) {
if (!JS_ValueToId(cx, id, &interned_id)) {
*_retval = JS_FALSE;
return NS_OK;
}
JSProperty *prop = nsnull;
JSObject *pobj;
if (!OBJ_LOOKUP_PROPERTY(cx, obj, interned_id, &pobj, &prop)) {
JSPropertyDescriptor desc;
if (!JS_GetPropertyDescriptorById(cx, obj, interned_id,
JSRESOLVE_QUALIFIED, &desc)) {
*_retval = JS_FALSE;
return NS_OK;
}
NS_ASSERTION(prop && obj == pobj, "The JS engine lies");
JSScopeProperty *sprop = reinterpret_cast<JSScopeProperty *>(prop);
JSPropertyOp getter = sprop->getter;
JSPropertyOp setter = sprop->setter;
uintN attrs = sprop->attrs;
OBJ_DROP_PROPERTY(cx, pobj, prop);
// Forward the add to the inner object
*_retval = OBJ_DEFINE_PROPERTY(cx, innerObj, interned_id, *vp, getter,
setter, attrs | JSPROP_ENUMERATE, nsnull);
*_retval = JS_DefinePropertyById(cx, innerObj, interned_id, *vp,
desc.getter, desc.setter,
desc.attrs | JSPROP_ENUMERATE);
return NS_OK;
}
}
@ -4997,8 +4989,8 @@ nsWindowSH::DelProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// Forward the del to the inner object
jsid interned_id;
*_retval = (::JS_ValueToId(cx, id, &interned_id) &&
OBJ_DELETE_PROPERTY(cx, innerObj, interned_id, vp));
*_retval = (JS_ValueToId(cx, id, &interned_id) &&
JS_DeletePropertyById(cx, innerObj, interned_id));
return NS_OK;
}

View File

@ -58,6 +58,7 @@
#include <string.h>
#include "jsapi.h"
#include "jscntxt.h"
#include "jsobj.h"
#include "jsj_private.h" /* LiveConnect internals */
#include "jsj_hash.h" /* Hash table with Java object as key */
@ -502,6 +503,10 @@ lookup_member_by_id(JSContext *cx, JNIEnv *jEnv, JSObject *obj,
JSObject *proto_chain;
JSBool found_in_proto;
// This method accesses slots without using the JSAPI and these slots may
// be stale if running on trace. Must run in the interpreter here.
js_LeaveTrace(cx);
found_in_proto = JS_FALSE;
member_descriptor = NULL;
java_wrapper = JS_GetPrivate(cx, obj);

View File

@ -40,7 +40,6 @@
#include "xpcprivate.h"
#include "nsDOMError.h"
#include "jsdbgapi.h"
#include "jsobj.h" // For OBJ_GET_PROPERTY.
#include "jscntxt.h" // For JSAutoTempValueRooter.
#include "XPCWrapper.h"
#include "nsIDOMWindow.h"
@ -705,8 +704,8 @@ XPC_XOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
}
JSBool ok = isSet
? OBJ_SET_PROPERTY(cx, wrappedObj, asId, vp)
: OBJ_GET_PROPERTY(cx, wrappedObj, asId, vp);
? JS_SetPropertyById(cx, wrappedObj, asId, vp)
: JS_GetPropertyById(cx, wrappedObj, asId, vp);
if (!ok) {
return JS_FALSE;
}
@ -715,7 +714,7 @@ XPC_XOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
JSObject *newProto = STOBJ_GET_PROTO(wrappedObj);
// If code is trying to set obj.__proto__ and we're on obj's
// prototype chain, then the OBJ_SET_PROPERTY above will do the
// prototype chain, then the JS_GetPropertyById above will do the
// wrong thing if wrappedObj still delegates to Object.prototype.
// However, it's hard to figure out if wrappedObj still does
// delegate to Object.prototype so check to see if proto changed as a

View File

@ -230,7 +230,7 @@ JSBool XPCDispObject::Dispatch(XPCCallContext& ccx, IDispatch * disp,
jsval * argv = ccx.GetArgv();
// Out, in/out parameters must be objects
if(!JSVAL_IS_OBJECT(argv[index]) ||
!OBJ_SET_PROPERTY(ccx, JSVAL_TO_OBJECT(argv[index]),
!JS_SetPropertyById(ccx, JSVAL_TO_OBJECT(argv[index]),
rt->GetStringID(XPCJSRuntime::IDX_VALUE), &val))
return ThrowBadParam(NS_ERROR_XPC_CANT_SET_OUT_VAL, index, ccx);
}
@ -357,9 +357,8 @@ JSBool XPCDispObject::Invoke(XPCCallContext & ccx, CallMode mode)
if(paramInfo.IsOut())
{
if(JSVAL_IS_PRIMITIVE(val) ||
!OBJ_GET_PROPERTY(ccx, JSVAL_TO_OBJECT(val),
rt->GetStringID(XPCJSRuntime::IDX_VALUE),
&val))
!JS_GetPropertyById(ccx, JSVAL_TO_OBJECT(val),
rt->GetStringID(XPCJSRuntime::IDX_VALUE), &val))
{
delete params;
return ThrowBadParam(NS_ERROR_XPC_NEED_OUT_OBJECT, index, ccx);

View File

@ -425,7 +425,7 @@ STDMETHODIMP XPCDispatchTearOff::Invoke(DISPID dispIdMember, REFIID riid,
}
// We'll assume in/out
// TODO: I'm not sure we tell out vs in/out
OBJ_SET_PROPERTY(cx, out_obj,
JS_SetPropertyById(cx, out_obj,
rt->GetStringID(XPCJSRuntime::IDX_VALUE),
&val);
*sp++ = OBJECT_TO_JSVAL(out_obj);
@ -496,7 +496,7 @@ pre_call_clean_up:
{
jsval val;
if(JSVAL_IS_PRIMITIVE(stackbase[i+2]) ||
!OBJ_GET_PROPERTY(cx, JSVAL_TO_OBJECT(stackbase[i+2]),
!JS_GetPropertyById(cx, JSVAL_TO_OBJECT(stackbase[i+2]),
rt->GetStringID(XPCJSRuntime::IDX_VALUE),
&val))
{

View File

@ -289,8 +289,8 @@ JSBool XPCIDispatchExtension::DefineProperty(XPCCallContext & ccx,
if(resolved)
*resolved = JS_TRUE;
return JS_ValueToId(ccx, idval, &id) &&
OBJ_DEFINE_PROPERTY(ccx, obj, id, OBJECT_TO_JSVAL(funobj),
nsnull, nsnull, propFlags, nsnull);
JS_DefinePropertyById(ccx, obj, id, OBJECT_TO_JSVAL(funobj),
nsnull, nsnull, propFlags);
}
// Define the property on the object
NS_ASSERTION(member->IsProperty(), "way broken!");
@ -304,10 +304,10 @@ JSBool XPCIDispatchExtension::DefineProperty(XPCCallContext & ccx,
if(resolved)
*resolved = JS_TRUE;
return JS_ValueToId(ccx, idval, &id) &&
OBJ_DEFINE_PROPERTY(ccx, obj, id, JSVAL_VOID,
(JSPropertyOp) funobj,
(JSPropertyOp) funobj,
propFlags, nsnull);
JS_DefinePropertyById(ccx, obj, id, JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
propFlags);
}

View File

@ -42,7 +42,6 @@
#include "XPCNativeWrapper.h"
#include "XPCWrapper.h"
#include "jsdbgapi.h"
#include "jsscope.h"
static JSBool
XPC_NW_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
@ -358,27 +357,22 @@ XPC_NW_WrapFunction(JSContext* cx, JSObject* funobj, jsval *rval)
static JSBool
XPC_NW_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
JSProperty *prop;
JSObject *pobj;
jsid idAsId;
JSPropertyDescriptor desc;
if (!::JS_ValueToId(cx, id, &idAsId) ||
!OBJ_LOOKUP_PROPERTY(cx, obj, idAsId, &pobj, &prop)) {
if (!JS_ValueToId(cx, id, &idAsId) ||
!JS_GetPropertyDescriptorById(cx, obj, idAsId, JSRESOLVE_QUALIFIED,
&desc)) {
return JS_FALSE;
}
// Do not allow scripted getters or setters on XPCNativeWrappers.
NS_ASSERTION(prop && pobj == obj, "Wasn't this property just added?");
JSScopeProperty *sprop = (JSScopeProperty *) prop;
uint8 attrs = sprop->attrs;
OBJ_DROP_PROPERTY(cx, pobj, prop);
if (attrs & (JSPROP_GETTER | JSPROP_SETTER)) {
if (desc.attrs & (JSPROP_GETTER | JSPROP_SETTER)) {
return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx);
}
jsval flags;
::JS_GetReservedSlot(cx, obj, 0, &flags);
jsval flags = JSVAL_VOID;
JS_GetReservedSlot(cx, obj, 0, &flags);
// The purpose of XPC_NW_AddProperty is to wrap any object set on the
// XPCNativeWrapper by the wrapped object's scriptable helper, so bail
// here if the scriptable helper is not currently adding a property.
@ -407,11 +401,11 @@ XPC_NW_DelProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
jsid interned_id;
if (!::JS_ValueToId(cx, id, &interned_id)) {
if (!JS_ValueToId(cx, id, &interned_id)) {
return JS_FALSE;
}
return OBJ_DELETE_PROPERTY(cx, obj, interned_id, vp);
return JS_DeletePropertyById(cx, obj, interned_id);
}
);
@ -594,8 +588,8 @@ XPC_NW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
}
return aIsSet
? OBJ_SET_PROPERTY(cx, nativeObj, interned_id, vp)
: OBJ_GET_PROPERTY(cx, nativeObj, interned_id, vp);
? JS_SetPropertyById(cx, nativeObj, interned_id, vp)
: JS_GetPropertyById(cx, nativeObj, interned_id, vp);
}
if (!aIsSet &&
@ -715,19 +709,16 @@ XPC_NW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
jsid interned_id;
JSObject *pobj;
JSProperty *prop;
if (!::JS_ValueToId(cx, id, &interned_id) ||
!OBJ_LOOKUP_PROPERTY(cx, wn->GetFlatJSObject(), interned_id,
&pobj, &prop)) {
jsval val;
if (!JS_ValueToId(cx, id, &interned_id) ||
!JS_LookupPropertyWithFlagsById(cx, wn->GetFlatJSObject(), interned_id,
JSRESOLVE_QUALIFIED, &pobj, &val)) {
return JS_FALSE;
}
if (prop) {
OBJ_DROP_PROPERTY(cx, pobj, prop);
if (!OBJ_DEFINE_PROPERTY(cx, obj, interned_id, JSVAL_VOID,
nsnull, nsnull, 0, nsnull)) {
if (pobj) {
if (!JS_DefinePropertyById(cx, obj, interned_id, JSVAL_VOID, nsnull,
nsnull, 0)) {
return JS_FALSE;
}

View File

@ -41,7 +41,6 @@
* ***** END LICENSE BLOCK ***** */
#include "XPCWrapper.h"
#include "jsscope.h"
const PRUint32
XPCWrapper::sWrappedObjSlot = 1;
@ -77,7 +76,7 @@ IteratorNext(JSContext *cx, uintN argc, jsval *vp)
{
JSObject *obj;
jsval v;
obj = JS_THIS_OBJECT(cx, vp);
if (!obj)
return JS_FALSE;
@ -104,7 +103,7 @@ IteratorNext(JSContext *cx, uintN argc, jsval *vp)
*vp = STRING_TO_JSVAL(str);
} else {
// We need to return an [id, value] pair.
if (!OBJ_GET_PROPERTY(cx, STOBJ_GET_PARENT(obj), id, &v)) {
if (!JS_GetPropertyById(cx, STOBJ_GET_PARENT(obj), id, &v)) {
return JS_FALSE;
}
@ -205,48 +204,23 @@ XPCWrapper::AddProperty(JSContext *cx, JSObject *wrapperObj,
return JS_FALSE;
}
JSProperty *prop;
JSObject *wrapperObjp;
if (!OBJ_LOOKUP_PROPERTY(cx, wrapperObj, interned_id, &wrapperObjp, &prop)) {
return JS_FALSE;
}
NS_ASSERTION(prop && OBJ_IS_NATIVE(wrapperObjp),
"What weird wrapper are we using?");
JSBool isXOW = (STOBJ_GET_CLASS(wrapperObj) == &sXPC_XOW_JSClass.base);
JSObject *wrapperObjp;
uintN attrs = JSPROP_ENUMERATE;
JSPropertyOp getter = nsnull;
JSPropertyOp setter = nsnull;
jsval v = *vp;
if (isXOW) {
JSScopeProperty *sprop = reinterpret_cast<JSScopeProperty *>(prop);
attrs = sprop->attrs;
if (attrs & JSPROP_GETTER) {
getter = sprop->getter;
}
if (attrs & JSPROP_SETTER) {
setter = sprop->setter;
}
if (SPROP_HAS_VALID_SLOT(sprop, OBJ_SCOPE(wrapperObjp))) {
v = OBJ_GET_SLOT(cx, wrapperObjp, sprop->slot);
}
if (!GetPropertyAttrs(cx, wrapperObj, interned_id, &wrapperObjp, isXOW,
JSRESOLVE_QUALIFIED, &attrs, &getter, &setter, vp)) {
return JS_FALSE;
}
OBJ_DROP_PROPERTY(cx, wrapperObjp, prop);
NS_ASSERTION(wrapperObjp == wrapperObj,
"What weird wrapper are we using?");
const uintN interesting_attrs = isXOW
? (JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT |
JSPROP_SHARED |
JSPROP_GETTER |
JSPROP_SETTER)
: JSPROP_ENUMERATE;
return OBJ_DEFINE_PROPERTY(cx, innerObj, interned_id, v, getter,
setter, (attrs & interesting_attrs), nsnull);
return DefineProperty(cx, innerObj, interned_id, isXOW, *vp,
getter, setter, attrs);
}
// static
@ -287,23 +261,23 @@ XPCWrapper::Enumerate(JSContext *cx, JSObject *wrapperObj, JSObject *innerObj)
for (jsint i = 0, n = ida->length; i < n; i++) {
JSObject *pobj;
JSProperty *prop;
// Let OBJ_LOOKUP_PROPERTY, in particular our NewResolve hook,
// figure out whether this id should be reflected.
ok = OBJ_LOOKUP_PROPERTY(cx, wrapperObj, ida->vector[i], &pobj, &prop);
// Note: v doesn't need to be rooted because it will be read out of a
// rooted object's slots.
jsval v = JSVAL_VOID;
// Let our NewResolve hook figure out whether this id should be reflected.
ok = JS_LookupPropertyWithFlagsById(cx, wrapperObj, ida->vector[i],
JSRESOLVE_QUALIFIED, &pobj, &v);
if (!ok) {
break;
}
if (prop) {
OBJ_DROP_PROPERTY(cx, pobj, prop);
}
if (pobj != wrapperObj) {
ok = OBJ_DEFINE_PROPERTY(cx, wrapperObj, ida->vector[i], JSVAL_VOID,
nsnull, nsnull, JSPROP_ENUMERATE | JSPROP_SHARED,
nsnull);
if (pobj && pobj != wrapperObj) {
// If the resolution actually happened on a different object, define the
// property here so that we're sure that enumeration picks it up.
ok = JS_DefinePropertyById(cx, wrapperObj, ida->vector[i], JSVAL_VOID,
nsnull, nsnull, JSPROP_ENUMERATE | JSPROP_SHARED);
}
if (!ok) {
@ -329,55 +303,34 @@ XPCWrapper::NewResolve(JSContext *cx, JSObject *wrapperObj,
return JS_FALSE;
}
JSProperty *prop;
JSBool isXOW = (STOBJ_GET_CLASS(wrapperObj) == &sXPC_XOW_JSClass.base);
JSObject *innerObjp;
if (!OBJ_LOOKUP_PROPERTY(cx, innerObj, interned_id, &innerObjp, &prop)) {
uintN attrs = JSPROP_ENUMERATE;
JSPropertyOp getter = nsnull;
JSPropertyOp setter = nsnull;
if (!GetPropertyAttrs(cx, innerObj, interned_id, &innerObjp, isXOW, flags,
&attrs, &getter, &setter, &v)) {
return JS_FALSE;
}
if (!prop) {
if (!innerObjp) {
// Nothing to define.
return JS_TRUE;
}
JSBool isXOW = (STOBJ_GET_CLASS(wrapperObj) == &sXPC_XOW_JSClass.base);
uintN attrs = JSPROP_ENUMERATE;
JSPropertyOp getter = nsnull;
JSPropertyOp setter = nsnull;
if (isXOW && OBJ_IS_NATIVE(innerObjp)) {
JSScopeProperty *sprop = reinterpret_cast<JSScopeProperty *>(prop);
attrs = sprop->attrs;
if (attrs & JSPROP_GETTER) {
getter = sprop->getter;
}
if (attrs & JSPROP_SETTER) {
setter = sprop->setter;
}
if (preserveVal && SPROP_HAS_VALID_SLOT(sprop, OBJ_SCOPE(innerObjp))) {
v = OBJ_GET_SLOT(cx, innerObjp, sprop->slot);
}
if (!preserveVal) {
v = JSVAL_VOID;
}
OBJ_DROP_PROPERTY(cx, innerObjp, prop);
jsval oldSlotVal;
if (!::JS_GetReservedSlot(cx, wrapperObj, sResolvingSlot, &oldSlotVal) ||
!::JS_SetReservedSlot(cx, wrapperObj, sResolvingSlot, JSVAL_TRUE)) {
return JS_FALSE;
}
const uintN interesting_attrs = isXOW
? (JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT |
JSPROP_SHARED |
JSPROP_GETTER |
JSPROP_SETTER)
: JSPROP_ENUMERATE;
JSBool ok = OBJ_DEFINE_PROPERTY(cx, wrapperObj, interned_id, v, getter,
setter, (attrs & interesting_attrs), nsnull);
JSBool ok = DefineProperty(cx, wrapperObj, interned_id, isXOW, v,
getter, setter, attrs);
if (ok && (ok = ::JS_SetReservedSlot(cx, wrapperObj, sResolvingSlot,
oldSlotVal))) {
@ -822,3 +775,65 @@ XPCWrapper::NativeToString(JSContext *cx, XPCWrappedNative *wrappedNative,
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
// 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)
{
// NB: All parameters must be initialized by this point.
if (!JS_LookupPropertyWithFlagsById(cx, obj, interned_id, flags,
objp, vp)) {
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
? (JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT |
JSPROP_SHARED |
JSPROP_GETTER |
JSPROP_SETTER)
: JSPROP_ENUMERATE;
return JS_DefinePropertyById(cx, obj, interned_id, v, getter, setter,
(attrs & interesting_attrs));
}

View File

@ -331,6 +331,29 @@ public:
static JSBool NativeToString(JSContext *cx, XPCWrappedNative *wrappedNative,
uintN argc, jsval *argv, jsval *rval,
JSBool isNativeWrapper);
private:
/**
* Looks up a property on obj. If it exists, then the parameters are filled
* in with useful values.
*
* 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);
};

View File

@ -49,7 +49,6 @@
#include "nsHashKeys.h"
#include "jsatom.h"
#include "jsfun.h"
#include "jsobj.h"
#include "jsscript.h"
#include "nsThreadUtilsInternal.h"
#include "dom_quickstubs.h"

View File

@ -366,13 +366,12 @@ nsXPCComponents_Interfaces::NewResolve(nsIXPConnectWrappedNative *wrapper,
*objp = obj;
*_retval = JS_ValueToId(cx, id, &idid) &&
OBJ_DEFINE_PROPERTY(cx, obj, idid,
OBJECT_TO_JSVAL(idobj),
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT,
nsnull);
JS_DefinePropertyById(cx, obj, idid,
OBJECT_TO_JSVAL(idobj),
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT);
}
}
}
@ -707,13 +706,12 @@ nsXPCComponents_InterfacesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
*objp = obj;
*_retval = JS_ValueToId(cx, id, &idid) &&
OBJ_DEFINE_PROPERTY(cx, obj, idid,
OBJECT_TO_JSVAL(idobj),
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT,
nsnull);
JS_DefinePropertyById(cx, obj, idid,
OBJECT_TO_JSVAL(idobj),
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT);
}
}
}
@ -1001,13 +999,12 @@ nsXPCComponents_Classes::NewResolve(nsIXPConnectWrappedNative *wrapper,
*objp = obj;
*_retval = JS_ValueToId(cx, id, &idid) &&
OBJ_DEFINE_PROPERTY(cx, obj, idid,
OBJECT_TO_JSVAL(idobj),
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT,
nsnull);
JS_DefinePropertyById(cx, obj, idid,
OBJECT_TO_JSVAL(idobj),
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT);
}
}
}
@ -1273,13 +1270,12 @@ nsXPCComponents_ClassesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
*objp = obj;
*_retval = JS_ValueToId(cx, id, &idid) &&
OBJ_DEFINE_PROPERTY(cx, obj, idid,
OBJECT_TO_JSVAL(idobj),
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT,
nsnull);
JS_DefinePropertyById(cx, obj, idid,
OBJECT_TO_JSVAL(idobj),
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT);
}
}
}
@ -1501,12 +1497,11 @@ nsXPCComponents_Results::NewResolve(nsIXPConnectWrappedNative *wrapper,
*objp = obj;
if(!JS_NewNumberValue(cx, (jsdouble)rv, &val) ||
!JS_ValueToId(cx, id, &idid) ||
!OBJ_DEFINE_PROPERTY(cx, obj, idid, val,
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT,
nsnull))
!JS_DefinePropertyById(cx, obj, idid, val,
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT))
{
return NS_ERROR_UNEXPECTED;
}
@ -3963,10 +3958,9 @@ nsXPCComponents::NewResolve(nsIXPConnectWrappedNative *wrapper,
return NS_OK;
*objp = obj;
*_retval = OBJ_DEFINE_PROPERTY(cx, obj, idid, JSVAL_VOID,
nsnull, nsnull,
JSPROP_ENUMERATE | JSPROP_PERMANENT | attrs,
nsnull);
*_retval = JS_DefinePropertyById(cx, obj, idid, JSVAL_VOID, nsnull, nsnull,
JSPROP_ENUMERATE | JSPROP_PERMANENT |
attrs);
return NS_OK;
}
@ -4067,11 +4061,9 @@ nsXPCComponents::AttachNewComponentsObject(XPCCallContext& ccx,
JSObject* obj;
return NS_SUCCEEDED(wrapper->GetJSObject(&obj)) &&
obj && OBJ_DEFINE_PROPERTY(ccx,
aGlobal, id, OBJECT_TO_JSVAL(obj),
nsnull, nsnull,
JSPROP_PERMANENT | JSPROP_READONLY,
nsnull);
obj && JS_DefinePropertyById(ccx, aGlobal, id, OBJECT_TO_JSVAL(obj),
nsnull, nsnull,
JSPROP_PERMANENT | JSPROP_READONLY);
}
/* void lookupMethod (); */

View File

@ -708,15 +708,12 @@ XPCWrappedNative::SweepTearOffs()
inline JSBool
xpc_ForcePropertyResolve(JSContext* cx, JSObject* obj, jsval idval)
{
JSProperty* prop;
JSObject* obj2;
jsid id;
jsval prop;
jsid id;
if(!JS_ValueToId(cx, idval, &id) ||
!OBJ_LOOKUP_PROPERTY(cx, obj, id, &obj2, &prop))
!JS_LookupPropertyById(cx, obj, id, &prop))
return JS_FALSE;
if(prop)
OBJ_DROP_PROPERTY(cx, obj2, prop);
return JS_TRUE;
}

View File

@ -516,12 +516,9 @@ nsJSIID::NewResolve(nsIXPConnectWrappedNative *wrapper,
return NS_ERROR_OUT_OF_MEMORY;
*objp = obj;
*_retval = OBJ_DEFINE_PROPERTY(cx, obj, idid, val,
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT,
nsnull);
*_retval = JS_DefinePropertyById(cx, obj, idid, val, nsnull, nsnull,
JSPROP_ENUMERATE | JSPROP_READONLY |
JSPROP_PERMANENT);
}
return NS_OK;

View File

@ -38,7 +38,6 @@
* ***** END LICENSE BLOCK ***** */
#include "jsapi.h"
#include "jsobj.h"
#include "jsstr.h"
#include "jscntxt.h" /* for error messages */
#include "nsCOMPtr.h"

View File

@ -247,7 +247,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(XPCCallContext& ccx,
// check upfront for the existence of the function property
funid = mRuntime->GetStringID(XPCJSRuntime::IDX_QUERY_INTERFACE);
if(!OBJ_GET_PROPERTY(cx, jsobj, funid, &fun) || JSVAL_IS_PRIMITIVE(fun))
if(!JS_GetPropertyById(cx, jsobj, funid, &fun) || JSVAL_IS_PRIMITIVE(fun))
return nsnull;
// protect fun so that we're sure it's alive when we call it
@ -364,7 +364,7 @@ GetNamedPropertyAsVariantRaw(XPCCallContext& ccx,
nsXPTType type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));
jsval val;
return OBJ_GET_PROPERTY(ccx, aJSObj, aName, &val) &&
return JS_GetPropertyById(ccx, aJSObj, aName, &val) &&
XPCConvert::JSData2Native(ccx, aResult, val, type, JS_FALSE,
&NS_GET_IID(nsIVariant), pErr);
}
@ -1521,7 +1521,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
if(param.IsIn())
{
if(!OBJ_SET_PROPERTY(cx, out_obj,
if(!JS_SetPropertyById(cx, out_obj,
mRuntime->GetStringID(XPCJSRuntime::IDX_VALUE),
&val))
{
@ -1686,7 +1686,7 @@ pre_call_clean_up:
if(param.IsRetval())
val = result;
else if(JSVAL_IS_PRIMITIVE(stackbase[i+2]) ||
!OBJ_GET_PROPERTY(cx, JSVAL_TO_OBJECT(stackbase[i+2]),
!JS_GetPropertyById(cx, JSVAL_TO_OBJECT(stackbase[i+2]),
mRuntime->GetStringID(XPCJSRuntime::IDX_VALUE),
&val))
HANDLE_OUT_CONVERSION_FAILURE
@ -1736,7 +1736,7 @@ pre_call_clean_up:
if(param.IsRetval())
val = result;
else if(!OBJ_GET_PROPERTY(cx, JSVAL_TO_OBJECT(stackbase[i+2]),
else if(!JS_GetPropertyById(cx, JSVAL_TO_OBJECT(stackbase[i+2]),
mRuntime->GetStringID(XPCJSRuntime::IDX_VALUE),
&val))
HANDLE_OUT_CONVERSION_FAILURE

View File

@ -2155,9 +2155,9 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
"Expected either enough arguments or an optional argument");
jsval arg = i < argc ? argv[i] : JSVAL_NULL;
if(JSVAL_IS_PRIMITIVE(arg) ||
!OBJ_GET_PROPERTY(ccx, JSVAL_TO_OBJECT(arg),
rt->GetStringID(XPCJSRuntime::IDX_VALUE),
&src))
!JS_GetPropertyById(ccx, JSVAL_TO_OBJECT(arg),
rt->GetStringID(XPCJSRuntime::IDX_VALUE),
&src))
{
ThrowBadParam(NS_ERROR_XPC_NEED_OUT_OBJECT, i, ccx);
goto done;
@ -2336,7 +2336,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
"Expected either enough arguments or an optional argument");
jsval arg = i < argc ? argv[i] : JSVAL_NULL;
if(JSVAL_IS_PRIMITIVE(arg) ||
!OBJ_GET_PROPERTY(ccx, JSVAL_TO_OBJECT(arg),
!JS_GetPropertyById(ccx, JSVAL_TO_OBJECT(arg),
rt->GetStringID(XPCJSRuntime::IDX_VALUE), &src))
{
ThrowBadParam(NS_ERROR_XPC_NEED_OUT_OBJECT, i, ccx);
@ -2534,7 +2534,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
{
// we actually assured this before doing the invoke
NS_ASSERTION(JSVAL_IS_OBJECT(argv[i]), "out var is not object");
if(!OBJ_SET_PROPERTY(ccx, JSVAL_TO_OBJECT(argv[i]),
if(!JS_SetPropertyById(ccx, JSVAL_TO_OBJECT(argv[i]),
rt->GetStringID(XPCJSRuntime::IDX_VALUE), &v))
{
ThrowBadParam(NS_ERROR_XPC_CANT_SET_OUT_VAL, i, ccx);

View File

@ -166,8 +166,8 @@ GetDoubleWrappedJSObject(XPCCallContext& ccx, XPCWrappedNative* wrapper)
GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT);
jsval val;
if(OBJ_GET_PROPERTY(ccx, mainObj, id,
&val) && !JSVAL_IS_PRIMITIVE(val))
if(JS_GetPropertyById(ccx, mainObj, id, &val) &&
!JSVAL_IS_PRIMITIVE(val))
{
obj = JSVAL_TO_OBJECT(val);
}
@ -311,11 +311,10 @@ DefinePropertyIfFound(XPCCallContext& ccx,
AutoResolveName arn(ccx, idval);
if(resolved)
*resolved = JS_TRUE;
return OBJ_DEFINE_PROPERTY(ccx, obj, id,
OBJECT_TO_JSVAL(JS_GetFunctionObject(fun)),
nsnull, nsnull,
propFlags & ~JSPROP_ENUMERATE,
nsnull);
return JS_DefinePropertyById(ccx, obj, id,
OBJECT_TO_JSVAL(JS_GetFunctionObject(fun)),
nsnull, nsnull,
propFlags & ~JSPROP_ENUMERATE);
}
}
// This *might* be a tearoff name that is not yet part of our
@ -341,10 +340,9 @@ DefinePropertyIfFound(XPCCallContext& ccx,
if(resolved)
*resolved = JS_TRUE;
return JS_ValueToId(ccx, idval, &id) &&
OBJ_DEFINE_PROPERTY(ccx, obj, id, OBJECT_TO_JSVAL(jso),
nsnull, nsnull,
propFlags & ~JSPROP_ENUMERATE,
nsnull);
JS_DefinePropertyById(ccx, obj, id, OBJECT_TO_JSVAL(jso),
nsnull, nsnull,
propFlags & ~JSPROP_ENUMERATE);
}
}
@ -377,10 +375,10 @@ DefinePropertyIfFound(XPCCallContext& ccx,
AutoResolveName arn(ccx, idval);
if(resolved)
*resolved = JS_TRUE;
return OBJ_DEFINE_PROPERTY(ccx, obj, id, JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
nsnull,
propFlags, nsnull);
return JS_DefinePropertyById(ccx, obj, id, JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp,
funobj),
nsnull, propFlags);
}
#ifdef XPC_IDISPATCH_SUPPORT
@ -413,10 +411,9 @@ DefinePropertyIfFound(XPCCallContext& ccx,
if(resolved)
*resolved = JS_TRUE;
return JS_ValueToId(ccx, idval, &id) &&
OBJ_DEFINE_PROPERTY(ccx, obj, id, OBJECT_TO_JSVAL(jso),
nsnull, nsnull,
propFlags & ~JSPROP_ENUMERATE,
nsnull);
JS_DefinePropertyById(ccx, obj, id, OBJECT_TO_JSVAL(jso),
nsnull, nsnull,
propFlags & ~JSPROP_ENUMERATE);
}
if(resolved)
*resolved = JS_FALSE;
@ -431,8 +428,8 @@ DefinePropertyIfFound(XPCCallContext& ccx,
*resolved = JS_TRUE;
return member->GetConstantValue(ccx, iface, &val) &&
JS_ValueToId(ccx, idval, &id) &&
OBJ_DEFINE_PROPERTY(ccx, obj, id, val, nsnull, nsnull,
propFlags, nsnull);
JS_DefinePropertyById(ccx, obj, id, val, nsnull, nsnull,
propFlags);
}
if(idval == rt->GetStringJSVal(XPCJSRuntime::IDX_TO_STRING) ||
@ -463,8 +460,8 @@ DefinePropertyIfFound(XPCCallContext& ccx,
if(resolved)
*resolved = JS_TRUE;
return JS_ValueToId(ccx, idval, &id) &&
OBJ_DEFINE_PROPERTY(ccx, obj, id, funval, nsnull, nsnull,
propFlags, nsnull);
JS_DefinePropertyById(ccx, obj, id, funval, nsnull, nsnull,
propFlags);
}
// else...
@ -484,10 +481,10 @@ DefinePropertyIfFound(XPCCallContext& ccx,
JSObject* funobj = JSVAL_TO_OBJECT(funval);
return JS_ValueToId(ccx, idval, &id) &&
OBJ_DEFINE_PROPERTY(ccx, obj, id, JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
propFlags, nsnull);
JS_DefinePropertyById(ccx, obj, id, JSVAL_VOID,
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj),
propFlags);
}
/***************************************************************************/

View File

@ -265,9 +265,9 @@ XPCWrappedNativeScope::SetGlobal(XPCCallContext& ccx, JSObject* aGlobal)
jsid idFun = mRuntime->GetStringID(XPCJSRuntime::IDX_FUNCTION);
jsid idProto = mRuntime->GetStringID(XPCJSRuntime::IDX_PROTOTYPE);
if(OBJ_GET_PROPERTY(ccx, aGlobal, idObj, &val) &&
if(JS_GetPropertyById(ccx, aGlobal, idObj, &val) &&
!JSVAL_IS_PRIMITIVE(val) &&
OBJ_GET_PROPERTY(ccx, JSVAL_TO_OBJECT(val), idProto, &val) &&
JS_GetPropertyById(ccx, JSVAL_TO_OBJECT(val), idProto, &val) &&
!JSVAL_IS_PRIMITIVE(val))
{
mPrototypeJSObject = JSVAL_TO_OBJECT(val);
@ -277,9 +277,9 @@ XPCWrappedNativeScope::SetGlobal(XPCCallContext& ccx, JSObject* aGlobal)
NS_ERROR("Can't get globalObject.Object.prototype");
}
if(OBJ_GET_PROPERTY(ccx, aGlobal, idFun, &val) &&
if(JS_GetPropertyById(ccx, aGlobal, idFun, &val) &&
!JSVAL_IS_PRIMITIVE(val) &&
OBJ_GET_PROPERTY(ccx, JSVAL_TO_OBJECT(val), idProto, &val) &&
JS_GetPropertyById(ccx, JSVAL_TO_OBJECT(val), idProto, &val) &&
!JSVAL_IS_PRIMITIVE(val))
{
mPrototypeJSFunction = JSVAL_TO_OBJECT(val);