| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 return observationState; | 50 return observationState; |
| 51 } | 51 } |
| 52 | 52 |
| 53 function GetWeakMapWrapper() { | 53 function GetWeakMapWrapper() { |
| 54 function MapWrapper(map) { | 54 function MapWrapper(map) { |
| 55 this.map_ = map; | 55 this.map_ = map; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 MapWrapper.prototype = { | 58 MapWrapper.prototype = { |
| 59 __proto__: null, |
| 59 get: function(key) { | 60 get: function(key) { |
| 60 return %WeakCollectionGet(this.map_, key); | 61 return %WeakCollectionGet(this.map_, key); |
| 61 }, | 62 }, |
| 62 set: function(key, value) { | 63 set: function(key, value) { |
| 63 %WeakCollectionSet(this.map_, key, value); | 64 %WeakCollectionSet(this.map_, key, value); |
| 64 }, | 65 }, |
| 65 has: function(key) { | 66 has: function(key) { |
| 66 return !IS_UNDEFINED(this.get(key)); | 67 return !IS_UNDEFINED(this.get(key)); |
| 67 } | 68 } |
| 68 }; | 69 }; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 throw MakeTypeError("observe_non_object", ["observe"]); | 358 throw MakeTypeError("observe_non_object", ["observe"]); |
| 358 if (%IsJSGlobalProxy(object)) | 359 if (%IsJSGlobalProxy(object)) |
| 359 throw MakeTypeError("observe_global_proxy", ["observe"]); | 360 throw MakeTypeError("observe_global_proxy", ["observe"]); |
| 360 if (!IS_SPEC_FUNCTION(callback)) | 361 if (!IS_SPEC_FUNCTION(callback)) |
| 361 throw MakeTypeError("observe_non_function", ["observe"]); | 362 throw MakeTypeError("observe_non_function", ["observe"]); |
| 362 if (ObjectIsFrozen(callback)) | 363 if (ObjectIsFrozen(callback)) |
| 363 throw MakeTypeError("observe_callback_frozen"); | 364 throw MakeTypeError("observe_callback_frozen"); |
| 364 if (!AcceptArgIsValid(acceptList)) | 365 if (!AcceptArgIsValid(acceptList)) |
| 365 throw MakeTypeError("observe_accept_invalid"); | 366 throw MakeTypeError("observe_accept_invalid"); |
| 366 | 367 |
| 368 return %NativeObjectObserve(object, callback, acceptList); |
| 369 } |
| 370 |
| 371 function NativeObjectObserve(object, callback, acceptList) { |
| 367 var objectInfo = ObjectInfoGetOrCreate(object); | 372 var objectInfo = ObjectInfoGetOrCreate(object); |
| 368 ObjectInfoAddObserver(objectInfo, callback, acceptList); | 373 ObjectInfoAddObserver(objectInfo, callback, acceptList); |
| 369 return object; | 374 return object; |
| 370 } | 375 } |
| 371 | 376 |
| 372 function ObjectUnobserve(object, callback) { | 377 function ObjectUnobserve(object, callback) { |
| 373 if (!IS_SPEC_OBJECT(object)) | 378 if (!IS_SPEC_OBJECT(object)) |
| 374 throw MakeTypeError("observe_non_object", ["unobserve"]); | 379 throw MakeTypeError("observe_non_object", ["unobserve"]); |
| 375 if (%IsJSGlobalProxy(object)) | 380 if (%IsJSGlobalProxy(object)) |
| 376 throw MakeTypeError("observe_global_proxy", ["unobserve"]); | 381 throw MakeTypeError("observe_global_proxy", ["unobserve"]); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 throw MakeTypeError("observe_type_non_string"); | 525 throw MakeTypeError("observe_type_non_string"); |
| 521 | 526 |
| 522 ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord); | 527 ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord); |
| 523 } | 528 } |
| 524 | 529 |
| 525 function ObjectNotifierPerformChange(changeType, changeFn) { | 530 function ObjectNotifierPerformChange(changeType, changeFn) { |
| 526 if (!IS_SPEC_OBJECT(this)) | 531 if (!IS_SPEC_OBJECT(this)) |
| 527 throw MakeTypeError("called_on_non_object", ["performChange"]); | 532 throw MakeTypeError("called_on_non_object", ["performChange"]); |
| 528 | 533 |
| 529 var objectInfo = ObjectInfoGetFromNotifier(this); | 534 var objectInfo = ObjectInfoGetFromNotifier(this); |
| 530 | |
| 531 if (IS_UNDEFINED(objectInfo)) | 535 if (IS_UNDEFINED(objectInfo)) |
| 532 throw MakeTypeError("observe_notify_non_notifier"); | 536 throw MakeTypeError("observe_notify_non_notifier"); |
| 533 if (!IS_STRING(changeType)) | 537 if (!IS_STRING(changeType)) |
| 534 throw MakeTypeError("observe_perform_non_string"); | 538 throw MakeTypeError("observe_perform_non_string"); |
| 535 if (!IS_SPEC_FUNCTION(changeFn)) | 539 if (!IS_SPEC_FUNCTION(changeFn)) |
| 536 throw MakeTypeError("observe_perform_non_function"); | 540 throw MakeTypeError("observe_perform_non_function"); |
| 537 | 541 |
| 542 return %NativeObjectNotifierPerformChange(objectInfo, changeType, changeFn) |
| 543 } |
| 544 |
| 545 function NativeObjectNotifierPerformChange(objectInfo, changeType, changeFn) { |
| 538 ObjectInfoAddPerformingType(objectInfo, changeType); | 546 ObjectInfoAddPerformingType(objectInfo, changeType); |
| 539 | 547 |
| 540 var changeRecord; | 548 var changeRecord; |
| 541 try { | 549 try { |
| 542 changeRecord = %_CallFunction(UNDEFINED, changeFn); | 550 changeRecord = %_CallFunction(UNDEFINED, changeFn); |
| 543 } finally { | 551 } finally { |
| 544 ObjectInfoRemovePerformingType(objectInfo, changeType); | 552 ObjectInfoRemovePerformingType(objectInfo, changeType); |
| 545 } | 553 } |
| 546 | 554 |
| 547 if (IS_SPEC_OBJECT(changeRecord)) | 555 if (IS_SPEC_OBJECT(changeRecord)) |
| 548 ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, changeType); | 556 ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, changeType); |
| 549 } | 557 } |
| 550 | 558 |
| 551 function ObjectGetNotifier(object) { | 559 function ObjectGetNotifier(object) { |
| 552 if (!IS_SPEC_OBJECT(object)) | 560 if (!IS_SPEC_OBJECT(object)) |
| 553 throw MakeTypeError("observe_non_object", ["getNotifier"]); | 561 throw MakeTypeError("observe_non_object", ["getNotifier"]); |
| 554 if (%IsJSGlobalProxy(object)) | 562 if (%IsJSGlobalProxy(object)) |
| 555 throw MakeTypeError("observe_global_proxy", ["getNotifier"]); | 563 throw MakeTypeError("observe_global_proxy", ["getNotifier"]); |
| 556 | 564 |
| 557 if (ObjectIsFrozen(object)) return null; | 565 if (ObjectIsFrozen(object)) return null; |
| 558 | 566 |
| 559 if (!%ObjectWasCreatedInCurrentOrigin(object)) return null; | 567 if (!%ObjectWasCreatedInCurrentOrigin(object)) return null; |
| 560 | 568 |
| 569 return %NativeObjectGetNotifier(object); |
| 570 } |
| 571 |
| 572 function NativeObjectGetNotifier(object) { |
| 561 var objectInfo = ObjectInfoGetOrCreate(object); | 573 var objectInfo = ObjectInfoGetOrCreate(object); |
| 562 return ObjectInfoGetNotifier(objectInfo); | 574 return ObjectInfoGetNotifier(objectInfo); |
| 563 } | 575 } |
| 564 | 576 |
| 565 function CallbackDeliverPending(callback) { | 577 function CallbackDeliverPending(callback) { |
| 566 var callbackInfo = GetCallbackInfoMap().get(callback); | 578 var callbackInfo = GetCallbackInfoMap().get(callback); |
| 567 if (IS_UNDEFINED(callbackInfo) || IS_NUMBER(callbackInfo)) | 579 if (IS_UNDEFINED(callbackInfo) || IS_NUMBER(callbackInfo)) |
| 568 return false; | 580 return false; |
| 569 | 581 |
| 570 // Clear the pending change records from callback and return it to its | 582 // Clear the pending change records from callback and return it to its |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 "observe", ArrayObserve, | 625 "observe", ArrayObserve, |
| 614 "unobserve", ArrayUnobserve | 626 "unobserve", ArrayUnobserve |
| 615 )); | 627 )); |
| 616 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( | 628 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( |
| 617 "notify", ObjectNotifierNotify, | 629 "notify", ObjectNotifierNotify, |
| 618 "performChange", ObjectNotifierPerformChange | 630 "performChange", ObjectNotifierPerformChange |
| 619 )); | 631 )); |
| 620 } | 632 } |
| 621 | 633 |
| 622 SetupObjectObserve(); | 634 SetupObjectObserve(); |
| OLD | NEW |