| 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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
| 11 #include "vm/native_entry.h" | 11 #include "vm/native_entry.h" |
| 12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 DEFINE_NATIVE_ENTRY(ByteBuffer_allocate, 1) { | 16 DEFINE_NATIVE_ENTRY(ByteBuffer_allocate, 1) { |
| 17 const Instance& length_instance = Instance::CheckedHandle(arguments->At(0)); | 17 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
| 18 if (!length_instance.IsSmi()) { | |
| 19 GrowableArray<const Object*> args; | |
| 20 args.Add(&length_instance); | |
| 21 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | |
| 22 } | |
| 23 Smi& length = Smi::Handle(); | |
| 24 length ^= length_instance.raw(); | |
| 25 if (length.Value() < 0) { | 18 if (length.Value() < 0) { |
| 26 GrowableArray<const Object*> args; | 19 GrowableArray<const Object*> args; |
| 27 args.Add(&length); | 20 args.Add(&length); |
| 28 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 21 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 29 } | 22 } |
| 30 uint8_t* data = new uint8_t[length.Value()]; | 23 uint8_t* data = new uint8_t[length.Value()]; |
| 31 memset(data, 0, length.Value()); | 24 memset(data, 0, length.Value()); |
| 32 const ByteBuffer& new_array = | 25 const ByteBuffer& new_array = |
| 33 ByteBuffer::Handle(ByteBuffer::New(data, length.Value())); | 26 ByteBuffer::Handle(ByteBuffer::New(data, length.Value())); |
| 34 arguments->SetReturn(new_array); | 27 arguments->SetReturn(new_array); |
| 35 } | 28 } |
| 36 | 29 |
| 37 | 30 |
| 38 DEFINE_NATIVE_ENTRY(ByteBuffer_getLength, 1) { | 31 DEFINE_NATIVE_ENTRY(ByteBuffer_getLength, 1) { |
| 39 const ByteBuffer& array = ByteBuffer::CheckedHandle(arguments->At(0)); | 32 const ByteBuffer& array = ByteBuffer::CheckedHandle(arguments->At(0)); |
| 40 if (array.IsNull()) { | |
| 41 // TODO(asiva): Need to handle error cases. | |
| 42 UNIMPLEMENTED(); | |
| 43 return; | |
| 44 } | |
| 45 const Smi& length = Smi::Handle(Smi::New(array.Length())); | 33 const Smi& length = Smi::Handle(Smi::New(array.Length())); |
| 46 arguments->SetReturn(length); | 34 arguments->SetReturn(length); |
| 47 } | 35 } |
| 48 | 36 |
| 49 | 37 |
| 50 template<typename ValueType, typename ObjectType> | 38 template<typename ValueType, typename ObjectType> |
| 51 static void GetIndexed(NativeArguments* arguments) { | 39 static void GetIndexed(NativeArguments* arguments) { |
| 52 const ByteBuffer& buffer = ByteBuffer::CheckedHandle(arguments->At(0)); | 40 const ByteBuffer& buffer = ByteBuffer::CheckedHandle(arguments->At(0)); |
| 53 const Instance& index_instance = Instance::CheckedHandle(arguments->At(1)); | 41 const Instance& index_instance = Instance::CheckedHandle(arguments->At(1)); |
| 54 if (!index_instance.IsSmi()) { | 42 if (!index_instance.IsSmi()) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 DEFINE_NATIVE_ENTRY(ByteBuffer_getFloat64, 2) { | 225 DEFINE_NATIVE_ENTRY(ByteBuffer_getFloat64, 2) { |
| 238 GetIndexed<double, Double>(arguments); | 226 GetIndexed<double, Double>(arguments); |
| 239 } | 227 } |
| 240 | 228 |
| 241 | 229 |
| 242 DEFINE_NATIVE_ENTRY(ByteBuffer_setFloat64, 3) { | 230 DEFINE_NATIVE_ENTRY(ByteBuffer_setFloat64, 3) { |
| 243 SetIndexed<double, Double>(arguments); | 231 SetIndexed<double, Double>(arguments); |
| 244 } | 232 } |
| 245 | 233 |
| 246 } // namespace dart | 234 } // namespace dart |
| OLD | NEW |