| OLD | NEW | 
|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. | 
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without | 
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are | 
| 4 // met: | 4 // met: | 
| 5 // | 5 // | 
| 6 //     * Redistributions of source code must retain the above copyright | 6 //     * Redistributions of source code must retain the above copyright | 
| 7 //       notice, this list of conditions and the following disclaimer. | 7 //       notice, this list of conditions and the following disclaimer. | 
| 8 //     * Redistributions in binary form must reproduce the above | 8 //     * Redistributions in binary form must reproduce the above | 
| 9 //       copyright notice, this list of conditions and the following | 9 //       copyright notice, this list of conditions and the following | 
| 10 //       disclaimer in the documentation and/or other materials provided | 10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 81     observer.records = r; | 81     observer.records = r; | 
| 82     observer.callbackCount++; | 82     observer.callbackCount++; | 
| 83   }; | 83   }; | 
| 84 | 84 | 
| 85   observer.reset(); | 85   observer.reset(); | 
| 86   allObservers.push(observer); | 86   allObservers.push(observer); | 
| 87   return observer; | 87   return observer; | 
| 88 } | 88 } | 
| 89 | 89 | 
| 90 var observer = createObserver(); | 90 var observer = createObserver(); | 
|  | 91 var observer2 = createObserver(); | 
|  | 92 | 
| 91 assertEquals("function", typeof observer.callback); | 93 assertEquals("function", typeof observer.callback); | 
|  | 94 assertEquals("function", typeof observer2.callback); | 
|  | 95 | 
| 92 var obj = {}; | 96 var obj = {}; | 
| 93 | 97 | 
| 94 function frozenFunction() {} | 98 function frozenFunction() {} | 
| 95 Object.freeze(frozenFunction); | 99 Object.freeze(frozenFunction); | 
| 96 var nonFunction = {}; | 100 var nonFunction = {}; | 
| 97 var changeRecordWithAccessor = { type: 'foo' }; | 101 var changeRecordWithAccessor = { type: 'foo' }; | 
| 98 var recordCreated = false; | 102 var recordCreated = false; | 
| 99 Object.defineProperty(changeRecordWithAccessor, 'name', { | 103 Object.defineProperty(changeRecordWithAccessor, 'name', { | 
| 100   get: function() { | 104   get: function() { | 
| 101     recordCreated = true; | 105     recordCreated = true; | 
| 102     return "bar"; | 106     return "bar"; | 
| 103   }, | 107   }, | 
| 104   enumerable: true | 108   enumerable: true | 
| 105 }) | 109 }) | 
| 106 | 110 | 
| 107 | 111 | 
| 108 // Object.observe | 112 // Object.observe | 
| 109 assertThrows(function() { Object.observe("non-object", observer.callback); }, Ty
      peError); | 113 assertThrows(function() { Object.observe("non-object", observer.callback); }, Ty
      peError); | 
| 110 assertThrows(function() { Object.observe(obj, nonFunction); }, TypeError); | 114 assertThrows(function() { Object.observe(obj, nonFunction); }, TypeError); | 
| 111 assertThrows(function() { Object.observe(obj, frozenFunction); }, TypeError); | 115 assertThrows(function() { Object.observe(obj, frozenFunction); }, TypeError); | 
|  | 116 assertThrows(function() { Object.observe(obj, function() {}, 1); }, TypeError); | 
|  | 117 assertThrows(function() { Object.observe(obj, function() {}, [undefined]); }, Ty
      peError); | 
|  | 118 assertThrows(function() { Object.observe(obj, function() {}, [1]); }, TypeError)
      ; | 
|  | 119 assertThrows(function() { Object.observe(obj, function() {}, ['foo', null]); }, 
      TypeError); | 
|  | 120 assertEquals(obj, Object.observe(obj, observer.callback, ['foo', 'bar', 'baz']))
      ; | 
