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

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

Issue 11361172: Fix InternalObjectHashTable to properly update table ref in observationState (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added test case 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 | « no previous file | test/cctest/test-object-observe.cc » ('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 20 matching lines...) Expand all
31 var InternalObjectFreeze = $Object.freeze; 31 var InternalObjectFreeze = $Object.freeze;
32 32
33 var observationState = %GetObservationState(); 33 var observationState = %GetObservationState();
34 if (IS_UNDEFINED(observationState.observerInfoMap)) { 34 if (IS_UNDEFINED(observationState.observerInfoMap)) {
35 observationState.observerInfoMap = %CreateObjectHashTable(); 35 observationState.observerInfoMap = %CreateObjectHashTable();
36 observationState.objectInfoMap = %CreateObjectHashTable(); 36 observationState.objectInfoMap = %CreateObjectHashTable();
37 observationState.activeObservers = new InternalArray; 37 observationState.activeObservers = new InternalArray;
38 observationState.observerPriority = 0; 38 observationState.observerPriority = 0;
39 } 39 }
40 40
41 function InternalObjectHashTable(table) { 41 function InternalObjectHashTable(tableName) {
42 this.table = table; 42 this.tableName = tableName;
43 } 43 }
44 44
45 InternalObjectHashTable.prototype = { 45 InternalObjectHashTable.prototype = {
46 get: function(key) { 46 get: function(key) {
47 return %ObjectHashTableGet(this.table, key); 47 return %ObjectHashTableGet(observationState[this.tableName], key);
48 }, 48 },
49 set: function(key, value) { 49 set: function(key, value) {
50 this.table = %ObjectHashTableSet(this.table, key, value); 50 observationState[this.tableName] =
51 %ObjectHashTableSet(observationState[this.tableName], key, value);
51 }, 52 },
52 has: function(key) { 53 has: function(key) {
53 return %ObjectHashTableHas(this.table, key); 54 return %ObjectHashTableHas(observationState[this.tableName], key);
54 } 55 }
55 }; 56 };
56 57
57 var observerInfoMap = new InternalObjectHashTable( 58 var observerInfoMap = new InternalObjectHashTable('observerInfoMap');
58 observationState.observerInfoMap); 59 var objectInfoMap = new InternalObjectHashTable('objectInfoMap');
59 var objectInfoMap = new InternalObjectHashTable(observationState.objectInfoMap);
60 60
61 function ObjectObserve(object, callback) { 61 function ObjectObserve(object, callback) {
62 if (!IS_SPEC_OBJECT(object)) 62 if (!IS_SPEC_OBJECT(object))
63 throw MakeTypeError("observe_non_object", ["observe"]); 63 throw MakeTypeError("observe_non_object", ["observe"]);
64 if (!IS_SPEC_FUNCTION(callback)) 64 if (!IS_SPEC_FUNCTION(callback))
65 throw MakeTypeError("observe_non_function", ["observe"]); 65 throw MakeTypeError("observe_non_function", ["observe"]);
66 if (InternalObjectIsFrozen(callback)) 66 if (InternalObjectIsFrozen(callback))
67 throw MakeTypeError("observe_callback_frozen"); 67 throw MakeTypeError("observe_callback_frozen");
68 68
69 if (!observerInfoMap.has(callback)) { 69 if (!observerInfoMap.has(callback)) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 %CheckIsBootstrapping(); 190 %CheckIsBootstrapping();
191 InstallFunctions($Object, DONT_ENUM, $Array( 191 InstallFunctions($Object, DONT_ENUM, $Array(
192 "deliverChangeRecords", ObjectDeliverChangeRecords, 192 "deliverChangeRecords", ObjectDeliverChangeRecords,
193 "notify", ObjectNotify, // TODO: Remove when getNotifier is implemented. 193 "notify", ObjectNotify, // TODO: Remove when getNotifier is implemented.
194 "observe", ObjectObserve, 194 "observe", ObjectObserve,
195 "unobserve", ObjectUnobserve 195 "unobserve", ObjectUnobserve
196 )); 196 ));
197 } 197 }
198 198
199 SetupObjectObserve(); 199 SetupObjectObserve();
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-object-observe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698