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

Unified Diff: lib/runtime/dart/async.js

Issue 1069493002: implement opassign, fix bugs in pre/postfix, introduce a let* helper (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: lib/runtime/dart/async.js
diff --git a/lib/runtime/dart/async.js b/lib/runtime/dart/async.js
index 45974063fdb3476eddafb39bd4cd4ce9a132fdbd..80bbe5ed214054d2838a6c63f3c833b9f178b190 100644
--- a/lib/runtime/dart/async.js
+++ b/lib/runtime/dart/async.js
@@ -43,7 +43,7 @@ var async;
toString() {
let result = `Uncaught Error: ${this.error}`;
if (this.stackTrace != null) {
- result = `\nStack Trace:\n${this.stackTrace}`;
+ result = core.String['+'](result, `\nStack Trace:\n${this.stackTrace}`);
}
return result;
}
@@ -90,7 +90,7 @@ var async;
// Function sendEvent: () → void
function sendEvent() {
watch.reset();
- let data = computation(((x) => computationCount = dart.notNull(x) + 1, x)(computationCount));
+ let data = computation(((x) => (x = computationCount, computationCount = dart.notNull(x) + 1, x))());
controller.add(data);
}
// Function startPeriodicTimer: () → void
@@ -689,7 +689,7 @@ var async;
_cancelAndValue(subscription, future, value);
return;
}
- elementIndex = 1;
+ elementIndex = dart.notNull(elementIndex) + 1;
}, {
onError: future[_completeError],
onDone: (() => {
@@ -903,7 +903,7 @@ var async;
return;
this[_pending] = pendingEvents;
if (!dart.notNull(pendingEvents.isEmpty)) {
- this[_state] = _BufferingStreamSubscription[_STATE_HAS_PENDING];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription[_STATE_HAS_PENDING]);
this[_pending].schedule(this);
}
}
@@ -953,7 +953,7 @@ var async;
this[_pending].schedule(this);
} else {
dart.assert(this[_mayResumeInput]);
- this[_state] = ~dart.notNull(_BufferingStreamSubscription[_STATE_INPUT_PAUSED]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStreamSubscription[_STATE_INPUT_PAUSED]);
if (!dart.notNull(this[_inCallback]))
this[_guardCallback](this[_onResume]);
}
@@ -961,7 +961,7 @@ var async;
}
}
cancel() {
- this[_state] = ~dart.notNull(_BufferingStreamSubscription[_STATE_WAIT_FOR_CANCEL]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStreamSubscription[_STATE_WAIT_FOR_CANCEL]);
if (this[_isCanceled])
return this[_cancelFuture];
this[_cancel]();
@@ -1014,7 +1014,7 @@ var async;
return this[_isPaused];
}
[_cancel]() {
- this[_state] = _BufferingStreamSubscription[_STATE_CANCELED];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription[_STATE_CANCELED]);
if (this[_hasPending]) {
this[_pending].cancelSchedule();
}
@@ -1027,7 +1027,7 @@ var async;
}
[_decrementPauseCount]() {
dart.assert(this[_isPaused]);
- this[_state] = _BufferingStreamSubscription[_STATE_PAUSE_COUNT];
+ this[_state] = dart.notNull(this[_state]) - dart.notNull(_BufferingStreamSubscription[_STATE_PAUSE_COUNT]);
}
[_add](data) {
dart.assert(!dart.notNull(this[_isClosed]));
@@ -1052,7 +1052,7 @@ var async;
dart.assert(!dart.notNull(this[_isClosed]));
if (this[_isCanceled])
return;
- this[_state] = _BufferingStreamSubscription[_STATE_CLOSED];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription[_STATE_CLOSED]);
if (this[_canFire]) {
this[_sendDone]();
} else {
@@ -1075,7 +1075,7 @@ var async;
pending = this[_pending] = new _StreamImplEvents();
pending.add(event);
if (!dart.notNull(this[_hasPending])) {
- this[_state] = _BufferingStreamSubscription[_STATE_HAS_PENDING];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription[_STATE_HAS_PENDING]);
if (!dart.notNull(this[_isPaused])) {
this[_pending].schedule(this);
}
@@ -1086,9 +1086,9 @@ var async;
dart.assert(!dart.notNull(this[_isPaused]));
dart.assert(!dart.notNull(this[_inCallback]));
let wasInputPaused = this[_isInputPaused];
- this[_state] = _BufferingStreamSubscription[_STATE_IN_CALLBACK];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
this[_zone].runUnaryGuarded(this[_onData], data);
- this[_state] = ~dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
this[_checkState](wasInputPaused);
}
[_sendError](error, stackTrace) {
@@ -1100,16 +1100,16 @@ var async;
function sendError() {
if (dart.notNull(this[_isCanceled]) && !dart.notNull(this[_waitsForCancel]))
return;
- this[_state] = _BufferingStreamSubscription[_STATE_IN_CALLBACK];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
if (dart.is(this[_onError], ZoneBinaryCallback)) {
this[_zone].runBinaryGuarded(dart.as(this[_onError], dart.throw_("Unimplemented type (dynamic, dynamic) → dynamic")), error, stackTrace);
} else {
this[_zone].runUnaryGuarded(dart.as(this[_onError], dart.throw_("Unimplemented type (dynamic) → dynamic")), error);
}
- this[_state] = ~dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
}
if (this[_cancelOnError]) {
- this[_state] = _BufferingStreamSubscription[_STATE_WAIT_FOR_CANCEL];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription[_STATE_WAIT_FOR_CANCEL]);
this[_cancel]();
if (dart.is(this[_cancelFuture], Future)) {
this[_cancelFuture].whenComplete(sendError);
@@ -1129,12 +1129,12 @@ var async;
function sendDone() {
if (!dart.notNull(this[_waitsForCancel]))
return;
- this[_state] = dart.notNull(_BufferingStreamSubscription[_STATE_CANCELED]) | dart.notNull(_BufferingStreamSubscription[_STATE_CLOSED]) | dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription[_STATE_CANCELED]) | dart.notNull(_BufferingStreamSubscription[_STATE_CLOSED]) | dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
this[_zone].runGuarded(this[_onDone]);
- this[_state] = ~dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
}
this[_cancel]();
- this[_state] = _BufferingStreamSubscription[_STATE_WAIT_FOR_CANCEL];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription[_STATE_WAIT_FOR_CANCEL]);
if (dart.is(this[_cancelFuture], Future)) {
this[_cancelFuture].whenComplete(sendDone);
} else {
@@ -1144,17 +1144,17 @@ var async;
[_guardCallback](callback) {
dart.assert(!dart.notNull(this[_inCallback]));
let wasInputPaused = this[_isInputPaused];
- this[_state] = _BufferingStreamSubscription[_STATE_IN_CALLBACK];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
dart.dinvokef(callback);
- this[_state] = ~dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
this[_checkState](wasInputPaused);
}
[_checkState](wasInputPaused) {
dart.assert(!dart.notNull(this[_inCallback]));
if (dart.notNull(this[_hasPending]) && dart.notNull(this[_pending].isEmpty)) {
- this[_state] = ~dart.notNull(_BufferingStreamSubscription[_STATE_HAS_PENDING]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStreamSubscription[_STATE_HAS_PENDING]);
if (dart.notNull(this[_isInputPaused]) && dart.notNull(this[_mayResumeInput])) {
- this[_state] = ~dart.notNull(_BufferingStreamSubscription[_STATE_INPUT_PAUSED]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStreamSubscription[_STATE_INPUT_PAUSED]);
}
}
while (true) {
@@ -1165,13 +1165,13 @@ var async;
let isInputPaused = this[_isInputPaused];
if (wasInputPaused == isInputPaused)
break;
- this[_state] = _BufferingStreamSubscription[_STATE_IN_CALLBACK];
+ this[_state] = dart.notNull(this[_state]) ^ dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
if (isInputPaused) {
this[_onPause]();
} else {
this[_onResume]();
}
- this[_state] = ~dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStreamSubscription[_STATE_IN_CALLBACK]);
wasInputPaused = isInputPaused;
}
if (dart.notNull(this[_hasPending]) && !dart.notNull(this[_isPaused])) {
@@ -1227,14 +1227,14 @@ var async;
return (dart.notNull(this[_eventState]) & dart.notNull(_BroadcastSubscription[_STATE_EVENT_ID])) == eventId;
}
[_toggleEventId]() {
- this[_eventState] = _BroadcastSubscription[_STATE_EVENT_ID];
+ this[_eventState] = dart.notNull(this[_eventState]) ^ dart.notNull(_BroadcastSubscription[_STATE_EVENT_ID]);
}
get [_isFiring]() {
return (dart.notNull(this[_eventState]) & dart.notNull(_BroadcastSubscription[_STATE_FIRING])) != 0;
}
[_setRemoveAfterFiring]() {
dart.assert(this[_isFiring]);
- this[_eventState] = _BroadcastSubscription[_STATE_REMOVE_AFTER_FIRING];
+ this[_eventState] = dart.notNull(this[_eventState]) | dart.notNull(_BroadcastSubscription[_STATE_REMOVE_AFTER_FIRING]);
}
get [_removeAfterFiring]() {
return (dart.notNull(this[_eventState]) & dart.notNull(_BroadcastSubscription[_STATE_REMOVE_AFTER_FIRING])) != 0;
@@ -1392,7 +1392,7 @@ var async;
}
if (!dart.notNull(this[_mayAddEvent]))
throw this[_addEventError]();
- this[_state] = _BroadcastStreamController[_STATE_CLOSED];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BroadcastStreamController[_STATE_CLOSED]);
let doneFuture = this[_ensureDoneFuture]();
this[_sendDone]();
return doneFuture;
@@ -1404,7 +1404,7 @@ var async;
let cancelOnError = opts && 'cancelOnError' in opts ? opts.cancelOnError : true;
if (!dart.notNull(this[_mayAddEvent]))
throw this[_addEventError]();
- this[_state] = _BroadcastStreamController[_STATE_ADDSTREAM];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BroadcastStreamController[_STATE_ADDSTREAM]);
this[_addStreamState] = dart.as(new _AddStreamState(this, stream, cancelOnError), _AddStreamState$(T));
return this[_addStreamState].addStreamFuture;
}
@@ -1418,7 +1418,7 @@ var async;
dart.assert(this[_isAddingStream]);
let addState = this[_addStreamState];
this[_addStreamState] = null;
- this[_state] = ~dart.notNull(_BroadcastStreamController[_STATE_ADDSTREAM]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BroadcastStreamController[_STATE_ADDSTREAM]);
addState.complete();
}
[_forEachListener](action) {
@@ -1428,24 +1428,24 @@ var async;
if (this[_isEmpty])
return;
let id = dart.notNull(this[_state]) & dart.notNull(_BroadcastStreamController[_STATE_EVENT_ID]);
- this[_state] = dart.notNull(_BroadcastStreamController[_STATE_EVENT_ID]) | dart.notNull(_BroadcastStreamController[_STATE_FIRING]);
+ this[_state] = dart.notNull(this[_state]) ^ (dart.notNull(_BroadcastStreamController[_STATE_EVENT_ID]) | dart.notNull(_BroadcastStreamController[_STATE_FIRING]));
let link = this[_next];
while (!dart.notNull(core.identical(link, this))) {
let subscription = dart.as(link, _BroadcastSubscription$(T));
if (subscription[_expectsEvent](id)) {
- subscription[_eventState] = _BroadcastSubscription[_STATE_FIRING];
+ subscription[_eventState] = dart.notNull(subscription[_eventState]) | dart.notNull(_BroadcastSubscription[_STATE_FIRING]);
action(subscription);
subscription[_toggleEventId]();
link = subscription[_next];
if (subscription[_removeAfterFiring]) {
this[_removeListener](subscription);
}
- subscription[_eventState] = ~dart.notNull(_BroadcastSubscription[_STATE_FIRING]);
+ subscription[_eventState] = dart.notNull(subscription[_eventState]) & ~dart.notNull(_BroadcastSubscription[_STATE_FIRING]);
} else {
link = subscription[_next];
}
}
- this[_state] = ~dart.notNull(_BroadcastStreamController[_STATE_FIRING]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BroadcastStreamController[_STATE_FIRING]);
if (this[_isEmpty]) {
this[_callOnCancel]();
}
@@ -1476,10 +1476,10 @@ var async;
if (this[_isEmpty])
return;
if (this[_hasOneListener]) {
- this[_state] = _BroadcastStreamController[_STATE_FIRING];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BroadcastStreamController[_STATE_FIRING]);
let subscription = dart.as(this[_next], _BroadcastSubscription);
subscription[_add](data);
- this[_state] = ~dart.notNull(_BroadcastStreamController[_STATE_FIRING]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BroadcastStreamController[_STATE_FIRING]);
if (this[_isEmpty]) {
this[_callOnCancel]();
}
@@ -1587,7 +1587,7 @@ var async;
close() {
if (!dart.notNull(this.isClosed) && dart.notNull(this[_isFiring])) {
this[_addPendingEvent](new _DelayedDone());
- this[_state] = _BroadcastStreamController[_STATE_CLOSED];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_BroadcastStreamController[_STATE_CLOSED]);
return super.done;
}
let result = super.close();
@@ -1627,8 +1627,9 @@ var async;
this[_resume](null);
}
[_resume](_) {
- if (dart.notNull(this[_pauseCount]) > 0)
+ if (dart.notNull(this[_pauseCount]) > 0) {
this[_pauseCount] = dart.notNull(this[_pauseCount]) - 1;
+ }
}
cancel() {
return new _Future.immediate(null);
@@ -1771,7 +1772,8 @@ var async;
}
}
for (let future of futures) {
- let pos = ((x) => remaining = dart.notNull(x) + 1, x)(remaining);
+ let pos = remaining;
+ remaining = dart.notNull(pos) + 1;
future.then((value) => {
remaining = dart.notNull(remaining) - 1;
if (values != null) {
@@ -2824,7 +2826,7 @@ var async;
return new _Future.immediate(null);
let addState = new _StreamControllerAddStreamState(this, this[_varData], source, cancelOnError);
this[_varData] = addState;
- this[_state] = _StreamController[_STATE_ADDSTREAM];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_StreamController[_STATE_ADDSTREAM]);
return addState.addStreamFuture;
}
get done() {
@@ -2864,7 +2866,7 @@ var async;
return this[_ensureDoneFuture]();
}
[_closeUnchecked]() {
- this[_state] = _StreamController[_STATE_CLOSED];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_StreamController[_STATE_CLOSED]);
if (this.hasListener) {
this[_sendDone]();
} else if (this[_isInitialState]) {
@@ -2889,7 +2891,7 @@ var async;
dart.assert(this[_isAddingStream]);
let addState = dart.as(this[_varData], _StreamControllerAddStreamState);
this[_varData] = addState.varData;
- this[_state] = ~dart.notNull(_StreamController[_STATE_ADDSTREAM]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_StreamController[_STATE_ADDSTREAM]);
addState.complete();
}
[_subscribe](onData, onError, onDone, cancelOnError) {
@@ -2898,7 +2900,7 @@ var async;
}
let subscription = new _ControllerSubscription(this, onData, onError, onDone, cancelOnError);
let pendingEvents = this[_pendingEvents];
- this[_state] = _StreamController[_STATE_SUBSCRIBED];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_StreamController[_STATE_SUBSCRIBED]);
if (this[_isAddingStream]) {
let addState = dart.as(this[_varData], _StreamControllerAddStreamState);
addState.varData = subscription;
@@ -2926,10 +2928,8 @@ var async;
result = dart.as(this[_onCancel](), Future);
} catch (e) {
let s = dart.stackTrace(e);
- result = ((_$) => {
- _$[_asyncCompleteError](e, s);
- return _$;
- })(new _Future());
+ result = new _Future();
+ result[_asyncCompleteError](e, s);
}
} else {
@@ -3164,10 +3164,9 @@ var async;
if (this[_isUsed])
throw new core.StateError("Stream has already been listened to.");
this[_isUsed] = true;
- return ((_$) => {
- _$[_setPendingEvents](this[_pending]());
- return _$;
- }).bind(this)(new _BufferingStreamSubscription(onData, onError, onDone, cancelOnError));
+ let _$ = new _BufferingStreamSubscription(onData, onError, onDone, cancelOnError);
+ _$[_setPendingEvents](this[_pending]());
+ return _$;
}
}
return _GeneratedStreamImpl;
@@ -3391,7 +3390,7 @@ var async;
if (this[_isScheduled])
return;
this[_zone].scheduleMicrotask(this[_sendDone]);
- this[_state] = _DoneStreamSubscription[_SCHEDULED];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_DoneStreamSubscription[_SCHEDULED]);
}
onData(handleData) {}
onError(handleError) {}
@@ -3401,13 +3400,13 @@ var async;
pause(resumeSignal) {
if (resumeSignal === void 0)
resumeSignal = null;
- this[_state] = _DoneStreamSubscription[_PAUSED];
+ this[_state] = dart.notNull(this[_state]) + dart.notNull(_DoneStreamSubscription[_PAUSED]);
if (resumeSignal != null)
resumeSignal.whenComplete(this.resume);
}
resume() {
if (this.isPaused) {
- this[_state] = _DoneStreamSubscription[_PAUSED];
+ this[_state] = dart.notNull(this[_state]) - dart.notNull(_DoneStreamSubscription[_PAUSED]);
if (!dart.notNull(this.isPaused) && !dart.notNull(this[_isSent])) {
this[_schedule]();
}
@@ -3426,10 +3425,10 @@ var async;
return result;
}
[_sendDone]() {
- this[_state] = ~dart.notNull(_DoneStreamSubscription[_SCHEDULED]);
+ this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_DoneStreamSubscription[_SCHEDULED]);
if (this.isPaused)
return;
- this[_state] = _DoneStreamSubscription[_DONE_SENT];
+ this[_state] = dart.notNull(this[_state]) | dart.notNull(_DoneStreamSubscription[_DONE_SENT]);
if (this[_onDone] != null)
this[_zone].runGuarded(this[_onDone]);
}
@@ -3959,7 +3958,7 @@ var async;
[_handleData](inputEvent, sink) {
if (dart.notNull(this[_remaining]) > 0) {
sink[_add](inputEvent);
- this[_remaining] = 1;
+ this[_remaining] = dart.notNull(this[_remaining]) - 1;
if (this[_remaining] == 0) {
sink[_close]();
}

Powered by Google App Engine
This is Rietveld 408576698