From a3a94a3484ed3423dde368f328ff2bebc1ffc1f9 Mon Sep 17 00:00:00 2001 From: Igor Bukanov Date: Thu, 17 Jun 2010 14:32:26 +0200 Subject: [PATCH] bug 572411 - removal of JSObjectOps::checkAccess. r=mrbkap --- js/src/jsapi.cpp | 2 +- js/src/jsarray.cpp | 2 -- js/src/jsdbgapi.cpp | 2 +- js/src/jsobj.cpp | 58 ++++++++++++++++++----------------------- js/src/jsobj.h | 14 +++++----- js/src/jsops.cpp | 2 +- js/src/jsproxy.cpp | 2 -- js/src/jsprvtd.h | 9 ------- js/src/jspubtd.h | 6 ----- js/src/jstypedarray.cpp | 1 - js/src/jsxml.cpp | 1 - 11 files changed, 34 insertions(+), 65 deletions(-) diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 2ad5b8e5658..000cd72d57a 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -3905,7 +3905,7 @@ JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, jsval *vp, uintN *attrsp) { CHECK_REQUEST(cx); - return obj->checkAccess(cx, id, mode, vp, attrsp); + return CheckAccess(cx, obj, id, mode, vp, attrsp); } #ifdef JS_THREADSAFE diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index 5125c7e7dcb..92e09353c59 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -839,7 +839,6 @@ static JSObjectOps js_SlowArrayObjectOps = { js_DeleteProperty, js_DefaultValue, js_Enumerate, - js_CheckAccess, array_typeOf, js_TraceObject, NULL, /* thisObject */ @@ -1097,7 +1096,6 @@ JSObjectOps js_ArrayObjectOps = { array_deleteProperty, js_DefaultValue, js_Enumerate, - js_CheckAccess, array_typeOf, array_trace, NULL, /* thisObject */ diff --git a/js/src/jsdbgapi.cpp b/js/src/jsdbgapi.cpp index 65c8d0cc781..acbdc5a8f05 100644 --- a/js/src/jsdbgapi.cpp +++ b/js/src/jsdbgapi.cpp @@ -814,7 +814,7 @@ JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval idval, * If, by unwrapping and innerizing, we changed the object, check * again to make sure that we're allowed to set a watch point. */ - if (origobj != obj && !obj->checkAccess(cx, propid, JSACC_WATCH, &v, &attrs)) + if (origobj != obj && !CheckAccess(cx, obj, propid, JSACC_WATCH, &v, &attrs)) return JS_FALSE; if (!obj->isNative()) { diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 91883629a10..5ac7f8c4856 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -115,7 +115,6 @@ JS_FRIEND_DATA(JSObjectOps) js_ObjectOps = { js_DeleteProperty, js_DefaultValue, js_Enumerate, - js_CheckAccess, js_TypeOf, js_TraceObject, NULL, /* thisObject */ @@ -151,10 +150,10 @@ obj_getProto(JSContext *cx, JSObject *obj, jsid id, jsval *vp) { JS_ASSERT(id == INT_TO_JSID(JSSLOT_PROTO)); - /* Let obj->checkAccess get the slot's value, based on the access mode. */ + /* Let CheckAccess get the slot's value, based on the access mode. */ uintN attrs; id = ATOM_TO_JSID(cx->runtime->atomState.protoAtom); - return obj->checkAccess(cx, id, JSACC_PROTO, vp, &attrs); + return CheckAccess(cx, obj, id, JSACC_PROTO, vp, &attrs); } static JSBool @@ -179,7 +178,7 @@ obj_setProto(JSContext *cx, JSObject *obj, jsid id, jsval *vp) uintN attrs; id = ATOM_TO_JSID(cx->runtime->atomState.protoAtom); - if (!obj->checkAccess(cx, id, JSAccessMode(JSACC_PROTO|JSACC_WRITE), vp, &attrs)) + if (!CheckAccess(cx, obj, id, JSAccessMode(JSACC_PROTO|JSACC_WRITE), vp, &attrs)) return JS_FALSE; return js_SetProtoOrParent(cx, obj, JSSLOT_PROTO, pobj, JS_TRUE); @@ -1439,7 +1438,7 @@ obj_watch(JSContext *cx, uintN argc, jsval *vp) return JS_FALSE; obj = JS_THIS_OBJECT(cx, vp); - if (!obj || !obj->checkAccess(cx, propid, JSACC_WATCH, &value, &attrs)) + if (!obj || !CheckAccess(cx, obj, propid, JSACC_WATCH, &value, &attrs)) return JS_FALSE; *vp = JSVAL_VOID; @@ -1670,7 +1669,7 @@ js_obj_defineGetter(JSContext *cx, uintN argc, jsval *vp) * Getters and setters are just like watchpoints from an access * control point of view. */ - if (!obj->checkAccess(cx, id, JSACC_WATCH, &junk, &attrs)) + if (!CheckAccess(cx, obj, id, JSACC_WATCH, &junk, &attrs)) return JS_FALSE; *vp = JSVAL_VOID; return obj->defineProperty(cx, id, JSVAL_VOID, @@ -1703,7 +1702,7 @@ js_obj_defineSetter(JSContext *cx, uintN argc, jsval *vp) * Getters and setters are just like watchpoints from an access * control point of view. */ - if (!obj->checkAccess(cx, id, JSACC_WATCH, &junk, &attrs)) + if (!CheckAccess(cx, obj, id, JSACC_WATCH, &junk, &attrs)) return JS_FALSE; *vp = JSVAL_VOID; return obj->defineProperty(cx, id, JSVAL_VOID, @@ -1784,8 +1783,8 @@ obj_getPrototypeOf(JSContext *cx, uintN argc, jsval *vp) } obj = JSVAL_TO_OBJECT(vp[2]); - return obj->checkAccess(cx, ATOM_TO_JSID(cx->runtime->atomState.protoAtom), - JSACC_PROTO, vp, &attrs); + return CheckAccess(cx, obj, ATOM_TO_JSID(cx->runtime->atomState.protoAtom), + JSACC_PROTO, vp, &attrs); } extern JSBool @@ -2130,8 +2129,7 @@ DefinePropertyOnObject(JSContext *cx, JSObject *obj, const PropertyDescriptor &d */ jsval dummy; uintN dummyAttrs; - JS_ASSERT(obj->map->ops->checkAccess == js_CheckAccess); - if (!js_CheckAccess(cx, obj, desc.id, JSACC_WATCH, &dummy, &dummyAttrs)) + if (!CheckAccess(cx, obj, desc.id, JSACC_WATCH, &dummy, &dummyAttrs)) return JS_FALSE; return js_DefineProperty(cx, obj, desc.id, JSVAL_VOID, @@ -2332,8 +2330,7 @@ DefinePropertyOnObject(JSContext *cx, JSObject *obj, const PropertyDescriptor &d * control point of view. */ jsval dummy; - JS_ASSERT(obj2->map->ops->checkAccess == js_CheckAccess); - if (!js_CheckAccess(cx, obj2, desc.id, JSACC_WATCH, &dummy, &attrs)) { + if (!CheckAccess(cx, obj2, desc.id, JSACC_WATCH, &dummy, &attrs)) { obj2->dropProperty(cx, current); return JS_FALSE; } @@ -2955,13 +2952,6 @@ with_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, return obj->getProto()->enumerate(cx, enum_op, statep, idp); } -static JSBool -with_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, - jsval *vp, uintN *attrsp) -{ - return obj->getProto()->checkAccess(cx, id, mode, vp, attrsp); -} - static JSType with_TypeOf(JSContext *cx, JSObject *obj) { @@ -2985,7 +2975,6 @@ JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps = { with_DeleteProperty, with_DefaultValue, with_Enumerate, - with_CheckAccess, with_TypeOf, js_TraceObject, with_ThisObject, @@ -5426,9 +5415,11 @@ js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, jsval *statep, j return true; } +namespace js { + JSBool -js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, - jsval *vp, uintN *attrsp) +CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, + jsval *vp, uintN *attrsp) { JSBool writing; JSObject *pobj; @@ -5438,6 +5429,9 @@ js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, JSSecurityCallbacks *callbacks; JSCheckAccessOp check; + while (JS_UNLIKELY(obj->getClass() == &js_WithClass)) + obj = obj->getProto(); + writing = (mode & JSACC_WRITE) != 0; switch (mode & JSACC_TYPEMASK) { case JSACC_PROTO: @@ -5466,15 +5460,11 @@ js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, } if (!pobj->isNative()) { - /* Avoid diverging for non-natives that reuse js_CheckAccess. */ - if (pobj->map->ops->checkAccess == js_CheckAccess) { - if (!writing) { - *vp = JSVAL_VOID; - *attrsp = 0; - } - break; + if (!writing) { + *vp = JSVAL_VOID; + *attrsp = 0; } - return pobj->checkAccess(cx, id, mode, vp, attrsp); + break; } sprop = (JSScopeProperty *)prop; @@ -5508,6 +5498,8 @@ js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, return !check || check(cx, pobj, ID_TO_VALUE(id), mode, vp); } +} + JSType js_TypeOf(JSContext *cx, JSObject *obj) { @@ -5777,7 +5769,7 @@ CheckCtorGetAccess(JSContext *cx, JSObject *obj, jsval id, jsval *vp) atom = cx->runtime->atomState.constructorAtom; JS_ASSERT(id == ATOM_TO_JSID(atom)); - return obj->checkAccess(cx, ATOM_TO_JSID(atom), JSACC_READ, vp, &attrs); + return CheckAccess(cx, obj, ATOM_TO_JSID(atom), JSACC_READ, vp, &attrs); } static JSBool @@ -5788,7 +5780,7 @@ CheckCtorSetAccess(JSContext *cx, JSObject *obj, jsval id, jsval *vp) atom = cx->runtime->atomState.constructorAtom; JS_ASSERT(id == ATOM_TO_JSID(atom)); - return obj->checkAccess(cx, ATOM_TO_JSID(atom), JSACC_WRITE, vp, &attrs); + return CheckAccess(cx, obj, ATOM_TO_JSID(atom), JSACC_WRITE, vp, &attrs); } JSBool diff --git a/js/src/jsobj.h b/js/src/jsobj.h index c308e01288a..eed26a657af 100644 --- a/js/src/jsobj.h +++ b/js/src/jsobj.h @@ -161,7 +161,6 @@ struct JSObjectOps { JSPropertyIdOp deleteProperty; JSConvertOp defaultValue; JSNewEnumerateOp enumerate; - JSCheckAccessIdOp checkAccess; JSTypeOfOp typeOf; JSTraceOp trace; @@ -679,11 +678,6 @@ struct JSObject { return map->ops->enumerate(cx, this, op, statep, idp); } - JSBool checkAccess(JSContext *cx, jsid id, JSAccessMode mode, jsval *vp, - uintN *attrsp) { - return map->ops->checkAccess(cx, this, id, mode, vp, attrsp); - } - JSType typeOf(JSContext *cx) { return map->ops->typeOf(cx, this); } @@ -1210,9 +1204,13 @@ extern JSBool js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, jsval *statep, jsid *idp); +namespace js { + extern JSBool -js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, - jsval *vp, uintN *attrsp); +CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, + jsval *vp, uintN *attrsp); + +} extern JSType js_TypeOf(JSContext *cx, JSObject *obj); diff --git a/js/src/jsops.cpp b/js/src/jsops.cpp index 78cd9de578d..08d51cb1b89 100644 --- a/js/src/jsops.cpp +++ b/js/src/jsops.cpp @@ -3154,7 +3154,7 @@ BEGIN_CASE(JSOP_SETTER) * Getters and setters are just like watchpoints from an access control * point of view. */ - if (!obj->checkAccess(cx, id, JSACC_WATCH, &rtmp, &attrs)) + if (!CheckAccess(cx, obj, id, JSACC_WATCH, &rtmp, &attrs)) goto error; if (op == JSOP_GETTER) { diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp index 6d8e199179f..79e3f24624d 100644 --- a/js/src/jsproxy.cpp +++ b/js/src/jsproxy.cpp @@ -902,7 +902,6 @@ JSObjectOps js_ObjectProxyObjectOps = { proxy_DeleteProperty, js_DefaultValue, js_Enumerate, - js_CheckAccess, proxy_TypeOf_obj, proxy_TraceObject, NULL, /* thisObject */ @@ -997,7 +996,6 @@ JSObjectOps js_FunctionProxyObjectOps = { proxy_DeleteProperty, js_DefaultValue, js_Enumerate, - js_CheckAccess, proxy_TypeOf_fun, proxy_TraceObject, NULL, /* thisObject */ diff --git a/js/src/jsprvtd.h b/js/src/jsprvtd.h index 9ec459fe002..492a1c13093 100644 --- a/js/src/jsprvtd.h +++ b/js/src/jsprvtd.h @@ -362,15 +362,6 @@ typedef JSBool typedef JSBool (* JSAttributesOp)(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp); -/* - * JSObjectOps.checkAccess type: check whether obj[id] may be accessed per - * mode, returning false on error/exception, true on success with obj[id]'s - * last-got value in *vp, and its attributes in *attrsp. - */ -typedef JSBool -(* JSCheckAccessIdOp)(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, - jsval *vp, uintN *attrsp); - /* * The following determines whether JS_EncodeCharacters and JS_DecodeBytes * treat char[] as utf-8 or simply as bytes that need to be inflated/deflated. diff --git a/js/src/jspubtd.h b/js/src/jspubtd.h index 8a4620cc104..5b7a32db832 100644 --- a/js/src/jspubtd.h +++ b/js/src/jspubtd.h @@ -310,12 +310,6 @@ typedef JSObjectOps * * returning false on error/exception, true on success with obj[id]'s last-got * value in *vp, and its attributes in *attrsp. As for JSPropertyOp above, id * is either a string or an int jsval. - * - * See JSCheckAccessIdOp, below, for the JSObjectOps counterpart, which takes - * a jsid (a tagged int or aligned, unique identifier pointer) rather than a - * jsval. The native js_ObjectOps.checkAccess simply forwards to the object's - * clasp->checkAccess, so that both JSClass and JSObjectOps implementors may - * specialize access checks. */ typedef JSBool (* JSCheckAccessOp)(JSContext *cx, JSObject *obj, jsval id, JSAccessMode mode, diff --git a/js/src/jstypedarray.cpp b/js/src/jstypedarray.cpp index 415a92e8d99..2e6d57e33e7 100644 --- a/js/src/jstypedarray.cpp +++ b/js/src/jstypedarray.cpp @@ -1315,7 +1315,6 @@ template<> JSObjectOps _typedArray::fastObjectOps = { \ _typedArray::obj_deleteProperty, \ js_DefaultValue, \ _typedArray::obj_enumerate, \ - js_CheckAccess, \ _typedArray::obj_typeOf, \ _typedArray::obj_trace, \ NULL, /* thisObject */ \ diff --git a/js/src/jsxml.cpp b/js/src/jsxml.cpp index 5220dcb3046..c29b4a9b4d0 100644 --- a/js/src/jsxml.cpp +++ b/js/src/jsxml.cpp @@ -5042,7 +5042,6 @@ JS_FRIEND_DATA(JSObjectOps) js_XMLObjectOps = { xml_deleteProperty, xml_defaultValue, xml_enumerate, - js_CheckAccess, xml_typeOf, js_TraceObject, NULL, /* thisObject */