Report an error when trying to watch an E4X property with a qualified name, rather than set a watchpoint that will not hit reliably. Bug 691746, r=jimb.
authorJason Orendorff <jorendorff@mozilla.com>
Mon, 24 Oct 2011 10:51:52 -0500
changeset 79141 58563c49a53197379a83eb81233d11b655cfd082
parent 79140 9cc812d5d96a7778bae9c130357eb006c67bca66
child 79142 78e519331f400178965ac51e875bd805736d0043
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjimb
bugs691746
milestone10.0a1
Report an error when trying to watch an E4X property with a qualified name, rather than set a watchpoint that will not hit reliably. Bug 691746, r=jimb.
js/src/js.msg
js/src/jsdbgapi.cpp
js/src/jswatchpoint.cpp
js/src/tests/js1_8_5/extensions/jstests.list
js/src/tests/js1_8_5/extensions/regress-691746.js
--- a/js/src/js.msg
+++ b/js/src/js.msg
@@ -365,8 +365,9 @@ MSG_DEF(JSMSG_DEBUG_OBJECT_WRONG_OWNER, 
 MSG_DEF(JSMSG_DEBUG_OBJECT_PROTO,     279, 0, JSEXN_TYPEERR, "Debugger.Object.prototype is not a valid Debugger.Object")
 MSG_DEF(JSMSG_DEBUG_LOOP,             280, 0, JSEXN_TYPEERR, "cannot debug an object in same compartment as debugger or a compartment that is already debugging the debugger")
 MSG_DEF(JSMSG_DEBUG_NOT_IDLE,         281, 0, JSEXN_ERR, "can't start debugging: a debuggee script is on the stack")
 MSG_DEF(JSMSG_DEBUG_BAD_OFFSET,       282, 0, JSEXN_TYPEERR, "invalid script offset")
 MSG_DEF(JSMSG_DEBUG_BAD_LINE,         283, 0, JSEXN_TYPEERR, "invalid line number")
 MSG_DEF(JSMSG_DEBUG_NOT_DEBUGGING,    284, 0, JSEXN_ERR, "can't set breakpoint: script global is not a debuggee")
 MSG_DEF(JSMSG_DEBUG_COMPARTMENT_MISMATCH, 285, 2, JSEXN_TYPEERR, "{0}: descriptor .{1} property is an object in a different compartment than the target object")
 MSG_DEF(JSMSG_DEBUG_NOT_SCRIPT_FRAME, 286, 0, JSEXN_ERR, "stack frame is not running JavaScript code")
+MSG_DEF(JSMSG_CANT_WATCH_PROP,        287, 0, JSEXN_TYPEERR, "properties whose names are objects can't be watched")
--- a/js/src/jsdbgapi.cpp
+++ b/js/src/jsdbgapi.cpp
@@ -292,16 +292,19 @@ JS_SetWatchPoint(JSContext *cx, JSObject
     origobj = obj;
     OBJ_TO_INNER_OBJECT(cx, obj);
     if (!obj)
         return false;
 
     AutoValueRooter idroot(cx);
     if (JSID_IS_INT(id)) {
         propid = id;
+    } else if (JSID_IS_OBJECT(id)) {
+        JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_WATCH_PROP);
+        return false;
     } else {
         if (!js_ValueToStringId(cx, IdToValue(id), &propid))
             return false;
         propid = js_CheckForStringIndex(propid);
         idroot.set(IdToValue(propid));
     }
 
     /*
@@ -323,17 +326,17 @@ JS_SetWatchPoint(JSContext *cx, JSObject
     if (!wpmap) {
         wpmap = cx->runtime->new_<WatchpointMap>();
         if (!wpmap || !wpmap->init()) {
             js_ReportOutOfMemory(cx);
             return false;
         }
         cx->compartment->watchpointMap = wpmap;
     }
-    return wpmap->watch(cx, obj, id, handler, closure);
+    return wpmap->watch(cx, obj, propid, handler, closure);
 }
 
 JS_PUBLIC_API(JSBool)
 JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id,
                    JSWatchPointHandler *handlerp, JSObject **closurep)
 {
     assertSameCompartment(cx, obj, id);
 
--- a/js/src/jswatchpoint.cpp
+++ b/js/src/jswatchpoint.cpp
@@ -79,16 +79,18 @@ WatchpointMap::init()
     return map.init();
 }
 
 bool
 WatchpointMap::watch(JSContext *cx, JSObject *obj, jsid id,
                      JSWatchPointHandler handler, JSObject *closure)
 {
     JS_ASSERT(id == js_CheckForStringIndex(id));
+    JS_ASSERT(JSID_IS_STRING(id) || JSID_IS_INT(id));
+
     obj->setWatched(cx);
     Watchpoint w;
     w.handler = handler;
     w.closure = closure;
     w.held = false;
     if (!map.put(WatchKey(obj, id), w)) {
         js_ReportOutOfMemory(cx);
         return false;
--- a/js/src/tests/js1_8_5/extensions/jstests.list
+++ b/js/src/tests/js1_8_5/extensions/jstests.list
@@ -53,8 +53,9 @@ script weakmap.js
 script regress-645160.js
 script regress-650753.js
 script regress-668438.js
 require-or(debugMode,skip) script regress-672804-1.js
 require-or(debugMode,skip) script regress-672804-2.js
 require-or(debugMode,skip) script regress-672804-3.js
 skip-if(!xulRuntime.shell) script regress-677589.js
 script regress-677924.js
+script regress-691746.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/js1_8_5/extensions/regress-691746.js
@@ -0,0 +1,11 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+var obj = {};
+try {
+    obj.watch(QName(), function () {});
+} catch (exc) {
+}
+gc();
+
+reportCompare(0, 0, 'ok');