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

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

Issue 24210003: Never return a Dart_Handle on a dart::Class from the embedding API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "include/dart_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 6
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 Isolate* isolate = Isolate::Current(); 452 Isolate* isolate = Isolate::Current();
453 DARTSCOPE(isolate); 453 DARTSCOPE(isolate);
454 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); 454 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in);
455 return Api::NewHandle(isolate, isolate->debugger()->GetInstanceFields(obj)); 455 return Api::NewHandle(isolate, isolate->debugger()->GetInstanceFields(obj));
456 } 456 }
457 457
458 458
459 DART_EXPORT Dart_Handle Dart_GetStaticFields(Dart_Handle target) { 459 DART_EXPORT Dart_Handle Dart_GetStaticFields(Dart_Handle target) {
460 Isolate* isolate = Isolate::Current(); 460 Isolate* isolate = Isolate::Current();
461 DARTSCOPE(isolate); 461 DARTSCOPE(isolate);
462 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); 462 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target));
siva 2013/09/19 03:16:58 Ditto comment about using const Type& type_obj = A
463 // For backwards compatibility we allow class objects to be passed in
464 // for now. This needs to be removed once all code that uses class
465 // objects is removed.
466 Class& cls = Class::Handle(); 463 Class& cls = Class::Handle();
467 if (obj.IsType()) { 464 if (obj.IsType()) {
468 cls = Type::Cast(obj).type_class(); 465 cls = Type::Cast(obj).type_class();
469 } else if (obj.IsClass()) {
470 cls = Class::Cast(obj).raw();
471 } else { 466 } else {
472 return Api::NewError("%s expects argument 'target' to be a type", 467 return Api::NewError("%s expects argument 'target' to be a type",
473 CURRENT_FUNC); 468 CURRENT_FUNC);
474 } 469 }
475 return Api::NewHandle(isolate, isolate->debugger()->GetStaticFields(cls)); 470 return Api::NewHandle(isolate, isolate->debugger()->GetStaticFields(cls));
476 } 471 }
477 472
478 473
479 DART_EXPORT Dart_Handle Dart_GetLibraryFields(intptr_t library_id) { 474 DART_EXPORT Dart_Handle Dart_GetLibraryFields(intptr_t library_id) {
480 Isolate* isolate = Isolate::Current(); 475 Isolate* isolate = Isolate::Current();
(...skipping 26 matching lines...) Expand all
507 Isolate* isolate = Isolate::Current(); 502 Isolate* isolate = Isolate::Current();
508 DARTSCOPE(isolate); 503 DARTSCOPE(isolate);
509 504
510 const Object& target = Object::Handle(isolate, Api::UnwrapHandle(target_in)); 505 const Object& target = Object::Handle(isolate, Api::UnwrapHandle(target_in));
511 if (target.IsError()) return target_in; 506 if (target.IsError()) return target_in;
512 if (target.IsNull()) { 507 if (target.IsNull()) {
513 return Api::NewError("%s expects argument 'target' to be non-null", 508 return Api::NewError("%s expects argument 'target' to be non-null",
514 CURRENT_FUNC); 509 CURRENT_FUNC);
515 } 510 }
516 UNWRAP_AND_CHECK_PARAM(String, expr, expr_in); 511 UNWRAP_AND_CHECK_PARAM(String, expr, expr_in);
517 if (target.IsInstance()) { 512 if (target.IsType()) {
513 const Class& cls = Class::Handle(isolate, Type::Cast(target).type_class());
514 return Api::NewHandle(isolate, cls.Evaluate(expr));
515 } else if (target.IsInstance()) {
518 return Api::NewHandle(isolate, Instance::Cast(target).Evaluate(expr)); 516 return Api::NewHandle(isolate, Instance::Cast(target).Evaluate(expr));
519 } else if (target.IsClass()) {
520 return Api::NewHandle(isolate, Class::Cast(target).Evaluate(expr));
521 } else if (target.IsLibrary()) { 517 } else if (target.IsLibrary()) {
522 return Api::NewHandle(isolate, Library::Cast(target).Evaluate(expr)); 518 return Api::NewHandle(isolate, Library::Cast(target).Evaluate(expr));
523 } 519 }
524 return Api::NewError("%s: unsupported target type", CURRENT_FUNC); 520 return Api::NewError("%s: unsupported target type", CURRENT_FUNC);
525 } 521 }
526 522
527 523
528 DART_EXPORT Dart_Handle Dart_GetObjClass(Dart_Handle object_in) { 524 DART_EXPORT Dart_Handle Dart_GetObjClass(Dart_Handle object_in) {
529 Isolate* isolate = Isolate::Current(); 525 Isolate* isolate = Isolate::Current();
530 DARTSCOPE(isolate); 526 DARTSCOPE(isolate);
531 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); 527 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in);
532 return Api::NewHandle(isolate, obj.clazz()); 528 return Api::NewHandle(isolate, obj.GetType());
533 } 529 }
534 530
535 531
536 DART_EXPORT Dart_Handle Dart_GetObjClassId(Dart_Handle object_in, 532 DART_EXPORT Dart_Handle Dart_GetObjClassId(Dart_Handle object_in,
537 intptr_t* class_id) { 533 intptr_t* class_id) {
538 Isolate* isolate = Isolate::Current(); 534 Isolate* isolate = Isolate::Current();
539 DARTSCOPE(isolate); 535 DARTSCOPE(isolate);
540 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); 536 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in);
541 CHECK_NOT_NULL(class_id); 537 CHECK_NOT_NULL(class_id);
542 *class_id = obj.GetClassId(); 538 *class_id = obj.GetClassId();
543 return Api::Success(); 539 return Api::Success();
544 } 540 }
545 541
546 542
547 DART_EXPORT Dart_Handle Dart_GetClassFromId(intptr_t class_id) { 543 DART_EXPORT Dart_Handle Dart_GetClassFromId(intptr_t class_id) {
548 Isolate* isolate = Isolate::Current(); 544 Isolate* isolate = Isolate::Current();
549 DARTSCOPE(isolate); 545 DARTSCOPE(isolate);
550 if (!isolate->class_table()->IsValidIndex(class_id)) { 546 if (!isolate->class_table()->IsValidIndex(class_id)) {
551 return Api::NewError("%s: %" Pd " is not a valid class id", 547 return Api::NewError("%s: %" Pd " is not a valid class id",
552 CURRENT_FUNC, class_id); 548 CURRENT_FUNC, class_id);
553 } 549 }
554 return Api::NewHandle(isolate, isolate->class_table()->At(class_id)); 550 return Api::NewHandle(isolate, isolate->class_table()->At(class_id));
555 } 551 }
556 552
557 553
558 DART_EXPORT Dart_Handle Dart_GetSuperclass(Dart_Handle cls_in) {
559 Isolate* isolate = Isolate::Current();
560 DARTSCOPE(isolate);
561 UNWRAP_AND_CHECK_PARAM(Class, cls, cls_in);
562 return Api::NewHandle(isolate, cls.SuperClass());
563 }
564
565
566 DART_EXPORT Dart_Handle Dart_GetSupertype(Dart_Handle type_in) { 554 DART_EXPORT Dart_Handle Dart_GetSupertype(Dart_Handle type_in) {
567 Isolate* isolate = Isolate::Current(); 555 Isolate* isolate = Isolate::Current();
568 DARTSCOPE(isolate); 556 DARTSCOPE(isolate);
569 557
570 UNWRAP_AND_CHECK_PARAM(Type, type, type_in); 558 UNWRAP_AND_CHECK_PARAM(Type, type, type_in);
571 if (!type.IsFinalized()) { 559 if (!type.IsFinalized()) {
572 return Api::NewError("%s: type in 'type_in' is not a finalized type", 560 return Api::NewError("%s: type in 'type_in' is not a finalized type",
573 CURRENT_FUNC); 561 CURRENT_FUNC);
574 } 562 }
575 if (!type.IsInstantiated()) { 563 if (!type.IsInstantiated()) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 885
898 886
899 DART_EXPORT char* Dart_GetVmStatus(const char* request) { 887 DART_EXPORT char* Dart_GetVmStatus(const char* request) {
900 if (strncmp(request, "/isolate/", 9) == 0) { 888 if (strncmp(request, "/isolate/", 9) == 0) {
901 return Isolate::GetStatus(request); 889 return Isolate::GetStatus(request);
902 } 890 }
903 return NULL; 891 return NULL;
904 } 892 }
905 893
906 } // namespace dart 894 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698