Add tests for some ancient watchpoint bugs (zombie setters!) and remove a senile line of code from obj_watch. Bug 604781, r=jimb.
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 01 Mar 2012 09:01:45 -0600
changeset 88092 502b21011c3ef66c86218dd7f4687cbdc952d84f
parent 88091 e8ed99cae455c8bbe1f1a32cfa56398da5902fba
child 88093 3f51e7052b7d5ac73a20d8e7ac067ad4b2e397b1
push id22171
push usermak77@bonardo.net
push dateFri, 02 Mar 2012 13:56:30 +0000
treeherdermozilla-central@343ec916dfd5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs604781
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Add tests for some ancient watchpoint bugs (zombie setters!) and remove a senile line of code from obj_watch. Bug 604781, r=jimb.
js/src/jsobj.cpp
js/src/tests/js1_8_5/extensions/jstests.list
js/src/tests/js1_8_5/extensions/regress-604781-1.js
js/src/tests/js1_8_5/extensions/regress-604781-2.js
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -1183,56 +1183,54 @@ obj_watch_handler(JSContext *cx, JSObjec
     return Invoke(cx, ObjectValue(*obj), ObjectOrNullValue(callable), ArrayLength(argv), argv, nvp);
 }
 
 static JSBool
 obj_watch(JSContext *cx, unsigned argc, Value *vp)
 {
     if (argc <= 1) {
         js_ReportMissingArg(cx, *vp, 1);
-        return JS_FALSE;
+        return false;
     }
 
     JSObject *callable = js_ValueToCallableObject(cx, &vp[3], 0);
     if (!callable)
-        return JS_FALSE;
+        return false;
 
     jsid propid;
     if (!ValueToId(cx, vp[2], &propid))
-        return JS_FALSE;
+        return false;
 
     JSObject *obj = ToObject(cx, &vp[1]);
     if (!obj)
         return false;
 
     Value tmp;
     unsigned attrs;
     if (!CheckAccess(cx, obj, propid, JSACC_WATCH, &tmp, &attrs))
-        return JS_FALSE;
+        return false;
 
     vp->setUndefined();
 
-    if (attrs & JSPROP_READONLY)
-        return JS_TRUE;
     if (obj->isDenseArray() && !obj->makeDenseArraySlow(cx))
-        return JS_FALSE;
+        return false;
     return JS_SetWatchPoint(cx, obj, propid, obj_watch_handler, callable);
 }
 
 static JSBool
 obj_unwatch(JSContext *cx, unsigned argc, Value *vp)
 {
     JSObject *obj = ToObject(cx, &vp[1]);
     if (!obj)
         return false;
     vp->setUndefined();
     jsid id;
     if (argc != 0) {
         if (!ValueToId(cx, vp[2], &id))
-            return JS_FALSE;
+            return false;
     } else {
         id = JSID_VOID;
     }
     return JS_ClearWatchPoint(cx, obj, id, NULL, NULL);
 }
 
 #endif /* JS_HAS_OBJ_WATCHPOINT */
 
--- a/js/src/tests/js1_8_5/extensions/jstests.list
+++ b/js/src/tests/js1_8_5/extensions/jstests.list
@@ -29,16 +29,18 @@ skip-if(!xulRuntime.shell) script clone-
 skip-if(!xulRuntime.shell) script clone-forge.js
 skip-if(!xulRuntime.shell) script clone-complex-object.js
 script set-property-non-extensible.js
 script recursion.js
 script findReferences-01.js
 script findReferences-02.js
 script findReferences-03.js
 script findReferences-04.js
+script regress-604781-1.js
+script regress-604781-2.js
 script regress-627859.js
 script regress-627984-1.js
 script regress-627984-2.js
 script regress-627984-3.js
 script regress-627984-4.js
 script regress-627984-5.js
 script regress-627984-6.js
 script regress-627984-7.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/js1_8_5/extensions/regress-604781-1.js
@@ -0,0 +1,24 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+var watcherCount, setterCount;
+function watcher(id, oldval, newval) { watcherCount++; return newval; }
+function setter(newval) { setterCount++; }
+
+var p = { set x(v) { setter(v); } };
+p.watch('x', watcher);
+
+watcherCount = setterCount = 0;
+p.x = 2;
+assertEq(setterCount, 1);
+assertEq(watcherCount, 1);
+
+var o = Object.defineProperty({}, 'x', { set:setter, enumerable:true, configurable:true });
+o.watch('x', watcher);
+
+watcherCount = setterCount = 0;
+o.x = 2;
+assertEq(setterCount, 1);
+assertEq(watcherCount, 1);
+
+reportCompare(0, 0, 'ok');
new file mode 100644
--- /dev/null
+++ b/js/src/tests/js1_8_5/extensions/regress-604781-2.js
@@ -0,0 +1,13 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+var log;
+function watcher(id, old, newval) { log += 'watcher'; return newval; }
+var o = { set x(v) { log += 'setter'; } };
+o.watch('x', watcher);
+Object.defineProperty(o, 'x', {value: 3, writable: true});
+log = '';
+o.x = 3;
+assertEq(log, 'watcher');
+
+reportCompare(0, 0, 'ok');