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

Side by Side Diff: runtime/vm/unit_test.cc

Issue 2205513002: Pay attention to exports when determine which libraries to reload. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Pay attention to exports when determine which libraries to reload. Created 4 years, 4 months 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/unit_test.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "vm/unit_test.h" 5 #include "vm/unit_test.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 static const char* kPackageScheme = "package:"; 68 static const char* kPackageScheme = "package:";
69 69
70 70
71 static bool IsPackageSchemeURL(const char* url_name) { 71 static bool IsPackageSchemeURL(const char* url_name) {
72 static const intptr_t kPackageSchemeLen = strlen(kPackageScheme); 72 static const intptr_t kPackageSchemeLen = strlen(kPackageScheme);
73 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0); 73 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0);
74 } 74 }
75 75
76 76
77 static bool IsImportableTestLib(const char* url_name) { 77 struct TestLibEntry {
78 const char* kImportTestLibUri = "test:importable_lib"; 78 const char* url;
79 static const intptr_t kImportTestLibUriLen = strlen(kImportTestLibUri); 79 const char* source;
80 return (strncmp(url_name, kImportTestLibUri, kImportTestLibUriLen) == 0); 80 };
81
82
83 static MallocGrowableArray<TestLibEntry>* test_libs_ = NULL;
84
85
86 void TestCase::AddTestLib(const char* url, const char* source) {
87 if (test_libs_ == NULL) {
88 test_libs_ = new MallocGrowableArray<TestLibEntry>();
89 }
90 // If the test lib is already added, replace the source.
91 for (intptr_t i = 0; i < test_libs_->length(); i++) {
92 if (strcmp(url, (*test_libs_)[i].url) == 0) {
93 (*test_libs_)[i].source = source;
94 return;
95 }
96 }
97 TestLibEntry entry;
98 entry.url = url;
99 entry.source = source;
100 test_libs_->Add(entry);
81 } 101 }
82 102
83 103
84 const char* kDefaultImportableTestLibScript = 104 const char* TestCase::GetTestLib(const char* url) {
85 "importedFunc() => 'a';\n" 105 if (test_libs_ == NULL) {
86 "importedIntFunc() => 4;\n" 106 return NULL;
87 "class ImportedMixin {\n" 107 }
88 " mixinFunc() => 'mixin';\n" 108 for (intptr_t i = 0; i < test_libs_->length(); i++) {
89 "}\n"; 109 if (strcmp(url, (*test_libs_)[i].url) == 0) {
90 const char* importable_test_lib_script = kDefaultImportableTestLibScript; 110 return (*test_libs_)[i].source;
91 111 }
92 112 }
93 void TestCase::SetImportableTestLibScript(const char* source) { 113 return NULL;
94 importable_test_lib_script = source;
95 } 114 }
96 115
97
98 void TestCase::RestoreImportableTestLibScript() {
99 importable_test_lib_script = kDefaultImportableTestLibScript;
100 }
101
102
103 static Dart_Handle ImportableTestLibSource() {
104 return DartUtils::NewString(importable_test_lib_script);
105 }
106
107
108 #ifndef PRODUCT 116 #ifndef PRODUCT
109 static bool IsIsolateReloadTestLib(const char* url_name) { 117 static bool IsIsolateReloadTestLib(const char* url_name) {
110 const char* kIsolateReloadTestLibUri = "test:isolate_reload_helper"; 118 const char* kIsolateReloadTestLibUri = "test:isolate_reload_helper";
111 static const intptr_t kIsolateReloadTestLibUriLen = 119 static const intptr_t kIsolateReloadTestLibUriLen =
112 strlen(kIsolateReloadTestLibUri); 120 strlen(kIsolateReloadTestLibUri);
113 return (strncmp(url_name, 121 return (strncmp(url_name,
114 kIsolateReloadTestLibUri, 122 kIsolateReloadTestLibUri,
115 kIsolateReloadTestLibUriLen) == 0); 123 kIsolateReloadTestLibUriLen) == 0);
116 } 124 }
117 125
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 ASSERT(tag == Dart_kImportTag); 205 ASSERT(tag == Dart_kImportTag);
198 // Handle imports of other built-in libraries present in the SDK. 206 // Handle imports of other built-in libraries present in the SDK.
199 if (DartUtils::IsDartIOLibURL(url_chars)) { 207 if (DartUtils::IsDartIOLibURL(url_chars)) {
200 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); 208 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
201 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { 209 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) {
202 return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 210 return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
203 } else { 211 } else {
204 return DartUtils::NewError("Do not know how to load '%s'", url_chars); 212 return DartUtils::NewError("Do not know how to load '%s'", url_chars);
205 } 213 }
206 } 214 }
207 if (IsImportableTestLib(url_chars)) { 215 const char* lib_source = TestCase::GetTestLib(url_chars);
208 return Dart_LoadLibrary(url, Dart_Null(), ImportableTestLibSource(), 0, 0); 216 if (lib_source != NULL) {
217 Dart_Handle source = Dart_NewStringFromCString(lib_source);
218 return Dart_LoadLibrary(url, Dart_Null(), source, 0, 0);
209 } 219 }
210 NOT_IN_PRODUCT( 220 NOT_IN_PRODUCT(
211 if (IsIsolateReloadTestLib(url_chars)) { 221 if (IsIsolateReloadTestLib(url_chars)) {
212 Dart_Handle library = 222 Dart_Handle library =
213 Dart_LoadLibrary(url, Dart_Null(), IsolateReloadTestLibSource(), 0, 0); 223 Dart_LoadLibrary(url, Dart_Null(), IsolateReloadTestLibSource(), 0, 0);
214 DART_CHECK_VALID(library); 224 DART_CHECK_VALID(library);
215 Dart_SetNativeResolver(library, IsolateReloadTestNativeResolver, 0); 225 Dart_SetNativeResolver(library, IsolateReloadTestNativeResolver, 0);
216 return library; 226 return library;
217 }) 227 })
218 if (is_io_library) { 228 if (is_io_library) {
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } 484 }
475 // Copy the remainder of in to out. 485 // Copy the remainder of in to out.
476 while (*in != '\0') { 486 while (*in != '\0') {
477 *out++ = *in++; 487 *out++ = *in++;
478 } 488 }
479 *out = '\0'; 489 *out = '\0';
480 } 490 }
481 491
482 492
483 } // namespace dart 493 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/unit_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698