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

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

Issue 11347037: Object.observe: generate change records for named properties. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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/ic.cc ('k') | src/objects.h » ('j') | src/objects.h » ('J')
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 }); 61 });
62 } 62 }
63 63
64 var objectInfo = objectInfoMap.get(object); 64 var objectInfo = objectInfoMap.get(object);
65 if (IS_UNDEFINED(objectInfo)) { 65 if (IS_UNDEFINED(objectInfo)) {
66 // TODO: setup objectInfo.notifier 66 // TODO: setup objectInfo.notifier
67 objectInfo = { 67 objectInfo = {
68 changeObservers: new InternalArray(callback) 68 changeObservers: new InternalArray(callback)
69 }; 69 };
70 objectInfoMap.set(object, objectInfo); 70 objectInfoMap.set(object, objectInfo);
71 %SetIsObserved(object, true);
71 return; 72 return;
72 } 73 }
rafaelw 2012/10/31 14:44:31 do we have JS debug-only ASSERTS? If so, it'd be n
rossberg 2012/11/05 17:11:08 Unfortunately, no.
73 74
74 var changeObservers = objectInfo.changeObservers; 75 var changeObservers = objectInfo.changeObservers;
75 if (changeObservers.indexOf(callback) >= 0) 76 if (changeObservers.indexOf(callback) >= 0)
76 return; 77 return;
77 78
78 changeObservers.push(callback); 79 changeObservers.push(callback);
79 } 80 }
80 81
81 function ObjectUnobserve(object, callback) { 82 function ObjectUnobserve(object, callback) {
82 if (!IS_SPEC_OBJECT(object)) 83 if (!IS_SPEC_OBJECT(object))
(...skipping 19 matching lines...) Expand all
102 // TODO: "activate" the observer 103 // TODO: "activate" the observer
103 104
104 if (IS_NULL(observerInfo.pendingChangeRecords)) { 105 if (IS_NULL(observerInfo.pendingChangeRecords)) {
105 observerInfo.pendingChangeRecords = new InternalArray(changeRecord); 106 observerInfo.pendingChangeRecords = new InternalArray(changeRecord);
106 } else { 107 } else {
107 observerInfo.pendingChangeRecords.push(changeRecord); 108 observerInfo.pendingChangeRecords.push(changeRecord);
108 } 109 }
109 } 110 }
110 } 111 }
111 112
113 function NotifyChange(type, object, name, oldValue) {
114 var objectInfo = objectInfoMap.get(object);
115 if (IS_UNDEFINED(objectInfo)) return;
rafaelw 2012/10/31 14:44:31 Seems like we should CHECK() here - can we crash f
rossberg 2012/11/05 17:11:08 There is no direct way to do that, but I just remo
116
117 var changeRecord = { type: type, object: object, name: name };
118 if (arguments.length == 4) changeRecord.oldValue = oldValue;
rafaelw 2012/10/31 14:44:31 For safety, I think that you should switch on argu
rossberg 2012/11/05 17:11:08 Done.
119 InternalObjectFreeze(changeRecord);
120 EnqueueChangeRecord(changeRecord, objectInfo.changeObservers);
121 }
122
112 function ObjectNotify(object, changeRecord) { 123 function ObjectNotify(object, changeRecord) {
113 // TODO: notifier needs to be [[THIS]] 124 // TODO: notifier needs to be [[THIS]]
114 if (!IS_STRING(changeRecord.type)) 125 if (!IS_STRING(changeRecord.type))
115 throw MakeTypeError("observe_type_non_string"); 126 throw MakeTypeError("observe_type_non_string");
116 127
117 var objectInfo = objectInfoMap.get(object); 128 var objectInfo = objectInfoMap.get(object);
118 if (IS_UNDEFINED(objectInfo)) 129 if (IS_UNDEFINED(objectInfo))
119 return; 130 return;
120 131
121 var newRecord = { 132 var newRecord = {
122 object: object // TODO: Needs to be 'object' retreived from notifier 133 object: object // TODO: Needs to be 'object' retrieved from notifier
123 }; 134 };
124 for (var prop in changeRecord) { 135 for (var prop in changeRecord) {
125 if (prop === 'object') 136 if (prop === 'object')
126 continue; 137 continue;
127 newRecord[prop] = changeRecord[prop]; 138 newRecord[prop] = changeRecord[prop];
128 } 139 }
129 InternalObjectFreeze(newRecord); 140 InternalObjectFreeze(newRecord);
130 141
131 EnqueueChangeRecord(newRecord, objectInfo.changeObservers); 142 EnqueueChangeRecord(newRecord, objectInfo.changeObservers);
132 } 143 }
(...skipping 21 matching lines...) Expand all
154 function SetupObjectObserve() { 165 function SetupObjectObserve() {
155 %CheckIsBootstrapping(); 166 %CheckIsBootstrapping();
156 InstallFunctions($Object, DONT_ENUM, $Array( 167 InstallFunctions($Object, DONT_ENUM, $Array(
157 "deliverChangeRecords", ObjectDeliverChangeRecords, 168 "deliverChangeRecords", ObjectDeliverChangeRecords,
158 "notify", ObjectNotify, // TODO: Remove when getNotifier is implemented. 169 "notify", ObjectNotify, // TODO: Remove when getNotifier is implemented.
159 "observe", ObjectObserve, 170 "observe", ObjectObserve,
160 "unobserve", ObjectUnobserve 171 "unobserve", ObjectUnobserve
161 )); 172 ));
162 } 173 }
163 174
164 SetupObjectObserve(); 175 SetupObjectObserve();
OLDNEW
« no previous file with comments | « src/ic.cc ('k') | src/objects.h » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698