|  | 121 assertEquals(obj, Object.observe(obj, observer.callback, [])); | 
|  | 122 assertEquals(obj, Object.observe(obj, observer.callback, undefined)); | 
| 112 assertEquals(obj, Object.observe(obj, observer.callback)); | 123 assertEquals(obj, Object.observe(obj, observer.callback)); | 
| 113 | 124 | 
| 114 |  | 
| 115 // Object.unobserve | 125 // Object.unobserve | 
| 116 assertThrows(function() { Object.unobserve(4, observer.callback); }, TypeError); | 126 assertThrows(function() { Object.unobserve(4, observer.callback); }, TypeError); | 
| 117 assertThrows(function() { Object.unobserve(obj, nonFunction); }, TypeError); | 127 assertThrows(function() { Object.unobserve(obj, nonFunction); }, TypeError); | 
| 118 assertEquals(obj, Object.unobserve(obj, observer.callback)); | 128 assertEquals(obj, Object.unobserve(obj, observer.callback)); | 
| 119 | 129 | 
| 120 | 130 | 
| 121 // Object.getNotifier | 131 // Object.getNotifier | 
| 122 var notifier = Object.getNotifier(obj); | 132 var notifier = Object.getNotifier(obj); | 
| 123 assertSame(notifier, Object.getNotifier(obj)); | 133 assertSame(notifier, Object.getNotifier(obj)); | 
| 124 assertEquals(null, Object.getNotifier(Object.freeze({}))); | 134 assertEquals(null, Object.getNotifier(Object.freeze({}))); | 
| 125 assertFalse(notifier.hasOwnProperty('notify')); | 135 assertFalse(notifier.hasOwnProperty('notify')); | 
| 126 assertEquals([], Object.keys(notifier)); | 136 assertEquals([], Object.keys(notifier)); | 
| 127 var notifyDesc = Object.getOwnPropertyDescriptor(notifier.__proto__, 'notify'); | 137 var notifyDesc = Object.getOwnPropertyDescriptor(notifier.__proto__, 'notify'); | 
| 128 assertTrue(notifyDesc.configurable); | 138 assertTrue(notifyDesc.configurable); | 
| 129 assertTrue(notifyDesc.writable); | 139 assertTrue(notifyDesc.writable); | 
| 130 assertFalse(notifyDesc.enumerable); | 140 assertFalse(notifyDesc.enumerable); | 
| 131 assertThrows(function() { notifier.notify({}); }, TypeError); | 141 assertThrows(function() { notifier.notify({}); }, TypeError); | 
| 132 assertThrows(function() { notifier.notify({ type: 4 }); }, TypeError); | 142 assertThrows(function() { notifier.notify({ type: 4 }); }, TypeError); | 
|  | 143 | 
|  | 144 assertThrows(function() { notifier.performChange(1, function(){}); }, TypeError)
      ; | 
|  | 145 assertThrows(function() { notifier.performChange(undefined, function(){}); }, Ty
      peError); | 
|  | 146 assertThrows(function() { notifier.performChange('foo', undefined); }, TypeError
      ); | 
