| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 // Overview: | 7 // Overview: |
| 8 // | 8 // |
| 9 // This file contains all of the routing and accounting for Object.observe. | 9 // This file contains all of the routing and accounting for Object.observe. |
| 10 // User code will interact with these mechanisms via the Object.observe APIs | 10 // User code will interact with these mechanisms via the Object.observe APIs |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 function GetObservationStateJS() { | 38 function GetObservationStateJS() { |
| 39 if (IS_UNDEFINED(observationState)) | 39 if (IS_UNDEFINED(observationState)) |
| 40 observationState = %GetObservationState(); | 40 observationState = %GetObservationState(); |
| 41 | 41 |
| 42 if (IS_UNDEFINED(observationState.callbackInfoMap)) { | 42 if (IS_UNDEFINED(observationState.callbackInfoMap)) { |
| 43 observationState.callbackInfoMap = %ObservationWeakMapCreate(); | 43 observationState.callbackInfoMap = %ObservationWeakMapCreate(); |
| 44 observationState.objectInfoMap = %ObservationWeakMapCreate(); | 44 observationState.objectInfoMap = %ObservationWeakMapCreate(); |
| 45 observationState.notifierObjectInfoMap = %ObservationWeakMapCreate(); | 45 observationState.notifierObjectInfoMap = %ObservationWeakMapCreate(); |
| 46 observationState.pendingObservers = null; | 46 observationState.pendingObservers = null; |
| 47 observationState.nextCallbackPriority = 0; | 47 observationState.nextCallbackPriority = 0; |
| 48 observationState.lastMicrotaskId = 0; |
| 48 } | 49 } |
| 49 | 50 |
| 50 return observationState; | 51 return observationState; |
| 51 } | 52 } |
| 52 | 53 |
| 53 function GetWeakMapWrapper() { | 54 function GetWeakMapWrapper() { |
| 54 function MapWrapper(map) { | 55 function MapWrapper(map) { |
| 55 this.map_ = map; | 56 this.map_ = map; |
| 56 }; | 57 }; |
| 57 | 58 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 415 |
| 415 var callback = ObserverGetCallback(observer); | 416 var callback = ObserverGetCallback(observer); |
| 416 if (!%ObserverObjectAndRecordHaveSameOrigin(callback, changeRecord.object, | 417 if (!%ObserverObjectAndRecordHaveSameOrigin(callback, changeRecord.object, |
| 417 changeRecord)) { | 418 changeRecord)) { |
| 418 return; | 419 return; |
| 419 } | 420 } |
| 420 | 421 |
| 421 var callbackInfo = CallbackInfoNormalize(callback); | 422 var callbackInfo = CallbackInfoNormalize(callback); |
| 422 if (IS_NULL(GetPendingObservers())) { | 423 if (IS_NULL(GetPendingObservers())) { |
| 423 SetPendingObservers(nullProtoObject()); | 424 SetPendingObservers(nullProtoObject()); |
| 424 %EnqueueMicrotask(ObserveMicrotaskRunner); | 425 if (DEBUG_IS_ACTIVE) { |
| 426 var id = ++GetObservationStateJS().lastMicrotaskId; |
| 427 var name = "Object.observe"; |
| 428 %EnqueueMicrotask(function() { |
| 429 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); |
| 430 ObserveMicrotaskRunner(); |
| 431 %DebugAsyncTaskEvent({ type: "didHandle", id: id, name: name }); |
| 432 }); |
| 433 %DebugAsyncTaskEvent({ type: "enqueue", id: id, name: name }); |
| 434 } else { |
| 435 %EnqueueMicrotask(ObserveMicrotaskRunner); |
| 436 } |
| 425 } | 437 } |
| 426 GetPendingObservers()[callbackInfo.priority] = callback; | 438 GetPendingObservers()[callbackInfo.priority] = callback; |
| 427 callbackInfo.push(changeRecord); | 439 callbackInfo.push(changeRecord); |
| 428 } | 440 } |
| 429 | 441 |
| 430 function ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, type) { | 442 function ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, type) { |
| 431 if (!ObjectInfoHasActiveObservers(objectInfo)) | 443 if (!ObjectInfoHasActiveObservers(objectInfo)) |
| 432 return; | 444 return; |
| 433 | 445 |
| 434 var hasType = !IS_UNDEFINED(type); | 446 var hasType = !IS_UNDEFINED(type); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 "observe", ArrayObserve, | 643 "observe", ArrayObserve, |
| 632 "unobserve", ArrayUnobserve | 644 "unobserve", ArrayUnobserve |
| 633 )); | 645 )); |
| 634 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( | 646 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( |
| 635 "notify", ObjectNotifierNotify, | 647 "notify", ObjectNotifierNotify, |
| 636 "performChange", ObjectNotifierPerformChange | 648 "performChange", ObjectNotifierPerformChange |
| 637 )); | 649 )); |
| 638 } | 650 } |
| 639 | 651 |
| 640 SetupObjectObserve(); | 652 SetupObjectObserve(); |
| OLD | NEW |