Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012, 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 | 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" | 
| 11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" | 
| (...skipping 2011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2023 args.SetAt(2, value_obj); | 2023 args.SetAt(2, value_obj); | 
| 2024 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(function, | 2024 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(function, | 
| 2025 args)); | 2025 args)); | 
| 2026 } | 2026 } | 
| 2027 } | 2027 } | 
| 2028 return Api::NewError("Object does not implement the 'List' interface"); | 2028 return Api::NewError("Object does not implement the 'List' interface"); | 
| 2029 } | 2029 } | 
| 2030 } | 2030 } | 
| 2031 | 2031 | 
| 2032 | 2032 | 
| 2033 // TODO(hpayer): value should always be smaller then 0xff. Add error handling. | |
| 2034 #define GET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ | 2033 #define GET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ | 
| 2035 length) \ | 2034 length) \ | 
| 2036 const type& array = type::Cast(obj); \ | 2035 const type& array = type::Cast(obj); \ | 
| 2037 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 2036 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 
| 2038 Object& element = Object::Handle(isolate); \ | 2037 Object& element = Object::Handle(isolate); \ | 
| 2039 for (int i = 0; i < length; i++) { \ | 2038 for (int i = 0; i < length; i++) { \ | 
| 2040 element = array.At(offset + i); \ | 2039 element = array.At(offset + i); \ | 
| 2041 if (!element.IsInteger()) { \ | 2040 if (!element.IsInteger()) { \ | 
| 2042 return Api::NewError("%s expects the argument 'list' to be " \ | 2041 Dart_Handle argument_error_class = \ | 
| 2043 "a List of int", CURRENT_FUNC); \ | 2042 Dart_GetClass( \ | 
| 2043 Dart_LookupLibrary(Dart_NewStringFromCString("dart:core")), \ | |
| 2044 Dart_NewStringFromCString("ArgumentError")); \ | |
| 2045 Dart_Handle args[1]; \ | |
| 2046 args[0] = Dart_NewStringFromCString("List contains non-int elements"); \ | |
| 2047 Dart_Handle exception = \ | |
| 2048 Dart_New(argument_error_class, Dart_Null(), 1, args); \ | |
| 2049 return Dart_ThrowException(exception); \ | |
| 2044 } \ | 2050 } \ | 
| 2045 const Integer& integer = Integer::Cast(element); \ | 2051 const Integer& integer = Integer::Cast(element); \ | 
| 2046 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ | 2052 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ | 
| 2047 ASSERT(integer.AsInt64Value() <= 0xff); \ | 2053 ASSERT(integer.AsInt64Value() <= 0xff); \ | 
| 
 
Mads Ager (google)
2013/01/31 07:53:30
I think this is what the TODO was about? It seems
 
Søren Gjesse
2013/01/31 12:12:01
You are right. I just saw the clamping and thought
 
 | |
| 2048 } \ | 2054 } \ | 
| 2049 return Api::Success(isolate); \ | 2055 return Api::Success(isolate); \ | 
| 2050 } \ | 2056 } \ | 
| 2051 return Api::NewError("Invalid length passed in to access array elements"); \ | 2057 return Api::NewError("Invalid length passed in to access array elements"); \ | 
| 2052 | 2058 | 
| 2053 | 2059 | 
| 2054 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 2060 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 
| 2055 intptr_t offset, | 2061 intptr_t offset, | 
| 2056 uint8_t* native_array, | 2062 uint8_t* native_array, | 
| 2057 intptr_t length) { | 2063 intptr_t length) { | 
| (...skipping 2464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4522 } | 4528 } | 
| 4523 { | 4529 { | 
| 4524 NoGCScope no_gc; | 4530 NoGCScope no_gc; | 
| 4525 RawObject* raw_obj = obj.raw(); | 4531 RawObject* raw_obj = obj.raw(); | 
| 4526 isolate->heap()->SetPeer(raw_obj, peer); | 4532 isolate->heap()->SetPeer(raw_obj, peer); | 
| 4527 } | 4533 } | 
| 4528 return Api::Success(isolate); | 4534 return Api::Success(isolate); | 
| 4529 } | 4535 } | 
| 4530 | 4536 | 
| 4531 } // namespace dart | 4537 } // namespace dart | 
| OLD | NEW |