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 15 matching lines...) Expand all Loading... |
26 error_(Dart_Null()), | 26 error_(Dart_Null()), |
27 monitor_(NULL), | 27 monitor_(NULL), |
28 pending_operations_(0), | 28 pending_operations_(0), |
29 results_(NULL), | 29 results_(NULL), |
30 results_length_(0), | 30 results_length_(0), |
31 results_capacity_(0), | 31 results_capacity_(0), |
32 payload_(NULL), | 32 payload_(NULL), |
33 payload_length_(0) { | 33 payload_length_(0) { |
34 monitor_ = new Monitor(); | 34 monitor_ = new Monitor(); |
35 ASSERT(isolate_data_ != NULL); | 35 ASSERT(isolate_data_ != NULL); |
36 port_ = Dart_NewNativePort("Loader", | 36 port_ = Dart_NewNativePort("Loader", Loader::NativeMessageHandler, false); |
37 Loader::NativeMessageHandler, | |
38 false); | |
39 isolate_data_->set_loader(this); | 37 isolate_data_->set_loader(this); |
40 AddLoader(port_, isolate_data_); | 38 AddLoader(port_, isolate_data_); |
41 } | 39 } |
42 | 40 |
43 | 41 |
44 Loader::~Loader() { | 42 Loader::~Loader() { |
45 ASSERT(port_ != ILLEGAL_PORT); | 43 ASSERT(port_ != ILLEGAL_PORT); |
46 // Enter the monitor while we close the Dart port. After the Dart port is | 44 // Enter the monitor while we close the Dart port. After the Dart port is |
47 // closed, no more results can be queued. | 45 // closed, no more results can be queued. |
48 monitor_->Enter(); | 46 monitor_->Enter(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // Payload is an error message. | 102 // Payload is an error message. |
105 payload_length = strlen(payload_message->value.as_string); | 103 payload_length = strlen(payload_message->value.as_string); |
106 payload = | 104 payload = |
107 reinterpret_cast<uint8_t*>(strdup(payload_message->value.as_string)); | 105 reinterpret_cast<uint8_t*>(strdup(payload_message->value.as_string)); |
108 } else { | 106 } else { |
109 // Payload is the contents of a file. | 107 // Payload is the contents of a file. |
110 ASSERT(payload_message->type == Dart_CObject_kTypedData); | 108 ASSERT(payload_message->type == Dart_CObject_kTypedData); |
111 ASSERT(payload_message->value.as_typed_data.type == Dart_TypedData_kUint8); | 109 ASSERT(payload_message->value.as_typed_data.type == Dart_TypedData_kUint8); |
112 payload_length = payload_message->value.as_typed_data.length; | 110 payload_length = payload_message->value.as_typed_data.length; |
113 payload = reinterpret_cast<uint8_t*>(malloc(payload_length)); | 111 payload = reinterpret_cast<uint8_t*>(malloc(payload_length)); |
114 memmove(payload, | 112 memmove(payload, payload_message->value.as_typed_data.values, |
115 payload_message->value.as_typed_data.values, | |
116 payload_length); | 113 payload_length); |
117 } | 114 } |
118 } | 115 } |
119 | 116 |
120 | 117 |
121 void Loader::IOResult::Cleanup() { | 118 void Loader::IOResult::Cleanup() { |
122 free(uri); | 119 free(uri); |
123 free(resolved_uri); | 120 free(resolved_uri); |
124 free(library_uri); | 121 free(library_uri); |
125 free(payload); | 122 free(payload); |
(...skipping 12 matching lines...) Expand all Loading... |
138 ASSERT(loader_port != ILLEGAL_PORT); | 135 ASSERT(loader_port != ILLEGAL_PORT); |
139 | 136 |
140 // Keep in sync with loader.dart. | 137 // Keep in sync with loader.dart. |
141 const intptr_t _Dart_kInitLoader = 4; | 138 const intptr_t _Dart_kInitLoader = 4; |
142 | 139 |
143 Dart_Handle request = Dart_NewList(8); | 140 Dart_Handle request = Dart_NewList(8); |
144 Dart_ListSetAt(request, 0, trace_loader ? Dart_True() : Dart_False()); | 141 Dart_ListSetAt(request, 0, trace_loader ? Dart_True() : Dart_False()); |
145 Dart_ListSetAt(request, 1, Dart_NewInteger(Dart_GetMainPortId())); | 142 Dart_ListSetAt(request, 1, Dart_NewInteger(Dart_GetMainPortId())); |
146 Dart_ListSetAt(request, 2, Dart_NewInteger(_Dart_kInitLoader)); | 143 Dart_ListSetAt(request, 2, Dart_NewInteger(_Dart_kInitLoader)); |
147 Dart_ListSetAt(request, 3, Dart_NewSendPort(port_)); | 144 Dart_ListSetAt(request, 3, Dart_NewSendPort(port_)); |
148 Dart_ListSetAt(request, 4, | 145 Dart_ListSetAt(request, 4, (package_root == NULL) |
149 (package_root == NULL) ? Dart_Null() : | 146 ? Dart_Null() |
150 Dart_NewStringFromCString(package_root)); | 147 : Dart_NewStringFromCString(package_root)); |
151 Dart_ListSetAt(request, 5, | 148 Dart_ListSetAt(request, 5, (packages_file == NULL) |
152 (packages_file == NULL) ? Dart_Null() : | 149 ? Dart_Null() |
153 Dart_NewStringFromCString(packages_file)); | 150 : Dart_NewStringFromCString(packages_file)); |
154 Dart_ListSetAt(request, 6, | 151 Dart_ListSetAt(request, 6, Dart_NewStringFromCString(working_directory)); |
155 Dart_NewStringFromCString(working_directory)); | 152 Dart_ListSetAt(request, 7, (root_script_uri == NULL) |
156 Dart_ListSetAt(request, 7, | 153 ? Dart_Null() |
157 (root_script_uri == NULL) ? Dart_Null() : | 154 : Dart_NewStringFromCString(root_script_uri)); |
158 Dart_NewStringFromCString(root_script_uri)); | |
159 | 155 |
160 bool success = Dart_Post(loader_port, request); | 156 bool success = Dart_Post(loader_port, request); |
161 ASSERT(success); | 157 ASSERT(success); |
162 } | 158 } |
163 | 159 |
164 | 160 |
165 void Loader::SendImportExtensionRequest(Dart_Handle url, | 161 void Loader::SendImportExtensionRequest(Dart_Handle url, |
166 Dart_Handle library_url) { | 162 Dart_Handle library_url) { |
167 // This port delivers loading messages to the service isolate. | 163 // This port delivers loading messages to the service isolate. |
168 Dart_Port loader_port = Builtin::LoadPort(); | 164 Dart_Port loader_port = Builtin::LoadPort(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 pending_operations_++; | 203 pending_operations_++; |
208 } | 204 } |
209 } | 205 } |
210 | 206 |
211 | 207 |
212 void Loader::QueueMessage(Dart_CObject* message) { | 208 void Loader::QueueMessage(Dart_CObject* message) { |
213 MonitorLocker ml(monitor_); | 209 MonitorLocker ml(monitor_); |
214 if (results_length_ == results_capacity_) { | 210 if (results_length_ == results_capacity_) { |
215 // Grow to an initial capacity or double in size. | 211 // Grow to an initial capacity or double in size. |
216 results_capacity_ = (results_capacity_ == 0) ? 4 : results_capacity_ * 2; | 212 results_capacity_ = (results_capacity_ == 0) ? 4 : results_capacity_ * 2; |
217 results_ = | 213 results_ = reinterpret_cast<IOResult*>( |
218 reinterpret_cast<IOResult*>( | 214 realloc(results_, sizeof(IOResult) * results_capacity_)); |
219 realloc(results_, | |
220 sizeof(IOResult) * results_capacity_)); | |
221 ASSERT(results_ != NULL); | 215 ASSERT(results_ != NULL); |
222 } | 216 } |
223 ASSERT(results_ != NULL); | 217 ASSERT(results_ != NULL); |
224 ASSERT(results_length_ < results_capacity_); | 218 ASSERT(results_length_ < results_capacity_); |
225 results_[results_length_].Setup(message); | 219 results_[results_length_].Setup(message); |
226 results_length_++; | 220 results_length_++; |
227 ml.Notify(); | 221 ml.Notify(); |
228 } | 222 } |
229 | 223 |
230 | 224 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 Dart_Handle library_uri = Dart_Null(); | 273 Dart_Handle library_uri = Dart_Null(); |
280 if (result->library_uri != NULL) { | 274 if (result->library_uri != NULL) { |
281 library_uri = | 275 library_uri = |
282 Dart_NewStringFromCString(reinterpret_cast<char*>(result->library_uri)); | 276 Dart_NewStringFromCString(reinterpret_cast<char*>(result->library_uri)); |
283 } | 277 } |
284 | 278 |
285 // A negative result tag indicates a loading error occurred in the service | 279 // A negative result tag indicates a loading error occurred in the service |
286 // isolate. The payload is a C string of the error message. | 280 // isolate. The payload is a C string of the error message. |
287 if (result->tag < 0) { | 281 if (result->tag < 0) { |
288 Dart_Handle library = Dart_LookupLibrary(uri); | 282 Dart_Handle library = Dart_LookupLibrary(uri); |
289 Dart_Handle error = Dart_NewStringFromUTF8(result->payload, | 283 Dart_Handle error = |
290 result->payload_length); | 284 Dart_NewStringFromUTF8(result->payload, result->payload_length); |
291 // If a library with the given uri exists, give it a chance to handle | 285 // If a library with the given uri exists, give it a chance to handle |
292 // the error. If the load requests stems from a deferred library load, | 286 // the error. If the load requests stems from a deferred library load, |
293 // an IO error is not fatal. | 287 // an IO error is not fatal. |
294 if (LibraryHandleError(library, error)) { | 288 if (LibraryHandleError(library, error)) { |
295 return true; | 289 return true; |
296 } | 290 } |
297 // Fall through | 291 // Fall through |
298 loader->error_ = Dart_NewUnhandledExceptionError(error); | 292 loader->error_ = Dart_NewUnhandledExceptionError(error); |
299 return false; | 293 return false; |
300 } | 294 } |
301 | 295 |
302 if (result->tag == _Dart_kImportExtension) { | 296 if (result->tag == _Dart_kImportExtension) { |
303 ASSERT(library_uri != Dart_Null()); | 297 ASSERT(library_uri != Dart_Null()); |
304 Dart_Handle library = Dart_LookupLibrary(library_uri); | 298 Dart_Handle library = Dart_LookupLibrary(library_uri); |
305 ASSERT(!Dart_IsError(library)); | 299 ASSERT(!Dart_IsError(library)); |
306 const char* lib_uri = reinterpret_cast<const char*>(result->payload); | 300 const char* lib_uri = reinterpret_cast<const char*>(result->payload); |
307 if (strncmp(lib_uri, "http://", 7) == 0 || | 301 if (strncmp(lib_uri, "http://", 7) == 0 || |
308 strncmp(lib_uri, "https://", 8) == 0) { | 302 strncmp(lib_uri, "https://", 8) == 0) { |
309 loader->error_ = | 303 loader->error_ = Dart_NewApiError( |
310 Dart_NewApiError("Cannot load native extensions over http: or https:"); | 304 "Cannot load native extensions over http: or https:"); |
311 return false; | 305 return false; |
312 } | 306 } |
313 const char* extension_uri = reinterpret_cast<const char*>(result->uri); | 307 const char* extension_uri = reinterpret_cast<const char*>(result->uri); |
314 const char* lib_path = NULL; | 308 const char* lib_path = NULL; |
315 if (strncmp(lib_uri, "file://", 7) == 0) { | 309 if (strncmp(lib_uri, "file://", 7) == 0) { |
316 lib_path = DartUtils::RemoveScheme(lib_uri); | 310 lib_path = DartUtils::RemoveScheme(lib_uri); |
317 } else { | 311 } else { |
318 lib_path = lib_uri; | 312 lib_path = lib_uri; |
319 } | 313 } |
320 const char* extension_path = DartUtils::RemoveScheme(extension_uri); | 314 const char* extension_path = DartUtils::RemoveScheme(extension_uri); |
321 if (!File::IsAbsolutePath(extension_path) && | 315 if (!File::IsAbsolutePath(extension_path) && |
322 PathContainsSeparator(extension_path)) { | 316 PathContainsSeparator(extension_path)) { |
323 loader->error_ = DartUtils::NewError( | 317 loader->error_ = DartUtils::NewError( |
324 "Native extension path must be absolute, or simply the file name: %s", | 318 "Native extension path must be absolute, or simply the file name: %s", |
325 extension_path); | 319 extension_path); |
326 return false; | 320 return false; |
327 } | 321 } |
328 Dart_Handle result = Extensions::LoadExtension(lib_path, | 322 Dart_Handle result = |
329 extension_path, | 323 Extensions::LoadExtension(lib_path, extension_path, library); |
330 library); | |
331 if (Dart_IsError(result)) { | 324 if (Dart_IsError(result)) { |
332 loader->error_ = result; | 325 loader->error_ = result; |
333 return false; | 326 return false; |
334 } | 327 } |
335 return true; | 328 return true; |
336 } | 329 } |
337 | 330 |
338 // Check for payload and load accordingly. | 331 // Check for payload and load accordingly. |
339 const uint8_t* payload = result->payload; | 332 const uint8_t* payload = result->payload; |
340 intptr_t payload_length = result->payload_length; | 333 intptr_t payload_length = result->payload_length; |
341 const DartUtils::MagicNumber payload_type = | 334 const DartUtils::MagicNumber payload_type = |
342 DartUtils::SniffForMagicNumber(&payload, &payload_length); | 335 DartUtils::SniffForMagicNumber(&payload, &payload_length); |
343 Dart_Handle source = Dart_Null(); | 336 Dart_Handle source = Dart_Null(); |
344 if (payload_type == DartUtils::kUnknownMagicNumber) { | 337 if (payload_type == DartUtils::kUnknownMagicNumber) { |
345 source = Dart_NewStringFromUTF8(result->payload, | 338 source = Dart_NewStringFromUTF8(result->payload, result->payload_length); |
346 result->payload_length); | |
347 if (Dart_IsError(source)) { | 339 if (Dart_IsError(source)) { |
348 loader->error_ = DartUtils::NewError( | 340 loader->error_ = |
349 "%s is not a valid UTF-8 script", | 341 DartUtils::NewError("%s is not a valid UTF-8 script", |
350 reinterpret_cast<char*>(result->uri)); | 342 reinterpret_cast<char*>(result->uri)); |
351 return false; | 343 return false; |
352 } | 344 } |
353 } | 345 } |
354 intptr_t tag = result->tag; | 346 intptr_t tag = result->tag; |
355 | 347 |
356 // No touching. | 348 // No touching. |
357 result = NULL; | 349 result = NULL; |
358 | 350 |
359 // We must drop the lock here because the tag handler may be recursively | 351 // We must drop the lock here because the tag handler may be recursively |
360 // invoked and it will attempt to acquire the lock to queue more work. | 352 // invoked and it will attempt to acquire the lock to queue more work. |
361 loader->monitor_->Exit(); | 353 loader->monitor_->Exit(); |
362 | 354 |
363 Dart_Handle dart_result = Dart_Null(); | 355 Dart_Handle dart_result = Dart_Null(); |
364 | 356 |
365 switch (tag) { | 357 switch (tag) { |
366 case Dart_kImportTag: | 358 case Dart_kImportTag: |
367 dart_result = Dart_LoadLibrary(uri, resolved_uri, source, 0, 0); | 359 dart_result = Dart_LoadLibrary(uri, resolved_uri, source, 0, 0); |
368 break; | 360 break; |
369 case Dart_kSourceTag: { | 361 case Dart_kSourceTag: { |
370 ASSERT(library_uri != Dart_Null()); | 362 ASSERT(library_uri != Dart_Null()); |
371 Dart_Handle library = Dart_LookupLibrary(library_uri); | 363 Dart_Handle library = Dart_LookupLibrary(library_uri); |
372 ASSERT(!Dart_IsError(library)); | 364 ASSERT(!Dart_IsError(library)); |
373 dart_result = Dart_LoadSource(library, uri, resolved_uri, source, 0, 0); | 365 dart_result = Dart_LoadSource(library, uri, resolved_uri, source, 0, 0); |
374 } | 366 } break; |
375 break; | |
376 case Dart_kScriptTag: | 367 case Dart_kScriptTag: |
377 if (payload_type == DartUtils::kSnapshotMagicNumber) { | 368 if (payload_type == DartUtils::kSnapshotMagicNumber) { |
378 dart_result = Dart_LoadScriptFromSnapshot(payload, payload_length); | 369 dart_result = Dart_LoadScriptFromSnapshot(payload, payload_length); |
379 } else if (payload_type == DartUtils::kKernelMagicNumber) { | 370 } else if (payload_type == DartUtils::kKernelMagicNumber) { |
380 dart_result = Dart_LoadKernel(payload, payload_length); | 371 dart_result = Dart_LoadKernel(payload, payload_length); |
381 } else { | 372 } else { |
382 dart_result = Dart_LoadScript(uri, resolved_uri, source, 0, 0); | 373 dart_result = Dart_LoadScript(uri, resolved_uri, source, 0, 0); |
383 } | 374 } |
384 break; | 375 break; |
385 default: | 376 default: |
386 UNREACHABLE(); | 377 UNREACHABLE(); |
387 } | 378 } |
388 | 379 |
389 // Re-acquire the lock before exiting the function (it was held before entry), | 380 // Re-acquire the lock before exiting the function (it was held before entry), |
390 loader->monitor_->Enter(); | 381 loader->monitor_->Enter(); |
391 if (Dart_IsError(dart_result)) { | 382 if (Dart_IsError(dart_result)) { |
392 // Remember the error if we encountered one. | 383 // Remember the error if we encountered one. |
393 loader->error_ = dart_result; | 384 loader->error_ = dart_result; |
394 return false; | 385 return false; |
395 } | 386 } |
396 | 387 |
397 return true; | 388 return true; |
398 } | 389 } |
399 | 390 |
400 | 391 |
401 bool Loader::ProcessUrlLoadResultLocked(Loader* loader, | 392 bool Loader::ProcessUrlLoadResultLocked(Loader* loader, |
402 Loader::IOResult* result) { | 393 Loader::IOResult* result) { |
403 // A negative result tag indicates a loading error occurred in the service | 394 // A negative result tag indicates a loading error occurred in the service |
404 // isolate. The payload is a C string of the error message. | 395 // isolate. The payload is a C string of the error message. |
405 if (result->tag < 0) { | 396 if (result->tag < 0) { |
406 Dart_Handle error = Dart_NewStringFromUTF8(result->payload, | 397 Dart_Handle error = |
407 result->payload_length); | 398 Dart_NewStringFromUTF8(result->payload, result->payload_length); |
408 loader->error_ = Dart_NewUnhandledExceptionError(error); | 399 loader->error_ = Dart_NewUnhandledExceptionError(error); |
409 return false; | 400 return false; |
410 } | 401 } |
411 loader->payload_length_ = result->payload_length; | 402 loader->payload_length_ = result->payload_length; |
412 loader->payload_ = | 403 loader->payload_ = |
413 reinterpret_cast<uint8_t*>(::malloc(loader->payload_length_)); | 404 reinterpret_cast<uint8_t*>(::malloc(loader->payload_length_)); |
414 memmove(loader->payload_, result->payload, loader->payload_length_); | 405 memmove(loader->payload_, result->payload, loader->payload_length_); |
415 return true; | 406 return true; |
416 } | 407 } |
417 | 408 |
(...skipping 14 matching lines...) Expand all Loading... |
432 | 423 |
433 | 424 |
434 void Loader::InitForSnapshot(const char* snapshot_uri) { | 425 void Loader::InitForSnapshot(const char* snapshot_uri) { |
435 IsolateData* isolate_data = | 426 IsolateData* isolate_data = |
436 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 427 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
437 ASSERT(isolate_data != NULL); | 428 ASSERT(isolate_data != NULL); |
438 ASSERT(!isolate_data->HasLoader()); | 429 ASSERT(!isolate_data->HasLoader()); |
439 // Setup a loader. The constructor does a bunch of leg work. | 430 // Setup a loader. The constructor does a bunch of leg work. |
440 Loader* loader = new Loader(isolate_data); | 431 Loader* loader = new Loader(isolate_data); |
441 // Send the init message. | 432 // Send the init message. |
442 loader->Init(isolate_data->package_root, | 433 loader->Init(isolate_data->package_root, isolate_data->packages_file, |
443 isolate_data->packages_file, | 434 DartUtils::original_working_directory, snapshot_uri); |
444 DartUtils::original_working_directory, | |
445 snapshot_uri); | |
446 // Destroy the loader. The destructor does a bunch of leg work. | 435 // Destroy the loader. The destructor does a bunch of leg work. |
447 delete loader; | 436 delete loader; |
448 } | 437 } |
449 | 438 |
450 | 439 |
451 Dart_Handle Loader::LoadUrlContents(Dart_Handle url, | 440 Dart_Handle Loader::LoadUrlContents(Dart_Handle url, |
452 uint8_t** payload, | 441 uint8_t** payload, |
453 intptr_t* payload_length) { | 442 intptr_t* payload_length) { |
454 IsolateData* isolate_data = | 443 IsolateData* isolate_data = |
455 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 444 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
456 ASSERT(isolate_data != NULL); | 445 ASSERT(isolate_data != NULL); |
457 ASSERT(!isolate_data->HasLoader()); | 446 ASSERT(!isolate_data->HasLoader()); |
458 Loader* loader = NULL; | 447 Loader* loader = NULL; |
459 | 448 |
460 // Setup the loader. The constructor does a bunch of leg work. | 449 // Setup the loader. The constructor does a bunch of leg work. |
461 loader = new Loader(isolate_data); | 450 loader = new Loader(isolate_data); |
462 loader->Init(isolate_data->package_root, | 451 loader->Init(isolate_data->package_root, isolate_data->packages_file, |
463 isolate_data->packages_file, | 452 DartUtils::original_working_directory, NULL); |
464 DartUtils::original_working_directory, | |
465 NULL); | |
466 ASSERT(loader != NULL); | 453 ASSERT(loader != NULL); |
467 ASSERT(isolate_data->HasLoader()); | 454 ASSERT(isolate_data->HasLoader()); |
468 | 455 |
469 // Now send a load request to the service isolate. | 456 // Now send a load request to the service isolate. |
470 loader->SendRequest(Dart_kScriptTag, url, Dart_Null()); | 457 loader->SendRequest(Dart_kScriptTag, url, Dart_Null()); |
471 | 458 |
472 // Wait for a reply to the load request. | 459 // Wait for a reply to the load request. |
473 loader->BlockUntilComplete(ProcessUrlLoadResultLocked); | 460 loader->BlockUntilComplete(ProcessUrlLoadResultLocked); |
474 | 461 |
475 // Copy fields from the loader before deleting it. | 462 // Copy fields from the loader before deleting it. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 const char* library_url_string = NULL; | 503 const char* library_url_string = NULL; |
517 result = Dart_StringToCString(library_url, &library_url_string); | 504 result = Dart_StringToCString(library_url, &library_url_string); |
518 if (Dart_IsError(result)) { | 505 if (Dart_IsError(result)) { |
519 return result; | 506 return result; |
520 } | 507 } |
521 | 508 |
522 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); | 509 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); |
523 bool is_dart_library = DartUtils::IsDartSchemeURL(library_url_string); | 510 bool is_dart_library = DartUtils::IsDartSchemeURL(library_url_string); |
524 | 511 |
525 if (is_dart_scheme_url || is_dart_library) { | 512 if (is_dart_scheme_url || is_dart_library) { |
526 return DartColonLibraryTagHandler(tag, | 513 return DartColonLibraryTagHandler(tag, library, url, library_url_string, |
527 library, | |
528 url, | |
529 library_url_string, | |
530 url_string); | 514 url_string); |
531 } | 515 } |
532 } | 516 } |
533 | 517 |
534 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 518 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
535 // Handle early error cases for dart-ext: imports. | 519 // Handle early error cases for dart-ext: imports. |
536 if (tag != Dart_kImportTag) { | 520 if (tag != Dart_kImportTag) { |
537 return DartUtils::NewError("Dart extensions must use import: '%s'", | 521 return DartUtils::NewError("Dart extensions must use import: '%s'", |
538 url_string); | 522 url_string); |
539 } | 523 } |
(...skipping 16 matching lines...) Expand all Loading... |
556 | 540 |
557 // If we are the outer invocation of the tag handler and the tag is an import | 541 // If we are the outer invocation of the tag handler and the tag is an import |
558 // this means that we are starting a deferred library load. | 542 // this means that we are starting a deferred library load. |
559 const bool is_deferred_import = blocking_call && (tag == Dart_kImportTag); | 543 const bool is_deferred_import = blocking_call && (tag == Dart_kImportTag); |
560 if (!isolate_data->HasLoader()) { | 544 if (!isolate_data->HasLoader()) { |
561 // The isolate doesn't have a loader -- this is the outer invocation which | 545 // The isolate doesn't have a loader -- this is the outer invocation which |
562 // will block. | 546 // will block. |
563 | 547 |
564 // Setup the loader. The constructor does a bunch of leg work. | 548 // Setup the loader. The constructor does a bunch of leg work. |
565 loader = new Loader(isolate_data); | 549 loader = new Loader(isolate_data); |
566 loader->Init(isolate_data->package_root, | 550 loader->Init(isolate_data->package_root, isolate_data->packages_file, |
567 isolate_data->packages_file, | |
568 DartUtils::original_working_directory, | 551 DartUtils::original_working_directory, |
569 (tag == Dart_kScriptTag) ? url_string : NULL); | 552 (tag == Dart_kScriptTag) ? url_string : NULL); |
570 } else { | 553 } else { |
571 ASSERT(tag != Dart_kScriptTag); | 554 ASSERT(tag != Dart_kScriptTag); |
572 // The isolate has a loader -- this is an inner invocation that will queue | 555 // The isolate has a loader -- this is an inner invocation that will queue |
573 // work with the service isolate. | 556 // work with the service isolate. |
574 // Use the existing loader. | 557 // Use the existing loader. |
575 loader = isolate_data->loader(); | 558 loader = isolate_data->loader(); |
576 } | 559 } |
577 ASSERT(loader != NULL); | 560 ASSERT(loader != NULL); |
578 ASSERT(isolate_data->HasLoader()); | 561 ASSERT(isolate_data->HasLoader()); |
579 | 562 |
580 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 563 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
581 loader->SendImportExtensionRequest(url, Dart_LibraryUrl(library)); | 564 loader->SendImportExtensionRequest(url, Dart_LibraryUrl(library)); |
582 } else { | 565 } else { |
583 loader->SendRequest(tag, | 566 loader->SendRequest(tag, url, (library != Dart_Null()) |
584 url, | 567 ? Dart_LibraryUrl(library) |
585 (library != Dart_Null()) ? | 568 : Dart_Null()); |
586 Dart_LibraryUrl(library) : Dart_Null()); | |
587 } | 569 } |
588 | 570 |
589 | 571 |
590 if (blocking_call) { | 572 if (blocking_call) { |
591 // The outer invocation of the tag handler will block here until all nested | 573 // The outer invocation of the tag handler will block here until all nested |
592 // invocations complete. | 574 // invocations complete. |
593 loader->BlockUntilComplete(ProcessResultLocked); | 575 loader->BlockUntilComplete(ProcessResultLocked); |
594 | 576 |
595 // Remember the error (if any). | 577 // Remember the error (if any). |
596 Dart_Handle error = loader->error(); | 578 Dart_Handle error = loader->error(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 Dart_Handle url, | 615 Dart_Handle url, |
634 const char* library_url_string, | 616 const char* library_url_string, |
635 const char* url_string) { | 617 const char* url_string) { |
636 // Handle canonicalization, 'import' and 'part' of 'dart:' libraries. | 618 // Handle canonicalization, 'import' and 'part' of 'dart:' libraries. |
637 if (tag == Dart_kCanonicalizeUrl) { | 619 if (tag == Dart_kCanonicalizeUrl) { |
638 // These will be handled internally. | 620 // These will be handled internally. |
639 return url; | 621 return url; |
640 } else if (tag == Dart_kImportTag) { | 622 } else if (tag == Dart_kImportTag) { |
641 Builtin::BuiltinLibraryId id = Builtin::FindId(url_string); | 623 Builtin::BuiltinLibraryId id = Builtin::FindId(url_string); |
642 if (id == Builtin::kInvalidLibrary) { | 624 if (id == Builtin::kInvalidLibrary) { |
643 return DartUtils::NewError("The built-in library '%s' is not available" | 625 return DartUtils::NewError( |
644 " on the stand-alone VM.\n", url_string); | 626 "The built-in library '%s' is not available" |
| 627 " on the stand-alone VM.\n", |
| 628 url_string); |
645 } | 629 } |
646 return Builtin::LoadLibrary(url, id); | 630 return Builtin::LoadLibrary(url, id); |
647 } else { | 631 } else { |
648 ASSERT(tag == Dart_kSourceTag); | 632 ASSERT(tag == Dart_kSourceTag); |
649 Builtin::BuiltinLibraryId id = Builtin::FindId(library_url_string); | 633 Builtin::BuiltinLibraryId id = Builtin::FindId(library_url_string); |
650 if (id == Builtin::kInvalidLibrary) { | 634 if (id == Builtin::kInvalidLibrary) { |
651 return DartUtils::NewError("The built-in library '%s' is not available" | 635 return DartUtils::NewError( |
652 " on the stand-alone VM. Trying to load" | 636 "The built-in library '%s' is not available" |
653 " '%s'.\n", library_url_string, url_string); | 637 " on the stand-alone VM. Trying to load" |
| 638 " '%s'.\n", |
| 639 library_url_string, url_string); |
654 } | 640 } |
655 // Prepend the library URI to form a unique script URI for the part. | 641 // Prepend the library URI to form a unique script URI for the part. |
656 intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string); | 642 intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string); |
657 char* part_uri = reinterpret_cast<char*>(malloc(len + 1)); | 643 char* part_uri = reinterpret_cast<char*>(malloc(len + 1)); |
658 snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string); | 644 snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string); |
659 Dart_Handle part_uri_obj = DartUtils::NewString(part_uri); | 645 Dart_Handle part_uri_obj = DartUtils::NewString(part_uri); |
660 free(part_uri); | 646 free(part_uri); |
661 return Dart_LoadSource(library, | 647 return Dart_LoadSource(library, part_uri_obj, Dart_Null(), |
662 part_uri_obj, Dart_Null(), | |
663 Builtin::PartSource(id, url_string), 0, 0); | 648 Builtin::PartSource(id, url_string), 0, 0); |
664 } | 649 } |
665 // All cases should have been handled above. | 650 // All cases should have been handled above. |
666 UNREACHABLE(); | 651 UNREACHABLE(); |
667 return Dart_Null(); | 652 return Dart_Null(); |
668 } | 653 } |
669 | 654 |
670 | 655 |
671 void Loader::InitOnce() { | 656 void Loader::InitOnce() { |
672 loader_infos_lock_ = new Mutex(); | 657 loader_infos_lock_ = new Mutex(); |
(...skipping 10 matching lines...) Expand all Loading... |
683 // native message arrives, we use this map to report the I/O result to the | 668 // native message arrives, we use this map to report the I/O result to the |
684 // correct loader. | 669 // correct loader. |
685 // This happens whenever an isolate begins loading. | 670 // This happens whenever an isolate begins loading. |
686 void Loader::AddLoader(Dart_Port port, IsolateData* isolate_data) { | 671 void Loader::AddLoader(Dart_Port port, IsolateData* isolate_data) { |
687 MutexLocker ml(loader_infos_lock_); | 672 MutexLocker ml(loader_infos_lock_); |
688 ASSERT(LoaderForLocked(port) == NULL); | 673 ASSERT(LoaderForLocked(port) == NULL); |
689 if (loader_infos_length_ == loader_infos_capacity_) { | 674 if (loader_infos_length_ == loader_infos_capacity_) { |
690 // Grow to an initial capacity or double in size. | 675 // Grow to an initial capacity or double in size. |
691 loader_infos_capacity_ = | 676 loader_infos_capacity_ = |
692 (loader_infos_capacity_ == 0) ? 4 : loader_infos_capacity_ * 2; | 677 (loader_infos_capacity_ == 0) ? 4 : loader_infos_capacity_ * 2; |
693 loader_infos_ = | 678 loader_infos_ = reinterpret_cast<Loader::LoaderInfo*>(realloc( |
694 reinterpret_cast<Loader::LoaderInfo*>( | 679 loader_infos_, sizeof(Loader::LoaderInfo) * loader_infos_capacity_)); |
695 realloc(loader_infos_, | |
696 sizeof(Loader::LoaderInfo) * loader_infos_capacity_)); | |
697 ASSERT(loader_infos_ != NULL); | 680 ASSERT(loader_infos_ != NULL); |
698 // Initialize new entries. | 681 // Initialize new entries. |
699 for (intptr_t i = loader_infos_length_; i < loader_infos_capacity_; i++) { | 682 for (intptr_t i = loader_infos_length_; i < loader_infos_capacity_; i++) { |
700 loader_infos_[i].port = ILLEGAL_PORT; | 683 loader_infos_[i].port = ILLEGAL_PORT; |
701 loader_infos_[i].isolate_data = NULL; | 684 loader_infos_[i].isolate_data = NULL; |
702 } | 685 } |
703 } | 686 } |
704 ASSERT(loader_infos_length_ < loader_infos_capacity_); | 687 ASSERT(loader_infos_length_ < loader_infos_capacity_); |
705 loader_infos_[loader_infos_length_].port = port; | 688 loader_infos_[loader_infos_length_].port = port; |
706 loader_infos_[loader_infos_length_].isolate_data = isolate_data; | 689 loader_infos_[loader_infos_length_].isolate_data = isolate_data; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 MutexLocker ml(loader_infos_lock_); | 738 MutexLocker ml(loader_infos_lock_); |
756 Loader* loader = LoaderForLocked(dest_port_id); | 739 Loader* loader = LoaderForLocked(dest_port_id); |
757 if (loader == NULL) { | 740 if (loader == NULL) { |
758 return; | 741 return; |
759 } | 742 } |
760 loader->QueueMessage(message); | 743 loader->QueueMessage(message); |
761 } | 744 } |
762 | 745 |
763 } // namespace bin | 746 } // namespace bin |
764 } // namespace dart | 747 } // namespace dart |
OLD | NEW |