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

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

Issue 8733011: Add the CHECK_ISOLATE macro, which validates that the current isolate (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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.h ('k') | runtime/vm/dart_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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 10 matching lines...) Expand all
21 #include "vm/object_store.h" 21 #include "vm/object_store.h"
22 #include "vm/port.h" 22 #include "vm/port.h"
23 #include "vm/resolver.h" 23 #include "vm/resolver.h"
24 #include "vm/snapshot.h" 24 #include "vm/snapshot.h"
25 #include "vm/stack_frame.h" 25 #include "vm/stack_frame.h"
26 #include "vm/timer.h" 26 #include "vm/timer.h"
27 #include "vm/verifier.h" 27 #include "vm/verifier.h"
28 28
29 namespace dart { 29 namespace dart {
30 30
31 static const char* CanonicalFunction(const char* func) { 31 const char* CanonicalFunction(const char* func) {
32 if (strncmp(func, "dart::", 6) == 0) { 32 if (strncmp(func, "dart::", 6) == 0) {
33 return func + 6; 33 return func + 6;
34 } else { 34 } else {
35 return func; 35 return func;
36 } 36 }
37 } 37 }
38 38
39 #define CURRENT_FUNC CanonicalFunction(__FUNCTION__)
40
41 #define RETURN_TYPE_ERROR(dart_handle, Type) \ 39 #define RETURN_TYPE_ERROR(dart_handle, Type) \
42 do { \ 40 do { \
43 const Object& tmp = Object::Handle(Api::UnwrapHandle((dart_handle))); \ 41 const Object& tmp = Object::Handle(Api::UnwrapHandle((dart_handle))); \
44 if (tmp.IsNull()) { \ 42 if (tmp.IsNull()) { \
45 return Api::Error("%s expects argument '%s' to be non-null.", \ 43 return Api::Error("%s expects argument '%s' to be non-null.", \
46 CURRENT_FUNC, #dart_handle); \ 44 CURRENT_FUNC, #dart_handle); \
47 } else if (tmp.IsApiError()) { \ 45 } else if (tmp.IsApiError()) { \
48 return dart_handle; \ 46 return dart_handle; \
49 } else { \ 47 } else { \
50 return Api::Error("%s expects argument '%s' to be of type %s.", \ 48 return Api::Error("%s expects argument '%s' to be of type %s.", \
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 Isolate* isolate = Isolate::Current(); 209 Isolate* isolate = Isolate::Current();
212 ASSERT(isolate != NULL); 210 ASSERT(isolate != NULL);
213 ApiState* state = isolate->api_state(); 211 ApiState* state = isolate->api_state();
214 ASSERT(state != NULL); 212 ASSERT(state != NULL);
215 PersistentHandle* true_handle = state->True(); 213 PersistentHandle* true_handle = state->True();
216 return reinterpret_cast<Dart_Handle>(true_handle); 214 return reinterpret_cast<Dart_Handle>(true_handle);
217 } 215 }
218 216
219 217
220 Dart_Handle Api::Error(const char* format, ...) { 218 Dart_Handle Api::Error(const char* format, ...) {
221 DARTSCOPE(Isolate::Current()); 219 DARTSCOPE_NOCHECKS(Isolate::Current());
222 220
223 va_list args; 221 va_list args;
224 va_start(args, format); 222 va_start(args, format);
225 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 223 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
226 va_end(args); 224 va_end(args);
227 225
228 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); 226 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1));
229 va_list args2; 227 va_list args2;
230 va_start(args2, format); 228 va_start(args2, format);
231 OS::VSNPrint(buffer, (len + 1), format, args2); 229 OS::VSNPrint(buffer, (len + 1), format, args2);
232 va_end(args2); 230 va_end(args2);
233 231
234 const String& message = String::Handle(String::New(buffer)); 232 const String& message = String::Handle(String::New(buffer));
235 const Object& obj = Object::Handle(ApiError::New(message)); 233 const Object& obj = Object::Handle(ApiError::New(message));
236 return Api::NewLocalHandle(obj); 234 return Api::NewLocalHandle(obj);
237 } 235 }
238 236
239 237
240 Dart_Handle Api::ErrorFromException(const Object& obj) { 238 Dart_Handle Api::ErrorFromException(const Object& obj) {
241 DARTSCOPE(Isolate::Current()); 239 DARTSCOPE_NOCHECKS(Isolate::Current());
242 240
243 ASSERT(obj.IsUnhandledException()); 241 ASSERT(obj.IsUnhandledException());
244 if (obj.IsUnhandledException()) { 242 if (obj.IsUnhandledException()) {
245 UnhandledException& uhe = UnhandledException::Handle(); 243 UnhandledException& uhe = UnhandledException::Handle();
246 uhe ^= obj.raw(); 244 uhe ^= obj.raw();
247 const Object& error = Object::Handle(ApiError::New(uhe)); 245 const Object& error = Object::Handle(ApiError::New(uhe));
248 return Api::NewLocalHandle(error); 246 return Api::NewLocalHandle(error);
249 } else { 247 } else {
250 return Api::Error("Internal error: expected obj.IsUnhandledException()."); 248 return Api::Error("Internal error: expected obj.IsUnhandledException().");
251 } 249 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 DARTSCOPE(Isolate::Current()); 482 DARTSCOPE(Isolate::Current());
485 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1)); 483 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1));
486 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2)); 484 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2));
487 *value = (expected.raw() == actual.raw()); 485 *value = (expected.raw() == actual.raw());
488 return Api::Success(); 486 return Api::Success();
489 } 487 }
490 488
491 489
492 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) { 490 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) {
493 Isolate* isolate = Isolate::Current(); 491 Isolate* isolate = Isolate::Current();
494 DARTSCOPE(isolate); 492 CHECK_ISOLATE(isolate);
493 DARTSCOPE_NOCHECKS(isolate);
495 ApiState* state = isolate->api_state(); 494 ApiState* state = isolate->api_state();
496 ASSERT(state != NULL); 495 ASSERT(state != NULL);
497 const Object& old_ref = Object::Handle(Api::UnwrapHandle(object)); 496 const Object& old_ref = Object::Handle(Api::UnwrapHandle(object));
498 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); 497 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle();
499 new_ref->set_raw(old_ref); 498 new_ref->set_raw(old_ref);
500 return reinterpret_cast<Dart_Handle>(new_ref); 499 return reinterpret_cast<Dart_Handle>(new_ref);
501 } 500 }
502 501
503 502
504 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) { 503 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) {
505 Isolate* isolate = Isolate::Current(); 504 Isolate* isolate = Isolate::Current();
506 ASSERT(isolate != NULL); 505 CHECK_ISOLATE(isolate);
507 ApiState* state = isolate->api_state(); 506 ApiState* state = isolate->api_state();
508 ASSERT(state != NULL); 507 ASSERT(state != NULL);
509 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object); 508 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
510 ASSERT(!ref->IsProtected()); 509 ASSERT(!ref->IsProtected());
511 if (!ref->IsProtected()) { 510 if (!ref->IsProtected()) {
512 state->persistent_handles().FreeHandle(ref); 511 state->persistent_handles().FreeHandle(ref);
513 } 512 }
514 } 513 }
515 514
516 515
(...skipping 29 matching lines...) Expand all
546 } 545 }
547 546
548 547
549 // --- Isolates --- 548 // --- Isolates ---
550 549
551 550
552 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const uint8_t* snapshot, 551 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const uint8_t* snapshot,
553 void* callback_data, 552 void* callback_data,
554 char** error) { 553 char** error) {
555 Isolate* isolate = Dart::CreateIsolate(); 554 Isolate* isolate = Dart::CreateIsolate();
556 ASSERT(isolate != NULL); 555 assert(isolate != NULL);
557 LongJump* base = isolate->long_jump_base(); 556 LongJump* base = isolate->long_jump_base();
558 LongJump jump; 557 LongJump jump;
559 isolate->set_long_jump_base(&jump); 558 isolate->set_long_jump_base(&jump);
560 if (setjmp(*jump.Set()) == 0) { 559 if (setjmp(*jump.Set()) == 0) {
561 Dart::InitializeIsolate(snapshot, callback_data); 560 Dart::InitializeIsolate(snapshot, callback_data);
562 START_TIMER(time_total_runtime); 561 START_TIMER(time_total_runtime);
563 isolate->set_long_jump_base(base); 562 isolate->set_long_jump_base(base);
564 return reinterpret_cast<Dart_Isolate>(isolate); 563 return reinterpret_cast<Dart_Isolate>(isolate);
565 } else { 564 } else {
566 { 565 {
567 DARTSCOPE(isolate); 566 DARTSCOPE_NOCHECKS(isolate);
568 const String& errmsg = 567 const String& errmsg =
569 String::Handle(isolate->object_store()->sticky_error()); 568 String::Handle(isolate->object_store()->sticky_error());
570 *error = strdup(errmsg.ToCString()); 569 *error = strdup(errmsg.ToCString());
571 } 570 }
572 Dart::ShutdownIsolate(); 571 Dart::ShutdownIsolate();
573 } 572 }
574 return reinterpret_cast<Dart_Isolate>(NULL); 573 return reinterpret_cast<Dart_Isolate>(NULL);
575 } 574 }
576 575
577 576
578 DART_EXPORT void Dart_ShutdownIsolate() { 577 DART_EXPORT void Dart_ShutdownIsolate() {
579 ASSERT(Isolate::Current() != NULL); 578 CHECK_ISOLATE(Isolate::Current());
580 STOP_TIMER(time_total_runtime); 579 STOP_TIMER(time_total_runtime);
581 Dart::ShutdownIsolate(); 580 Dart::ShutdownIsolate();
582 } 581 }
583 582
584 583
585 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { 584 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() {
586 return Api::CastIsolate(Isolate::Current()); 585 return Api::CastIsolate(Isolate::Current());
587 } 586 }
588 587
589 588
590 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate dart_isolate) { 589 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate dart_isolate) {
590 CHECK_NO_ISOLATE(Isolate::Current());
591 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); 591 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate);
592 ASSERT(Isolate::Current() == NULL);
593 Isolate::SetCurrent(isolate); 592 Isolate::SetCurrent(isolate);
594 } 593 }
595 594
596 595
597 DART_EXPORT void Dart_ExitIsolate() { 596 DART_EXPORT void Dart_ExitIsolate() {
598 ASSERT(Isolate::Current() != NULL); 597 CHECK_ISOLATE(Isolate::Current());
599 Isolate::SetCurrent(NULL); 598 Isolate::SetCurrent(NULL);
600 } 599 }
601 600
602 601
603 static uint8_t* ApiAllocator(uint8_t* ptr, 602 static uint8_t* ApiAllocator(uint8_t* ptr,
604 intptr_t old_size, 603 intptr_t old_size,
605 intptr_t new_size) { 604 intptr_t new_size) {
606 uword new_ptr = Api::Reallocate(reinterpret_cast<uword>(ptr), 605 uword new_ptr = Api::Reallocate(reinterpret_cast<uword>(ptr),
607 old_size, 606 old_size,
608 new_size); 607 new_size);
(...skipping 22 matching lines...) Expand all
631 } 630 }
632 631
633 632
634 // --- Messages and Ports --- 633 // --- Messages and Ports ---
635 634
636 635
637 DART_EXPORT void Dart_SetMessageCallbacks( 636 DART_EXPORT void Dart_SetMessageCallbacks(
638 Dart_PostMessageCallback post_message_callback, 637 Dart_PostMessageCallback post_message_callback,
639 Dart_ClosePortCallback close_port_callback) { 638 Dart_ClosePortCallback close_port_callback) {
640 Isolate* isolate = Isolate::Current(); 639 Isolate* isolate = Isolate::Current();
641 ASSERT(isolate != NULL); 640 CHECK_ISOLATE(isolate);
642 ASSERT(post_message_callback != NULL); 641 ASSERT(post_message_callback != NULL);
643 ASSERT(close_port_callback != NULL); 642 ASSERT(close_port_callback != NULL);
644 isolate->set_post_message_callback(post_message_callback); 643 isolate->set_post_message_callback(post_message_callback);
645 isolate->set_close_port_callback(close_port_callback); 644 isolate->set_close_port_callback(close_port_callback);
646 } 645 }
647 646
648 647
649 static RawInstance* DeserializeMessage(void* data) { 648 static RawInstance* DeserializeMessage(void* data) {
650 // Create a snapshot object using the buffer. 649 // Create a snapshot object using the buffer.
651 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); 650 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 MessageWriter writer(&buffer, &allocator); 732 MessageWriter writer(&buffer, &allocator);
734 733
735 writer.WriteMessage(len, data); 734 writer.WriteMessage(len, data);
736 735
737 // Post the message at the given port. 736 // Post the message at the given port.
738 return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(buffer)); 737 return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(buffer));
739 } 738 }
740 739
741 740
742 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { 741 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) {
743 DARTSCOPE(Isolate::Current()); 742 Isolate* isolate = Isolate::Current();
743 CHECK_ISOLATE(isolate);
744 DARTSCOPE_NOCHECKS(isolate);
744 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); 745 const Object& object = Object::Handle(Api::UnwrapHandle(handle));
745 uint8_t* data = NULL; 746 uint8_t* data = NULL;
746 SnapshotWriter writer(false, &data, &allocator); 747 SnapshotWriter writer(false, &data, &allocator);
747 writer.WriteObject(object.raw()); 748 writer.WriteObject(object.raw());
748 writer.FinalizeBuffer(); 749 writer.FinalizeBuffer();
749 return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(data)); 750 return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(data));
750 } 751 }
751 752
752 753
753 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { 754 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 GrowableArray<const Object*> arguments(kNumArguments); 794 GrowableArray<const Object*> arguments(kNumArguments);
794 arguments.Add(&Integer::Handle(Integer::New(port_id))); 795 arguments.Add(&Integer::Handle(Integer::New(port_id)));
795 Dart_Handle result; 796 Dart_Handle result;
796 InvokeStatic(isolate, function, arguments, &result); 797 InvokeStatic(isolate, function, arguments, &result);
797 return result; 798 return result;
798 } 799 }
799 800
800 801
801 DART_EXPORT Dart_Port Dart_GetMainPortId() { 802 DART_EXPORT Dart_Port Dart_GetMainPortId() {
802 Isolate* isolate = Isolate::Current(); 803 Isolate* isolate = Isolate::Current();
803 ASSERT(isolate); 804 CHECK_ISOLATE(isolate);
804 return isolate->main_port(); 805 return isolate->main_port();
805 } 806 }
806 807
807 // --- Scopes ---- 808 // --- Scopes ----
808 809
809 810
810 DART_EXPORT void Dart_EnterScope() { 811 DART_EXPORT void Dart_EnterScope() {
811 Isolate* isolate = Isolate::Current(); 812 Isolate* isolate = Isolate::Current();
812 ASSERT(isolate != NULL); 813 CHECK_ISOLATE(isolate);
813 ApiState* state = isolate->api_state(); 814 ApiState* state = isolate->api_state();
814 ASSERT(state != NULL); 815 ASSERT(state != NULL);
815 ApiLocalScope* new_scope = new ApiLocalScope(state->top_scope(), 816 ApiLocalScope* new_scope = new ApiLocalScope(state->top_scope(),
816 reinterpret_cast<uword>(&state)); 817 reinterpret_cast<uword>(&state));
817 ASSERT(new_scope != NULL); 818 ASSERT(new_scope != NULL);
818 state->set_top_scope(new_scope); // New scope is now the top scope. 819 state->set_top_scope(new_scope); // New scope is now the top scope.
819 } 820 }
820 821
821 822
822 DART_EXPORT void Dart_ExitScope() { 823 DART_EXPORT void Dart_ExitScope() {
823 Isolate* isolate = Isolate::Current(); 824 Isolate* isolate = Isolate::Current();
824 ASSERT(isolate != NULL); 825 CHECK_ISOLATE_SCOPE(isolate);
825 ApiState* state = isolate->api_state(); 826 ApiState* state = isolate->api_state();
826 ASSERT(state != NULL);
827 ApiLocalScope* scope = state->top_scope(); 827 ApiLocalScope* scope = state->top_scope();
828 ASSERT(scope != NULL); 828
829 state->set_top_scope(scope->previous()); // Reset top scope to previous. 829 state->set_top_scope(scope->previous()); // Reset top scope to previous.
830 delete scope; // Free up the old scope which we have just exited. 830 delete scope; // Free up the old scope which we have just exited.
831 } 831 }
832 832
833 833
834 // --- Objects ---- 834 // --- Objects ----
835 835
836 836
837 DART_EXPORT Dart_Handle Dart_Null() { 837 DART_EXPORT Dart_Handle Dart_Null() {
838 CHECK_ISOLATE_SCOPE(Isolate::Current());
838 return Api::Null(); 839 return Api::Null();
839 } 840 }
840 841
841 842
842 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { 843 DART_EXPORT bool Dart_IsNull(Dart_Handle object) {
843 DARTSCOPE(Isolate::Current()); 844 DARTSCOPE(Isolate::Current());
844 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 845 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
845 return obj.IsNull(); 846 return obj.IsNull();
846 } 847 }
847 848
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 return Api::Success(); 990 return Api::Success();
990 } 991 }
991 return Api::Error("Object is not a Integer"); 992 return Api::Error("Object is not a Integer");
992 } 993 }
993 994
994 995
995 // --- Booleans ---- 996 // --- Booleans ----
996 997
997 998
998 DART_EXPORT Dart_Handle Dart_True() { 999 DART_EXPORT Dart_Handle Dart_True() {
1000 CHECK_ISOLATE_SCOPE(Isolate::Current());
999 return Api::True(); 1001 return Api::True();
1000 } 1002 }
1001 1003
1002 1004
1003 DART_EXPORT Dart_Handle Dart_False() { 1005 DART_EXPORT Dart_Handle Dart_False() {
1006 CHECK_ISOLATE_SCOPE(Isolate::Current());
1004 return Api::False(); 1007 return Api::False();
1005 } 1008 }
1006 1009
1007 1010
1008 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { 1011 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) {
1009 DARTSCOPE(Isolate::Current()); 1012 DARTSCOPE(Isolate::Current());
1010 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1013 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1011 return obj.IsBool(); 1014 return obj.IsBool();
1012 } 1015 }
1013 1016
1014 1017
1015 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { 1018 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) {
1019 CHECK_ISOLATE_SCOPE(Isolate::Current());
1016 return value ? Api::True() : Api::False(); 1020 return value ? Api::True() : Api::False();
1017 } 1021 }
1018 1022
1019 1023
1020 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object, 1024 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object,
1021 bool* value) { 1025 bool* value) {
1022 DARTSCOPE(Isolate::Current()); 1026 DARTSCOPE(Isolate::Current());
1023 const Object& obj = Object::Handle(Api::UnwrapHandle(bool_object)); 1027 const Object& obj = Object::Handle(Api::UnwrapHandle(bool_object));
1024 if (obj.IsBool()) { 1028 if (obj.IsBool()) {
1025 Bool& bool_obj = Bool::Handle(); 1029 Bool& bool_obj = Bool::Handle();
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 ASSERT(state != NULL); 2053 ASSERT(state != NULL);
2050 state->UnwindScopes(isolate->top_exit_frame_info()); 2054 state->UnwindScopes(isolate->top_exit_frame_info());
2051 Exceptions::Throw(excp); 2055 Exceptions::Throw(excp);
2052 return Api::Error("Exception was not thrown, internal error"); 2056 return Api::Error("Exception was not thrown, internal error");
2053 } 2057 }
2054 2058
2055 2059
2056 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, 2060 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
2057 Dart_Handle stacktrace) { 2061 Dart_Handle stacktrace) {
2058 Isolate* isolate = Isolate::Current(); 2062 Isolate* isolate = Isolate::Current();
2059 ASSERT(isolate != NULL); 2063 CHECK_ISOLATE(isolate);
2060 if (isolate->top_exit_frame_info() == 0) { 2064 if (isolate->top_exit_frame_info() == 0) {
2061 // There are no dart frames on the stack so it would be illegal to 2065 // There are no dart frames on the stack so it would be illegal to
2062 // throw an exception here. 2066 // throw an exception here.
2063 return Api::Error("No Dart frames on stack, cannot throw exception"); 2067 return Api::Error("No Dart frames on stack, cannot throw exception");
2064 } 2068 }
2065 DARTSCOPE(isolate); 2069 DARTSCOPE(isolate);
2066 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); 2070 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception));
2067 const Instance& stk = Instance::CheckedHandle(Api::UnwrapHandle(stacktrace)); 2071 const Instance& stk = Instance::CheckedHandle(Api::UnwrapHandle(stacktrace));
2068 // Unwind all the API scopes till the exit frame before throwing an 2072 // Unwind all the API scopes till the exit frame before throwing an
2069 // exception. 2073 // exception.
(...skipping 11 matching lines...) Expand all
2081 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, 2085 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args,
2082 int index) { 2086 int index) {
2083 DARTSCOPE(Isolate::Current()); 2087 DARTSCOPE(Isolate::Current());
2084 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 2088 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
2085 const Object& obj = Object::Handle(arguments->At(index)); 2089 const Object& obj = Object::Handle(arguments->At(index));
2086 return Api::NewLocalHandle(obj); 2090 return Api::NewLocalHandle(obj);
2087 } 2091 }
2088 2092
2089 2093
2090 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { 2094 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) {
2095 CHECK_ISOLATE(Isolate::Current());
2091 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 2096 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
2092 return arguments->Count(); 2097 return arguments->Count();
2093 } 2098 }
2094 2099
2095 2100
2096 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, 2101 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args,
2097 Dart_Handle retval) { 2102 Dart_Handle retval) {
2098 DARTSCOPE(Isolate::Current()); 2103 DARTSCOPE(Isolate::Current());
2099 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 2104 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
2100 arguments->SetReturn(Object::Handle(Api::UnwrapHandle(retval))); 2105 arguments->SetReturn(Object::Handle(Api::UnwrapHandle(retval)));
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 } 2377 }
2373 delete debug_region; 2378 delete debug_region;
2374 } else { 2379 } else {
2375 *buffer = NULL; 2380 *buffer = NULL;
2376 *buffer_size = 0; 2381 *buffer_size = 0;
2377 } 2382 }
2378 } 2383 }
2379 2384
2380 2385
2381 } // namespace dart 2386 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698