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