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

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: remove Dart_IsClass from header. remove demo assert 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
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/debugger_api_impl_test.cc » ('j') | 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) 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 Type& type_obj = Api::UnwrapTypeHandle(isolate, target);
463 // For backwards compatibility we allow class objects to be passed in 463 if (type_obj.IsNull()) {
464 // for now. This needs to be removed once all code that uses class
465 // objects is removed.
466 Class& cls = Class::Handle();
467 if (obj.IsType()) {
468 cls = Type::Cast(obj).type_class();
469 } else if (obj.IsClass()) {
470 cls = Class::Cast(obj).raw();
471 } else {
472 return Api::NewError("%s expects argument 'target' to be a type", 464 return Api::NewError("%s expects argument 'target' to be a type",
473 CURRENT_FUNC); 465 CURRENT_FUNC);
474 } 466 }
467 const Class& cls = Class::Handle(isolate, type_obj.type_class());
475 return Api::NewHandle(isolate, isolate->debugger()->GetStaticFields(cls)); 468 return Api::NewHandle(isolate, isolate->debugger()->GetStaticFields(cls));
476 } 469 }
477 470
478 471
479 DART_EXPORT Dart_Handle Dart_GetLibraryFields(intptr_t library_id) { 472 DART_EXPORT Dart_Handle Dart_GetLibraryFields(intptr_t library_id) {
480 Isolate* isolate = Isolate::Current(); 473 Isolate* isolate = Isolate::Current();
481 DARTSCOPE(isolate); 474 DARTSCOPE(isolate);
482 const Library& lib = 475 const Library& lib =
483 Library::Handle(isolate, Library::GetLibrary(library_id)); 476 Library::Handle(isolate, Library::GetLibrary(library_id));
484 if (lib.IsNull()) { 477 if (lib.IsNull()) {
(...skipping 22 matching lines...) Expand all
507 Isolate* isolate = Isolate::Current(); 500 Isolate* isolate = Isolate::Current();
508 DARTSCOPE(isolate); 501 DARTSCOPE(isolate);
509 502
510 const Object& target = Object::Handle(isolate, Api::UnwrapHandle(target_in)); 503 const Object& target = Object::Handle(isolate, Api::UnwrapHandle(target_in));
511 if (target.IsError()) return target_in; 504 if (target.IsError()) return target_in;
512 if (target.IsNull()) { 505 if (target.IsNull()) {
513 return Api::NewError("%s expects argument 'target' to be non-null", 506 return Api::NewError("%s expects argument 'target' to be non-null",
514 CURRENT_FUNC); 507 CURRENT_FUNC);
515 } 508 }
516 UNWRAP_AND_CHECK_PARAM(String, expr, expr_in); 509 UNWRAP_AND_CHECK_PARAM(String, expr, expr_in);
517 if (target.IsInstance()) { 510 if (target.IsType()) {
511 const Class& cls = Class::Handle(isolate, Type::Cast(target).type_class());
512 return Api::NewHandle(isolate, cls.Evaluate(expr));
513 } else if (target.IsInstance()) {
518 return Api::NewHandle(isolate, Instance::Cast(target).Evaluate(expr)); 514 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()) { 515 } else if (target.IsLibrary()) {
522 return Api::NewHandle(isolate, Library::Cast(target).Evaluate(expr)); 516 return Api::NewHandle(isolate, Library::Cast(target).Evaluate(expr));
523 } 517 }
524 return Api::NewError("%s: unsupported target type", CURRENT_FUNC); 518 return Api::NewError("%s: unsupported target type", CURRENT_FUNC);
525 } 519 }
526 520
527 521
528 DART_EXPORT Dart_Handle Dart_GetObjClass(Dart_Handle object_in) { 522 DART_EXPORT Dart_Handle Dart_GetObjClass(Dart_Handle object_in) {
529 Isolate* isolate = Isolate::Current(); 523 Isolate* isolate = Isolate::Current();
530 DARTSCOPE(isolate); 524 DARTSCOPE(isolate);
531 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); 525 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in);
532 return Api::NewHandle(isolate, obj.clazz()); 526 return Api::NewHandle(isolate, obj.GetType());
533 } 527 }
534 528
535 529
536 DART_EXPORT Dart_Handle Dart_GetObjClassId(Dart_Handle object_in, 530 DART_EXPORT Dart_Handle Dart_GetObjClassId(Dart_Handle object_in,
537 intptr_t* class_id) { 531 intptr_t* class_id) {
538 Isolate* isolate = Isolate::Current(); 532 Isolate* isolate = Isolate::Current();
539 DARTSCOPE(isolate); 533 DARTSCOPE(isolate);
540 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); 534 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in);
541 CHECK_NOT_NULL(class_id); 535 CHECK_NOT_NULL(class_id);
542 *class_id = obj.GetClassId(); 536 *class_id = obj.GetClassId();
543 return Api::Success(); 537 return Api::Success();
544 } 538 }
545 539
546 540
547 DART_EXPORT Dart_Handle Dart_GetClassFromId(intptr_t class_id) { 541 DART_EXPORT Dart_Handle Dart_GetClassFromId(intptr_t class_id) {
548 Isolate* isolate = Isolate::Current(); 542 Isolate* isolate = Isolate::Current();
549 DARTSCOPE(isolate); 543 DARTSCOPE(isolate);
550 if (!isolate->class_table()->IsValidIndex(class_id)) { 544 if (!isolate->class_table()->IsValidIndex(class_id)) {
551 return Api::NewError("%s: %" Pd " is not a valid class id", 545 return Api::NewError("%s: %" Pd " is not a valid class id",
552 CURRENT_FUNC, class_id); 546 CURRENT_FUNC, class_id);
553 } 547 }
554 return Api::NewHandle(isolate, isolate->class_table()->At(class_id)); 548 return Api::NewHandle(isolate, isolate->class_table()->At(class_id));
555 } 549 }
556 550
557 551
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) { 552 DART_EXPORT Dart_Handle Dart_GetSupertype(Dart_Handle type_in) {
567 Isolate* isolate = Isolate::Current(); 553 Isolate* isolate = Isolate::Current();
568 DARTSCOPE(isolate); 554 DARTSCOPE(isolate);
569 555
570 UNWRAP_AND_CHECK_PARAM(Type, type, type_in); 556 UNWRAP_AND_CHECK_PARAM(Type, type, type_in);
571 if (!type.IsFinalized()) { 557 if (!type.IsFinalized()) {
572 return Api::NewError("%s: type in 'type_in' is not a finalized type", 558 return Api::NewError("%s: type in 'type_in' is not a finalized type",
573 CURRENT_FUNC); 559 CURRENT_FUNC);
574 } 560 }
575 if (!type.IsInstantiated()) { 561 if (!type.IsInstantiated()) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 883
898 884
899 DART_EXPORT char* Dart_GetVmStatus(const char* request) { 885 DART_EXPORT char* Dart_GetVmStatus(const char* request) {
900 if (strncmp(request, "/isolate/", 9) == 0) { 886 if (strncmp(request, "/isolate/", 9) == 0) {
901 return Isolate::GetStatus(request); 887 return Isolate::GetStatus(request);
902 } 888 }
903 return NULL; 889 return NULL;
904 } 890 }
905 891
906 } // namespace dart 892 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/debugger_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698