| 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
| 8 | 8 |
| 9 #include "bin/builtin.h" |
| 10 #include "bin/dartutils.h" |
| 11 |
| 9 #include "vm/assembler.h" | 12 #include "vm/assembler.h" |
| 10 #include "vm/ast_printer.h" | 13 #include "vm/ast_printer.h" |
| 11 #include "vm/code_generator.h" | 14 #include "vm/code_generator.h" |
| 12 #include "vm/compiler.h" | 15 #include "vm/compiler.h" |
| 13 #include "vm/dart_api_impl.h" | 16 #include "vm/dart_api_impl.h" |
| 14 #include "vm/disassembler.h" | 17 #include "vm/disassembler.h" |
| 15 #include "vm/longjump.h" | 18 #include "vm/longjump.h" |
| 16 #include "vm/parser.h" | 19 #include "vm/parser.h" |
| 17 #include "vm/virtual_memory.h" | 20 #include "vm/virtual_memory.h" |
| 18 | 21 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return Dart_Error("not a library"); | 56 return Dart_Error("not a library"); |
| 54 } | 57 } |
| 55 if (!Dart_IsString8(url)) { | 58 if (!Dart_IsString8(url)) { |
| 56 return Dart_Error("url is not a string"); | 59 return Dart_Error("url is not a string"); |
| 57 } | 60 } |
| 58 const char* url_chars = NULL; | 61 const char* url_chars = NULL; |
| 59 Dart_Handle result = Dart_StringToCString(url, &url_chars); | 62 Dart_Handle result = Dart_StringToCString(url, &url_chars); |
| 60 if (Dart_IsError(result)) { | 63 if (Dart_IsError(result)) { |
| 61 return Dart_Error("accessing url characters failed"); | 64 return Dart_Error("accessing url characters failed"); |
| 62 } | 65 } |
| 63 static const char* kDartScheme = "dart:"; | 66 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_chars); |
| 64 static const intptr_t kDartSchemeLen = strlen(kDartScheme); | 67 if (tag == kCanonicalizeUrl) { |
| 65 // If the URL starts with "dart:" then it is not modified as it will be | 68 // If this is a Dart Scheme URL then it is not modified as it will be |
| 66 // handled by the VM internally. | 69 // handled by the VM internally. |
| 67 if (strncmp(url_chars, kDartScheme, kDartSchemeLen) == 0) { | 70 if (is_dart_scheme_url) { |
| 68 if (tag == kCanonicalizeUrl) { | |
| 69 return url; | 71 return url; |
| 70 } | 72 } |
| 71 return Dart_Error("unexpected tag encountered %d", tag); | 73 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); |
| 74 DART_CHECK_VALID(builtin_lib); |
| 75 return DartUtils::CanonicalizeURL(NULL, library, url_chars); |
| 72 } | 76 } |
| 73 return Dart_Error("unsupported url encountered %s", url_chars); | 77 if (is_dart_scheme_url) { |
| 78 ASSERT(tag == kImportTag); |
| 79 // Handle imports of other built-in libraries present in the SDK. |
| 80 if (DartUtils::IsDartIOLibURL(url_chars)) { |
| 81 return Builtin::LoadLibrary(Builtin::kIOLibrary); |
| 82 } else if (DartUtils::IsDartJsonLibURL(url_chars)) { |
| 83 return Builtin::LoadLibrary(Builtin::kJsonLibrary); |
| 84 } else if (DartUtils::IsDartUriLibURL(url_chars)) { |
| 85 return Builtin::LoadLibrary(Builtin::kUriLibrary); |
| 86 } else if (DartUtils::IsDartUtfLibURL(url_chars)) { |
| 87 return Builtin::LoadLibrary(Builtin::kUtfLibrary); |
| 88 } else { |
| 89 return Dart_Error("Do not know how to load '%s'", url_chars); |
| 90 } |
| 91 } |
| 92 result = DartUtils::LoadSource(NULL, |
| 93 library, |
| 94 url, |
| 95 tag, |
| 96 url_chars, |
| 97 import_map); |
| 98 if (!Dart_IsError(result) && (tag == kImportTag)) { |
| 99 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary); |
| 100 } |
| 101 return result; |
| 74 } | 102 } |
| 75 | 103 |
| 76 | 104 |
| 77 Dart_Handle TestCase::LoadTestScript(const char* script, | 105 Dart_Handle TestCase::LoadTestScript(const char* script, |
| 78 Dart_NativeEntryResolver resolver) { | 106 Dart_NativeEntryResolver resolver) { |
| 79 Dart_Handle url = Dart_NewString(TestCase::url()); | 107 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 80 Dart_Handle source = Dart_NewString(script); | 108 Dart_Handle source = Dart_NewString(script); |
| 81 Dart_Handle import_map = Dart_NewList(0); | 109 Dart_Handle import_map = Dart_NewList(0); |
| 82 Dart_Handle lib = Dart_LoadScript(url, source, LibraryTagHandler, import_map); | 110 Dart_Handle lib = Dart_LoadScript(url, source, LibraryTagHandler, import_map); |
| 83 DART_CHECK_VALID(lib); | 111 DART_CHECK_VALID(lib); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 221 |
| 194 bool CompilerTest::TestCompileFunction(const Function& function) { | 222 bool CompilerTest::TestCompileFunction(const Function& function) { |
| 195 Isolate* isolate = Isolate::Current(); | 223 Isolate* isolate = Isolate::Current(); |
| 196 ASSERT(isolate != NULL); | 224 ASSERT(isolate != NULL); |
| 197 ASSERT(ClassFinalizer::AllClassesFinalized()); | 225 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 198 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 226 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
| 199 return error.IsNull(); | 227 return error.IsNull(); |
| 200 } | 228 } |
| 201 | 229 |
| 202 } // namespace dart | 230 } // namespace dart |
| OLD | NEW |