OLD | NEW |
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" |
| 11 #include "bin/isolate_data.h" |
11 | 12 |
12 #include "platform/globals.h" | 13 #include "platform/globals.h" |
| 14 |
13 #include "vm/assembler.h" | 15 #include "vm/assembler.h" |
14 #include "vm/ast_printer.h" | 16 #include "vm/ast_printer.h" |
15 #include "vm/compiler.h" | 17 #include "vm/compiler.h" |
16 #include "vm/dart_api_impl.h" | 18 #include "vm/dart_api_impl.h" |
17 #include "vm/disassembler.h" | 19 #include "vm/disassembler.h" |
18 #include "vm/parser.h" | 20 #include "vm/parser.h" |
19 #include "vm/symbols.h" | 21 #include "vm/symbols.h" |
20 #include "vm/thread.h" | 22 #include "vm/thread.h" |
21 #include "vm/virtual_memory.h" | 23 #include "vm/virtual_memory.h" |
22 | 24 |
(...skipping 19 matching lines...) Expand all Loading... |
42 | 44 |
43 | 45 |
44 void TestCaseBase::RunAll() { | 46 void TestCaseBase::RunAll() { |
45 TestCaseBase* test = first_; | 47 TestCaseBase* test = first_; |
46 while (test != NULL) { | 48 while (test != NULL) { |
47 test->RunTest(); | 49 test->RunTest(); |
48 test = test->next_; | 50 test = test->next_; |
49 } | 51 } |
50 } | 52 } |
51 | 53 |
| 54 |
| 55 Dart_Isolate TestCase::CreateIsolate(const uint8_t* buffer, const char* name) { |
| 56 bin::IsolateData* isolate_data = new bin::IsolateData(name, NULL, NULL); |
| 57 char* err; |
| 58 Dart_Isolate isolate = Dart_CreateIsolate( |
| 59 name, NULL, buffer, NULL, isolate_data, &err); |
| 60 if (isolate == NULL) { |
| 61 OS::Print("Creation of isolate failed '%s'\n", err); |
| 62 free(err); |
| 63 } |
| 64 EXPECT(isolate != NULL); |
| 65 return isolate; |
| 66 } |
| 67 |
| 68 |
52 static const char* kPackageScheme = "package:"; | 69 static const char* kPackageScheme = "package:"; |
53 | 70 |
54 static bool IsPackageSchemeURL(const char* url_name) { | 71 static bool IsPackageSchemeURL(const char* url_name) { |
55 static const intptr_t kPackageSchemeLen = strlen(kPackageScheme); | 72 static const intptr_t kPackageSchemeLen = strlen(kPackageScheme); |
56 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0); | 73 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0); |
57 } | 74 } |
58 | 75 |
59 static Dart_Handle ResolvePackageUri(Dart_Handle builtin_lib, | 76 static Dart_Handle ResolvePackageUri(const char* uri_chars) { |
60 const char* uri_chars) { | 77 bin::IsolateData* isolate_data = |
| 78 reinterpret_cast<bin::IsolateData*>(Dart_CurrentIsolateData()); |
| 79 Dart_Handle builtin_lib = isolate_data->builtin_lib(); |
61 const int kNumArgs = 1; | 80 const int kNumArgs = 1; |
62 Dart_Handle dart_args[kNumArgs]; | 81 Dart_Handle dart_args[kNumArgs]; |
63 dart_args[0] = DartUtils::NewString(uri_chars); | 82 dart_args[0] = DartUtils::NewString(uri_chars); |
64 return Dart_Invoke(builtin_lib, | 83 return Dart_Invoke(builtin_lib, |
65 DartUtils::NewString("_filePathFromUri"), | 84 DartUtils::NewString("_filePathFromUri"), |
66 kNumArgs, | 85 kNumArgs, |
67 dart_args); | 86 dart_args); |
68 } | 87 } |
69 | 88 |
70 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, | 89 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, |
(...skipping 10 matching lines...) Expand all Loading... |
81 if (Dart_IsError(result)) { | 100 if (Dart_IsError(result)) { |
82 return Dart_NewApiError("accessing url characters failed"); | 101 return Dart_NewApiError("accessing url characters failed"); |
83 } | 102 } |
84 Dart_Handle library_url = Dart_LibraryUrl(library); | 103 Dart_Handle library_url = Dart_LibraryUrl(library); |
85 const char* library_url_string = NULL; | 104 const char* library_url_string = NULL; |
86 result = Dart_StringToCString(library_url, &library_url_string); | 105 result = Dart_StringToCString(library_url, &library_url_string); |
87 if (Dart_IsError(result)) { | 106 if (Dart_IsError(result)) { |
88 return result; | 107 return result; |
89 } | 108 } |
90 | 109 |
91 Dart_Handle builtin_lib = | |
92 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | |
93 DART_CHECK_VALID(builtin_lib); | |
94 | |
95 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars); | 110 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars); |
96 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); | 111 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); |
97 if (tag == Dart_kCanonicalizeUrl) { | 112 if (tag == Dart_kCanonicalizeUrl) { |
98 // If this is a Dart Scheme URL then it is not modified as it will be | 113 // If this is a Dart Scheme URL then it is not modified as it will be |
99 // handled by the VM internally. | 114 // handled by the VM internally. |
100 if (is_dart_scheme_url || is_io_library) { | 115 if (is_dart_scheme_url || is_io_library) { |
101 return url; | 116 return url; |
102 } | 117 } |
103 | 118 |
104 Dart_Handle library_url = Dart_LibraryUrl(library); | 119 Dart_Handle library_url = Dart_LibraryUrl(library); |
105 if (Dart_IsError(library_url)) { | 120 if (Dart_IsError(library_url)) { |
106 return library_url; | 121 return library_url; |
107 } | 122 } |
108 return DartUtils::ResolveUri(library_url, url, builtin_lib); | 123 return DartUtils::ResolveUri(library_url, url); |
109 } | 124 } |
110 if (is_dart_scheme_url) { | 125 if (is_dart_scheme_url) { |
111 ASSERT(tag == Dart_kImportTag); | 126 ASSERT(tag == Dart_kImportTag); |
112 // Handle imports of other built-in libraries present in the SDK. | 127 // Handle imports of other built-in libraries present in the SDK. |
113 if (DartUtils::IsDartIOLibURL(url_chars)) { | 128 if (DartUtils::IsDartIOLibURL(url_chars)) { |
114 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 129 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
115 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { | 130 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { |
116 return builtin_lib; | 131 return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
117 } else { | 132 } else { |
118 return DartUtils::NewError("Do not know how to load '%s'", url_chars); | 133 return DartUtils::NewError("Do not know how to load '%s'", url_chars); |
119 } | 134 } |
120 } | 135 } |
121 if (is_io_library) { | 136 if (is_io_library) { |
122 ASSERT(tag == Dart_kSourceTag); | 137 ASSERT(tag == Dart_kSourceTag); |
123 return Dart_LoadSource(library, | 138 return Dart_LoadSource(library, |
124 url, | 139 url, |
125 Builtin::PartSource(Builtin::kIOLibrary, | 140 Builtin::PartSource(Builtin::kIOLibrary, |
126 url_chars), | 141 url_chars), |
127 0, 0); | 142 0, 0); |
128 } | 143 } |
129 if (IsPackageSchemeURL(url_chars)) { | 144 if (IsPackageSchemeURL(url_chars)) { |
130 Dart_Handle resolved_uri = ResolvePackageUri(builtin_lib, url_chars); | 145 Dart_Handle resolved_uri = ResolvePackageUri(url_chars); |
131 DART_CHECK_VALID(resolved_uri); | 146 DART_CHECK_VALID(resolved_uri); |
132 url_chars = NULL; | 147 url_chars = NULL; |
133 Dart_Handle result = Dart_StringToCString(resolved_uri, &url_chars); | 148 Dart_Handle result = Dart_StringToCString(resolved_uri, &url_chars); |
134 if (Dart_IsError(result)) { | 149 if (Dart_IsError(result)) { |
135 return Dart_NewApiError("accessing url characters failed"); | 150 return Dart_NewApiError("accessing url characters failed"); |
136 } | 151 } |
137 } | 152 } |
138 // Do sync loading since unit_test doesn't support async. | 153 // Do sync loading since unit_test doesn't support async. |
139 Dart_Handle source = DartUtils::ReadStringFromFile(url_chars); | 154 Dart_Handle source = DartUtils::ReadStringFromFile(url_chars); |
140 EXPECT_VALID(source); | 155 EXPECT_VALID(source); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 315 } |
301 // Copy the remainder of in to out. | 316 // Copy the remainder of in to out. |
302 while (*in != '\0') { | 317 while (*in != '\0') { |
303 *out++ = *in++; | 318 *out++ = *in++; |
304 } | 319 } |
305 *out = '\0'; | 320 *out = '\0'; |
306 } | 321 } |
307 | 322 |
308 | 323 |
309 } // namespace dart | 324 } // namespace dart |
OLD | NEW |