|  | 147 assertThrows(function() { notifier.performChange('foo', 'bar'); }, TypeError); | 
|  | 148 var testSelf = {}; | 
|  | 149 notifier.performChange('foo', function() { | 
|  | 150   assertTrue(testSelf === this); | 
|  | 151 }, testSelf); | 
|  | 152 var self = this; | 
|  | 153 notifier.performChange('foo', function() { | 
|  | 154   assertTrue(self === this); | 
|  | 155 }); | 
|  | 156 | 
| 133 var notify = notifier.notify; | 157 var notify = notifier.notify; | 
| 134 assertThrows(function() { notify.call(undefined, { type: 'a' }); }, TypeError); | 158 assertThrows(function() { notify.call(undefined, { type: 'a' }); }, TypeError); | 
| 135 assertThrows(function() { notify.call(null, { type: 'a' }); }, TypeError); | 159 assertThrows(function() { notify.call(null, { type: 'a' }); }, TypeError); | 
| 136 assertThrows(function() { notify.call(5, { type: 'a' }); }, TypeError); | 160 assertThrows(function() { notify.call(5, { type: 'a' }); }, TypeError); | 
| 137 assertThrows(function() { notify.call('hello', { type: 'a' }); }, TypeError); | 161 assertThrows(function() { notify.call('hello', { type: 'a' }); }, TypeError); | 
| 138 assertThrows(function() { notify.call(false, { type: 'a' }); }, TypeError); | 162 assertThrows(function() { notify.call(false, { type: 'a' }); }, TypeError); | 
| 139 assertThrows(function() { notify.call({}, { type: 'a' }); }, TypeError); | 163 assertThrows(function() { notify.call({}, { type: 'a' }); }, TypeError); | 
| 140 assertFalse(recordCreated); | 164 assertFalse(recordCreated); | 
| 141 notifier.notify(changeRecordWithAccessor); | 165 notifier.notify(changeRecordWithAccessor); | 
| 142 assertFalse(recordCreated);  // not observed yet | 166 assertFalse(recordCreated);  // not observed yet | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 188 reset(); | 212 reset(); | 
| 189 Object.deliverChangeRecords(observer.callback); | 213 Object.deliverChangeRecords(observer.callback); | 
| 190 observer.assertNotCalled(); | 214 observer.assertNotCalled(); | 
| 191 | 215 | 
| 192 | 216 | 
| 193 // Multiple observation has no effect. | 217 // Multiple observation has no effect. | 
| 194 reset(); | 218 reset(); | 
| 195 Object.observe(obj, observer.callback); | 219 Object.observe(obj, observer.callback); | 
| 196 Object.observe(obj, observer.callback); | 220 Object.observe(obj, observer.callback); | 
| 197 Object.getNotifier(obj).notify({ | 221 Object.getNotifier(obj).notify({ | 
| 198   type: 'foo', | 222   type: 'updated', | 
| 199 }); | 223 }); | 
| 200 Object.deliverChangeRecords(observer.callback); | 224 Object.deliverChangeRecords(observer.callback); | 
| 201 observer.assertCalled(); | 225 observer.assertCalled(); | 
| 202 | 226 | 
| 203 | 227 | 
| 204 // Observation can be stopped. | 228 // Observation can be stopped. | 
| 205 reset(); | 229 reset(); | 
| 206 Object.unobserve(obj, observer.callback); | 230 Object.unobserve(obj, observer.callback); | 
| 207 Object.getNotifier(obj).notify({ | 231 Object.getNotifier(obj).notify({ | 
| 208   type: 'foo', | 232   type: 'updated', | 
| 209 }); | 233 }); | 
| 210 Object.deliverChangeRecords(observer.callback); | 234 Object.deliverChangeRecords(observer.callback); | 
| 211 observer.assertNotCalled(); | 235 observer.assertNotCalled(); | 
| 212 | 236 | 
| 213 | 237 | 
| 214 // Multiple unobservation has no effect | 238 // Multiple unobservation has no effect | 
| 215 reset(); | 239 reset(); | 
| 216 Object.unobserve(obj, observer.callback); | 240 Object.unobserve(obj, observer.callback); | 
| 217 Object.unobserve(obj, observer.callback); | 241 Object.unobserve(obj, observer.callback); | 
| 218 Object.getNotifier(obj).notify({ | 242 Object.getNotifier(obj).notify({ | 
| 219   type: 'foo', | 243   type: 'updated', | 
| 220 }); | 244 }); | 
| 221 Object.deliverChangeRecords(observer.callback); | 245 Object.deliverChangeRecords(observer.callback); | 
| 222 observer.assertNotCalled(); | 246 observer.assertNotCalled(); | 
| 223 | 247 | 
| 224 | 248 | 
| 225 // Re-observation works and only includes changeRecords after of call. | 249 // Re-observation works and only includes changeRecords after of call. | 
| 226 reset(); | 250 reset(); | 
| 227 Object.getNotifier(obj).notify({ | 251 Object.getNotifier(obj).notify({ | 
| 228   type: 'foo', | 252   type: 'updated', | 
| 229 }); | 253 }); | 
| 230 Object.observe(obj, observer.callback); | 254 Object.observe(obj, observer.callback); | 
| 231 Object.getNotifier(obj).notify({ | 255 Object.getNotifier(obj).notify({ | 
| 232   type: 'foo', | 256   type: 'updated', | 
| 233 }); | 257 }); | 
| 234 records = undefined; | 258 records = undefined; | 
| 235 Object.deliverChangeRecords(observer.callback); | 259 Object.deliverChangeRecords(observer.callback); | 
| 236 observer.assertRecordCount(1); | 260 observer.assertRecordCount(1); | 
| 237 | 261 | 
| 238 | 262 | 
| 239 // Observing a continuous stream of changes, while itermittantly unobserving. | 263 // Observing a continuous stream of changes, while itermittantly unobserving. | 
| 240 reset(); | 264 reset(); | 
| 241 Object.observe(obj, observer.callback); | 265 Object.observe(obj, observer.callback); | 
| 242 Object.getNotifier(obj).notify({ | 266 Object.getNotifier(obj).notify({ | 
| 243   type: 'foo', | 267   type: 'updated', | 
| 244   val: 1 | 268   val: 1 | 
| 245 }); | 269 }); | 
| 246 | 270 | 
| 247 Object.unobserve(obj, observer.callback); | 271 Object.unobserve(obj, observer.callback); | 
| 248 Object.getNotifier(obj).notify({ | 272 Object.getNotifier(obj).notify({ | 
| 249   type: 'foo', | 273   type: 'updated', | 
| 250   val: 2 | 274   val: 2 | 
| 251 }); | 275 }); | 
| 252 | 276 | 
| 253 Object.observe(obj, observer.callback); | 277 Object.observe(obj, observer.callback); | 
| 254 Object.getNotifier(obj).notify({ | 278 Object.getNotifier(obj).notify({ | 
| 255   type: 'foo', | 279   type: 'updated', | 
| 256   val: 3 | 280   val: 3 | 
| 257 }); | 281 }); | 
| 258 | 282 | 
| 259 Object.unobserve(obj, observer.callback); | 283 Object.unobserve(obj, observer.callback); | 
| 260 Object.getNotifier(obj).notify({ | 284 Object.getNotifier(obj).notify({ | 
| 261   type: 'foo', | 285   type: 'updated', | 
| 262   val: 4 | 286   val: 4 | 
| 263 }); | 287 }); | 
| 264 | 288 | 
| 265 Object.observe(obj, observer.callback); | 289 Object.observe(obj, observer.callback); | 
| 266 Object.getNotifier(obj).notify({ | 290 Object.getNotifier(obj).notify({ | 
| 267   type: 'foo', | 291   type: 'updated', | 
| 268   val: 5 | 292   val: 5 | 
| 269 }); | 293 }); | 
| 270 | 294 | 
| 271 Object.unobserve(obj, observer.callback); | 295 Object.unobserve(obj, observer.callback); | 
| 272 Object.deliverChangeRecords(observer.callback); | 296 Object.deliverChangeRecords(observer.callback); | 
| 273 observer.assertCallbackRecords([ | 297 observer.assertCallbackRecords([ | 
| 274   { object: obj, type: 'foo', val: 1 }, | 298   { object: obj, type: 'updated', val: 1 }, | 
| 275   { object: obj, type: 'foo', val: 3 }, | 299   { object: obj, type: 'updated', val: 3 }, | 
| 276   { object: obj, type: 'foo', val: 5 } | 300   { object: obj, type: 'updated', val: 5 } | 
| 277 ]); | 301 ]); | 
| 278 | 302 | 
| 279 | 303 // Accept | 
|  | 304 reset(); | 
|  | 305 Object.observe(obj, observer.callback, []); | 
|  | 306 Object.getNotifier(obj).notify({ | 
|  | 307   type: 'new' | 
|  | 308 }); | 
|  | 309 Object.getNotifier(obj).notify({ | 
|  | 310   type: 'updated' | 
|  | 311 }); | 
|  | 312 Object.getNotifier(obj).notify({ | 
|  | 313   type: 'deleted' | 
|  | 314 }); | 
|  | 315 Object.getNotifier(obj).notify({ | 
|  | 316   type: 'reconfigured' | 
|  | 317 }); | 
|  | 318 Object.getNotifier(obj).notify({ | 
|  | 319   type: 'prototype' | 
|  | 320 }); | 
|  | 321 Object.deliverChangeRecords(observer.callback); | 
|  | 322 observer.assertNotCalled(); | 
|  | 323 | 
|  | 324 reset(); | 
|  | 325 Object.observe(obj, observer.callback, ['new', 'deleted', 'prototype']); | 
|  | 326 Object.getNotifier(obj).notify({ | 
|  | 327   type: 'new' | 
|  | 328 }); | 
|  | 329 Object.getNotifier(obj).notify({ | 
|  | 330   type: 'updated' | 
|  | 331 }); | 
|  | 332 Object.getNotifier(obj).notify({ | 
|  | 333   type: 'deleted' | 
|  | 334 }); | 
|  | 335 Object.getNotifier(obj).notify({ | 
|  | 336   type: 'deleted' | 
|  | 337 }); | 
|  | 338 Object.getNotifier(obj).notify({ | 
|  | 339   type: 'reconfigured' | 
|  | 340 }); | 
|  | 341 Object.getNotifier(obj).notify({ | 
|  | 342   type: 'prototype' | 
|  | 343 }); | 
|  | 344 Object.deliverChangeRecords(observer.callback); | 
|  | 345 observer.assertCallbackRecords([ | 
|  | 346   { object: obj, type: 'new' }, | 
|  | 347   { object: obj, type: 'deleted' }, | 
|  | 348   { object: obj, type: 'deleted' }, | 
|  | 349   { object: obj, type: 'prototype' } | 
|  | 350 ]); | 
|  | 351 | 
|  | 352 reset(); | 
|  | 353 Object.observe(obj, observer.callback, ['updated', 'foo']); | 
|  | 354 Object.getNotifier(obj).notify({ | 
|  | 355   type: 'new' | 
|  | 356 }); | 
|  | 357 Object.getNotifier(obj).notify({ | 
|  | 358   type: 'updated' | 
|  | 359 }); | 
|  | 360 Object.getNotifier(obj).notify({ | 
|  | 361   type: 'deleted' | 
|  | 362 }); | 
|  | 363 Object.getNotifier(obj).notify({ | 
|  | 364   type: 'foo' | 
|  | 365 }); | 
|  | 366 Object.getNotifier(obj).notify({ | 
|  | 367   type: 'bar' | 
|  | 368 }); | 
|  | 369 Object.getNotifier(obj).notify({ | 
|  | 370   type: 'foo' | 
|  | 371 }); | 
|  | 372 Object.deliverChangeRecords(observer.callback); | 
|  | 373 observer.assertCallbackRecords([ | 
|  | 374   { object: obj, type: 'updated' }, | 
|  | 375   { object: obj, type: 'foo' }, | 
|  | 376   { object: obj, type: 'foo' } | 
|  | 377 ]); | 
|  | 378 | 
|  | 379 reset(); | 
|  | 380 function Thingy (a, b, c) { | 
|  | 381   this.a = a; | 
|  | 382   this.b = b; | 
|  | 383 } | 
|  | 384 | 
|  | 385 Thingy.MULTIPLY = 'multiply'; | 
|  | 386 Thingy.INCREMENT = 'increment'; | 
|  | 387 Thingy.INCREMENT_AND_MULTIPLY = 'incrementAndMultiply'; | 
|  | 388 | 
|  | 389 Thingy.prototype = { | 
|  | 390   increment: function(amount) { | 
|  | 391     var notifier = Object.getNotifier(this); | 
|  | 392 | 
|  | 393     notifier.performChange(Thingy.INCREMENT, function() { | 
|  | 394       this.a += amount; | 
|  | 395       this.b += amount; | 
|  | 396     }, this); | 
|  | 397 | 
|  | 398     notifier.notify({ | 
|  | 399       object: this, | 
|  | 400       type: Thingy.INCREMENT, | 
|  | 401       incremented: amount | 
|  | 402     }); | 
|  | 403   }, | 
|  | 404 | 
|  | 405   multiply: function(amount) { | 
|  | 406     var notifier = Object.getNotifier(this); | 
|  | 407 | 
|  | 408     notifier.performChange(Thingy.MULTIPLY, function() { | 
|  | 409       this.a *= amount; | 
|  | 410       this.b *= amount; | 
|  | 411     }, this); | 
|  | 412 | 
|  | 413     notifier.notify({ | 
|  | 414       object: this, | 
|  | 415       type: Thingy.MULTIPLY, | 
|  | 416       multiplied: amount | 
|  | 417     }); | 
|  | 418   }, | 
|  | 419 | 
|  | 420   incrementAndMultiply: function(incAmount, multAmount) { | 
|  | 421     var notifier = Object.getNotifier(this); | 
|  | 422 | 
|  | 423     notifier.performChange(Thingy.INCREMENT_AND_MULTIPLY, function() { | 
|  | 424       this.increment(incAmount); | 
|  | 425       this.multiply(multAmount); | 
|  | 426     }, this); | 
|  | 427 | 
|  | 428     notifier.notify({ | 
|  | 429       object: this, | 
|  | 430       type: Thingy.INCREMENT_AND_MULTIPLY, | 
|  | 431       incremented: incAmount, | 
|  | 432       multiplied: multAmount | 
|  | 433     }); | 
|  | 434   } | 
|  | 435 } | 
|  | 436 | 
|  | 437 Thingy.observe = function(thingy, callback) { | 
|  | 438   Object.observe(thingy, callback, [Thingy.INCREMENT, | 
|  | 439                                     Thingy.MULTIPLY, | 
|  | 440                                     Thingy.INCREMENT_AND_MULTIPLY, | 
|  | 441                                     'updated']); | 
|  | 442 } | 
|  | 443 | 
|  | 444 Thingy.unobserve = function(thingy, callback) { | 
|  | 445   Object.unobserve(thingy); | 
|  | 446 } | 
|  | 447 | 
|  | 448 var thingy = new Thingy(2, 4); | 
|  | 449 | 
|  | 450 Object.observe(thingy, observer.callback); | 
|  | 451 Thingy.observe(thingy, observer2.callback); | 
|  | 452 thingy.increment(3);               // { a: 5, b: 7 } | 
|  | 453 thingy.b++;                        // { a: 5, b: 8 } | 
|  | 454 thingy.multiply(2);                // { a: 10, b: 16 } | 
|  | 455 thingy.a++;                        // { a: 11, b: 16 } | 
|  | 456 thingy.incrementAndMultiply(2, 2); // { a: 26, b: 36 } | 
|  | 457 | 
|  | 458 Object.deliverChangeRecords(observer.callback); | 
|  | 459 Object.deliverChangeRecords(observer2.callback); | 
|  | 460 observer.assertCallbackRecords([ | 
|  | 461   { object: thingy, type: 'updated', name: 'a', oldValue: 2 }, | 
|  | 462   { object: thingy, type: 'updated', name: 'b', oldValue: 4 }, | 
|  | 463   { object: thingy, type: 'updated', name: 'b', oldValue: 7 }, | 
|  | 464   { object: thingy, type: 'updated', name: 'a', oldValue: 5 }, | 
|  | 465   { object: thingy, type: 'updated', name: 'b', oldValue: 8 }, | 
|  | 466   { object: thingy, type: 'updated', name: 'a', oldValue: 10 }, | 
|  | 467   { object: thingy, type: 'updated', name: 'a', oldValue: 11 }, | 
|  | 468   { object: thingy, type: 'updated', name: 'b', oldValue: 16 }, | 
|  | 469   { object: thingy, type: 'updated', name: 'a', oldValue: 13 }, | 
|  | 470   { object: thingy, type: 'updated', name: 'b', oldValue: 18 }, | 
|  | 471 ]); | 
|  | 472 | 
|  | 473 observer2.assertCallbackRecords([ | 
|  | 474   { object: thingy, type: Thingy.INCREMENT, incremented: 3 }, | 
|  | 475   { object: thingy, type: 'updated', name: 'b', oldValue: 7 }, | 
|  | 476   { object: thingy, type: Thingy.MULTIPLY, multiplied: 2 }, | 
|  | 477   { object: thingy, type: 'updated', name: 'a', oldValue: 10 }, | 
|  | 478   { | 
|  | 479     object: thingy, | 
|  | 480     type: Thingy.INCREMENT_AND_MULTIPLY, | 
|  | 481     incremented: 2, | 
|  | 482     multiplied: 2 | 
|  | 483   } | 
|  | 484 ]); | 
|  | 485 | 
|  | 486 | 
| 280 // Observing multiple objects; records appear in order. | 487 // Observing multiple objects; records appear in order. | 
| 281 reset(); | 488 reset(); | 
| 282 var obj2 = {}; | 489 var obj2 = {}; | 
| 283 var obj3 = {} | 490 var obj3 = {} | 
| 284 Object.observe(obj, observer.callback); | 491 Object.observe(obj, observer.callback); | 
| 285 Object.observe(obj3, observer.callback); | 492 Object.observe(obj3, observer.callback); | 
| 286 Object.observe(obj2, observer.callback); | 493 Object.observe(obj2, observer.callback); | 
| 287 Object.getNotifier(obj).notify({ | 494 Object.getNotifier(obj).notify({ | 
| 288   type: 'foo1', | 495   type: 'new', | 
| 289 }); | 496 }); | 
| 290 Object.getNotifier(obj2).notify({ | 497 Object.getNotifier(obj2).notify({ | 
| 291   type: 'foo2', | 498   type: 'updated', | 
| 292 }); | 499 }); | 
| 293 Object.getNotifier(obj3).notify({ | 500 Object.getNotifier(obj3).notify({ | 
| 294   type: 'foo3', | 501   type: 'deleted', | 
| 295 }); | 502 }); | 
| 296 Object.observe(obj3, observer.callback); | 503 Object.observe(obj3, observer.callback); | 
| 297 Object.deliverChangeRecords(observer.callback); | 504 Object.deliverChangeRecords(observer.callback); | 
| 298 observer.assertCallbackRecords([ | 505 observer.assertCallbackRecords([ | 
| 299   { object: obj, type: 'foo1' }, | 506   { object: obj, type: 'new' }, | 
| 300   { object: obj2, type: 'foo2' }, | 507   { object: obj2, type: 'updated' }, | 
| 301   { object: obj3, type: 'foo3' } | 508   { object: obj3, type: 'deleted' } | 
| 302 ]); | 509 ]); | 
| 303 | 510 | 
| 304 | 511 | 
| 305 // Recursive observation. | 512 // Recursive observation. | 
| 306 var obj = {a: 1}; | 513 var obj = {a: 1}; | 
| 307 var callbackCount = 0; | 514 var callbackCount = 0; | 
| 308 function recursiveObserver(r) { | 515 function recursiveObserver(r) { | 
| 309   assertEquals(1, r.length); | 516   assertEquals(1, r.length); | 
| 310   ++callbackCount; | 517   ++callbackCount; | 
| 311   if (r[0].oldValue < 100) ++obj[r[0].name]; | 518   if (r[0].oldValue < 100) ++obj[r[0].name]; | 
| (...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1070     for (var n1 = 0; n1 < 3; ++n1) | 1277     for (var n1 = 0; n1 < 3; ++n1) | 
| 1071       for (var n2 = 0; n2 < 3; ++n2) | 1278       for (var n2 = 0; n2 < 3; ++n2) | 
| 1072         for (var i in mutation) | 1279         for (var i in mutation) | 
| 1073           TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); | 1280           TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); | 
| 1074 | 1281 | 
| 1075 for (var b1 = 0; b1 < 2; ++b1) | 1282 for (var b1 = 0; b1 < 2; ++b1) | 
| 1076   for (var b2 = 0; b2 < 2; ++b2) | 1283   for (var b2 = 0; b2 < 2; ++b2) | 
| 1077     for (var n = 0; n < 3; ++n) | 1284     for (var n = 0; n < 3; ++n) | 
| 1078       for (var i in mutationByIncr) | 1285       for (var i in mutationByIncr) | 
| 1079         TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); | 1286         TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); | 
| OLD | NEW | 
|---|