| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Handle dart scripts. | 5 // Handle dart scripts. |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 Dart_Handle url, | 91 Dart_Handle url, |
| 92 bool import_builtin_lib) { | 92 bool import_builtin_lib) { |
| 93 if (!Dart_IsLibrary(library)) { | 93 if (!Dart_IsLibrary(library)) { |
| 94 return Dart_Error("not a library"); | 94 return Dart_Error("not a library"); |
| 95 } | 95 } |
| 96 if (!Dart_IsString8(url)) { | 96 if (!Dart_IsString8(url)) { |
| 97 return Dart_Error("url is not a string"); | 97 return Dart_Error("url is not a string"); |
| 98 } | 98 } |
| 99 const char* url_chars = NULL; | 99 const char* url_chars = NULL; |
| 100 Dart_Handle result = Dart_StringToCString(url, &url_chars); | 100 Dart_Handle result = Dart_StringToCString(url, &url_chars); |
| 101 if (!Dart_IsValid(result)) { | 101 if (Dart_IsError(result)) { |
| 102 return Dart_Error("accessing url characters failed"); | 102 return Dart_Error("accessing url characters failed"); |
| 103 } | 103 } |
| 104 | 104 |
| 105 if (tag == kCanonicalizeUrl) { | 105 if (tag == kCanonicalizeUrl) { |
| 106 // Create the full path based on the including library and the current url. | 106 // Create the full path based on the including library and the current url. |
| 107 | 107 |
| 108 // Get the url of the calling library. | 108 // Get the url of the calling library. |
| 109 Dart_Handle library_url = Dart_LibraryUrl(library); | 109 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 110 if (!Dart_IsValid(library_url)) { | 110 if (Dart_IsError(library_url)) { |
| 111 return Dart_Error("accessing library url failed"); | 111 return Dart_Error("accessing library url failed"); |
| 112 } | 112 } |
| 113 if (!Dart_IsString8(library_url)) { | 113 if (!Dart_IsString8(library_url)) { |
| 114 return Dart_Error("library url is not a string"); | 114 return Dart_Error("library url is not a string"); |
| 115 } | 115 } |
| 116 const char* library_url_chars = NULL; | 116 const char* library_url_chars = NULL; |
| 117 result = Dart_StringToCString(library_url, &library_url_chars); | 117 result = Dart_StringToCString(library_url, &library_url_chars); |
| 118 if (!Dart_IsValid(result)) { | 118 if (Dart_IsError(result)) { |
| 119 return Dart_Error("accessing library url characters failed"); | 119 return Dart_Error("accessing library url characters failed"); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Calculate the path. | 122 // Calculate the path. |
| 123 const char* canon_url_chars = CanonicalizeUrl(library_url_chars, url_chars); | 123 const char* canon_url_chars = CanonicalizeUrl(library_url_chars, url_chars); |
| 124 Dart_Handle canon_url = Dart_NewString(canon_url_chars); | 124 Dart_Handle canon_url = Dart_NewString(canon_url_chars); |
| 125 free(const_cast<char*>(canon_url_chars)); | 125 free(const_cast<char*>(canon_url_chars)); |
| 126 | 126 |
| 127 return canon_url; | 127 return canon_url; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // The tag is either an import or a source tag. Read the file based on the | 130 // The tag is either an import or a source tag. Read the file based on the |
| 131 // url chars. | 131 // url chars. |
| 132 Dart_Handle source = ReadStringFromFile(url_chars); | 132 Dart_Handle source = ReadStringFromFile(url_chars); |
| 133 if (!Dart_IsValid(source)) { | 133 if (Dart_IsError(source)) { |
| 134 return source; // source contains the error string. | 134 return source; // source contains the error string. |
| 135 } | 135 } |
| 136 if (tag == kImportTag) { | 136 if (tag == kImportTag) { |
| 137 Dart_Handle new_lib = Dart_LoadLibrary(url, source); | 137 Dart_Handle new_lib = Dart_LoadLibrary(url, source); |
| 138 if (import_builtin_lib && Dart_IsValid(new_lib)) { | 138 if (import_builtin_lib && !Dart_IsError(new_lib)) { |
| 139 Builtin_ImportLibrary(new_lib); | 139 Builtin_ImportLibrary(new_lib); |
| 140 } | 140 } |
| 141 return new_lib; // Return library object or an error string. | 141 return new_lib; // Return library object or an error string. |
| 142 } else if (tag == kSourceTag) { | 142 } else if (tag == kSourceTag) { |
| 143 return Dart_LoadSource(library, url, source); | 143 return Dart_LoadSource(library, url, source); |
| 144 } | 144 } |
| 145 return Dart_Error("wrong tag"); | 145 return Dart_Error("wrong tag"); |
| 146 } | 146 } |
| 147 | 147 |
| 148 static Dart_Handle MainLibraryTagHandler(Dart_LibraryTag tag, | 148 static Dart_Handle MainLibraryTagHandler(Dart_LibraryTag tag, |
| 149 Dart_Handle library, | 149 Dart_Handle library, |
| 150 Dart_Handle url) { | 150 Dart_Handle url) { |
| 151 const bool kImportBuiltinLib = true; // Import builtin library. | 151 const bool kImportBuiltinLib = true; // Import builtin library. |
| 152 return LibraryTagHandlerHelper(tag, library, url, kImportBuiltinLib); | 152 return LibraryTagHandlerHelper(tag, library, url, kImportBuiltinLib); |
| 153 } | 153 } |
| 154 | 154 |
| 155 | 155 |
| 156 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, | 156 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, |
| 157 Dart_Handle library, | 157 Dart_Handle library, |
| 158 Dart_Handle url) { | 158 Dart_Handle url) { |
| 159 const bool kDontImportBuiltinLib = false; // Do not import builtin lib. | 159 const bool kDontImportBuiltinLib = false; // Do not import builtin lib. |
| 160 return LibraryTagHandlerHelper(tag, library, url, kDontImportBuiltinLib); | 160 return LibraryTagHandlerHelper(tag, library, url, kDontImportBuiltinLib); |
| 161 } | 161 } |
| 162 | 162 |
| 163 | 163 |
| 164 Dart_Handle LoadScript(const char* script_name) { | 164 Dart_Handle LoadScript(const char* script_name) { |
| 165 Dart_Handle source = ReadStringFromFile(script_name); | 165 Dart_Handle source = ReadStringFromFile(script_name); |
| 166 if (!Dart_IsValid(source)) { | 166 if (Dart_IsError(source)) { |
| 167 return source; | 167 return source; |
| 168 } | 168 } |
| 169 Dart_Handle url = Dart_NewString(script_name); | 169 Dart_Handle url = Dart_NewString(script_name); |
| 170 | 170 |
| 171 return Dart_LoadScript(url, source, MainLibraryTagHandler); | 171 return Dart_LoadScript(url, source, MainLibraryTagHandler); |
| 172 } | 172 } |
| 173 | 173 |
| 174 | 174 |
| 175 Dart_Handle LoadSnapshotCreationScript(const char* script_name) { | 175 Dart_Handle LoadSnapshotCreationScript(const char* script_name) { |
| 176 Dart_Handle source = ReadStringFromFile(script_name); | 176 Dart_Handle source = ReadStringFromFile(script_name); |
| 177 if (!Dart_IsValid(source)) { | 177 if (Dart_IsError(source)) { |
| 178 return source; | 178 return source; |
| 179 } | 179 } |
| 180 Dart_Handle url = Dart_NewString(script_name); | 180 Dart_Handle url = Dart_NewString(script_name); |
| 181 | 181 |
| 182 return Dart_LoadScript(url, source, CreateSnapshotLibraryTagHandler); | 182 return Dart_LoadScript(url, source, CreateSnapshotLibraryTagHandler); |
| 183 } | 183 } |
| OLD | NEW |