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 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1120 DARTSCOPE(isolate); | 1120 DARTSCOPE(isolate); |
1121 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1121 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
1122 if (obj.IsArray()) { | 1122 if (obj.IsArray()) { |
1123 Array& array_obj = Array::Handle(); | 1123 Array& array_obj = Array::Handle(); |
1124 array_obj ^= obj.raw(); | 1124 array_obj ^= obj.raw(); |
1125 if ((offset + length) <= array_obj.Length()) { | 1125 if ((offset + length) <= array_obj.Length()) { |
1126 Object& element = Object::Handle(); | 1126 Object& element = Object::Handle(); |
1127 Integer& integer = Integer::Handle(); | 1127 Integer& integer = Integer::Handle(); |
1128 for (int i = 0; i < length; i++) { | 1128 for (int i = 0; i < length; i++) { |
1129 element = array_obj.At(offset + i); | 1129 element = array_obj.At(offset + i); |
1130 if (!element.IsInteger()) { | |
1131 return Api::Error("%s expects the argument 'list' to be " | |
1132 "a list of integers", CURRENT_FUNC); | |
turnidge
2011/11/16 18:56:45
I don't know if we capitalize Integer here or not.
siva
2011/11/16 18:59:08
Our official type name is int, maybe I should re w
| |
1133 } | |
1130 integer ^= element.raw(); | 1134 integer ^= element.raw(); |
1131 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); | 1135 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); |
1132 ASSERT(integer.AsInt64Value() <= 0xff); | 1136 ASSERT(integer.AsInt64Value() <= 0xff); |
1133 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1137 // TODO(hpayer): value should always be smaller then 0xff. Add error |
1134 // handling. | 1138 // handling. |
1135 } | 1139 } |
1136 return Api::Success(); | 1140 return Api::Success(); |
1137 } | 1141 } |
1138 return Api::Error("Invalid length passed in to access array elements"); | 1142 return Api::Error("Invalid length passed in to access array elements"); |
1139 } | 1143 } |
1140 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1144 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
1141 // Now check and handle a dart object that implements the List interface. | 1145 // Now check and handle a dart object that implements the List interface. |
1142 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1146 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
1143 if (!instance.IsNull()) { | 1147 if (!instance.IsNull()) { |
1144 String& name = String::Handle(String::New("[]")); | 1148 String& name = String::Handle(String::New("[]")); |
1145 const Function& function = Function::Handle( | 1149 const Function& function = Function::Handle( |
1146 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1150 Resolver::ResolveDynamic(instance, name, 2, 0)); |
1147 if (!function.IsNull()) { | 1151 if (!function.IsNull()) { |
1148 Object& element = Object::Handle(); | 1152 Object& element = Object::Handle(); |
1149 Integer& intobj = Integer::Handle(); | 1153 Integer& intobj = Integer::Handle(); |
1150 Dart_Handle result; | 1154 Dart_Handle result; |
1151 for (int i = 0; i < length; i++) { | 1155 for (int i = 0; i < length; i++) { |
1152 intobj = Integer::New(offset + i); | 1156 intobj = Integer::New(offset + i); |
1153 element = GetListAt(isolate, instance, intobj, function, &result); | 1157 element = GetListAt(isolate, instance, intobj, function, &result); |
1154 if (Dart_IsError(result)) { | 1158 if (Dart_IsError(result)) { |
1155 return result; // Error condition. | 1159 return result; // Error condition. |
1156 } | 1160 } |
1161 if (!element.IsInteger()) { | |
1162 return Api::Error("%s expects the argument 'list' to be " | |
1163 "a list of integers", CURRENT_FUNC); | |
1164 } | |
1157 intobj ^= element.raw(); | 1165 intobj ^= element.raw(); |
1158 ASSERT(intobj.AsInt64Value() <= 0xff); | 1166 ASSERT(intobj.AsInt64Value() <= 0xff); |
1159 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1167 // TODO(hpayer): value should always be smaller then 0xff. Add error |
1160 // handling. | 1168 // handling. |
1161 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); | 1169 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); |
1162 } | 1170 } |
1163 return Api::Success(); | 1171 return Api::Success(); |
1164 } | 1172 } |
1165 } | 1173 } |
1166 return Api::Error("Object does not implement the 'List' interface"); | 1174 return Api::Error("Object does not implement the 'List' interface"); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1242 intptr_t length) { | 1250 intptr_t length) { |
1243 Isolate* isolate = Isolate::Current(); | 1251 Isolate* isolate = Isolate::Current(); |
1244 DARTSCOPE(isolate); | 1252 DARTSCOPE(isolate); |
1245 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1253 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
1246 if (obj.IsArray()) { | 1254 if (obj.IsArray()) { |
1247 Array& array_obj = Array::Handle(); | 1255 Array& array_obj = Array::Handle(); |
1248 array_obj ^= obj.raw(); | 1256 array_obj ^= obj.raw(); |
1249 Integer& integer = Integer::Handle(); | 1257 Integer& integer = Integer::Handle(); |
1250 if ((offset + length) <= array_obj.Length()) { | 1258 if ((offset + length) <= array_obj.Length()) { |
1251 for (int i = 0; i < length; i++) { | 1259 for (int i = 0; i < length; i++) { |
1252 integer ^= Integer::New(native_array[i]); | 1260 integer = Integer::New(native_array[i]); |
1253 array_obj.SetAt(offset + i, integer); | 1261 array_obj.SetAt(offset + i, integer); |
1254 } | 1262 } |
1255 return Api::Success(); | 1263 return Api::Success(); |
1256 } | 1264 } |
1257 return Api::Error("Invalid length passed in to set array elements"); | 1265 return Api::Error("Invalid length passed in to set array elements"); |
1258 } | 1266 } |
1259 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1267 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
1260 // Now check and handle a dart object that implements the List interface. | 1268 // Now check and handle a dart object that implements the List interface. |
1261 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1269 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
1262 if (!instance.IsNull()) { | 1270 if (!instance.IsNull()) { |
1263 String& name = String::Handle(String::New("[]=")); | 1271 String& name = String::Handle(String::New("[]=")); |
1264 const Function& function = Function::Handle( | 1272 const Function& function = Function::Handle( |
1265 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1273 Resolver::ResolveDynamic(instance, name, 3, 0)); |
1266 if (!function.IsNull()) { | 1274 if (!function.IsNull()) { |
1267 Integer& indexobj = Integer::Handle(); | 1275 Integer& indexobj = Integer::Handle(); |
1268 Integer& valueobj = Integer::Handle(); | 1276 Integer& valueobj = Integer::Handle(); |
1269 Dart_Handle result; | 1277 Dart_Handle result; |
1270 for (int i = 0; i < length; i++) { | 1278 for (int i = 0; i < length; i++) { |
1271 indexobj = Integer::New(offset + i); | 1279 indexobj = Integer::New(offset + i); |
1272 valueobj ^= Integer::New(native_array[i]); | 1280 valueobj = Integer::New(native_array[i]); |
1273 SetListAt(isolate, instance, indexobj, valueobj, function, &result); | 1281 SetListAt(isolate, instance, indexobj, valueobj, function, &result); |
1274 if (Dart_IsError(result)) { | 1282 if (Dart_IsError(result)) { |
1275 return result; // Error condition. | 1283 return result; // Error condition. |
1276 } | 1284 } |
1277 } | 1285 } |
1278 return Api::Success(); | 1286 return Api::Success(); |
1279 } | 1287 } |
1280 } | 1288 } |
1281 return Api::Error("Object does not implement the 'List' interface"); | 1289 return Api::Error("Object does not implement the 'List' interface"); |
1282 } | 1290 } |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2133 ASSERT(isolate != NULL); | 2141 ASSERT(isolate != NULL); |
2134 ApiState* state = isolate->api_state(); | 2142 ApiState* state = isolate->api_state(); |
2135 ASSERT(state != NULL); | 2143 ASSERT(state != NULL); |
2136 ApiLocalScope* scope = state->top_scope(); | 2144 ApiLocalScope* scope = state->top_scope(); |
2137 ASSERT(scope != NULL); | 2145 ASSERT(scope != NULL); |
2138 return scope->zone().Reallocate(ptr, old_size, new_size); | 2146 return scope->zone().Reallocate(ptr, old_size, new_size); |
2139 } | 2147 } |
2140 | 2148 |
2141 | 2149 |
2142 } // namespace dart | 2150 } // namespace dart |
OLD | NEW |