| 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 #include "include/dart_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 return url; | 236 return url; |
| 237 } | 237 } |
| 238 // Create a canonical path based on the including library and current url. | 238 // Create a canonical path based on the including library and current url. |
| 239 return DartUtils::CanonicalizeURL(NULL, library, url_string); | 239 return DartUtils::CanonicalizeURL(NULL, library, url_string); |
| 240 } | 240 } |
| 241 if (is_dart_scheme_url) { | 241 if (is_dart_scheme_url) { |
| 242 return Dart_Error("Do not know how to load '%s'", url_string); | 242 return Dart_Error("Do not know how to load '%s'", url_string); |
| 243 } | 243 } |
| 244 result = DartUtils::LoadSource(NULL, library, url, tag, url_string); | 244 result = DartUtils::LoadSource(NULL, library, url, tag, url_string); |
| 245 if (!Dart_IsError(result) && (tag == kImportTag)) { | 245 if (!Dart_IsError(result) && (tag == kImportTag)) { |
| 246 Builtin::ImportLibrary(result); | 246 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary); |
| 247 } | 247 } |
| 248 return result; | 248 return result; |
| 249 } | 249 } |
| 250 | 250 |
| 251 | 251 |
| 252 static Dart_Handle LoadScript(const char* script_name) { | 252 static Dart_Handle LoadScript(const char* script_name) { |
| 253 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); | 253 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); |
| 254 if (Dart_IsError(source)) { | 254 if (Dart_IsError(source)) { |
| 255 return source; | 255 return source; |
| 256 } | 256 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 268 return false; | 268 return false; |
| 269 } | 269 } |
| 270 | 270 |
| 271 Dart_Handle library; | 271 Dart_Handle library; |
| 272 Dart_EnterScope(); | 272 Dart_EnterScope(); |
| 273 | 273 |
| 274 // Load the specified application script into the newly created isolate. | 274 // Load the specified application script into the newly created isolate. |
| 275 if (script_snapshot_buffer != NULL) { | 275 if (script_snapshot_buffer != NULL) { |
| 276 library = Dart_LoadScriptFromSnapshot(script_snapshot_buffer); | 276 library = Dart_LoadScriptFromSnapshot(script_snapshot_buffer); |
| 277 } else { | 277 } else { |
| 278 // If we are not using snapshots make sure that the builtin IO |
| 279 // library is loaded so the main script can import it. Since we do |
| 280 // not have a tag handler at this point, load the libraries needed |
| 281 // by the IO library directly instead of relying on imports. |
| 282 if (snapshot_buffer == NULL) { |
| 283 Dart_Handle io_lib = Builtin::LoadLibrary(Builtin::kIOLibrary); |
| 284 Builtin::ImportLibrary(io_lib, Builtin::kNativeWrappersLibrary); |
| 285 Builtin::ImportLibrary(io_lib, Builtin::kCoreImplLibrary); |
| 286 } |
| 278 library = LoadScript(canonical_script_name); | 287 library = LoadScript(canonical_script_name); |
| 279 } | 288 } |
| 280 if (Dart_IsError(library)) { | 289 if (Dart_IsError(library)) { |
| 281 *error = strdup(Dart_GetError(library)); | 290 *error = strdup(Dart_GetError(library)); |
| 282 Dart_ExitScope(); | 291 Dart_ExitScope(); |
| 283 Dart_ShutdownIsolate(); | 292 Dart_ShutdownIsolate(); |
| 284 return false; | 293 return false; |
| 285 } | 294 } |
| 286 if (!Dart_IsLibrary(library)) { | 295 if (!Dart_IsLibrary(library)) { |
| 287 char errbuf[256]; | 296 char errbuf[256]; |
| 288 snprintf(errbuf, sizeof(errbuf), | 297 snprintf(errbuf, sizeof(errbuf), |
| 289 "Expected a library when loading script: %s", | 298 "Expected a library when loading script: %s", |
| 290 canonical_script_name); | 299 canonical_script_name); |
| 291 *error = strdup(errbuf); | 300 *error = strdup(errbuf); |
| 292 Dart_ExitScope(); | 301 Dart_ExitScope(); |
| 293 Dart_ShutdownIsolate(); | 302 Dart_ShutdownIsolate(); |
| 294 return false; | 303 return false; |
| 295 } | 304 } |
| 296 if (script_snapshot_buffer == NULL) { | 305 if (script_snapshot_buffer == NULL) { |
| 297 Builtin::ImportLibrary(library); // Implicitly import builtin into app. | 306 // Implicitly import builtin into app. |
| 307 Builtin::ImportLibrary(library, Builtin::kBuiltinLibrary); |
| 298 } | 308 } |
| 299 if (snapshot_buffer != NULL) { | 309 if (snapshot_buffer != NULL) { |
| 300 // Setup the native resolver as the snapshot does not carry it. | 310 // Setup the native resolver as the snapshot does not carry it. |
| 301 Builtin::SetNativeResolver(); | 311 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 312 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 302 } | 313 } |
| 303 Dart_ExitScope(); | 314 Dart_ExitScope(); |
| 304 return true; | 315 return true; |
| 305 } | 316 } |
| 306 | 317 |
| 307 | 318 |
| 308 static bool CaptureScriptSnapshot() { | 319 static bool CaptureScriptSnapshot() { |
| 309 char* error = NULL; | 320 char* error = NULL; |
| 310 Dart_Handle result; | 321 Dart_Handle result; |
| 311 | 322 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 Dart_ExitScope(); | 557 Dart_ExitScope(); |
| 547 // Dump symbol information for the profiler. | 558 // Dump symbol information for the profiler. |
| 548 DumpPprofSymbolInfo(); | 559 DumpPprofSymbolInfo(); |
| 549 // Shutdown the isolate. | 560 // Shutdown the isolate. |
| 550 Dart_ShutdownIsolate(); | 561 Dart_ShutdownIsolate(); |
| 551 // Terminate event handler. | 562 // Terminate event handler. |
| 552 EventHandler::Terminate(); | 563 EventHandler::Terminate(); |
| 553 | 564 |
| 554 return 0; | 565 return 0; |
| 555 } | 566 } |
| OLD | NEW |