| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 if (obj.IsInstance()) { | 864 if (obj.IsInstance()) { |
| 865 Instance& instance = Instance::Handle(); | 865 Instance& instance = Instance::Handle(); |
| 866 instance ^= obj.raw(); | 866 instance ^= obj.raw(); |
| 867 const Type& type = Type::Handle(isolate->object_store()->list_interface()); | 867 const Type& type = Type::Handle(isolate->object_store()->list_interface()); |
| 868 return instance.Is(type) ? instance.raw() : Instance::null(); | 868 return instance.Is(type) ? instance.raw() : Instance::null(); |
| 869 } | 869 } |
| 870 return Instance::null(); | 870 return Instance::null(); |
| 871 } | 871 } |
| 872 | 872 |
| 873 | 873 |
| 874 DART_EXPORT bool Dart_IsArray(Dart_Handle object) { | 874 DART_EXPORT bool Dart_IsList(Dart_Handle object) { |
| 875 Zone zone; // Setup a VM zone as we are creating some handles. | 875 Zone zone; // Setup a VM zone as we are creating some handles. |
| 876 HandleScope scope; // Setup a VM handle scope. | 876 HandleScope scope; // Setup a VM handle scope. |
| 877 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 877 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 878 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 878 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
| 879 return (obj.IsArray() || (GetListInstance(Isolate::Current(), obj) != | 879 return (obj.IsArray() || |
| 880 Instance::null())); | 880 (GetListInstance(Isolate::Current(), obj) != Instance::null())); |
| 881 } | 881 } |
| 882 | 882 |
| 883 | 883 |
| 884 DART_EXPORT Dart_Handle Dart_NewArray(intptr_t length) { | 884 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
| 885 Zone zone; // Setup a VM zone as we are creating some handles. | 885 Zone zone; // Setup a VM zone as we are creating some handles. |
| 886 HandleScope scope; // Setup a VM handle scope. | 886 HandleScope scope; // Setup a VM handle scope. |
| 887 const Array& obj = Array::Handle(Array::New(length)); | 887 const Array& obj = Array::Handle(Array::New(length)); |
| 888 return Api::NewLocalHandle(obj); | 888 return Api::NewLocalHandle(obj); |
| 889 } | 889 } |
| 890 | 890 |
| 891 | 891 |
| 892 DART_EXPORT Dart_Handle Dart_GetLength(Dart_Handle array, intptr_t* len) { | 892 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { |
| 893 Zone zone; // Setup a VM zone as we are creating some handles. | 893 Zone zone; // Setup a VM zone as we are creating some handles. |
| 894 HandleScope scope; // Setup a VM handle scope. | 894 HandleScope scope; // Setup a VM handle scope. |
| 895 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); | 895 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 896 if (obj.IsArray()) { | 896 if (obj.IsArray()) { |
| 897 Array& array_obj = Array::Handle(); | 897 Array& array_obj = Array::Handle(); |
| 898 array_obj ^= obj.raw(); | 898 array_obj ^= obj.raw(); |
| 899 *len = array_obj.Length(); | 899 *len = array_obj.Length(); |
| 900 return Api::Success(); | 900 return Api::Success(); |
| 901 } | 901 } |
| 902 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 902 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
| 903 // Now check and handle a dart object that implements the List interface. | 903 // Now check and handle a dart object that implements the List interface. |
| 904 Isolate* isolate = Isolate::Current(); | 904 Isolate* isolate = Isolate::Current(); |
| 905 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 905 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 SetupErrorResult(&result); | 942 SetupErrorResult(&result); |
| 943 } | 943 } |
| 944 isolate->set_long_jump_base(base); | 944 isolate->set_long_jump_base(base); |
| 945 return result; | 945 return result; |
| 946 } | 946 } |
| 947 } | 947 } |
| 948 return Api::Error("Object does not implement the list inteface"); | 948 return Api::Error("Object does not implement the list inteface"); |
| 949 } | 949 } |
| 950 | 950 |
| 951 | 951 |
| 952 static RawObject* GetArrayAt(Isolate* isolate, | 952 static RawObject* GetListAt(Isolate* isolate, |
| 953 const Instance& instance, | 953 const Instance& instance, |
| 954 const Integer& index, | 954 const Integer& index, |
| 955 const Function& function, | 955 const Function& function, |
| 956 Dart_Handle* result) { | 956 Dart_Handle* result) { |
| 957 ASSERT(isolate != NULL); | 957 ASSERT(isolate != NULL); |
| 958 ASSERT(result != NULL); | 958 ASSERT(result != NULL); |
| 959 LongJump* base = isolate->long_jump_base(); | 959 LongJump* base = isolate->long_jump_base(); |
| 960 LongJump jump; | 960 LongJump jump; |
| 961 isolate->set_long_jump_base(&jump); | 961 isolate->set_long_jump_base(&jump); |
| 962 if (setjmp(*jump.Set()) == 0) { | 962 if (setjmp(*jump.Set()) == 0) { |
| 963 Instance& retval = Instance::Handle(); | 963 Instance& retval = Instance::Handle(); |
| 964 GrowableArray<const Object*> args(0); | 964 GrowableArray<const Object*> args(0); |
| 965 args.Add(&index); | 965 args.Add(&index); |
| 966 const Array& kNoArgumentNames = Array::Handle(); | 966 const Array& kNoArgumentNames = Array::Handle(); |
| 967 retval = DartEntry::InvokeDynamic(instance, | 967 retval = DartEntry::InvokeDynamic(instance, |
| 968 function, | 968 function, |
| 969 args, | 969 args, |
| 970 kNoArgumentNames); | 970 kNoArgumentNames); |
| 971 if (retval.IsUnhandledException()) { | 971 if (retval.IsUnhandledException()) { |
| 972 *result = Api::Error("Unexpected exception in '[]'"); | 972 *result = Api::Error("Unexpected exception in '[]'"); |
| 973 } else { | 973 } else { |
| 974 *result = Api::Success(); | 974 *result = Api::Success(); |
| 975 } | 975 } |
| 976 isolate->set_long_jump_base(base); | 976 isolate->set_long_jump_base(base); |
| 977 return retval.raw(); | 977 return retval.raw(); |
| 978 } | 978 } |
| 979 SetupErrorResult(result); | 979 SetupErrorResult(result); |
| 980 isolate->set_long_jump_base(base); | 980 isolate->set_long_jump_base(base); |
| 981 return Object::null(); | 981 return Object::null(); |
| 982 } | 982 } |
| 983 | 983 |
| 984 | 984 |
| 985 DART_EXPORT Dart_Handle Dart_ArrayGet(Dart_Handle array, | 985 DART_EXPORT Dart_Handle Dart_ListGet(Dart_Handle list, |
| 986 intptr_t offset, | 986 intptr_t offset, |
| 987 uint8_t* native_array, | 987 uint8_t* native_array, |
| 988 intptr_t length) { | 988 intptr_t length) { |
| 989 Zone zone; // Setup a VM zone as we are creating some handles. | 989 Zone zone; // Setup a VM zone as we are creating some handles. |
| 990 HandleScope scope; // Setup a VM handle scope. | 990 HandleScope scope; // Setup a VM handle scope. |
| 991 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); | 991 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 992 if (obj.IsArray()) { | 992 if (obj.IsArray()) { |
| 993 Array& array_obj = Array::Handle(); | 993 Array& array_obj = Array::Handle(); |
| 994 array_obj ^= obj.raw(); | 994 array_obj ^= obj.raw(); |
| 995 if ((offset + length) <= array_obj.Length()) { | 995 if ((offset + length) <= array_obj.Length()) { |
| 996 Object& element = Object::Handle(); | 996 Object& element = Object::Handle(); |
| 997 Integer& integer = Integer::Handle(); | 997 Integer& integer = Integer::Handle(); |
| 998 for (int i = 0; i < length; i++) { | 998 for (int i = 0; i < length; i++) { |
| 999 element = array_obj.At(offset + i); | 999 element = array_obj.At(offset + i); |
| 1000 integer ^= element.raw(); | 1000 integer ^= element.raw(); |
| 1001 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); | 1001 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1014 if (!instance.IsNull()) { | 1014 if (!instance.IsNull()) { |
| 1015 String& name = String::Handle(String::New("[]")); | 1015 String& name = String::Handle(String::New("[]")); |
| 1016 const Function& function = Function::Handle( | 1016 const Function& function = Function::Handle( |
| 1017 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1017 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1018 if (!function.IsNull()) { | 1018 if (!function.IsNull()) { |
| 1019 Object& element = Object::Handle(); | 1019 Object& element = Object::Handle(); |
| 1020 Integer& intobj = Integer::Handle(); | 1020 Integer& intobj = Integer::Handle(); |
| 1021 Dart_Handle result; | 1021 Dart_Handle result; |
| 1022 for (int i = 0; i < length; i++) { | 1022 for (int i = 0; i < length; i++) { |
| 1023 intobj = Integer::New(offset + i); | 1023 intobj = Integer::New(offset + i); |
| 1024 element = GetArrayAt(isolate, instance, intobj, function, &result); | 1024 element = GetListAt(isolate, instance, intobj, function, &result); |
| 1025 if (!Dart_IsValid(result)) { | 1025 if (!Dart_IsValid(result)) { |
| 1026 return result; // Error condition. | 1026 return result; // Error condition. |
| 1027 } | 1027 } |
| 1028 intobj ^= element.raw(); | 1028 intobj ^= element.raw(); |
| 1029 ASSERT(intobj.AsInt64Value() <= 0xff); | 1029 ASSERT(intobj.AsInt64Value() <= 0xff); |
| 1030 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1030 // TODO(hpayer): value should always be smaller then 0xff. Add error |
| 1031 // handling. | 1031 // handling. |
| 1032 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); | 1032 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); |
| 1033 } | 1033 } |
| 1034 return Api::Success(); | 1034 return Api::Success(); |
| 1035 } | 1035 } |
| 1036 } | 1036 } |
| 1037 return Api::Error("Object does not implement the 'List' interface"); | 1037 return Api::Error("Object does not implement the 'List' interface"); |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 | 1040 |
| 1041 DART_EXPORT Dart_Handle Dart_ArrayGetAt(Dart_Handle array, intptr_t index) { | 1041 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
| 1042 Zone zone; // Setup a VM zone as we are creating some handles. | 1042 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1043 HandleScope scope; // Setup a VM handle scope. | 1043 HandleScope scope; // Setup a VM handle scope. |
| 1044 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); | 1044 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1045 if (obj.IsArray()) { | 1045 if (obj.IsArray()) { |
| 1046 Array& array_obj = Array::Handle(); | 1046 Array& array_obj = Array::Handle(); |
| 1047 array_obj ^= obj.raw(); | 1047 array_obj ^= obj.raw(); |
| 1048 if ((index >= 0) && (index < array_obj.Length())) { | 1048 if ((index >= 0) && (index < array_obj.Length())) { |
| 1049 const Object& element = Object::Handle(array_obj.At(index)); | 1049 const Object& element = Object::Handle(array_obj.At(index)); |
| 1050 return Api::NewLocalHandle(element); | 1050 return Api::NewLocalHandle(element); |
| 1051 } | 1051 } |
| 1052 return Api::Error("Invalid index passed in to access array element"); | 1052 return Api::Error("Invalid index passed in to access array element"); |
| 1053 } | 1053 } |
| 1054 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1054 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
| 1055 // Now check and handle a dart object that implements the List interface. | 1055 // Now check and handle a dart object that implements the List interface. |
| 1056 Isolate* isolate = Isolate::Current(); | 1056 Isolate* isolate = Isolate::Current(); |
| 1057 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1057 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
| 1058 if (!instance.IsNull()) { | 1058 if (!instance.IsNull()) { |
| 1059 String& name = String::Handle(String::New("[]")); | 1059 String& name = String::Handle(String::New("[]")); |
| 1060 const Function& function = Function::Handle( | 1060 const Function& function = Function::Handle( |
| 1061 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1061 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1062 if (!function.IsNull()) { | 1062 if (!function.IsNull()) { |
| 1063 Object& element = Object::Handle(); | 1063 Object& element = Object::Handle(); |
| 1064 Integer& indexobj = Integer::Handle(); | 1064 Integer& indexobj = Integer::Handle(); |
| 1065 Dart_Handle result; | 1065 Dart_Handle result; |
| 1066 indexobj = Integer::New(index); | 1066 indexobj = Integer::New(index); |
| 1067 element = GetArrayAt(isolate, instance, indexobj, function, &result); | 1067 element = GetListAt(isolate, instance, indexobj, function, &result); |
| 1068 if (!Dart_IsValid(result)) { | 1068 if (!Dart_IsValid(result)) { |
| 1069 return result; // Error condition. | 1069 return result; // Error condition. |
| 1070 } | 1070 } |
| 1071 return Api::NewLocalHandle(element); | 1071 return Api::NewLocalHandle(element); |
| 1072 } | 1072 } |
| 1073 } | 1073 } |
| 1074 return Api::Error("Object does not implement the 'List' interface"); | 1074 return Api::Error("Object does not implement the 'List' interface"); |
| 1075 } | 1075 } |
| 1076 | 1076 |
| 1077 | 1077 |
| 1078 static void SetArrayAt(Isolate* isolate, | 1078 static void SetListAt(Isolate* isolate, |
| 1079 const Instance& instance, | 1079 const Instance& instance, |
| 1080 const Integer& index, | 1080 const Integer& index, |
| 1081 const Object& value, | 1081 const Object& value, |
| 1082 const Function& function, | 1082 const Function& function, |
| 1083 Dart_Handle* result) { | 1083 Dart_Handle* result) { |
| 1084 ASSERT(isolate != NULL); | 1084 ASSERT(isolate != NULL); |
| 1085 ASSERT(result != NULL); | 1085 ASSERT(result != NULL); |
| 1086 LongJump* base = isolate->long_jump_base(); | 1086 LongJump* base = isolate->long_jump_base(); |
| 1087 LongJump jump; | 1087 LongJump jump; |
| 1088 isolate->set_long_jump_base(&jump); | 1088 isolate->set_long_jump_base(&jump); |
| 1089 if (setjmp(*jump.Set()) == 0) { | 1089 if (setjmp(*jump.Set()) == 0) { |
| 1090 GrowableArray<const Object*> args(1); | 1090 GrowableArray<const Object*> args(1); |
| 1091 args.Add(&index); | 1091 args.Add(&index); |
| 1092 args.Add(&value); | 1092 args.Add(&value); |
| 1093 Instance& retval = Instance::Handle(); | 1093 Instance& retval = Instance::Handle(); |
| 1094 const Array& kNoArgumentNames = Array::Handle(); | 1094 const Array& kNoArgumentNames = Array::Handle(); |
| 1095 retval = DartEntry::InvokeDynamic(instance, | 1095 retval = DartEntry::InvokeDynamic(instance, |
| 1096 function, | 1096 function, |
| 1097 args, | 1097 args, |
| 1098 kNoArgumentNames); | 1098 kNoArgumentNames); |
| 1099 if (retval.IsUnhandledException()) { | 1099 if (retval.IsUnhandledException()) { |
| 1100 *result = Api::Error("Unexpected exception in '[]='"); | 1100 *result = Api::Error("Unexpected exception in '[]='"); |
| 1101 } else { | 1101 } else { |
| 1102 *result = Api::Success(); | 1102 *result = Api::Success(); |
| 1103 } | 1103 } |
| 1104 } else { | 1104 } else { |
| 1105 SetupErrorResult(result); | 1105 SetupErrorResult(result); |
| 1106 } | 1106 } |
| 1107 isolate->set_long_jump_base(base); | 1107 isolate->set_long_jump_base(base); |
| 1108 } | 1108 } |
| 1109 | 1109 |
| 1110 | 1110 |
| 1111 DART_EXPORT Dart_Handle Dart_ArraySet(Dart_Handle array, | 1111 DART_EXPORT Dart_Handle Dart_ListSet(Dart_Handle list, |
| 1112 intptr_t offset, | 1112 intptr_t offset, |
| 1113 uint8_t* native_array, | 1113 uint8_t* native_array, |
| 1114 intptr_t length) { | 1114 intptr_t length) { |
| 1115 Zone zone; | 1115 Zone zone; |
| 1116 HandleScope scope; | 1116 HandleScope scope; |
| 1117 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); | 1117 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1118 if (obj.IsArray()) { | 1118 if (obj.IsArray()) { |
| 1119 Array& array_obj = Array::Handle(); | 1119 Array& array_obj = Array::Handle(); |
| 1120 array_obj ^= obj.raw(); | 1120 array_obj ^= obj.raw(); |
| 1121 Integer& integer = Integer::Handle(); | 1121 Integer& integer = Integer::Handle(); |
| 1122 if ((offset + length) <= array_obj.Length()) { | 1122 if ((offset + length) <= array_obj.Length()) { |
| 1123 for (int i = 0; i < length; i++) { | 1123 for (int i = 0; i < length; i++) { |
| 1124 integer ^= Integer::New(native_array[i]); | 1124 integer ^= Integer::New(native_array[i]); |
| 1125 array_obj.SetAt(offset + i, integer); | 1125 array_obj.SetAt(offset + i, integer); |
| 1126 } | 1126 } |
| 1127 return Api::Success(); | 1127 return Api::Success(); |
| 1128 } | 1128 } |
| 1129 return Api::Error("Invalid length passed in to set array elements"); | 1129 return Api::Error("Invalid length passed in to set array elements"); |
| 1130 } | 1130 } |
| 1131 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1131 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
| 1132 // Now check and handle a dart object that implements the List interface. | 1132 // Now check and handle a dart object that implements the List interface. |
| 1133 Isolate* isolate = Isolate::Current(); | 1133 Isolate* isolate = Isolate::Current(); |
| 1134 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1134 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
| 1135 if (!instance.IsNull()) { | 1135 if (!instance.IsNull()) { |
| 1136 String& name = String::Handle(String::New("[]=")); | 1136 String& name = String::Handle(String::New("[]=")); |
| 1137 const Function& function = Function::Handle( | 1137 const Function& function = Function::Handle( |
| 1138 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1138 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 1139 if (!function.IsNull()) { | 1139 if (!function.IsNull()) { |
| 1140 Integer& indexobj = Integer::Handle(); | 1140 Integer& indexobj = Integer::Handle(); |
| 1141 Integer& valueobj = Integer::Handle(); | 1141 Integer& valueobj = Integer::Handle(); |
| 1142 Dart_Handle result; | 1142 Dart_Handle result; |
| 1143 for (int i = 0; i < length; i++) { | 1143 for (int i = 0; i < length; i++) { |
| 1144 indexobj = Integer::New(offset + i); | 1144 indexobj = Integer::New(offset + i); |
| 1145 valueobj ^= Integer::New(native_array[i]); | 1145 valueobj ^= Integer::New(native_array[i]); |
| 1146 SetArrayAt(isolate, instance, indexobj, valueobj, function, &result); | 1146 SetListAt(isolate, instance, indexobj, valueobj, function, &result); |
| 1147 if (!Dart_IsValid(result)) { | 1147 if (!Dart_IsValid(result)) { |
| 1148 return result; // Error condition. | 1148 return result; // Error condition. |
| 1149 } | 1149 } |
| 1150 } | 1150 } |
| 1151 return Api::Success(); | 1151 return Api::Success(); |
| 1152 } | 1152 } |
| 1153 } | 1153 } |
| 1154 return Api::Error("Object does not implement the 'List' interface"); | 1154 return Api::Error("Object does not implement the 'List' interface"); |
| 1155 } | 1155 } |
| 1156 | 1156 |
| 1157 | 1157 |
| 1158 DART_EXPORT Dart_Handle Dart_ArraySetAt(Dart_Handle array, | 1158 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
| 1159 intptr_t index, | 1159 intptr_t index, |
| 1160 Dart_Handle value) { | 1160 Dart_Handle value) { |
| 1161 Zone zone; // Setup a VM zone as we are creating some handles. | 1161 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1162 HandleScope scope; // Setup a VM handle scope. | 1162 HandleScope scope; // Setup a VM handle scope. |
| 1163 const Object& obj = Object::Handle(Api::UnwrapHandle(array)); | 1163 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1164 if (obj.IsArray()) { | 1164 if (obj.IsArray()) { |
| 1165 Array& array_obj = Array::Handle(); | 1165 Array& array_obj = Array::Handle(); |
| 1166 array_obj ^= obj.raw(); | 1166 array_obj ^= obj.raw(); |
| 1167 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); | 1167 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); |
| 1168 if ((index >= 0) && (index < array_obj.Length())) { | 1168 if ((index >= 0) && (index < array_obj.Length())) { |
| 1169 array_obj.SetAt(index, value_obj); | 1169 array_obj.SetAt(index, value_obj); |
| 1170 return Api::Success(); | 1170 return Api::Success(); |
| 1171 } | 1171 } |
| 1172 return Api::Error("Invalid index passed in to set array element"); | 1172 return Api::Error("Invalid index passed in to set array element"); |
| 1173 } | 1173 } |
| 1174 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1174 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
| 1175 // Now check and handle a dart object that implements the List interface. | 1175 // Now check and handle a dart object that implements the List interface. |
| 1176 Isolate* isolate = Isolate::Current(); | 1176 Isolate* isolate = Isolate::Current(); |
| 1177 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1177 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
| 1178 if (!instance.IsNull()) { | 1178 if (!instance.IsNull()) { |
| 1179 String& name = String::Handle(String::New("[]=")); | 1179 String& name = String::Handle(String::New("[]=")); |
| 1180 const Function& function = Function::Handle( | 1180 const Function& function = Function::Handle( |
| 1181 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1181 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 1182 if (!function.IsNull()) { | 1182 if (!function.IsNull()) { |
| 1183 Dart_Handle result; | 1183 Dart_Handle result; |
| 1184 const Integer& index_obj = Integer::Handle(Integer::New(index)); | 1184 const Integer& index_obj = Integer::Handle(Integer::New(index)); |
| 1185 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); | 1185 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); |
| 1186 SetArrayAt(isolate, instance, index_obj, value_obj, function, &result); | 1186 SetListAt(isolate, instance, index_obj, value_obj, function, &result); |
| 1187 return result; | 1187 return result; |
| 1188 } | 1188 } |
| 1189 } | 1189 } |
| 1190 return Api::Error("Object does not implement the 'List' interface"); | 1190 return Api::Error("Object does not implement the 'List' interface"); |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 | 1193 |
| 1194 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 1194 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 1195 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 1195 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 1196 // which shows up because of the use of setjmp. | 1196 // which shows up because of the use of setjmp. |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1999 ASSERT(isolate != NULL); | 1999 ASSERT(isolate != NULL); |
| 2000 ApiState* state = isolate->api_state(); | 2000 ApiState* state = isolate->api_state(); |
| 2001 ASSERT(state != NULL); | 2001 ASSERT(state != NULL); |
| 2002 ApiLocalScope* scope = state->top_scope(); | 2002 ApiLocalScope* scope = state->top_scope(); |
| 2003 ASSERT(scope != NULL); | 2003 ASSERT(scope != NULL); |
| 2004 return scope->zone().Reallocate(ptr, old_size, new_size); | 2004 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 2005 } | 2005 } |
| 2006 | 2006 |
| 2007 | 2007 |
| 2008 } // namespace dart | 2008 } // namespace dart |
| OLD | NEW |