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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 !%IsAccessAllowedForObserver( | 377 !%IsAccessAllowedForObserver( |
378 callback, changeRecord.object, changeRecord.name))) { | 378 callback, changeRecord.object, changeRecord.name))) { |
379 return; | 379 return; |
380 } | 380 } |
381 | 381 |
382 var callbackInfo = CallbackInfoNormalize(callback); | 382 var callbackInfo = CallbackInfoNormalize(callback); |
383 if (!observationState.pendingObservers) | 383 if (!observationState.pendingObservers) |
384 observationState.pendingObservers = { __proto__: null }; | 384 observationState.pendingObservers = { __proto__: null }; |
385 observationState.pendingObservers[callbackInfo.priority] = callback; | 385 observationState.pendingObservers[callbackInfo.priority] = callback; |
386 callbackInfo.push(changeRecord); | 386 callbackInfo.push(changeRecord); |
387 %SetObserverDeliveryPending(); | 387 %SetMicrotasksPending(true); |
388 } | 388 } |
389 | 389 |
390 function ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, type) { | 390 function ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, type) { |
391 if (!ObjectInfoHasActiveObservers(objectInfo)) | 391 if (!ObjectInfoHasActiveObservers(objectInfo)) |
392 return; | 392 return; |
393 | 393 |
394 var hasType = !IS_UNDEFINED(type); | 394 var hasType = !IS_UNDEFINED(type); |
395 var newRecord = hasType ? | 395 var newRecord = hasType ? |
396 { object: ObjectInfoGetObject(objectInfo), type: type } : | 396 { object: ObjectInfoGetObject(objectInfo), type: type } : |
397 { object: ObjectInfoGetObject(objectInfo) }; | 397 { object: ObjectInfoGetObject(objectInfo) }; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 callbackInfoMap.set(callback, priority); | 544 callbackInfoMap.set(callback, priority); |
545 | 545 |
546 if (observationState.pendingObservers) | 546 if (observationState.pendingObservers) |
547 delete observationState.pendingObservers[priority]; | 547 delete observationState.pendingObservers[priority]; |
548 | 548 |
549 var delivered = []; | 549 var delivered = []; |
550 %MoveArrayContents(callbackInfo, delivered); | 550 %MoveArrayContents(callbackInfo, delivered); |
551 | 551 |
552 try { | 552 try { |
553 %_CallFunction(UNDEFINED, delivered, callback); | 553 %_CallFunction(UNDEFINED, delivered, callback); |
554 } catch (ex) {} | 554 } catch (ex) {} // TODO(rossberg): perhaps log uncaught exceptions. |
555 return true; | 555 return true; |
556 } | 556 } |
557 | 557 |
558 function ObjectDeliverChangeRecords(callback) { | 558 function ObjectDeliverChangeRecords(callback) { |
559 if (!IS_SPEC_FUNCTION(callback)) | 559 if (!IS_SPEC_FUNCTION(callback)) |
560 throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]); | 560 throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]); |
561 | 561 |
562 while (CallbackDeliverPending(callback)) {} | 562 while (CallbackDeliverPending(callback)) {} |
563 } | 563 } |
564 | 564 |
565 function DeliverChangeRecords() { | 565 function ObserveMicrotasksRunner() { |
566 while (observationState.pendingObservers) { | 566 var pendingObservers = observationState.pendingObservers; |
567 var pendingObservers = observationState.pendingObservers; | 567 if (pendingObservers) { |
568 observationState.pendingObservers = null; | 568 observationState.pendingObservers = null; |
569 for (var i in pendingObservers) { | 569 for (var i in pendingObservers) { |
570 CallbackDeliverPending(pendingObservers[i]); | 570 CallbackDeliverPending(pendingObservers[i]); |
571 } | 571 } |
572 } | 572 } |
573 } | 573 } |
| 574 RunMicrotasks.runners.push(ObserveMicrotasksRunner); |
574 | 575 |
575 function SetupObjectObserve() { | 576 function SetupObjectObserve() { |
576 %CheckIsBootstrapping(); | 577 %CheckIsBootstrapping(); |
577 InstallFunctions($Object, DONT_ENUM, $Array( | 578 InstallFunctions($Object, DONT_ENUM, $Array( |
578 "deliverChangeRecords", ObjectDeliverChangeRecords, | 579 "deliverChangeRecords", ObjectDeliverChangeRecords, |
579 "getNotifier", ObjectGetNotifier, | 580 "getNotifier", ObjectGetNotifier, |
580 "observe", ObjectObserve, | 581 "observe", ObjectObserve, |
581 "unobserve", ObjectUnobserve | 582 "unobserve", ObjectUnobserve |
582 )); | 583 )); |
583 InstallFunctions($Array, DONT_ENUM, $Array( | 584 InstallFunctions($Array, DONT_ENUM, $Array( |
584 "observe", ArrayObserve, | 585 "observe", ArrayObserve, |
585 "unobserve", ArrayUnobserve | 586 "unobserve", ArrayUnobserve |
586 )); | 587 )); |
587 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( | 588 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( |
588 "notify", ObjectNotifierNotify, | 589 "notify", ObjectNotifierNotify, |
589 "performChange", ObjectNotifierPerformChange | 590 "performChange", ObjectNotifierPerformChange |
590 )); | 591 )); |
591 } | 592 } |
592 | 593 |
593 SetupObjectObserve(); | 594 SetupObjectObserve(); |
OLD | NEW |