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

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: whitespace 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') | src/objects.cc » ('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 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;
rossberg 2013/10/30 19:11:45 I think you can write this more concisely as follo
rafaelw 2013/10/30 23:00:30 We need the changeRecord object to have the defaul
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 {
453 changeRecord = {
454 type: type,
455 object: object,
456 name: name,
457 oldValue: oldValue
458 };
459 }
460
449 ObjectFreeze(changeRecord); 461 ObjectFreeze(changeRecord);
450 ObjectInfoEnqueueChangeRecord(objectInfo, changeRecord); 462 ObjectInfoEnqueueChangeRecord(objectInfo, changeRecord);
451 } 463 }
452 464
453 var notifierPrototype = {}; 465 var notifierPrototype = {};
454 466
455 function ObjectNotifierNotify(changeRecord) { 467 function ObjectNotifierNotify(changeRecord) {
456 if (!IS_SPEC_OBJECT(this)) 468 if (!IS_SPEC_OBJECT(this))
457 throw MakeTypeError("called_on_non_object", ["notify"]); 469 throw MakeTypeError("called_on_non_object", ["notify"]);
458 470
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 "observe", ArrayObserve, 571 "observe", ArrayObserve,
560 "unobserve", ArrayUnobserve 572 "unobserve", ArrayUnobserve
561 )); 573 ));
562 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( 574 InstallFunctions(notifierPrototype, DONT_ENUM, $Array(
563 "notify", ObjectNotifierNotify, 575 "notify", ObjectNotifierNotify,
564 "performChange", ObjectNotifierPerformChange 576 "performChange", ObjectNotifierPerformChange
565 )); 577 ));
566 } 578 }
567 579
568 SetupObjectObserve(); 580 SetupObjectObserve();
OLDNEW
« no previous file with comments | « no previous file | src/objects.cc » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698