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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/isolate_helper.dart

Issue 11549017: Clean up the patch file for the isolate library by introducing a new builtin library: isolate_helpe… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
Index: sdk/lib/_internal/compiler/implementation/lib/isolate_helper.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/lib/isolate_helper.dart (revision 16024)
+++ sdk/lib/_internal/compiler/implementation/lib/isolate_helper.dart (working copy)
@@ -2,8 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-// Patch file for the dart:isolate library.
+library _isolate_helper;
+import 'dart:isolate';
import 'dart:uri';
/**
@@ -92,27 +93,8 @@
JS("void", r"$static_init()");
}
-ReceivePort _lazyPort;
-patch ReceivePort get port {
- if (_lazyPort == null) {
- _lazyPort = new ReceivePort();
- }
- return _lazyPort;
-}
+ReceivePort lazyPort;
-patch SendPort spawnFunction(void topLevelFunction()) {
- final name = _IsolateNatives._getJSFunctionName(topLevelFunction);
- if (name == null) {
- throw new UnsupportedError(
- "only top-level functions can be spawned.");
- }
- return _IsolateNatives._spawn(name, null, false);
-}
-
-patch SendPort spawnUri(String uri) {
- return _IsolateNatives._spawn(null, uri, false);
-}
-
/** State associated with the current manager. See [globalState]. */
// TODO(sigmund): split in multiple classes: global, thread, main-worker states?
class _Manager {
@@ -193,12 +175,12 @@
void _nativeInitWorkerMessageHandler() {
JS("void", r"""
$globalThis.onmessage = function (e) {
- _IsolateNatives._processWorkerMessage(this.mainManager, e);
+ IsolateNatives._processWorkerMessage(this.mainManager, e);
}""");
}
/*: TODO: check that _processWorkerMessage is not discarded while treeshaking.
""" {
- _IsolateNatives._processWorkerMessage(null, null);
+ IsolateNatives._processWorkerMessage(null, null);
}
*/
@@ -318,8 +300,7 @@
* run asynchronously.
*/
void _runHelper() {
- // [_window] is defined in timer_provider.dart.
- if (_window != null) {
+ if (hasWindow()) {
// Run each iteration from the browser's top event loop.
void next() {
if (!runIteration()) return;
@@ -389,7 +370,8 @@
* enforce that the type is defined dynamically only when web workers
* are actually available.
*/
-class _WorkerStub implements _ManagerStub native "*Worker" {
+// @Native("*Worker");
ahe 2012/12/14 08:49:15 Add a comment explaining why you're commenting thi
+class _WorkerStub implements _ManagerStub {
get id => JS("var", "#.id", this);
void set id(i) { JS("void", "#.id = #", this, i); }
void set onmessage(f) { JS("void", "#.onmessage = #", this, f); }
@@ -400,7 +382,7 @@
const String _SPAWNED_SIGNAL = "spawned";
-class _IsolateNatives {
+class IsolateNatives {
/**
* The src url for the script tag that loaded this code. Used to create
@@ -521,9 +503,18 @@
return JS("Object", "new #()", ctor);
}
+ static SendPort spawnFunction(void topLevelFunction()) {
+ final name = _getJSFunctionName(topLevelFunction);
+ if (name == null) {
+ throw new UnsupportedError(
+ "only top-level functions can be spawned.");
+ }
+ return spawn(name, null, false);
+ }
+
// TODO(sigmund): clean up above, after we make the new API the default:
- static _spawn(String functionName, String uri, bool isLight) {
+ static SendPort spawn(String functionName, String uri, bool isLight) {
Completer<SendPort> completer = new Completer<SendPort>();
ReceivePort port = new ReceivePort();
port.receive((msg, SendPort replyPort) {
@@ -569,7 +560,7 @@
static void _startIsolate(Function topLevel, SendPort replyTo) {
_fillStatics(_globalState.currentContext);
- _lazyPort = new ReceivePort();
+ lazyPort = new ReceivePort();
replyTo.send(_SPAWNED_SIGNAL, port.toSendPort());
topLevel();
@@ -628,7 +619,7 @@
Future call(var message) {
final completer = new Completer();
- final port = new _ReceivePortImpl();
+ final port = new ReceivePortImpl();
send(message, port.toSendPort());
port.receive((value, ignoreReplyTo) {
port.close();
@@ -648,7 +639,7 @@
/** A send port that delivers messages in-memory via native JavaScript calls. */
class _NativeJsSendPort extends _BaseSendPort implements SendPort {
- final _ReceivePortImpl _receivePort;
+ final ReceivePortImpl _receivePort;
const _NativeJsSendPort(this._receivePort, int isolateId) : super(isolateId);
@@ -783,21 +774,13 @@
int get hashCode => _id;
}
-/** Default factory for receive ports. */
-patch class ReceivePort {
- patch factory ReceivePort() {
- return new _ReceivePortImpl();
- }
-
-}
-
/** Implementation of a multi-use [ReceivePort] on top of JavaScript. */
-class _ReceivePortImpl implements ReceivePort {
+class ReceivePortImpl implements ReceivePort {
int _id;
Function _callback;
static int _nextFreeId = 1;
- _ReceivePortImpl()
+ ReceivePortImpl()
: _id = _nextFreeId++ {
_globalState.currentContext.register(_id, this);
}
@@ -1244,28 +1227,50 @@
// Currently, none of the two Dart classes have subclasses.
typedef void _TimeoutHandler();
-class _Window native "@*DOMWindow" {
- int setTimeout(_TimeoutHandler handler, int timeout) native;
- int setInterval(_TimeoutHandler handler, int timeout) native;
- void clearTimeout(int handle) native;
- void clearInterval(int handle) native;
+// @Native("*DOMWindow");
ahe 2012/12/14 08:49:15 Ditto.
+class _Window {
+ int setTimeout(_TimeoutHandler handler, int timeout) {
+ return JS('int',
+ '#.setTimeout(#, #)',
+ this,
+ convertDartClosureToJS(handler, 0),
+ timeout);
+ }
+
+ int setInterval(_TimeoutHandler handler, int timeout) {
+ return JS('int',
+ '#.setInterval(#, #)',
+ this,
+ convertDartClosureToJS(handler, 0),
+ timeout);
+ }
+
+ void clearTimeout(int handle) {
+ JS('void', '#.clearTimeout(#)', this, handle);
+ }
+
+ void clearInterval(int handle) {
+ JS('void', '#.clearInterval(#)', this, handle);
+ }
}
_Window get _window =>
JS('bool', 'typeof window != "undefined"') ? JS('_Window', 'window') : null;
-class _Timer implements Timer {
+bool hasWindow() => _window != null;
+
+class TimerImpl implements Timer {
final bool _once;
int _handle;
- _Timer(int milliSeconds, void callback(Timer timer))
+ TimerImpl(int milliseconds, void callback(Timer timer))
: _once = true {
- _handle = _window.setTimeout(() => callback(this), milliSeconds);
+ _handle = _window.setTimeout(() => callback(this), milliseconds);
}
- _Timer.repeating(int milliSeconds, void callback(Timer timer))
+ TimerImpl.repeating(int milliseconds, void callback(Timer timer))
: _once = false {
- _handle = _window.setInterval(() => callback(this), milliSeconds);
+ _handle = _window.setInterval(() => callback(this), milliseconds);
}
void cancel() {
@@ -1276,23 +1281,3 @@
}
}
}
-
-patch class Timer {
- patch factory Timer(int milliSeconds, void callback(Timer timer)) {
- if (_window == null) {
- throw new UnsupportedError("Timer interface not supported.");
- }
- return new _Timer(milliSeconds, callback);
- }
-
- /**
- * Creates a new repeating timer. The [callback] is invoked every
- * [milliSeconds] millisecond until cancelled.
- */
- patch factory Timer.repeating(int milliSeconds, void callback(Timer timer)) {
- if (_window == null) {
- throw new UnsupportedError("Timer interface not supported.");
- }
- return new _Timer.repeating(milliSeconds, callback);
- }
-}

Powered by Google App Engine
This is Rietveld 408576698