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

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: cr comments 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 ObjectFreeze(changeRecord); 457 ObjectFreeze(changeRecord);
457 ObjectFreeze(changeRecord.removed); 458 ObjectFreeze(changeRecord.removed);
458 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord); 459 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord);
459 } 460 }
460 461
461 function NotifyChange(type, object, name, oldValue) { 462 function NotifyChange(type, object, name, oldValue) {
462 var objectInfo = objectInfoMap.get(object); 463 var objectInfo = objectInfoMap.get(object);
463 if (!ObjectInfoHasActiveObservers(objectInfo)) 464 if (!ObjectInfoHasActiveObservers(objectInfo))
464 return; 465 return;
465 466
466 var changeRecord = (arguments.length < 4) ? 467 var changeRecord;
467 { type: type, object: object, name: name } : 468 if (arguments.length == 2) {
468 { type: type, object: object, name: name, oldValue: oldValue }; 469 changeRecord = { type: type, object: object };
470 } else if (arguments.length == 3) {
471 changeRecord = { type: type, object: object, name: name };
472 } else {
473 changeRecord = {
474 type: type,
475 object: object,
476 name: name,
477 oldValue: oldValue
478 };
479 }
480
469 ObjectFreeze(changeRecord); 481 ObjectFreeze(changeRecord);
470 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord); 482 ObjectInfoEnqueueInternalChangeRecord(objectInfo, changeRecord);
471 } 483 }
472 484
473 var notifierPrototype = {}; 485 var notifierPrototype = {};
474 486
475 function ObjectNotifierNotify(changeRecord) { 487 function ObjectNotifierNotify(changeRecord) {
476 if (!IS_SPEC_OBJECT(this)) 488 if (!IS_SPEC_OBJECT(this))
477 throw MakeTypeError("called_on_non_object", ["notify"]); 489 throw MakeTypeError("called_on_non_object", ["notify"]);
478 490
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 "observe", ArrayObserve, 584 "observe", ArrayObserve,
573 "unobserve", ArrayUnobserve 585 "unobserve", ArrayUnobserve
574 )); 586 ));
575 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( 587 InstallFunctions(notifierPrototype, DONT_ENUM, $Array(
576 "notify", ObjectNotifierNotify, 588 "notify", ObjectNotifierNotify,
577 "performChange", ObjectNotifierPerformChange 589 "performChange", ObjectNotifierPerformChange
578 )); 590 ));
579 } 591 }
580 592
581 SetupObjectObserve(); 593 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