| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1982 } \ | 1982 } \ |
| 1983 return Api::NewError("Invalid index passed in to set list element"); \ | 1983 return Api::NewError("Invalid index passed in to set list element"); \ |
| 1984 | 1984 |
| 1985 | 1985 |
| 1986 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 1986 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
| 1987 intptr_t index, | 1987 intptr_t index, |
| 1988 Dart_Handle value) { | 1988 Dart_Handle value) { |
| 1989 Isolate* isolate = Isolate::Current(); | 1989 Isolate* isolate = Isolate::Current(); |
| 1990 DARTSCOPE(isolate); | 1990 DARTSCOPE(isolate); |
| 1991 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1991 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1992 if (obj.IsArray()) { | 1992 // If the list is immutable we call into Dart for the indexed setter to |
| 1993 if (obj.IsImmutableArray()) { | 1993 // get the unsupported operation exception as the result. |
| 1994 return Api::NewError("Cannot modify immutable array"); | 1994 if (obj.IsArray() && !obj.IsImmutableArray()) { |
| 1995 } | |
| 1996 SET_LIST_ELEMENT(isolate, Array, obj, index, value); | 1995 SET_LIST_ELEMENT(isolate, Array, obj, index, value); |
| 1997 } else if (obj.IsGrowableObjectArray()) { | 1996 } else if (obj.IsGrowableObjectArray()) { |
| 1998 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); | 1997 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); |
| 1999 } else if (obj.IsError()) { | 1998 } else if (obj.IsError()) { |
| 2000 return list; | 1999 return list; |
| 2001 } else { | 2000 } else { |
| 2002 // Check and handle a dart object that implements the List interface. | 2001 // Check and handle a dart object that implements the List interface. |
| 2003 const Instance& instance = | 2002 const Instance& instance = |
| 2004 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2003 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2005 if (!instance.IsNull()) { | 2004 if (!instance.IsNull()) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2146 DARTSCOPE(isolate); | 2145 DARTSCOPE(isolate); |
| 2147 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 2146 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 2148 if (obj.IsUint8Array() || obj.IsExternalUint8Array() || | 2147 if (obj.IsUint8Array() || obj.IsExternalUint8Array() || |
| 2149 obj.IsUint8ClampedArray() || obj.IsExternalUint8ClampedArray()) { | 2148 obj.IsUint8ClampedArray() || obj.IsExternalUint8ClampedArray()) { |
| 2150 const ByteArray& byte_array = ByteArray::Cast(obj); | 2149 const ByteArray& byte_array = ByteArray::Cast(obj); |
| 2151 if (Utils::RangeCheck(offset, length, byte_array.Length())) { | 2150 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
| 2152 ByteArray::Copy(byte_array, offset, native_array, length); | 2151 ByteArray::Copy(byte_array, offset, native_array, length); |
| 2153 return Api::Success(isolate); | 2152 return Api::Success(isolate); |
| 2154 } | 2153 } |
| 2155 return Api::NewError("Invalid length passed in to set list elements"); | 2154 return Api::NewError("Invalid length passed in to set list elements"); |
| 2156 } else if (obj.IsArray()) { | 2155 } else if (obj.IsArray() && !obj.IsImmutableArray()) { |
| 2157 if (obj.IsImmutableArray()) { | 2156 // If the list is immutable we call into Dart for the indexed setter to |
| 2158 return Api::NewError("Cannot modify immutable array"); | 2157 // get the unsupported operation exception as the result. |
| 2159 } | |
| 2160 SET_LIST_ELEMENT_AS_BYTES(isolate, | 2158 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2161 Array, | 2159 Array, |
| 2162 obj, | 2160 obj, |
| 2163 native_array, | 2161 native_array, |
| 2164 offset, | 2162 offset, |
| 2165 length); | 2163 length); |
| 2166 } else if (obj.IsGrowableObjectArray()) { | 2164 } else if (obj.IsGrowableObjectArray()) { |
| 2167 SET_LIST_ELEMENT_AS_BYTES(isolate, | 2165 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2168 GrowableObjectArray, | 2166 GrowableObjectArray, |
| 2169 obj, | 2167 obj, |
| 2170 native_array, | 2168 native_array, |
| 2171 offset, | 2169 offset, |
| 2172 length); | 2170 length); |
| 2173 } else if (obj.IsError()) { | 2171 } else if (obj.IsError()) { |
| 2174 return list; | 2172 return list; |
| 2175 } else { | 2173 } else { |
| 2176 // Check and handle a dart object that implements the List interface. | 2174 // Check and handle a dart object that implements the List interface. |
| 2177 const Instance& instance = | 2175 const Instance& instance = |
| 2178 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2176 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2179 if (!instance.IsNull()) { | 2177 if (!instance.IsNull()) { |
| 2180 const Function& function = Function::Handle( | 2178 const Function& function = Function::Handle( |
| 2181 isolate, | 2179 isolate, |
| 2182 Resolver::ResolveDynamic(instance, | 2180 Resolver::ResolveDynamic(instance, |
| 2183 Symbols::AssignIndexToken(), | 2181 Symbols::AssignIndexToken(), |
| 2184 3, | 2182 3, |
| 2185 0)); | 2183 0)); |
| 2186 if (!function.IsNull()) { | 2184 if (!function.IsNull()) { |
| (...skipping 2337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4524 } | 4522 } |
| 4525 { | 4523 { |
| 4526 NoGCScope no_gc; | 4524 NoGCScope no_gc; |
| 4527 RawObject* raw_obj = obj.raw(); | 4525 RawObject* raw_obj = obj.raw(); |
| 4528 isolate->heap()->SetPeer(raw_obj, peer); | 4526 isolate->heap()->SetPeer(raw_obj, peer); |
| 4529 } | 4527 } |
| 4530 return Api::Success(isolate); | 4528 return Api::Success(isolate); |
| 4531 } | 4529 } |
| 4532 | 4530 |
| 4533 } // namespace dart | 4531 } // namespace dart |
| OLD | NEW |