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

Unified Diff: frog/lib/isolate.dart

Issue 8999030: frog isolate fixes: minor changes to the isolate library + architecture.py (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 years 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
« no previous file with comments | « no previous file | frog/minfrog » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/lib/isolate.dart
diff --git a/frog/lib/isolate.dart b/frog/lib/isolate.dart
index e3e6991fbf7674eaee5927c079f0fc5a65d5a390..cd156fc4d3ef84bc4b6c387ff202db1f7623bb46 100644
--- a/frog/lib/isolate.dart
+++ b/frog/lib/isolate.dart
@@ -166,10 +166,23 @@ _deserializeMessage(message) {
class MainWorker {
int id = 0;
void postMessage(msg) native "return \$globalThis.postMessage(msg);";
- void onmessage(f) native "\$globalThis.onmessage = f;";
+ void set onmessage(f) native "\$globalThis.onmessage = f;";
void terminate() {}
}
+/**
+ * A web worker. This type is also defined in 'dart:dom', but we define it here
+ * to avoid introducing a dependency from corelib to dom. This definition uses a
+ * 'hidden' type (* prefix on the native name) to enforce that the type is
+ * defined dynamically only when web workers are actually available.
+ */
+class _Worker native "*Worker" {
+ get id() native "return this.id;";
+ void set id(i) native "this.id = i;";
+ void set onmessage(f) native "this.onmessage = f;";
+ void postMessage(msg) native "return this.postMessage(msg);";
+}
+
/** Context information tracked for each isolate. */
class IsolateContext {
/** Current isolate id. */
@@ -203,7 +216,7 @@ class IsolateContext {
result = code();
} finally {
_globalState.currentContext = old;
- old._setGlobals();
+ if (old != null) old._setGlobals();
}
return result;
}
@@ -292,10 +305,9 @@ class EventLoop {
} else {
try {
_runHelper();
- } catch(e) {
- // TODO(floitsch): try to send stack-trace to the other side.
+ } catch(var e, var trace) {
_globalState.mainWorker.postMessage(_serializeMessage(
- {'command': 'error', 'msg': "" + e }));
+ {'command': 'error', 'msg': '$e\n$trace' }));
}
}
}
@@ -490,18 +502,15 @@ class IsolateNatives {
""";
/** Starts a new worker with the given URL. */
- static _newWorker(url) native "return new Worker(url)";
+ static _Worker _newWorker(url) native "return new Worker(url);";
/**
* Spawns an isolate in a worker. [factoryName] is the Javascript constructor
* name for the isolate entry point class.
*/
static void _spawnWorker(factoryName, serializedReplyPort) {
- var worker = _newWorker(_thisScript);
- // TODO(sigmund): make this work.
- worker.onmessage = function(e) {
- _processWorkerMessage(worker, e);
- };
+ final worker = _newWorker(_thisScript);
+ worker.onmessage = (e) { _processWorkerMessage(worker, e); };
var workerId = _globalState.nextWorkerId++;
// We also store the id on the worker itself so that we can unregister it.
worker.id = workerId;
« no previous file with comments | « no previous file | frog/minfrog » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698