js/src/jit-test/tests/basic/testWatchRecursion.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Test that the watch handler is not called recursively for the same object
michael@0 2 // and property.
michael@0 3 (function() {
michael@0 4 var obj1 = {}, obj2 = {};
michael@0 5 var handler_entry_count = 0;
michael@0 6 var handler_exit_count = 0;
michael@0 7
michael@0 8 obj1.watch('x', handler);
michael@0 9 obj1.watch('y', handler);
michael@0 10 obj2.watch('x', handler);
michael@0 11 obj1.x = 1;
michael@0 12 assertEq(handler_entry_count, 3);
michael@0 13 assertEq(handler_exit_count, 3);
michael@0 14
michael@0 15 function handler(id) {
michael@0 16 handler_entry_count++;
michael@0 17 assertEq(handler_exit_count, 0);
michael@0 18 switch (true) {
michael@0 19 case this === obj1 && id === "x":
michael@0 20 assertEq(handler_entry_count, 1);
michael@0 21 obj2.x = 3;
michael@0 22 assertEq(handler_exit_count, 2);
michael@0 23 break;
michael@0 24 case this === obj2 && id === "x":
michael@0 25 assertEq(handler_entry_count, 2);
michael@0 26 obj1.y = 4;
michael@0 27 assertEq(handler_exit_count, 1);
michael@0 28 break;
michael@0 29 default:
michael@0 30 assertEq(this, obj1);
michael@0 31 assertEq(id, "y");
michael@0 32 assertEq(handler_entry_count, 3);
michael@0 33
michael@0 34 // We expect no more watch handler invocations
michael@0 35 obj1.x = 5;
michael@0 36 obj1.y = 6;
michael@0 37 obj2.x = 7;
michael@0 38 assertEq(handler_exit_count, 0);
michael@0 39 break;
michael@0 40 }
michael@0 41 ++handler_exit_count;
michael@0 42 assertEq(handler_entry_count, 3);
michael@0 43 }
michael@0 44 })();
michael@0 45
michael@0 46
michael@0 47 // Test that run-away recursion in watch handlers is properly handled.
michael@0 48 (function() {
michael@0 49 var obj = {};
michael@0 50 var i = 0;
michael@0 51 try {
michael@0 52 handler();
michael@0 53 throw new Error("Unreachable");
michael@0 54 } catch(e) {
michael@0 55 assertEq(e instanceof InternalError, true);
michael@0 56 }
michael@0 57
michael@0 58 function handler() {
michael@0 59 var prop = "a" + ++i;
michael@0 60 obj.watch(prop, handler);
michael@0 61 obj[prop] = 2;
michael@0 62 }
michael@0 63 })();

mercurial