Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: src/object-observe.js

Issue 11274014: Store Object.observe state per-isolate rather than per-context (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added back runtime asserts Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap.cc ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 "use strict"; 28 "use strict";
29 29
30 var InternalObjectIsFrozen = $Object.isFrozen; 30 var InternalObjectIsFrozen = $Object.isFrozen;
31 var InternalObjectFreeze = $Object.freeze; 31 var InternalObjectFreeze = $Object.freeze;
32 32
33 var InternalWeakMapProto = { 33 var observationState = %GetObservationState();
34 __proto__: null, 34 if (IS_UNDEFINED(observationState.observerInfoMap)) {
35 set: $WeakMap.prototype.set, 35 observationState.observerInfoMap = %CreateObjectHashTable();
36 get: $WeakMap.prototype.get, 36 observationState.objectInfoMap = %CreateObjectHashTable();
37 has: $WeakMap.prototype.has
38 } 37 }
39 38
40 function createInternalWeakMap() { 39 function InternalObjectHashTable(table) {
41 var map = new $WeakMap; 40 this.table = table;
42 map.__proto__ = InternalWeakMapProto;
43 return map;
44 } 41 }
45 42
46 var observerInfoMap = createInternalWeakMap(); 43 InternalObjectHashTable.prototype = {
47 var objectInfoMap = createInternalWeakMap(); 44 get: function(key) {
45 return %ObjectHashTableGet(this.table, key);
46 },
47 set: function(key, value) {
48 return %ObjectHashTableSet(this.table, key, value);
49 },
50 has: function(key) {
51 return %ObjectHashTableHas(this.table, key);
52 }
53 };
54
55 var observerInfoMap = new InternalObjectHashTable(
56 observationState.observerInfoMap);
57 var objectInfoMap = new InternalObjectHashTable(observationState.objectInfoMap);
48 58
49 function ObjectObserve(object, callback) { 59 function ObjectObserve(object, callback) {
50 if (!IS_SPEC_OBJECT(object)) 60 if (!IS_SPEC_OBJECT(object))
51 throw MakeTypeError("observe_non_object", ["observe"]); 61 throw MakeTypeError("observe_non_object", ["observe"]);
52 if (!IS_SPEC_FUNCTION(callback)) 62 if (!IS_SPEC_FUNCTION(callback))
53 throw MakeTypeError("observe_non_function", ["observe"]); 63 throw MakeTypeError("observe_non_function", ["observe"]);
54 if (InternalObjectIsFrozen(callback)) 64 if (InternalObjectIsFrozen(callback))
55 throw MakeTypeError("observe_callback_frozen"); 65 throw MakeTypeError("observe_callback_frozen");
56 66
57 if (!observerInfoMap.has(callback)) { 67 if (!observerInfoMap.has(callback)) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 %CheckIsBootstrapping(); 175 %CheckIsBootstrapping();
166 InstallFunctions($Object, DONT_ENUM, $Array( 176 InstallFunctions($Object, DONT_ENUM, $Array(
167 "deliverChangeRecords", ObjectDeliverChangeRecords, 177 "deliverChangeRecords", ObjectDeliverChangeRecords,
168 "notify", ObjectNotify, // TODO: Remove when getNotifier is implemented. 178 "notify", ObjectNotify, // TODO: Remove when getNotifier is implemented.
169 "observe", ObjectObserve, 179 "observe", ObjectObserve,
170 "unobserve", ObjectUnobserve 180 "unobserve", ObjectUnobserve
171 )); 181 ));
172 } 182 }
173 183
174 SetupObjectObserve(); 184 SetupObjectObserve();
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698