| 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 // Generate a snapshot file after loading all the scripts specified on the | 5 // Generate a snapshot file after loading all the scripts specified on the |
| 6 // command line. | 6 // command line. |
| 7 | 7 |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 ASSERT(file != NULL); | 109 ASSERT(file != NULL); |
| 110 for (intptr_t i = 0; i < size; i++) { | 110 for (intptr_t i = 0; i < size; i++) { |
| 111 file->WriteByte(buffer[i]); | 111 file->WriteByte(buffer[i]); |
| 112 } | 112 } |
| 113 delete file; | 113 delete file; |
| 114 } | 114 } |
| 115 | 115 |
| 116 | 116 |
| 117 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, | 117 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, |
| 118 Dart_Handle library, | 118 Dart_Handle library, |
| 119 Dart_Handle url) { | 119 Dart_Handle url, |
| 120 Dart_Handle import_map) { |
| 120 if (!Dart_IsLibrary(library)) { | 121 if (!Dart_IsLibrary(library)) { |
| 121 return Dart_Error("not a library"); | 122 return Dart_Error("not a library"); |
| 122 } | 123 } |
| 123 if (!Dart_IsString8(url)) { | 124 if (!Dart_IsString8(url)) { |
| 124 return Dart_Error("url is not a string"); | 125 return Dart_Error("url is not a string"); |
| 125 } | 126 } |
| 126 const char* url_string = NULL; | 127 const char* url_string = NULL; |
| 127 Dart_Handle result = Dart_StringToCString(url, &url_string); | 128 Dart_Handle result = Dart_StringToCString(url, &url_string); |
| 128 if (Dart_IsError(result)) { | 129 if (Dart_IsError(result)) { |
| 129 return Dart_Error("accessing url characters failed"); | 130 return Dart_Error("accessing url characters failed"); |
| 130 } | 131 } |
| 131 | 132 |
| 132 // If the URL starts with "dart:" then it is handled specially. | 133 // If the URL starts with "dart:" then it is handled specially. |
| 133 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); | 134 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); |
| 134 if (tag == kCanonicalizeUrl) { | 135 if (tag == kCanonicalizeUrl) { |
| 135 if (is_dart_scheme_url) { | 136 if (is_dart_scheme_url) { |
| 136 return url; | 137 return url; |
| 137 } | 138 } |
| 138 return DartUtils::CanonicalizeURL(url_mapping, library, url_string); | 139 return DartUtils::CanonicalizeURL(url_mapping, library, url_string); |
| 139 } | 140 } |
| 140 return DartUtils::LoadSource(url_mapping, library, url, tag, url_string); | 141 return DartUtils::LoadSource(url_mapping, |
| 142 library, |
| 143 url, |
| 144 tag, |
| 145 url_string, |
| 146 import_map); |
| 141 } | 147 } |
| 142 | 148 |
| 143 | 149 |
| 144 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { | 150 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { |
| 145 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); | 151 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); |
| 146 if (Dart_IsError(source)) { | 152 if (Dart_IsError(source)) { |
| 147 return source; // source contains the error string. | 153 return source; // source contains the error string. |
| 148 } | 154 } |
| 149 Dart_Handle url = Dart_NewString(script_name); | 155 Dart_Handle url = Dart_NewString(script_name); |
| 156 Dart_Handle import_map = Dart_NewList(0); |
| 150 | 157 |
| 151 return Dart_LoadScript(url, source, CreateSnapshotLibraryTagHandler); | 158 return Dart_LoadScript(url, |
| 159 source, |
| 160 CreateSnapshotLibraryTagHandler, |
| 161 import_map); |
| 152 } | 162 } |
| 153 | 163 |
| 154 | 164 |
| 155 static Dart_Handle BuiltinLibraryTagHandler(Dart_LibraryTag tag, | 165 static Dart_Handle BuiltinLibraryTagHandler(Dart_LibraryTag tag, |
| 156 Dart_Handle library, | 166 Dart_Handle library, |
| 157 Dart_Handle url) { | 167 Dart_Handle url, |
| 168 Dart_Handle import_map) { |
| 158 if (!Dart_IsLibrary(library)) { | 169 if (!Dart_IsLibrary(library)) { |
| 159 return Dart_Error("not a library"); | 170 return Dart_Error("not a library"); |
| 160 } | 171 } |
| 161 if (!Dart_IsString8(url)) { | 172 if (!Dart_IsString8(url)) { |
| 162 return Dart_Error("url is not a string"); | 173 return Dart_Error("url is not a string"); |
| 163 } | 174 } |
| 164 const char* url_string = NULL; | 175 const char* url_string = NULL; |
| 165 Dart_Handle result = Dart_StringToCString(url, &url_string); | 176 Dart_Handle result = Dart_StringToCString(url, &url_string); |
| 166 if (Dart_IsError(result)) { | 177 if (Dart_IsError(result)) { |
| 167 return Dart_Error("accessing url characters failed"); | 178 return Dart_Error("accessing url characters failed"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 180 static Dart_Handle LoadGenericSnapshotCreationScript( | 191 static Dart_Handle LoadGenericSnapshotCreationScript( |
| 181 Builtin::BuiltinLibraryId id) { | 192 Builtin::BuiltinLibraryId id) { |
| 182 Dart_Handle source = Builtin::Source(id); | 193 Dart_Handle source = Builtin::Source(id); |
| 183 if (Dart_IsError(source)) { | 194 if (Dart_IsError(source)) { |
| 184 return source; // source contains the error string. | 195 return source; // source contains the error string. |
| 185 } | 196 } |
| 186 Dart_Handle lib; | 197 Dart_Handle lib; |
| 187 if (id == Builtin::kBuiltinLibrary) { | 198 if (id == Builtin::kBuiltinLibrary) { |
| 188 // Load the dart:builtin library as the script. | 199 // Load the dart:builtin library as the script. |
| 189 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 200 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
| 190 lib = Dart_LoadScript(url, source, BuiltinLibraryTagHandler); | 201 Dart_Handle import_map = Dart_NewList(0); |
| 202 lib = Dart_LoadScript(url, |
| 203 source, |
| 204 BuiltinLibraryTagHandler, |
| 205 import_map); |
| 191 } else { | 206 } else { |
| 192 ASSERT(id == Builtin::kIOLibrary); | 207 ASSERT(id == Builtin::kIOLibrary); |
| 193 // Load the dart:io library to make it available in the snapshot | 208 // Load the dart:io library to make it available in the snapshot |
| 194 // for importing. | 209 // for importing. |
| 195 lib = Builtin::LoadLibrary(Builtin::kIOLibrary); | 210 lib = Builtin::LoadLibrary(Builtin::kIOLibrary); |
| 196 } | 211 } |
| 197 if (!Dart_IsError(lib)) { | 212 if (!Dart_IsError(lib)) { |
| 198 Builtin::SetupLibrary(lib, id); | 213 Builtin::SetupLibrary(lib, id); |
| 199 } | 214 } |
| 200 return lib; | 215 return lib; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 exit(255); | 301 exit(255); |
| 287 } | 302 } |
| 288 // Now write the snapshot out to specified file and exit. | 303 // Now write the snapshot out to specified file and exit. |
| 289 WriteSnapshotFile(buffer, size); | 304 WriteSnapshotFile(buffer, size); |
| 290 Dart_ExitScope(); | 305 Dart_ExitScope(); |
| 291 | 306 |
| 292 // Shutdown the isolate. | 307 // Shutdown the isolate. |
| 293 Dart_ShutdownIsolate(); | 308 Dart_ShutdownIsolate(); |
| 294 return 0; | 309 return 0; |
| 295 } | 310 } |
| OLD | NEW |