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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 delete file; | 144 delete file; |
145 } | 145 } |
146 | 146 |
147 | 147 |
148 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, | 148 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, |
149 Dart_Handle library, | 149 Dart_Handle library, |
150 Dart_Handle url) { | 150 Dart_Handle url) { |
151 if (!Dart_IsLibrary(library)) { | 151 if (!Dart_IsLibrary(library)) { |
152 return Dart_Error("not a library"); | 152 return Dart_Error("not a library"); |
153 } | 153 } |
154 if (!Dart_IsString8(url)) { | 154 if (!Dart_IsString(url)) { |
155 return Dart_Error("url is not a string"); | 155 return Dart_Error("url is not a string"); |
156 } | 156 } |
157 const char* url_string = NULL; | 157 const char* url_string = NULL; |
158 Dart_Handle result = Dart_StringToCString(url, &url_string); | 158 Dart_Handle result = Dart_StringAsCString(url, &url_string); |
159 if (Dart_IsError(result)) { | 159 if (Dart_IsError(result)) { |
160 return result; | 160 return result; |
161 } | 161 } |
162 | 162 |
163 // If the URL starts with "dart:" then it is handled specially. | 163 // If the URL starts with "dart:" then it is handled specially. |
164 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); | 164 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); |
165 if (tag == kCanonicalizeUrl) { | 165 if (tag == kCanonicalizeUrl) { |
166 if (is_dart_scheme_url) { | 166 if (is_dart_scheme_url) { |
167 return url; | 167 return url; |
168 } | 168 } |
169 return DartUtils::CanonicalizeURL(url_mapping, library, url_string); | 169 return DartUtils::CanonicalizeURL(url_mapping, library, url_string); |
170 } | 170 } |
171 return DartUtils::LoadSource(url_mapping, | 171 return DartUtils::LoadSource(url_mapping, |
172 library, | 172 library, |
173 url, | 173 url, |
174 tag, | 174 tag, |
175 url_string); | 175 url_string); |
176 } | 176 } |
177 | 177 |
178 | 178 |
179 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { | 179 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { |
180 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); | 180 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); |
181 if (Dart_IsError(source)) { | 181 if (Dart_IsError(source)) { |
182 return source; // source contains the error string. | 182 return source; // source contains the error string. |
183 } | 183 } |
184 Dart_Handle url = Dart_NewString(script_name); | 184 Dart_Handle url = DartUtils::NewString(script_name); |
185 | 185 |
186 return Dart_LoadScript(url, source); | 186 return Dart_LoadScript(url, source); |
187 } | 187 } |
188 | 188 |
189 | 189 |
190 static Dart_Handle LoadGenericSnapshotCreationScript( | 190 static Dart_Handle LoadGenericSnapshotCreationScript( |
191 Builtin::BuiltinLibraryId id) { | 191 Builtin::BuiltinLibraryId id) { |
192 Dart_Handle source = Builtin::Source(id); | 192 Dart_Handle source = Builtin::Source(id); |
193 if (Dart_IsError(source)) { | 193 if (Dart_IsError(source)) { |
194 return source; // source contains the error string. | 194 return source; // source contains the error string. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 CreateAndWriteSnapshot(true); | 385 CreateAndWriteSnapshot(true); |
386 | 386 |
387 free(snapshot_buffer); | 387 free(snapshot_buffer); |
388 } | 388 } |
389 } else { | 389 } else { |
390 SetupForGenericSnapshotCreation(); | 390 SetupForGenericSnapshotCreation(); |
391 CreateAndWriteSnapshot(false); | 391 CreateAndWriteSnapshot(false); |
392 } | 392 } |
393 return 0; | 393 return 0; |
394 } | 394 } |
OLD | NEW |