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

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

Issue 150103012: Revert "Implement Microtask Delivery Queue" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 months 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/promise.js » ('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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // implementation of (1) and (2) have "optimized" states which represent 56 // implementation of (1) and (2) have "optimized" states which represent
57 // common cases which can be handled more efficiently. 57 // common cases which can be handled more efficiently.
58 58
59 var observationState = %GetObservationState(); 59 var observationState = %GetObservationState();
60 if (IS_UNDEFINED(observationState.callbackInfoMap)) { 60 if (IS_UNDEFINED(observationState.callbackInfoMap)) {
61 observationState.callbackInfoMap = %ObservationWeakMapCreate(); 61 observationState.callbackInfoMap = %ObservationWeakMapCreate();
62 observationState.objectInfoMap = %ObservationWeakMapCreate(); 62 observationState.objectInfoMap = %ObservationWeakMapCreate();
63 observationState.notifierObjectInfoMap = %ObservationWeakMapCreate(); 63 observationState.notifierObjectInfoMap = %ObservationWeakMapCreate();
64 observationState.pendingObservers = null; 64 observationState.pendingObservers = null;
65 observationState.nextCallbackPriority = 0; 65 observationState.nextCallbackPriority = 0;
66 observationState.microtaskScheduled = false;
67 } 66 }
68 67
69 function ObservationWeakMap(map) { 68 function ObservationWeakMap(map) {
70 this.map_ = map; 69 this.map_ = map;
71 } 70 }
72 71
73 ObservationWeakMap.prototype = { 72 ObservationWeakMap.prototype = {
74 get: function(key) { 73 get: function(key) {
75 key = %UnwrapGlobalProxy(key); 74 key = %UnwrapGlobalProxy(key);
76 if (!IS_SPEC_OBJECT(key)) return UNDEFINED; 75 if (!IS_SPEC_OBJECT(key)) return UNDEFINED;
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 !%IsAccessAllowedForObserver( 387 !%IsAccessAllowedForObserver(
389 callback, changeRecord.object, changeRecord.name))) { 388 callback, changeRecord.object, changeRecord.name))) {
390 return; 389 return;
391 } 390 }
392 391
393 var callbackInfo = CallbackInfoNormalize(callback); 392 var callbackInfo = CallbackInfoNormalize(callback);
394 if (!observationState.pendingObservers) 393 if (!observationState.pendingObservers)
395 observationState.pendingObservers = nullProtoObject(); 394 observationState.pendingObservers = nullProtoObject();
396 observationState.pendingObservers[callbackInfo.priority] = callback; 395 observationState.pendingObservers[callbackInfo.priority] = callback;
397 callbackInfo.push(changeRecord); 396 callbackInfo.push(changeRecord);
398 EnqueueObserveMicrotask(); 397 %SetMicrotaskPending(true);
399 } 398 }
400 399
401 function ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, type) { 400 function ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord, type) {
402 if (!ObjectInfoHasActiveObservers(objectInfo)) 401 if (!ObjectInfoHasActiveObservers(objectInfo))
403 return; 402 return;
404 403
405 var hasType = !IS_UNDEFINED(type); 404 var hasType = !IS_UNDEFINED(type);
406 var newRecord = hasType ? 405 var newRecord = hasType ?
407 { object: ObjectInfoGetObject(objectInfo), type: type } : 406 { object: ObjectInfoGetObject(objectInfo), type: type } :
408 { object: ObjectInfoGetObject(objectInfo) }; 407 { object: ObjectInfoGetObject(objectInfo) };
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 } 568 }
570 569
571 function ObjectDeliverChangeRecords(callback) { 570 function ObjectDeliverChangeRecords(callback) {
572 if (!IS_SPEC_FUNCTION(callback)) 571 if (!IS_SPEC_FUNCTION(callback))
573 throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]); 572 throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]);
574 573
575 while (CallbackDeliverPending(callback)) {} 574 while (CallbackDeliverPending(callback)) {}
576 } 575 }
577 576
578 function ObserveMicrotaskRunner() { 577 function ObserveMicrotaskRunner() {
579 observationState.microtaskScheduled = false;
580 var pendingObservers = observationState.pendingObservers; 578 var pendingObservers = observationState.pendingObservers;
581 if (pendingObservers) { 579 if (pendingObservers) {
582 observationState.pendingObservers = null; 580 observationState.pendingObservers = null;
583 for (var i in pendingObservers) { 581 for (var i in pendingObservers) {
584 CallbackDeliverPending(pendingObservers[i]); 582 CallbackDeliverPending(pendingObservers[i]);
585 } 583 }
586 } 584 }
587 } 585 }
588 586 RunMicrotasks.runners.push(ObserveMicrotaskRunner);
589 function EnqueueObserveMicrotask() {
590 if (observationState.microtaskScheduled)
591 return;
592
593 RunMicrotasks.queue.push(ObserveMicrotaskRunner);
594 %SetMicrotaskPending(true);
595 observationState.microtaskScheduled = true;
596 }
597 587
598 function SetupObjectObserve() { 588 function SetupObjectObserve() {
599 %CheckIsBootstrapping(); 589 %CheckIsBootstrapping();
600 InstallFunctions($Object, DONT_ENUM, $Array( 590 InstallFunctions($Object, DONT_ENUM, $Array(
601 "deliverChangeRecords", ObjectDeliverChangeRecords, 591 "deliverChangeRecords", ObjectDeliverChangeRecords,
602 "getNotifier", ObjectGetNotifier, 592 "getNotifier", ObjectGetNotifier,
603 "observe", ObjectObserve, 593 "observe", ObjectObserve,
604 "unobserve", ObjectUnobserve 594 "unobserve", ObjectUnobserve
605 )); 595 ));
606 InstallFunctions($Array, DONT_ENUM, $Array( 596 InstallFunctions($Array, DONT_ENUM, $Array(
607 "observe", ArrayObserve, 597 "observe", ArrayObserve,
608 "unobserve", ArrayUnobserve 598 "unobserve", ArrayUnobserve
609 )); 599 ));
610 InstallFunctions(notifierPrototype, DONT_ENUM, $Array( 600 InstallFunctions(notifierPrototype, DONT_ENUM, $Array(
611 "notify", ObjectNotifierNotify, 601 "notify", ObjectNotifierNotify,
612 "performChange", ObjectNotifierPerformChange 602 "performChange", ObjectNotifierPerformChange
613 )); 603 ));
614 } 604 }
615 605
616 SetupObjectObserve(); 606 SetupObjectObserve();
OLDNEW
« no previous file with comments | « no previous file | src/promise.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698