| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 | 5 |
| 6 #include "bin/loader.h" | 6 #include "bin/loader.h" |
| 7 | 7 |
| 8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
| 9 #include "bin/dartutils.h" | 9 #include "bin/dartutils.h" |
| 10 #include "bin/extensions.h" | 10 #include "bin/extensions.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 extension_path, | 329 extension_path, |
| 330 library); | 330 library); |
| 331 if (Dart_IsError(result)) { | 331 if (Dart_IsError(result)) { |
| 332 loader->error_ = result; | 332 loader->error_ = result; |
| 333 return false; | 333 return false; |
| 334 } | 334 } |
| 335 return true; | 335 return true; |
| 336 } | 336 } |
| 337 | 337 |
| 338 // Check for payload and load accordingly. | 338 // Check for payload and load accordingly. |
| 339 bool is_snapshot = false; | |
| 340 const uint8_t* payload = result->payload; | 339 const uint8_t* payload = result->payload; |
| 341 intptr_t payload_length = result->payload_length; | 340 intptr_t payload_length = result->payload_length; |
| 342 payload = | 341 const DartUtils::MagicNumber payload_type = |
| 343 DartUtils::SniffForMagicNumber(payload, | 342 DartUtils::SniffForMagicNumber(&payload, &payload_length); |
| 344 &payload_length, | |
| 345 &is_snapshot); | |
| 346 Dart_Handle source = Dart_Null(); | 343 Dart_Handle source = Dart_Null(); |
| 347 if (!is_snapshot) { | 344 if (payload_type == DartUtils::kUnknownMagicNumber) { |
| 348 source = Dart_NewStringFromUTF8(result->payload, | 345 source = Dart_NewStringFromUTF8(result->payload, |
| 349 result->payload_length); | 346 result->payload_length); |
| 350 if (Dart_IsError(source)) { | 347 if (Dart_IsError(source)) { |
| 351 loader->error_ = DartUtils::NewError( | 348 loader->error_ = DartUtils::NewError( |
| 352 "%s is not a valid UTF-8 script", | 349 "%s is not a valid UTF-8 script", |
| 353 reinterpret_cast<char*>(result->uri)); | 350 reinterpret_cast<char*>(result->uri)); |
| 354 return false; | 351 return false; |
| 355 } | 352 } |
| 356 } | 353 } |
| 357 intptr_t tag = result->tag; | 354 intptr_t tag = result->tag; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 370 dart_result = Dart_LoadLibrary(uri, resolved_uri, source, 0, 0); | 367 dart_result = Dart_LoadLibrary(uri, resolved_uri, source, 0, 0); |
| 371 break; | 368 break; |
| 372 case Dart_kSourceTag: { | 369 case Dart_kSourceTag: { |
| 373 ASSERT(library_uri != Dart_Null()); | 370 ASSERT(library_uri != Dart_Null()); |
| 374 Dart_Handle library = Dart_LookupLibrary(library_uri); | 371 Dart_Handle library = Dart_LookupLibrary(library_uri); |
| 375 ASSERT(!Dart_IsError(library)); | 372 ASSERT(!Dart_IsError(library)); |
| 376 dart_result = Dart_LoadSource(library, uri, resolved_uri, source, 0, 0); | 373 dart_result = Dart_LoadSource(library, uri, resolved_uri, source, 0, 0); |
| 377 } | 374 } |
| 378 break; | 375 break; |
| 379 case Dart_kScriptTag: | 376 case Dart_kScriptTag: |
| 380 if (is_snapshot) { | 377 if (payload_type == DartUtils::kSnapshotMagicNumber) { |
| 381 dart_result = Dart_LoadScriptFromSnapshot(payload, payload_length); | 378 dart_result = Dart_LoadScriptFromSnapshot(payload, payload_length); |
| 379 } else if (payload_type == DartUtils::kKernelMagicNumber) { |
| 380 dart_result = Dart_LoadKernel(payload, payload_length); |
| 382 } else { | 381 } else { |
| 383 dart_result = Dart_LoadScript(uri, resolved_uri, source, 0, 0); | 382 dart_result = Dart_LoadScript(uri, resolved_uri, source, 0, 0); |
| 384 } | 383 } |
| 385 break; | 384 break; |
| 386 default: | 385 default: |
| 387 UNREACHABLE(); | 386 UNREACHABLE(); |
| 388 } | 387 } |
| 389 | 388 |
| 390 // Re-acquire the lock before exiting the function (it was held before entry), | 389 // Re-acquire the lock before exiting the function (it was held before entry), |
| 391 loader->monitor_->Enter(); | 390 loader->monitor_->Enter(); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 MutexLocker ml(loader_infos_lock_); | 755 MutexLocker ml(loader_infos_lock_); |
| 757 Loader* loader = LoaderForLocked(dest_port_id); | 756 Loader* loader = LoaderForLocked(dest_port_id); |
| 758 if (loader == NULL) { | 757 if (loader == NULL) { |
| 759 return; | 758 return; |
| 760 } | 759 } |
| 761 loader->QueueMessage(message); | 760 loader->QueueMessage(message); |
| 762 } | 761 } |
| 763 | 762 |
| 764 } // namespace bin | 763 } // namespace bin |
| 765 } // namespace dart | 764 } // namespace dart |
| OLD | NEW |