Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
|
zra
2016/11/29 21:24:35
2016
bkonyi
2016/11/29 21:43:17
Done.
| |
| 3 * for details. All rights reserved. Use of this source code is governed by a | |
| 4 * BSD-style license that can be found in the LICENSE file. | |
| 5 */ | |
| 6 /** | |
|
zra
2016/11/29 21:24:35
We probably don't need to copy this comment from t
bkonyi
2016/11/29 21:43:17
Done.
| |
| 7 * @assertion The current library is the library currently being compiled. The | |
| 8 * import modifies the import namespace of the current library in a manner that | |
| 9 * is determined by the imported library and by the optional elements of the | |
| 10 * import. | |
| 11 * . . . | |
| 12 * Let I be an import directive that refers to a URI via the string s1. | |
| 13 * Evaluation of I proceeds as follows: | |
| 14 * | |
| 15 * If I is a deferred import, no evaluation takes place. Instead, a mapping of | |
| 16 * the name of the prefix, p to a deferred prefix object is added to the scope | |
| 17 * of the current library L. The deferred prefix object has the following | |
| 18 * methods: | |
| 19 * • loadLibrary. This method returns a future f. When called, the method | |
| 20 * causes an immediate import I to be executed at some future time, where | |
| 21 * I is is derived from I by eliding the word deferred and adding a hide | |
| 22 * loadLibrary combinator clause. When I executes without error, f completes | |
| 23 * successfully. If I executes without error, we say that the call to | |
| 24 * loadLibrary has succeeded, otherwise we say the call has failed. | |
| 25 * • For every top level function f named id in the imported library B, a | |
| 26 * corresponding method named id with the same signature as f. Calling | |
| 27 * the method results in a runtime error. | |
| 28 * • For every top level getter g named id in B, a corresponding getter named | |
| 29 * id with the same signature as g. Calling the method results in a runtime | |
| 30 * error. | |
| 31 * • For every top level setter s named id in B, a corresponding setter named | |
| 32 * id with the same signature as s. Calling the method results in a runtime | |
| 33 * error. | |
| 34 * • For every type T named id in B, a corresponding getter named id with | |
| 35 * return type Type. Calling the method results in a runtime error. | |
| 36 * . . . | |
| 37 * After a call succeeds, the name p is mapped to a non-deferred prefix object | |
| 38 * as described below. In addition, the prefix object also supports the | |
| 39 * loadLibrary method, and so it is possible to call loadLibrary again. If | |
| 40 * a call fails, nothing happens, and one again has the option to call | |
| 41 * loadLibrary again. Whether a repeated call to loadLibrary succeeds will | |
| 42 * vary as described below. | |
| 43 * The effect of a repeated call to p.loadLibrary is as follows: | |
| 44 * • If another call to p.loadLibrary has already succeeded, the repeated call | |
| 45 * also succeeds. Otherwise, | |
| 46 * • If another call to to p.loadLibrary has failed: | |
| 47 * – If the failure is due to a compilation error, the repeated call fails | |
| 48 * for the same reason. | |
| 49 * – If the failure is due to other causes, the repeated call behaves as if | |
| 50 * no previous call had been made. | |
| 51 * In other words, one can retry a deferred load after a network failure or | |
| 52 * because a file is absent, but once one finds some content and loads it, one | |
| 53 * can no longer reload. | |
| 54 * | |
| 55 * @description Checks that if a library is load successfully, prefix is | |
| 56 * mapped to a non-deferred prefix object, and top-level declarations from | |
| 57 * the imported library became accessed in the current library with specified | |
| 58 * prefix. If a call loadLibrary fails nothing happens, and one again has the | |
| 59 * option to call loadLibrary again. Also checks to see that an attempt to | |
| 60 * load a library from a bad path throws a sane exception. | |
| 61 * @author ngl@unipro.ru | |
| 62 */ | |
| 63 import "dart:async"; | |
| 64 import "../../co19/src/Utils/expect.dart"; | |
|
zra
2016/11/29 21:24:35
Let's not have a dependence on co19 here. Use:
im
bkonyi
2016/11/29 21:43:17
Done.
| |
| 65 import "regress_27201_lib.dart" deferred as p; | |
| 66 import "regress_27201_bad_lib_path.dart" deferred as q; | |
| 67 | |
| 68 test_loaded() { | |
| 69 try { | |
| 70 p.someFunc(); | |
| 71 } catch (e) { | |
| 72 Expect.fail("Should not be here"); | |
| 73 } | |
| 74 try { | |
| 75 p.someGetter; | |
| 76 } catch (e) { | |
| 77 Expect.fail("Should not be here"); | |
| 78 } | |
| 79 try { | |
| 80 p.someSetter = 1; | |
| 81 } catch (e) { | |
| 82 Expect.fail("Should not be here"); | |
| 83 } | |
| 84 try { | |
| 85 p.Func; | |
| 86 } catch (e) { | |
| 87 Expect.fail("Should not be here"); | |
| 88 } | |
| 89 try { | |
| 90 Expect.isTrue(p.loadLibrary() is Future); | |
| 91 } catch (e) { | |
| 92 Expect.fail("Should not be here"); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 | |
| 97 main() async { | |
|
zra
2016/11/29 21:24:35
There is no await, so async is not needed.
bkonyi
2016/11/29 21:43:17
Done.
| |
| 98 p.loadLibrary().then((v) { | |
| 99 test_loaded(); | |
| 100 }, | |
| 101 onError: (e) { | |
| 102 Expect.fail("Should have loaded library!"); | |
| 103 }); | |
| 104 | |
| 105 // Ensure bad library import is handled correctly | |
|
zra
2016/11/29 21:24:35
Please end comments with a '.'
bkonyi
2016/11/29 21:43:17
Done.
| |
| 106 q.loadLibrary().then((v) { | |
| 107 Expect.fail("Should have failed"); | |
| 108 }, | |
| 109 onError: (e) { | |
| 110 Expect.throws(() => q.x); | |
| 111 }); | |
| 112 } | |
| 113 | |
| OLD | NEW |