Chromium Code Reviews| Index: frog/lib/isolate.dart |
| diff --git a/frog/lib/isolate.dart b/frog/lib/isolate.dart |
| index e3e6991fbf7674eaee5927c079f0fc5a65d5a390..1a2914ecee9c2638ff5054d4fe5bc162115e38e7 100644 |
| --- a/frog/lib/isolate.dart |
| +++ b/frog/lib/isolate.dart |
| @@ -166,10 +166,17 @@ _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() {} |
| } |
| +class _Worker native "*Worker" { |
|
Jennifer Messerly
2011/12/22 19:49:44
I'd add a comment here that this type is defined i
|
| + 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 +210,7 @@ class IsolateContext { |
| result = code(); |
| } finally { |
| _globalState.currentContext = old; |
| - old._setGlobals(); |
| + if (old != null) old._setGlobals(); |
| } |
| return result; |
| } |
| @@ -292,10 +299,9 @@ class EventLoop { |
| } else { |
| try { |
| _runHelper(); |
| - } catch(e) { |
| - // TODO(floitsch): try to send stack-trace to the other side. |
| + } catch(var e, var trace) { |
|
Jennifer Messerly
2011/12/22 19:49:44
Is trace actually working? if so ... that's cool :
|
| _globalState.mainWorker.postMessage(_serializeMessage( |
| - {'command': 'error', 'msg': "" + e })); |
| + {'command': 'error', 'msg': '$e\n$trace' })); |
| } |
| } |
| } |
| @@ -490,18 +496,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);"; |
|
Jennifer Messerly
2011/12/22 19:49:44
we aren't very consistent about it, but personally
|
| /** |
| * 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); |
|
Jennifer Messerly
2011/12/22 19:49:44
Are you using "final" to avoid dynamic dispatch? I
|
| + 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; |