Implement spawnDomUri.

Also fix some bugs in the test.

R=podivilov@chromium.org,vsm@google.com

Review URL: https://codereview.chromium.org//13144014

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20776 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
antonm@google.com 2013-04-02 12:48:34 +00:00
parent 15f3714613
commit 00d846b241
5 changed files with 56 additions and 14 deletions

View file

@ -36175,8 +36175,7 @@ class _VariableSizeListIterator<T> implements Iterator<T> {
// BSD-style license that can be found in the LICENSE file.
// This API is exploratory.
Future<SendPort> spawnDomFunction(Function topLevelFunction) {
_makeSendPortFuture(spawnRequest) {
final completer = new Completer<SendPort>();
final port = new ReceivePort();
port.receive((result, _) {
@ -36184,10 +36183,17 @@ Future<SendPort> spawnDomFunction(Function topLevelFunction) {
port.close();
});
// TODO: SendPort.hashCode is ugly way to access port id.
_Utils.spawnDomFunction(topLevelFunction, port.toSendPort().hashCode);
spawnRequest(port.toSendPort().hashCode);
return completer.future;
}
// This API is exploratory.
Future<SendPort> spawnDomFunction(Function f) =>
_makeSendPortFuture((portId) { _Utils.spawnDomFunction(f, portId); });
Future<SendPort> spawnDomUri(String uri) =>
_makeSendPortFuture((portId) { _Utils.spawnDomUri(uri, portId); });
// testRunner implementation.
// FIXME: provide a separate lib for testRunner.
@ -36270,7 +36276,8 @@ class _Utils {
static window() native "Utils_window";
static forwardingPrint(String message) native "Utils_forwardingPrint";
static void spawnDomFunction(Function topLevelFunction, int replyTo) native "Utils_spawnDomFunction";
static void spawnDomFunction(Function f, int replyTo) native "Utils_spawnDomFunction";
static void spawnDomUri(String uri, int replyTo) native "Utils_spawnDomUri";
static int _getNewIsolateId() native "Utils_getNewIsolateId";
static bool shadowRootSupported(Document document) native "Utils_shadowRootSupported";
}

View file

@ -36,15 +36,19 @@ main() {
useHtmlConfiguration();
test('Simple DOM isolate test', () {
spawnDomFunction(childDomIsolate).then((sendPort) {
expect(sendPort.call('check'), completion('${window.location}'));
});
spawnDomFunction(childDomIsolate).then(expectAsync1(
(sendPort) {
expect(sendPort.call('check'), completion('${window.location}'));
}
));
});
test('Nested DOM isolates test', () {
spawnDomFunction(trampolineIsolate).then((sendPort) {
expect(sendPort.call('check'), completion('${window.location}'));
});
spawnDomFunction(trampolineIsolate).then(expectAsync1(
(sendPort) {
expect(sendPort.call('check'), completion('${window.location}'));
}
));
});
test('Spawn DOM isolate from pure', () {
@ -52,6 +56,14 @@ main() {
completion('${window.location}'));
});
test('Spawn DOM by uri', () {
spawnDomUri('dom_isolates_test.dart.child_isolate.dart').then(expectAsync1(
(sendPort) {
expect(sendPort.call('check'), completion('${window.location}'));
}
));
});
test('Not function', () {
expect(() => spawnDomFunction(42), throws);
});

View file

@ -0,0 +1,16 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// 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
import 'dart:html';
import 'dart:isolate';
main() {
port.receive((msg, replyTo) {
if (msg != 'check') {
replyTo.send('wrong msg: $msg');
}
replyTo.send('${window.location}');
port.close();
});
}

View file

@ -59,7 +59,8 @@ class _Utils {
static window() native "Utils_window";
static forwardingPrint(String message) native "Utils_forwardingPrint";
static void spawnDomFunction(Function topLevelFunction, int replyTo) native "Utils_spawnDomFunction";
static void spawnDomFunction(Function f, int replyTo) native "Utils_spawnDomFunction";
static void spawnDomUri(String uri, int replyTo) native "Utils_spawnDomUri";
static int _getNewIsolateId() native "Utils_getNewIsolateId";
static bool shadowRootSupported(Document document) native "Utils_shadowRootSupported";
}

View file

@ -4,8 +4,7 @@
part of html;
// This API is exploratory.
Future<SendPort> spawnDomFunction(Function topLevelFunction) {
_makeSendPortFuture(spawnRequest) {
final completer = new Completer<SendPort>();
final port = new ReceivePort();
port.receive((result, _) {
@ -13,10 +12,17 @@ Future<SendPort> spawnDomFunction(Function topLevelFunction) {
port.close();
});
// TODO: SendPort.hashCode is ugly way to access port id.
_Utils.spawnDomFunction(topLevelFunction, port.toSendPort().hashCode);
spawnRequest(port.toSendPort().hashCode);
return completer.future;
}
// This API is exploratory.
Future<SendPort> spawnDomFunction(Function f) =>
_makeSendPortFuture((portId) { _Utils.spawnDomFunction(f, portId); });
Future<SendPort> spawnDomUri(String uri) =>
_makeSendPortFuture((portId) { _Utils.spawnDomUri(uri, portId); });
// testRunner implementation.
// FIXME: provide a separate lib for testRunner.