| Index: LayoutTests/dart/multiscript-js-interop.html
|
| diff --git a/LayoutTests/dart/Multiscript.html b/LayoutTests/dart/multiscript-js-interop.html
|
| similarity index 65%
|
| copy from LayoutTests/dart/Multiscript.html
|
| copy to LayoutTests/dart/multiscript-js-interop.html
|
| index c4df14cbbc6f0b6f9470818b0a58626b23961143..80a7f1b2717770a8b663dd4c14446b8f53345713 100644
|
| --- a/LayoutTests/dart/Multiscript.html
|
| +++ b/LayoutTests/dart/multiscript-js-interop.html
|
| @@ -2,7 +2,7 @@
|
| <head>
|
| <script type="application/javascript" src="../../../../dart/pkg/unittest/lib/test_controller.js"></script>
|
| <script type="application/javascript">
|
| -var sJs = 0;
|
| +var sJs;
|
| var callbacks = [];
|
| var numCallbacks = 0;
|
| // Trivial method to run all 4 callbacks in order once they are all
|
| @@ -22,91 +22,102 @@ function registerCallback(index, callback) {
|
|
|
| <script type="application/dart">
|
| import 'dart:async';
|
| +import 'package:js/js.dart';
|
| import 'package:unittest/unittest.dart';
|
| -import 'Multiscript.dart';
|
| +import 'multiscript-js-interop.dart';
|
|
|
| main() {
|
| - State.registerCallback(0, () {
|
| + State.registerCallback(0, allowInterop(() {
|
| // FIXME: Rewrite this test to use html-imports.
|
| print("Running script 0");
|
| State.update();
|
| - expect(State.sJs, equals(1));
|
| + expect(State.sJs.length, equals(1));
|
| expect(State.sDart, equals(1));
|
| - });
|
| + }));
|
| }
|
| </script>
|
|
|
| <script type="application/dart">
|
| -import 'dart:js' as js;
|
| +import 'package:js/js.dart';
|
| import 'dart:math';
|
| import 'package:unittest/unittest.dart';
|
| -import 'Multiscript.dart';
|
| +import 'multiscript-js-interop.dart';
|
| +
|
| +@JS()
|
| +external Function get doubleValue;
|
| +@JS()
|
| +external Function set doubleValue(Function v);
|
|
|
| main() {
|
| - State.registerCallback(1, () {
|
| + State.registerCallback(1, allowInterop(() {
|
| print("Running script 1");
|
| State.update();
|
| - expect(State.sJs, equals(2));
|
| + expect(State.sJs.length, equals(2));
|
| expect(State.sDart, equals(1));
|
| - js.context['doubleValue'] = (x) => x*2;
|
| - expect(js.context.callMethod('doubleValue', [21]), equals(42));
|
| - expect(js.context.callMethod('doubleValue', ["Foo"]), equals("FooFoo"));
|
| + doubleValue = allowInterop((x) => x*2);
|
| + expect(doubleValue(21), equals(42));
|
| + expect(doubleValue("Foo"), equals("FooFoo"));
|
| // Point is not a primitive type so passing it to a different isolate is
|
| // not allowed.
|
| - expect(js.context.callMethod('doubleValue', [new Point(2, 4)]),
|
| + expect(doubleValue(new Point(2, 4)),
|
| equals(new Point(4, 8)));
|
| - });
|
| + }));
|
| }
|
| </script>
|
|
|
| <script type="application/dart">
|
| +import 'package:js/js.dart';
|
| import 'package:unittest/unittest.dart';
|
| -import 'Multiscript.dart';
|
| +import 'multiscript-js-interop.dart';
|
|
|
| main() {
|
| - State.registerCallback(2, () {
|
| + State.registerCallback(2, allowInterop(() {
|
| print("Running script 2");
|
| State.update();
|
| - expect(State.sJs, equals(3));
|
| + expect(State.sJs.length, equals(3));
|
| expect(State.sDart, equals(1));
|
| - });
|
| + }));
|
| }
|
| </script>
|
|
|
| <script type="application/dart">
|
| -import 'dart:js' as js;
|
| import 'dart:math';
|
| +import 'package:js/js.dart';
|
| import 'package:unittest/unittest.dart';
|
| import 'package:unittest/html_config.dart';
|
| -import 'Multiscript.dart';
|
| +import 'multiscript-js-interop.dart';
|
| +
|
| +// This function is set by a different isolate.
|
| +@JS()
|
| +external Function get doubleValue;
|
|
|
| main() {
|
| - State.registerCallback(3, () {
|
| + State.registerCallback(3, allowInterop(() {
|
| print("Running script 3");
|
| useHtmlConfiguration(true);
|
| test('Multiple script tags', () {
|
| State.update();
|
| - expect(State.sJs, equals(4));
|
| + expect(State.sJs.length, equals(4));
|
| expect(State.sDart, equals(1));
|
|
|
| // doubleValue is from a different Dart isolate but arguments are primitive
|
| // types so it is safe to call.
|
| - expect(js.context.callMethod('doubleValue', [21]), equals(42));
|
| - expect(js.context.callMethod('doubleValue', ["Foo"]), equals("FooFoo"));
|
| + expect(doubleValue(21), equals(42));
|
| + expect(doubleValue("Foo"), equals("FooFoo"));
|
| // Point is not a primitive type so passing it to a different isolate
|
| // using js interop results in a JsObject rather than a Point. A
|
| // NoSuchMethodError is thrown in the other Dart isolate but once the
|
| // error gets to this isolate it shows up as just an Unhandled Exception.
|
| expect(() {
|
| try {
|
| - js.context.callMethod('doubleValue', [new Point(2, 4)]);
|
| + doubleValue(new Point(2, 4));
|
| } catch (e) {
|
| throw new Exception(e.toString());
|
| }
|
| },
|
| throwsException);
|
| });
|
| - });
|
| + }));
|
| }
|
| </script>
|
| </body>
|
|
|