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

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

Issue 47703003: Make Object.freeze/seal/preventExtensions observable (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: added assert Created 7 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 | src/objects.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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 return true; 127 return true;
128 } 128 }
129 129
130 var defaultAcceptTypes = TypeMapCreateFromList([ 130 var defaultAcceptTypes = TypeMapCreateFromList([
131 'new', 131 'new',
132 'updated', 132 'updated',
133 'deleted', 133 'deleted',
134 'prototype', 134 'prototype',
135 'reconfigured' 135 'reconfigured',
136 'preventExtensions'
136 ]); 137 ]);
137 138
138 // An Observer is a registration to observe an object by a callback with 139 // An Observer is a registration to observe an object by a callback with
139 // a given set of accept types. If the set of accept types is the default 140 // a given set of accept types. If the set of accept types is the default
140 // set for Object.observe, the observer is represented as a direct reference 141 // set for Object.observe, the observer is represented as a direct reference
141 // to the callback. An observer never changes its accept types and thus never 142 // to the callback. An observer never changes its accept types and thus never
142 // needs to "normalize". 143 // needs to "normalize".
143 function ObserverCreate(callback, acceptList) { 144 function ObserverCreate(callback, acceptList) {
144 return IS_UNDEFINED(acceptList) ? callback : { 145 return IS_UNDEFINED(acceptList) ? callback : {
145 __proto__: null, 146 __proto__: null,
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 ObjectFreeze(changeRecord); 437 ObjectFreeze(changeRecord);
437 ObjectFreeze(changeRecord.removed); 438 ObjectFreeze(changeRecord.removed);
438 ObjectInfoEnqueueChangeRecord(objectInfo, changeRecord); 439 ObjectInfoEnqueueChangeRecord(objectInfo, changeRecord);
439 } 440 }
440 441
441 function NotifyChange(type, object, name, oldValue) { 442 function NotifyChange(type, object, name, oldValue) {
442 var objectInfo = objectInfoMap.get(object); 443 var objectInfo = objectInfoMap.get(object);
443 if (!ObjectInfoHasActiveObservers(objectInfo)) 444 if (!ObjectInfoHasActiveObservers(objectInfo))
444 return; 445 return;
445 446
446 var changeRecord = (arguments.length < 4) ? 447 var changeRecord;
447 { type: type, object: object, name: name } : 448 if (arguments.length == 2)
448 { type: type, object: object, name: name, oldValue: oldValue }; 449 changeRecord = { type: type, object: object };
450 else if (arguments.length == 3)
451 changeRecord = { type: type, object: object, name: name };
452 else
adamk 2013/10/29 20:46:08 Please add braces around this clause (and thus aro
rafaelw 2013/10/29 20:56:27 Done.
453 changeRecord = {
454 type: type,
455 object: object,
456 name: name,
457 oldValue: oldValue
458 };
459
449 ObjectFreeze(changeRecord); 460 ObjectFreeze(changeRecord);
450 ObjectInfoEnqueueChangeRecord(objectInfo, changeRecord); 461 ObjectInfoEnqueueChangeRecord(objectInfo, changeRecord);
451 } 462 }
452 463
453 var notifierPrototype = {}; 464 var notifierPrototype = {};
454 465
455 function ObjectNotifierNotify(changeRecord) { 466 function ObjectNotifierNotify(changeRecord) {
456 if (!IS_SPEC_OBJECT(this)) 467 if (!IS_SPEC_OBJECT(this))
457 throw MakeTypeError("called_on_non_object", ["notify"]); 468 throw MakeTypeError("called_on_non_object", ["notify"]);
458 469
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 "observe", ArrayObserve, 570 "observe", ArrayObserve,
560 "unobserve", ArrayUnobserve 571 "unobserve", ArrayUnobserve
561 )); 572 ));
562 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( 573 InstallFunctions(notifierPrototype, DONT_ENUM, $Array(
563 "notify", ObjectNotifierNotify, 574 "notify", ObjectNotifierNotify,
564 "performChange", ObjectNotifierPerformChange 575 "performChange", ObjectNotifierPerformChange
565 )); 576 ));
566 } 577 }
567 578
568 SetupObjectObserve(); 579 SetupObjectObserve();
OLDNEW
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698