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