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) { | |
61 const int kNumArgs = 1; | 77 const int kNumArgs = 1; |
62 Dart_Handle dart_args[kNumArgs]; | 78 Dart_Handle dart_args[kNumArgs]; |
63 dart_args[0] = DartUtils::NewString(uri_chars); | 79 dart_args[0] = DartUtils::NewString(uri_chars); |
64 return Dart_Invoke(builtin_lib, | 80 return Dart_Invoke(DartUtils::BuiltinLib(), |
65 DartUtils::NewString("_filePathFromUri"), | 81 DartUtils::NewString("_filePathFromUri"), |
66 kNumArgs, | 82 kNumArgs, |
67 dart_args); | 83 dart_args); |
68 } | 84 } |
69 | 85 |
70 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, | 86 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, |
71 Dart_Handle library, | 87 Dart_Handle library, |
72 Dart_Handle url) { | 88 Dart_Handle url) { |
73 if (!Dart_IsLibrary(library)) { | 89 if (!Dart_IsLibrary(library)) { |
74 return Dart_NewApiError("not a library"); | 90 return Dart_NewApiError("not a library"); |
75 } | 91 } |
76 if (!Dart_IsString(url)) { | 92 if (!Dart_IsString(url)) { |
77 return Dart_NewApiError("url is not a string"); | 93 return Dart_NewApiError("url is not a string"); |
78 } | 94 } |
79 const char* url_chars = NULL; | 95 const char* url_chars = NULL; |
80 Dart_Handle result = Dart_StringToCString(url, &url_chars); | 96 Dart_Handle result = Dart_StringToCString(url, &url_chars); |
81 if (Dart_IsError(result)) { | 97 if (Dart_IsError(result)) { |
82 return Dart_NewApiError("accessing url characters failed"); | 98 return Dart_NewApiError("accessing url characters failed"); |
83 } | 99 } |
84 Dart_Handle library_url = Dart_LibraryUrl(library); | 100 Dart_Handle library_url = Dart_LibraryUrl(library); |
85 const char* library_url_string = NULL; | 101 const char* library_url_string = NULL; |
86 result = Dart_StringToCString(library_url, &library_url_string); | 102 result = Dart_StringToCString(library_url, &library_url_string); |
87 if (Dart_IsError(result)) { | 103 if (Dart_IsError(result)) { |
88 return result; | 104 return result; |
89 } | 105 } |
90 | 106 |
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); | 107 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars); |
96 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); | 108 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); |
97 if (tag == Dart_kCanonicalizeUrl) { | 109 if (tag == Dart_kCanonicalizeUrl) { |
98 // If this is a Dart Scheme URL then it is not modified as it will be | 110 // If this is a Dart Scheme URL then it is not modified as it will be |
99 // handled by the VM internally. | 111 // handled by the VM internally. |
100 if (is_dart_scheme_url || is_io_library) { | 112 if (is_dart_scheme_url || is_io_library) { |
101 return url; | 113 return url; |
102 } | 114 } |
103 | 115 |
104 Dart_Handle library_url = Dart_LibraryUrl(library); | 116 Dart_Handle library_url = Dart_LibraryUrl(library); |
105 if (Dart_IsError(library_url)) { | 117 if (Dart_IsError(library_url)) { |
106 return library_url; | 118 return library_url; |
107 } | 119 } |
108 return DartUtils::ResolveUri(library_url, url, builtin_lib); | 120 return DartUtils::ResolveUri(library_url, url); |
109 } | 121 } |
110 if (is_dart_scheme_url) { | 122 if (is_dart_scheme_url) { |
111 ASSERT(tag == Dart_kImportTag); | 123 ASSERT(tag == Dart_kImportTag); |
112 // Handle imports of other built-in libraries present in the SDK. | 124 // Handle imports of other built-in libraries present in the SDK. |
113 if (DartUtils::IsDartIOLibURL(url_chars)) { | 125 if (DartUtils::IsDartIOLibURL(url_chars)) { |
114 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 126 return Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
115 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { | 127 } else if (DartUtils::IsDartBuiltinLibURL(url_chars)) { |
116 return builtin_lib; | 128 return Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
117 } else { | 129 } else { |
118 return DartUtils::NewError("Do not know how to load '%s'", url_chars); | 130 return DartUtils::NewError("Do not know how to load '%s'", url_chars); |
119 } | 131 } |
120 } | 132 } |
121 if (is_io_library) { | 133 if (is_io_library) { |
122 ASSERT(tag == Dart_kSourceTag); | 134 ASSERT(tag == Dart_kSourceTag); |
123 return Dart_LoadSource(library, | 135 return Dart_LoadSource(library, |
124 url, | 136 url, |
125 Builtin::PartSource(Builtin::kIOLibrary, | 137 Builtin::PartSource(Builtin::kIOLibrary, |
126 url_chars), | 138 url_chars), |
127 0, 0); | 139 0, 0); |
128 } | 140 } |
129 if (IsPackageSchemeURL(url_chars)) { | 141 if (IsPackageSchemeURL(url_chars)) { |
130 Dart_Handle resolved_uri = ResolvePackageUri(builtin_lib, url_chars); | 142 Dart_Handle resolved_uri = ResolvePackageUri(url_chars); |
131 DART_CHECK_VALID(resolved_uri); | 143 DART_CHECK_VALID(resolved_uri); |
132 url_chars = NULL; | 144 url_chars = NULL; |
133 Dart_Handle result = Dart_StringToCString(resolved_uri, &url_chars); | 145 Dart_Handle result = Dart_StringToCString(resolved_uri, &url_chars); |
134 if (Dart_IsError(result)) { | 146 if (Dart_IsError(result)) { |
135 return Dart_NewApiError("accessing url characters failed"); | 147 return Dart_NewApiError("accessing url characters failed"); |
136 } | 148 } |
137 } | 149 } |
138 // Do sync loading since unit_test doesn't support async. | 150 // Do sync loading since unit_test doesn't support async. |
139 Dart_Handle source = DartUtils::ReadStringFromFile(url_chars); | 151 Dart_Handle source = DartUtils::ReadStringFromFile(url_chars); |
140 EXPECT_VALID(source); | 152 EXPECT_VALID(source); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 312 } |
301 // Copy the remainder of in to out. | 313 // Copy the remainder of in to out. |
302 while (*in != '\0') { | 314 while (*in != '\0') { |
303 *out++ = *in++; | 315 *out++ = *in++; |
304 } | 316 } |
305 *out = '\0'; | 317 *out = '\0'; |
306 } | 318 } |
307 | 319 |
308 | 320 |
309 } // namespace dart | 321 } // namespace dart |
OLD | NEW |