| 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 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 | 13 |
| 14 var GetHash; | 14 var GetHash; |
| 15 var GlobalArray = global.Array; | 15 var GlobalArray = global.Array; |
| 16 var GlobalObject = global.Object; | 16 var GlobalObject = global.Object; |
| 17 var InternalArray = utils.InternalArray; | 17 var InternalArray = utils.InternalArray; |
| 18 var MakeTypeError; | 18 var MakeTypeError; |
| 19 var ObjectFreeze; | |
| 20 var ObjectIsFrozen; | |
| 21 | 19 |
| 22 utils.Import(function(from) { | 20 utils.Import(function(from) { |
| 23 GetHash = from.GetHash; | 21 GetHash = from.GetHash; |
| 24 MakeTypeError = from.MakeTypeError; | 22 MakeTypeError = from.MakeTypeError; |
| 25 ObjectFreeze = from.ObjectFreeze; | |
| 26 ObjectIsFrozen = from.ObjectIsFrozen; | |
| 27 }); | 23 }); |
| 28 | 24 |
| 29 // ------------------------------------------------------------------- | 25 // ------------------------------------------------------------------- |
| 30 | 26 |
| 31 // Overview: | 27 // Overview: |
| 32 // | 28 // |
| 33 // This file contains all of the routing and accounting for Object.observe. | 29 // This file contains all of the routing and accounting for Object.observe. |
| 34 // User code will interact with these mechanisms via the Object.observe APIs | 30 // User code will interact with these mechanisms via the Object.observe APIs |
| 35 // and, as a side effect of mutation objects which are observed. The V8 runtime | 31 // and, as a side effect of mutation objects which are observed. The V8 runtime |
| 36 // (both C++ and JS) will interact with these mechanisms primarily by enqueuing | 32 // (both C++ and JS) will interact with these mechanisms primarily by enqueuing |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 377 |
| 382 function ObjectObserve(object, callback, acceptList) { | 378 function ObjectObserve(object, callback, acceptList) { |
| 383 if (!IS_RECEIVER(object)) | 379 if (!IS_RECEIVER(object)) |
| 384 throw MakeTypeError(kObserveNonObject, "observe", "observe"); | 380 throw MakeTypeError(kObserveNonObject, "observe", "observe"); |
| 385 if (%IsJSGlobalProxy(object)) | 381 if (%IsJSGlobalProxy(object)) |
| 386 throw MakeTypeError(kObserveGlobalProxy, "observe"); | 382 throw MakeTypeError(kObserveGlobalProxy, "observe"); |
| 387 if (%IsAccessCheckNeeded(object)) | 383 if (%IsAccessCheckNeeded(object)) |
| 388 throw MakeTypeError(kObserveAccessChecked, "observe"); | 384 throw MakeTypeError(kObserveAccessChecked, "observe"); |
| 389 if (!IS_CALLABLE(callback)) | 385 if (!IS_CALLABLE(callback)) |
| 390 throw MakeTypeError(kObserveNonFunction, "observe"); | 386 throw MakeTypeError(kObserveNonFunction, "observe"); |
| 391 if (ObjectIsFrozen(callback)) | 387 if (%object_is_frozen(callback)) |
| 392 throw MakeTypeError(kObserveCallbackFrozen); | 388 throw MakeTypeError(kObserveCallbackFrozen); |
| 393 | 389 |
| 394 var objectObserveFn = %GetObjectContextObjectObserve(object); | 390 var objectObserveFn = %GetObjectContextObjectObserve(object); |
| 395 return objectObserveFn(object, callback, acceptList); | 391 return objectObserveFn(object, callback, acceptList); |
| 396 } | 392 } |
| 397 | 393 |
| 398 | 394 |
| 399 function NativeObjectObserve(object, callback, acceptList) { | 395 function NativeObjectObserve(object, callback, acceptList) { |
| 400 var objectInfo = ObjectInfoGetOrCreate(object); | 396 var objectInfo = ObjectInfoGetOrCreate(object); |
| 401 var typeList = ConvertAcceptListToTypeMap(acceptList); | 397 var typeList = ConvertAcceptListToTypeMap(acceptList); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 var hasType = !IS_UNDEFINED(type); | 470 var hasType = !IS_UNDEFINED(type); |
| 475 var newRecord = hasType ? | 471 var newRecord = hasType ? |
| 476 { object: objectInfo.object, type: type } : | 472 { object: objectInfo.object, type: type } : |
| 477 { object: objectInfo.object }; | 473 { object: objectInfo.object }; |
| 478 | 474 |
| 479 for (var prop in changeRecord) { | 475 for (var prop in changeRecord) { |
| 480 if (prop === 'object' || (hasType && prop === 'type')) continue; | 476 if (prop === 'object' || (hasType && prop === 'type')) continue; |
| 481 %DefineDataPropertyUnchecked( | 477 %DefineDataPropertyUnchecked( |
| 482 newRecord, prop, changeRecord[prop], READ_ONLY + DONT_DELETE); | 478 newRecord, prop, changeRecord[prop], READ_ONLY + DONT_DELETE); |
| 483 } | 479 } |
| 484 ObjectFreeze(newRecord); | 480 %object_freeze(newRecord); |
| 485 | 481 |
| 486 ObjectInfoEnqueueInternalChangeRecord(objectInfo, newRecord); | 482 ObjectInfoEnqueueInternalChangeRecord(objectInfo, newRecord); |
| 487 } | 483 } |
| 488 | 484 |
| 489 | 485 |
| 490 function ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord) { | 486 function ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord) { |
| 491 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 487 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
| 492 if (IS_SYMBOL(changeRecord.name)) return; | 488 if (IS_SYMBOL(changeRecord.name)) return; |
| 493 | 489 |
| 494 if (ChangeObserversIsOptimized(objectInfo.changeObservers)) { | 490 if (ChangeObserversIsOptimized(objectInfo.changeObservers)) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 return; | 522 return; |
| 527 | 523 |
| 528 var changeRecord = { | 524 var changeRecord = { |
| 529 type: 'splice', | 525 type: 'splice', |
| 530 object: array, | 526 object: array, |
| 531 index: index, | 527 index: index, |
| 532 removed: removed, | 528 removed: removed, |
| 533 addedCount: addedCount | 529 addedCount: addedCount |
| 534 }; | 530 }; |
| 535 | 531 |
| 536 ObjectFreeze(changeRecord); | 532 %object_freeze(changeRecord); |
| 537 ObjectFreeze(changeRecord.removed); | 533 %object_freeze(changeRecord.removed); |
| 538 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord); | 534 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord); |
| 539 } | 535 } |
| 540 | 536 |
| 541 | 537 |
| 542 function NotifyChange(type, object, name, oldValue) { | 538 function NotifyChange(type, object, name, oldValue) { |
| 543 var objectInfo = ObjectInfoGet(object); | 539 var objectInfo = ObjectInfoGet(object); |
| 544 if (!ObjectInfoHasActiveObservers(objectInfo)) | 540 if (!ObjectInfoHasActiveObservers(objectInfo)) |
| 545 return; | 541 return; |
| 546 | 542 |
| 547 var changeRecord; | 543 var changeRecord; |
| 548 if (arguments.length == 2) { | 544 if (arguments.length == 2) { |
| 549 changeRecord = { type: type, object: object }; | 545 changeRecord = { type: type, object: object }; |
| 550 } else if (arguments.length == 3) { | 546 } else if (arguments.length == 3) { |
| 551 changeRecord = { type: type, object: object, name: name }; | 547 changeRecord = { type: type, object: object, name: name }; |
| 552 } else { | 548 } else { |
| 553 changeRecord = { | 549 changeRecord = { |
| 554 type: type, | 550 type: type, |
| 555 object: object, | 551 object: object, |
| 556 name: name, | 552 name: name, |
| 557 oldValue: oldValue | 553 oldValue: oldValue |
| 558 }; | 554 }; |
| 559 } | 555 } |
| 560 | 556 |
| 561 ObjectFreeze(changeRecord); | 557 %object_freeze(changeRecord); |
| 562 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord); | 558 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord); |
| 563 } | 559 } |
| 564 | 560 |
| 565 | 561 |
| 566 function ObjectNotifierNotify(changeRecord) { | 562 function ObjectNotifierNotify(changeRecord) { |
| 567 if (!IS_RECEIVER(this)) | 563 if (!IS_RECEIVER(this)) |
| 568 throw MakeTypeError(kCalledOnNonObject, "notify"); | 564 throw MakeTypeError(kCalledOnNonObject, "notify"); |
| 569 | 565 |
| 570 var objectInfo = ObjectInfoGetFromNotifier(this); | 566 var objectInfo = ObjectInfoGetFromNotifier(this); |
| 571 if (IS_UNDEFINED(objectInfo)) | 567 if (IS_UNDEFINED(objectInfo)) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 606 |
| 611 | 607 |
| 612 function ObjectGetNotifier(object) { | 608 function ObjectGetNotifier(object) { |
| 613 if (!IS_RECEIVER(object)) | 609 if (!IS_RECEIVER(object)) |
| 614 throw MakeTypeError(kObserveNonObject, "getNotifier", "getNotifier"); | 610 throw MakeTypeError(kObserveNonObject, "getNotifier", "getNotifier"); |
| 615 if (%IsJSGlobalProxy(object)) | 611 if (%IsJSGlobalProxy(object)) |
| 616 throw MakeTypeError(kObserveGlobalProxy, "getNotifier"); | 612 throw MakeTypeError(kObserveGlobalProxy, "getNotifier"); |
| 617 if (%IsAccessCheckNeeded(object)) | 613 if (%IsAccessCheckNeeded(object)) |
| 618 throw MakeTypeError(kObserveAccessChecked, "getNotifier"); | 614 throw MakeTypeError(kObserveAccessChecked, "getNotifier"); |
| 619 | 615 |
| 620 if (ObjectIsFrozen(object)) return null; | 616 if (%object_is_frozen(object)) return null; |
| 621 | 617 |
| 622 if (!%ObjectWasCreatedInCurrentOrigin(object)) return null; | 618 if (!%ObjectWasCreatedInCurrentOrigin(object)) return null; |
| 623 | 619 |
| 624 var getNotifierFn = %GetObjectContextObjectGetNotifier(object); | 620 var getNotifierFn = %GetObjectContextObjectGetNotifier(object); |
| 625 return getNotifierFn(object); | 621 return getNotifierFn(object); |
| 626 } | 622 } |
| 627 | 623 |
| 628 | 624 |
| 629 function NativeObjectGetNotifier(object) { | 625 function NativeObjectGetNotifier(object) { |
| 630 var objectInfo = ObjectInfoGetOrCreate(object); | 626 var objectInfo = ObjectInfoGetOrCreate(object); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 | 708 |
| 713 utils.Export(function(to) { | 709 utils.Export(function(to) { |
| 714 to.ObserveArrayMethods = ObserveArrayMethods; | 710 to.ObserveArrayMethods = ObserveArrayMethods; |
| 715 to.ObserveBeginPerformSplice = BeginPerformSplice; | 711 to.ObserveBeginPerformSplice = BeginPerformSplice; |
| 716 to.ObserveEndPerformSplice = EndPerformSplice; | 712 to.ObserveEndPerformSplice = EndPerformSplice; |
| 717 to.ObserveEnqueueSpliceRecord = EnqueueSpliceRecord; | 713 to.ObserveEnqueueSpliceRecord = EnqueueSpliceRecord; |
| 718 to.ObserveObjectMethods = ObserveObjectMethods; | 714 to.ObserveObjectMethods = ObserveObjectMethods; |
| 719 }); | 715 }); |
| 720 | 716 |
| 721 }) | 717 }) |
| OLD | NEW |