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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 224 |
225 // We have to copy everything we care about out of |result| because after | 225 // We have to copy everything we care about out of |result| because after |
226 // dropping the lock below |result| may no longer valid. | 226 // dropping the lock below |result| may no longer valid. |
227 Dart_Handle uri = | 227 Dart_Handle uri = |
228 Dart_NewStringFromCString(reinterpret_cast<char*>(result->uri)); | 228 Dart_NewStringFromCString(reinterpret_cast<char*>(result->uri)); |
229 Dart_Handle library_uri = Dart_Null(); | 229 Dart_Handle library_uri = Dart_Null(); |
230 if (result->library_uri != NULL) { | 230 if (result->library_uri != NULL) { |
231 library_uri = | 231 library_uri = |
232 Dart_NewStringFromCString(reinterpret_cast<char*>(result->library_uri)); | 232 Dart_NewStringFromCString(reinterpret_cast<char*>(result->library_uri)); |
233 } | 233 } |
234 Dart_Handle source = | 234 // Check for payload and load accordingly. |
235 Dart_NewStringFromUTF8(result->payload, | 235 bool is_snapshot = false; |
236 result->payload_length); | 236 const uint8_t* payload = result->payload; |
| 237 intptr_t payload_length = result->payload_length; |
| 238 payload = |
| 239 DartUtils::SniffForMagicNumber(payload, |
| 240 &payload_length, |
| 241 &is_snapshot); |
| 242 Dart_Handle source = Dart_Null(); |
| 243 if (!is_snapshot) { |
| 244 source = Dart_NewStringFromUTF8(result->payload, |
| 245 result->payload_length); |
| 246 if (Dart_IsError(source)) { |
| 247 error_ = DartUtils::NewError("%s is not a valid UTF-8 script", |
| 248 reinterpret_cast<char*>(result->uri)); |
| 249 return false; |
| 250 } |
| 251 } |
237 intptr_t tag = result->tag; | 252 intptr_t tag = result->tag; |
238 | 253 |
239 // No touching. | 254 // No touching. |
240 result = NULL; | 255 result = NULL; |
241 | 256 |
242 // We must drop the lock here because the tag handler may be recursively | 257 // We must drop the lock here because the tag handler may be recursively |
243 // invoked and it will attempt to acquire the lock to queue more work. | 258 // invoked and it will attempt to acquire the lock to queue more work. |
244 monitor_->Exit(); | 259 monitor_->Exit(); |
245 | 260 |
246 Dart_Handle dart_result = Dart_Null(); | 261 Dart_Handle dart_result = Dart_Null(); |
247 | 262 |
248 | |
249 switch (tag) { | 263 switch (tag) { |
250 case Dart_kImportTag: | 264 case Dart_kImportTag: |
251 dart_result = Dart_LoadLibrary(uri, source, 0, 0); | 265 dart_result = Dart_LoadLibrary(uri, source, 0, 0); |
252 break; | 266 break; |
253 case Dart_kSourceTag: { | 267 case Dart_kSourceTag: { |
254 ASSERT(library_uri != Dart_Null()); | 268 ASSERT(library_uri != Dart_Null()); |
255 Dart_Handle library = Dart_LookupLibrary(library_uri); | 269 Dart_Handle library = Dart_LookupLibrary(library_uri); |
256 ASSERT(!Dart_IsError(library)); | 270 ASSERT(!Dart_IsError(library)); |
257 dart_result = Dart_LoadSource(library, uri, source, 0, 0); | 271 dart_result = Dart_LoadSource(library, uri, source, 0, 0); |
258 } | 272 } |
259 break; | 273 break; |
260 case Dart_kScriptTag: | 274 case Dart_kScriptTag: |
261 dart_result = Dart_LoadScript(uri, source, 0, 0); | 275 if (is_snapshot) { |
| 276 dart_result = Dart_LoadScriptFromSnapshot(payload, payload_length); |
| 277 } else { |
| 278 dart_result = Dart_LoadScript(uri, source, 0, 0); |
| 279 } |
262 break; | 280 break; |
263 default: | 281 default: |
264 UNREACHABLE(); | 282 UNREACHABLE(); |
265 } | 283 } |
266 | 284 |
267 // Re-acquire the lock before exiting the function (it was held before entry), | 285 // Re-acquire the lock before exiting the function (it was held before entry), |
268 monitor_->Enter(); | 286 monitor_->Enter(); |
269 if (Dart_IsError(dart_result)) { | 287 if (Dart_IsError(dart_result)) { |
270 // Remember the error if we encountered one. | 288 // Remember the error if we encountered one. |
271 error_ = dart_result; | 289 error_ = dart_result; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 MutexLocker ml(&loader_infos_lock_); | 557 MutexLocker ml(&loader_infos_lock_); |
540 Loader* loader = LoaderForLocked(dest_port_id); | 558 Loader* loader = LoaderForLocked(dest_port_id); |
541 if (loader == NULL) { | 559 if (loader == NULL) { |
542 return; | 560 return; |
543 } | 561 } |
544 loader->QueueMessage(message); | 562 loader->QueueMessage(message); |
545 } | 563 } |
546 | 564 |
547 } // namespace bin | 565 } // namespace bin |
548 } // namespace dart | 566 } // namespace dart |
OLD | NEW |