зеркало из https://github.com/mozilla/gecko-dev.git
Add tests for some ancient watchpoint bugs (zombie setters!) and remove a senile line of code from obj_watch. Bug 604781, r=jimb.
This commit is contained in:
Родитель
c15a26719a
Коммит
36b2a186d7
|
@ -1188,16 +1188,16 @@ 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)
|
||||
|
@ -1206,14 +1206,12 @@ obj_watch(JSContext *cx, unsigned argc, Value *vp)
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -1227,7 +1225,7 @@ obj_unwatch(JSContext *cx, unsigned argc, Value *vp)
|
|||
jsid id;
|
||||
if (argc != 0) {
|
||||
if (!ValueToId(cx, vp[2], &id))
|
||||
return JS_FALSE;
|
||||
return false;
|
||||
} else {
|
||||
id = JSID_VOID;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ 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
|
||||
|
|
|
@ -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');
|
|
@ -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');
|
Загрузка…
Ссылка в новой задаче