OLD | NEW |
---|---|
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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 #include "vm/tags.h" | 38 #include "vm/tags.h" |
39 #include "vm/thread_registry.h" | 39 #include "vm/thread_registry.h" |
40 #include "vm/timeline.h" | 40 #include "vm/timeline.h" |
41 #include "vm/timer.h" | 41 #include "vm/timer.h" |
42 #include "vm/unicode.h" | 42 #include "vm/unicode.h" |
43 #include "vm/verifier.h" | 43 #include "vm/verifier.h" |
44 #include "vm/version.h" | 44 #include "vm/version.h" |
45 | 45 |
46 namespace dart { | 46 namespace dart { |
47 | 47 |
48 // Facilitate quick access to the current zone once we have the curren thread. | |
49 #define Z (T->zone()) | |
50 | |
51 | |
48 DECLARE_FLAG(bool, load_deferred_eagerly); | 52 DECLARE_FLAG(bool, load_deferred_eagerly); |
49 DECLARE_FLAG(bool, print_class_table); | 53 DECLARE_FLAG(bool, print_class_table); |
50 DECLARE_FLAG(bool, verify_handles); | 54 DECLARE_FLAG(bool, verify_handles); |
51 #if defined(DART_NO_SNAPSHOT) | 55 #if defined(DART_NO_SNAPSHOT) |
52 DEFINE_FLAG(bool, check_function_fingerprints, true, | 56 DEFINE_FLAG(bool, check_function_fingerprints, true, |
53 "Check function fingerprints"); | 57 "Check function fingerprints"); |
54 #endif // defined(DART_NO_SNAPSHOT). | 58 #endif // defined(DART_NO_SNAPSHOT). |
55 DEFINE_FLAG(bool, trace_api, false, | 59 DEFINE_FLAG(bool, trace_api, false, |
56 "Trace invocation of API calls (debug mode only)"); | 60 "Trace invocation of API calls (debug mode only)"); |
57 DEFINE_FLAG(bool, verify_acquired_data, false, | 61 DEFINE_FLAG(bool, verify_acquired_data, false, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 } | 113 } |
110 | 114 |
111 private: | 115 private: |
112 Class& classHandle_; | 116 Class& classHandle_; |
113 Function& funcHandle_; | 117 Function& funcHandle_; |
114 AbstractType& typeHandle_; | 118 AbstractType& typeHandle_; |
115 }; | 119 }; |
116 #endif // #if defined(DEBUG). | 120 #endif // #if defined(DEBUG). |
117 | 121 |
118 | 122 |
119 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { | 123 static RawInstance* GetListInstance(Zone* zone, const Object& obj) { |
120 if (obj.IsInstance()) { | 124 if (obj.IsInstance()) { |
121 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 125 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); |
122 const Class& list_class = | 126 const Class& list_class = |
123 Class::Handle(core_lib.LookupClass(Symbols::List())); | 127 Class::Handle(zone, core_lib.LookupClass(Symbols::List())); |
124 ASSERT(!list_class.IsNull()); | 128 ASSERT(!list_class.IsNull()); |
125 const Instance& instance = Instance::Cast(obj); | 129 const Instance& instance = Instance::Cast(obj); |
126 const Class& obj_class = Class::Handle(isolate, obj.clazz()); | 130 const Class& obj_class = Class::Handle(zone, obj.clazz()); |
127 Error& malformed_type_error = Error::Handle(isolate); | 131 Error& malformed_type_error = Error::Handle(zone); |
128 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), | 132 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), |
129 list_class, | 133 list_class, |
130 Object::null_type_arguments(), | 134 Object::null_type_arguments(), |
131 &malformed_type_error)) { | 135 &malformed_type_error)) { |
132 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. | 136 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. |
133 return instance.raw(); | 137 return instance.raw(); |
134 } | 138 } |
135 } | 139 } |
136 return Instance::null(); | 140 return Instance::null(); |
137 } | 141 } |
138 | 142 |
139 static RawInstance* GetMapInstance(Isolate* isolate, const Object& obj) { | 143 static RawInstance* GetMapInstance(Zone* zone, const Object& obj) { |
140 if (obj.IsInstance()) { | 144 if (obj.IsInstance()) { |
141 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 145 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); |
142 const Class& map_class = | 146 const Class& map_class = |
143 Class::Handle(core_lib.LookupClass(Symbols::Map())); | 147 Class::Handle(core_lib.LookupClass(Symbols::Map())); |
144 ASSERT(!map_class.IsNull()); | 148 ASSERT(!map_class.IsNull()); |
145 const Instance& instance = Instance::Cast(obj); | 149 const Instance& instance = Instance::Cast(obj); |
146 const Class& obj_class = Class::Handle(isolate, obj.clazz()); | 150 const Class& obj_class = Class::Handle(zone, obj.clazz()); |
147 Error& malformed_type_error = Error::Handle(isolate); | 151 Error& malformed_type_error = Error::Handle(zone); |
148 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), | 152 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), |
149 map_class, | 153 map_class, |
150 Object::null_type_arguments(), | 154 Object::null_type_arguments(), |
151 &malformed_type_error)) { | 155 &malformed_type_error)) { |
152 ASSERT(malformed_type_error.IsNull()); // Type is a raw Map. | 156 ASSERT(malformed_type_error.IsNull()); // Type is a raw Map. |
153 return instance.raw(); | 157 return instance.raw(); |
154 } | 158 } |
155 } | 159 } |
156 return Instance::null(); | 160 return Instance::null(); |
157 } | 161 } |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); | 440 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); |
437 } | 441 } |
438 | 442 |
439 | 443 |
440 Dart_Isolate Api::CastIsolate(Isolate* isolate) { | 444 Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
441 return reinterpret_cast<Dart_Isolate>(isolate); | 445 return reinterpret_cast<Dart_Isolate>(isolate); |
442 } | 446 } |
443 | 447 |
444 | 448 |
445 Dart_Handle Api::NewError(const char* format, ...) { | 449 Dart_Handle Api::NewError(const char* format, ...) { |
446 Thread* thread = Thread::Current(); | 450 DARTSCOPE(Thread::Current()); |
447 Isolate* isolate = thread->isolate(); | 451 CHECK_CALLBACK_STATE(I); |
448 Zone* zone = thread->zone(); | |
449 DARTSCOPE(isolate); | |
450 CHECK_CALLBACK_STATE(isolate); | |
451 | 452 |
452 va_list args; | 453 va_list args; |
453 va_start(args, format); | 454 va_start(args, format); |
454 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 455 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
455 va_end(args); | 456 va_end(args); |
456 | 457 |
457 char* buffer = zone->Alloc<char>(len + 1); | 458 char* buffer = Z->Alloc<char>(len + 1); |
458 va_list args2; | 459 va_list args2; |
459 va_start(args2, format); | 460 va_start(args2, format); |
460 OS::VSNPrint(buffer, (len + 1), format, args2); | 461 OS::VSNPrint(buffer, (len + 1), format, args2); |
461 va_end(args2); | 462 va_end(args2); |
462 | 463 |
463 const String& message = String::Handle(zone, String::New(buffer)); | 464 const String& message = String::Handle(Z, String::New(buffer)); |
464 return Api::NewHandle(isolate, ApiError::New(message)); | 465 return Api::NewHandle(I, ApiError::New(message)); |
465 } | 466 } |
466 | 467 |
467 | 468 |
468 void Api::SetupAcquiredError(Isolate* isolate) { | 469 void Api::SetupAcquiredError(Isolate* isolate) { |
469 ASSERT(isolate != NULL); | 470 ASSERT(isolate != NULL); |
470 ApiState* state = isolate->api_state(); | 471 ApiState* state = isolate->api_state(); |
471 ASSERT(state != NULL); | 472 ASSERT(state != NULL); |
472 state->SetupAcquiredError(); | 473 state->SetupAcquiredError(); |
473 } | 474 } |
474 | 475 |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 } | 739 } |
739 | 740 |
740 | 741 |
741 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { | 742 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { |
742 TRACE_API_CALL(CURRENT_FUNC); | 743 TRACE_API_CALL(CURRENT_FUNC); |
743 return Api::ClassId(object) == kUnwindErrorCid; | 744 return Api::ClassId(object) == kUnwindErrorCid; |
744 } | 745 } |
745 | 746 |
746 | 747 |
747 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 748 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
748 Isolate* isolate = Isolate::Current(); | 749 DARTSCOPE(Thread::Current()); |
749 DARTSCOPE(isolate); | 750 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
750 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | |
751 if (obj.IsError()) { | 751 if (obj.IsError()) { |
752 const Error& error = Error::Cast(obj); | 752 const Error& error = Error::Cast(obj); |
753 const char* str = error.ToErrorCString(); | 753 const char* str = error.ToErrorCString(); |
754 intptr_t len = strlen(str) + 1; | 754 intptr_t len = strlen(str) + 1; |
755 char* str_copy = Api::TopScope(isolate)->zone()->Alloc<char>(len); | 755 char* str_copy = Api::TopScope(I)->zone()->Alloc<char>(len); |
756 strncpy(str_copy, str, len); | 756 strncpy(str_copy, str, len); |
757 // Strip a possible trailing '\n'. | 757 // Strip a possible trailing '\n'. |
758 if ((len > 1) && (str_copy[len - 2] == '\n')) { | 758 if ((len > 1) && (str_copy[len - 2] == '\n')) { |
759 str_copy[len - 2] = '\0'; | 759 str_copy[len - 2] = '\0'; |
760 } | 760 } |
761 return str_copy; | 761 return str_copy; |
762 } else { | 762 } else { |
763 return ""; | 763 return ""; |
764 } | 764 } |
765 } | 765 } |
766 | 766 |
767 | 767 |
768 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { | 768 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { |
769 Isolate* isolate = Isolate::Current(); | 769 DARTSCOPE(Thread::Current()); |
770 DARTSCOPE(isolate); | 770 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
771 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | |
772 return obj.IsUnhandledException(); | 771 return obj.IsUnhandledException(); |
773 } | 772 } |
774 | 773 |
775 | 774 |
776 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { | 775 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { |
777 Isolate* isolate = Isolate::Current(); | 776 DARTSCOPE(Thread::Current()); |
778 DARTSCOPE(isolate); | 777 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
779 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | |
780 if (obj.IsUnhandledException()) { | 778 if (obj.IsUnhandledException()) { |
781 const UnhandledException& error = UnhandledException::Cast(obj); | 779 const UnhandledException& error = UnhandledException::Cast(obj); |
782 return Api::NewHandle(isolate, error.exception()); | 780 return Api::NewHandle(I, error.exception()); |
783 } else if (obj.IsError()) { | 781 } else if (obj.IsError()) { |
784 return Api::NewError("This error is not an unhandled exception error."); | 782 return Api::NewError("This error is not an unhandled exception error."); |
785 } else { | 783 } else { |
786 return Api::NewError("Can only get exceptions from error handles."); | 784 return Api::NewError("Can only get exceptions from error handles."); |
787 } | 785 } |
788 } | 786 } |
789 | 787 |
790 | 788 |
791 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { | 789 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { |
792 Isolate* isolate = Isolate::Current(); | 790 DARTSCOPE(Thread::Current()); |
793 DARTSCOPE(isolate); | 791 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
794 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | |
795 if (obj.IsUnhandledException()) { | 792 if (obj.IsUnhandledException()) { |
796 const UnhandledException& error = UnhandledException::Cast(obj); | 793 const UnhandledException& error = UnhandledException::Cast(obj); |
797 return Api::NewHandle(isolate, error.stacktrace()); | 794 return Api::NewHandle(I, error.stacktrace()); |
798 } else if (obj.IsError()) { | 795 } else if (obj.IsError()) { |
799 return Api::NewError("This error is not an unhandled exception error."); | 796 return Api::NewError("This error is not an unhandled exception error."); |
800 } else { | 797 } else { |
801 return Api::NewError("Can only get stacktraces from error handles."); | 798 return Api::NewError("Can only get stacktraces from error handles."); |
802 } | 799 } |
803 } | 800 } |
804 | 801 |
805 | 802 |
806 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 803 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
807 // fix this but not sure if it available on all of our builds. | 804 // fix this but not sure if it available on all of our builds. |
808 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { | 805 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { |
809 Isolate* isolate = Isolate::Current(); | 806 DARTSCOPE(Thread::Current()); |
810 DARTSCOPE(isolate); | 807 CHECK_CALLBACK_STATE(I); |
811 CHECK_CALLBACK_STATE(isolate); | |
812 | 808 |
813 const String& message = String::Handle(isolate, String::New(error)); | 809 const String& message = String::Handle(Z, String::New(error)); |
814 return Api::NewHandle(isolate, ApiError::New(message)); | 810 return Api::NewHandle(I, ApiError::New(message)); |
815 } | 811 } |
816 | 812 |
817 | 813 |
818 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { | 814 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { |
819 Isolate* isolate = Isolate::Current(); | 815 DARTSCOPE(Thread::Current()); |
820 DARTSCOPE(isolate); | 816 CHECK_CALLBACK_STATE(I); |
821 CHECK_CALLBACK_STATE(isolate); | |
822 | 817 |
823 Instance& obj = Instance::Handle(isolate); | 818 Instance& obj = Instance::Handle(Z); |
824 intptr_t class_id = Api::ClassId(exception); | 819 intptr_t class_id = Api::ClassId(exception); |
825 if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) { | 820 if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) { |
826 obj = String::New(::Dart_GetError(exception)); | 821 obj = String::New(::Dart_GetError(exception)); |
827 } else { | 822 } else { |
828 obj = Api::UnwrapInstanceHandle(isolate, exception).raw(); | 823 obj = Api::UnwrapInstanceHandle(I, exception).raw(); |
829 if (obj.IsNull()) { | 824 if (obj.IsNull()) { |
830 RETURN_TYPE_ERROR(isolate, exception, Instance); | 825 RETURN_TYPE_ERROR(I, exception, Instance); |
831 } | 826 } |
832 } | 827 } |
833 const Stacktrace& stacktrace = Stacktrace::Handle(isolate); | 828 const Stacktrace& stacktrace = Stacktrace::Handle(Z); |
834 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); | 829 return Api::NewHandle(I, UnhandledException::New(obj, stacktrace)); |
835 } | 830 } |
836 | 831 |
837 | 832 |
838 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 833 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
839 Isolate* isolate = Isolate::Current(); | 834 Isolate* isolate = Isolate::Current(); |
840 { | 835 { |
841 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 836 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
842 if (!obj.IsError()) { | 837 if (!obj.IsError()) { |
843 return Api::NewError( | 838 return Api::NewError( |
844 "%s expects argument 'handle' to be an error handle. " | 839 "%s expects argument 'handle' to be an error handle. " |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
876 int line, | 871 int line, |
877 const char* handle, | 872 const char* handle, |
878 const char* message) { | 873 const char* message) { |
879 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", | 874 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", |
880 file, line, handle, message); | 875 file, line, handle, message); |
881 OS::Abort(); | 876 OS::Abort(); |
882 } | 877 } |
883 | 878 |
884 | 879 |
885 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { | 880 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
886 Isolate* isolate = Isolate::Current(); | 881 DARTSCOPE(Thread::Current()); |
887 DARTSCOPE(isolate); | 882 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
888 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
889 if (obj.IsString()) { | 883 if (obj.IsString()) { |
890 return Api::NewHandle(isolate, obj.raw()); | 884 return Api::NewHandle(I, obj.raw()); |
891 } else if (obj.IsInstance()) { | 885 } else if (obj.IsInstance()) { |
892 CHECK_CALLBACK_STATE(isolate); | 886 CHECK_CALLBACK_STATE(I); |
893 const Instance& receiver = Instance::Cast(obj); | 887 const Instance& receiver = Instance::Cast(obj); |
894 return Api::NewHandle(isolate, DartLibraryCalls::ToString(receiver)); | 888 return Api::NewHandle(I, DartLibraryCalls::ToString(receiver)); |
895 } else { | 889 } else { |
896 CHECK_CALLBACK_STATE(isolate); | 890 CHECK_CALLBACK_STATE(I); |
897 // This is a VM internal object. Call the C++ method of printing. | 891 // This is a VM internal object. Call the C++ method of printing. |
898 return Api::NewHandle(isolate, String::New(obj.ToCString())); | 892 return Api::NewHandle(I, String::New(obj.ToCString())); |
899 } | 893 } |
900 } | 894 } |
901 | 895 |
902 | 896 |
903 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { | 897 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { |
904 Isolate* isolate = Isolate::Current(); | 898 DARTSCOPE(Thread::Current()); |
905 DARTSCOPE(isolate); | |
906 { | 899 { |
907 NoSafepointScope no_safepoint_scope; | 900 NoSafepointScope no_safepoint_scope; |
908 if (Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2)) { | 901 if (Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2)) { |
909 return true; | 902 return true; |
910 } | 903 } |
911 } | 904 } |
912 const Object& object1 = Object::Handle(isolate, Api::UnwrapHandle(obj1)); | 905 const Object& object1 = Object::Handle(Z, Api::UnwrapHandle(obj1)); |
913 const Object& object2 = Object::Handle(isolate, Api::UnwrapHandle(obj2)); | 906 const Object& object2 = Object::Handle(Z, Api::UnwrapHandle(obj2)); |
914 if (object1.IsInstance() && object2.IsInstance()) { | 907 if (object1.IsInstance() && object2.IsInstance()) { |
915 return Instance::Cast(object1).IsIdenticalTo(Instance::Cast(object2)); | 908 return Instance::Cast(object1).IsIdenticalTo(Instance::Cast(object2)); |
916 } | 909 } |
917 return false; | 910 return false; |
918 } | 911 } |
919 | 912 |
920 | 913 |
921 DART_EXPORT uint64_t Dart_IdentityHash(Dart_Handle obj) { | 914 DART_EXPORT uint64_t Dart_IdentityHash(Dart_Handle obj) { |
922 Isolate* isolate = Isolate::Current(); | 915 DARTSCOPE(Thread::Current()); |
923 DARTSCOPE(isolate); | |
924 | 916 |
925 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(obj)); | 917 const Object& object = Object::Handle(Z, Api::UnwrapHandle(obj)); |
926 if (!object.IsInstance() && !object.IsNull()) { | 918 if (!object.IsInstance() && !object.IsNull()) { |
927 return 0; | 919 return 0; |
928 } | 920 } |
929 | 921 |
930 const Library& libcore = Library::Handle(isolate, Library::CoreLibrary()); | 922 const Library& libcore = Library::Handle(Z, Library::CoreLibrary()); |
931 const String& function_name = String::Handle(isolate, | 923 const String& function_name = String::Handle(Z, |
932 String::New("identityHashCode")); | 924 String::New("identityHashCode")); |
933 const Function& function = | 925 const Function& function = |
934 Function::Handle(isolate, | 926 Function::Handle(Z, libcore.LookupFunctionAllowPrivate(function_name)); |
935 libcore.LookupFunctionAllowPrivate(function_name)); | |
936 if (function.IsNull()) { | 927 if (function.IsNull()) { |
937 UNREACHABLE(); | 928 UNREACHABLE(); |
938 return 0; | 929 return 0; |
939 } | 930 } |
940 | 931 |
941 const Array& arguments = Array::Handle(isolate, Array::New(1)); | 932 const Array& arguments = Array::Handle(Z, Array::New(1)); |
942 arguments.SetAt(0, object); | 933 arguments.SetAt(0, object); |
943 const Object& result = | 934 const Object& result = |
944 Object::Handle(isolate, DartEntry::InvokeFunction(function, arguments)); | 935 Object::Handle(Z, DartEntry::InvokeFunction(function, arguments)); |
945 | 936 |
946 if (result.IsSmi()) { | 937 if (result.IsSmi()) { |
947 return Smi::Cast(result).Value(); | 938 return Smi::Cast(result).Value(); |
948 } | 939 } |
949 if (result.IsMint()) { | 940 if (result.IsMint()) { |
950 const Mint& mint = Mint::Cast(result); | 941 const Mint& mint = Mint::Cast(result); |
951 if (!mint.IsNegative()) { | 942 if (!mint.IsNegative()) { |
952 return mint.AsInt64Value(); | 943 return mint.AsInt64Value(); |
953 } | 944 } |
954 } | 945 } |
(...skipping 24 matching lines...) Expand all Loading... | |
979 CHECK_ISOLATE(isolate); | 970 CHECK_ISOLATE(isolate); |
980 ApiState* state = isolate->api_state(); | 971 ApiState* state = isolate->api_state(); |
981 ASSERT(state != NULL); | 972 ASSERT(state != NULL); |
982 FinalizablePersistentHandle* weak_ref = | 973 FinalizablePersistentHandle* weak_ref = |
983 FinalizablePersistentHandle::Cast(object); | 974 FinalizablePersistentHandle::Cast(object); |
984 return Api::NewHandle(isolate, weak_ref->raw()); | 975 return Api::NewHandle(isolate, weak_ref->raw()); |
985 } | 976 } |
986 | 977 |
987 | 978 |
988 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { | 979 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { |
989 Isolate* isolate = Isolate::Current(); | 980 DARTSCOPE(Thread::Current()); |
990 DARTSCOPE(isolate); | 981 ApiState* state = I->api_state(); |
991 ApiState* state = isolate->api_state(); | |
992 ASSERT(state != NULL); | 982 ASSERT(state != NULL); |
993 const Object& old_ref = Object::Handle(isolate, Api::UnwrapHandle(object)); | 983 const Object& old_ref = Object::Handle(Z, Api::UnwrapHandle(object)); |
994 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); | 984 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); |
995 new_ref->set_raw(old_ref); | 985 new_ref->set_raw(old_ref); |
996 return new_ref->apiHandle(); | 986 return new_ref->apiHandle(); |
997 } | 987 } |
998 | 988 |
999 | 989 |
1000 DART_EXPORT void Dart_SetPersistentHandle(Dart_PersistentHandle obj1, | 990 DART_EXPORT void Dart_SetPersistentHandle(Dart_PersistentHandle obj1, |
1001 Dart_Handle obj2) { | 991 Dart_Handle obj2) { |
1002 Isolate* isolate = Isolate::Current(); | 992 DARTSCOPE(Thread::Current()); |
1003 DARTSCOPE(isolate); | 993 ApiState* state = I->api_state(); |
1004 ApiState* state = isolate->api_state(); | |
1005 ASSERT(state != NULL); | 994 ASSERT(state != NULL); |
1006 ASSERT(state->IsValidPersistentHandle(obj1)); | 995 ASSERT(state->IsValidPersistentHandle(obj1)); |
1007 const Object& obj2_ref = Object::Handle(isolate, Api::UnwrapHandle(obj2)); | 996 const Object& obj2_ref = Object::Handle(Z, Api::UnwrapHandle(obj2)); |
1008 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1); | 997 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1); |
1009 obj1_ref->set_raw(obj2_ref); | 998 obj1_ref->set_raw(obj2_ref); |
1010 } | 999 } |
1011 | 1000 |
1012 | 1001 |
1013 static Dart_WeakPersistentHandle AllocateFinalizableHandle( | 1002 static Dart_WeakPersistentHandle AllocateFinalizableHandle( |
1014 Isolate* isolate, | 1003 Isolate* isolate, |
1015 Dart_Handle object, | 1004 Dart_Handle object, |
1016 bool is_prologue, | 1005 bool is_prologue, |
1017 void* peer, | 1006 void* peer, |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1361 // Setup default flags in case none were passed. | 1350 // Setup default flags in case none were passed. |
1362 Dart_IsolateFlags api_flags; | 1351 Dart_IsolateFlags api_flags; |
1363 if (flags == NULL) { | 1352 if (flags == NULL) { |
1364 Isolate::Flags vm_flags; | 1353 Isolate::Flags vm_flags; |
1365 vm_flags.CopyTo(&api_flags); | 1354 vm_flags.CopyTo(&api_flags); |
1366 flags = &api_flags; | 1355 flags = &api_flags; |
1367 } | 1356 } |
1368 Isolate* isolate = Dart::CreateIsolate(isolate_name, *flags); | 1357 Isolate* isolate = Dart::CreateIsolate(isolate_name, *flags); |
1369 free(isolate_name); | 1358 free(isolate_name); |
1370 { | 1359 { |
1371 StackZone zone(isolate); | 1360 Thread* thread = Thread::Current(); |
siva
2015/09/01 23:38:16
Would it be uniform to name this variable T
Thread
Ivan Posva
2015/09/02 00:03:33
Done + renamed isolate->I.
| |
1372 HANDLESCOPE(isolate); | 1361 StackZone zone(thread); |
1362 HANDLESCOPE(thread); | |
1373 // We enter an API scope here as InitializeIsolate could compile some | 1363 // We enter an API scope here as InitializeIsolate could compile some |
1374 // bootstrap library files which call out to a tag handler that may create | 1364 // bootstrap library files which call out to a tag handler that may create |
1375 // Api Handles when an error is encountered. | 1365 // Api Handles when an error is encountered. |
1376 Dart_EnterScope(); | 1366 Dart_EnterScope(); |
1377 const Error& error_obj = | 1367 const Error& error_obj = |
1378 Error::Handle(isolate, | 1368 Error::Handle(thread->zone(), |
1379 Dart::InitializeIsolate(snapshot, callback_data)); | 1369 Dart::InitializeIsolate(snapshot, callback_data)); |
1380 if (error_obj.IsNull()) { | 1370 if (error_obj.IsNull()) { |
1381 #if defined(DART_NO_SNAPSHOT) | 1371 #if defined(DART_NO_SNAPSHOT) |
1382 if (FLAG_check_function_fingerprints) { | 1372 if (FLAG_check_function_fingerprints) { |
1383 Library::CheckFunctionFingerprints(); | 1373 Library::CheckFunctionFingerprints(); |
1384 } | 1374 } |
1385 #endif // defined(DART_NO_SNAPSHOT). | 1375 #endif // defined(DART_NO_SNAPSHOT). |
1386 // We exit the API scope entered above. | 1376 // We exit the API scope entered above. |
1387 Dart_ExitScope(); | 1377 Dart_ExitScope(); |
1388 START_TIMER(isolate, time_total_runtime); | 1378 START_TIMER(isolate, time_total_runtime); |
1389 return Api::CastIsolate(isolate); | 1379 return Api::CastIsolate(isolate); |
1390 } | 1380 } |
1391 *error = strdup(error_obj.ToErrorCString()); | 1381 *error = strdup(error_obj.ToErrorCString()); |
1392 // We exit the API scope entered above. | 1382 // We exit the API scope entered above. |
1393 Dart_ExitScope(); | 1383 Dart_ExitScope(); |
1394 } | 1384 } |
1395 Dart::ShutdownIsolate(); | 1385 Dart::ShutdownIsolate(); |
1396 return reinterpret_cast<Dart_Isolate>(NULL); | 1386 return reinterpret_cast<Dart_Isolate>(NULL); |
1397 } | 1387 } |
1398 | 1388 |
1399 | 1389 |
1400 DART_EXPORT void Dart_ShutdownIsolate() { | 1390 DART_EXPORT void Dart_ShutdownIsolate() { |
1401 Isolate* isolate = Isolate::Current(); | 1391 Thread* thread = Thread::Current(); |
siva
2015/09/01 23:38:16
Ditto.
Ivan Posva
2015/09/02 00:03:33
Done.
| |
1392 Isolate* isolate = thread->isolate(); | |
1402 CHECK_ISOLATE(isolate); | 1393 CHECK_ISOLATE(isolate); |
1403 { | 1394 { |
1404 StackZone zone(isolate); | 1395 StackZone zone(thread); |
1405 HandleScope handle_scope(isolate); | 1396 HandleScope handle_scope(thread); |
1406 Dart::RunShutdownCallback(); | 1397 Dart::RunShutdownCallback(); |
1407 } | 1398 } |
1408 STOP_TIMER(isolate, time_total_runtime); | 1399 STOP_TIMER(isolate, time_total_runtime); |
1409 Dart::ShutdownIsolate(); | 1400 Dart::ShutdownIsolate(); |
1410 } | 1401 } |
1411 | 1402 |
1412 | 1403 |
1413 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { | 1404 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { |
1414 return Api::CastIsolate(Isolate::Current()); | 1405 return Api::CastIsolate(Isolate::Current()); |
1415 } | 1406 } |
(...skipping 11 matching lines...) Expand all Loading... | |
1427 if (isolate == NULL) { | 1418 if (isolate == NULL) { |
1428 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1419 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1429 } | 1420 } |
1430 // TODO(16615): Validate isolate parameter. | 1421 // TODO(16615): Validate isolate parameter. |
1431 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1422 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1432 return iso->init_callback_data(); | 1423 return iso->init_callback_data(); |
1433 } | 1424 } |
1434 | 1425 |
1435 | 1426 |
1436 DART_EXPORT Dart_Handle Dart_DebugName() { | 1427 DART_EXPORT Dart_Handle Dart_DebugName() { |
1437 Isolate* isolate = Isolate::Current(); | 1428 DARTSCOPE(Thread::Current()); |
1438 DARTSCOPE(isolate); | 1429 return Api::NewHandle(I, String::New(I->name())); |
1439 return Api::NewHandle(isolate, String::New(isolate->name())); | |
1440 } | 1430 } |
1441 | 1431 |
1442 | 1432 |
1443 | 1433 |
1444 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { | 1434 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { |
1445 CHECK_NO_ISOLATE(Isolate::Current()); | 1435 CHECK_NO_ISOLATE(Isolate::Current()); |
1446 // TODO(16615): Validate isolate parameter. | 1436 // TODO(16615): Validate isolate parameter. |
1447 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1437 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1448 if (iso->HasMutatorThread()) { | 1438 if (iso->HasMutatorThread()) { |
1449 FATAL("Multiple mutators within one isolate is not supported."); | 1439 FATAL("Multiple mutators within one isolate is not supported."); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1505 ptr, old_size, new_size); | 1495 ptr, old_size, new_size); |
1506 } | 1496 } |
1507 | 1497 |
1508 | 1498 |
1509 DART_EXPORT Dart_Handle Dart_CreateSnapshot( | 1499 DART_EXPORT Dart_Handle Dart_CreateSnapshot( |
1510 uint8_t** vm_isolate_snapshot_buffer, | 1500 uint8_t** vm_isolate_snapshot_buffer, |
1511 intptr_t* vm_isolate_snapshot_size, | 1501 intptr_t* vm_isolate_snapshot_size, |
1512 uint8_t** isolate_snapshot_buffer, | 1502 uint8_t** isolate_snapshot_buffer, |
1513 intptr_t* isolate_snapshot_size) { | 1503 intptr_t* isolate_snapshot_size) { |
1514 ASSERT(FLAG_load_deferred_eagerly); | 1504 ASSERT(FLAG_load_deferred_eagerly); |
1515 Thread* thread = Thread::Current(); | 1505 DARTSCOPE(Thread::Current()); |
1516 Isolate* isolate = thread->isolate(); | 1506 TIMERSCOPE(T, time_creating_snapshot); |
1517 DARTSCOPE(isolate); | |
1518 TIMERSCOPE(thread, time_creating_snapshot); | |
1519 if (vm_isolate_snapshot_buffer != NULL && | 1507 if (vm_isolate_snapshot_buffer != NULL && |
1520 vm_isolate_snapshot_size == NULL) { | 1508 vm_isolate_snapshot_size == NULL) { |
1521 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 1509 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
1522 } | 1510 } |
1523 if (isolate_snapshot_buffer == NULL) { | 1511 if (isolate_snapshot_buffer == NULL) { |
1524 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 1512 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
1525 } | 1513 } |
1526 if (isolate_snapshot_size == NULL) { | 1514 if (isolate_snapshot_size == NULL) { |
1527 RETURN_NULL_ERROR(isolate_snapshot_size); | 1515 RETURN_NULL_ERROR(isolate_snapshot_size); |
1528 } | 1516 } |
1529 // Finalize all classes if needed. | 1517 // Finalize all classes if needed. |
1530 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); | 1518 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); |
1531 if (::Dart_IsError(state)) { | 1519 if (::Dart_IsError(state)) { |
1532 return state; | 1520 return state; |
1533 } | 1521 } |
1534 isolate->heap()->CollectAllGarbage(); | 1522 I->heap()->CollectAllGarbage(); |
1535 #if defined(DEBUG) | 1523 #if defined(DEBUG) |
1536 FunctionVisitor check_canonical(isolate); | 1524 FunctionVisitor check_canonical(I); |
1537 isolate->heap()->IterateObjects(&check_canonical); | 1525 I->heap()->IterateObjects(&check_canonical); |
1538 #endif // #if defined(DEBUG). | 1526 #endif // #if defined(DEBUG). |
1539 | 1527 |
1540 // Since this is only a snapshot the root library should not be set. | 1528 // Since this is only a snapshot the root library should not be set. |
1541 isolate->object_store()->set_root_library(Library::Handle(isolate)); | 1529 I->object_store()->set_root_library(Library::Handle(Z)); |
1542 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, | 1530 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, |
1543 isolate_snapshot_buffer, | 1531 isolate_snapshot_buffer, |
1544 ApiReallocate, | 1532 ApiReallocate, |
1545 false /* snapshot_code */); | 1533 false /* snapshot_code */); |
1546 writer.WriteFullSnapshot(); | 1534 writer.WriteFullSnapshot(); |
1547 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 1535 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
1548 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 1536 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
1549 return Api::Success(); | 1537 return Api::Success(); |
1550 } | 1538 } |
1551 | 1539 |
1552 | 1540 |
1553 static Dart_Handle createLibrarySnapshot(Dart_Handle library, | 1541 static Dart_Handle createLibrarySnapshot(Dart_Handle library, |
1554 uint8_t** buffer, | 1542 uint8_t** buffer, |
1555 intptr_t* size) { | 1543 intptr_t* size) { |
1556 Thread* thread = Thread::Current(); | 1544 DARTSCOPE(Thread::Current()); |
1557 Isolate* isolate = thread->isolate(); | 1545 TIMERSCOPE(T, time_creating_snapshot); |
1558 DARTSCOPE(isolate); | |
1559 TIMERSCOPE(thread, time_creating_snapshot); | |
1560 if (buffer == NULL) { | 1546 if (buffer == NULL) { |
1561 RETURN_NULL_ERROR(buffer); | 1547 RETURN_NULL_ERROR(buffer); |
1562 } | 1548 } |
1563 if (size == NULL) { | 1549 if (size == NULL) { |
1564 RETURN_NULL_ERROR(size); | 1550 RETURN_NULL_ERROR(size); |
1565 } | 1551 } |
1566 // Finalize all classes if needed. | 1552 // Finalize all classes if needed. |
1567 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); | 1553 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); |
1568 if (::Dart_IsError(state)) { | 1554 if (::Dart_IsError(state)) { |
1569 return state; | 1555 return state; |
1570 } | 1556 } |
1571 Library& lib = Library::Handle(isolate); | 1557 Library& lib = Library::Handle(Z); |
1572 if (library == Dart_Null()) { | 1558 if (library == Dart_Null()) { |
1573 lib ^= isolate->object_store()->root_library(); | 1559 lib ^= I->object_store()->root_library(); |
1574 } else { | 1560 } else { |
1575 lib ^= Api::UnwrapHandle(library); | 1561 lib ^= Api::UnwrapHandle(library); |
1576 } | 1562 } |
1577 isolate->heap()->CollectAllGarbage(); | 1563 I->heap()->CollectAllGarbage(); |
1578 #if defined(DEBUG) | 1564 #if defined(DEBUG) |
1579 FunctionVisitor check_canonical(isolate); | 1565 FunctionVisitor check_canonical(I); |
1580 isolate->heap()->IterateObjects(&check_canonical); | 1566 I->heap()->IterateObjects(&check_canonical); |
1581 #endif // #if defined(DEBUG). | 1567 #endif // #if defined(DEBUG). |
1582 ScriptSnapshotWriter writer(buffer, ApiReallocate); | 1568 ScriptSnapshotWriter writer(buffer, ApiReallocate); |
1583 writer.WriteScriptSnapshot(lib); | 1569 writer.WriteScriptSnapshot(lib); |
1584 *size = writer.BytesWritten(); | 1570 *size = writer.BytesWritten(); |
1585 return Api::Success(); | 1571 return Api::Success(); |
1586 } | 1572 } |
1587 | 1573 |
1588 | 1574 |
1589 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, | 1575 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
1590 intptr_t* size) { | 1576 intptr_t* size) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1653 static void RunLoopDone(uword param) { | 1639 static void RunLoopDone(uword param) { |
1654 RunLoopData* data = reinterpret_cast<RunLoopData*>(param); | 1640 RunLoopData* data = reinterpret_cast<RunLoopData*>(param); |
1655 ASSERT(data->monitor != NULL); | 1641 ASSERT(data->monitor != NULL); |
1656 MonitorLocker ml(data->monitor); | 1642 MonitorLocker ml(data->monitor); |
1657 data->done = true; | 1643 data->done = true; |
1658 ml.Notify(); | 1644 ml.Notify(); |
1659 } | 1645 } |
1660 | 1646 |
1661 | 1647 |
1662 DART_EXPORT Dart_Handle Dart_RunLoop() { | 1648 DART_EXPORT Dart_Handle Dart_RunLoop() { |
1663 Isolate* isolate = Isolate::Current(); | 1649 Thread* thread = Thread::Current(); |
1650 Isolate* isolate = thread->isolate(); | |
siva
2015/09/01 23:38:16
Ditto comment about using T, I
Ivan Posva
2015/09/02 00:03:33
Done.
| |
1664 CHECK_ISOLATE_SCOPE(isolate); | 1651 CHECK_ISOLATE_SCOPE(isolate); |
1665 CHECK_CALLBACK_STATE(isolate); | 1652 CHECK_CALLBACK_STATE(isolate); |
1666 Monitor monitor; | 1653 Monitor monitor; |
1667 MonitorLocker ml(&monitor); | 1654 MonitorLocker ml(&monitor); |
1668 { | 1655 { |
1669 SwitchIsolateScope switch_scope(NULL); | 1656 SwitchIsolateScope switch_scope(NULL); |
1670 | 1657 |
1671 RunLoopData data; | 1658 RunLoopData data; |
1672 data.monitor = &monitor; | 1659 data.monitor = &monitor; |
1673 data.done = false; | 1660 data.done = false; |
1674 isolate->message_handler()->Run( | 1661 isolate->message_handler()->Run( |
1675 Dart::thread_pool(), | 1662 Dart::thread_pool(), |
1676 NULL, RunLoopDone, reinterpret_cast<uword>(&data)); | 1663 NULL, RunLoopDone, reinterpret_cast<uword>(&data)); |
1677 while (!data.done) { | 1664 while (!data.done) { |
1678 ml.Wait(); | 1665 ml.Wait(); |
1679 } | 1666 } |
1680 } | 1667 } |
1681 if (isolate->object_store()->sticky_error() != Object::null()) { | 1668 if (isolate->object_store()->sticky_error() != Object::null()) { |
1682 Dart_Handle error = Api::NewHandle(isolate, | 1669 Dart_Handle error = Api::NewHandle(isolate, |
1683 isolate->object_store()->sticky_error()); | 1670 isolate->object_store()->sticky_error()); |
1684 isolate->object_store()->clear_sticky_error(); | 1671 isolate->object_store()->clear_sticky_error(); |
1685 return error; | 1672 return error; |
1686 } | 1673 } |
1687 if (FLAG_print_class_table) { | 1674 if (FLAG_print_class_table) { |
1688 HANDLESCOPE(isolate); | 1675 HANDLESCOPE(thread); |
1689 isolate->class_table()->Print(); | 1676 isolate->class_table()->Print(); |
1690 } | 1677 } |
1691 return Api::Success(); | 1678 return Api::Success(); |
1692 } | 1679 } |
1693 | 1680 |
1694 | 1681 |
1695 DART_EXPORT Dart_Handle Dart_HandleMessage() { | 1682 DART_EXPORT Dart_Handle Dart_HandleMessage() { |
1696 Isolate* isolate = Isolate::Current(); | 1683 Isolate* isolate = Isolate::Current(); |
1697 CHECK_ISOLATE_SCOPE(isolate); | 1684 CHECK_ISOLATE_SCOPE(isolate); |
1698 CHECK_CALLBACK_STATE(isolate); | 1685 CHECK_CALLBACK_STATE(isolate); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1731 } | 1718 } |
1732 | 1719 |
1733 | 1720 |
1734 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 1721 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
1735 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 1722 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
1736 return reinterpret_cast<uint8_t*>(new_ptr); | 1723 return reinterpret_cast<uint8_t*>(new_ptr); |
1737 } | 1724 } |
1738 | 1725 |
1739 | 1726 |
1740 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { | 1727 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { |
1741 Isolate* isolate = Isolate::Current(); | 1728 DARTSCOPE(Thread::Current()); |
1742 DARTSCOPE(isolate); | |
1743 if (port_id == ILLEGAL_PORT) { | 1729 if (port_id == ILLEGAL_PORT) { |
1744 return false; | 1730 return false; |
1745 } | 1731 } |
1746 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 1732 const Object& object = Object::Handle(Z, Api::UnwrapHandle(handle)); |
1747 uint8_t* data = NULL; | 1733 uint8_t* data = NULL; |
1748 MessageWriter writer(&data, &allocator, false); | 1734 MessageWriter writer(&data, &allocator, false); |
1749 writer.WriteMessage(object); | 1735 writer.WriteMessage(object); |
1750 intptr_t len = writer.BytesWritten(); | 1736 intptr_t len = writer.BytesWritten(); |
1751 return PortMap::PostMessage(new Message( | 1737 return PortMap::PostMessage(new Message( |
1752 port_id, data, len, Message::kNormalPriority)); | 1738 port_id, data, len, Message::kNormalPriority)); |
1753 } | 1739 } |
1754 | 1740 |
1755 | 1741 |
1756 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 1742 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
1757 Isolate* isolate = Isolate::Current(); | 1743 DARTSCOPE(Thread::Current()); |
1758 DARTSCOPE(isolate); | 1744 CHECK_CALLBACK_STATE(I); |
1759 CHECK_CALLBACK_STATE(isolate); | |
1760 if (port_id == ILLEGAL_PORT) { | 1745 if (port_id == ILLEGAL_PORT) { |
1761 return Api::NewError("%s: illegal port_id %" Pd64 ".", | 1746 return Api::NewError("%s: illegal port_id %" Pd64 ".", |
1762 CURRENT_FUNC, | 1747 CURRENT_FUNC, |
1763 port_id); | 1748 port_id); |
1764 } | 1749 } |
1765 return Api::NewHandle(isolate, SendPort::New(port_id)); | 1750 return Api::NewHandle(I, SendPort::New(port_id)); |
1766 } | 1751 } |
1767 | 1752 |
1768 | 1753 |
1769 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, | 1754 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, |
1770 Dart_Port* port_id) { | 1755 Dart_Port* port_id) { |
1771 Isolate* isolate = Isolate::Current(); | 1756 DARTSCOPE(Thread::Current()); |
1772 DARTSCOPE(isolate); | 1757 CHECK_CALLBACK_STATE(I); |
1773 CHECK_CALLBACK_STATE(isolate); | 1758 const SendPort& send_port = Api::UnwrapSendPortHandle(I, port); |
1774 const SendPort& send_port = Api::UnwrapSendPortHandle(isolate, port); | |
1775 if (send_port.IsNull()) { | 1759 if (send_port.IsNull()) { |
1776 RETURN_TYPE_ERROR(isolate, port, SendPort); | 1760 RETURN_TYPE_ERROR(I, port, SendPort); |
1777 } | 1761 } |
1778 if (port_id == NULL) { | 1762 if (port_id == NULL) { |
1779 RETURN_NULL_ERROR(port_id); | 1763 RETURN_NULL_ERROR(port_id); |
1780 } | 1764 } |
1781 *port_id = send_port.Id(); | 1765 *port_id = send_port.Id(); |
1782 return Api::Success(); | 1766 return Api::Success(); |
1783 } | 1767 } |
1784 | 1768 |
1785 | 1769 |
1786 DART_EXPORT Dart_Port Dart_GetMainPortId() { | 1770 DART_EXPORT Dart_Port Dart_GetMainPortId() { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1862 } | 1846 } |
1863 | 1847 |
1864 | 1848 |
1865 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { | 1849 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { |
1866 return Api::UnwrapHandle(object) == Object::null(); | 1850 return Api::UnwrapHandle(object) == Object::null(); |
1867 } | 1851 } |
1868 | 1852 |
1869 | 1853 |
1870 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, | 1854 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, |
1871 bool* value) { | 1855 bool* value) { |
1872 Thread* thread = Thread::Current(); | 1856 DARTSCOPE(Thread::Current()); |
1873 Isolate* isolate = thread->isolate(); | 1857 CHECK_CALLBACK_STATE(I); |
1874 Zone* zone = thread->zone(); | |
1875 DARTSCOPE(isolate); | |
1876 CHECK_CALLBACK_STATE(isolate); | |
1877 const Instance& expected = | 1858 const Instance& expected = |
1878 Instance::CheckedHandle(zone, Api::UnwrapHandle(obj1)); | 1859 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj1)); |
1879 const Instance& actual = | 1860 const Instance& actual = |
1880 Instance::CheckedHandle(zone, Api::UnwrapHandle(obj2)); | 1861 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj2)); |
1881 const Object& result = | 1862 const Object& result = |
1882 Object::Handle(zone, DartLibraryCalls::Equals(expected, actual)); | 1863 Object::Handle(Z, DartLibraryCalls::Equals(expected, actual)); |
1883 if (result.IsBool()) { | 1864 if (result.IsBool()) { |
1884 *value = Bool::Cast(result).value(); | 1865 *value = Bool::Cast(result).value(); |
1885 return Api::Success(); | 1866 return Api::Success(); |
1886 } else if (result.IsError()) { | 1867 } else if (result.IsError()) { |
1887 return Api::NewHandle(isolate, result.raw()); | 1868 return Api::NewHandle(I, result.raw()); |
1888 } else { | 1869 } else { |
1889 return Api::NewError("Expected boolean result from =="); | 1870 return Api::NewError("Expected boolean result from =="); |
1890 } | 1871 } |
1891 } | 1872 } |
1892 | 1873 |
1893 | 1874 |
1894 // TODO(iposva): This call actually implements IsInstanceOfClass. | 1875 // TODO(iposva): This call actually implements IsInstanceOfClass. |
1895 // Do we also need a real Dart_IsInstanceOf, which should take an instance | 1876 // Do we also need a real Dart_IsInstanceOf, which should take an instance |
1896 // rather than an object? | 1877 // rather than an object? |
1897 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, | 1878 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, |
1898 Dart_Handle type, | 1879 Dart_Handle type, |
1899 bool* value) { | 1880 bool* value) { |
1900 Isolate* isolate = Isolate::Current(); | 1881 DARTSCOPE(Thread::Current()); |
1901 DARTSCOPE(isolate); | |
1902 | 1882 |
1903 const Type& type_obj = Api::UnwrapTypeHandle(isolate, type); | 1883 const Type& type_obj = Api::UnwrapTypeHandle(I, type); |
1904 if (type_obj.IsNull()) { | 1884 if (type_obj.IsNull()) { |
1905 *value = false; | 1885 *value = false; |
1906 RETURN_TYPE_ERROR(isolate, type, Type); | 1886 RETURN_TYPE_ERROR(I, type, Type); |
1907 } | 1887 } |
1908 if (!type_obj.IsFinalized()) { | 1888 if (!type_obj.IsFinalized()) { |
1909 return Api::NewError( | 1889 return Api::NewError( |
1910 "%s expects argument 'type' to be a fully resolved type.", | 1890 "%s expects argument 'type' to be a fully resolved type.", |
1911 CURRENT_FUNC); | 1891 CURRENT_FUNC); |
1912 } | 1892 } |
1913 if (object == Api::Null()) { | 1893 if (object == Api::Null()) { |
1914 *value = false; | 1894 *value = false; |
1915 return Api::Success(); | 1895 return Api::Success(); |
1916 } | 1896 } |
1917 const Instance& instance = Api::UnwrapInstanceHandle(isolate, object); | 1897 const Instance& instance = Api::UnwrapInstanceHandle(I, object); |
1918 if (instance.IsNull()) { | 1898 if (instance.IsNull()) { |
1919 *value = false; | 1899 *value = false; |
1920 RETURN_TYPE_ERROR(isolate, object, Instance); | 1900 RETURN_TYPE_ERROR(I, object, Instance); |
1921 } | 1901 } |
1922 CHECK_CALLBACK_STATE(isolate); | 1902 CHECK_CALLBACK_STATE(I); |
1923 Error& malformed_type_error = Error::Handle(isolate); | 1903 Error& malformed_type_error = Error::Handle(Z); |
1924 *value = instance.IsInstanceOf(type_obj, | 1904 *value = instance.IsInstanceOf(type_obj, |
1925 Object::null_type_arguments(), | 1905 Object::null_type_arguments(), |
1926 &malformed_type_error); | 1906 &malformed_type_error); |
1927 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. | 1907 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. |
1928 return Api::Success(); | 1908 return Api::Success(); |
1929 } | 1909 } |
1930 | 1910 |
1931 | 1911 |
1932 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { | 1912 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { |
1933 Isolate* isolate = Isolate::Current(); | 1913 Isolate* isolate = Isolate::Current(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1980 return RawObject::IsExternalStringClassId(Api::ClassId(object)); | 1960 return RawObject::IsExternalStringClassId(Api::ClassId(object)); |
1981 } | 1961 } |
1982 | 1962 |
1983 | 1963 |
1984 DART_EXPORT bool Dart_IsList(Dart_Handle object) { | 1964 DART_EXPORT bool Dart_IsList(Dart_Handle object) { |
1985 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) { | 1965 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) { |
1986 TRACE_API_CALL(CURRENT_FUNC); | 1966 TRACE_API_CALL(CURRENT_FUNC); |
1987 return true; | 1967 return true; |
1988 } | 1968 } |
1989 | 1969 |
1990 Isolate* isolate = Isolate::Current(); | 1970 DARTSCOPE(Thread::Current()); |
1991 DARTSCOPE(isolate); | 1971 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
1992 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1972 return GetListInstance(Z, obj) != Instance::null(); |
1993 return GetListInstance(isolate, obj) != Instance::null(); | |
1994 } | 1973 } |
1995 | 1974 |
1996 | 1975 |
1997 DART_EXPORT bool Dart_IsMap(Dart_Handle object) { | 1976 DART_EXPORT bool Dart_IsMap(Dart_Handle object) { |
1998 Isolate* isolate = Isolate::Current(); | 1977 DARTSCOPE(Thread::Current()); |
1999 DARTSCOPE(isolate); | 1978 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
2000 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1979 return GetMapInstance(Z, obj) != Instance::null(); |
2001 return GetMapInstance(isolate, obj) != Instance::null(); | |
2002 } | 1980 } |
2003 | 1981 |
2004 | 1982 |
2005 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { | 1983 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { |
2006 TRACE_API_CALL(CURRENT_FUNC); | 1984 TRACE_API_CALL(CURRENT_FUNC); |
2007 return Api::ClassId(object) == kLibraryCid; | 1985 return Api::ClassId(object) == kLibraryCid; |
2008 } | 1986 } |
2009 | 1987 |
2010 | 1988 |
2011 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { | 1989 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2054 | 2032 |
2055 | 2033 |
2056 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) { | 2034 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) { |
2057 TRACE_API_CALL(CURRENT_FUNC); | 2035 TRACE_API_CALL(CURRENT_FUNC); |
2058 return Api::ClassId(handle) == kByteBufferCid; | 2036 return Api::ClassId(handle) == kByteBufferCid; |
2059 } | 2037 } |
2060 | 2038 |
2061 | 2039 |
2062 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) { | 2040 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) { |
2063 TRACE_API_CALL(CURRENT_FUNC); | 2041 TRACE_API_CALL(CURRENT_FUNC); |
2064 Isolate* isolate = Isolate::Current(); | 2042 DARTSCOPE(Thread::Current()); |
2065 DARTSCOPE(isolate); | 2043 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
2066 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | |
2067 if (obj.IsInstance()) { | 2044 if (obj.IsInstance()) { |
2068 const Class& future_class = | 2045 const Class& future_class = |
2069 Class::Handle(isolate->object_store()->future_class()); | 2046 Class::Handle(I->object_store()->future_class()); |
2070 ASSERT(!future_class.IsNull()); | 2047 ASSERT(!future_class.IsNull()); |
2071 const Class& obj_class = Class::Handle(isolate, obj.clazz()); | 2048 const Class& obj_class = Class::Handle(Z, obj.clazz()); |
2072 Error& malformed_type_error = Error::Handle(isolate); | 2049 Error& malformed_type_error = Error::Handle(Z); |
2073 bool is_future = obj_class.IsSubtypeOf(Object::null_type_arguments(), | 2050 bool is_future = obj_class.IsSubtypeOf(Object::null_type_arguments(), |
2074 future_class, | 2051 future_class, |
2075 Object::null_type_arguments(), | 2052 Object::null_type_arguments(), |
2076 &malformed_type_error); | 2053 &malformed_type_error); |
2077 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. | 2054 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. |
2078 return is_future; | 2055 return is_future; |
2079 } | 2056 } |
2080 return false; | 2057 return false; |
2081 } | 2058 } |
2082 | 2059 |
2083 | 2060 |
2084 // --- Instances ---- | 2061 // --- Instances ---- |
2085 | 2062 |
2086 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { | 2063 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { |
2087 Isolate* isolate = Isolate::Current(); | 2064 DARTSCOPE(Thread::Current()); |
2088 DARTSCOPE(isolate); | 2065 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance)); |
2089 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(instance)); | |
2090 if (obj.IsNull()) { | 2066 if (obj.IsNull()) { |
2091 return Api::NewHandle(isolate, isolate->object_store()->null_type()); | 2067 return Api::NewHandle(I, I->object_store()->null_type()); |
2092 } | 2068 } |
2093 if (!obj.IsInstance()) { | 2069 if (!obj.IsInstance()) { |
2094 RETURN_TYPE_ERROR(isolate, instance, Instance); | 2070 RETURN_TYPE_ERROR(I, instance, Instance); |
2095 } | 2071 } |
2096 const Type& type = Type::Handle(Instance::Cast(obj).GetType()); | 2072 const Type& type = Type::Handle(Instance::Cast(obj).GetType()); |
2097 return Api::NewHandle(isolate, type.Canonicalize()); | 2073 return Api::NewHandle(I, type.Canonicalize()); |
2098 } | 2074 } |
2099 | 2075 |
2100 | 2076 |
2101 // --- Numbers, Integers and Doubles ---- | 2077 // --- Numbers, Integers and Doubles ---- |
2102 | 2078 |
2103 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, | 2079 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, |
2104 bool* fits) { | 2080 bool* fits) { |
2105 // Fast path for Smis and Mints. | 2081 // Fast path for Smis and Mints. |
2106 Isolate* isolate = Isolate::Current(); | 2082 Thread* thread = Thread::Current(); |
2083 Isolate* isolate = thread->isolate(); | |
2107 CHECK_ISOLATE(isolate); | 2084 CHECK_ISOLATE(isolate); |
2108 intptr_t class_id = Api::ClassId(integer); | 2085 intptr_t class_id = Api::ClassId(integer); |
2109 if (class_id == kSmiCid || class_id == kMintCid) { | 2086 if (class_id == kSmiCid || class_id == kMintCid) { |
2110 *fits = true; | 2087 *fits = true; |
2111 return Api::Success(); | 2088 return Api::Success(); |
2112 } | 2089 } |
2113 // Slow path for Mints and Bigints. | 2090 // Slow path for Mints and Bigints. |
2114 DARTSCOPE(isolate); | 2091 DARTSCOPE(thread); |
2115 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 2092 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
2116 if (int_obj.IsNull()) { | 2093 if (int_obj.IsNull()) { |
2117 RETURN_TYPE_ERROR(isolate, integer, Integer); | 2094 RETURN_TYPE_ERROR(isolate, integer, Integer); |
2118 } | 2095 } |
2119 ASSERT(!Bigint::Cast(int_obj).FitsIntoInt64()); | 2096 ASSERT(!Bigint::Cast(int_obj).FitsIntoInt64()); |
2120 *fits = false; | 2097 *fits = false; |
2121 return Api::Success(); | 2098 return Api::Success(); |
2122 } | 2099 } |
2123 | 2100 |
2124 | 2101 |
2125 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, | 2102 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, |
2126 bool* fits) { | 2103 bool* fits) { |
2127 // Fast path for Smis. | 2104 // Fast path for Smis. |
2128 Isolate* isolate = Isolate::Current(); | 2105 Thread* thread = Thread::Current(); |
2106 Isolate* isolate = thread->isolate(); | |
2129 CHECK_ISOLATE(isolate); | 2107 CHECK_ISOLATE(isolate); |
2130 if (Api::IsSmi(integer)) { | 2108 if (Api::IsSmi(integer)) { |
2131 *fits = (Api::SmiValue(integer) >= 0); | 2109 *fits = (Api::SmiValue(integer) >= 0); |
2132 return Api::Success(); | 2110 return Api::Success(); |
2133 } | 2111 } |
2134 // Slow path for Mints and Bigints. | 2112 // Slow path for Mints and Bigints. |
2135 DARTSCOPE(isolate); | 2113 DARTSCOPE(thread); |
2136 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 2114 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
2137 if (int_obj.IsNull()) { | 2115 if (int_obj.IsNull()) { |
2138 RETURN_TYPE_ERROR(isolate, integer, Integer); | 2116 RETURN_TYPE_ERROR(isolate, integer, Integer); |
2139 } | 2117 } |
2140 ASSERT(!int_obj.IsSmi()); | 2118 ASSERT(!int_obj.IsSmi()); |
2141 if (int_obj.IsMint()) { | 2119 if (int_obj.IsMint()) { |
2142 *fits = !int_obj.IsNegative(); | 2120 *fits = !int_obj.IsNegative(); |
2143 } else { | 2121 } else { |
2144 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); | 2122 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); |
2145 } | 2123 } |
2146 return Api::Success(); | 2124 return Api::Success(); |
2147 } | 2125 } |
2148 | 2126 |
2149 | 2127 |
2150 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { | 2128 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { |
2151 // Fast path for Smis. | 2129 // Fast path for Smis. |
2152 Isolate* isolate = Isolate::Current(); | 2130 Thread* thread = Thread::Current(); |
2131 Isolate* isolate = thread->isolate(); | |
2153 CHECK_ISOLATE(isolate); | 2132 CHECK_ISOLATE(isolate); |
2154 if (Smi::IsValid(value)) { | 2133 if (Smi::IsValid(value)) { |
2155 NOHANDLESCOPE(isolate); | 2134 NOHANDLESCOPE(thread); |
2156 return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value))); | 2135 return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value))); |
2157 } | 2136 } |
2158 // Slow path for Mints and Bigints. | 2137 // Slow path for Mints and Bigints. |
2159 DARTSCOPE(isolate); | 2138 DARTSCOPE(thread); |
2160 CHECK_CALLBACK_STATE(isolate); | 2139 CHECK_CALLBACK_STATE(isolate); |
2161 return Api::NewHandle(isolate, Integer::New(value)); | 2140 return Api::NewHandle(isolate, Integer::New(value)); |
2162 } | 2141 } |
2163 | 2142 |
2164 | 2143 |
2165 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { | 2144 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { |
2166 Isolate* isolate = Isolate::Current(); | 2145 DARTSCOPE(Thread::Current()); |
2167 DARTSCOPE(isolate); | 2146 CHECK_CALLBACK_STATE(I); |
2168 CHECK_CALLBACK_STATE(isolate); | 2147 return Api::NewHandle(I, Integer::NewFromUint64(value)); |
2169 return Api::NewHandle(isolate, Integer::NewFromUint64(value)); | |
2170 } | 2148 } |
2171 | 2149 |
2172 | 2150 |
2173 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 2151 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
2174 Isolate* isolate = Isolate::Current(); | 2152 DARTSCOPE(Thread::Current()); |
2175 DARTSCOPE(isolate); | 2153 CHECK_CALLBACK_STATE(I); |
2176 CHECK_CALLBACK_STATE(isolate); | 2154 const String& str_obj = String::Handle(Z, String::New(str)); |
2177 const String& str_obj = String::Handle(isolate, String::New(str)); | 2155 return Api::NewHandle(I, Integer::New(str_obj)); |
2178 return Api::NewHandle(isolate, Integer::New(str_obj)); | |
2179 } | 2156 } |
2180 | 2157 |
2181 | 2158 |
2182 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, | 2159 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
2183 int64_t* value) { | 2160 int64_t* value) { |
2184 // Fast path for Smis. | 2161 // Fast path for Smis. |
2185 Isolate* isolate = Isolate::Current(); | 2162 Thread* thread = Thread::Current(); |
2163 Isolate* isolate = thread->isolate(); | |
2186 CHECK_ISOLATE(isolate); | 2164 CHECK_ISOLATE(isolate); |
2187 if (Api::IsSmi(integer)) { | 2165 if (Api::IsSmi(integer)) { |
2188 *value = Api::SmiValue(integer); | 2166 *value = Api::SmiValue(integer); |
2189 return Api::Success(); | 2167 return Api::Success(); |
2190 } | 2168 } |
2191 // Slow path for Mints and Bigints. | 2169 // Slow path for Mints and Bigints. |
2192 DARTSCOPE(isolate); | 2170 DARTSCOPE(thread); |
2193 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 2171 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
2194 if (int_obj.IsNull()) { | 2172 if (int_obj.IsNull()) { |
2195 RETURN_TYPE_ERROR(isolate, integer, Integer); | 2173 RETURN_TYPE_ERROR(isolate, integer, Integer); |
2196 } | 2174 } |
2197 ASSERT(!int_obj.IsSmi()); | 2175 ASSERT(!int_obj.IsSmi()); |
2198 if (int_obj.IsMint()) { | 2176 if (int_obj.IsMint()) { |
2199 *value = int_obj.AsInt64Value(); | 2177 *value = int_obj.AsInt64Value(); |
2200 return Api::Success(); | 2178 return Api::Success(); |
2201 } else { | 2179 } else { |
2202 const Bigint& bigint = Bigint::Cast(int_obj); | 2180 const Bigint& bigint = Bigint::Cast(int_obj); |
2203 if (bigint.FitsIntoInt64()) { | 2181 if (bigint.FitsIntoInt64()) { |
2204 *value = bigint.AsInt64Value(); | 2182 *value = bigint.AsInt64Value(); |
2205 return Api::Success(); | 2183 return Api::Success(); |
2206 } | 2184 } |
2207 } | 2185 } |
2208 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", | 2186 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", |
2209 CURRENT_FUNC, int_obj.ToCString()); | 2187 CURRENT_FUNC, int_obj.ToCString()); |
2210 } | 2188 } |
2211 | 2189 |
2212 | 2190 |
2213 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, | 2191 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, |
2214 uint64_t* value) { | 2192 uint64_t* value) { |
2215 // Fast path for Smis. | 2193 // Fast path for Smis. |
2216 Isolate* isolate = Isolate::Current(); | 2194 Thread* thread = Thread::Current(); |
2195 Isolate* isolate = thread->isolate(); | |
2217 CHECK_ISOLATE(isolate); | 2196 CHECK_ISOLATE(isolate); |
2218 if (Api::IsSmi(integer)) { | 2197 if (Api::IsSmi(integer)) { |
2219 intptr_t smi_value = Api::SmiValue(integer); | 2198 intptr_t smi_value = Api::SmiValue(integer); |
2220 if (smi_value >= 0) { | 2199 if (smi_value >= 0) { |
2221 *value = smi_value; | 2200 *value = smi_value; |
2222 return Api::Success(); | 2201 return Api::Success(); |
2223 } | 2202 } |
2224 } | 2203 } |
2225 // Slow path for Mints and Bigints. | 2204 // Slow path for Mints and Bigints. |
2226 DARTSCOPE(isolate); | 2205 DARTSCOPE(thread); |
2227 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 2206 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
2228 if (int_obj.IsNull()) { | 2207 if (int_obj.IsNull()) { |
2229 RETURN_TYPE_ERROR(isolate, integer, Integer); | 2208 RETURN_TYPE_ERROR(isolate, integer, Integer); |
2230 } | 2209 } |
2231 if (int_obj.IsSmi()) { | 2210 if (int_obj.IsSmi()) { |
2232 ASSERT(int_obj.IsNegative()); | 2211 ASSERT(int_obj.IsNegative()); |
2233 } else if (int_obj.IsMint() && !int_obj.IsNegative()) { | 2212 } else if (int_obj.IsMint() && !int_obj.IsNegative()) { |
2234 *value = int_obj.AsInt64Value(); | 2213 *value = int_obj.AsInt64Value(); |
2235 return Api::Success(); | 2214 return Api::Success(); |
2236 } else { | 2215 } else { |
2237 const Bigint& bigint = Bigint::Cast(int_obj); | 2216 const Bigint& bigint = Bigint::Cast(int_obj); |
2238 if (bigint.FitsIntoUint64()) { | 2217 if (bigint.FitsIntoUint64()) { |
2239 *value = bigint.AsUint64Value(); | 2218 *value = bigint.AsUint64Value(); |
2240 return Api::Success(); | 2219 return Api::Success(); |
2241 } | 2220 } |
2242 } | 2221 } |
2243 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", | 2222 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", |
2244 CURRENT_FUNC, int_obj.ToCString()); | 2223 CURRENT_FUNC, int_obj.ToCString()); |
2245 } | 2224 } |
2246 | 2225 |
2247 | 2226 |
2248 static uword BigintAllocate(intptr_t size) { | 2227 static uword BigintAllocate(intptr_t size) { |
2249 return Api::TopScope(Isolate::Current())->zone()->AllocUnsafe(size); | 2228 return Api::TopScope(Isolate::Current())->zone()->AllocUnsafe(size); |
2250 } | 2229 } |
2251 | 2230 |
2252 | 2231 |
2253 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | 2232 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, |
2254 const char** value) { | 2233 const char** value) { |
2255 Isolate* isolate = Isolate::Current(); | 2234 DARTSCOPE(Thread::Current()); |
2256 DARTSCOPE(isolate); | 2235 const Integer& int_obj = Api::UnwrapIntegerHandle(I, integer); |
2257 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | |
2258 if (int_obj.IsNull()) { | 2236 if (int_obj.IsNull()) { |
2259 RETURN_TYPE_ERROR(isolate, integer, Integer); | 2237 RETURN_TYPE_ERROR(I, integer, Integer); |
2260 } | 2238 } |
2261 if (int_obj.IsSmi() || int_obj.IsMint()) { | 2239 if (int_obj.IsSmi() || int_obj.IsMint()) { |
2262 const Bigint& bigint = Bigint::Handle(isolate, | 2240 const Bigint& bigint = Bigint::Handle(Z, |
2263 Bigint::NewFromInt64(int_obj.AsInt64Value())); | 2241 Bigint::NewFromInt64(int_obj.AsInt64Value())); |
2264 *value = bigint.ToHexCString(BigintAllocate); | 2242 *value = bigint.ToHexCString(BigintAllocate); |
2265 } else { | 2243 } else { |
2266 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate); | 2244 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate); |
2267 } | 2245 } |
2268 return Api::Success(); | 2246 return Api::Success(); |
2269 } | 2247 } |
2270 | 2248 |
2271 | 2249 |
2272 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { | 2250 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { |
2273 Isolate* isolate = Isolate::Current(); | 2251 DARTSCOPE(Thread::Current()); |
2274 DARTSCOPE(isolate); | 2252 CHECK_CALLBACK_STATE(I); |
2275 CHECK_CALLBACK_STATE(isolate); | 2253 return Api::NewHandle(I, Double::New(value)); |
2276 return Api::NewHandle(isolate, Double::New(value)); | |
2277 } | 2254 } |
2278 | 2255 |
2279 | 2256 |
2280 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, | 2257 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, |
2281 double* value) { | 2258 double* value) { |
2282 Isolate* isolate = Isolate::Current(); | 2259 DARTSCOPE(Thread::Current()); |
2283 DARTSCOPE(isolate); | 2260 const Double& obj = Api::UnwrapDoubleHandle(I, double_obj); |
2284 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj); | |
2285 if (obj.IsNull()) { | 2261 if (obj.IsNull()) { |
2286 RETURN_TYPE_ERROR(isolate, double_obj, Double); | 2262 RETURN_TYPE_ERROR(I, double_obj, Double); |
2287 } | 2263 } |
2288 *value = obj.value(); | 2264 *value = obj.value(); |
2289 return Api::Success(); | 2265 return Api::Success(); |
2290 } | 2266 } |
2291 | 2267 |
2292 | 2268 |
2293 // --- Booleans ---- | 2269 // --- Booleans ---- |
2294 | 2270 |
2295 DART_EXPORT Dart_Handle Dart_True() { | 2271 DART_EXPORT Dart_Handle Dart_True() { |
2296 ASSERT(Isolate::Current() != NULL); | 2272 ASSERT(Isolate::Current() != NULL); |
2297 return Api::True(); | 2273 return Api::True(); |
2298 } | 2274 } |
2299 | 2275 |
2300 | 2276 |
2301 DART_EXPORT Dart_Handle Dart_False() { | 2277 DART_EXPORT Dart_Handle Dart_False() { |
2302 ASSERT(Isolate::Current() != NULL); | 2278 ASSERT(Isolate::Current() != NULL); |
2303 return Api::False(); | 2279 return Api::False(); |
2304 } | 2280 } |
2305 | 2281 |
2306 | 2282 |
2307 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { | 2283 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { |
2308 Isolate* isolate = Isolate::Current(); | 2284 Isolate* isolate = Isolate::Current(); |
2309 CHECK_ISOLATE(isolate); | 2285 CHECK_ISOLATE(isolate); |
2310 return value ? Api::True() : Api::False(); | 2286 return value ? Api::True() : Api::False(); |
2311 } | 2287 } |
2312 | 2288 |
2313 | 2289 |
2314 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, | 2290 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, |
2315 bool* value) { | 2291 bool* value) { |
2316 Isolate* isolate = Isolate::Current(); | 2292 DARTSCOPE(Thread::Current()); |
2317 DARTSCOPE(isolate); | 2293 const Bool& obj = Api::UnwrapBoolHandle(I, boolean_obj); |
2318 const Bool& obj = Api::UnwrapBoolHandle(isolate, boolean_obj); | |
2319 if (obj.IsNull()) { | 2294 if (obj.IsNull()) { |
2320 RETURN_TYPE_ERROR(isolate, boolean_obj, Bool); | 2295 RETURN_TYPE_ERROR(I, boolean_obj, Bool); |
2321 } | 2296 } |
2322 *value = obj.value(); | 2297 *value = obj.value(); |
2323 return Api::Success(); | 2298 return Api::Success(); |
2324 } | 2299 } |
2325 | 2300 |
2326 | 2301 |
2327 // --- Strings --- | 2302 // --- Strings --- |
2328 | 2303 |
2329 | 2304 |
2330 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { | 2305 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { |
2331 Isolate* isolate = Isolate::Current(); | 2306 Isolate* isolate = Isolate::Current(); |
2332 CHECK_ISOLATE(isolate); | 2307 CHECK_ISOLATE(isolate); |
2333 ReusableObjectHandleScope reused_obj_handle(isolate); | 2308 ReusableObjectHandleScope reused_obj_handle(isolate); |
2334 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); | 2309 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); |
2335 if (str_obj.IsNull()) { | 2310 if (str_obj.IsNull()) { |
2336 RETURN_TYPE_ERROR(isolate, str, String); | 2311 RETURN_TYPE_ERROR(isolate, str, String); |
2337 } | 2312 } |
2338 *len = str_obj.Length(); | 2313 *len = str_obj.Length(); |
2339 return Api::Success(); | 2314 return Api::Success(); |
2340 } | 2315 } |
2341 | 2316 |
2342 | 2317 |
2343 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { | 2318 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { |
2344 Isolate* isolate = Isolate::Current(); | 2319 DARTSCOPE(Thread::Current()); |
2345 DARTSCOPE(isolate); | |
2346 if (str == NULL) { | 2320 if (str == NULL) { |
2347 RETURN_NULL_ERROR(str); | 2321 RETURN_NULL_ERROR(str); |
2348 } | 2322 } |
2349 CHECK_CALLBACK_STATE(isolate); | 2323 CHECK_CALLBACK_STATE(I); |
2350 return Api::NewHandle(isolate, String::New(str)); | 2324 return Api::NewHandle(I, String::New(str)); |
2351 } | 2325 } |
2352 | 2326 |
2353 | 2327 |
2354 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, | 2328 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, |
2355 intptr_t length) { | 2329 intptr_t length) { |
2356 Isolate* isolate = Isolate::Current(); | 2330 DARTSCOPE(Thread::Current()); |
2357 DARTSCOPE(isolate); | |
2358 if (utf8_array == NULL && length != 0) { | 2331 if (utf8_array == NULL && length != 0) { |
2359 RETURN_NULL_ERROR(utf8_array); | 2332 RETURN_NULL_ERROR(utf8_array); |
2360 } | 2333 } |
2361 CHECK_LENGTH(length, String::kMaxElements); | 2334 CHECK_LENGTH(length, String::kMaxElements); |
2362 if (!Utf8::IsValid(utf8_array, length)) { | 2335 if (!Utf8::IsValid(utf8_array, length)) { |
2363 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", | 2336 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", |
2364 CURRENT_FUNC); | 2337 CURRENT_FUNC); |
2365 } | 2338 } |
2366 CHECK_CALLBACK_STATE(isolate); | 2339 CHECK_CALLBACK_STATE(I); |
2367 return Api::NewHandle(isolate, String::FromUTF8(utf8_array, length)); | 2340 return Api::NewHandle(I, String::FromUTF8(utf8_array, length)); |
2368 } | 2341 } |
2369 | 2342 |
2370 | 2343 |
2371 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, | 2344 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, |
2372 intptr_t length) { | 2345 intptr_t length) { |
2373 Isolate* isolate = Isolate::Current(); | 2346 DARTSCOPE(Thread::Current()); |
2374 DARTSCOPE(isolate); | |
2375 if (utf16_array == NULL && length != 0) { | 2347 if (utf16_array == NULL && length != 0) { |
2376 RETURN_NULL_ERROR(utf16_array); | 2348 RETURN_NULL_ERROR(utf16_array); |
2377 } | 2349 } |
2378 CHECK_LENGTH(length, String::kMaxElements); | 2350 CHECK_LENGTH(length, String::kMaxElements); |
2379 CHECK_CALLBACK_STATE(isolate); | 2351 CHECK_CALLBACK_STATE(I); |
2380 return Api::NewHandle(isolate, String::FromUTF16(utf16_array, length)); | 2352 return Api::NewHandle(I, String::FromUTF16(utf16_array, length)); |
2381 } | 2353 } |
2382 | 2354 |
2383 | 2355 |
2384 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, | 2356 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, |
2385 intptr_t length) { | 2357 intptr_t length) { |
2386 Isolate* isolate = Isolate::Current(); | 2358 DARTSCOPE(Thread::Current()); |
2387 DARTSCOPE(isolate); | |
2388 if (utf32_array == NULL && length != 0) { | 2359 if (utf32_array == NULL && length != 0) { |
2389 RETURN_NULL_ERROR(utf32_array); | 2360 RETURN_NULL_ERROR(utf32_array); |
2390 } | 2361 } |
2391 CHECK_LENGTH(length, String::kMaxElements); | 2362 CHECK_LENGTH(length, String::kMaxElements); |
2392 CHECK_CALLBACK_STATE(isolate); | 2363 CHECK_CALLBACK_STATE(I); |
2393 return Api::NewHandle(isolate, String::FromUTF32(utf32_array, length)); | 2364 return Api::NewHandle(I, String::FromUTF32(utf32_array, length)); |
2394 } | 2365 } |
2395 | 2366 |
2396 | 2367 |
2397 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( | 2368 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( |
2398 const uint8_t* latin1_array, | 2369 const uint8_t* latin1_array, |
2399 intptr_t length, | 2370 intptr_t length, |
2400 void* peer, | 2371 void* peer, |
2401 Dart_PeerFinalizer cback) { | 2372 Dart_PeerFinalizer cback) { |
2402 Isolate* isolate = Isolate::Current(); | 2373 DARTSCOPE(Thread::Current()); |
2403 DARTSCOPE(isolate); | |
2404 if (latin1_array == NULL && length != 0) { | 2374 if (latin1_array == NULL && length != 0) { |
2405 RETURN_NULL_ERROR(latin1_array); | 2375 RETURN_NULL_ERROR(latin1_array); |
2406 } | 2376 } |
2407 CHECK_LENGTH(length, String::kMaxElements); | 2377 CHECK_LENGTH(length, String::kMaxElements); |
2408 CHECK_CALLBACK_STATE(isolate); | 2378 CHECK_CALLBACK_STATE(I); |
2409 return Api::NewHandle(isolate, | 2379 return Api::NewHandle(I, |
2410 String::NewExternal(latin1_array, | 2380 String::NewExternal(latin1_array, |
2411 length, | 2381 length, |
2412 peer, | 2382 peer, |
2413 cback, | 2383 cback, |
2414 SpaceForExternal(isolate, length))); | 2384 SpaceForExternal(I, length))); |
2415 } | 2385 } |
2416 | 2386 |
2417 | 2387 |
2418 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, | 2388 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, |
2419 intptr_t length, | 2389 intptr_t length, |
2420 void* peer, | 2390 void* peer, |
2421 Dart_PeerFinalizer cback) { | 2391 Dart_PeerFinalizer cback) { |
2422 Isolate* isolate = Isolate::Current(); | 2392 DARTSCOPE(Thread::Current()); |
2423 DARTSCOPE(isolate); | |
2424 if (utf16_array == NULL && length != 0) { | 2393 if (utf16_array == NULL && length != 0) { |
2425 RETURN_NULL_ERROR(utf16_array); | 2394 RETURN_NULL_ERROR(utf16_array); |
2426 } | 2395 } |
2427 CHECK_LENGTH(length, String::kMaxElements); | 2396 CHECK_LENGTH(length, String::kMaxElements); |
2428 CHECK_CALLBACK_STATE(isolate); | 2397 CHECK_CALLBACK_STATE(I); |
2429 intptr_t bytes = length * sizeof(*utf16_array); | 2398 intptr_t bytes = length * sizeof(*utf16_array); |
2430 return Api::NewHandle(isolate, | 2399 return Api::NewHandle(I, |
2431 String::NewExternal(utf16_array, | 2400 String::NewExternal(utf16_array, |
2432 length, | 2401 length, |
2433 peer, | 2402 peer, |
2434 cback, | 2403 cback, |
2435 SpaceForExternal(isolate, bytes))); | 2404 SpaceForExternal(I, bytes))); |
2436 } | 2405 } |
2437 | 2406 |
2438 | 2407 |
2439 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, | 2408 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
2440 const char** cstr) { | 2409 const char** cstr) { |
2441 Isolate* isolate = Isolate::Current(); | 2410 DARTSCOPE(Thread::Current()); |
2442 DARTSCOPE(isolate); | |
2443 if (cstr == NULL) { | 2411 if (cstr == NULL) { |
2444 RETURN_NULL_ERROR(cstr); | 2412 RETURN_NULL_ERROR(cstr); |
2445 } | 2413 } |
2446 const String& str_obj = Api::UnwrapStringHandle(isolate, object); | 2414 const String& str_obj = Api::UnwrapStringHandle(I, object); |
2447 if (str_obj.IsNull()) { | 2415 if (str_obj.IsNull()) { |
2448 RETURN_TYPE_ERROR(isolate, object, String); | 2416 RETURN_TYPE_ERROR(I, object, String); |
2449 } | 2417 } |
2450 intptr_t string_length = Utf8::Length(str_obj); | 2418 intptr_t string_length = Utf8::Length(str_obj); |
2451 char* res = Api::TopScope(isolate)->zone()->Alloc<char>(string_length + 1); | 2419 char* res = Api::TopScope(I)->zone()->Alloc<char>(string_length + 1); |
2452 if (res == NULL) { | 2420 if (res == NULL) { |
2453 return Api::NewError("Unable to allocate memory"); | 2421 return Api::NewError("Unable to allocate memory"); |
2454 } | 2422 } |
2455 const char* string_value = str_obj.ToCString(); | 2423 const char* string_value = str_obj.ToCString(); |
2456 memmove(res, string_value, string_length + 1); | 2424 memmove(res, string_value, string_length + 1); |
2457 ASSERT(res[string_length] == '\0'); | 2425 ASSERT(res[string_length] == '\0'); |
2458 *cstr = res; | 2426 *cstr = res; |
2459 return Api::Success(); | 2427 return Api::Success(); |
2460 } | 2428 } |
2461 | 2429 |
2462 | 2430 |
2463 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, | 2431 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, |
2464 uint8_t** utf8_array, | 2432 uint8_t** utf8_array, |
2465 intptr_t* length) { | 2433 intptr_t* length) { |
2466 Isolate* isolate = Isolate::Current(); | 2434 DARTSCOPE(Thread::Current()); |
2467 DARTSCOPE(isolate); | |
2468 if (utf8_array == NULL) { | 2435 if (utf8_array == NULL) { |
2469 RETURN_NULL_ERROR(utf8_array); | 2436 RETURN_NULL_ERROR(utf8_array); |
2470 } | 2437 } |
2471 if (length == NULL) { | 2438 if (length == NULL) { |
2472 RETURN_NULL_ERROR(length); | 2439 RETURN_NULL_ERROR(length); |
2473 } | 2440 } |
2474 const String& str_obj = Api::UnwrapStringHandle(isolate, str); | 2441 const String& str_obj = Api::UnwrapStringHandle(I, str); |
2475 if (str_obj.IsNull()) { | 2442 if (str_obj.IsNull()) { |
2476 RETURN_TYPE_ERROR(isolate, str, String); | 2443 RETURN_TYPE_ERROR(I, str, String); |
2477 } | 2444 } |
2478 intptr_t str_len = Utf8::Length(str_obj); | 2445 intptr_t str_len = Utf8::Length(str_obj); |
2479 *utf8_array = Api::TopScope(isolate)->zone()->Alloc<uint8_t>(str_len); | 2446 *utf8_array = Api::TopScope(I)->zone()->Alloc<uint8_t>(str_len); |
2480 if (*utf8_array == NULL) { | 2447 if (*utf8_array == NULL) { |
2481 return Api::NewError("Unable to allocate memory"); | 2448 return Api::NewError("Unable to allocate memory"); |
2482 } | 2449 } |
2483 str_obj.ToUTF8(*utf8_array, str_len); | 2450 str_obj.ToUTF8(*utf8_array, str_len); |
2484 *length = str_len; | 2451 *length = str_len; |
2485 return Api::Success(); | 2452 return Api::Success(); |
2486 } | 2453 } |
2487 | 2454 |
2488 | 2455 |
2489 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, | 2456 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, |
2490 uint8_t* latin1_array, | 2457 uint8_t* latin1_array, |
2491 intptr_t* length) { | 2458 intptr_t* length) { |
2492 Isolate* isolate = Isolate::Current(); | 2459 DARTSCOPE(Thread::Current()); |
2493 DARTSCOPE(isolate); | |
2494 if (latin1_array == NULL) { | 2460 if (latin1_array == NULL) { |
2495 RETURN_NULL_ERROR(latin1_array); | 2461 RETURN_NULL_ERROR(latin1_array); |
2496 } | 2462 } |
2497 if (length == NULL) { | 2463 if (length == NULL) { |
2498 RETURN_NULL_ERROR(length); | 2464 RETURN_NULL_ERROR(length); |
2499 } | 2465 } |
2500 const String& str_obj = Api::UnwrapStringHandle(isolate, str); | 2466 const String& str_obj = Api::UnwrapStringHandle(I, str); |
2501 if (str_obj.IsNull() || !str_obj.IsOneByteString()) { | 2467 if (str_obj.IsNull() || !str_obj.IsOneByteString()) { |
2502 RETURN_TYPE_ERROR(isolate, str, String); | 2468 RETURN_TYPE_ERROR(I, str, String); |
2503 } | 2469 } |
2504 intptr_t str_len = str_obj.Length(); | 2470 intptr_t str_len = str_obj.Length(); |
2505 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 2471 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
2506 | 2472 |
2507 // We have already asserted that the string object is a Latin-1 string | 2473 // We have already asserted that the string object is a Latin-1 string |
2508 // so we can copy the characters over using a simple loop. | 2474 // so we can copy the characters over using a simple loop. |
2509 for (intptr_t i = 0; i < copy_len; i++) { | 2475 for (intptr_t i = 0; i < copy_len; i++) { |
2510 latin1_array[i] = str_obj.CharAt(i); | 2476 latin1_array[i] = str_obj.CharAt(i); |
2511 } | 2477 } |
2512 *length = copy_len; | 2478 *length = copy_len; |
2513 return Api::Success(); | 2479 return Api::Success(); |
2514 } | 2480 } |
2515 | 2481 |
2516 | 2482 |
2517 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, | 2483 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, |
2518 uint16_t* utf16_array, | 2484 uint16_t* utf16_array, |
2519 intptr_t* length) { | 2485 intptr_t* length) { |
2520 Isolate* isolate = Isolate::Current(); | 2486 DARTSCOPE(Thread::Current()); |
2521 DARTSCOPE(isolate); | 2487 const String& str_obj = Api::UnwrapStringHandle(I, str); |
2522 const String& str_obj = Api::UnwrapStringHandle(isolate, str); | |
2523 if (str_obj.IsNull()) { | 2488 if (str_obj.IsNull()) { |
2524 RETURN_TYPE_ERROR(isolate, str, String); | 2489 RETURN_TYPE_ERROR(I, str, String); |
2525 } | 2490 } |
2526 intptr_t str_len = str_obj.Length(); | 2491 intptr_t str_len = str_obj.Length(); |
2527 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 2492 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
2528 for (intptr_t i = 0; i < copy_len; i++) { | 2493 for (intptr_t i = 0; i < copy_len; i++) { |
2529 utf16_array[i] = str_obj.CharAt(i); | 2494 utf16_array[i] = str_obj.CharAt(i); |
2530 } | 2495 } |
2531 *length = copy_len; | 2496 *length = copy_len; |
2532 return Api::Success(); | 2497 return Api::Success(); |
2533 } | 2498 } |
2534 | 2499 |
(...skipping 13 matching lines...) Expand all Loading... | |
2548 *size = (str_obj.Length() * str_obj.CharSize()); | 2513 *size = (str_obj.Length() * str_obj.CharSize()); |
2549 return Api::Success(); | 2514 return Api::Success(); |
2550 } | 2515 } |
2551 | 2516 |
2552 | 2517 |
2553 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, | 2518 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, |
2554 void* array, | 2519 void* array, |
2555 intptr_t length, | 2520 intptr_t length, |
2556 void* peer, | 2521 void* peer, |
2557 Dart_PeerFinalizer cback) { | 2522 Dart_PeerFinalizer cback) { |
2558 Isolate* isolate = Isolate::Current(); | 2523 DARTSCOPE(Thread::Current()); |
2559 DARTSCOPE(isolate); | 2524 const String& str_obj = Api::UnwrapStringHandle(I, str); |
2560 const String& str_obj = Api::UnwrapStringHandle(isolate, str); | |
2561 if (str_obj.IsExternal()) { | 2525 if (str_obj.IsExternal()) { |
2562 return str; // String is already an external string. | 2526 return str; // String is already an external string. |
2563 } | 2527 } |
2564 if (str_obj.IsNull()) { | 2528 if (str_obj.IsNull()) { |
2565 RETURN_TYPE_ERROR(isolate, str, String); | 2529 RETURN_TYPE_ERROR(I, str, String); |
2566 } | 2530 } |
2567 if (array == NULL) { | 2531 if (array == NULL) { |
2568 RETURN_NULL_ERROR(array); | 2532 RETURN_NULL_ERROR(array); |
2569 } | 2533 } |
2570 intptr_t str_size = (str_obj.Length() * str_obj.CharSize()); | 2534 intptr_t str_size = (str_obj.Length() * str_obj.CharSize()); |
2571 if ((length < str_size) || (length > String::kMaxElements)) { | 2535 if ((length < str_size) || (length > String::kMaxElements)) { |
2572 return Api::NewError("Dart_MakeExternalString " | 2536 return Api::NewError("Dart_MakeExternalString " |
2573 "expects argument length to be in the range" | 2537 "expects argument length to be in the range" |
2574 "[%" Pd "..%" Pd "].", | 2538 "[%" Pd "..%" Pd "].", |
2575 str_size, String::kMaxElements); | 2539 str_size, String::kMaxElements); |
(...skipping 16 matching lines...) Expand all Loading... | |
2592 ASSERT(str_obj.IsTwoByteString()); | 2556 ASSERT(str_obj.IsTwoByteString()); |
2593 ASSERT(length >= (copy_len * str_obj.CharSize())); | 2557 ASSERT(length >= (copy_len * str_obj.CharSize())); |
2594 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array); | 2558 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array); |
2595 for (intptr_t i = 0; i < copy_len; i++) { | 2559 for (intptr_t i = 0; i < copy_len; i++) { |
2596 utf16_array[i] = str_obj.CharAt(i); | 2560 utf16_array[i] = str_obj.CharAt(i); |
2597 } | 2561 } |
2598 TwoByteString::SetPeer(str_obj, peer, cback); | 2562 TwoByteString::SetPeer(str_obj, peer, cback); |
2599 } | 2563 } |
2600 return str; | 2564 return str; |
2601 } | 2565 } |
2602 return Api::NewHandle(isolate, | 2566 return Api::NewHandle(I, str_obj.MakeExternal(array, length, peer, cback)); |
2603 str_obj.MakeExternal(array, length, peer, cback)); | |
2604 } | 2567 } |
2605 | 2568 |
2606 | 2569 |
2607 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, | 2570 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, |
2608 intptr_t* char_size, | 2571 intptr_t* char_size, |
2609 intptr_t* str_len, | 2572 intptr_t* str_len, |
2610 void** peer) { | 2573 void** peer) { |
2611 Isolate* isolate = Isolate::Current(); | 2574 Isolate* isolate = Isolate::Current(); |
2612 CHECK_ISOLATE(isolate); | 2575 CHECK_ISOLATE(isolate); |
2613 ReusableObjectHandleScope reused_obj_handle(isolate); | 2576 ReusableObjectHandleScope reused_obj_handle(isolate); |
(...skipping 10 matching lines...) Expand all Loading... | |
2624 } | 2587 } |
2625 *char_size = str.CharSize(); | 2588 *char_size = str.CharSize(); |
2626 *str_len = str.Length(); | 2589 *str_len = str.Length(); |
2627 return Api::Success(); | 2590 return Api::Success(); |
2628 } | 2591 } |
2629 | 2592 |
2630 | 2593 |
2631 // --- Lists --- | 2594 // --- Lists --- |
2632 | 2595 |
2633 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { | 2596 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
2634 Isolate* isolate = Isolate::Current(); | 2597 DARTSCOPE(Thread::Current()); |
2635 DARTSCOPE(isolate); | |
2636 CHECK_LENGTH(length, Array::kMaxElements); | 2598 CHECK_LENGTH(length, Array::kMaxElements); |
2637 CHECK_CALLBACK_STATE(isolate); | 2599 CHECK_CALLBACK_STATE(I); |
2638 return Api::NewHandle(isolate, Array::New(length)); | 2600 return Api::NewHandle(I, Array::New(length)); |
2639 } | 2601 } |
2640 | 2602 |
2641 | 2603 |
2642 #define GET_LIST_LENGTH(isolate, type, obj, len) \ | 2604 #define GET_LIST_LENGTH(zone, type, obj, len) \ |
2643 type& array = type::Handle(isolate); \ | 2605 type& array = type::Handle(zone); \ |
2644 array ^= obj.raw(); \ | 2606 array ^= obj.raw(); \ |
2645 *len = array.Length(); \ | 2607 *len = array.Length(); \ |
2646 return Api::Success(); \ | 2608 return Api::Success(); \ |
2647 | 2609 |
2648 | 2610 |
2649 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { | 2611 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { |
2650 Isolate* isolate = Isolate::Current(); | 2612 DARTSCOPE(Thread::Current()); |
2651 DARTSCOPE(isolate); | 2613 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2652 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | |
2653 if (obj.IsError()) { | 2614 if (obj.IsError()) { |
2654 // Pass through errors. | 2615 // Pass through errors. |
2655 return list; | 2616 return list; |
2656 } | 2617 } |
2657 if (obj.IsTypedData()) { | 2618 if (obj.IsTypedData()) { |
2658 GET_LIST_LENGTH(isolate, TypedData, obj, len); | 2619 GET_LIST_LENGTH(Z, TypedData, obj, len); |
2659 } | 2620 } |
2660 if (obj.IsArray()) { | 2621 if (obj.IsArray()) { |
2661 GET_LIST_LENGTH(isolate, Array, obj, len); | 2622 GET_LIST_LENGTH(Z, Array, obj, len); |
2662 } | 2623 } |
2663 if (obj.IsGrowableObjectArray()) { | 2624 if (obj.IsGrowableObjectArray()) { |
2664 GET_LIST_LENGTH(isolate, GrowableObjectArray, obj, len); | 2625 GET_LIST_LENGTH(Z, GrowableObjectArray, obj, len); |
2665 } | 2626 } |
2666 if (obj.IsExternalTypedData()) { | 2627 if (obj.IsExternalTypedData()) { |
2667 GET_LIST_LENGTH(isolate, ExternalTypedData, obj, len); | 2628 GET_LIST_LENGTH(Z, ExternalTypedData, obj, len); |
2668 } | 2629 } |
2669 CHECK_CALLBACK_STATE(isolate); | 2630 CHECK_CALLBACK_STATE(I); |
2670 | 2631 |
2671 // Now check and handle a dart object that implements the List interface. | 2632 // Now check and handle a dart object that implements the List interface. |
2672 const Instance& instance = | 2633 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2673 Instance::Handle(isolate, GetListInstance(isolate, obj)); | |
2674 if (instance.IsNull()) { | 2634 if (instance.IsNull()) { |
2675 return Api::NewError("Object does not implement the List interface"); | 2635 return Api::NewError("Object does not implement the List interface"); |
2676 } | 2636 } |
2677 const String& name = String::Handle(Field::GetterName(Symbols::Length())); | 2637 const String& name = String::Handle(Z, Field::GetterName(Symbols::Length())); |
2678 const int kNumArgs = 1; | 2638 const int kNumArgs = 1; |
2679 ArgumentsDescriptor args_desc( | 2639 ArgumentsDescriptor args_desc( |
2680 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 2640 Array::Handle(Z, ArgumentsDescriptor::New(kNumArgs))); |
2681 const Function& function = | 2641 const Function& function = |
2682 Function::Handle(isolate, Resolver::ResolveDynamic(instance, | 2642 Function::Handle(Z, Resolver::ResolveDynamic(instance, name, args_desc)); |
2683 name, | |
2684 args_desc)); | |
2685 if (function.IsNull()) { | 2643 if (function.IsNull()) { |
2686 return Api::NewError("List object does not have a 'length' field."); | 2644 return Api::NewError("List object does not have a 'length' field."); |
2687 } | 2645 } |
2688 | 2646 |
2689 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2647 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
2690 args.SetAt(0, instance); // Set up the receiver as the first argument. | 2648 args.SetAt(0, instance); // Set up the receiver as the first argument. |
2691 const Object& retval = | 2649 const Object& retval = |
2692 Object::Handle(isolate, DartEntry::InvokeFunction(function, args)); | 2650 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); |
2693 if (retval.IsSmi()) { | 2651 if (retval.IsSmi()) { |
2694 *len = Smi::Cast(retval).Value(); | 2652 *len = Smi::Cast(retval).Value(); |
2695 return Api::Success(); | 2653 return Api::Success(); |
2696 } else if (retval.IsMint() || retval.IsBigint()) { | 2654 } else if (retval.IsMint() || retval.IsBigint()) { |
2697 if (retval.IsMint()) { | 2655 if (retval.IsMint()) { |
2698 int64_t mint_value = Mint::Cast(retval).value(); | 2656 int64_t mint_value = Mint::Cast(retval).value(); |
2699 if (mint_value >= kIntptrMin && mint_value <= kIntptrMax) { | 2657 if (mint_value >= kIntptrMin && mint_value <= kIntptrMax) { |
2700 *len = static_cast<intptr_t>(mint_value); | 2658 *len = static_cast<intptr_t>(mint_value); |
2701 } | 2659 } |
2702 } else { | 2660 } else { |
2703 // Check for a non-canonical Mint range value. | 2661 // Check for a non-canonical Mint range value. |
2704 ASSERT(retval.IsBigint()); | 2662 ASSERT(retval.IsBigint()); |
2705 const Bigint& bigint = Bigint::Handle(); | 2663 const Bigint& bigint = Bigint::Handle(); |
2706 if (bigint.FitsIntoInt64()) { | 2664 if (bigint.FitsIntoInt64()) { |
2707 int64_t bigint_value = bigint.AsInt64Value(); | 2665 int64_t bigint_value = bigint.AsInt64Value(); |
2708 if (bigint_value >= kIntptrMin && bigint_value <= kIntptrMax) { | 2666 if (bigint_value >= kIntptrMin && bigint_value <= kIntptrMax) { |
2709 *len = static_cast<intptr_t>(bigint_value); | 2667 *len = static_cast<intptr_t>(bigint_value); |
2710 } | 2668 } |
2711 } | 2669 } |
2712 } | 2670 } |
2713 return Api::NewError("Length of List object is greater than the " | 2671 return Api::NewError("Length of List object is greater than the " |
2714 "maximum value that 'len' parameter can hold"); | 2672 "maximum value that 'len' parameter can hold"); |
2715 } else if (retval.IsError()) { | 2673 } else if (retval.IsError()) { |
2716 return Api::NewHandle(isolate, retval.raw()); | 2674 return Api::NewHandle(I, retval.raw()); |
2717 } else { | 2675 } else { |
2718 return Api::NewError("Length of List object is not an integer"); | 2676 return Api::NewError("Length of List object is not an integer"); |
2719 } | 2677 } |
2720 } | 2678 } |
2721 | 2679 |
2722 | 2680 |
2723 #define GET_LIST_ELEMENT(isolate, type, obj, index) \ | 2681 #define GET_LIST_ELEMENT(isolate, type, obj, index) \ |
2724 const type& array_obj = type::Cast(obj); \ | 2682 const type& array_obj = type::Cast(obj); \ |
2725 if ((index >= 0) && (index < array_obj.Length())) { \ | 2683 if ((index >= 0) && (index < array_obj.Length())) { \ |
2726 return Api::NewHandle(isolate, array_obj.At(index)); \ | 2684 return Api::NewHandle(isolate, array_obj.At(index)); \ |
2727 } \ | 2685 } \ |
2728 return Api::NewError("Invalid index passed in to access list element"); \ | 2686 return Api::NewError("Invalid index passed in to access list element"); \ |
2729 | 2687 |
2730 | 2688 |
2731 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 2689 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
2732 Isolate* isolate = Isolate::Current(); | 2690 DARTSCOPE(Thread::Current()); |
2733 DARTSCOPE(isolate); | 2691 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2734 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | |
2735 if (obj.IsArray()) { | 2692 if (obj.IsArray()) { |
2736 GET_LIST_ELEMENT(isolate, Array, obj, index); | 2693 GET_LIST_ELEMENT(I, Array, obj, index); |
2737 } else if (obj.IsGrowableObjectArray()) { | 2694 } else if (obj.IsGrowableObjectArray()) { |
2738 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); | 2695 GET_LIST_ELEMENT(I, GrowableObjectArray, obj, index); |
2739 } else if (obj.IsError()) { | 2696 } else if (obj.IsError()) { |
2740 return list; | 2697 return list; |
2741 } else { | 2698 } else { |
2742 CHECK_CALLBACK_STATE(isolate); | 2699 CHECK_CALLBACK_STATE(I); |
2743 // Check and handle a dart object that implements the List interface. | 2700 // Check and handle a dart object that implements the List interface. |
2744 const Instance& instance = | 2701 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2745 Instance::Handle(isolate, GetListInstance(isolate, obj)); | |
2746 if (!instance.IsNull()) { | 2702 if (!instance.IsNull()) { |
2747 return Api::NewHandle(isolate, Send1Arg( | 2703 return Api::NewHandle(I, Send1Arg( |
2748 instance, | 2704 instance, |
2749 Symbols::IndexToken(), | 2705 Symbols::IndexToken(), |
2750 Instance::Handle(isolate, Integer::New(index)))); | 2706 Instance::Handle(Z, Integer::New(index)))); |
2751 } | 2707 } |
2752 return Api::NewError("Object does not implement the 'List' interface"); | 2708 return Api::NewError("Object does not implement the 'List' interface"); |
2753 } | 2709 } |
2754 } | 2710 } |
2755 | 2711 |
2756 | 2712 |
2757 #define GET_LIST_RANGE(isolate, type, obj, offset, length) \ | 2713 #define GET_LIST_RANGE(isolate, type, obj, offset, length) \ |
2758 const type& array_obj = type::Cast(obj); \ | 2714 const type& array_obj = type::Cast(obj); \ |
2759 if ((offset >= 0) && (offset + length <= array_obj.Length())) { \ | 2715 if ((offset >= 0) && (offset + length <= array_obj.Length())) { \ |
2760 for (intptr_t index = 0; index < length; ++index) { \ | 2716 for (intptr_t index = 0; index < length; ++index) { \ |
2761 result[index] = Api::NewHandle(isolate, array_obj.At(index + offset)); \ | 2717 result[index] = Api::NewHandle(isolate, array_obj.At(index + offset)); \ |
2762 } \ | 2718 } \ |
2763 return Api::Success(); \ | 2719 return Api::Success(); \ |
2764 } \ | 2720 } \ |
2765 return Api::NewError("Invalid offset/length passed in to access list"); \ | 2721 return Api::NewError("Invalid offset/length passed in to access list"); \ |
2766 | 2722 |
2767 | 2723 |
2768 DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, | 2724 DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, |
2769 intptr_t offset, | 2725 intptr_t offset, |
2770 intptr_t length, | 2726 intptr_t length, |
2771 Dart_Handle* result) { | 2727 Dart_Handle* result) { |
2772 Isolate* isolate = Isolate::Current(); | 2728 DARTSCOPE(Thread::Current()); |
2773 DARTSCOPE(isolate); | |
2774 if (result == NULL) { | 2729 if (result == NULL) { |
2775 RETURN_NULL_ERROR(result); | 2730 RETURN_NULL_ERROR(result); |
2776 } | 2731 } |
2777 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 2732 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2778 if (obj.IsArray()) { | 2733 if (obj.IsArray()) { |
2779 GET_LIST_RANGE(isolate, Array, obj, offset, length); | 2734 GET_LIST_RANGE(I, Array, obj, offset, length); |
2780 } else if (obj.IsGrowableObjectArray()) { | 2735 } else if (obj.IsGrowableObjectArray()) { |
2781 GET_LIST_RANGE(isolate, GrowableObjectArray, obj, offset, length); | 2736 GET_LIST_RANGE(I, GrowableObjectArray, obj, offset, length); |
2782 } else if (obj.IsError()) { | 2737 } else if (obj.IsError()) { |
2783 return list; | 2738 return list; |
2784 } else { | 2739 } else { |
2785 CHECK_CALLBACK_STATE(isolate); | 2740 CHECK_CALLBACK_STATE(I); |
2786 // Check and handle a dart object that implements the List interface. | 2741 // Check and handle a dart object that implements the List interface. |
2787 const Instance& instance = | 2742 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2788 Instance::Handle(isolate, GetListInstance(isolate, obj)); | |
2789 if (!instance.IsNull()) { | 2743 if (!instance.IsNull()) { |
2790 const intptr_t kNumArgs = 2; | 2744 const intptr_t kNumArgs = 2; |
2791 ArgumentsDescriptor args_desc( | 2745 ArgumentsDescriptor args_desc( |
2792 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 2746 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
2793 const Function& function = Function::Handle( | 2747 const Function& function = Function::Handle(Z, |
2794 isolate, | |
2795 Resolver::ResolveDynamic(instance, | 2748 Resolver::ResolveDynamic(instance, |
2796 Symbols::AssignIndexToken(), | 2749 Symbols::AssignIndexToken(), |
2797 args_desc)); | 2750 args_desc)); |
2798 if (!function.IsNull()) { | 2751 if (!function.IsNull()) { |
2799 const Array& args = Array::Handle(Array::New(kNumArgs)); | 2752 const Array& args = Array::Handle(Array::New(kNumArgs)); |
2800 args.SetAt(0, instance); | 2753 args.SetAt(0, instance); |
2801 Instance& index = Instance::Handle(isolate); | 2754 Instance& index = Instance::Handle(Z); |
2802 for (intptr_t i = 0; i < length; ++i) { | 2755 for (intptr_t i = 0; i < length; ++i) { |
2803 index = Integer::New(i); | 2756 index = Integer::New(i); |
2804 args.SetAt(1, index); | 2757 args.SetAt(1, index); |
2805 Dart_Handle value = Api::NewHandle(isolate, | 2758 Dart_Handle value = Api::NewHandle(I, |
2806 DartEntry::InvokeFunction(function, args)); | 2759 DartEntry::InvokeFunction(function, args)); |
2807 if (::Dart_IsError(value)) | 2760 if (::Dart_IsError(value)) |
2808 return value; | 2761 return value; |
2809 result[i] = value; | 2762 result[i] = value; |
2810 } | 2763 } |
2811 return Api::Success(); | 2764 return Api::Success(); |
2812 } | 2765 } |
2813 } | 2766 } |
2814 return Api::NewError("Object does not implement the 'List' interface"); | 2767 return Api::NewError("Object does not implement the 'List' interface"); |
2815 } | 2768 } |
2816 } | 2769 } |
2817 | 2770 |
2818 | 2771 |
2819 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ | 2772 #define SET_LIST_ELEMENT(type, obj, index, value) \ |
2820 const type& array = type::Cast(obj); \ | 2773 const type& array = type::Cast(obj); \ |
2821 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ | 2774 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); \ |
2822 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ | 2775 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ |
2823 RETURN_TYPE_ERROR(isolate, value, Instance); \ | 2776 RETURN_TYPE_ERROR(I, value, Instance); \ |
2824 } \ | 2777 } \ |
2825 if ((index >= 0) && (index < array.Length())) { \ | 2778 if ((index >= 0) && (index < array.Length())) { \ |
2826 array.SetAt(index, value_obj); \ | 2779 array.SetAt(index, value_obj); \ |
2827 return Api::Success(); \ | 2780 return Api::Success(); \ |
2828 } \ | 2781 } \ |
2829 return Api::NewError("Invalid index passed in to set list element"); \ | 2782 return Api::NewError("Invalid index passed in to set list element"); \ |
2830 | 2783 |
2831 | 2784 |
2832 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 2785 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
2833 intptr_t index, | 2786 intptr_t index, |
2834 Dart_Handle value) { | 2787 Dart_Handle value) { |
2835 Isolate* isolate = Isolate::Current(); | 2788 DARTSCOPE(Thread::Current()); |
2836 DARTSCOPE(isolate); | 2789 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2837 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | |
2838 // If the list is immutable we call into Dart for the indexed setter to | 2790 // If the list is immutable we call into Dart for the indexed setter to |
2839 // get the unsupported operation exception as the result. | 2791 // get the unsupported operation exception as the result. |
2840 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { | 2792 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { |
2841 SET_LIST_ELEMENT(isolate, Array, obj, index, value); | 2793 SET_LIST_ELEMENT(Array, obj, index, value); |
2842 } else if (obj.IsGrowableObjectArray()) { | 2794 } else if (obj.IsGrowableObjectArray()) { |
2843 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); | 2795 SET_LIST_ELEMENT(GrowableObjectArray, obj, index, value); |
2844 } else if (obj.IsError()) { | 2796 } else if (obj.IsError()) { |
2845 return list; | 2797 return list; |
2846 } else { | 2798 } else { |
2847 CHECK_CALLBACK_STATE(isolate); | 2799 CHECK_CALLBACK_STATE(I); |
2848 | 2800 |
2849 // Check and handle a dart object that implements the List interface. | 2801 // Check and handle a dart object that implements the List interface. |
2850 const Instance& instance = | 2802 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2851 Instance::Handle(isolate, GetListInstance(isolate, obj)); | |
2852 if (!instance.IsNull()) { | 2803 if (!instance.IsNull()) { |
2853 const intptr_t kNumArgs = 3; | 2804 const intptr_t kNumArgs = 3; |
2854 ArgumentsDescriptor args_desc( | 2805 ArgumentsDescriptor args_desc( |
2855 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 2806 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
2856 const Function& function = Function::Handle( | 2807 const Function& function = Function::Handle(Z, |
2857 isolate, | |
2858 Resolver::ResolveDynamic(instance, | 2808 Resolver::ResolveDynamic(instance, |
2859 Symbols::AssignIndexToken(), | 2809 Symbols::AssignIndexToken(), |
2860 args_desc)); | 2810 args_desc)); |
2861 if (!function.IsNull()) { | 2811 if (!function.IsNull()) { |
2862 const Integer& index_obj = | 2812 const Integer& index_obj = Integer::Handle(Z, Integer::New(index)); |
2863 Integer::Handle(isolate, Integer::New(index)); | 2813 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); |
2864 const Object& value_obj = | |
2865 Object::Handle(isolate, Api::UnwrapHandle(value)); | |
2866 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 2814 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
2867 RETURN_TYPE_ERROR(isolate, value, Instance); | 2815 RETURN_TYPE_ERROR(I, value, Instance); |
2868 } | 2816 } |
2869 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2817 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
2870 args.SetAt(0, instance); | 2818 args.SetAt(0, instance); |
2871 args.SetAt(1, index_obj); | 2819 args.SetAt(1, index_obj); |
2872 args.SetAt(2, value_obj); | 2820 args.SetAt(2, value_obj); |
2873 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, | 2821 return Api::NewHandle(I, DartEntry::InvokeFunction(function, |
2874 args)); | 2822 args)); |
2875 } | 2823 } |
2876 } | 2824 } |
2877 return Api::NewError("Object does not implement the 'List' interface"); | 2825 return Api::NewError("Object does not implement the 'List' interface"); |
2878 } | 2826 } |
2879 } | 2827 } |
2880 | 2828 |
2881 | 2829 |
2882 static RawObject* ResolveConstructor(const char* current_func, | 2830 static RawObject* ResolveConstructor(const char* current_func, |
2883 const Class& cls, | 2831 const Class& cls, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2946 state->UnwindScopes(isolate->top_exit_frame_info()); | 2894 state->UnwindScopes(isolate->top_exit_frame_info()); |
2947 saved_exception = &Instance::Handle(raw_exception); | 2895 saved_exception = &Instance::Handle(raw_exception); |
2948 } | 2896 } |
2949 Exceptions::Throw(thread, *saved_exception); | 2897 Exceptions::Throw(thread, *saved_exception); |
2950 const String& message = String::Handle( | 2898 const String& message = String::Handle( |
2951 String::New("Exception was not thrown, internal error")); | 2899 String::New("Exception was not thrown, internal error")); |
2952 return ApiError::New(message); | 2900 return ApiError::New(message); |
2953 } | 2901 } |
2954 | 2902 |
2955 // TODO(sgjesse): value should always be smaller then 0xff. Add error handling. | 2903 // TODO(sgjesse): value should always be smaller then 0xff. Add error handling. |
2956 #define GET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ | 2904 #define GET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ |
2957 length) \ | |
2958 const type& array = type::Cast(obj); \ | 2905 const type& array = type::Cast(obj); \ |
2959 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 2906 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
2960 Object& element = Object::Handle(isolate); \ | 2907 Object& element = Object::Handle(Z); \ |
2961 for (int i = 0; i < length; i++) { \ | 2908 for (int i = 0; i < length; i++) { \ |
2962 element = array.At(offset + i); \ | 2909 element = array.At(offset + i); \ |
2963 if (!element.IsInteger()) { \ | 2910 if (!element.IsInteger()) { \ |
2964 return Api::NewHandle( \ | 2911 return Api::NewHandle(I, \ |
2965 isolate, ThrowArgumentError("List contains non-int elements")); \ | 2912 ThrowArgumentError("List contains non-int elements")); \ |
2966 \ | 2913 \ |
2967 } \ | 2914 } \ |
2968 const Integer& integer = Integer::Cast(element); \ | 2915 const Integer& integer = Integer::Cast(element); \ |
2969 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ | 2916 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ |
2970 ASSERT(integer.AsInt64Value() <= 0xff); \ | 2917 ASSERT(integer.AsInt64Value() <= 0xff); \ |
2971 } \ | 2918 } \ |
2972 return Api::Success(); \ | 2919 return Api::Success(); \ |
2973 } \ | 2920 } \ |
2974 return Api::NewError("Invalid length passed in to access array elements"); \ | 2921 return Api::NewError("Invalid length passed in to access array elements"); \ |
2975 | 2922 |
2976 template<typename T> | 2923 template<typename T> |
2977 static Dart_Handle CopyBytes(const T& array, | 2924 static Dart_Handle CopyBytes(const T& array, |
2978 intptr_t offset, | 2925 intptr_t offset, |
2979 uint8_t* native_array, | 2926 uint8_t* native_array, |
2980 intptr_t length) { | 2927 intptr_t length) { |
2981 ASSERT(array.ElementSizeInBytes() == 1); | 2928 ASSERT(array.ElementSizeInBytes() == 1); |
2982 NoSafepointScope no_safepoint; | 2929 NoSafepointScope no_safepoint; |
2983 memmove(native_array, | 2930 memmove(native_array, |
2984 reinterpret_cast<uint8_t*>(array.DataAddr(offset)), | 2931 reinterpret_cast<uint8_t*>(array.DataAddr(offset)), |
2985 length); | 2932 length); |
2986 return Api::Success(); | 2933 return Api::Success(); |
2987 } | 2934 } |
2988 | 2935 |
2989 | 2936 |
2990 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 2937 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
2991 intptr_t offset, | 2938 intptr_t offset, |
2992 uint8_t* native_array, | 2939 uint8_t* native_array, |
2993 intptr_t length) { | 2940 intptr_t length) { |
2994 Isolate* isolate = Isolate::Current(); | 2941 DARTSCOPE(Thread::Current()); |
2995 DARTSCOPE(isolate); | 2942 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2996 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | |
2997 if (obj.IsTypedData()) { | 2943 if (obj.IsTypedData()) { |
2998 const TypedData& array = TypedData::Cast(obj); | 2944 const TypedData& array = TypedData::Cast(obj); |
2999 if (array.ElementSizeInBytes() == 1) { | 2945 if (array.ElementSizeInBytes() == 1) { |
3000 if (!Utils::RangeCheck(offset, length, array.Length())) { | 2946 if (!Utils::RangeCheck(offset, length, array.Length())) { |
3001 return Api::NewError( | 2947 return Api::NewError( |
3002 "Invalid length passed in to access list elements"); | 2948 "Invalid length passed in to access list elements"); |
3003 } | 2949 } |
3004 return CopyBytes(array, offset, native_array, length); | 2950 return CopyBytes(array, offset, native_array, length); |
3005 } | 2951 } |
3006 } | 2952 } |
(...skipping 22 matching lines...) Expand all Loading... | |
3029 intptr_t data_offset = | 2975 intptr_t data_offset = |
3030 Smi::Value(TypedDataView::OffsetInBytes(view)) + offset; | 2976 Smi::Value(TypedDataView::OffsetInBytes(view)) + offset; |
3031 // Range check already performed on the view object. | 2977 // Range check already performed on the view object. |
3032 ASSERT(Utils::RangeCheck(data_offset, length, array.Length())); | 2978 ASSERT(Utils::RangeCheck(data_offset, length, array.Length())); |
3033 return CopyBytes(array, data_offset, native_array, length); | 2979 return CopyBytes(array, data_offset, native_array, length); |
3034 } | 2980 } |
3035 } | 2981 } |
3036 } | 2982 } |
3037 } | 2983 } |
3038 if (obj.IsArray()) { | 2984 if (obj.IsArray()) { |
3039 GET_LIST_ELEMENT_AS_BYTES(isolate, | 2985 GET_LIST_ELEMENT_AS_BYTES(Array, obj, native_array, offset, length); |
3040 Array, | |
3041 obj, | |
3042 native_array, | |
3043 offset, | |
3044 length); | |
3045 } | 2986 } |
3046 if (obj.IsGrowableObjectArray()) { | 2987 if (obj.IsGrowableObjectArray()) { |
3047 GET_LIST_ELEMENT_AS_BYTES(isolate, | 2988 GET_LIST_ELEMENT_AS_BYTES( |
3048 GrowableObjectArray, | 2989 GrowableObjectArray, obj, native_array, offset, length); |
3049 obj, | |
3050 native_array, | |
3051 offset, | |
3052 length); | |
3053 } | 2990 } |
3054 if (obj.IsError()) { | 2991 if (obj.IsError()) { |
3055 return list; | 2992 return list; |
3056 } | 2993 } |
3057 CHECK_CALLBACK_STATE(isolate); | 2994 CHECK_CALLBACK_STATE(I); |
3058 | 2995 |
3059 // Check and handle a dart object that implements the List interface. | 2996 // Check and handle a dart object that implements the List interface. |
3060 const Instance& instance = | 2997 const Instance& instance = |
3061 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2998 Instance::Handle(Z, GetListInstance(Z, obj)); |
3062 if (!instance.IsNull()) { | 2999 if (!instance.IsNull()) { |
3063 const int kNumArgs = 2; | 3000 const int kNumArgs = 2; |
3064 ArgumentsDescriptor args_desc( | 3001 ArgumentsDescriptor args_desc( |
3065 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 3002 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
3066 const Function& function = Function::Handle( | 3003 const Function& function = Function::Handle(Z, |
3067 isolate, | |
3068 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), args_desc)); | 3004 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), args_desc)); |
3069 if (!function.IsNull()) { | 3005 if (!function.IsNull()) { |
3070 Object& result = Object::Handle(isolate); | 3006 Object& result = Object::Handle(Z); |
3071 Integer& intobj = Integer::Handle(isolate); | 3007 Integer& intobj = Integer::Handle(Z); |
3072 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 3008 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
3073 args.SetAt(0, instance); // Set up the receiver as the first argument. | 3009 args.SetAt(0, instance); // Set up the receiver as the first argument. |
3074 for (int i = 0; i < length; i++) { | 3010 for (int i = 0; i < length; i++) { |
3075 HANDLESCOPE(isolate); | 3011 HANDLESCOPE(T); |
3076 intobj = Integer::New(offset + i); | 3012 intobj = Integer::New(offset + i); |
3077 args.SetAt(1, intobj); | 3013 args.SetAt(1, intobj); |
3078 result = DartEntry::InvokeFunction(function, args); | 3014 result = DartEntry::InvokeFunction(function, args); |
3079 if (result.IsError()) { | 3015 if (result.IsError()) { |
3080 return Api::NewHandle(isolate, result.raw()); | 3016 return Api::NewHandle(I, result.raw()); |
3081 } | 3017 } |
3082 if (!result.IsInteger()) { | 3018 if (!result.IsInteger()) { |
3083 return Api::NewError("%s expects the argument 'list' to be " | 3019 return Api::NewError("%s expects the argument 'list' to be " |
3084 "a List of int", CURRENT_FUNC); | 3020 "a List of int", CURRENT_FUNC); |
3085 } | 3021 } |
3086 const Integer& integer_result = Integer::Cast(result); | 3022 const Integer& integer_result = Integer::Cast(result); |
3087 ASSERT(integer_result.AsInt64Value() <= 0xff); | 3023 ASSERT(integer_result.AsInt64Value() <= 0xff); |
3088 // TODO(hpayer): value should always be smaller then 0xff. Add error | 3024 // TODO(hpayer): value should always be smaller then 0xff. Add error |
3089 // handling. | 3025 // handling. |
3090 native_array[i] = | 3026 native_array[i] = |
3091 static_cast<uint8_t>(integer_result.AsInt64Value() & 0xff); | 3027 static_cast<uint8_t>(integer_result.AsInt64Value() & 0xff); |
3092 } | 3028 } |
3093 return Api::Success(); | 3029 return Api::Success(); |
3094 } | 3030 } |
3095 } | 3031 } |
3096 return Api::NewError("Object does not implement the 'List' interface"); | 3032 return Api::NewError("Object does not implement the 'List' interface"); |
3097 } | 3033 } |
3098 | 3034 |
3099 | 3035 |
3100 #define SET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ | 3036 #define SET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ |
3101 length) \ | |
3102 const type& array = type::Cast(obj); \ | 3037 const type& array = type::Cast(obj); \ |
3103 Integer& integer = Integer::Handle(isolate); \ | 3038 Integer& integer = Integer::Handle(Z); \ |
3104 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 3039 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
3105 for (int i = 0; i < length; i++) { \ | 3040 for (int i = 0; i < length; i++) { \ |
3106 integer = Integer::New(native_array[i]); \ | 3041 integer = Integer::New(native_array[i]); \ |
3107 array.SetAt(offset + i, integer); \ | 3042 array.SetAt(offset + i, integer); \ |
3108 } \ | 3043 } \ |
3109 return Api::Success(); \ | 3044 return Api::Success(); \ |
3110 } \ | 3045 } \ |
3111 return Api::NewError("Invalid length passed in to set array elements"); \ | 3046 return Api::NewError("Invalid length passed in to set array elements"); \ |
3112 | 3047 |
3113 | 3048 |
3114 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, | 3049 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, |
3115 intptr_t offset, | 3050 intptr_t offset, |
3116 uint8_t* native_array, | 3051 uint8_t* native_array, |
3117 intptr_t length) { | 3052 intptr_t length) { |
3118 Isolate* isolate = Isolate::Current(); | 3053 DARTSCOPE(Thread::Current()); |
3119 DARTSCOPE(isolate); | 3054 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
3120 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | |
3121 if (obj.IsTypedData()) { | 3055 if (obj.IsTypedData()) { |
3122 const TypedData& array = TypedData::Cast(obj); | 3056 const TypedData& array = TypedData::Cast(obj); |
3123 if (array.ElementSizeInBytes() == 1) { | 3057 if (array.ElementSizeInBytes() == 1) { |
3124 if (Utils::RangeCheck(offset, length, array.Length())) { | 3058 if (Utils::RangeCheck(offset, length, array.Length())) { |
3125 NoSafepointScope no_safepoint; | 3059 NoSafepointScope no_safepoint; |
3126 memmove(reinterpret_cast<uint8_t*>(array.DataAddr(offset)), | 3060 memmove(reinterpret_cast<uint8_t*>(array.DataAddr(offset)), |
3127 native_array, | 3061 native_array, |
3128 length); | 3062 length); |
3129 return Api::Success(); | 3063 return Api::Success(); |
3130 } | 3064 } |
3131 return Api::NewError("Invalid length passed in to access list elements"); | 3065 return Api::NewError("Invalid length passed in to access list elements"); |
3132 } | 3066 } |
3133 } | 3067 } |
3134 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { | 3068 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { |
3135 // If the list is immutable we call into Dart for the indexed setter to | 3069 // If the list is immutable we call into Dart for the indexed setter to |
3136 // get the unsupported operation exception as the result. | 3070 // get the unsupported operation exception as the result. |
3137 SET_LIST_ELEMENT_AS_BYTES(isolate, | 3071 SET_LIST_ELEMENT_AS_BYTES(Array, obj, native_array, offset, length); |
3138 Array, | |
3139 obj, | |
3140 native_array, | |
3141 offset, | |
3142 length); | |
3143 } | 3072 } |
3144 if (obj.IsGrowableObjectArray()) { | 3073 if (obj.IsGrowableObjectArray()) { |
3145 SET_LIST_ELEMENT_AS_BYTES(isolate, | 3074 SET_LIST_ELEMENT_AS_BYTES( |
3146 GrowableObjectArray, | 3075 GrowableObjectArray, obj, native_array, offset, length); |
3147 obj, | |
3148 native_array, | |
3149 offset, | |
3150 length); | |
3151 } | 3076 } |
3152 if (obj.IsError()) { | 3077 if (obj.IsError()) { |
3153 return list; | 3078 return list; |
3154 } | 3079 } |
3155 CHECK_CALLBACK_STATE(isolate); | 3080 CHECK_CALLBACK_STATE(I); |
3156 | 3081 |
3157 // Check and handle a dart object that implements the List interface. | 3082 // Check and handle a dart object that implements the List interface. |
3158 const Instance& instance = | 3083 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
3159 Instance::Handle(isolate, GetListInstance(isolate, obj)); | |
3160 if (!instance.IsNull()) { | 3084 if (!instance.IsNull()) { |
3161 const int kNumArgs = 3; | 3085 const int kNumArgs = 3; |
3162 ArgumentsDescriptor args_desc( | 3086 ArgumentsDescriptor args_desc( |
3163 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 3087 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
3164 const Function& function = Function::Handle( | 3088 const Function& function = Function::Handle(Z, |
3165 isolate, | |
3166 Resolver::ResolveDynamic(instance, | 3089 Resolver::ResolveDynamic(instance, |
3167 Symbols::AssignIndexToken(), | 3090 Symbols::AssignIndexToken(), |
3168 args_desc)); | 3091 args_desc)); |
3169 if (!function.IsNull()) { | 3092 if (!function.IsNull()) { |
3170 Integer& indexobj = Integer::Handle(isolate); | 3093 Integer& indexobj = Integer::Handle(Z); |
3171 Integer& valueobj = Integer::Handle(isolate); | 3094 Integer& valueobj = Integer::Handle(Z); |
3172 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 3095 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
3173 args.SetAt(0, instance); // Set up the receiver as the first argument. | 3096 args.SetAt(0, instance); // Set up the receiver as the first argument. |
3174 for (int i = 0; i < length; i++) { | 3097 for (int i = 0; i < length; i++) { |
3175 indexobj = Integer::New(offset + i); | 3098 indexobj = Integer::New(offset + i); |
3176 valueobj = Integer::New(native_array[i]); | 3099 valueobj = Integer::New(native_array[i]); |
3177 args.SetAt(1, indexobj); | 3100 args.SetAt(1, indexobj); |
3178 args.SetAt(2, valueobj); | 3101 args.SetAt(2, valueobj); |
3179 const Object& result = Object::Handle( | 3102 const Object& result = Object::Handle(Z, |
3180 isolate, DartEntry::InvokeFunction(function, args)); | 3103 DartEntry::InvokeFunction(function, args)); |
3181 if (result.IsError()) { | 3104 if (result.IsError()) { |
3182 return Api::NewHandle(isolate, result.raw()); | 3105 return Api::NewHandle(I, result.raw()); |
3183 } | 3106 } |
3184 } | 3107 } |
3185 return Api::Success(); | 3108 return Api::Success(); |
3186 } | 3109 } |
3187 } | 3110 } |
3188 return Api::NewError("Object does not implement the 'List' interface"); | 3111 return Api::NewError("Object does not implement the 'List' interface"); |
3189 } | 3112 } |
3190 | 3113 |
3191 | 3114 |
3192 // --- Maps --- | 3115 // --- Maps --- |
3193 | 3116 |
3194 DART_EXPORT Dart_Handle Dart_MapGetAt(Dart_Handle map, Dart_Handle key) { | 3117 DART_EXPORT Dart_Handle Dart_MapGetAt(Dart_Handle map, Dart_Handle key) { |
3195 Isolate* isolate = Isolate::Current(); | 3118 DARTSCOPE(Thread::Current()); |
3196 DARTSCOPE(isolate); | 3119 CHECK_CALLBACK_STATE(I); |
3197 CHECK_CALLBACK_STATE(isolate); | 3120 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
3198 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(map)); | 3121 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
3199 const Instance& instance = | |
3200 Instance::Handle(isolate, GetMapInstance(isolate, obj)); | |
3201 if (!instance.IsNull()) { | 3122 if (!instance.IsNull()) { |
3202 const Object& key_obj = Object::Handle(Api::UnwrapHandle(key)); | 3123 const Object& key_obj = Object::Handle(Api::UnwrapHandle(key)); |
3203 if (!(key_obj.IsInstance() || key_obj.IsNull())) { | 3124 if (!(key_obj.IsInstance() || key_obj.IsNull())) { |
3204 return Api::NewError("Key is not an instance"); | 3125 return Api::NewError("Key is not an instance"); |
3205 } | 3126 } |
3206 return Api::NewHandle(isolate, Send1Arg( | 3127 return Api::NewHandle(I, |
3207 instance, | 3128 Send1Arg(instance, Symbols::IndexToken(), Instance::Cast(key_obj))); |
3208 Symbols::IndexToken(), | |
3209 Instance::Cast(key_obj))); | |
3210 } | 3129 } |
3211 return Api::NewError("Object does not implement the 'Map' interface"); | 3130 return Api::NewError("Object does not implement the 'Map' interface"); |
3212 } | 3131 } |
3213 | 3132 |
3214 | 3133 |
3215 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { | 3134 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { |
3216 Isolate* isolate = Isolate::Current(); | 3135 DARTSCOPE(Thread::Current()); |
3217 DARTSCOPE(isolate); | 3136 CHECK_CALLBACK_STATE(I); |
3218 CHECK_CALLBACK_STATE(isolate); | 3137 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
3219 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(map)); | 3138 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
3220 const Instance& instance = | |
3221 Instance::Handle(isolate, GetMapInstance(isolate, obj)); | |
3222 if (!instance.IsNull()) { | 3139 if (!instance.IsNull()) { |
3223 const Object& key_obj = Object::Handle(Api::UnwrapHandle(key)); | 3140 const Object& key_obj = Object::Handle(Z, Api::UnwrapHandle(key)); |
3224 if (!(key_obj.IsInstance() || key_obj.IsNull())) { | 3141 if (!(key_obj.IsInstance() || key_obj.IsNull())) { |
3225 return Api::NewError("Key is not an instance"); | 3142 return Api::NewError("Key is not an instance"); |
3226 } | 3143 } |
3227 return Api::NewHandle(isolate, Send1Arg( | 3144 return Api::NewHandle(I, Send1Arg( |
3228 instance, | 3145 instance, |
3229 String::Handle(isolate, String::New("containsKey")), | 3146 String::Handle(Z, String::New("containsKey")), |
3230 Instance::Cast(key_obj))); | 3147 Instance::Cast(key_obj))); |
3231 } | 3148 } |
3232 return Api::NewError("Object does not implement the 'Map' interface"); | 3149 return Api::NewError("Object does not implement the 'Map' interface"); |
3233 } | 3150 } |
3234 | 3151 |
3235 | 3152 |
3236 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { | 3153 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { |
3237 Isolate* isolate = Isolate::Current(); | 3154 DARTSCOPE(Thread::Current()); |
3238 DARTSCOPE(isolate); | 3155 CHECK_CALLBACK_STATE(I); |
3239 CHECK_CALLBACK_STATE(isolate); | 3156 Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
3240 Object& obj = Object::Handle(isolate, Api::UnwrapHandle(map)); | 3157 Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
3241 Instance& instance = | |
3242 Instance::Handle(isolate, GetMapInstance(isolate, obj)); | |
3243 if (!instance.IsNull()) { | 3158 if (!instance.IsNull()) { |
3244 const Object& iterator = Object::Handle(Send0Arg( | 3159 const Object& iterator = Object::Handle(Send0Arg( |
3245 instance, String::Handle(String::New("get:keys")))); | 3160 instance, String::Handle(Z, String::New("get:keys")))); |
3246 if (!iterator.IsInstance()) { | 3161 if (!iterator.IsInstance()) { |
3247 return Api::NewHandle(isolate, iterator.raw()); | 3162 return Api::NewHandle(I, iterator.raw()); |
3248 } | 3163 } |
3249 return Api::NewHandle(isolate, Send0Arg( | 3164 return Api::NewHandle(I, Send0Arg( |
3250 Instance::Cast(iterator), | 3165 Instance::Cast(iterator), |
3251 String::Handle(String::New("toList")))); | 3166 String::Handle(String::New("toList")))); |
3252 } | 3167 } |
3253 return Api::NewError("Object does not implement the 'Map' interface"); | 3168 return Api::NewError("Object does not implement the 'Map' interface"); |
3254 } | 3169 } |
3255 | 3170 |
3256 | 3171 |
3257 // --- Typed Data --- | 3172 // --- Typed Data --- |
3258 | 3173 |
3259 // Helper method to get the type of a TypedData object. | 3174 // Helper method to get the type of a TypedData object. |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3455 | 3370 |
3456 // Invoke the constructor and return the new object. | 3371 // Invoke the constructor and return the new object. |
3457 result = DartEntry::InvokeFunction(factory, args); | 3372 result = DartEntry::InvokeFunction(factory, args); |
3458 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); | 3373 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); |
3459 return Api::NewHandle(isolate, result.raw()); | 3374 return Api::NewHandle(isolate, result.raw()); |
3460 } | 3375 } |
3461 | 3376 |
3462 | 3377 |
3463 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, | 3378 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, |
3464 intptr_t length) { | 3379 intptr_t length) { |
3465 Isolate* isolate = Isolate::Current(); | 3380 DARTSCOPE(Thread::Current()); |
3466 DARTSCOPE(isolate); | 3381 CHECK_CALLBACK_STATE(I); |
3467 CHECK_CALLBACK_STATE(isolate); | |
3468 switch (type) { | 3382 switch (type) { |
3469 case Dart_TypedData_kByteData : | 3383 case Dart_TypedData_kByteData : |
3470 return NewByteData(isolate, length); | 3384 return NewByteData(I, length); |
3471 case Dart_TypedData_kInt8 : | 3385 case Dart_TypedData_kInt8 : |
3472 return NewTypedData(isolate, kTypedDataInt8ArrayCid, length); | 3386 return NewTypedData(I, kTypedDataInt8ArrayCid, length); |
3473 case Dart_TypedData_kUint8 : | 3387 case Dart_TypedData_kUint8 : |
3474 return NewTypedData(isolate, kTypedDataUint8ArrayCid, length); | 3388 return NewTypedData(I, kTypedDataUint8ArrayCid, length); |
3475 case Dart_TypedData_kUint8Clamped : | 3389 case Dart_TypedData_kUint8Clamped : |
3476 return NewTypedData(isolate, kTypedDataUint8ClampedArrayCid, length); | 3390 return NewTypedData(I, kTypedDataUint8ClampedArrayCid, length); |
3477 case Dart_TypedData_kInt16 : | 3391 case Dart_TypedData_kInt16 : |
3478 return NewTypedData(isolate, kTypedDataInt16ArrayCid, length); | 3392 return NewTypedData(I, kTypedDataInt16ArrayCid, length); |
3479 case Dart_TypedData_kUint16 : | 3393 case Dart_TypedData_kUint16 : |
3480 return NewTypedData(isolate, kTypedDataUint16ArrayCid, length); | 3394 return NewTypedData(I, kTypedDataUint16ArrayCid, length); |
3481 case Dart_TypedData_kInt32 : | 3395 case Dart_TypedData_kInt32 : |
3482 return NewTypedData(isolate, kTypedDataInt32ArrayCid, length); | 3396 return NewTypedData(I, kTypedDataInt32ArrayCid, length); |
3483 case Dart_TypedData_kUint32 : | 3397 case Dart_TypedData_kUint32 : |
3484 return NewTypedData(isolate, kTypedDataUint32ArrayCid, length); | 3398 return NewTypedData(I, kTypedDataUint32ArrayCid, length); |
3485 case Dart_TypedData_kInt64 : | 3399 case Dart_TypedData_kInt64 : |
3486 return NewTypedData(isolate, kTypedDataInt64ArrayCid, length); | 3400 return NewTypedData(I, kTypedDataInt64ArrayCid, length); |
3487 case Dart_TypedData_kUint64 : | 3401 case Dart_TypedData_kUint64 : |
3488 return NewTypedData(isolate, kTypedDataUint64ArrayCid, length); | 3402 return NewTypedData(I, kTypedDataUint64ArrayCid, length); |
3489 case Dart_TypedData_kFloat32 : | 3403 case Dart_TypedData_kFloat32 : |
3490 return NewTypedData(isolate, kTypedDataFloat32ArrayCid, length); | 3404 return NewTypedData(I, kTypedDataFloat32ArrayCid, length); |
3491 case Dart_TypedData_kFloat64 : | 3405 case Dart_TypedData_kFloat64 : |
3492 return NewTypedData(isolate, kTypedDataFloat64ArrayCid, length); | 3406 return NewTypedData(I, kTypedDataFloat64ArrayCid, length); |
3493 case Dart_TypedData_kFloat32x4: | 3407 case Dart_TypedData_kFloat32x4: |
3494 return NewTypedData(isolate, kTypedDataFloat32x4ArrayCid, length); | 3408 return NewTypedData(I, kTypedDataFloat32x4ArrayCid, length); |
3495 default: | 3409 default: |
3496 return Api::NewError("%s expects argument 'type' to be of 'TypedData'", | 3410 return Api::NewError("%s expects argument 'type' to be of 'TypedData'", |
3497 CURRENT_FUNC); | 3411 CURRENT_FUNC); |
3498 } | 3412 } |
3499 UNREACHABLE(); | 3413 UNREACHABLE(); |
3500 return Api::Null(); | 3414 return Api::Null(); |
3501 } | 3415 } |
3502 | 3416 |
3503 | 3417 |
3504 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( | 3418 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( |
3505 Dart_TypedData_Type type, | 3419 Dart_TypedData_Type type, |
3506 void* data, | 3420 void* data, |
3507 intptr_t length) { | 3421 intptr_t length) { |
3508 Isolate* isolate = Isolate::Current(); | 3422 DARTSCOPE(Thread::Current()); |
3509 DARTSCOPE(isolate); | |
3510 if (data == NULL && length != 0) { | 3423 if (data == NULL && length != 0) { |
3511 RETURN_NULL_ERROR(data); | 3424 RETURN_NULL_ERROR(data); |
3512 } | 3425 } |
3513 CHECK_CALLBACK_STATE(isolate); | 3426 CHECK_CALLBACK_STATE(I); |
3514 switch (type) { | 3427 switch (type) { |
3515 case Dart_TypedData_kByteData: | 3428 case Dart_TypedData_kByteData: |
3516 return NewExternalByteData(isolate, data, length); | 3429 return NewExternalByteData(I, data, length); |
3517 case Dart_TypedData_kInt8: | 3430 case Dart_TypedData_kInt8: |
3518 return NewExternalTypedData(isolate, | 3431 return NewExternalTypedData(I, |
3519 kExternalTypedDataInt8ArrayCid, | 3432 kExternalTypedDataInt8ArrayCid, data, length); |
3520 data, | |
3521 length); | |
3522 case Dart_TypedData_kUint8: | 3433 case Dart_TypedData_kUint8: |
3523 return NewExternalTypedData(isolate, | 3434 return NewExternalTypedData(I, |
3524 kExternalTypedDataUint8ArrayCid, | 3435 kExternalTypedDataUint8ArrayCid, data, length); |
3525 data, | |
3526 length); | |
3527 case Dart_TypedData_kUint8Clamped: | 3436 case Dart_TypedData_kUint8Clamped: |
3528 return NewExternalTypedData(isolate, | 3437 return NewExternalTypedData(I, |
3529 kExternalTypedDataUint8ClampedArrayCid, | 3438 kExternalTypedDataUint8ClampedArrayCid, data, length); |
3530 data, | |
3531 length); | |
3532 case Dart_TypedData_kInt16: | 3439 case Dart_TypedData_kInt16: |
3533 return NewExternalTypedData(isolate, | 3440 return NewExternalTypedData(I, |
3534 kExternalTypedDataInt16ArrayCid, | 3441 kExternalTypedDataInt16ArrayCid, data, length); |
3535 data, | |
3536 length); | |
3537 case Dart_TypedData_kUint16: | 3442 case Dart_TypedData_kUint16: |
3538 return NewExternalTypedData(isolate, | 3443 return NewExternalTypedData(I, |
3539 kExternalTypedDataUint16ArrayCid, | 3444 kExternalTypedDataUint16ArrayCid, data, length); |
3540 data, | |
3541 length); | |
3542 case Dart_TypedData_kInt32: | 3445 case Dart_TypedData_kInt32: |
3543 return NewExternalTypedData(isolate, | 3446 return NewExternalTypedData(I, |
3544 kExternalTypedDataInt32ArrayCid, | 3447 kExternalTypedDataInt32ArrayCid, data, length); |
3545 data, | |
3546 length); | |
3547 case Dart_TypedData_kUint32: | 3448 case Dart_TypedData_kUint32: |
3548 return NewExternalTypedData(isolate, | 3449 return NewExternalTypedData(I, |
3549 kExternalTypedDataUint32ArrayCid, | 3450 kExternalTypedDataUint32ArrayCid, data, length); |
3550 data, | |
3551 length); | |
3552 case Dart_TypedData_kInt64: | 3451 case Dart_TypedData_kInt64: |
3553 return NewExternalTypedData(isolate, | 3452 return NewExternalTypedData(I, |
3554 kExternalTypedDataInt64ArrayCid, | 3453 kExternalTypedDataInt64ArrayCid, data, length); |
3555 data, | |
3556 length); | |
3557 case Dart_TypedData_kUint64: | 3454 case Dart_TypedData_kUint64: |
3558 return NewExternalTypedData(isolate, | 3455 return NewExternalTypedData(I, |
3559 kExternalTypedDataUint64ArrayCid, | 3456 kExternalTypedDataUint64ArrayCid, data, length); |
3560 data, | |
3561 length); | |
3562 case Dart_TypedData_kFloat32: | 3457 case Dart_TypedData_kFloat32: |
3563 return NewExternalTypedData(isolate, | 3458 return NewExternalTypedData(I, |
3564 kExternalTypedDataFloat32ArrayCid, | 3459 kExternalTypedDataFloat32ArrayCid, data, length); |
3565 data, | |
3566 length); | |
3567 case Dart_TypedData_kFloat64: | 3460 case Dart_TypedData_kFloat64: |
3568 return NewExternalTypedData(isolate, | 3461 return NewExternalTypedData(I, |
3569 kExternalTypedDataFloat64ArrayCid, | 3462 kExternalTypedDataFloat64ArrayCid, data, length); |
3570 data, | |
3571 length); | |
3572 case Dart_TypedData_kFloat32x4: | 3463 case Dart_TypedData_kFloat32x4: |
3573 return NewExternalTypedData(isolate, | 3464 return NewExternalTypedData(I, |
3574 kExternalTypedDataFloat32x4ArrayCid, | 3465 kExternalTypedDataFloat32x4ArrayCid, data, length); |
3575 data, | |
3576 length); | |
3577 default: | 3466 default: |
3578 return Api::NewError("%s expects argument 'type' to be of" | 3467 return Api::NewError("%s expects argument 'type' to be of" |
3579 " 'external TypedData'", CURRENT_FUNC); | 3468 " 'external TypedData'", CURRENT_FUNC); |
3580 } | 3469 } |
3581 UNREACHABLE(); | 3470 UNREACHABLE(); |
3582 return Api::Null(); | 3471 return Api::Null(); |
3583 } | 3472 } |
3584 | 3473 |
3585 | 3474 |
3586 static RawObject* GetByteBufferConstructor(Isolate* isolate, | 3475 static RawObject* GetByteBufferConstructor(Isolate* isolate, |
3587 const String& class_name, | 3476 const String& class_name, |
3588 const String& constructor_name, | 3477 const String& constructor_name, |
3589 intptr_t num_args) { | 3478 intptr_t num_args) { |
3590 const Library& lib = | 3479 const Library& lib = |
3591 Library::Handle(isolate->object_store()->typed_data_library()); | 3480 Library::Handle(isolate->object_store()->typed_data_library()); |
3592 ASSERT(!lib.IsNull()); | 3481 ASSERT(!lib.IsNull()); |
3593 const Class& cls = Class::Handle( | 3482 const Class& cls = Class::Handle( |
3594 isolate, lib.LookupClassAllowPrivate(class_name)); | 3483 isolate, lib.LookupClassAllowPrivate(class_name)); |
3595 ASSERT(!cls.IsNull()); | 3484 ASSERT(!cls.IsNull()); |
3596 return ResolveConstructor(CURRENT_FUNC, | 3485 return ResolveConstructor(CURRENT_FUNC, |
3597 cls, | 3486 cls, |
3598 class_name, | 3487 class_name, |
3599 constructor_name, | 3488 constructor_name, |
3600 num_args); | 3489 num_args); |
3601 } | 3490 } |
3602 | 3491 |
3603 | 3492 |
3604 DART_EXPORT Dart_Handle Dart_NewByteBuffer(Dart_Handle typed_data) { | 3493 DART_EXPORT Dart_Handle Dart_NewByteBuffer(Dart_Handle typed_data) { |
3605 Isolate* isolate = Isolate::Current(); | 3494 DARTSCOPE(Thread::Current()); |
3606 DARTSCOPE(isolate); | |
3607 intptr_t class_id = Api::ClassId(typed_data); | 3495 intptr_t class_id = Api::ClassId(typed_data); |
3608 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3496 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
3609 !RawObject::IsTypedDataViewClassId(class_id) && | 3497 !RawObject::IsTypedDataViewClassId(class_id) && |
3610 !RawObject::IsTypedDataClassId(class_id)) { | 3498 !RawObject::IsTypedDataClassId(class_id)) { |
3611 RETURN_TYPE_ERROR(isolate, typed_data, 'TypedData'); | 3499 RETURN_TYPE_ERROR(I, typed_data, 'TypedData'); |
3612 } | 3500 } |
3613 Object& result = Object::Handle(isolate); | 3501 Object& result = Object::Handle(Z); |
3614 result = GetByteBufferConstructor(isolate, | 3502 result = GetByteBufferConstructor(I, |
3615 Symbols::_ByteBuffer(), | 3503 Symbols::_ByteBuffer(), |
3616 Symbols::_ByteBufferDot_New(), | 3504 Symbols::_ByteBufferDot_New(), |
3617 1); | 3505 1); |
3618 ASSERT(!result.IsNull()); | 3506 ASSERT(!result.IsNull()); |
3619 ASSERT(result.IsFunction()); | 3507 ASSERT(result.IsFunction()); |
3620 const Function& factory = Function::Cast(result); | 3508 const Function& factory = Function::Cast(result); |
3621 ASSERT(!factory.IsGenerativeConstructor()); | 3509 ASSERT(!factory.IsGenerativeConstructor()); |
3622 | 3510 |
3623 // Create the argument list. | 3511 // Create the argument list. |
3624 const Array& args = Array::Handle(isolate, Array::New(2)); | 3512 const Array& args = Array::Handle(Z, Array::New(2)); |
3625 // Factories get type arguments. | 3513 // Factories get type arguments. |
3626 args.SetAt(0, Object::null_type_arguments()); | 3514 args.SetAt(0, Object::null_type_arguments()); |
3627 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(typed_data)); | 3515 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(typed_data)); |
3628 args.SetAt(1, obj); | 3516 args.SetAt(1, obj); |
3629 | 3517 |
3630 // Invoke the factory constructor and return the new object. | 3518 // Invoke the factory constructor and return the new object. |
3631 result = DartEntry::InvokeFunction(factory, args); | 3519 result = DartEntry::InvokeFunction(factory, args); |
3632 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); | 3520 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); |
3633 return Api::NewHandle(isolate, result.raw()); | 3521 return Api::NewHandle(I, result.raw()); |
3634 } | 3522 } |
3635 | 3523 |
3636 | 3524 |
3637 // Structure to record acquired typed data for verification purposes. | 3525 // Structure to record acquired typed data for verification purposes. |
3638 class AcquiredData { | 3526 class AcquiredData { |
3639 public: | 3527 public: |
3640 AcquiredData(void* data, intptr_t size_in_bytes, bool copy) | 3528 AcquiredData(void* data, intptr_t size_in_bytes, bool copy) |
3641 : size_in_bytes_(size_in_bytes), data_(data), data_copy_(NULL) { | 3529 : size_in_bytes_(size_in_bytes), data_(data), data_copy_(NULL) { |
3642 if (copy) { | 3530 if (copy) { |
3643 data_copy_ = malloc(size_in_bytes_); | 3531 data_copy_ = malloc(size_in_bytes_); |
(...skipping 20 matching lines...) Expand all Loading... | |
3664 void* data_copy_; | 3552 void* data_copy_; |
3665 | 3553 |
3666 DISALLOW_COPY_AND_ASSIGN(AcquiredData); | 3554 DISALLOW_COPY_AND_ASSIGN(AcquiredData); |
3667 }; | 3555 }; |
3668 | 3556 |
3669 | 3557 |
3670 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, | 3558 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, |
3671 Dart_TypedData_Type* type, | 3559 Dart_TypedData_Type* type, |
3672 void** data, | 3560 void** data, |
3673 intptr_t* len) { | 3561 intptr_t* len) { |
3674 Thread* thread = Thread::Current(); | 3562 DARTSCOPE(Thread::Current()); |
3675 Isolate* isolate = thread->isolate(); | |
3676 DARTSCOPE(isolate); | |
3677 intptr_t class_id = Api::ClassId(object); | 3563 intptr_t class_id = Api::ClassId(object); |
3678 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3564 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
3679 !RawObject::IsTypedDataViewClassId(class_id) && | 3565 !RawObject::IsTypedDataViewClassId(class_id) && |
3680 !RawObject::IsTypedDataClassId(class_id)) { | 3566 !RawObject::IsTypedDataClassId(class_id)) { |
3681 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); | 3567 RETURN_TYPE_ERROR(I, object, 'TypedData'); |
3682 } | 3568 } |
3683 if (type == NULL) { | 3569 if (type == NULL) { |
3684 RETURN_NULL_ERROR(type); | 3570 RETURN_NULL_ERROR(type); |
3685 } | 3571 } |
3686 if (data == NULL) { | 3572 if (data == NULL) { |
3687 RETURN_NULL_ERROR(data); | 3573 RETURN_NULL_ERROR(data); |
3688 } | 3574 } |
3689 if (len == NULL) { | 3575 if (len == NULL) { |
3690 RETURN_NULL_ERROR(len); | 3576 RETURN_NULL_ERROR(len); |
3691 } | 3577 } |
3692 // Get the type of typed data object. | 3578 // Get the type of typed data object. |
3693 *type = GetType(class_id); | 3579 *type = GetType(class_id); |
3694 intptr_t length = 0; | 3580 intptr_t length = 0; |
3695 intptr_t size_in_bytes = 0; | 3581 intptr_t size_in_bytes = 0; |
3696 void* data_tmp = NULL; | 3582 void* data_tmp = NULL; |
3697 bool external = false; | 3583 bool external = false; |
3698 // If it is an external typed data object just return the data field. | 3584 // If it is an external typed data object just return the data field. |
3699 if (RawObject::IsExternalTypedDataClassId(class_id)) { | 3585 if (RawObject::IsExternalTypedDataClassId(class_id)) { |
3700 const ExternalTypedData& obj = | 3586 const ExternalTypedData& obj = |
3701 Api::UnwrapExternalTypedDataHandle(isolate, object); | 3587 Api::UnwrapExternalTypedDataHandle(I, object); |
3702 ASSERT(!obj.IsNull()); | 3588 ASSERT(!obj.IsNull()); |
3703 length = obj.Length(); | 3589 length = obj.Length(); |
3704 size_in_bytes = length * ExternalTypedData::ElementSizeInBytes(class_id); | 3590 size_in_bytes = length * ExternalTypedData::ElementSizeInBytes(class_id); |
3705 data_tmp = obj.DataAddr(0); | 3591 data_tmp = obj.DataAddr(0); |
3706 external = true; | 3592 external = true; |
3707 } else if (RawObject::IsTypedDataClassId(class_id)) { | 3593 } else if (RawObject::IsTypedDataClassId(class_id)) { |
3708 // Regular typed data object, set up some GC and API callback guards. | 3594 // Regular typed data object, set up some GC and API callback guards. |
3709 const TypedData& obj = Api::UnwrapTypedDataHandle(isolate, object); | 3595 const TypedData& obj = Api::UnwrapTypedDataHandle(I, object); |
3710 ASSERT(!obj.IsNull()); | 3596 ASSERT(!obj.IsNull()); |
3711 length = obj.Length(); | 3597 length = obj.Length(); |
3712 size_in_bytes = length * TypedData::ElementSizeInBytes(class_id); | 3598 size_in_bytes = length * TypedData::ElementSizeInBytes(class_id); |
3713 thread->IncrementNoSafepointScopeDepth(); | 3599 T->IncrementNoSafepointScopeDepth(); |
3714 START_NO_CALLBACK_SCOPE(isolate); | 3600 START_NO_CALLBACK_SCOPE(I); |
3715 data_tmp = obj.DataAddr(0); | 3601 data_tmp = obj.DataAddr(0); |
3716 } else { | 3602 } else { |
3717 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); | 3603 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); |
3718 const Instance& view_obj = Api::UnwrapInstanceHandle(isolate, object); | 3604 const Instance& view_obj = Api::UnwrapInstanceHandle(I, object); |
3719 ASSERT(!view_obj.IsNull()); | 3605 ASSERT(!view_obj.IsNull()); |
3720 Smi& val = Smi::Handle(); | 3606 Smi& val = Smi::Handle(); |
3721 val ^= TypedDataView::Length(view_obj); | 3607 val ^= TypedDataView::Length(view_obj); |
3722 length = val.Value(); | 3608 length = val.Value(); |
3723 size_in_bytes = length * TypedDataView::ElementSizeInBytes(class_id); | 3609 size_in_bytes = length * TypedDataView::ElementSizeInBytes(class_id); |
3724 val ^= TypedDataView::OffsetInBytes(view_obj); | 3610 val ^= TypedDataView::OffsetInBytes(view_obj); |
3725 intptr_t offset_in_bytes = val.Value(); | 3611 intptr_t offset_in_bytes = val.Value(); |
3726 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj)); | 3612 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj)); |
3727 thread->IncrementNoSafepointScopeDepth(); | 3613 T->IncrementNoSafepointScopeDepth(); |
3728 START_NO_CALLBACK_SCOPE(isolate); | 3614 START_NO_CALLBACK_SCOPE(I); |
3729 if (TypedData::IsTypedData(obj)) { | 3615 if (TypedData::IsTypedData(obj)) { |
3730 const TypedData& data_obj = TypedData::Cast(obj); | 3616 const TypedData& data_obj = TypedData::Cast(obj); |
3731 data_tmp = data_obj.DataAddr(offset_in_bytes); | 3617 data_tmp = data_obj.DataAddr(offset_in_bytes); |
3732 } else { | 3618 } else { |
3733 ASSERT(ExternalTypedData::IsExternalTypedData(obj)); | 3619 ASSERT(ExternalTypedData::IsExternalTypedData(obj)); |
3734 const ExternalTypedData& data_obj = ExternalTypedData::Cast(obj); | 3620 const ExternalTypedData& data_obj = ExternalTypedData::Cast(obj); |
3735 data_tmp = data_obj.DataAddr(offset_in_bytes); | 3621 data_tmp = data_obj.DataAddr(offset_in_bytes); |
3736 external = true; | 3622 external = true; |
3737 } | 3623 } |
3738 } | 3624 } |
3739 if (FLAG_verify_acquired_data) { | 3625 if (FLAG_verify_acquired_data) { |
3740 if (external) { | 3626 if (external) { |
3741 ASSERT(!isolate->heap()->Contains(reinterpret_cast<uword>(data_tmp))); | 3627 ASSERT(!I->heap()->Contains(reinterpret_cast<uword>(data_tmp))); |
3742 } else { | 3628 } else { |
3743 ASSERT(isolate->heap()->Contains(reinterpret_cast<uword>(data_tmp))); | 3629 ASSERT(I->heap()->Contains(reinterpret_cast<uword>(data_tmp))); |
3744 } | 3630 } |
3745 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 3631 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
3746 WeakTable* table = isolate->api_state()->acquired_table(); | 3632 WeakTable* table = I->api_state()->acquired_table(); |
3747 intptr_t current = table->GetValue(obj.raw()); | 3633 intptr_t current = table->GetValue(obj.raw()); |
3748 if (current != 0) { | 3634 if (current != 0) { |
3749 return Api::NewError("Data was already acquired for this object."); | 3635 return Api::NewError("Data was already acquired for this object."); |
3750 } | 3636 } |
3751 // Do not make a copy if the data is external. Some callers expect external | 3637 // Do not make a copy if the data is external. Some callers expect external |
3752 // data to remain in place, even though the API spec doesn't guarantee it. | 3638 // data to remain in place, even though the API spec doesn't guarantee it. |
3753 // TODO(koda/asiva): Make final decision and document it. | 3639 // TODO(koda/asiva): Make final decision and document it. |
3754 AcquiredData* ad = new AcquiredData(data_tmp, size_in_bytes, !external); | 3640 AcquiredData* ad = new AcquiredData(data_tmp, size_in_bytes, !external); |
3755 table->SetValue(obj.raw(), reinterpret_cast<intptr_t>(ad)); | 3641 table->SetValue(obj.raw(), reinterpret_cast<intptr_t>(ad)); |
3756 data_tmp = ad->GetData(); | 3642 data_tmp = ad->GetData(); |
3757 } | 3643 } |
3758 *data = data_tmp; | 3644 *data = data_tmp; |
3759 *len = length; | 3645 *len = length; |
3760 return Api::Success(); | 3646 return Api::Success(); |
3761 } | 3647 } |
3762 | 3648 |
3763 | 3649 |
3764 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { | 3650 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { |
3765 Thread* thread = Thread::Current(); | 3651 DARTSCOPE(Thread::Current()); |
3766 Isolate* isolate = thread->isolate(); | |
3767 DARTSCOPE(isolate); | |
3768 intptr_t class_id = Api::ClassId(object); | 3652 intptr_t class_id = Api::ClassId(object); |
3769 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3653 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
3770 !RawObject::IsTypedDataViewClassId(class_id) && | 3654 !RawObject::IsTypedDataViewClassId(class_id) && |
3771 !RawObject::IsTypedDataClassId(class_id)) { | 3655 !RawObject::IsTypedDataClassId(class_id)) { |
3772 RETURN_TYPE_ERROR(isolate, object, 'TypedData'); | 3656 RETURN_TYPE_ERROR(I, object, 'TypedData'); |
3773 } | 3657 } |
3774 if (!RawObject::IsExternalTypedDataClassId(class_id)) { | 3658 if (!RawObject::IsExternalTypedDataClassId(class_id)) { |
3775 thread->DecrementNoSafepointScopeDepth(); | 3659 T->DecrementNoSafepointScopeDepth(); |
3776 END_NO_CALLBACK_SCOPE(isolate); | 3660 END_NO_CALLBACK_SCOPE(I); |
3777 } | 3661 } |
3778 if (FLAG_verify_acquired_data) { | 3662 if (FLAG_verify_acquired_data) { |
3779 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 3663 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
3780 WeakTable* table = isolate->api_state()->acquired_table(); | 3664 WeakTable* table = I->api_state()->acquired_table(); |
3781 intptr_t current = table->GetValue(obj.raw()); | 3665 intptr_t current = table->GetValue(obj.raw()); |
3782 if (current == 0) { | 3666 if (current == 0) { |
3783 return Api::NewError("Data was not acquired for this object."); | 3667 return Api::NewError("Data was not acquired for this object."); |
3784 } | 3668 } |
3785 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current); | 3669 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current); |
3786 table->SetValue(obj.raw(), 0); // Delete entry from table. | 3670 table->SetValue(obj.raw(), 0); // Delete entry from table. |
3787 delete ad; | 3671 delete ad; |
3788 } | 3672 } |
3789 return Api::Success(); | 3673 return Api::Success(); |
3790 } | 3674 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3850 return ApiError::New(message); | 3734 return ApiError::New(message); |
3851 } | 3735 } |
3852 return constructor.raw(); | 3736 return constructor.raw(); |
3853 } | 3737 } |
3854 | 3738 |
3855 | 3739 |
3856 DART_EXPORT Dart_Handle Dart_New(Dart_Handle type, | 3740 DART_EXPORT Dart_Handle Dart_New(Dart_Handle type, |
3857 Dart_Handle constructor_name, | 3741 Dart_Handle constructor_name, |
3858 int number_of_arguments, | 3742 int number_of_arguments, |
3859 Dart_Handle* arguments) { | 3743 Dart_Handle* arguments) { |
3860 Isolate* isolate = Isolate::Current(); | 3744 DARTSCOPE(Thread::Current()); |
3861 DARTSCOPE(isolate); | 3745 CHECK_CALLBACK_STATE(I); |
3862 CHECK_CALLBACK_STATE(isolate); | 3746 Object& result = Object::Handle(Z); |
3863 Object& result = Object::Handle(isolate); | |
3864 | 3747 |
3865 if (number_of_arguments < 0) { | 3748 if (number_of_arguments < 0) { |
3866 return Api::NewError( | 3749 return Api::NewError( |
3867 "%s expects argument 'number_of_arguments' to be non-negative.", | 3750 "%s expects argument 'number_of_arguments' to be non-negative.", |
3868 CURRENT_FUNC); | 3751 CURRENT_FUNC); |
3869 } | 3752 } |
3870 | 3753 |
3871 // Get the class to instantiate. | 3754 // Get the class to instantiate. |
3872 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type)); | 3755 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type)); |
3873 if (unchecked_type.IsNull() || !unchecked_type.IsType()) { | 3756 if (unchecked_type.IsNull() || !unchecked_type.IsType()) { |
3874 RETURN_TYPE_ERROR(isolate, type, Type); | 3757 RETURN_TYPE_ERROR(I, type, Type); |
3875 } | 3758 } |
3876 Type& type_obj = Type::Handle(); | 3759 Type& type_obj = Type::Handle(); |
3877 type_obj ^= unchecked_type.raw(); | 3760 type_obj ^= unchecked_type.raw(); |
3878 if (!type_obj.IsFinalized()) { | 3761 if (!type_obj.IsFinalized()) { |
3879 return Api::NewError( | 3762 return Api::NewError( |
3880 "%s expects argument 'type' to be a fully resolved type.", | 3763 "%s expects argument 'type' to be a fully resolved type.", |
3881 CURRENT_FUNC); | 3764 CURRENT_FUNC); |
3882 } | 3765 } |
3883 Class& cls = Class::Handle(isolate, type_obj.type_class()); | 3766 Class& cls = Class::Handle(Z, type_obj.type_class()); |
3884 TypeArguments& type_arguments = | 3767 TypeArguments& type_arguments = |
3885 TypeArguments::Handle(isolate, type_obj.arguments()); | 3768 TypeArguments::Handle(Z, type_obj.arguments()); |
3886 | 3769 |
3887 const String& base_constructor_name = String::Handle(isolate, cls.Name()); | 3770 const String& base_constructor_name = String::Handle(Z, cls.Name()); |
3888 | 3771 |
3889 // And get the name of the constructor to invoke. | 3772 // And get the name of the constructor to invoke. |
3890 String& dot_name = String::Handle(isolate); | 3773 String& dot_name = String::Handle(Z); |
3891 result = Api::UnwrapHandle(constructor_name); | 3774 result = Api::UnwrapHandle(constructor_name); |
3892 if (result.IsNull()) { | 3775 if (result.IsNull()) { |
3893 dot_name = Symbols::Dot().raw(); | 3776 dot_name = Symbols::Dot().raw(); |
3894 } else if (result.IsString()) { | 3777 } else if (result.IsString()) { |
3895 dot_name = String::Concat(Symbols::Dot(), String::Cast(result)); | 3778 dot_name = String::Concat(Symbols::Dot(), String::Cast(result)); |
3896 } else { | 3779 } else { |
3897 RETURN_TYPE_ERROR(isolate, constructor_name, String); | 3780 RETURN_TYPE_ERROR(I, constructor_name, String); |
3898 } | 3781 } |
3899 | 3782 |
3900 // Resolve the constructor. | 3783 // Resolve the constructor. |
3901 String& constr_name = | 3784 String& constr_name = |
3902 String::Handle(String::Concat(base_constructor_name, dot_name)); | 3785 String::Handle(String::Concat(base_constructor_name, dot_name)); |
3903 result = ResolveConstructor("Dart_New", | 3786 result = ResolveConstructor("Dart_New", |
3904 cls, | 3787 cls, |
3905 base_constructor_name, | 3788 base_constructor_name, |
3906 constr_name, | 3789 constr_name, |
3907 number_of_arguments); | 3790 number_of_arguments); |
3908 if (result.IsError()) { | 3791 if (result.IsError()) { |
3909 return Api::NewHandle(isolate, result.raw()); | 3792 return Api::NewHandle(I, result.raw()); |
3910 } | 3793 } |
3911 ASSERT(result.IsFunction()); | 3794 ASSERT(result.IsFunction()); |
3912 Function& constructor = Function::Handle(isolate); | 3795 Function& constructor = Function::Handle(Z); |
3913 constructor ^= result.raw(); | 3796 constructor ^= result.raw(); |
3914 | 3797 |
3915 Instance& new_object = Instance::Handle(isolate); | 3798 Instance& new_object = Instance::Handle(Z); |
3916 if (constructor.IsRedirectingFactory()) { | 3799 if (constructor.IsRedirectingFactory()) { |
3917 ClassFinalizer::ResolveRedirectingFactory(cls, constructor); | 3800 ClassFinalizer::ResolveRedirectingFactory(cls, constructor); |
3918 Type& redirect_type = Type::Handle(constructor.RedirectionType()); | 3801 Type& redirect_type = Type::Handle(constructor.RedirectionType()); |
3919 constructor = constructor.RedirectionTarget(); | 3802 constructor = constructor.RedirectionTarget(); |
3920 if (constructor.IsNull()) { | 3803 if (constructor.IsNull()) { |
3921 ASSERT(redirect_type.IsMalformed()); | 3804 ASSERT(redirect_type.IsMalformed()); |
3922 return Api::NewHandle(isolate, redirect_type.error()); | 3805 return Api::NewHandle(I, redirect_type.error()); |
3923 } | 3806 } |
3924 | 3807 |
3925 if (!redirect_type.IsInstantiated()) { | 3808 if (!redirect_type.IsInstantiated()) { |
3926 // The type arguments of the redirection type are instantiated from the | 3809 // The type arguments of the redirection type are instantiated from the |
3927 // type arguments of the type argument. | 3810 // type arguments of the type argument. |
3928 Error& bound_error = Error::Handle(); | 3811 Error& bound_error = Error::Handle(); |
3929 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, | 3812 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, |
3930 &bound_error); | 3813 &bound_error); |
3931 if (!bound_error.IsNull()) { | 3814 if (!bound_error.IsNull()) { |
3932 return Api::NewHandle(isolate, bound_error.raw()); | 3815 return Api::NewHandle(I, bound_error.raw()); |
3933 } | 3816 } |
3934 redirect_type ^= redirect_type.Canonicalize(); | 3817 redirect_type ^= redirect_type.Canonicalize(); |
3935 } | 3818 } |
3936 | 3819 |
3937 type_obj = redirect_type.raw(); | 3820 type_obj = redirect_type.raw(); |
3938 type_arguments = redirect_type.arguments(); | 3821 type_arguments = redirect_type.arguments(); |
3939 | 3822 |
3940 cls = type_obj.type_class(); | 3823 cls = type_obj.type_class(); |
3941 } | 3824 } |
3942 if (constructor.IsGenerativeConstructor()) { | 3825 if (constructor.IsGenerativeConstructor()) { |
3943 // Create the new object. | 3826 // Create the new object. |
3944 new_object = Instance::New(cls); | 3827 new_object = Instance::New(cls); |
3945 } | 3828 } |
3946 | 3829 |
3947 // Create the argument list. | 3830 // Create the argument list. |
3948 intptr_t arg_index = 0; | 3831 intptr_t arg_index = 0; |
3949 int extra_args = (constructor.IsGenerativeConstructor() ? 2 : 1); | 3832 int extra_args = (constructor.IsGenerativeConstructor() ? 2 : 1); |
3950 const Array& args = | 3833 const Array& args = |
3951 Array::Handle(isolate, Array::New(number_of_arguments + extra_args)); | 3834 Array::Handle(Z, Array::New(number_of_arguments + extra_args)); |
3952 if (constructor.IsGenerativeConstructor()) { | 3835 if (constructor.IsGenerativeConstructor()) { |
3953 // Constructors get the uninitialized object and a constructor phase. | 3836 // Constructors get the uninitialized object and a constructor phase. |
3954 if (!type_arguments.IsNull()) { | 3837 if (!type_arguments.IsNull()) { |
3955 // The type arguments will be null if the class has no type parameters, in | 3838 // The type arguments will be null if the class has no type parameters, in |
3956 // which case the following call would fail because there is no slot | 3839 // which case the following call would fail because there is no slot |
3957 // reserved in the object for the type vector. | 3840 // reserved in the object for the type vector. |
3958 new_object.SetTypeArguments(type_arguments); | 3841 new_object.SetTypeArguments(type_arguments); |
3959 } | 3842 } |
3960 args.SetAt(arg_index++, new_object); | 3843 args.SetAt(arg_index++, new_object); |
3961 args.SetAt(arg_index++, | 3844 args.SetAt(arg_index++, Smi::Handle(Z, Smi::New(Function::kCtorPhaseAll))); |
3962 Smi::Handle(isolate, Smi::New(Function::kCtorPhaseAll))); | |
3963 } else { | 3845 } else { |
3964 // Factories get type arguments. | 3846 // Factories get type arguments. |
3965 args.SetAt(arg_index++, type_arguments); | 3847 args.SetAt(arg_index++, type_arguments); |
3966 } | 3848 } |
3967 Object& argument = Object::Handle(isolate); | 3849 Object& argument = Object::Handle(Z); |
3968 for (int i = 0; i < number_of_arguments; i++) { | 3850 for (int i = 0; i < number_of_arguments; i++) { |
3969 argument = Api::UnwrapHandle(arguments[i]); | 3851 argument = Api::UnwrapHandle(arguments[i]); |
3970 if (!argument.IsNull() && !argument.IsInstance()) { | 3852 if (!argument.IsNull() && !argument.IsInstance()) { |
3971 if (argument.IsError()) { | 3853 if (argument.IsError()) { |
3972 return Api::NewHandle(isolate, argument.raw()); | 3854 return Api::NewHandle(I, argument.raw()); |
3973 } else { | 3855 } else { |
3974 return Api::NewError( | 3856 return Api::NewError( |
3975 "%s expects arguments[%d] to be an Instance handle.", | 3857 "%s expects arguments[%d] to be an Instance handle.", |
3976 CURRENT_FUNC, i); | 3858 CURRENT_FUNC, i); |
3977 } | 3859 } |
3978 } | 3860 } |
3979 args.SetAt(arg_index++, argument); | 3861 args.SetAt(arg_index++, argument); |
3980 } | 3862 } |
3981 | 3863 |
3982 // Invoke the constructor and return the new object. | 3864 // Invoke the constructor and return the new object. |
3983 result = DartEntry::InvokeFunction(constructor, args); | 3865 result = DartEntry::InvokeFunction(constructor, args); |
3984 if (result.IsError()) { | 3866 if (result.IsError()) { |
3985 return Api::NewHandle(isolate, result.raw()); | 3867 return Api::NewHandle(I, result.raw()); |
3986 } | 3868 } |
3987 | 3869 |
3988 if (constructor.IsGenerativeConstructor()) { | 3870 if (constructor.IsGenerativeConstructor()) { |
3989 ASSERT(result.IsNull()); | 3871 ASSERT(result.IsNull()); |
3990 } else { | 3872 } else { |
3991 ASSERT(result.IsNull() || result.IsInstance()); | 3873 ASSERT(result.IsNull() || result.IsInstance()); |
3992 new_object ^= result.raw(); | 3874 new_object ^= result.raw(); |
3993 } | 3875 } |
3994 return Api::NewHandle(isolate, new_object.raw()); | 3876 return Api::NewHandle(I, new_object.raw()); |
3995 } | 3877 } |
3996 | 3878 |
3997 | 3879 |
3998 static RawInstance* AllocateObject(Isolate* isolate, const Class& cls) { | 3880 static RawInstance* AllocateObject(Isolate* isolate, const Class& cls) { |
3999 if (!cls.is_fields_marked_nullable()) { | 3881 if (!cls.is_fields_marked_nullable()) { |
4000 // Mark all fields as nullable. | 3882 // Mark all fields as nullable. |
4001 Class& iterate_cls = Class::Handle(isolate, cls.raw()); | 3883 Class& iterate_cls = Class::Handle(isolate, cls.raw()); |
4002 Field& field = Field::Handle(isolate); | 3884 Field& field = Field::Handle(isolate); |
4003 Array& fields = Array::Handle(isolate); | 3885 Array& fields = Array::Handle(isolate); |
4004 while (!iterate_cls.IsNull()) { | 3886 while (!iterate_cls.IsNull()) { |
(...skipping 10 matching lines...) Expand all Loading... | |
4015 } | 3897 } |
4016 } | 3898 } |
4017 } | 3899 } |
4018 | 3900 |
4019 // Allocate an object for the given class. | 3901 // Allocate an object for the given class. |
4020 return Instance::New(cls); | 3902 return Instance::New(cls); |
4021 } | 3903 } |
4022 | 3904 |
4023 | 3905 |
4024 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { | 3906 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { |
4025 Isolate* isolate = Isolate::Current(); | 3907 DARTSCOPE(Thread::Current()); |
4026 DARTSCOPE(isolate); | 3908 CHECK_CALLBACK_STATE(I); |
4027 CHECK_CALLBACK_STATE(isolate); | |
4028 | 3909 |
4029 const Type& type_obj = Api::UnwrapTypeHandle(isolate, type); | 3910 const Type& type_obj = Api::UnwrapTypeHandle(I, type); |
4030 // Get the class to instantiate. | 3911 // Get the class to instantiate. |
4031 if (type_obj.IsNull()) { | 3912 if (type_obj.IsNull()) { |
4032 RETURN_TYPE_ERROR(isolate, type, Type); | 3913 RETURN_TYPE_ERROR(I, type, Type); |
4033 } | 3914 } |
4034 const Class& cls = Class::Handle(isolate, type_obj.type_class()); | 3915 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
4035 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); | 3916 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(I)); |
4036 if (!error.IsNull()) { | 3917 if (!error.IsNull()) { |
4037 // An error occurred, return error object. | 3918 // An error occurred, return error object. |
4038 return Api::NewHandle(isolate, error.raw()); | 3919 return Api::NewHandle(I, error.raw()); |
4039 } | 3920 } |
4040 return Api::NewHandle(isolate, AllocateObject(isolate, cls)); | 3921 return Api::NewHandle(I, AllocateObject(I, cls)); |
4041 } | 3922 } |
4042 | 3923 |
4043 | 3924 |
4044 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( | 3925 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( |
4045 Dart_Handle type, | 3926 Dart_Handle type, |
4046 intptr_t num_native_fields, | 3927 intptr_t num_native_fields, |
4047 const intptr_t* native_fields) { | 3928 const intptr_t* native_fields) { |
4048 Isolate* isolate = Isolate::Current(); | 3929 DARTSCOPE(Thread::Current()); |
4049 DARTSCOPE(isolate); | 3930 CHECK_CALLBACK_STATE(I); |
4050 CHECK_CALLBACK_STATE(isolate); | |
4051 | 3931 |
4052 const Type& type_obj = Api::UnwrapTypeHandle(isolate, type); | 3932 const Type& type_obj = Api::UnwrapTypeHandle(I, type); |
4053 // Get the class to instantiate. | 3933 // Get the class to instantiate. |
4054 if (type_obj.IsNull()) { | 3934 if (type_obj.IsNull()) { |
4055 RETURN_TYPE_ERROR(isolate, type, Type); | 3935 RETURN_TYPE_ERROR(I, type, Type); |
4056 } | 3936 } |
4057 if (native_fields == NULL) { | 3937 if (native_fields == NULL) { |
4058 RETURN_NULL_ERROR(native_fields); | 3938 RETURN_NULL_ERROR(native_fields); |
4059 } | 3939 } |
4060 const Class& cls = Class::Handle(isolate, type_obj.type_class()); | 3940 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
4061 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); | 3941 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(I)); |
4062 if (!error.IsNull()) { | 3942 if (!error.IsNull()) { |
4063 // An error occurred, return error object. | 3943 // An error occurred, return error object. |
4064 return Api::NewHandle(isolate, error.raw()); | 3944 return Api::NewHandle(I, error.raw()); |
4065 } | 3945 } |
4066 if (num_native_fields != cls.num_native_fields()) { | 3946 if (num_native_fields != cls.num_native_fields()) { |
4067 return Api::NewError( | 3947 return Api::NewError( |
4068 "%s: invalid number of native fields %" Pd " passed in, expected %d", | 3948 "%s: invalid number of native fields %" Pd " passed in, expected %d", |
4069 CURRENT_FUNC, num_native_fields, cls.num_native_fields()); | 3949 CURRENT_FUNC, num_native_fields, cls.num_native_fields()); |
4070 } | 3950 } |
4071 const Instance& instance = Instance::Handle(isolate, | 3951 const Instance& instance = Instance::Handle(Z, AllocateObject(I, cls)); |
4072 AllocateObject(isolate, cls)); | |
4073 instance.SetNativeFields(num_native_fields, native_fields); | 3952 instance.SetNativeFields(num_native_fields, native_fields); |
4074 return Api::NewHandle(isolate, instance.raw()); | 3953 return Api::NewHandle(I, instance.raw()); |
4075 } | 3954 } |
4076 | 3955 |
4077 | 3956 |
4078 static Dart_Handle SetupArguments(Isolate* isolate, | 3957 static Dart_Handle SetupArguments(Isolate* isolate, |
4079 int num_args, | 3958 int num_args, |
4080 Dart_Handle* arguments, | 3959 Dart_Handle* arguments, |
4081 int extra_args, | 3960 int extra_args, |
4082 Array* args) { | 3961 Array* args) { |
4083 // Check for malformed arguments in the arguments list. | 3962 // Check for malformed arguments in the arguments list. |
4084 *args = Array::New(num_args + extra_args); | 3963 *args = Array::New(num_args + extra_args); |
(...skipping 13 matching lines...) Expand all Loading... | |
4098 args->SetAt((i + extra_args), arg); | 3977 args->SetAt((i + extra_args), arg); |
4099 } | 3978 } |
4100 return Api::Success(); | 3979 return Api::Success(); |
4101 } | 3980 } |
4102 | 3981 |
4103 | 3982 |
4104 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, | 3983 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, |
4105 Dart_Handle name, | 3984 Dart_Handle name, |
4106 int number_of_arguments, | 3985 int number_of_arguments, |
4107 Dart_Handle* arguments) { | 3986 Dart_Handle* arguments) { |
4108 Isolate* isolate = Isolate::Current(); | 3987 DARTSCOPE(Thread::Current()); |
4109 DARTSCOPE(isolate); | 3988 CHECK_CALLBACK_STATE(I); |
4110 CHECK_CALLBACK_STATE(isolate); | |
4111 | 3989 |
4112 if (number_of_arguments < 0) { | 3990 if (number_of_arguments < 0) { |
4113 return Api::NewError( | 3991 return Api::NewError( |
4114 "%s expects argument 'number_of_arguments' to be non-negative.", | 3992 "%s expects argument 'number_of_arguments' to be non-negative.", |
4115 CURRENT_FUNC); | 3993 CURRENT_FUNC); |
4116 } | 3994 } |
4117 const String& constructor_name = Api::UnwrapStringHandle(isolate, name); | 3995 const String& constructor_name = Api::UnwrapStringHandle(I, name); |
4118 if (constructor_name.IsNull()) { | 3996 if (constructor_name.IsNull()) { |
4119 RETURN_TYPE_ERROR(isolate, name, String); | 3997 RETURN_TYPE_ERROR(I, name, String); |
4120 } | 3998 } |
4121 const Instance& instance = Api::UnwrapInstanceHandle(isolate, object); | 3999 const Instance& instance = Api::UnwrapInstanceHandle(I, object); |
4122 if (instance.IsNull()) { | 4000 if (instance.IsNull()) { |
4123 RETURN_TYPE_ERROR(isolate, object, Instance); | 4001 RETURN_TYPE_ERROR(I, object, Instance); |
4124 } | 4002 } |
4125 | 4003 |
4126 // Since we have allocated an object it would mean that the type | 4004 // Since we have allocated an object it would mean that the type |
4127 // is finalized. | 4005 // is finalized. |
4128 // TODO(asiva): How do we ensure that a constructor is not called more than | 4006 // TODO(asiva): How do we ensure that a constructor is not called more than |
4129 // once for the same object. | 4007 // once for the same object. |
4130 | 4008 |
4131 // Construct name of the constructor to invoke. | 4009 // Construct name of the constructor to invoke. |
4132 const Type& type_obj = Type::Handle(isolate, instance.GetType()); | 4010 const Type& type_obj = Type::Handle(Z, instance.GetType()); |
4133 const Class& cls = Class::Handle(isolate, type_obj.type_class()); | 4011 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
4134 const String& class_name = String::Handle(isolate, cls.Name()); | 4012 const String& class_name = String::Handle(Z, cls.Name()); |
4135 const Array& strings = Array::Handle(Array::New(3)); | 4013 const Array& strings = Array::Handle(Z, Array::New(3)); |
4136 strings.SetAt(0, class_name); | 4014 strings.SetAt(0, class_name); |
4137 strings.SetAt(1, Symbols::Dot()); | 4015 strings.SetAt(1, Symbols::Dot()); |
4138 strings.SetAt(2, constructor_name); | 4016 strings.SetAt(2, constructor_name); |
4139 const String& dot_name = String::Handle(isolate, String::ConcatAll(strings)); | 4017 const String& dot_name = String::Handle(Z, String::ConcatAll(strings)); |
4140 const TypeArguments& type_arguments = | 4018 const TypeArguments& type_arguments = |
4141 TypeArguments::Handle(isolate, type_obj.arguments()); | 4019 TypeArguments::Handle(Z, type_obj.arguments()); |
4142 const Function& constructor = | 4020 const Function& constructor = |
4143 Function::Handle(isolate, cls.LookupFunctionAllowPrivate(dot_name)); | 4021 Function::Handle(Z, cls.LookupFunctionAllowPrivate(dot_name)); |
4144 const int extra_args = 2; | 4022 const int extra_args = 2; |
4145 if (!constructor.IsNull() && | 4023 if (!constructor.IsNull() && |
4146 constructor.IsGenerativeConstructor() && | 4024 constructor.IsGenerativeConstructor() && |
4147 constructor.AreValidArgumentCounts(number_of_arguments + extra_args, | 4025 constructor.AreValidArgumentCounts(number_of_arguments + extra_args, |
4148 0, | 4026 0, |
4149 NULL)) { | 4027 NULL)) { |
4150 // Create the argument list. | 4028 // Create the argument list. |
4151 // Constructors get the uninitialized object and a constructor phase. | 4029 // Constructors get the uninitialized object and a constructor phase. |
4152 if (!type_arguments.IsNull()) { | 4030 if (!type_arguments.IsNull()) { |
4153 // The type arguments will be null if the class has no type | 4031 // The type arguments will be null if the class has no type |
4154 // parameters, in which case the following call would fail | 4032 // parameters, in which case the following call would fail |
4155 // because there is no slot reserved in the object for the | 4033 // because there is no slot reserved in the object for the |
4156 // type vector. | 4034 // type vector. |
4157 instance.SetTypeArguments(type_arguments); | 4035 instance.SetTypeArguments(type_arguments); |
4158 } | 4036 } |
4159 Dart_Handle result; | 4037 Dart_Handle result; |
4160 Array& args = Array::Handle(isolate); | 4038 Array& args = Array::Handle(Z); |
4161 result = SetupArguments(isolate, | 4039 result = SetupArguments(I, |
4162 number_of_arguments, | 4040 number_of_arguments, arguments, extra_args, &args); |
4163 arguments, | |
4164 extra_args, | |
4165 &args); | |
4166 if (!::Dart_IsError(result)) { | 4041 if (!::Dart_IsError(result)) { |
4167 args.SetAt(0, instance); | 4042 args.SetAt(0, instance); |
4168 args.SetAt(1, Smi::Handle(isolate, Smi::New(Function::kCtorPhaseAll))); | 4043 args.SetAt(1, Smi::Handle(Z, Smi::New(Function::kCtorPhaseAll))); |
4169 const Object& retval = Object::Handle( | 4044 const Object& retval = Object::Handle(Z, |
4170 isolate, | |
4171 DartEntry::InvokeFunction(constructor, args)); | 4045 DartEntry::InvokeFunction(constructor, args)); |
4172 if (retval.IsError()) { | 4046 if (retval.IsError()) { |
4173 result = Api::NewHandle(isolate, retval.raw()); | 4047 result = Api::NewHandle(I, retval.raw()); |
4174 } else { | 4048 } else { |
4175 result = Api::NewHandle(isolate, instance.raw()); | 4049 result = Api::NewHandle(I, instance.raw()); |
4176 } | 4050 } |
4177 } | 4051 } |
4178 return result; | 4052 return result; |
4179 } | 4053 } |
4180 return Api::NewError( | 4054 return Api::NewError( |
4181 "%s expects argument 'name' to be a valid constructor.", | 4055 "%s expects argument 'name' to be a valid constructor.", |
4182 CURRENT_FUNC); | 4056 CURRENT_FUNC); |
4183 } | 4057 } |
4184 | 4058 |
4185 | 4059 |
4186 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 4060 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
4187 Dart_Handle name, | 4061 Dart_Handle name, |
4188 int number_of_arguments, | 4062 int number_of_arguments, |
4189 Dart_Handle* arguments) { | 4063 Dart_Handle* arguments) { |
4190 Thread* thread = Thread::Current(); | 4064 DARTSCOPE(Thread::Current()); |
4191 Isolate* isolate = thread->isolate(); | 4065 CHECK_CALLBACK_STATE(I); |
4192 DARTSCOPE(isolate); | |
4193 CHECK_CALLBACK_STATE(isolate); | |
4194 // TODO(turnidge): This is a bit simplistic. It overcounts when | 4066 // TODO(turnidge): This is a bit simplistic. It overcounts when |
4195 // other operations (gc, compilation) are active. | 4067 // other operations (gc, compilation) are active. |
4196 TIMERSCOPE(thread, time_dart_execution); | 4068 TIMERSCOPE(T, time_dart_execution); |
4197 | 4069 |
4198 const String& function_name = Api::UnwrapStringHandle(isolate, name); | 4070 const String& function_name = Api::UnwrapStringHandle(I, name); |
4199 if (function_name.IsNull()) { | 4071 if (function_name.IsNull()) { |
4200 RETURN_TYPE_ERROR(isolate, name, String); | 4072 RETURN_TYPE_ERROR(I, name, String); |
4201 } | 4073 } |
4202 if (number_of_arguments < 0) { | 4074 if (number_of_arguments < 0) { |
4203 return Api::NewError( | 4075 return Api::NewError( |
4204 "%s expects argument 'number_of_arguments' to be non-negative.", | 4076 "%s expects argument 'number_of_arguments' to be non-negative.", |
4205 CURRENT_FUNC); | 4077 CURRENT_FUNC); |
4206 } | 4078 } |
4207 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); | 4079 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(target)); |
4208 if (obj.IsError()) { | 4080 if (obj.IsError()) { |
4209 return target; | 4081 return target; |
4210 } | 4082 } |
4211 Dart_Handle result; | 4083 Dart_Handle result; |
4212 Array& args = Array::Handle(isolate); | 4084 Array& args = Array::Handle(Z); |
4213 if (obj.IsType()) { | 4085 if (obj.IsType()) { |
4214 if (!Type::Cast(obj).IsFinalized()) { | 4086 if (!Type::Cast(obj).IsFinalized()) { |
4215 return Api::NewError( | 4087 return Api::NewError( |
4216 "%s expects argument 'target' to be a fully resolved type.", | 4088 "%s expects argument 'target' to be a fully resolved type.", |
4217 CURRENT_FUNC); | 4089 CURRENT_FUNC); |
4218 } | 4090 } |
4219 | 4091 |
4220 const Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); | 4092 const Class& cls = Class::Handle(Z, Type::Cast(obj).type_class()); |
4221 const Function& function = Function::Handle( | 4093 const Function& function = Function::Handle(Z, |
4222 isolate, | |
4223 Resolver::ResolveStaticAllowPrivate(cls, | 4094 Resolver::ResolveStaticAllowPrivate(cls, |
4224 function_name, | 4095 function_name, |
4225 number_of_arguments, | 4096 number_of_arguments, |
4226 Object::empty_array())); | 4097 Object::empty_array())); |
4227 if (function.IsNull()) { | 4098 if (function.IsNull()) { |
4228 const String& cls_name = String::Handle(isolate, cls.Name()); | 4099 const String& cls_name = String::Handle(Z, cls.Name()); |
4229 return Api::NewError("%s: did not find static method '%s.%s'.", | 4100 return Api::NewError("%s: did not find static method '%s.%s'.", |
4230 CURRENT_FUNC, | 4101 CURRENT_FUNC, |
4231 cls_name.ToCString(), | 4102 cls_name.ToCString(), |
4232 function_name.ToCString()); | 4103 function_name.ToCString()); |
4233 } | 4104 } |
4234 // Setup args and check for malformed arguments in the arguments list. | 4105 // Setup args and check for malformed arguments in the arguments list. |
4235 result = SetupArguments(isolate, number_of_arguments, arguments, 0, &args); | 4106 result = SetupArguments(I, number_of_arguments, arguments, 0, &args); |
4236 if (!::Dart_IsError(result)) { | 4107 if (!::Dart_IsError(result)) { |
4237 result = Api::NewHandle(isolate, | 4108 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args)); |
4238 DartEntry::InvokeFunction(function, args)); | |
4239 } | 4109 } |
4240 return result; | 4110 return result; |
4241 } else if (obj.IsNull() || obj.IsInstance()) { | 4111 } else if (obj.IsNull() || obj.IsInstance()) { |
4242 // Since we have allocated an object it would mean that the type of the | 4112 // Since we have allocated an object it would mean that the type of the |
4243 // receiver is already resolved and finalized, hence it is not necessary | 4113 // receiver is already resolved and finalized, hence it is not necessary |
4244 // to check here. | 4114 // to check here. |
4245 Instance& instance = Instance::Handle(isolate); | 4115 Instance& instance = Instance::Handle(Z); |
4246 instance ^= obj.raw(); | 4116 instance ^= obj.raw(); |
4247 ArgumentsDescriptor args_desc( | 4117 ArgumentsDescriptor args_desc( |
4248 Array::Handle(ArgumentsDescriptor::New(number_of_arguments + 1))); | 4118 Array::Handle(Z, ArgumentsDescriptor::New(number_of_arguments + 1))); |
4249 const Function& function = Function::Handle( | 4119 const Function& function = Function::Handle(Z, |
4250 isolate, | |
4251 Resolver::ResolveDynamic(instance, function_name, args_desc)); | 4120 Resolver::ResolveDynamic(instance, function_name, args_desc)); |
4252 if (function.IsNull()) { | 4121 if (function.IsNull()) { |
4253 // Setup args and check for malformed arguments in the arguments list. | 4122 // Setup args and check for malformed arguments in the arguments list. |
4254 result = SetupArguments(isolate, | 4123 result = SetupArguments(I, |
4255 number_of_arguments, | 4124 number_of_arguments, |
4256 arguments, | 4125 arguments, |
4257 1, | 4126 1, |
4258 &args); | 4127 &args); |
4259 if (!::Dart_IsError(result)) { | 4128 if (!::Dart_IsError(result)) { |
4260 args.SetAt(0, instance); | 4129 args.SetAt(0, instance); |
4261 const Array& args_descriptor = | 4130 const Array& args_descriptor = |
4262 Array::Handle(ArgumentsDescriptor::New(args.Length())); | 4131 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
4263 result = Api::NewHandle(isolate, | 4132 result = Api::NewHandle(I, |
4264 DartEntry::InvokeNoSuchMethod(instance, | 4133 DartEntry::InvokeNoSuchMethod(instance, |
4265 function_name, | 4134 function_name, |
4266 args, | 4135 args, |
4267 args_descriptor)); | 4136 args_descriptor)); |
4268 } | 4137 } |
4269 return result; | 4138 return result; |
4270 } | 4139 } |
4271 // Setup args and check for malformed arguments in the arguments list. | 4140 // Setup args and check for malformed arguments in the arguments list. |
4272 result = SetupArguments(isolate, number_of_arguments, arguments, 1, &args); | 4141 result = SetupArguments(I, number_of_arguments, arguments, 1, &args); |
4273 if (!::Dart_IsError(result)) { | 4142 if (!::Dart_IsError(result)) { |
4274 args.SetAt(0, instance); | 4143 args.SetAt(0, instance); |
4275 result = Api::NewHandle(isolate, | 4144 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args)); |
4276 DartEntry::InvokeFunction(function, args)); | |
4277 } | 4145 } |
4278 return result; | 4146 return result; |
4279 } else if (obj.IsLibrary()) { | 4147 } else if (obj.IsLibrary()) { |
4280 // Check whether class finalization is needed. | 4148 // Check whether class finalization is needed. |
4281 const Library& lib = Library::Cast(obj); | 4149 const Library& lib = Library::Cast(obj); |
4282 | 4150 |
4283 // Check that the library is loaded. | 4151 // Check that the library is loaded. |
4284 if (!lib.Loaded()) { | 4152 if (!lib.Loaded()) { |
4285 return Api::NewError( | 4153 return Api::NewError( |
4286 "%s expects library argument 'target' to be loaded.", | 4154 "%s expects library argument 'target' to be loaded.", |
4287 CURRENT_FUNC); | 4155 CURRENT_FUNC); |
4288 } | 4156 } |
4289 | 4157 |
4290 const Function& function = | 4158 const Function& function = |
4291 Function::Handle(isolate, | 4159 Function::Handle(Z, lib.LookupFunctionAllowPrivate(function_name)); |
4292 lib.LookupFunctionAllowPrivate(function_name)); | |
4293 if (function.IsNull()) { | 4160 if (function.IsNull()) { |
4294 return Api::NewError("%s: did not find top-level function '%s'.", | 4161 return Api::NewError("%s: did not find top-level function '%s'.", |
4295 CURRENT_FUNC, | 4162 CURRENT_FUNC, |
4296 function_name.ToCString()); | 4163 function_name.ToCString()); |
4297 } | 4164 } |
4298 // LookupFunctionAllowPrivate does not check argument arity, so we | 4165 // LookupFunctionAllowPrivate does not check argument arity, so we |
4299 // do it here. | 4166 // do it here. |
4300 String& error_message = String::Handle(); | 4167 String& error_message = String::Handle(Z); |
4301 if (!function.AreValidArgumentCounts(number_of_arguments, | 4168 if (!function.AreValidArgumentCounts(number_of_arguments, |
4302 0, | 4169 0, |
4303 &error_message)) { | 4170 &error_message)) { |
4304 return Api::NewError("%s: wrong argument count for function '%s': %s.", | 4171 return Api::NewError("%s: wrong argument count for function '%s': %s.", |
4305 CURRENT_FUNC, | 4172 CURRENT_FUNC, |
4306 function_name.ToCString(), | 4173 function_name.ToCString(), |
4307 error_message.ToCString()); | 4174 error_message.ToCString()); |
4308 } | 4175 } |
4309 // Setup args and check for malformed arguments in the arguments list. | 4176 // Setup args and check for malformed arguments in the arguments list. |
4310 result = SetupArguments(isolate, number_of_arguments, arguments, 0, &args); | 4177 result = SetupArguments(I, number_of_arguments, arguments, 0, &args); |
4311 if (!::Dart_IsError(result)) { | 4178 if (!::Dart_IsError(result)) { |
4312 result = Api::NewHandle(isolate, | 4179 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args)); |
4313 DartEntry::InvokeFunction(function, args)); | |
4314 } | 4180 } |
4315 return result; | 4181 return result; |
4316 } else { | 4182 } else { |
4317 return Api::NewError( | 4183 return Api::NewError( |
4318 "%s expects argument 'target' to be an object, type, or library.", | 4184 "%s expects argument 'target' to be an object, type, or library.", |
4319 CURRENT_FUNC); | 4185 CURRENT_FUNC); |
4320 } | 4186 } |
4321 } | 4187 } |
4322 | 4188 |
4323 | 4189 |
4324 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 4190 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
4325 int number_of_arguments, | 4191 int number_of_arguments, |
4326 Dart_Handle* arguments) { | 4192 Dart_Handle* arguments) { |
4327 Isolate* isolate = Isolate::Current(); | 4193 DARTSCOPE(Thread::Current()); |
4328 DARTSCOPE(isolate); | 4194 CHECK_CALLBACK_STATE(I); |
4329 CHECK_CALLBACK_STATE(isolate); | 4195 const Instance& closure_obj = Api::UnwrapInstanceHandle(I, closure); |
4330 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, closure); | |
4331 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) { | 4196 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) { |
4332 RETURN_TYPE_ERROR(isolate, closure, Instance); | 4197 RETURN_TYPE_ERROR(I, closure, Instance); |
4333 } | 4198 } |
4334 if (number_of_arguments < 0) { | 4199 if (number_of_arguments < 0) { |
4335 return Api::NewError( | 4200 return Api::NewError( |
4336 "%s expects argument 'number_of_arguments' to be non-negative.", | 4201 "%s expects argument 'number_of_arguments' to be non-negative.", |
4337 CURRENT_FUNC); | 4202 CURRENT_FUNC); |
4338 } | 4203 } |
4339 | 4204 |
4340 // Set up arguments to include the closure as the first argument. | 4205 // Set up arguments to include the closure as the first argument. |
4341 const Array& args = Array::Handle(isolate, | 4206 const Array& args = Array::Handle(Z, Array::New(number_of_arguments + 1)); |
4342 Array::New(number_of_arguments + 1)); | 4207 Object& obj = Object::Handle(Z); |
4343 Object& obj = Object::Handle(isolate); | |
4344 args.SetAt(0, closure_obj); | 4208 args.SetAt(0, closure_obj); |
4345 for (int i = 0; i < number_of_arguments; i++) { | 4209 for (int i = 0; i < number_of_arguments; i++) { |
4346 obj = Api::UnwrapHandle(arguments[i]); | 4210 obj = Api::UnwrapHandle(arguments[i]); |
4347 if (!obj.IsNull() && !obj.IsInstance()) { | 4211 if (!obj.IsNull() && !obj.IsInstance()) { |
4348 RETURN_TYPE_ERROR(isolate, arguments[i], Instance); | 4212 RETURN_TYPE_ERROR(I, arguments[i], Instance); |
4349 } | 4213 } |
4350 args.SetAt(i + 1, obj); | 4214 args.SetAt(i + 1, obj); |
4351 } | 4215 } |
4352 // Now try to invoke the closure. | 4216 // Now try to invoke the closure. |
4353 return Api::NewHandle(isolate, DartEntry::InvokeClosure(args)); | 4217 return Api::NewHandle(I, DartEntry::InvokeClosure(args)); |
4354 } | 4218 } |
4355 | 4219 |
4356 | 4220 |
4357 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 4221 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
4358 Isolate* isolate = Isolate::Current(); | 4222 DARTSCOPE(Thread::Current()); |
4359 DARTSCOPE(isolate); | 4223 CHECK_CALLBACK_STATE(I); |
4360 CHECK_CALLBACK_STATE(isolate); | |
4361 | 4224 |
4362 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 4225 const String& field_name = Api::UnwrapStringHandle(I, name); |
4363 if (field_name.IsNull()) { | 4226 if (field_name.IsNull()) { |
4364 RETURN_TYPE_ERROR(isolate, name, String); | 4227 RETURN_TYPE_ERROR(I, name, String); |
4365 } | 4228 } |
4366 | 4229 |
4367 Field& field = Field::Handle(isolate); | 4230 Field& field = Field::Handle(Z); |
4368 Function& getter = Function::Handle(isolate); | 4231 Function& getter = Function::Handle(Z); |
4369 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 4232 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(container)); |
4370 if (obj.IsNull()) { | 4233 if (obj.IsNull()) { |
4371 return Api::NewError("%s expects argument 'container' to be non-null.", | 4234 return Api::NewError("%s expects argument 'container' to be non-null.", |
4372 CURRENT_FUNC); | 4235 CURRENT_FUNC); |
4373 } else if (obj.IsType()) { | 4236 } else if (obj.IsType()) { |
4374 if (!Type::Cast(obj).IsFinalized()) { | 4237 if (!Type::Cast(obj).IsFinalized()) { |
4375 return Api::NewError( | 4238 return Api::NewError( |
4376 "%s expects argument 'container' to be a fully resolved type.", | 4239 "%s expects argument 'container' to be a fully resolved type.", |
4377 CURRENT_FUNC); | 4240 CURRENT_FUNC); |
4378 } | 4241 } |
4379 // To access a static field we may need to use the Field or the | 4242 // To access a static field we may need to use the Field or the |
4380 // getter Function. | 4243 // getter Function. |
4381 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); | 4244 Class& cls = Class::Handle(Z, Type::Cast(obj).type_class()); |
4382 | 4245 |
4383 field = cls.LookupStaticField(field_name); | 4246 field = cls.LookupStaticField(field_name); |
4384 if (field.IsNull() || field.IsUninitialized()) { | 4247 if (field.IsNull() || field.IsUninitialized()) { |
4385 const String& getter_name = | 4248 const String& getter_name = |
4386 String::Handle(isolate, Field::GetterName(field_name)); | 4249 String::Handle(Z, Field::GetterName(field_name)); |
4387 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 4250 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
4388 } | 4251 } |
4389 | 4252 |
4390 if (!getter.IsNull()) { | 4253 if (!getter.IsNull()) { |
4391 // Invoke the getter and return the result. | 4254 // Invoke the getter and return the result. |
4392 return Api::NewHandle( | 4255 return Api::NewHandle(I, |
4393 isolate, DartEntry::InvokeFunction(getter, Object::empty_array())); | 4256 DartEntry::InvokeFunction(getter, Object::empty_array())); |
4394 } else if (!field.IsNull()) { | 4257 } else if (!field.IsNull()) { |
4395 return Api::NewHandle(isolate, field.value()); | 4258 return Api::NewHandle(I, field.value()); |
4396 } else { | 4259 } else { |
4397 return Api::NewError("%s: did not find static field '%s'.", | 4260 return Api::NewError("%s: did not find static field '%s'.", |
4398 CURRENT_FUNC, field_name.ToCString()); | 4261 CURRENT_FUNC, field_name.ToCString()); |
4399 } | 4262 } |
4400 | 4263 |
4401 } else if (obj.IsInstance()) { | 4264 } else if (obj.IsInstance()) { |
4402 // Every instance field has a getter Function. Try to find the | 4265 // Every instance field has a getter Function. Try to find the |
4403 // getter in any superclass and use that function to access the | 4266 // getter in any superclass and use that function to access the |
4404 // field. | 4267 // field. |
4405 const Instance& instance = Instance::Cast(obj); | 4268 const Instance& instance = Instance::Cast(obj); |
4406 Class& cls = Class::Handle(isolate, instance.clazz()); | 4269 Class& cls = Class::Handle(Z, instance.clazz()); |
4407 String& getter_name = | 4270 String& getter_name = String::Handle(Z, Field::GetterName(field_name)); |
4408 String::Handle(isolate, Field::GetterName(field_name)); | |
4409 while (!cls.IsNull()) { | 4271 while (!cls.IsNull()) { |
4410 getter = cls.LookupDynamicFunctionAllowPrivate(getter_name); | 4272 getter = cls.LookupDynamicFunctionAllowPrivate(getter_name); |
4411 if (!getter.IsNull()) { | 4273 if (!getter.IsNull()) { |
4412 break; | 4274 break; |
4413 } | 4275 } |
4414 cls = cls.SuperClass(); | 4276 cls = cls.SuperClass(); |
4415 } | 4277 } |
4416 | 4278 |
4417 // Invoke the getter and return the result. | 4279 // Invoke the getter and return the result. |
4418 const int kNumArgs = 1; | 4280 const int kNumArgs = 1; |
4419 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 4281 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
4420 args.SetAt(0, instance); | 4282 args.SetAt(0, instance); |
4421 if (getter.IsNull()) { | 4283 if (getter.IsNull()) { |
4422 const Array& args_descriptor = | 4284 const Array& args_descriptor = |
4423 Array::Handle(ArgumentsDescriptor::New(args.Length())); | 4285 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
4424 return Api::NewHandle(isolate, | 4286 return Api::NewHandle(I, |
4425 DartEntry::InvokeNoSuchMethod(instance, | 4287 DartEntry::InvokeNoSuchMethod(instance, |
4426 getter_name, | 4288 getter_name, |
4427 args, | 4289 args, |
4428 args_descriptor)); | 4290 args_descriptor)); |
4429 } | 4291 } |
4430 return Api::NewHandle(isolate, DartEntry::InvokeFunction(getter, args)); | 4292 return Api::NewHandle(I, DartEntry::InvokeFunction(getter, args)); |
4431 | 4293 |
4432 } else if (obj.IsLibrary()) { | 4294 } else if (obj.IsLibrary()) { |
4433 // To access a top-level we may need to use the Field or the | 4295 // To access a top-level we may need to use the Field or the |
4434 // getter Function. The getter function may either be in the | 4296 // getter Function. The getter function may either be in the |
4435 // library or in the field's owner class, depending. | 4297 // library or in the field's owner class, depending. |
4436 const Library& lib = Library::Cast(obj); | 4298 const Library& lib = Library::Cast(obj); |
4437 // Check that the library is loaded. | 4299 // Check that the library is loaded. |
4438 if (!lib.Loaded()) { | 4300 if (!lib.Loaded()) { |
4439 return Api::NewError( | 4301 return Api::NewError( |
4440 "%s expects library argument 'container' to be loaded.", | 4302 "%s expects library argument 'container' to be loaded.", |
4441 CURRENT_FUNC); | 4303 CURRENT_FUNC); |
4442 } | 4304 } |
4443 field = lib.LookupFieldAllowPrivate(field_name); | 4305 field = lib.LookupFieldAllowPrivate(field_name); |
4444 if (field.IsNull()) { | 4306 if (field.IsNull()) { |
4445 // No field found and no ambiguity error. Check for a getter in the lib. | 4307 // No field found and no ambiguity error. Check for a getter in the lib. |
4446 const String& getter_name = | 4308 const String& getter_name = |
4447 String::Handle(isolate, Field::GetterName(field_name)); | 4309 String::Handle(Z, Field::GetterName(field_name)); |
4448 getter = lib.LookupFunctionAllowPrivate(getter_name); | 4310 getter = lib.LookupFunctionAllowPrivate(getter_name); |
4449 } else if (!field.IsNull() && field.IsUninitialized()) { | 4311 } else if (!field.IsNull() && field.IsUninitialized()) { |
4450 // A field was found. Check for a getter in the field's owner classs. | 4312 // A field was found. Check for a getter in the field's owner classs. |
4451 const Class& cls = Class::Handle(isolate, field.owner()); | 4313 const Class& cls = Class::Handle(Z, field.owner()); |
4452 const String& getter_name = | 4314 const String& getter_name = String::Handle(Z, |
4453 String::Handle(isolate, Field::GetterName(field_name)); | 4315 Field::GetterName(field_name)); |
4454 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 4316 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
4455 } | 4317 } |
4456 | 4318 |
4457 if (!getter.IsNull()) { | 4319 if (!getter.IsNull()) { |
4458 // Invoke the getter and return the result. | 4320 // Invoke the getter and return the result. |
4459 return Api::NewHandle( | 4321 return Api::NewHandle(I, |
4460 isolate, DartEntry::InvokeFunction(getter, Object::empty_array())); | 4322 DartEntry::InvokeFunction(getter, Object::empty_array())); |
4461 } | 4323 } |
4462 if (!field.IsNull()) { | 4324 if (!field.IsNull()) { |
4463 return Api::NewHandle(isolate, field.value()); | 4325 return Api::NewHandle(I, field.value()); |
4464 } | 4326 } |
4465 return Api::NewError("%s: did not find top-level variable '%s'.", | 4327 return Api::NewError("%s: did not find top-level variable '%s'.", |
4466 CURRENT_FUNC, field_name.ToCString()); | 4328 CURRENT_FUNC, field_name.ToCString()); |
4467 | 4329 |
4468 } else if (obj.IsError()) { | 4330 } else if (obj.IsError()) { |
4469 return container; | 4331 return container; |
4470 } else { | 4332 } else { |
4471 return Api::NewError( | 4333 return Api::NewError( |
4472 "%s expects argument 'container' to be an object, type, or library.", | 4334 "%s expects argument 'container' to be an object, type, or library.", |
4473 CURRENT_FUNC); | 4335 CURRENT_FUNC); |
4474 } | 4336 } |
4475 } | 4337 } |
4476 | 4338 |
4477 | 4339 |
4478 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, | 4340 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, |
4479 Dart_Handle name, | 4341 Dart_Handle name, |
4480 Dart_Handle value) { | 4342 Dart_Handle value) { |
4481 Isolate* isolate = Isolate::Current(); | 4343 DARTSCOPE(Thread::Current()); |
4482 DARTSCOPE(isolate); | 4344 CHECK_CALLBACK_STATE(I); |
4483 CHECK_CALLBACK_STATE(isolate); | |
4484 | 4345 |
4485 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 4346 const String& field_name = Api::UnwrapStringHandle(I, name); |
4486 if (field_name.IsNull()) { | 4347 if (field_name.IsNull()) { |
4487 RETURN_TYPE_ERROR(isolate, name, String); | 4348 RETURN_TYPE_ERROR(I, name, String); |
4488 } | 4349 } |
4489 | 4350 |
4490 // Since null is allowed for value, we don't use UnwrapInstanceHandle. | 4351 // Since null is allowed for value, we don't use UnwrapInstanceHandle. |
4491 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); | 4352 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); |
4492 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 4353 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
4493 RETURN_TYPE_ERROR(isolate, value, Instance); | 4354 RETURN_TYPE_ERROR(I, value, Instance); |
4494 } | 4355 } |
4495 Instance& value_instance = Instance::Handle(isolate); | 4356 Instance& value_instance = Instance::Handle(Z); |
4496 value_instance ^= value_obj.raw(); | 4357 value_instance ^= value_obj.raw(); |
4497 | 4358 |
4498 Field& field = Field::Handle(isolate); | 4359 Field& field = Field::Handle(Z); |
4499 Function& setter = Function::Handle(isolate); | 4360 Function& setter = Function::Handle(Z); |
4500 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 4361 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(container)); |
4501 if (obj.IsNull()) { | 4362 if (obj.IsNull()) { |
4502 return Api::NewError("%s expects argument 'container' to be non-null.", | 4363 return Api::NewError("%s expects argument 'container' to be non-null.", |
4503 CURRENT_FUNC); | 4364 CURRENT_FUNC); |
4504 } else if (obj.IsType()) { | 4365 } else if (obj.IsType()) { |
4505 if (!Type::Cast(obj).IsFinalized()) { | 4366 if (!Type::Cast(obj).IsFinalized()) { |
4506 return Api::NewError( | 4367 return Api::NewError( |
4507 "%s expects argument 'container' to be a fully resolved type.", | 4368 "%s expects argument 'container' to be a fully resolved type.", |
4508 CURRENT_FUNC); | 4369 CURRENT_FUNC); |
4509 } | 4370 } |
4510 | 4371 |
4511 // To access a static field we may need to use the Field or the | 4372 // To access a static field we may need to use the Field or the |
4512 // setter Function. | 4373 // setter Function. |
4513 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); | 4374 Class& cls = Class::Handle(Z, Type::Cast(obj).type_class()); |
4514 | 4375 |
4515 field = cls.LookupStaticField(field_name); | 4376 field = cls.LookupStaticField(field_name); |
4516 if (field.IsNull()) { | 4377 if (field.IsNull()) { |
4517 String& setter_name = | 4378 String& setter_name = String::Handle(Z, Field::SetterName(field_name)); |
4518 String::Handle(isolate, Field::SetterName(field_name)); | |
4519 setter = cls.LookupStaticFunctionAllowPrivate(setter_name); | 4379 setter = cls.LookupStaticFunctionAllowPrivate(setter_name); |
4520 } | 4380 } |
4521 | 4381 |
4522 if (!setter.IsNull()) { | 4382 if (!setter.IsNull()) { |
4523 // Invoke the setter and return the result. | 4383 // Invoke the setter and return the result. |
4524 const int kNumArgs = 1; | 4384 const int kNumArgs = 1; |
4525 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 4385 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
4526 args.SetAt(0, value_instance); | 4386 args.SetAt(0, value_instance); |
4527 const Object& result = | 4387 const Object& result = Object::Handle(Z, |
4528 Object::Handle(isolate, DartEntry::InvokeFunction(setter, args)); | 4388 DartEntry::InvokeFunction(setter, args)); |
4529 if (result.IsError()) { | 4389 if (result.IsError()) { |
4530 return Api::NewHandle(isolate, result.raw()); | 4390 return Api::NewHandle(I, result.raw()); |
4531 } else { | 4391 } else { |
4532 return Api::Success(); | 4392 return Api::Success(); |
4533 } | 4393 } |
4534 } else if (!field.IsNull()) { | 4394 } else if (!field.IsNull()) { |
4535 if (field.is_final()) { | 4395 if (field.is_final()) { |
4536 return Api::NewError("%s: cannot set final field '%s'.", | 4396 return Api::NewError("%s: cannot set final field '%s'.", |
4537 CURRENT_FUNC, field_name.ToCString()); | 4397 CURRENT_FUNC, field_name.ToCString()); |
4538 } else { | 4398 } else { |
4539 field.set_value(value_instance); | 4399 field.set_value(value_instance); |
4540 return Api::Success(); | 4400 return Api::Success(); |
4541 } | 4401 } |
4542 } else { | 4402 } else { |
4543 return Api::NewError("%s: did not find static field '%s'.", | 4403 return Api::NewError("%s: did not find static field '%s'.", |
4544 CURRENT_FUNC, field_name.ToCString()); | 4404 CURRENT_FUNC, field_name.ToCString()); |
4545 } | 4405 } |
4546 | 4406 |
4547 } else if (obj.IsInstance()) { | 4407 } else if (obj.IsInstance()) { |
4548 // Every instance field has a setter Function. Try to find the | 4408 // Every instance field has a setter Function. Try to find the |
4549 // setter in any superclass and use that function to access the | 4409 // setter in any superclass and use that function to access the |
4550 // field. | 4410 // field. |
4551 const Instance& instance = Instance::Cast(obj); | 4411 const Instance& instance = Instance::Cast(obj); |
4552 Class& cls = Class::Handle(isolate, instance.clazz()); | 4412 Class& cls = Class::Handle(Z, instance.clazz()); |
4553 String& setter_name = | 4413 String& setter_name = String::Handle(Z, Field::SetterName(field_name)); |
4554 String::Handle(isolate, Field::SetterName(field_name)); | |
4555 while (!cls.IsNull()) { | 4414 while (!cls.IsNull()) { |
4556 field = cls.LookupInstanceField(field_name); | 4415 field = cls.LookupInstanceField(field_name); |
4557 if (!field.IsNull() && field.is_final()) { | 4416 if (!field.IsNull() && field.is_final()) { |
4558 return Api::NewError("%s: cannot set final field '%s'.", | 4417 return Api::NewError("%s: cannot set final field '%s'.", |
4559 CURRENT_FUNC, field_name.ToCString()); | 4418 CURRENT_FUNC, field_name.ToCString()); |
4560 } | 4419 } |
4561 setter = cls.LookupDynamicFunctionAllowPrivate(setter_name); | 4420 setter = cls.LookupDynamicFunctionAllowPrivate(setter_name); |
4562 if (!setter.IsNull()) { | 4421 if (!setter.IsNull()) { |
4563 break; | 4422 break; |
4564 } | 4423 } |
4565 cls = cls.SuperClass(); | 4424 cls = cls.SuperClass(); |
4566 } | 4425 } |
4567 | 4426 |
4568 // Invoke the setter and return the result. | 4427 // Invoke the setter and return the result. |
4569 const int kNumArgs = 2; | 4428 const int kNumArgs = 2; |
4570 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 4429 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
4571 args.SetAt(0, instance); | 4430 args.SetAt(0, instance); |
4572 args.SetAt(1, value_instance); | 4431 args.SetAt(1, value_instance); |
4573 if (setter.IsNull()) { | 4432 if (setter.IsNull()) { |
4574 const Array& args_descriptor = | 4433 const Array& args_descriptor = |
4575 Array::Handle(ArgumentsDescriptor::New(args.Length())); | 4434 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
4576 return Api::NewHandle(isolate, | 4435 return Api::NewHandle(I, DartEntry::InvokeNoSuchMethod(instance, |
4577 DartEntry::InvokeNoSuchMethod(instance, | 4436 setter_name, |
4578 setter_name, | 4437 args, |
4579 args, | 4438 args_descriptor)); |
4580 args_descriptor)); | |
4581 } | 4439 } |
4582 return Api::NewHandle(isolate, DartEntry::InvokeFunction(setter, args)); | 4440 return Api::NewHandle(I, DartEntry::InvokeFunction(setter, args)); |
4583 | 4441 |
4584 } else if (obj.IsLibrary()) { | 4442 } else if (obj.IsLibrary()) { |
4585 // To access a top-level we may need to use the Field or the | 4443 // To access a top-level we may need to use the Field or the |
4586 // setter Function. The setter function may either be in the | 4444 // setter Function. The setter function may either be in the |
4587 // library or in the field's owner class, depending. | 4445 // library or in the field's owner class, depending. |
4588 const Library& lib = Library::Cast(obj); | 4446 const Library& lib = Library::Cast(obj); |
4589 // Check that the library is loaded. | 4447 // Check that the library is loaded. |
4590 if (!lib.Loaded()) { | 4448 if (!lib.Loaded()) { |
4591 return Api::NewError( | 4449 return Api::NewError( |
4592 "%s expects library argument 'container' to be loaded.", | 4450 "%s expects library argument 'container' to be loaded.", |
4593 CURRENT_FUNC); | 4451 CURRENT_FUNC); |
4594 } | 4452 } |
4595 field = lib.LookupFieldAllowPrivate(field_name); | 4453 field = lib.LookupFieldAllowPrivate(field_name); |
4596 if (field.IsNull()) { | 4454 if (field.IsNull()) { |
4597 const String& setter_name = | 4455 const String& setter_name = |
4598 String::Handle(isolate, Field::SetterName(field_name)); | 4456 String::Handle(Z, Field::SetterName(field_name)); |
4599 setter ^= lib.LookupFunctionAllowPrivate(setter_name); | 4457 setter ^= lib.LookupFunctionAllowPrivate(setter_name); |
4600 } | 4458 } |
4601 | 4459 |
4602 if (!setter.IsNull()) { | 4460 if (!setter.IsNull()) { |
4603 // Invoke the setter and return the result. | 4461 // Invoke the setter and return the result. |
4604 const int kNumArgs = 1; | 4462 const int kNumArgs = 1; |
4605 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 4463 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
4606 args.SetAt(0, value_instance); | 4464 args.SetAt(0, value_instance); |
4607 const Object& result = | 4465 const Object& result = |
4608 Object::Handle(isolate, DartEntry::InvokeFunction(setter, args)); | 4466 Object::Handle(Z, DartEntry::InvokeFunction(setter, args)); |
4609 if (result.IsError()) { | 4467 if (result.IsError()) { |
4610 return Api::NewHandle(isolate, result.raw()); | 4468 return Api::NewHandle(I, result.raw()); |
4611 } | 4469 } |
4612 return Api::Success(); | 4470 return Api::Success(); |
4613 } | 4471 } |
4614 if (!field.IsNull()) { | 4472 if (!field.IsNull()) { |
4615 if (field.is_final()) { | 4473 if (field.is_final()) { |
4616 return Api::NewError("%s: cannot set final top-level variable '%s'.", | 4474 return Api::NewError("%s: cannot set final top-level variable '%s'.", |
4617 CURRENT_FUNC, field_name.ToCString()); | 4475 CURRENT_FUNC, field_name.ToCString()); |
4618 } | 4476 } |
4619 field.set_value(value_instance); | 4477 field.set_value(value_instance); |
4620 return Api::Success(); | 4478 return Api::Success(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4708 Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace); | 4566 Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace); |
4709 return Api::NewError("Exception was not re thrown, internal error"); | 4567 return Api::NewError("Exception was not re thrown, internal error"); |
4710 } | 4568 } |
4711 | 4569 |
4712 | 4570 |
4713 // --- Native fields and functions --- | 4571 // --- Native fields and functions --- |
4714 | 4572 |
4715 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 4573 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
4716 Dart_Handle name, | 4574 Dart_Handle name, |
4717 int field_count) { | 4575 int field_count) { |
4718 Isolate* isolate = Isolate::Current(); | 4576 DARTSCOPE(Thread::Current()); |
4719 DARTSCOPE(isolate); | 4577 const String& cls_name = Api::UnwrapStringHandle(I, name); |
4720 const String& cls_name = Api::UnwrapStringHandle(isolate, name); | |
4721 if (cls_name.IsNull()) { | 4578 if (cls_name.IsNull()) { |
4722 RETURN_TYPE_ERROR(isolate, name, String); | 4579 RETURN_TYPE_ERROR(I, name, String); |
4723 } | 4580 } |
4724 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4581 const Library& lib = Api::UnwrapLibraryHandle(I, library); |
4725 if (lib.IsNull()) { | 4582 if (lib.IsNull()) { |
4726 RETURN_TYPE_ERROR(isolate, library, Library); | 4583 RETURN_TYPE_ERROR(I, library, Library); |
4727 } | 4584 } |
4728 if (!Utils::IsUint(16, field_count)) { | 4585 if (!Utils::IsUint(16, field_count)) { |
4729 return Api::NewError( | 4586 return Api::NewError( |
4730 "Invalid field_count passed to Dart_CreateNativeWrapperClass"); | 4587 "Invalid field_count passed to Dart_CreateNativeWrapperClass"); |
4731 } | 4588 } |
4732 CHECK_CALLBACK_STATE(isolate); | 4589 CHECK_CALLBACK_STATE(I); |
4733 | 4590 |
4734 String& cls_symbol = String::Handle(isolate, Symbols::New(cls_name)); | 4591 String& cls_symbol = String::Handle(Z, Symbols::New(cls_name)); |
4735 const Class& cls = Class::Handle( | 4592 const Class& cls = Class::Handle(Z, |
4736 isolate, Class::NewNativeWrapper(lib, cls_symbol, field_count)); | 4593 Class::NewNativeWrapper(lib, cls_symbol, field_count)); |
4737 if (cls.IsNull()) { | 4594 if (cls.IsNull()) { |
4738 return Api::NewError( | 4595 return Api::NewError( |
4739 "Unable to create native wrapper class : already exists"); | 4596 "Unable to create native wrapper class : already exists"); |
4740 } | 4597 } |
4741 return Api::NewHandle(isolate, cls.RareType()); | 4598 return Api::NewHandle(I, cls.RareType()); |
4742 } | 4599 } |
4743 | 4600 |
4744 | 4601 |
4745 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, | 4602 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, |
4746 int* count) { | 4603 int* count) { |
4747 Isolate* isolate = Isolate::Current(); | 4604 Isolate* isolate = Isolate::Current(); |
4748 CHECK_ISOLATE(isolate); | 4605 CHECK_ISOLATE(isolate); |
4749 ReusableObjectHandleScope reused_obj_handle(isolate); | 4606 ReusableObjectHandleScope reused_obj_handle(isolate); |
4750 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); | 4607 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); |
4751 if (instance.IsNull()) { | 4608 if (instance.IsNull()) { |
(...skipping 20 matching lines...) Expand all Loading... | |
4772 CURRENT_FUNC, index); | 4629 CURRENT_FUNC, index); |
4773 } | 4630 } |
4774 *value = instance.GetNativeField(index); | 4631 *value = instance.GetNativeField(index); |
4775 return Api::Success(); | 4632 return Api::Success(); |
4776 } | 4633 } |
4777 | 4634 |
4778 | 4635 |
4779 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, | 4636 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, |
4780 int index, | 4637 int index, |
4781 intptr_t value) { | 4638 intptr_t value) { |
4782 Isolate* isolate = Isolate::Current(); | 4639 DARTSCOPE(Thread::Current()); |
4783 DARTSCOPE(isolate); | 4640 const Instance& instance = Api::UnwrapInstanceHandle(I, obj); |
4784 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); | |
4785 if (instance.IsNull()) { | 4641 if (instance.IsNull()) { |
4786 RETURN_TYPE_ERROR(isolate, obj, Instance); | 4642 RETURN_TYPE_ERROR(I, obj, Instance); |
4787 } | 4643 } |
4788 if (!instance.IsValidNativeIndex(index)) { | 4644 if (!instance.IsValidNativeIndex(index)) { |
4789 return Api::NewError( | 4645 return Api::NewError( |
4790 "%s: invalid index %d passed in to set native instance field", | 4646 "%s: invalid index %d passed in to set native instance field", |
4791 CURRENT_FUNC, index); | 4647 CURRENT_FUNC, index); |
4792 } | 4648 } |
4793 instance.SetNativeField(index, value); | 4649 instance.SetNativeField(index, value); |
4794 return Api::Success(); | 4650 return Api::Success(); |
4795 } | 4651 } |
4796 | 4652 |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5200 // as having failed to load without providing an error instance. | 5056 // as having failed to load without providing an error instance. |
5201 lib.SetLoadError(Object::null_instance()); | 5057 lib.SetLoadError(Object::null_instance()); |
5202 } | 5058 } |
5203 } | 5059 } |
5204 | 5060 |
5205 | 5061 |
5206 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 5062 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
5207 Dart_Handle source, | 5063 Dart_Handle source, |
5208 intptr_t line_offset, | 5064 intptr_t line_offset, |
5209 intptr_t column_offset) { | 5065 intptr_t column_offset) { |
5210 Thread* thread = Thread::Current(); | 5066 DARTSCOPE(Thread::Current()); |
5211 Isolate* isolate = thread->isolate(); | 5067 TIMERSCOPE(T, time_script_loading); |
5212 DARTSCOPE(isolate); | 5068 const String& url_str = Api::UnwrapStringHandle(I, url); |
5213 TIMERSCOPE(thread, time_script_loading); | |
5214 const String& url_str = Api::UnwrapStringHandle(isolate, url); | |
5215 if (url_str.IsNull()) { | 5069 if (url_str.IsNull()) { |
5216 RETURN_TYPE_ERROR(isolate, url, String); | 5070 RETURN_TYPE_ERROR(I, url, String); |
5217 } | 5071 } |
5218 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 5072 const String& source_str = Api::UnwrapStringHandle(I, source); |
5219 if (source_str.IsNull()) { | 5073 if (source_str.IsNull()) { |
5220 RETURN_TYPE_ERROR(isolate, source, String); | 5074 RETURN_TYPE_ERROR(I, source, String); |
5221 } | 5075 } |
5222 Library& library = | 5076 Library& library = Library::Handle(Z, I->object_store()->root_library()); |
5223 Library::Handle(isolate, isolate->object_store()->root_library()); | |
5224 if (!library.IsNull()) { | 5077 if (!library.IsNull()) { |
5225 const String& library_url = String::Handle(isolate, library.url()); | 5078 const String& library_url = String::Handle(Z, library.url()); |
5226 return Api::NewError("%s: A script has already been loaded from '%s'.", | 5079 return Api::NewError("%s: A script has already been loaded from '%s'.", |
5227 CURRENT_FUNC, library_url.ToCString()); | 5080 CURRENT_FUNC, library_url.ToCString()); |
5228 } | 5081 } |
5229 if (line_offset < 0) { | 5082 if (line_offset < 0) { |
5230 return Api::NewError("%s: argument 'line_offset' must be positive number", | 5083 return Api::NewError("%s: argument 'line_offset' must be positive number", |
5231 CURRENT_FUNC); | 5084 CURRENT_FUNC); |
5232 } | 5085 } |
5233 if (column_offset < 0) { | 5086 if (column_offset < 0) { |
5234 return Api::NewError("%s: argument 'column_offset' must be positive number", | 5087 return Api::NewError("%s: argument 'column_offset' must be positive number", |
5235 CURRENT_FUNC); | 5088 CURRENT_FUNC); |
5236 } | 5089 } |
5237 CHECK_CALLBACK_STATE(isolate); | 5090 CHECK_CALLBACK_STATE(I); |
5238 | 5091 |
5239 NoHeapGrowthControlScope no_growth_control; | 5092 NoHeapGrowthControlScope no_growth_control; |
5240 | 5093 |
5241 library = Library::New(url_str); | 5094 library = Library::New(url_str); |
5242 library.set_debuggable(true); | 5095 library.set_debuggable(true); |
5243 library.Register(); | 5096 library.Register(); |
5244 isolate->object_store()->set_root_library(library); | 5097 I->object_store()->set_root_library(library); |
5245 | 5098 |
5246 const Script& script = Script::Handle( | 5099 const Script& script = Script::Handle(Z, |
5247 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); | 5100 Script::New(url_str, source_str, RawScript::kScriptTag)); |
5248 script.SetLocationOffset(line_offset, column_offset); | 5101 script.SetLocationOffset(line_offset, column_offset); |
5249 Dart_Handle result; | 5102 Dart_Handle result; |
5250 CompileSource(isolate, library, script, &result); | 5103 CompileSource(I, library, script, &result); |
5251 return result; | 5104 return result; |
5252 } | 5105 } |
5253 | 5106 |
5254 | 5107 |
5255 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, | 5108 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, |
5256 intptr_t buffer_len) { | 5109 intptr_t buffer_len) { |
5257 Thread* thread = Thread::Current(); | 5110 DARTSCOPE(Thread::Current()); |
5258 Isolate* isolate = thread->isolate(); | 5111 TIMERSCOPE(T, time_script_loading); |
5259 DARTSCOPE(isolate); | 5112 StackZone zone(T); |
5260 TIMERSCOPE(thread, time_script_loading); | |
5261 StackZone zone(isolate); | |
5262 if (buffer == NULL) { | 5113 if (buffer == NULL) { |
5263 RETURN_NULL_ERROR(buffer); | 5114 RETURN_NULL_ERROR(buffer); |
5264 } | 5115 } |
5265 NoHeapGrowthControlScope no_growth_control; | 5116 NoHeapGrowthControlScope no_growth_control; |
5266 | 5117 |
5267 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 5118 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
5268 if (!snapshot->IsScriptSnapshot()) { | 5119 if (!snapshot->IsScriptSnapshot()) { |
5269 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 5120 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
5270 " snapshot.", CURRENT_FUNC); | 5121 " snapshot.", CURRENT_FUNC); |
5271 } | 5122 } |
5272 if (snapshot->length() != buffer_len) { | 5123 if (snapshot->length() != buffer_len) { |
5273 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd | 5124 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd |
5274 " which is the expected length in the snapshot.", | 5125 " which is the expected length in the snapshot.", |
5275 CURRENT_FUNC, buffer_len, snapshot->length()); | 5126 CURRENT_FUNC, buffer_len, snapshot->length()); |
5276 } | 5127 } |
5277 Library& library = | 5128 Library& library = Library::Handle(Z, I->object_store()->root_library()); |
5278 Library::Handle(isolate, isolate->object_store()->root_library()); | |
5279 if (!library.IsNull()) { | 5129 if (!library.IsNull()) { |
5280 const String& library_url = String::Handle(isolate, library.url()); | 5130 const String& library_url = String::Handle(Z, library.url()); |
5281 return Api::NewError("%s: A script has already been loaded from '%s'.", | 5131 return Api::NewError("%s: A script has already been loaded from '%s'.", |
5282 CURRENT_FUNC, library_url.ToCString()); | 5132 CURRENT_FUNC, library_url.ToCString()); |
5283 } | 5133 } |
5284 CHECK_CALLBACK_STATE(isolate); | 5134 CHECK_CALLBACK_STATE(I); |
5285 | 5135 |
5286 ASSERT(snapshot->kind() == Snapshot::kScript); | 5136 ASSERT(snapshot->kind() == Snapshot::kScript); |
5287 ScriptSnapshotReader reader(snapshot->content(), | 5137 ScriptSnapshotReader reader(snapshot->content(), snapshot->length(), T); |
5288 snapshot->length(), | 5138 const Object& tmp = Object::Handle(Z, reader.ReadScriptSnapshot()); |
5289 isolate, | |
5290 zone.GetZone()); | |
5291 const Object& tmp = Object::Handle(isolate, reader.ReadScriptSnapshot()); | |
5292 if (tmp.IsError()) { | 5139 if (tmp.IsError()) { |
5293 return Api::NewHandle(isolate, tmp.raw()); | 5140 return Api::NewHandle(I, tmp.raw()); |
5294 } | 5141 } |
5295 library ^= tmp.raw(); | 5142 library ^= tmp.raw(); |
5296 library.set_debuggable(true); | 5143 library.set_debuggable(true); |
5297 isolate->object_store()->set_root_library(library); | 5144 I->object_store()->set_root_library(library); |
5298 return Api::NewHandle(isolate, library.raw()); | 5145 return Api::NewHandle(I, library.raw()); |
5299 } | 5146 } |
5300 | 5147 |
5301 | 5148 |
5302 DART_EXPORT Dart_Handle Dart_RootLibrary() { | 5149 DART_EXPORT Dart_Handle Dart_RootLibrary() { |
5303 Isolate* isolate = Isolate::Current(); | 5150 Isolate* isolate = Isolate::Current(); |
5304 CHECK_ISOLATE(isolate); | 5151 CHECK_ISOLATE(isolate); |
5305 return Api::NewHandle(isolate, isolate->object_store()->root_library()); | 5152 return Api::NewHandle(isolate, isolate->object_store()->root_library()); |
5306 } | 5153 } |
5307 | 5154 |
5308 | 5155 |
5309 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, | 5156 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, |
5310 Dart_Handle class_name) { | 5157 Dart_Handle class_name) { |
5311 Isolate* isolate = Isolate::Current(); | 5158 DARTSCOPE(Thread::Current()); |
5312 DARTSCOPE(isolate); | 5159 const Library& lib = Api::UnwrapLibraryHandle(I, library); |
5313 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | |
5314 if (lib.IsNull()) { | 5160 if (lib.IsNull()) { |
5315 RETURN_TYPE_ERROR(isolate, library, Library); | 5161 RETURN_TYPE_ERROR(I, library, Library); |
5316 } | 5162 } |
5317 const String& cls_name = Api::UnwrapStringHandle(isolate, class_name); | 5163 const String& cls_name = Api::UnwrapStringHandle(I, class_name); |
5318 if (cls_name.IsNull()) { | 5164 if (cls_name.IsNull()) { |
5319 RETURN_TYPE_ERROR(isolate, class_name, String); | 5165 RETURN_TYPE_ERROR(I, class_name, String); |
5320 } | 5166 } |
5321 const Class& cls = Class::Handle( | 5167 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(cls_name)); |
5322 isolate, lib.LookupClassAllowPrivate(cls_name)); | |
5323 if (cls.IsNull()) { | 5168 if (cls.IsNull()) { |
5324 // TODO(turnidge): Return null or error in this case? | 5169 // TODO(turnidge): Return null or error in this case? |
5325 const String& lib_name = String::Handle(isolate, lib.name()); | 5170 const String& lib_name = String::Handle(Z, lib.name()); |
5326 return Api::NewError("Class '%s' not found in library '%s'.", | 5171 return Api::NewError("Class '%s' not found in library '%s'.", |
5327 cls_name.ToCString(), lib_name.ToCString()); | 5172 cls_name.ToCString(), lib_name.ToCString()); |
5328 } | 5173 } |
5329 return Api::NewHandle(isolate, cls.RareType()); | 5174 return Api::NewHandle(I, cls.RareType()); |
5330 } | 5175 } |
5331 | 5176 |
5332 | 5177 |
5333 DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library, | 5178 DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library, |
5334 Dart_Handle class_name, | 5179 Dart_Handle class_name, |
5335 intptr_t number_of_type_arguments, | 5180 intptr_t number_of_type_arguments, |
5336 Dart_Handle* type_arguments) { | 5181 Dart_Handle* type_arguments) { |
5337 Isolate* isolate = Isolate::Current(); | 5182 DARTSCOPE(Thread::Current()); |
5338 DARTSCOPE(isolate); | |
5339 | 5183 |
5340 // Validate the input arguments. | 5184 // Validate the input arguments. |
5341 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 5185 const Library& lib = Api::UnwrapLibraryHandle(I, library); |
5342 if (lib.IsNull()) { | 5186 if (lib.IsNull()) { |
5343 RETURN_TYPE_ERROR(isolate, library, Library); | 5187 RETURN_TYPE_ERROR(I, library, Library); |
5344 } | 5188 } |
5345 if (!lib.Loaded()) { | 5189 if (!lib.Loaded()) { |
5346 return Api::NewError( | 5190 return Api::NewError( |
5347 "%s expects library argument 'library' to be loaded.", | 5191 "%s expects library argument 'library' to be loaded.", |
5348 CURRENT_FUNC); | 5192 CURRENT_FUNC); |
5349 } | 5193 } |
5350 const String& name_str = Api::UnwrapStringHandle(isolate, class_name); | 5194 const String& name_str = Api::UnwrapStringHandle(I, class_name); |
5351 if (name_str.IsNull()) { | 5195 if (name_str.IsNull()) { |
5352 RETURN_TYPE_ERROR(isolate, class_name, String); | 5196 RETURN_TYPE_ERROR(I, class_name, String); |
5353 } | 5197 } |
5354 const Class& cls = | 5198 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(name_str)); |
5355 Class::Handle(isolate, lib.LookupClassAllowPrivate(name_str)); | |
5356 if (cls.IsNull()) { | 5199 if (cls.IsNull()) { |
5357 const String& lib_name = String::Handle(isolate, lib.name()); | 5200 const String& lib_name = String::Handle(Z, lib.name()); |
5358 return Api::NewError("Type '%s' not found in library '%s'.", | 5201 return Api::NewError("Type '%s' not found in library '%s'.", |
5359 name_str.ToCString(), lib_name.ToCString()); | 5202 name_str.ToCString(), lib_name.ToCString()); |
5360 } | 5203 } |
5361 if (cls.NumTypeArguments() == 0) { | 5204 if (cls.NumTypeArguments() == 0) { |
5362 if (number_of_type_arguments != 0) { | 5205 if (number_of_type_arguments != 0) { |
5363 return Api::NewError("Invalid number of type arguments specified, " | 5206 return Api::NewError("Invalid number of type arguments specified, " |
5364 "got %" Pd " expected 0", number_of_type_arguments); | 5207 "got %" Pd " expected 0", number_of_type_arguments); |
5365 } | 5208 } |
5366 return Api::NewHandle(isolate, Type::NewNonParameterizedType(cls)); | 5209 return Api::NewHandle(I, Type::NewNonParameterizedType(cls)); |
5367 } | 5210 } |
5368 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); | 5211 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); |
5369 TypeArguments& type_args_obj = TypeArguments::Handle(); | 5212 TypeArguments& type_args_obj = TypeArguments::Handle(); |
5370 if (number_of_type_arguments > 0) { | 5213 if (number_of_type_arguments > 0) { |
5371 if (type_arguments == NULL) { | 5214 if (type_arguments == NULL) { |
5372 RETURN_NULL_ERROR(type_arguments); | 5215 RETURN_NULL_ERROR(type_arguments); |
5373 } | 5216 } |
5374 if (num_expected_type_arguments != number_of_type_arguments) { | 5217 if (num_expected_type_arguments != number_of_type_arguments) { |
5375 return Api::NewError("Invalid number of type arguments specified, " | 5218 return Api::NewError("Invalid number of type arguments specified, " |
5376 "got %" Pd " expected %" Pd, | 5219 "got %" Pd " expected %" Pd, |
5377 number_of_type_arguments, | 5220 number_of_type_arguments, |
5378 num_expected_type_arguments); | 5221 num_expected_type_arguments); |
5379 } | 5222 } |
5380 const Array& array = Api::UnwrapArrayHandle(isolate, *type_arguments); | 5223 const Array& array = Api::UnwrapArrayHandle(I, *type_arguments); |
5381 if (array.IsNull()) { | 5224 if (array.IsNull()) { |
5382 RETURN_TYPE_ERROR(isolate, *type_arguments, Array); | 5225 RETURN_TYPE_ERROR(I, *type_arguments, Array); |
5383 } | 5226 } |
5384 if (array.Length() != num_expected_type_arguments) { | 5227 if (array.Length() != num_expected_type_arguments) { |
5385 return Api::NewError("Invalid type arguments specified, expected an " | 5228 return Api::NewError("Invalid type arguments specified, expected an " |
5386 "array of len %" Pd " but got an array of len %" Pd, | 5229 "array of len %" Pd " but got an array of len %" Pd, |
5387 number_of_type_arguments, | 5230 number_of_type_arguments, |
5388 array.Length()); | 5231 array.Length()); |
5389 } | 5232 } |
5390 // Set up the type arguments array. | 5233 // Set up the type arguments array. |
5391 type_args_obj ^= TypeArguments::New(num_expected_type_arguments); | 5234 type_args_obj ^= TypeArguments::New(num_expected_type_arguments); |
5392 AbstractType& type_arg = AbstractType::Handle(); | 5235 AbstractType& type_arg = AbstractType::Handle(); |
5393 for (intptr_t i = 0; i < number_of_type_arguments; i++) { | 5236 for (intptr_t i = 0; i < number_of_type_arguments; i++) { |
5394 type_arg ^= array.At(i); | 5237 type_arg ^= array.At(i); |
5395 type_args_obj.SetTypeAt(i, type_arg); | 5238 type_args_obj.SetTypeAt(i, type_arg); |
5396 } | 5239 } |
5397 } | 5240 } |
5398 | 5241 |
5399 // Construct the type object, canonicalize it and return. | 5242 // Construct the type object, canonicalize it and return. |
5400 Type& instantiated_type = Type::Handle( | 5243 Type& instantiated_type = Type::Handle( |
5401 Type::New(cls, type_args_obj, Scanner::kNoSourcePos)); | 5244 Type::New(cls, type_args_obj, Scanner::kNoSourcePos)); |
5402 instantiated_type ^= ClassFinalizer::FinalizeType( | 5245 instantiated_type ^= ClassFinalizer::FinalizeType( |
5403 cls, instantiated_type, ClassFinalizer::kCanonicalize); | 5246 cls, instantiated_type, ClassFinalizer::kCanonicalize); |
5404 return Api::NewHandle(isolate, instantiated_type.raw()); | 5247 return Api::NewHandle(I, instantiated_type.raw()); |
5405 } | 5248 } |
5406 | 5249 |
5407 | 5250 |
5408 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { | 5251 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { |
5409 Isolate* isolate = Isolate::Current(); | 5252 DARTSCOPE(Thread::Current()); |
5410 DARTSCOPE(isolate); | 5253 const Library& lib = Api::UnwrapLibraryHandle(I, library); |
5411 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | |
5412 if (lib.IsNull()) { | 5254 if (lib.IsNull()) { |
5413 RETURN_TYPE_ERROR(isolate, library, Library); | 5255 RETURN_TYPE_ERROR(I, library, Library); |
5414 } | 5256 } |
5415 const String& url = String::Handle(isolate, lib.url()); | 5257 const String& url = String::Handle(Z, lib.url()); |
5416 ASSERT(!url.IsNull()); | 5258 ASSERT(!url.IsNull()); |
5417 return Api::NewHandle(isolate, url.raw()); | 5259 return Api::NewHandle(I, url.raw()); |
5418 } | 5260 } |
5419 | 5261 |
5420 | 5262 |
5421 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { | 5263 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { |
5422 Isolate* isolate = Isolate::Current(); | 5264 DARTSCOPE(Thread::Current()); |
5423 DARTSCOPE(isolate); | 5265 const String& url_str = Api::UnwrapStringHandle(I, url); |
5424 const String& url_str = Api::UnwrapStringHandle(isolate, url); | |
5425 if (url_str.IsNull()) { | 5266 if (url_str.IsNull()) { |
5426 RETURN_TYPE_ERROR(isolate, url, String); | 5267 RETURN_TYPE_ERROR(I, url, String); |
5427 } | 5268 } |
5428 const Library& library = | 5269 const Library& library = Library::Handle(Z, Library::LookupLibrary(url_str)); |
5429 Library::Handle(isolate, Library::LookupLibrary(url_str)); | |
5430 if (library.IsNull()) { | 5270 if (library.IsNull()) { |
5431 return Api::NewError("%s: library '%s' not found.", | 5271 return Api::NewError("%s: library '%s' not found.", |
5432 CURRENT_FUNC, url_str.ToCString()); | 5272 CURRENT_FUNC, url_str.ToCString()); |
5433 } else { | 5273 } else { |
5434 return Api::NewHandle(isolate, library.raw()); | 5274 return Api::NewHandle(I, library.raw()); |
5435 } | 5275 } |
5436 } | 5276 } |
5437 | 5277 |
5438 | 5278 |
5439 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, | 5279 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, |
5440 Dart_Handle error_in) { | 5280 Dart_Handle error_in) { |
5441 Isolate* isolate = Isolate::Current(); | 5281 DARTSCOPE(Thread::Current()); |
5442 DARTSCOPE(isolate); | |
5443 | 5282 |
5444 const Library& lib = Api::UnwrapLibraryHandle(isolate, library_in); | 5283 const Library& lib = Api::UnwrapLibraryHandle(I, library_in); |
5445 if (lib.IsNull()) { | 5284 if (lib.IsNull()) { |
5446 RETURN_TYPE_ERROR(isolate, library_in, Library); | 5285 RETURN_TYPE_ERROR(I, library_in, Library); |
5447 } | 5286 } |
5448 const Instance& err = Api::UnwrapInstanceHandle(isolate, error_in); | 5287 const Instance& err = Api::UnwrapInstanceHandle(I, error_in); |
5449 if (err.IsNull()) { | 5288 if (err.IsNull()) { |
5450 RETURN_TYPE_ERROR(isolate, error_in, Instance); | 5289 RETURN_TYPE_ERROR(I, error_in, Instance); |
5451 } | 5290 } |
5452 CHECK_CALLBACK_STATE(isolate); | 5291 CHECK_CALLBACK_STATE(I); |
5453 | 5292 |
5454 const GrowableObjectArray& pending_deferred_loads = | 5293 const GrowableObjectArray& pending_deferred_loads = |
5455 GrowableObjectArray::Handle( | 5294 GrowableObjectArray::Handle(Z, |
5456 isolate->object_store()->pending_deferred_loads()); | 5295 I->object_store()->pending_deferred_loads()); |
5457 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { | 5296 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { |
5458 if (pending_deferred_loads.At(i) == lib.raw()) { | 5297 if (pending_deferred_loads.At(i) == lib.raw()) { |
5459 lib.SetLoadError(err); | 5298 lib.SetLoadError(err); |
5460 return Api::Null(); | 5299 return Api::Null(); |
5461 } | 5300 } |
5462 } | 5301 } |
5463 return error_in; | 5302 return error_in; |
5464 } | 5303 } |
5465 | 5304 |
5466 | 5305 |
5467 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 5306 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
5468 Dart_Handle source, | 5307 Dart_Handle source, |
5469 intptr_t line_offset, | 5308 intptr_t line_offset, |
5470 intptr_t column_offset) { | 5309 intptr_t column_offset) { |
5471 Thread* thread = Thread::Current(); | 5310 DARTSCOPE(Thread::Current()); |
5472 Isolate* isolate = thread->isolate(); | 5311 TIMERSCOPE(T, time_script_loading); |
5473 DARTSCOPE(isolate); | 5312 const String& url_str = Api::UnwrapStringHandle(I, url); |
5474 TIMERSCOPE(thread, time_script_loading); | |
5475 const String& url_str = Api::UnwrapStringHandle(isolate, url); | |
5476 if (url_str.IsNull()) { | 5313 if (url_str.IsNull()) { |
5477 RETURN_TYPE_ERROR(isolate, url, String); | 5314 RETURN_TYPE_ERROR(I, url, String); |
5478 } | 5315 } |
5479 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 5316 const String& source_str = Api::UnwrapStringHandle(I, source); |
5480 if (source_str.IsNull()) { | 5317 if (source_str.IsNull()) { |
5481 RETURN_TYPE_ERROR(isolate, source, String); | 5318 RETURN_TYPE_ERROR(I, source, String); |
5482 } | 5319 } |
5483 if (line_offset < 0) { | 5320 if (line_offset < 0) { |
5484 return Api::NewError("%s: argument 'line_offset' must be positive number", | 5321 return Api::NewError("%s: argument 'line_offset' must be positive number", |
5485 CURRENT_FUNC); | 5322 CURRENT_FUNC); |
5486 } | 5323 } |
5487 if (column_offset < 0) { | 5324 if (column_offset < 0) { |
5488 return Api::NewError("%s: argument 'column_offset' must be positive number", | 5325 return Api::NewError("%s: argument 'column_offset' must be positive number", |
5489 CURRENT_FUNC); | 5326 CURRENT_FUNC); |
5490 } | 5327 } |
5491 CHECK_CALLBACK_STATE(isolate); | 5328 CHECK_CALLBACK_STATE(I); |
5492 | 5329 |
5493 NoHeapGrowthControlScope no_growth_control; | 5330 NoHeapGrowthControlScope no_growth_control; |
5494 | 5331 |
5495 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); | 5332 Library& library = Library::Handle(Z, Library::LookupLibrary(url_str)); |
5496 if (library.IsNull()) { | 5333 if (library.IsNull()) { |
5497 library = Library::New(url_str); | 5334 library = Library::New(url_str); |
5498 library.Register(); | 5335 library.Register(); |
5499 } else if (library.LoadInProgress() || | 5336 } else if (library.LoadInProgress() || |
5500 library.Loaded() || | 5337 library.Loaded() || |
5501 library.LoadFailed()) { | 5338 library.LoadFailed()) { |
5502 // The source for this library has either been loaded or is in the | 5339 // The source for this library has either been loaded or is in the |
5503 // process of loading. Return an error. | 5340 // process of loading. Return an error. |
5504 return Api::NewError("%s: library '%s' has already been loaded.", | 5341 return Api::NewError("%s: library '%s' has already been loaded.", |
5505 CURRENT_FUNC, url_str.ToCString()); | 5342 CURRENT_FUNC, url_str.ToCString()); |
5506 } | 5343 } |
5507 const Script& script = Script::Handle( | 5344 const Script& script = Script::Handle(Z, |
5508 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag)); | 5345 Script::New(url_str, source_str, RawScript::kLibraryTag)); |
5509 script.SetLocationOffset(line_offset, column_offset); | 5346 script.SetLocationOffset(line_offset, column_offset); |
5510 Dart_Handle result; | 5347 Dart_Handle result; |
5511 CompileSource(isolate, library, script, &result); | 5348 CompileSource(I, library, script, &result); |
5512 // Propagate the error out right now. | 5349 // Propagate the error out right now. |
5513 if (::Dart_IsError(result)) { | 5350 if (::Dart_IsError(result)) { |
5514 return result; | 5351 return result; |
5515 } | 5352 } |
5516 | 5353 |
5517 // If this is the dart:_builtin library, register it with the VM. | 5354 // If this is the dart:_builtin library, register it with the VM. |
5518 if (url_str.Equals("dart:_builtin")) { | 5355 if (url_str.Equals("dart:_builtin")) { |
5519 isolate->object_store()->set_builtin_library(library); | 5356 I->object_store()->set_builtin_library(library); |
5520 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); | 5357 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); |
5521 if (::Dart_IsError(state)) { | 5358 if (::Dart_IsError(state)) { |
5522 return state; | 5359 return state; |
5523 } | 5360 } |
5524 } | 5361 } |
5525 return result; | 5362 return result; |
5526 } | 5363 } |
5527 | 5364 |
5528 | 5365 |
5529 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, | 5366 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, |
5530 Dart_Handle import, | 5367 Dart_Handle import, |
5531 Dart_Handle prefix) { | 5368 Dart_Handle prefix) { |
5532 Isolate* isolate = Isolate::Current(); | 5369 DARTSCOPE(Thread::Current()); |
5533 DARTSCOPE(isolate); | 5370 const Library& library_vm = Api::UnwrapLibraryHandle(I, library); |
5534 const Library& library_vm = Api::UnwrapLibraryHandle(isolate, library); | |
5535 if (library_vm.IsNull()) { | 5371 if (library_vm.IsNull()) { |
5536 RETURN_TYPE_ERROR(isolate, library, Library); | 5372 RETURN_TYPE_ERROR(I, library, Library); |
5537 } | 5373 } |
5538 const Library& import_vm = Api::UnwrapLibraryHandle(isolate, import); | 5374 const Library& import_vm = Api::UnwrapLibraryHandle(I, import); |
5539 if (import_vm.IsNull()) { | 5375 if (import_vm.IsNull()) { |
5540 RETURN_TYPE_ERROR(isolate, import, Library); | 5376 RETURN_TYPE_ERROR(I, import, Library); |
5541 } | 5377 } |
5542 const Object& prefix_object = | 5378 const Object& prefix_object = Object::Handle(Z, Api::UnwrapHandle(prefix)); |
5543 Object::Handle(isolate, Api::UnwrapHandle(prefix)); | |
5544 const String& prefix_vm = prefix_object.IsNull() | 5379 const String& prefix_vm = prefix_object.IsNull() |
5545 ? Symbols::Empty() | 5380 ? Symbols::Empty() |
5546 : String::Cast(prefix_object); | 5381 : String::Cast(prefix_object); |
5547 if (prefix_vm.IsNull()) { | 5382 if (prefix_vm.IsNull()) { |
5548 RETURN_TYPE_ERROR(isolate, prefix, String); | 5383 RETURN_TYPE_ERROR(I, prefix, String); |
5549 } | 5384 } |
5550 CHECK_CALLBACK_STATE(isolate); | 5385 CHECK_CALLBACK_STATE(I); |
5551 | 5386 |
5552 const String& prefix_symbol = | 5387 const String& prefix_symbol = String::Handle(Z, Symbols::New(prefix_vm)); |
5553 String::Handle(isolate, Symbols::New(prefix_vm)); | 5388 const Namespace& import_ns = Namespace::Handle(Z, |
5554 const Namespace& import_ns = Namespace::Handle( | |
5555 Namespace::New(import_vm, Object::null_array(), Object::null_array())); | 5389 Namespace::New(import_vm, Object::null_array(), Object::null_array())); |
5556 if (prefix_vm.Length() == 0) { | 5390 if (prefix_vm.Length() == 0) { |
5557 library_vm.AddImport(import_ns); | 5391 library_vm.AddImport(import_ns); |
5558 } else { | 5392 } else { |
5559 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); | 5393 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); |
5560 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol); | 5394 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol); |
5561 if (!library_prefix.IsNull()) { | 5395 if (!library_prefix.IsNull()) { |
5562 library_prefix.AddImport(import_ns); | 5396 library_prefix.AddImport(import_ns); |
5563 } else { | 5397 } else { |
5564 library_prefix = | 5398 library_prefix = |
5565 LibraryPrefix::New(prefix_symbol, import_ns, false, library_vm); | 5399 LibraryPrefix::New(prefix_symbol, import_ns, false, library_vm); |
5566 library_vm.AddObject(library_prefix, prefix_symbol); | 5400 library_vm.AddObject(library_prefix, prefix_symbol); |
5567 } | 5401 } |
5568 } | 5402 } |
5569 return Api::Success(); | 5403 return Api::Success(); |
5570 } | 5404 } |
5571 | 5405 |
5572 | 5406 |
5573 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, | 5407 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, |
5574 Dart_Handle url, | 5408 Dart_Handle url, |
5575 Dart_Handle source, | 5409 Dart_Handle source, |
5576 intptr_t line_offset, | 5410 intptr_t line_offset, |
5577 intptr_t column_offset) { | 5411 intptr_t column_offset) { |
5578 Thread* thread = Thread::Current(); | 5412 DARTSCOPE(Thread::Current()); |
5579 Isolate* isolate = thread->isolate(); | 5413 TIMERSCOPE(T, time_script_loading); |
5580 DARTSCOPE(isolate); | 5414 const Library& lib = Api::UnwrapLibraryHandle(I, library); |
5581 TIMERSCOPE(thread, time_script_loading); | |
5582 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | |
5583 if (lib.IsNull()) { | 5415 if (lib.IsNull()) { |
5584 RETURN_TYPE_ERROR(isolate, library, Library); | 5416 RETURN_TYPE_ERROR(I, library, Library); |
5585 } | 5417 } |
5586 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 5418 const String& url_str = Api::UnwrapStringHandle(I, url); |
5587 if (url_str.IsNull()) { | 5419 if (url_str.IsNull()) { |
5588 RETURN_TYPE_ERROR(isolate, url, String); | 5420 RETURN_TYPE_ERROR(I, url, String); |
5589 } | 5421 } |
5590 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 5422 const String& source_str = Api::UnwrapStringHandle(I, source); |
5591 if (source_str.IsNull()) { | 5423 if (source_str.IsNull()) { |
5592 RETURN_TYPE_ERROR(isolate, source, String); | 5424 RETURN_TYPE_ERROR(I, source, String); |
5593 } | 5425 } |
5594 if (line_offset < 0) { | 5426 if (line_offset < 0) { |
5595 return Api::NewError("%s: argument 'line_offset' must be positive number", | 5427 return Api::NewError("%s: argument 'line_offset' must be positive number", |
5596 CURRENT_FUNC); | 5428 CURRENT_FUNC); |
5597 } | 5429 } |
5598 if (column_offset < 0) { | 5430 if (column_offset < 0) { |
5599 return Api::NewError("%s: argument 'column_offset' must be positive number", | 5431 return Api::NewError("%s: argument 'column_offset' must be positive number", |
5600 CURRENT_FUNC); | 5432 CURRENT_FUNC); |
5601 } | 5433 } |
5602 CHECK_CALLBACK_STATE(isolate); | 5434 CHECK_CALLBACK_STATE(I); |
5603 | 5435 |
5604 NoHeapGrowthControlScope no_growth_control; | 5436 NoHeapGrowthControlScope no_growth_control; |
5605 | 5437 |
5606 const Script& script = Script::Handle( | 5438 const Script& script = Script::Handle(Z, |
5607 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); | 5439 Script::New(url_str, source_str, RawScript::kSourceTag)); |
5608 script.SetLocationOffset(line_offset, column_offset); | 5440 script.SetLocationOffset(line_offset, column_offset); |
5609 Dart_Handle result; | 5441 Dart_Handle result; |
5610 CompileSource(isolate, lib, script, &result); | 5442 CompileSource(I, lib, script, &result); |
5611 return result; | 5443 return result; |
5612 } | 5444 } |
5613 | 5445 |
5614 | 5446 |
5615 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, | 5447 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, |
5616 Dart_Handle url, | 5448 Dart_Handle url, |
5617 Dart_Handle patch_source) { | 5449 Dart_Handle patch_source) { |
5618 Thread* thread = Thread::Current(); | 5450 DARTSCOPE(Thread::Current()); |
5619 Isolate* isolate = thread->isolate(); | 5451 TIMERSCOPE(T, time_script_loading); |
5620 DARTSCOPE(isolate); | 5452 const Library& lib = Api::UnwrapLibraryHandle(I, library); |
5621 TIMERSCOPE(thread, time_script_loading); | |
5622 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | |
5623 if (lib.IsNull()) { | 5453 if (lib.IsNull()) { |
5624 RETURN_TYPE_ERROR(isolate, library, Library); | 5454 RETURN_TYPE_ERROR(I, library, Library); |
5625 } | 5455 } |
5626 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 5456 const String& url_str = Api::UnwrapStringHandle(I, url); |
5627 if (url_str.IsNull()) { | 5457 if (url_str.IsNull()) { |
5628 RETURN_TYPE_ERROR(isolate, url, String); | 5458 RETURN_TYPE_ERROR(I, url, String); |
5629 } | 5459 } |
5630 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); | 5460 const String& source_str = Api::UnwrapStringHandle(I, patch_source); |
5631 if (source_str.IsNull()) { | 5461 if (source_str.IsNull()) { |
5632 RETURN_TYPE_ERROR(isolate, patch_source, String); | 5462 RETURN_TYPE_ERROR(I, patch_source, String); |
5633 } | 5463 } |
5634 CHECK_CALLBACK_STATE(isolate); | 5464 CHECK_CALLBACK_STATE(I); |
5635 | 5465 |
5636 NoHeapGrowthControlScope no_growth_control; | 5466 NoHeapGrowthControlScope no_growth_control; |
5637 | 5467 |
5638 const Script& script = Script::Handle( | 5468 const Script& script = Script::Handle(Z, |
5639 isolate, Script::New(url_str, source_str, RawScript::kPatchTag)); | 5469 Script::New(url_str, source_str, RawScript::kPatchTag)); |
5640 Dart_Handle result; | 5470 Dart_Handle result; |
5641 CompileSource(isolate, lib, script, &result); | 5471 CompileSource(I, lib, script, &result); |
5642 return result; | 5472 return result; |
5643 } | 5473 } |
5644 | 5474 |
5645 | 5475 |
5646 // Finalizes classes and invokes Dart core library function that completes | 5476 // Finalizes classes and invokes Dart core library function that completes |
5647 // futures of loadLibrary calls (deferred library loading). | 5477 // futures of loadLibrary calls (deferred library loading). |
5648 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { | 5478 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { |
5649 Isolate* isolate = Isolate::Current(); | 5479 DARTSCOPE(Thread::Current()); |
5650 DARTSCOPE(isolate); | 5480 CHECK_CALLBACK_STATE(I); |
5651 CHECK_CALLBACK_STATE(isolate); | |
5652 | 5481 |
5653 isolate->DoneLoading(); | 5482 I->DoneLoading(); |
5654 | 5483 |
5655 // TODO(hausner): move the remaining code below (finalization and | 5484 // TODO(hausner): move the remaining code below (finalization and |
5656 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). | 5485 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). |
5657 | 5486 |
5658 // Finalize all classes if needed. | 5487 // Finalize all classes if needed. |
5659 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); | 5488 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); |
5660 if (::Dart_IsError(state)) { | 5489 if (::Dart_IsError(state)) { |
5661 return state; | 5490 return state; |
5662 } | 5491 } |
5663 | 5492 |
5664 // Now that the newly loaded classes are finalized, notify the debugger | 5493 // Now that the newly loaded classes are finalized, notify the debugger |
5665 // that new code has been loaded. If there are latent breakpoints in | 5494 // that new code has been loaded. If there are latent breakpoints in |
5666 // the new code, the debugger convert them to unresolved source breakpoints. | 5495 // the new code, the debugger convert them to unresolved source breakpoints. |
5667 // The code that completes the futures (invoked below) may call into the | 5496 // The code that completes the futures (invoked below) may call into the |
5668 // newly loaded code and trigger one of these breakpoints. | 5497 // newly loaded code and trigger one of these breakpoints. |
5669 isolate->debugger()->NotifyDoneLoading(); | 5498 I->debugger()->NotifyDoneLoading(); |
5670 | 5499 |
5671 // Notify mirrors that MirrorSystem.libraries needs to be recomputed. | 5500 // Notify mirrors that MirrorSystem.libraries needs to be recomputed. |
5672 const Library& libmirrors = | 5501 const Library& libmirrors = Library::Handle(Z, Library::MirrorsLibrary()); |
5673 Library::Handle(isolate, Library::MirrorsLibrary()); | 5502 const Field& dirty_bit = Field::Handle(Z, |
5674 const Field& dirty_bit = Field::Handle(isolate, | |
5675 libmirrors.LookupLocalField(String::Handle(String::New("dirty")))); | 5503 libmirrors.LookupLocalField(String::Handle(String::New("dirty")))); |
5676 ASSERT(!dirty_bit.IsNull() && dirty_bit.is_static()); | 5504 ASSERT(!dirty_bit.IsNull() && dirty_bit.is_static()); |
5677 dirty_bit.set_value(Bool::True()); | 5505 dirty_bit.set_value(Bool::True()); |
5678 | 5506 |
5679 if (complete_futures) { | 5507 if (complete_futures) { |
5680 const Library& corelib = Library::Handle(isolate, Library::CoreLibrary()); | 5508 const Library& corelib = Library::Handle(Z, Library::CoreLibrary()); |
5681 const String& function_name = | 5509 const String& function_name = |
5682 String::Handle(isolate, String::New("_completeDeferredLoads")); | 5510 String::Handle(Z, String::New("_completeDeferredLoads")); |
5683 const Function& function = | 5511 const Function& function = Function::Handle(Z, |
5684 Function::Handle(isolate, | 5512 corelib.LookupFunctionAllowPrivate(function_name)); |
5685 corelib.LookupFunctionAllowPrivate(function_name)); | |
5686 ASSERT(!function.IsNull()); | 5513 ASSERT(!function.IsNull()); |
5687 const Array& args = Array::empty_array(); | 5514 const Array& args = Array::empty_array(); |
5688 | 5515 |
5689 const Object& res = | 5516 const Object& res = |
5690 Object::Handle(isolate, DartEntry::InvokeFunction(function, args)); | 5517 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); |
5691 isolate->object_store()->clear_pending_deferred_loads(); | 5518 I->object_store()->clear_pending_deferred_loads(); |
5692 if (res.IsError() || res.IsUnhandledException()) { | 5519 if (res.IsError() || res.IsUnhandledException()) { |
5693 return Api::NewHandle(isolate, res.raw()); | 5520 return Api::NewHandle(I, res.raw()); |
5694 } | 5521 } |
5695 } | 5522 } |
5696 return Api::Success(); | 5523 return Api::Success(); |
5697 } | 5524 } |
5698 | 5525 |
5699 | 5526 |
5700 DART_EXPORT Dart_Handle Dart_SetNativeResolver( | 5527 DART_EXPORT Dart_Handle Dart_SetNativeResolver( |
5701 Dart_Handle library, | 5528 Dart_Handle library, |
5702 Dart_NativeEntryResolver resolver, | 5529 Dart_NativeEntryResolver resolver, |
5703 Dart_NativeEntrySymbol symbol) { | 5530 Dart_NativeEntrySymbol symbol) { |
5704 Isolate* isolate = Isolate::Current(); | 5531 DARTSCOPE(Thread::Current()); |
5705 DARTSCOPE(isolate); | 5532 const Library& lib = Api::UnwrapLibraryHandle(I, library); |
5706 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | |
5707 if (lib.IsNull()) { | 5533 if (lib.IsNull()) { |
5708 RETURN_TYPE_ERROR(isolate, library, Library); | 5534 RETURN_TYPE_ERROR(I, library, Library); |
5709 } | 5535 } |
5710 lib.set_native_entry_resolver(resolver); | 5536 lib.set_native_entry_resolver(resolver); |
5711 lib.set_native_entry_symbol_resolver(symbol); | 5537 lib.set_native_entry_symbol_resolver(symbol); |
5712 return Api::Success(); | 5538 return Api::Success(); |
5713 } | 5539 } |
5714 | 5540 |
5715 | 5541 |
5716 // --- Peer support --- | 5542 // --- Peer support --- |
5717 | 5543 |
5718 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) { | 5544 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5820 } | 5646 } |
5821 Service::SetEmbedderStreamCallbacks(listen_callback, cancel_callback); | 5647 Service::SetEmbedderStreamCallbacks(listen_callback, cancel_callback); |
5822 return Api::Success(); | 5648 return Api::Success(); |
5823 } | 5649 } |
5824 | 5650 |
5825 | 5651 |
5826 DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, | 5652 DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, |
5827 const char* event_kind, | 5653 const char* event_kind, |
5828 const uint8_t* bytes, | 5654 const uint8_t* bytes, |
5829 intptr_t bytes_length) { | 5655 intptr_t bytes_length) { |
5830 Isolate* isolate = Isolate::Current(); | 5656 DARTSCOPE(Thread::Current()); |
5831 DARTSCOPE(isolate); | |
5832 if (stream_id == NULL) { | 5657 if (stream_id == NULL) { |
5833 RETURN_NULL_ERROR(stream_id); | 5658 RETURN_NULL_ERROR(stream_id); |
5834 } | 5659 } |
5835 if (event_kind == NULL) { | 5660 if (event_kind == NULL) { |
5836 RETURN_NULL_ERROR(event_kind); | 5661 RETURN_NULL_ERROR(event_kind); |
5837 } | 5662 } |
5838 if (bytes == NULL) { | 5663 if (bytes == NULL) { |
5839 RETURN_NULL_ERROR(bytes); | 5664 RETURN_NULL_ERROR(bytes); |
5840 } | 5665 } |
5841 if (bytes_length < 0) { | 5666 if (bytes_length < 0) { |
5842 return Api::NewError("%s expects argument 'bytes_length' to be >= 0.", | 5667 return Api::NewError("%s expects argument 'bytes_length' to be >= 0.", |
5843 CURRENT_FUNC); | 5668 CURRENT_FUNC); |
5844 } | 5669 } |
5845 Service::SendEmbedderEvent(isolate, stream_id, event_kind, | 5670 Service::SendEmbedderEvent(I, stream_id, event_kind, |
5846 bytes, bytes_length); | 5671 bytes, bytes_length); |
5847 return Api::Success(); | 5672 return Api::Success(); |
5848 } | 5673 } |
5849 | 5674 |
5850 | 5675 |
5851 DART_EXPORT void Dart_TimelineSetRecordedStreams(int64_t stream_mask) { | 5676 DART_EXPORT void Dart_TimelineSetRecordedStreams(int64_t stream_mask) { |
5852 Isolate* isolate = Isolate::Current(); | 5677 Isolate* isolate = Isolate::Current(); |
5853 CHECK_ISOLATE(isolate); | 5678 CHECK_ISOLATE(isolate); |
5854 isolate->GetAPIStream()->set_enabled( | 5679 isolate->GetAPIStream()->set_enabled( |
5855 (stream_mask & DART_TIMELINE_STREAM_API) != 0); | 5680 (stream_mask & DART_TIMELINE_STREAM_API) != 0); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6038 ASSERT(stream != NULL); | 5863 ASSERT(stream != NULL); |
6039 TimelineEvent* event = stream->StartEvent(); | 5864 TimelineEvent* event = stream->StartEvent(); |
6040 if (event != NULL) { | 5865 if (event != NULL) { |
6041 event->AsyncEnd(label, async_id); | 5866 event->AsyncEnd(label, async_id); |
6042 event->Complete(); | 5867 event->Complete(); |
6043 } | 5868 } |
6044 return Api::Success(); | 5869 return Api::Success(); |
6045 } | 5870 } |
6046 | 5871 |
6047 } // namespace dart | 5872 } // namespace dart |
OLD | NEW |