Bug 496113 - Unwrap 'with' objects before calling into getters to restore API compatibility. r=brendan
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 03 Jun 2009 16:37:44 -0700
changeset 28936 bdb423e6cab8667eef412b4aabba391950e36adc
parent 28935 56f77c5d4b8976ffa32e83c40bdcff2b0a1bbbe3
child 28937 a481f4cce93afeb753001424812224ff28b5a4f2
push id7339
push userrsayre@mozilla.com
push dateThu, 04 Jun 2009 17:30:42 +0000
treeherderautoland@b298555c111c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbrendan
bugs496113
milestone1.9.2a1pre
Bug 496113 - Unwrap 'with' objects before calling into getters to restore API compatibility. r=brendan
js/src/jsscope.h
--- a/js/src/jsscope.h
+++ b/js/src/jsscope.h
@@ -363,16 +363,24 @@ js_GetSprop(JSContext* cx, JSScopeProper
     JS_ASSERT(!SPROP_HAS_STUB_GETTER(sprop));
 
     if (sprop->attrs & JSPROP_GETTER) {
         jsval fval = js_CastAsObjectJSVal(sprop->getter);
         return js_InternalGetOrSet(cx, obj, sprop->id, fval, JSACC_READ,
                                    0, 0, vp);
     }
 
+    /*
+     * JSObjectOps is private, so we know there are only two implementations
+     * of the thisObject hook: with objects and XPConnect wrapped native
+     * objects.  XPConnect objects don't expect the hook to be called here,
+     * but with objects do.
+     */
+    if (STOBJ_GET_CLASS(obj) == &js_WithClass)
+        obj = obj->map->ops->thisObject(cx, obj);
     return sprop->getter(cx, obj, SPROP_USERID(sprop), vp);
 }
 
 static JS_INLINE JSBool
 js_SetSprop(JSContext* cx, JSScopeProperty* sprop, JSObject* obj, jsval* vp)
 {
     JS_ASSERT(!(SPROP_HAS_STUB_SETTER(sprop) &&
                 !(sprop->attrs & JSPROP_GETTER)));
@@ -383,16 +391,19 @@ js_SetSprop(JSContext* cx, JSScopeProper
                                    1, vp, vp);
     }
 
     if (sprop->attrs & JSPROP_GETTER) {
         js_ReportGetterOnlyAssignment(cx);
         return JS_FALSE;
     }
 
+    /* See the comment in js_GetSprop as to why we can check for 'with'. */
+    if (STOBJ_GET_CLASS(obj) == &js_WithClass)
+        obj = obj->map->ops->thisObject(cx, obj);
     return sprop->setter(cx, obj, SPROP_USERID(sprop), vp);
 }
 
 /* Macro for common expression to test for shared permanent attributes. */
 #define SPROP_IS_SHARED_PERMANENT(sprop)                                      \
     ((~(sprop)->attrs & (JSPROP_SHARED | JSPROP_PERMANENT)) == 0)
 
 extern JSScope *