Chromium Code Reviews| 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 (obj.IsArray() && !obj.IsImmutableArray()) { |
|
Ivan Posva
2013/01/25 00:53:48
How about adding a comment that we let the Dart in
Mads Ager (google)
2013/01/29 10:15:13
Done. If index is out of bounds we still get an un
| |
| 1993 if (obj.IsImmutableArray()) { | |
| 1994 return Api::NewError("Cannot modify immutable array"); | |
| 1995 } | |
| 1996 SET_LIST_ELEMENT(isolate, Array, obj, index, value); | 1993 SET_LIST_ELEMENT(isolate, Array, obj, index, value); |
| 1997 } else if (obj.IsGrowableObjectArray()) { | 1994 } else if (obj.IsGrowableObjectArray()) { |
| 1998 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); | 1995 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); |
| 1999 } else if (obj.IsError()) { | 1996 } else if (obj.IsError()) { |
| 2000 return list; | 1997 return list; |
| 2001 } else { | 1998 } else { |
| 2002 // Check and handle a dart object that implements the List interface. | 1999 // Check and handle a dart object that implements the List interface. |
| 2003 const Instance& instance = | 2000 const Instance& instance = |
| 2004 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2001 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2005 if (!instance.IsNull()) { | 2002 if (!instance.IsNull()) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2146 DARTSCOPE(isolate); | 2143 DARTSCOPE(isolate); |
| 2147 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 2144 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 2148 if (obj.IsUint8Array() || obj.IsExternalUint8Array() || | 2145 if (obj.IsUint8Array() || obj.IsExternalUint8Array() || |
| 2149 obj.IsUint8ClampedArray() || obj.IsExternalUint8ClampedArray()) { | 2146 obj.IsUint8ClampedArray() || obj.IsExternalUint8ClampedArray()) { |
| 2150 const ByteArray& byte_array = ByteArray::Cast(obj); | 2147 const ByteArray& byte_array = ByteArray::Cast(obj); |
| 2151 if (Utils::RangeCheck(offset, length, byte_array.Length())) { | 2148 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
| 2152 ByteArray::Copy(byte_array, offset, native_array, length); | 2149 ByteArray::Copy(byte_array, offset, native_array, length); |
| 2153 return Api::Success(isolate); | 2150 return Api::Success(isolate); |
| 2154 } | 2151 } |
| 2155 return Api::NewError("Invalid length passed in to set list elements"); | 2152 return Api::NewError("Invalid length passed in to set list elements"); |
| 2156 } else if (obj.IsArray()) { | 2153 } else if (obj.IsArray() && !obj.IsImmutableArray()) { |
|
Ivan Posva
2013/01/25 00:53:48
ditto.
Mads Ager (google)
2013/01/29 10:15:13
Done.
| |
| 2157 if (obj.IsImmutableArray()) { | |
| 2158 return Api::NewError("Cannot modify immutable array"); | |
| 2159 } | |
| 2160 SET_LIST_ELEMENT_AS_BYTES(isolate, | 2154 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2161 Array, | 2155 Array, |
| 2162 obj, | 2156 obj, |
| 2163 native_array, | 2157 native_array, |
| 2164 offset, | 2158 offset, |
| 2165 length); | 2159 length); |
| 2166 } else if (obj.IsGrowableObjectArray()) { | 2160 } else if (obj.IsGrowableObjectArray()) { |
| 2167 SET_LIST_ELEMENT_AS_BYTES(isolate, | 2161 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2168 GrowableObjectArray, | 2162 GrowableObjectArray, |
| 2169 obj, | 2163 obj, |
| 2170 native_array, | 2164 native_array, |
| 2171 offset, | 2165 offset, |
| 2172 length); | 2166 length); |
| 2173 } else if (obj.IsError()) { | 2167 } else if (obj.IsError()) { |
| 2174 return list; | 2168 return list; |
| 2175 } else { | 2169 } else { |
| 2176 // Check and handle a dart object that implements the List interface. | 2170 // Check and handle a dart object that implements the List interface. |
| 2177 const Instance& instance = | 2171 const Instance& instance = |
| 2178 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2172 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2179 if (!instance.IsNull()) { | 2173 if (!instance.IsNull()) { |
| 2180 const Function& function = Function::Handle( | 2174 const Function& function = Function::Handle( |
| 2181 isolate, | 2175 isolate, |
| 2182 Resolver::ResolveDynamic(instance, | 2176 Resolver::ResolveDynamic(instance, |
| 2183 Symbols::AssignIndexToken(), | 2177 Symbols::AssignIndexToken(), |
| 2184 3, | 2178 3, |
| 2185 0)); | 2179 0)); |
| 2186 if (!function.IsNull()) { | 2180 if (!function.IsNull()) { |
| (...skipping 2337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4524 } | 4518 } |
| 4525 { | 4519 { |
| 4526 NoGCScope no_gc; | 4520 NoGCScope no_gc; |
| 4527 RawObject* raw_obj = obj.raw(); | 4521 RawObject* raw_obj = obj.raw(); |
| 4528 isolate->heap()->SetPeer(raw_obj, peer); | 4522 isolate->heap()->SetPeer(raw_obj, peer); |
| 4529 } | 4523 } |
| 4530 return Api::Success(isolate); | 4524 return Api::Success(isolate); |
| 4531 } | 4525 } |
| 4532 | 4526 |
| 4533 } // namespace dart | 4527 } // namespace dart |
| OLD | NEW |