OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'package:async_helper/async_helper.dart'; | 5 import 'package:async_helper/async_helper.dart'; |
6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
7 | 7 |
8 import 'deferred_custom_loader_lib.dart' deferred as def; | 8 import 'deferred_custom_loader_lib.dart' deferred as def; |
9 | 9 |
10 void setup() native """ | 10 void setup() native """ |
11 // In d8 we don't have any way to load the content of the file, so just use | 11 // In d8 we don't have any way to load the content of the file, so just use |
12 // the preamble's loader. | 12 // the preamble's loader. |
13 if (!self.dartDeferredLibraryLoader) { | 13 if (!self.dartDeferredLibraryLoader) { |
14 self.dartDeferredLibraryLoader = function(uri, success, error) { | 14 self.dartDeferredLibraryLoader = function(uri, success, error) { |
15 var req = new XMLHttpRequest(); | 15 var req = new XMLHttpRequest(); |
16 req.addEventListener("load", function() { | 16 req.addEventListener("load", function() { |
17 eval(this.responseText); | 17 eval(this.responseText); |
18 success(); | 18 success(); |
19 }); | 19 }); |
20 req.open("GET", uri); | 20 req.open("GET", uri); |
21 req.send(); | 21 req.send(); |
22 }; | 22 }; |
23 } | 23 } |
24 """; | 24 """; |
25 | 25 |
26 | |
27 runTest() async { | 26 runTest() async { |
28 setup(); | 27 setup(); |
29 await def.loadLibrary(); | 28 await def.loadLibrary(); |
30 Expect.equals(499, def.foo()); | 29 Expect.equals(499, def.foo()); |
31 } | 30 } |
32 | 31 |
33 main() { | 32 main() { |
34 asyncStart(); | 33 asyncStart(); |
35 runTest().then((_) => asyncEnd()); | 34 runTest().then((_) => asyncEnd()); |
36 } | 35 } |
OLD | NEW |