Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: runtime/vm/service.cc

Issue 391943003: Allow for no embedder provided library tag handler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "vm/service.h" 5 #include "vm/service.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 9
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return entry.function; 295 return entry.function;
296 } 296 }
297 } 297 }
298 return NULL; 298 return NULL;
299 } 299 }
300 300
301 301
302 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; 302 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL;
303 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; 303 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL;
304 Isolate* Service::service_isolate_ = NULL; 304 Isolate* Service::service_isolate_ = NULL;
305 Dart_LibraryTagHandler Service::default_handler_ = NULL; 305 Dart_LibraryTagHandler Service::embedder_provided_handler_ = NULL;
306 Dart_Port Service::port_ = ILLEGAL_PORT; 306 Dart_Port Service::port_ = ILLEGAL_PORT;
307 uint32_t Service::event_mask_ = 0; 307 uint32_t Service::event_mask_ = 0;
308 308
309 309
310 static Dart_Port ExtractPort(Dart_Handle receivePort) { 310 static Dart_Port ExtractPort(Dart_Handle receivePort) {
311 HANDLESCOPE(Isolate::Current()); 311 HANDLESCOPE(Isolate::Current());
312 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort)); 312 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort));
313 const Instance& rp = Instance::Cast(unwrapped_rp); 313 const Instance& rp = Instance::Cast(unwrapped_rp);
314 // Extract RawReceivePort port id. 314 // Extract RawReceivePort port id.
315 if (!rp.IsReceivePort()) { 315 if (!rp.IsReceivePort()) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 Isolate::SetCurrent(isolate); 410 Isolate::SetCurrent(isolate);
411 { 411 {
412 // Install the dart:vmservice library. 412 // Install the dart:vmservice library.
413 StackZone zone(isolate); 413 StackZone zone(isolate);
414 HANDLESCOPE(isolate); 414 HANDLESCOPE(isolate);
415 Library& library = 415 Library& library =
416 Library::Handle(isolate, isolate->object_store()->root_library()); 416 Library::Handle(isolate, isolate->object_store()->root_library());
417 // Isolate is empty. 417 // Isolate is empty.
418 ASSERT(library.IsNull()); 418 ASSERT(library.IsNull());
419 // Grab embedder tag handler. 419 // Grab embedder tag handler.
420 default_handler_ = isolate->library_tag_handler(); 420 embedder_provided_handler_ = isolate->library_tag_handler();
421 ASSERT(default_handler_ != NULL);
422 // Temporarily install our own. 421 // Temporarily install our own.
423 isolate->set_library_tag_handler(LibraryTagHandler); 422 isolate->set_library_tag_handler(LibraryTagHandler);
424 // Get script resource. 423 // Get script resource.
425 const char* resource = NULL; 424 const char* resource = NULL;
426 const char* path = "/vmservice.dart"; 425 const char* path = "/vmservice.dart";
427 intptr_t r = Resources::ResourceLookup(path, &resource); 426 intptr_t r = Resources::ResourceLookup(path, &resource);
428 ASSERT(r != Resources::kNoSuchInstance); 427 ASSERT(r != Resources::kNoSuchInstance);
429 ASSERT(resource != NULL); 428 ASSERT(resource != NULL);
430 const String& source_str = String::Handle( 429 const String& source_str = String::Handle(
431 String::FromUTF8(reinterpret_cast<const uint8_t*>(resource), r)); 430 String::FromUTF8(reinterpret_cast<const uint8_t*>(resource), r));
432 ASSERT(!source_str.IsNull()); 431 ASSERT(!source_str.IsNull());
433 const String& url_str = String::Handle(Symbols::DartVMService().raw()); 432 const String& url_str = String::Handle(Symbols::DartVMService().raw());
434 library ^= Library::LookupLibrary(url_str); 433 library ^= Library::LookupLibrary(url_str);
435 ASSERT(library.IsNull()); 434 ASSERT(library.IsNull());
436 // Setup library. 435 // Setup library.
437 library = Library::New(url_str); 436 library = Library::New(url_str);
438 library.Register(); 437 library.Register();
439 const Script& script = Script::Handle( 438 const Script& script = Script::Handle(
440 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag)); 439 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag));
441 library.SetLoadInProgress(); 440 library.SetLoadInProgress();
442 Dart_EnterScope(); // Need to enter scope for tag handler. 441 Dart_EnterScope(); // Need to enter scope for tag handler.
443 const Error& error = Error::Handle(isolate, 442 const Error& error = Error::Handle(isolate,
444 Compiler::Compile(library, script)); 443 Compiler::Compile(library, script));
445 ASSERT(error.IsNull()); 444 ASSERT(error.IsNull());
446 Dart_ExitScope(); 445 Dart_ExitScope();
447 library.SetLoaded(); 446 library.SetLoaded();
448 // Install embedder default library tag handler again. 447 // Install embedder default library tag handler again.
449 isolate->set_library_tag_handler(default_handler_); 448 isolate->set_library_tag_handler(embedder_provided_handler_);
450 default_handler_ = NULL; 449 embedder_provided_handler_ = NULL;
451 library.set_native_entry_resolver(VmServiceNativeResolver); 450 library.set_native_entry_resolver(VmServiceNativeResolver);
452 } 451 }
453 { 452 {
454 // Boot the dart:vmservice library. 453 // Boot the dart:vmservice library.
455 Dart_EnterScope(); 454 Dart_EnterScope();
456 Dart_Handle result; 455 Dart_Handle result;
457 Dart_Handle url_str = 456 Dart_Handle url_str =
458 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId)); 457 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId));
459 Dart_Handle library = Dart_LookupLibrary(url_str); 458 Dart_Handle library = Dart_LookupLibrary(url_str);
460 ASSERT(Dart_IsLibrary(library)); 459 ASSERT(Dart_IsLibrary(library));
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 if (!Dart_IsString(url)) { 562 if (!Dart_IsString(url)) {
564 return Dart_NewApiError("url is not a string"); 563 return Dart_NewApiError("url is not a string");
565 } 564 }
566 const char* url_string = NULL; 565 const char* url_string = NULL;
567 Dart_Handle result = Dart_StringToCString(url, &url_string); 566 Dart_Handle result = Dart_StringToCString(url, &url_string);
568 if (Dart_IsError(result)) { 567 if (Dart_IsError(result)) {
569 return result; 568 return result;
570 } 569 }
571 if (tag == Dart_kImportTag) { 570 if (tag == Dart_kImportTag) {
572 // Embedder handles all requests for external libraries. 571 // Embedder handles all requests for external libraries.
573 ASSERT(default_handler_ != NULL); 572 if (embedder_provided_handler_ == NULL) {
574 return default_handler_(tag, library, url); 573 return Dart_NewApiError("Unable to import module as no library tag "
574 "handler has been provided by embedder");
575 }
576 return embedder_provided_handler_(tag, library, url);
575 } 577 }
576 ASSERT((tag == Dart_kSourceTag) || (tag == Dart_kCanonicalizeUrl)); 578 ASSERT((tag == Dart_kSourceTag) || (tag == Dart_kCanonicalizeUrl));
577 if (tag == Dart_kCanonicalizeUrl) { 579 if (tag == Dart_kCanonicalizeUrl) {
578 // url is already canonicalized. 580 // url is already canonicalized.
579 return url; 581 return url;
580 } 582 }
581 Dart_Handle source = GetSource(url_string); 583 Dart_Handle source = GetSource(url_string);
582 if (Dart_IsError(source)) { 584 if (Dart_IsError(source)) {
583 return source; 585 return source;
584 } 586 }
(...skipping 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after
2381 while (current != NULL) { 2383 while (current != NULL) {
2382 if (strcmp(name, current->name()) == 0) { 2384 if (strcmp(name, current->name()) == 0) {
2383 return current; 2385 return current;
2384 } 2386 }
2385 current = current->next(); 2387 current = current->next();
2386 } 2388 }
2387 return NULL; 2389 return NULL;
2388 } 2390 }
2389 2391
2390 } // namespace dart 2392 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698