Skip to content

Commit

Permalink
fixes #177, FunctionDeclarationStatement and closing over this
Browse files Browse the repository at this point in the history
R=vsm@google.com

Review URL: https://codereview.chromium.org/1132113003
  • Loading branch information
John Messerly committed May 8, 2015
1 parent ef8edb1 commit a7c8601
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 86 deletions.
20 changes: 10 additions & 10 deletions pkg/dev_compiler/lib/runtime/dart/_isolate_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,9 @@ var async = dart.import(async);
return;
}
// Function respond: () → void
function respond() {
let respond = () => {
responsePort.send(null);
}
};
if (pingType == isolate.Isolate.AS_EVENT) {
exports._globalState.topEventLoop.enqueue(this, respond, "ping");
return;
Expand Down Expand Up @@ -779,11 +779,11 @@ var async = dart.import(async);
[_runHelper]() {
if (exports.globalWindow != null) {
// Function next: () → void
function next() {
let next = (() => {
if (!dart.notNull(this.runIteration()))
return;
async.Timer.run(next);
}
}).bind(this);
next();
} else {
while (this.runIteration()) {
Expand Down Expand Up @@ -1059,7 +1059,7 @@ var async = dart.import(async);
_js_helper.Primitives.initializeStatics(context.id);
replyTo.send([_SPAWNED_SIGNAL, context.controlPort.sendPort, context.pauseCapability, context.terminateCapability]);
// Function runStartFunction: () → void
function runStartFunction() {
let runStartFunction = () => {
context.initialized = true;
if (!dart.notNull(isSpawnUri)) {
dart.dcall(topLevel, message);
Expand All @@ -1070,7 +1070,7 @@ var async = dart.import(async);
} else {
dart.dcall(topLevel);
}
}
};
if (startPaused) {
context.addPause(context.pauseCapability, context.pauseCapability);
exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'start isolate');
Expand Down Expand Up @@ -1290,20 +1290,20 @@ var async = dart.import(async);
this[_handle] = null;
if (milliseconds == 0 && (!dart.notNull(hasTimer()) || dart.notNull(exports._globalState.isWorker))) {
// Function internalCallback: () → void
function internalCallback() {
let internalCallback = (() => {
this[_handle] = null;
callback();
}
}).bind(this);
this[_handle] = 1;
exports._globalState.topEventLoop.enqueue(exports._globalState.currentContext, internalCallback, 'timer');
this[_inEventLoop] = true;
} else if (hasTimer()) {
// Function internalCallback: () → void
function internalCallback() {
let internalCallback = (() => {
this[_handle] = null;
leaveJsAsync();
callback();
}
}).bind(this);
enterJsAsync();
this[_handle] = self.setTimeout(_js_helper.convertDartClosureToJS(internalCallback, 0), milliseconds);
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/dev_compiler/lib/runtime/dart/_js_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2466,15 +2466,15 @@ var _isolate_helper = dart.lazyImport(_isolate_helper);
// Function unwrapException: (dynamic) → dynamic
function unwrapException(ex) {
// Function saveStackTrace: (dynamic) → dynamic
function saveStackTrace(error) {
let saveStackTrace = error => {
if (dart.is(error, core.Error)) {
let thrownStackTrace = error.$thrownJsError;
if (thrownStackTrace == null) {
error.$thrownJsError = ex;
}
}
return error;
}
};
if (ex == null)
return null;
if (typeof ex !== "object")
Expand Down
76 changes: 38 additions & 38 deletions pkg/dev_compiler/lib/runtime/dart/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ var collection = dart.import(collection);
let controller = null;
let watch = new core.Stopwatch();
// Function sendEvent: () → void
function sendEvent() {
let sendEvent = () => {
watch.reset();
let data = computation((() => {
let x = computationCount;
computationCount = dart.notNull(x) + 1;
return x;
})());
controller.add(data);
}
};
// Function startPeriodicTimer: () → void
function startPeriodicTimer() {
let startPeriodicTimer = () => {
dart.assert(timer == null);
timer = new Timer.periodic(period, timer => {
sendEvent();
});
}
};
controller = new (StreamController$(T))({
sync: true,
onListen: () => {
Expand Down Expand Up @@ -164,7 +164,7 @@ var collection = dart.import(collection);
let controller = null;
let subscription = null;
// Function onListen: () → void
function onListen() {
let onListen = (() => {
let add = controller.add.bind(controller);
dart.assert(dart.is(controller, _StreamController) || dart.is(controller, _BroadcastStreamController));
let eventSink = controller;
Expand All @@ -187,7 +187,7 @@ var collection = dart.import(collection);
controller.add(newValue);
}
}, {onError: dart.as(addError, core.Function), onDone: controller.close.bind(controller)});
}
}).bind(this);
if (this.isBroadcast) {
controller = new StreamController.broadcast({
onListen: onListen,
Expand Down Expand Up @@ -218,7 +218,7 @@ var collection = dart.import(collection);
let controller = null;
let subscription = null;
// Function onListen: () → void
function onListen() {
let onListen = (() => {
dart.assert(dart.is(controller, _StreamController) || dart.is(controller, _BroadcastStreamController));
let eventSink = controller;
subscription = this.listen(event => {
Expand All @@ -237,7 +237,7 @@ var collection = dart.import(collection);
controller.addStream(newStream).whenComplete(dart.bind(subscription, 'resume'));
}
}, {onError: dart.as(eventSink[_addError], core.Function), onDone: controller.close.bind(controller)});
}
}).bind(this);
if (this.isBroadcast) {
controller = new StreamController.broadcast({
onListen: onListen,
Expand Down Expand Up @@ -759,27 +759,27 @@ var collection = dart.import(collection);
let zone = null;
let timeout = null;
// Function onData: (T) → void
function onData(event) {
let onData = event => {
dart.as(event, T);
timer.cancel();
controller.add(event);
timer = zone.createTimer(timeLimit, dart.as(timeout, __CastType17));
}
};
// Function onError: (dynamic, StackTrace) → void
function onError(error, stackTrace) {
let onError = (error, stackTrace) => {
timer.cancel();
dart.assert(dart.is(controller, _StreamController) || dart.is(controller, _BroadcastStreamController));
let eventSink = controller;
dart.dcall(eventSink[_addError], error, stackTrace);
timer = zone.createTimer(timeLimit, dart.as(timeout, dart.functionType(dart.void, [])));
}
};
// Function onDone: () → void
function onDone() {
let onDone = () => {
timer.cancel();
controller.close();
}
};
// Function onListen: () → void
function onListen() {
let onListen = (() => {
zone = Zone.current;
if (onTimeout == null) {
timeout = () => {
Expand All @@ -796,14 +796,14 @@ var collection = dart.import(collection);
}
subscription = this.listen(onData, {onError: onError, onDone: onDone});
timer = zone.createTimer(timeLimit, dart.as(timeout, dart.functionType(dart.void, [])));
}
}).bind(this);
// Function onCancel: () → Future<dynamic>
function onCancel() {
let onCancel = () => {
timer.cancel();
let result = subscription.cancel();
subscription = null;
return result;
}
};
controller = this.isBroadcast ? new _SyncBroadcastStreamController(onListen, onCancel) : new _SyncStreamController(onListen, () => {
timer.cancel();
subscription.pause();
Expand Down Expand Up @@ -1151,7 +1151,7 @@ var collection = dart.import(collection);
dart.assert(!dart.notNull(this[_inCallback]));
let wasInputPaused = this[_isInputPaused];
// Function sendError: () → void
function sendError() {
let sendError = (() => {
if (dart.notNull(this[_isCanceled]) && !dart.notNull(this[_waitsForCancel]))
return;
this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription._STATE_IN_CALLBACK);
Expand All @@ -1161,7 +1161,7 @@ var collection = dart.import(collection);
this[_zone].runUnaryGuarded(dart.as(this[_onError], __CastType25), error);
}
this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStreamSubscription._STATE_IN_CALLBACK);
}
}).bind(this);
if (this[_cancelOnError]) {
this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription._STATE_WAIT_FOR_CANCEL);
this[_cancel]();
Expand All @@ -1180,13 +1180,13 @@ var collection = dart.import(collection);
dart.assert(!dart.notNull(this[_isPaused]));
dart.assert(!dart.notNull(this[_inCallback]));
// Function sendDone: () → void
function sendDone() {
let sendDone = (() => {
if (!dart.notNull(this[_waitsForCancel]))
return;
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(this[_state]) & ~dart.notNull(_BufferingStreamSubscription._STATE_IN_CALLBACK);
}
}).bind(this);
this[_cancel]();
this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStreamSubscription._STATE_WAIT_FOR_CANCEL);
if (dart.is(this[_cancelFuture], Future)) {
Expand Down Expand Up @@ -1829,7 +1829,7 @@ var collection = dart.import(collection);
let error = null;
let stackTrace = null;
// Function handleError: (dynamic, dynamic) → void
function handleError(theError, theStackTrace) {
let handleError = (theError, theStackTrace) => {
remaining = dart.notNull(remaining) - 1;
if (values != null) {
if (cleanUp != null) {
Expand All @@ -1851,7 +1851,7 @@ var collection = dart.import(collection);
} else if (remaining == 0 && !dart.notNull(eagerError)) {
result[_completeError](error, stackTrace);
}
}
};
for (let future of futures) {
let pos = remaining;
remaining = dart.notNull(pos) + 1;
Expand Down Expand Up @@ -2380,7 +2380,7 @@ var collection = dart.import(collection);
oldZone = Zone._enter(zone);
}
// Function handleValueCallback: () → bool
function handleValueCallback() {
let handleValueCallback = () => {
try {
listenerValueOrError = zone.runUnary(listener[_onValue], sourceValue);
return true;
Expand All @@ -2390,9 +2390,9 @@ var collection = dart.import(collection);
return false;
}

}
};
// Function handleError: () → void
function handleError() {
let handleError = () => {
let asyncError = source[_error];
let matchesTest = true;
if (listener.hasErrorTest) {
Expand Down Expand Up @@ -2427,9 +2427,9 @@ var collection = dart.import(collection);
listenerValueOrError = asyncError;
listenerHasValue = false;
}
}
};
// Function handleWhenCompleteCallback: () → void
function handleWhenCompleteCallback() {
let handleWhenCompleteCallback = () => {
let completeResult = null;
try {
completeResult = zone.run(listener[_whenCompleteAction]);
Expand Down Expand Up @@ -2462,7 +2462,7 @@ var collection = dart.import(collection);
}
});
}
}
};
if (!dart.notNull(hasError)) {
if (listener.handlesValue) {
listenerHasValue = handleValueCallback();
Expand Down Expand Up @@ -2652,12 +2652,12 @@ var collection = dart.import(collection);
let span = self.document.createElement("span");
let storedCallback = null;
// Function internalCallback: (dynamic) → dynamic
function internalCallback(_) {
let internalCallback = _ => {
_isolate_helper.leaveJsAsync();
let f = storedCallback;
storedCallback = null;
dart.dcall(f);
}
};
;
let observer = new self.MutationObserver(_js_helper.convertDartClosureToJS(internalCallback, 1));
observer.observe(div, {childList: true});
Expand All @@ -2674,20 +2674,20 @@ var collection = dart.import(collection);
}
static _scheduleImmediateJsOverride(callback) {
// Function internalCallback: () → dynamic
function internalCallback() {
let internalCallback = () => {
_isolate_helper.leaveJsAsync();
callback();
}
};
;
_isolate_helper.enterJsAsync();
self.scheduleImmediate(_js_helper.convertDartClosureToJS(internalCallback, 0));
}
static _scheduleImmediateWithSetImmediate(callback) {
// Function internalCallback: () → dynamic
function internalCallback() {
let internalCallback = () => {
_isolate_helper.leaveJsAsync();
callback();
}
};
;
_isolate_helper.enterJsAsync();
self.setImmediate(_js_helper.convertDartClosureToJS(internalCallback, 0));
Expand Down Expand Up @@ -3041,11 +3041,11 @@ var collection = dart.import(collection);
}
}
// Function complete: () → void
function complete() {
let complete = (() => {
if (dart.notNull(this[_doneFuture] != null) && dart.notNull(this[_doneFuture][_mayComplete])) {
this[_doneFuture][_asyncComplete](null);
}
}
}).bind(this);
if (result != null) {
result = result.whenComplete(complete);
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/dev_compiler/lib/runtime/dart/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3085,7 +3085,7 @@ var math = dart.lazyImport(math);
let found = false;
let initialSplayCount = this[_splayCount];
// Function visit: (_SplayTreeMapNode<dynamic, dynamic>) → bool
function visit(node) {
let visit = (node => {
while (node != null) {
if (dart.equals(node.value, value))
return true;
Expand All @@ -3097,7 +3097,7 @@ var math = dart.lazyImport(math);
node = dart.as(node.left, _SplayTreeMapNode);
}
return false;
}
}).bind(this);
return visit(dart.as(this[_root], _SplayTreeMapNode));
}
get keys() {
Expand Down
Loading

0 comments on commit a7c8601

Please sign in to comment.