| 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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 function ObjectObserve(object, callback, acceptList) { | 361 function ObjectObserve(object, callback, acceptList) { |
| 362 if (!IS_SPEC_OBJECT(object)) | 362 if (!IS_SPEC_OBJECT(object)) |
| 363 throw MakeTypeError("observe_non_object", ["observe"]); | 363 throw MakeTypeError("observe_non_object", ["observe"]); |
| 364 if (%IsJSGlobalProxy(object)) | 364 if (%IsJSGlobalProxy(object)) |
| 365 throw MakeTypeError("observe_global_proxy", ["observe"]); | 365 throw MakeTypeError("observe_global_proxy", ["observe"]); |
| 366 if (!IS_SPEC_FUNCTION(callback)) | 366 if (!IS_SPEC_FUNCTION(callback)) |
| 367 throw MakeTypeError("observe_non_function", ["observe"]); | 367 throw MakeTypeError("observe_non_function", ["observe"]); |
| 368 if (ObjectIsFrozen(callback)) | 368 if (ObjectIsFrozen(callback)) |
| 369 throw MakeTypeError("observe_callback_frozen"); | 369 throw MakeTypeError("observe_callback_frozen"); |
| 370 | 370 |
| 371 return %ObjectObserveInObjectContext(object, callback, acceptList); | 371 var objectObserveFn = %GetObjectContextObjectObserve(object); |
| 372 return objectObserveFn(object, callback, acceptList); |
| 372 } | 373 } |
| 373 | 374 |
| 374 function NativeObjectObserve(object, callback, acceptList) { | 375 function NativeObjectObserve(object, callback, acceptList) { |
| 375 var objectInfo = ObjectInfoGetOrCreate(object); | 376 var objectInfo = ObjectInfoGetOrCreate(object); |
| 376 var typeList = ConvertAcceptListToTypeMap(acceptList); | 377 var typeList = ConvertAcceptListToTypeMap(acceptList); |
| 377 ObjectInfoAddObserver(objectInfo, callback, typeList); | 378 ObjectInfoAddObserver(objectInfo, callback, typeList); |
| 378 return object; | 379 return object; |
| 379 } | 380 } |
| 380 | 381 |
| 381 function ObjectUnobserve(object, callback) { | 382 function ObjectUnobserve(object, callback) { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 throw MakeTypeError("called_on_non_object", ["performChange"]); | 537 throw MakeTypeError("called_on_non_object", ["performChange"]); |
| 537 | 538 |
| 538 var objectInfo = ObjectInfoGetFromNotifier(this); | 539 var objectInfo = ObjectInfoGetFromNotifier(this); |
| 539 if (IS_UNDEFINED(objectInfo)) | 540 if (IS_UNDEFINED(objectInfo)) |
| 540 throw MakeTypeError("observe_notify_non_notifier"); | 541 throw MakeTypeError("observe_notify_non_notifier"); |
| 541 if (!IS_STRING(changeType)) | 542 if (!IS_STRING(changeType)) |
| 542 throw MakeTypeError("observe_perform_non_string"); | 543 throw MakeTypeError("observe_perform_non_string"); |
| 543 if (!IS_SPEC_FUNCTION(changeFn)) | 544 if (!IS_SPEC_FUNCTION(changeFn)) |
| 544 throw MakeTypeError("observe_perform_non_function"); | 545 throw MakeTypeError("observe_perform_non_function"); |
| 545 | 546 |
| 546 return %ObjectNotifierPerformChangeInObjectContext( | 547 var performChangeFn = %GetObjectContextNotifierPerformChange(objectInfo); |
| 547 objectInfo, changeType, changeFn); | 548 performChangeFn(objectInfo, changeType, changeFn); |
| 548 } | 549 } |
| 549 | 550 |
| 550 function NativeObjectNotifierPerformChange(objectInfo, changeType, changeFn) { | 551 function NativeObjectNotifierPerformChange(objectInfo, changeType, changeFn) { |
| 551 ObjectInfoAddPerformingType(objectInfo, changeType); | 552 ObjectInfoAddPerformingType(objectInfo, changeType); |
| 552 | 553 |
| 553 var changeRecord; | 554 var changeRecord; |
| 554 try { | 555 try { |
| 555 changeRecord = %_CallFunction(UNDEFINED, changeFn); | 556 changeRecord = %_CallFunction(UNDEFINED, changeFn); |
| 556 } finally { | 557 } finally { |
| 557 ObjectInfoRemovePerformingType(objectInfo, changeType); | 558 ObjectInfoRemovePerformingType(objectInfo, changeType); |
| 558 } | 559 } |
| 559 | 560 |
| 560 if (IS_SPEC_OBJECT(changeRecord)) | 561 if (IS_SPEC_OBJECT(changeRecord)) |
| 561 ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, changeType); | 562 ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, changeType); |
| 562 } | 563 } |
| 563 | 564 |
| 564 function ObjectGetNotifier(object) { | 565 function ObjectGetNotifier(object) { |
| 565 if (!IS_SPEC_OBJECT(object)) | 566 if (!IS_SPEC_OBJECT(object)) |
| 566 throw MakeTypeError("observe_non_object", ["getNotifier"]); | 567 throw MakeTypeError("observe_non_object", ["getNotifier"]); |
| 567 if (%IsJSGlobalProxy(object)) | 568 if (%IsJSGlobalProxy(object)) |
| 568 throw MakeTypeError("observe_global_proxy", ["getNotifier"]); | 569 throw MakeTypeError("observe_global_proxy", ["getNotifier"]); |
| 569 | 570 |
| 570 if (ObjectIsFrozen(object)) return null; | 571 if (ObjectIsFrozen(object)) return null; |
| 571 | 572 |
| 572 if (!%ObjectWasCreatedInCurrentOrigin(object)) return null; | 573 if (!%ObjectWasCreatedInCurrentOrigin(object)) return null; |
| 573 | 574 |
| 574 return %ObjectGetNotifierInObjectContext(object); | 575 var getNotifierFn = %GetObjectContextObjectGetNotifier(object); |
| 576 return getNotifierFn(object); |
| 575 } | 577 } |
| 576 | 578 |
| 577 function NativeObjectGetNotifier(object) { | 579 function NativeObjectGetNotifier(object) { |
| 578 var objectInfo = ObjectInfoGetOrCreate(object); | 580 var objectInfo = ObjectInfoGetOrCreate(object); |
| 579 return ObjectInfoGetNotifier(objectInfo); | 581 return ObjectInfoGetNotifier(objectInfo); |
| 580 } | 582 } |
| 581 | 583 |
| 582 function CallbackDeliverPending(callback) { | 584 function CallbackDeliverPending(callback) { |
| 583 var callbackInfo = GetCallbackInfoMap().get(callback); | 585 var callbackInfo = GetCallbackInfoMap().get(callback); |
| 584 if (IS_UNDEFINED(callbackInfo) || IS_NUMBER(callbackInfo)) | 586 if (IS_UNDEFINED(callbackInfo) || IS_NUMBER(callbackInfo)) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 "observe", ArrayObserve, | 632 "observe", ArrayObserve, |
| 631 "unobserve", ArrayUnobserve | 633 "unobserve", ArrayUnobserve |
| 632 )); | 634 )); |
| 633 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( | 635 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( |
| 634 "notify", ObjectNotifierNotify, | 636 "notify", ObjectNotifierNotify, |
| 635 "performChange", ObjectNotifierPerformChange | 637 "performChange", ObjectNotifierPerformChange |
| 636 )); | 638 )); |
| 637 } | 639 } |
| 638 | 640 |
| 639 SetupObjectObserve(); | 641 SetupObjectObserve(); |
| OLD | NEW |