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

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

Issue 1310463005: - Ensure that HandleScope is initialized with a thread. (Remove (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
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 "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/globals.h" 9 #include "platform/globals.h"
10 10
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 return true; 504 return true;
505 } 505 }
506 506
507 507
508 void Service::PostError(const String& method_name, 508 void Service::PostError(const String& method_name,
509 const Array& parameter_keys, 509 const Array& parameter_keys,
510 const Array& parameter_values, 510 const Array& parameter_values,
511 const Instance& reply_port, 511 const Instance& reply_port,
512 const Instance& id, 512 const Instance& id,
513 const Error& error) { 513 const Error& error) {
514 Isolate* isolate = Isolate::Current(); 514 Thread* thread = Thread::Current();
515 Isolate* isolate = thread->isolate();
515 StackZone zone(isolate); 516 StackZone zone(isolate);
516 HANDLESCOPE(isolate); 517 HANDLESCOPE(thread);
517 JSONStream js; 518 JSONStream js;
518 js.Setup(zone.GetZone(), SendPort::Cast(reply_port).Id(), 519 js.Setup(zone.GetZone(), SendPort::Cast(reply_port).Id(),
519 id, method_name, parameter_keys, parameter_values); 520 id, method_name, parameter_keys, parameter_values);
520 js.PrintError(kExtensionError, 521 js.PrintError(kExtensionError,
521 "Error in extension `%s`: %s", 522 "Error in extension `%s`: %s",
522 js.method(), error.ToErrorCString()); 523 js.method(), error.ToErrorCString());
523 js.PostReply(); 524 js.PostReply();
524 } 525 }
525 526
526 527
527 void Service::InvokeMethod(Isolate* isolate, const Array& msg) { 528 void Service::InvokeMethod(Isolate* isolate, const Array& msg) {
529 Thread* thread = Thread::Current();
530 ASSERT(isolate == thread->isolate());
528 ASSERT(isolate != NULL); 531 ASSERT(isolate != NULL);
529 ASSERT(!msg.IsNull()); 532 ASSERT(!msg.IsNull());
530 ASSERT(msg.Length() == 6); 533 ASSERT(msg.Length() == 6);
531 534
532 { 535 {
533 StackZone zone(isolate); 536 StackZone zone(isolate);
534 HANDLESCOPE(isolate); 537 HANDLESCOPE(thread);
535 538
536 Instance& reply_port = Instance::Handle(isolate); 539 Instance& reply_port = Instance::Handle(isolate);
537 Instance& seq = String::Handle(isolate); 540 Instance& seq = String::Handle(isolate);
538 String& method_name = String::Handle(isolate); 541 String& method_name = String::Handle(isolate);
539 Array& param_keys = Array::Handle(isolate); 542 Array& param_keys = Array::Handle(isolate);
540 Array& param_values = Array::Handle(isolate); 543 Array& param_values = Array::Handle(isolate);
541 reply_port ^= msg.At(1); 544 reply_port ^= msg.At(1);
542 seq ^= msg.At(2); 545 seq ^= msg.At(2);
543 method_name ^= msg.At(3); 546 method_name ^= msg.At(3);
544 param_keys ^= msg.At(4); 547 param_keys ^= msg.At(4);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 } 646 }
644 647
645 648
646 void Service::SendEvent(const char* stream_id, 649 void Service::SendEvent(const char* stream_id,
647 const char* event_type, 650 const char* event_type,
648 const Object& event_message) { 651 const Object& event_message) {
649 ASSERT(!ServiceIsolate::IsServiceIsolateDescendant(Isolate::Current())); 652 ASSERT(!ServiceIsolate::IsServiceIsolateDescendant(Isolate::Current()));
650 if (!ServiceIsolate::IsRunning()) { 653 if (!ServiceIsolate::IsRunning()) {
651 return; 654 return;
652 } 655 }
653 Isolate* isolate = Isolate::Current(); 656 Thread* thread = Thread::Current();
657 Isolate* isolate = thread->isolate();
654 ASSERT(isolate != NULL); 658 ASSERT(isolate != NULL);
655 HANDLESCOPE(isolate); 659 HANDLESCOPE(thread);
656 660
657 const Array& list = Array::Handle(Array::New(2)); 661 const Array& list = Array::Handle(Array::New(2));
658 ASSERT(!list.IsNull()); 662 ASSERT(!list.IsNull());
659 const String& stream_id_str = String::Handle(String::New(stream_id)); 663 const String& stream_id_str = String::Handle(String::New(stream_id));
660 list.SetAt(0, stream_id_str); 664 list.SetAt(0, stream_id_str);
661 list.SetAt(1, event_message); 665 list.SetAt(1, event_message);
662 666
663 // Push the event to port_. 667 // Push the event to port_.
664 uint8_t* data = NULL; 668 uint8_t* data = NULL;
665 MessageWriter writer(&data, &allocator, false); 669 MessageWriter writer(&data, &allocator, false);
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 isolate->message_handler()->AcquireQueues(&aq); 1475 isolate->message_handler()->AcquireQueues(&aq);
1472 Message* message = aq.queue()->FindMessageById(message_id); 1476 Message* message = aq.queue()->FindMessageById(message_id);
1473 if (message == NULL) { 1477 if (message == NULL) {
1474 // The user may try to load an expired message, so we treat 1478 // The user may try to load an expired message, so we treat
1475 // unrecognized ids as if they are expired. 1479 // unrecognized ids as if they are expired.
1476 PrintSentinel(js, kExpiredSentinel); 1480 PrintSentinel(js, kExpiredSentinel);
1477 return true; 1481 return true;
1478 } 1482 }
1479 MessageSnapshotReader reader(message->data(), 1483 MessageSnapshotReader reader(message->data(),
1480 message->len(), 1484 message->len(),
1481 isolate, 1485 Thread::Current());
1482 Thread::Current()->zone());
1483 const Object& msg_obj = Object::Handle(reader.ReadObject()); 1486 const Object& msg_obj = Object::Handle(reader.ReadObject());
1484 msg_obj.PrintJSON(js); 1487 msg_obj.PrintJSON(js);
1485 return true; 1488 return true;
1486 } 1489 }
1487 } 1490 }
1488 return false; 1491 return false;
1489 } 1492 }
1490 1493
1491 1494
1492 static bool PrintInboundReferences(Isolate* isolate, 1495 static bool PrintInboundReferences(Isolate* isolate,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 } 1542 }
1540 1543
1541 1544
1542 static const MethodParameter* get_inbound_references_params[] = { 1545 static const MethodParameter* get_inbound_references_params[] = {
1543 ISOLATE_PARAMETER, 1546 ISOLATE_PARAMETER,
1544 NULL, 1547 NULL,
1545 }; 1548 };
1546 1549
1547 1550
1548 static bool GetInboundReferences(Isolate* isolate, JSONStream* js) { 1551 static bool GetInboundReferences(Isolate* isolate, JSONStream* js) {
1552 Thread* thread = Thread::Current();
1553 ASSERT(isolate == thread->isolate());
1554
1549 const char* target_id = js->LookupParam("targetId"); 1555 const char* target_id = js->LookupParam("targetId");
1550 if (target_id == NULL) { 1556 if (target_id == NULL) {
1551 PrintMissingParamError(js, "targetId"); 1557 PrintMissingParamError(js, "targetId");
1552 return true; 1558 return true;
1553 } 1559 }
1554 const char* limit_cstr = js->LookupParam("limit"); 1560 const char* limit_cstr = js->LookupParam("limit");
1555 if (limit_cstr == NULL) { 1561 if (limit_cstr == NULL) {
1556 PrintMissingParamError(js, "limit"); 1562 PrintMissingParamError(js, "limit");
1557 return true; 1563 return true;
1558 } 1564 }
1559 intptr_t limit; 1565 intptr_t limit;
1560 if (!GetIntegerId(limit_cstr, &limit)) { 1566 if (!GetIntegerId(limit_cstr, &limit)) {
1561 PrintInvalidParamError(js, "limit"); 1567 PrintInvalidParamError(js, "limit");
1562 return true; 1568 return true;
1563 } 1569 }
1564 1570
1565 Object& obj = Object::Handle(isolate); 1571 Object& obj = Object::Handle(isolate);
1566 ObjectIdRing::LookupResult lookup_result; 1572 ObjectIdRing::LookupResult lookup_result;
1567 { 1573 {
1568 HANDLESCOPE(isolate); 1574 HANDLESCOPE(thread);
1569 obj = LookupHeapObject(isolate, target_id, &lookup_result); 1575 obj = LookupHeapObject(isolate, target_id, &lookup_result);
1570 } 1576 }
1571 if (obj.raw() == Object::sentinel().raw()) { 1577 if (obj.raw() == Object::sentinel().raw()) {
1572 if (lookup_result == ObjectIdRing::kCollected) { 1578 if (lookup_result == ObjectIdRing::kCollected) {
1573 PrintSentinel(js, kCollectedSentinel); 1579 PrintSentinel(js, kCollectedSentinel);
1574 } else if (lookup_result == ObjectIdRing::kExpired) { 1580 } else if (lookup_result == ObjectIdRing::kExpired) {
1575 PrintSentinel(js, kExpiredSentinel); 1581 PrintSentinel(js, kExpiredSentinel);
1576 } else { 1582 } else {
1577 PrintInvalidParamError(js, "targetId"); 1583 PrintInvalidParamError(js, "targetId");
1578 } 1584 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 } 1644 }
1639 1645
1640 1646
1641 static const MethodParameter* get_retaining_path_params[] = { 1647 static const MethodParameter* get_retaining_path_params[] = {
1642 ISOLATE_PARAMETER, 1648 ISOLATE_PARAMETER,
1643 NULL, 1649 NULL,
1644 }; 1650 };
1645 1651
1646 1652
1647 static bool GetRetainingPath(Isolate* isolate, JSONStream* js) { 1653 static bool GetRetainingPath(Isolate* isolate, JSONStream* js) {
1654 Thread* thread = Thread::Current();
1655 ASSERT(isolate == thread->isolate());
1656
1648 const char* target_id = js->LookupParam("targetId"); 1657 const char* target_id = js->LookupParam("targetId");
1649 if (target_id == NULL) { 1658 if (target_id == NULL) {
1650 PrintMissingParamError(js, "targetId"); 1659 PrintMissingParamError(js, "targetId");
1651 return true; 1660 return true;
1652 } 1661 }
1653 const char* limit_cstr = js->LookupParam("limit"); 1662 const char* limit_cstr = js->LookupParam("limit");
1654 if (limit_cstr == NULL) { 1663 if (limit_cstr == NULL) {
1655 PrintMissingParamError(js, "limit"); 1664 PrintMissingParamError(js, "limit");
1656 return true; 1665 return true;
1657 } 1666 }
1658 intptr_t limit; 1667 intptr_t limit;
1659 if (!GetIntegerId(limit_cstr, &limit)) { 1668 if (!GetIntegerId(limit_cstr, &limit)) {
1660 PrintInvalidParamError(js, "limit"); 1669 PrintInvalidParamError(js, "limit");
1661 return true; 1670 return true;
1662 } 1671 }
1663 1672
1664 Object& obj = Object::Handle(isolate); 1673 Object& obj = Object::Handle(isolate);
1665 ObjectIdRing::LookupResult lookup_result; 1674 ObjectIdRing::LookupResult lookup_result;
1666 { 1675 {
1667 HANDLESCOPE(isolate); 1676 HANDLESCOPE(thread);
1668 obj = LookupHeapObject(isolate, target_id, &lookup_result); 1677 obj = LookupHeapObject(isolate, target_id, &lookup_result);
1669 } 1678 }
1670 if (obj.raw() == Object::sentinel().raw()) { 1679 if (obj.raw() == Object::sentinel().raw()) {
1671 if (lookup_result == ObjectIdRing::kCollected) { 1680 if (lookup_result == ObjectIdRing::kCollected) {
1672 PrintSentinel(js, kCollectedSentinel); 1681 PrintSentinel(js, kCollectedSentinel);
1673 } else if (lookup_result == ObjectIdRing::kExpired) { 1682 } else if (lookup_result == ObjectIdRing::kExpired) {
1674 PrintSentinel(js, kExpiredSentinel); 1683 PrintSentinel(js, kExpiredSentinel);
1675 } else { 1684 } else {
1676 PrintInvalidParamError(js, "targetId"); 1685 PrintInvalidParamError(js, "targetId");
1677 } 1686 }
(...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after
3163 ServiceMethodDescriptor& method = service_methods_[i]; 3172 ServiceMethodDescriptor& method = service_methods_[i];
3164 if (strcmp(method_name, method.name) == 0) { 3173 if (strcmp(method_name, method.name) == 0) {
3165 return &method; 3174 return &method;
3166 } 3175 }
3167 } 3176 }
3168 return NULL; 3177 return NULL;
3169 } 3178 }
3170 3179
3171 3180
3172 } // namespace dart 3181 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698