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

Unified Diff: tests/language/vm/regress_27201_test.dart

Issue 2537253002: Fixed assert causing crash when attempting to load a library from an invalid path. (Closed)
Patch Set: Created 4 years, 1 month 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: tests/language/vm/regress_27201_test.dart
diff --git a/tests/language/vm/regress_27201_test.dart b/tests/language/vm/regress_27201_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b36310f82ccafd2cdfc65b5164e2b5e28bc7dcb5
--- /dev/null
+++ b/tests/language/vm/regress_27201_test.dart
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ * 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.
+ */
+/**
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.
+ * @assertion The current library is the library currently being compiled. The
+ * import modifies the import namespace of the current library in a manner that
+ * is determined by the imported library and by the optional elements of the
+ * import.
+ * . . .
+ * Let I be an import directive that refers to a URI via the string s1.
+ * Evaluation of I proceeds as follows:
+ *
+ * If I is a deferred import, no evaluation takes place. Instead, a mapping of
+ * the name of the prefix, p to a deferred prefix object is added to the scope
+ * of the current library L. The deferred prefix object has the following
+ * methods:
+ * • loadLibrary. This method returns a future f. When called, the method
+ * causes an immediate import I to be executed at some future time, where
+ * I is is derived from I by eliding the word deferred and adding a hide
+ * loadLibrary combinator clause. When I executes without error, f completes
+ * successfully. If I executes without error, we say that the call to
+ * loadLibrary has succeeded, otherwise we say the call has failed.
+ * • For every top level function f named id in the imported library B, a
+ * corresponding method named id with the same signature as f. Calling
+ * the method results in a runtime error.
+ * • For every top level getter g named id in B, a corresponding getter named
+ * id with the same signature as g. Calling the method results in a runtime
+ * error.
+ * • For every top level setter s named id in B, a corresponding setter named
+ * id with the same signature as s. Calling the method results in a runtime
+ * error.
+ * • For every type T named id in B, a corresponding getter named id with
+ * return type Type. Calling the method results in a runtime error.
+ * . . .
+ * After a call succeeds, the name p is mapped to a non-deferred prefix object
+ * as described below. In addition, the prefix object also supports the
+ * loadLibrary method, and so it is possible to call loadLibrary again. If
+ * a call fails, nothing happens, and one again has the option to call
+ * loadLibrary again. Whether a repeated call to loadLibrary succeeds will
+ * vary as described below.
+ * The effect of a repeated call to p.loadLibrary is as follows:
+ * • If another call to p.loadLibrary has already succeeded, the repeated call
+ * also succeeds. Otherwise,
+ * • If another call to to p.loadLibrary has failed:
+ * – If the failure is due to a compilation error, the repeated call fails
+ * for the same reason.
+ * – If the failure is due to other causes, the repeated call behaves as if
+ * no previous call had been made.
+ * In other words, one can retry a deferred load after a network failure or
+ * because a file is absent, but once one finds some content and loads it, one
+ * can no longer reload.
+ *
+ * @description Checks that if a library is load successfully, prefix is
+ * mapped to a non-deferred prefix object, and top-level declarations from
+ * the imported library became accessed in the current library with specified
+ * prefix. If a call loadLibrary fails nothing happens, and one again has the
+ * option to call loadLibrary again. Also checks to see that an attempt to
+ * load a library from a bad path throws a sane exception.
+ * @author ngl@unipro.ru
+ */
+import "dart:async";
+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.
+import "regress_27201_lib.dart" deferred as p;
+import "regress_27201_bad_lib_path.dart" deferred as q;
+
+test_loaded() {
+ try {
+ p.someFunc();
+ } catch (e) {
+ Expect.fail("Should not be here");
+ }
+ try {
+ p.someGetter;
+ } catch (e) {
+ Expect.fail("Should not be here");
+ }
+ try {
+ p.someSetter = 1;
+ } catch (e) {
+ Expect.fail("Should not be here");
+ }
+ try {
+ p.Func;
+ } catch (e) {
+ Expect.fail("Should not be here");
+ }
+ try {
+ Expect.isTrue(p.loadLibrary() is Future);
+ } catch (e) {
+ Expect.fail("Should not be here");
+ }
+}
+
+
+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.
+ p.loadLibrary().then((v) {
+ test_loaded();
+ },
+ onError: (e) {
+ Expect.fail("Should have loaded library!");
+ });
+
+ // 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.
+ q.loadLibrary().then((v) {
+ Expect.fail("Should have failed");
+ },
+ onError: (e) {
+ Expect.throws(() => q.x);
+ });
+}
+
« tests/language/vm/regress_27201_lib.dart ('K') | « tests/language/vm/regress_27201_lib.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698