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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
6 | 6 |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
9 #include "vm/native_entry.h" | 9 #include "vm/native_entry.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 DEFINE_NATIVE_ENTRY(ByteArray_getLength, 1) { | 14 // ByteArray |
15 const ByteArray& byte_array = ByteArray::CheckedHandle(arguments->At(0)); | |
16 const Smi& length = Smi::Handle(Smi::New(byte_array.Length())); | |
17 arguments->SetReturn(length); | |
18 } | |
19 | |
20 | |
21 DEFINE_NATIVE_ENTRY(InternalByteArray_allocate, 1) { | |
22 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); | |
23 if (length.Value() < 0) { | |
24 GrowableArray<const Object*> args; | |
25 args.Add(&length); | |
26 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | |
27 } | |
28 const InternalByteArray& new_array = | |
29 InternalByteArray::Handle(InternalByteArray::New(length.Value())); | |
30 arguments->SetReturn(new_array); | |
31 } | |
32 | |
33 | 15 |
34 static void RangeCheck(const ByteArray& array, | 16 static void RangeCheck(const ByteArray& array, |
35 intptr_t index, | 17 intptr_t index, |
36 intptr_t num_bytes) { | 18 intptr_t num_bytes) { |
37 if (!Utils::RangeCheck(index, num_bytes, array.Length())) { | 19 if (!Utils::RangeCheck(index, num_bytes, array.ByteLength())) { |
38 GrowableArray<const Object*> arguments; | 20 GrowableArray<const Object*> arguments; |
39 const Smi &index_object = Smi::Handle(Smi::New(index)); | 21 const Smi &index_object = Smi::Handle(Smi::New(index)); |
40 arguments.Add(&index_object); | 22 arguments.Add(&index_object); |
41 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); | 23 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); |
42 } | 24 } |
43 } | 25 } |
44 | 26 |
45 | 27 |
| 28 #define GETTER_ARGUMENTS(ArrayT, ValueT) \ |
| 29 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ |
| 30 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); |
| 31 |
| 32 |
| 33 #define SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT) \ |
| 34 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ |
| 35 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); \ |
| 36 GET_NATIVE_ARGUMENT(ObjectT, value_object, arguments->At(2)); |
| 37 |
| 38 |
| 39 #define GETTER(ArrayT, ObjectT, ValueT) \ |
| 40 GETTER_ARGUMENTS(ArrayT, ValueT); \ |
| 41 RangeCheck(array, index.Value() * sizeof(ValueT), sizeof(ValueT)); \ |
| 42 ValueT result = array.At(index.Value()); \ |
| 43 arguments->SetReturn(ObjectT::Handle(ObjectT::New(result))); |
| 44 |
| 45 |
| 46 #define SETTER(ArrayT, ObjectT, Getter, ValueT) \ |
| 47 SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT); \ |
| 48 RangeCheck(array, index.Value() * sizeof(ValueT), sizeof(ValueT)); \ |
| 49 ValueT value = value_object.Getter(); \ |
| 50 array.SetAt(index.Value(), value); |
| 51 |
| 52 |
| 53 #define UNALIGNED_GETTER(ArrayT, ObjectT, ValueT) \ |
| 54 GETTER_ARGUMENTS(ArrayT, ValueT); \ |
| 55 RangeCheck(array, index.Value(), sizeof(ValueT)); \ |
| 56 ValueT result; \ |
| 57 ByteArray::Copy(&result, array, index.Value(), sizeof(ValueT)); \ |
| 58 arguments->SetReturn(ObjectT::Handle(ObjectT::New(result))); |
| 59 |
| 60 |
| 61 #define UNALIGNED_SETTER(ArrayT, ObjectT, Getter, ValueT) \ |
| 62 SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT); \ |
| 63 RangeCheck(array, index.Value(), sizeof(ValueT)); \ |
| 64 ValueT src = value_object.Getter(); \ |
| 65 ByteArray::Copy(array, index.Value(), &src, sizeof(ValueT)); |
| 66 |
| 67 |
| 68 #define UINT64_TO_INTEGER(value, integer) \ |
| 69 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { \ |
| 70 result = BigintOperations::NewFromUint64(value); \ |
| 71 } else if (value > static_cast<uint64_t>(Smi::kMaxValue)) { \ |
| 72 result = Mint::New(value); \ |
| 73 } else { \ |
| 74 result = Smi::New(value); \ |
| 75 } |
| 76 |
| 77 |
| 78 #define GETTER_UINT64(ArrayT) \ |
| 79 GETTER_ARGUMENTS(ArrayT, uint64_t); \ |
| 80 intptr_t size = sizeof(uint64_t); \ |
| 81 RangeCheck(array, index.Value() * size, size); \ |
| 82 uint64_t value = array.At(index.Value()); \ |
| 83 Integer& result = Integer::Handle(); \ |
| 84 UINT64_TO_INTEGER(value, result); \ |
| 85 arguments->SetReturn(result); |
| 86 |
| 87 |
| 88 #define UNALIGNED_GETTER_UINT64(ArrayT) \ |
| 89 GETTER_ARGUMENTS(ArrayT, uint64_t); \ |
| 90 RangeCheck(array, index.Value(), sizeof(uint64_t)); \ |
| 91 uint64_t value; \ |
| 92 ByteArray::Copy(&value, array, index.Value(), sizeof(uint64_t)); \ |
| 93 Integer& result = Integer::Handle(); \ |
| 94 UINT64_TO_INTEGER(value, result); \ |
| 95 arguments->SetReturn(result); |
| 96 |
| 97 |
| 98 #define INTEGER_TO_UINT64(integer, uint64) \ |
| 99 if (integer.IsBigint()) { \ |
| 100 Bigint& bigint = Bigint::Handle(); \ |
| 101 bigint ^= integer.raw(); \ |
| 102 ASSERT(BigintOperations::FitsIntoUint64(bigint)); \ |
| 103 value = BigintOperations::AbsToUint64(bigint); \ |
| 104 } else { \ |
| 105 ASSERT(integer.IsMint() || integer.IsSmi()); \ |
| 106 value = integer.AsInt64Value(); \ |
| 107 } \ |
| 108 |
| 109 |
| 110 #define SETTER_UINT64(ArrayT) \ |
| 111 SETTER_ARGUMENTS(ArrayT, Integer, uint64_t); \ |
| 112 intptr_t size = sizeof(uint64_t); \ |
| 113 RangeCheck(array, index.Value() * size, size); \ |
| 114 uint64_t value; \ |
| 115 INTEGER_TO_UINT64(value_object, value); \ |
| 116 array.SetAt(index.Value(), value); |
| 117 |
| 118 |
| 119 #define UNALIGNED_SETTER_UINT64(ArrayT) \ |
| 120 SETTER_ARGUMENTS(ArrayT, Integer, uint64_t); \ |
| 121 RangeCheck(array, index.Value(), sizeof(uint64_t)); \ |
| 122 uint64_t value; \ |
| 123 INTEGER_TO_UINT64(value_object, value); \ |
| 124 ByteArray::Copy(array, index.Value(), &value, sizeof(uint64_t)); |
| 125 |
| 126 |
| 127 DEFINE_NATIVE_ENTRY(ByteArray_getLength, 1) { |
| 128 GET_NATIVE_ARGUMENT(ByteArray, array, arguments->At(0)); |
| 129 const Smi& length = Smi::Handle(Smi::New(array.Length())); |
| 130 arguments->SetReturn(length); |
| 131 } |
| 132 |
| 133 |
| 134 DEFINE_NATIVE_ENTRY(ByteArray_getInt8, 2) { |
| 135 UNALIGNED_GETTER(ByteArray, Smi, int8_t); |
| 136 } |
| 137 |
| 138 |
| 139 DEFINE_NATIVE_ENTRY(ByteArray_setInt8, 3) { |
| 140 UNALIGNED_SETTER(ByteArray, Smi, Value, int8_t); |
| 141 } |
| 142 |
| 143 |
| 144 DEFINE_NATIVE_ENTRY(ByteArray_getUint8, 2) { |
| 145 UNALIGNED_GETTER(ByteArray, Smi, uint8_t); |
| 146 } |
| 147 |
| 148 |
| 149 DEFINE_NATIVE_ENTRY(ByteArray_setUint8, 3) { |
| 150 UNALIGNED_SETTER(ByteArray, Smi, Value, uint8_t); |
| 151 } |
| 152 |
| 153 |
| 154 DEFINE_NATIVE_ENTRY(ByteArray_getInt16, 2) { |
| 155 UNALIGNED_GETTER(ByteArray, Smi, int16_t); |
| 156 } |
| 157 |
| 158 |
| 159 DEFINE_NATIVE_ENTRY(ByteArray_setInt16, 3) { |
| 160 UNALIGNED_SETTER(ByteArray, Smi, Value, int16_t); |
| 161 } |
| 162 |
| 163 |
| 164 DEFINE_NATIVE_ENTRY(ByteArray_getUint16, 2) { |
| 165 UNALIGNED_GETTER(ByteArray, Smi, uint16_t); |
| 166 } |
| 167 |
| 168 |
| 169 DEFINE_NATIVE_ENTRY(ByteArray_setUint16, 3) { |
| 170 UNALIGNED_SETTER(ByteArray, Smi, Value, uint16_t); |
| 171 } |
| 172 |
| 173 |
| 174 DEFINE_NATIVE_ENTRY(ByteArray_getInt32, 2) { |
| 175 UNALIGNED_GETTER(ByteArray, Integer, int32_t); |
| 176 } |
| 177 |
| 178 |
| 179 DEFINE_NATIVE_ENTRY(ByteArray_setInt32, 3) { |
| 180 UNALIGNED_SETTER(ByteArray, Integer, AsInt64Value, int32_t); |
| 181 } |
| 182 |
| 183 |
| 184 DEFINE_NATIVE_ENTRY(ByteArray_getUint32, 2) { |
| 185 UNALIGNED_GETTER(ByteArray, Integer, uint32_t); |
| 186 } |
| 187 |
| 188 |
| 189 DEFINE_NATIVE_ENTRY(ByteArray_setUint32, 3) { |
| 190 UNALIGNED_SETTER(ByteArray, Integer, AsInt64Value, uint32_t); |
| 191 } |
| 192 |
| 193 |
| 194 DEFINE_NATIVE_ENTRY(ByteArray_getInt64, 2) { |
| 195 UNALIGNED_GETTER(ByteArray, Integer, int64_t); |
| 196 } |
| 197 |
| 198 |
| 199 DEFINE_NATIVE_ENTRY(ByteArray_setInt64, 3) { |
| 200 UNALIGNED_SETTER(ByteArray, Integer, AsInt64Value, int64_t); |
| 201 } |
| 202 |
| 203 |
| 204 DEFINE_NATIVE_ENTRY(ByteArray_getUint64, 2) { |
| 205 UNALIGNED_GETTER_UINT64(ByteArray); |
| 206 } |
| 207 |
| 208 |
| 209 DEFINE_NATIVE_ENTRY(ByteArray_setUint64, 3) { |
| 210 UNALIGNED_SETTER_UINT64(ByteArray); |
| 211 } |
| 212 |
| 213 |
| 214 DEFINE_NATIVE_ENTRY(ByteArray_getFloat32, 2) { |
| 215 UNALIGNED_GETTER(ByteArray, Double, float); |
| 216 } |
| 217 |
| 218 |
| 219 DEFINE_NATIVE_ENTRY(ByteArray_setFloat32, 3) { |
| 220 UNALIGNED_SETTER(ByteArray, Double, value, float); |
| 221 } |
| 222 |
| 223 |
| 224 DEFINE_NATIVE_ENTRY(ByteArray_getFloat64, 2) { |
| 225 UNALIGNED_GETTER(ByteArray, Double, double); |
| 226 } |
| 227 |
| 228 |
| 229 DEFINE_NATIVE_ENTRY(ByteArray_setFloat64, 3) { |
| 230 UNALIGNED_SETTER(ByteArray, Double, value, double); |
| 231 } |
| 232 |
| 233 |
46 DEFINE_NATIVE_ENTRY(ByteArray_setRange, 5) { | 234 DEFINE_NATIVE_ENTRY(ByteArray_setRange, 5) { |
47 ByteArray& dst = ByteArray::CheckedHandle(arguments->At(0)); | 235 ByteArray& dst = ByteArray::CheckedHandle(arguments->At(0)); |
48 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(1)); | 236 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(1)); |
49 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(2)); | 237 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(2)); |
50 GET_NATIVE_ARGUMENT(ByteArray, src, arguments->At(3)); | 238 GET_NATIVE_ARGUMENT(ByteArray, src, arguments->At(3)); |
51 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(4)); | 239 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(4)); |
52 intptr_t length_value = length.Value(); | 240 intptr_t length_value = length.Value(); |
53 intptr_t src_start_value = src_start.Value(); | 241 intptr_t src_start_value = src_start.Value(); |
54 intptr_t dst_start_value = dst_start.Value(); | 242 intptr_t dst_start_value = dst_start.Value(); |
55 if (length_value < 0) { | 243 if (length_value < 0) { |
56 GrowableArray<const Object*> args; | 244 GrowableArray<const Object*> args; |
57 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 245 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
58 } | 246 } |
59 RangeCheck(src, src_start_value, length_value); | 247 RangeCheck(src, src_start_value, length_value); |
60 RangeCheck(dst, dst_start_value, length_value); | 248 RangeCheck(dst, dst_start_value, length_value); |
61 ByteArray::Copy(dst, dst_start_value, src, src_start_value, length_value); | 249 ByteArray::Copy(dst, dst_start_value, src, src_start_value, length_value); |
62 } | 250 } |
63 | 251 |
64 #define GETTER_ARGUMENTS(ArrayT, ValueT) \ | 252 |
65 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ | 253 // Int8Array |
66 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); \ | 254 |
67 RangeCheck(array, index.Value(), sizeof(ValueT)); | 255 DEFINE_NATIVE_ENTRY(Int8Array_new, 1) { |
68 | 256 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
69 | 257 if (length.Value() < 0) { |
70 #define SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT) \ | 258 GrowableArray<const Object*> args; |
71 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ | 259 args.Add(&length); |
72 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); \ | 260 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
73 RangeCheck(array, index.Value(), sizeof(ValueT)); \ | 261 } |
74 GET_NATIVE_ARGUMENT(ObjectT, integer_value, arguments->At(2)); | 262 const Int8Array& new_array = |
75 | 263 Int8Array::Handle(Int8Array::New(length.Value())); |
76 | 264 arguments->SetReturn(new_array); |
77 #define GETTER(ArrayT, ObjectT, ValueT) \ | 265 } |
78 GETTER_ARGUMENTS(ArrayT, ValueT); \ | 266 |
79 ValueT result = array.UnalignedAt<ValueT>(index.Value()); \ | 267 |
80 arguments->SetReturn(ObjectT::Handle(ObjectT::New(result))); | 268 DEFINE_NATIVE_ENTRY(Int8Array_getIndexed, 2) { |
81 | 269 GETTER(Int8Array, Smi, int8_t); |
82 | 270 } |
83 #define SETTER(ArrayT, ObjectT, Getter, ValueT) \ | 271 |
84 SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT); \ | 272 |
85 array.SetUnalignedAt<ValueT>(index.Value(), integer_value.Getter()); | 273 DEFINE_NATIVE_ENTRY(Int8Array_setIndexed, 3) { |
86 | 274 SETTER(Int8Array, Smi, Value, int8_t); |
87 | 275 } |
88 #define GETTER_UINT64(ArrayT) \ | 276 |
89 GETTER_ARGUMENTS(ArrayT, uint64_t); \ | 277 |
90 uint64_t value = array.UnalignedAt<uint64_t>(index.Value()); \ | 278 // Uint8Array |
91 Integer& result = Integer::Handle(); \ | 279 |
92 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { \ | 280 DEFINE_NATIVE_ENTRY(Uint8Array_new, 1) { |
93 result = BigintOperations::NewFromUint64(value); \ | 281 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
94 } else if (value > static_cast<uint64_t>(Smi::kMaxValue)) { \ | 282 if (length.Value() < 0) { |
95 result = Mint::New(value); \ | 283 GrowableArray<const Object*> args; |
96 } else { \ | 284 args.Add(&length); |
97 result = Smi::New(value); \ | 285 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
98 } \ | 286 } |
99 arguments->SetReturn(result); | 287 const Uint8Array& new_array = |
100 | 288 Uint8Array::Handle(Uint8Array::New(length.Value())); |
101 | 289 arguments->SetReturn(new_array); |
102 #define SETTER_UINT64(ArrayT) \ | 290 } |
103 SETTER_ARGUMENTS(ArrayT, Integer, uint64_t); \ | 291 |
104 uint64_t value; \ | 292 |
105 if (integer_value.IsBigint()) { \ | 293 DEFINE_NATIVE_ENTRY(Uint8Array_getIndexed, 2) { |
106 Bigint& bigint_value = Bigint::Handle(); \ | 294 GETTER(Uint8Array, Smi, uint8_t); |
107 bigint_value ^= integer_value.raw(); \ | 295 } |
108 ASSERT(BigintOperations::FitsIntoUint64(bigint_value)); \ | 296 |
109 value = BigintOperations::AbsToUint64(bigint_value); \ | 297 |
110 } else { \ | 298 DEFINE_NATIVE_ENTRY(Uint8Array_setIndexed, 3) { |
111 ASSERT(integer_value.IsMint() || integer_value.IsSmi()); \ | 299 SETTER(Uint8Array, Smi, Value, uint8_t); |
112 value = integer_value.AsInt64Value(); \ | 300 } |
113 } \ | 301 |
114 array.SetUnalignedAt<uint64_t>(index.Value(), value); | 302 |
115 | 303 // Int16Array |
116 | 304 |
117 DEFINE_NATIVE_ENTRY(InternalByteArray_getInt8, 2) { | 305 DEFINE_NATIVE_ENTRY(Int16Array_new, 1) { |
118 GETTER(InternalByteArray, Smi, int8_t); | 306 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
119 } | 307 if (length.Value() < 0) { |
120 | 308 GrowableArray<const Object*> args; |
121 | 309 args.Add(&length); |
122 DEFINE_NATIVE_ENTRY(InternalByteArray_setInt8, 3) { | 310 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
123 SETTER(InternalByteArray, Smi, Value, int8_t); | 311 } |
124 } | 312 const Int16Array& new_array = |
125 | 313 Int16Array::Handle(Int16Array::New(length.Value())); |
126 | 314 arguments->SetReturn(new_array); |
127 DEFINE_NATIVE_ENTRY(InternalByteArray_getUint8, 2) { | 315 } |
128 GETTER(InternalByteArray, Smi, uint8_t); | 316 |
129 } | 317 |
130 | 318 DEFINE_NATIVE_ENTRY(Int16Array_getIndexed, 2) { |
131 | 319 GETTER(Int16Array, Smi, int16_t); |
132 DEFINE_NATIVE_ENTRY(InternalByteArray_setUint8, 3) { | 320 } |
133 SETTER(InternalByteArray, Smi, Value, uint8_t); | 321 |
134 } | 322 |
135 | 323 DEFINE_NATIVE_ENTRY(Int16Array_setIndexed, 3) { |
136 | 324 SETTER(Int16Array, Smi, Value, int16_t); |
137 DEFINE_NATIVE_ENTRY(InternalByteArray_getInt16, 2) { | 325 } |
138 GETTER(InternalByteArray, Smi, int16_t); | 326 |
139 } | 327 |
140 | 328 // Uint16Array |
141 | 329 |
142 DEFINE_NATIVE_ENTRY(InternalByteArray_setInt16, 3) { | 330 DEFINE_NATIVE_ENTRY(Uint16Array_new, 1) { |
143 SETTER(InternalByteArray, Smi, Value, int16_t); | 331 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
144 } | 332 if (length.Value() < 0) { |
145 | 333 GrowableArray<const Object*> args; |
146 | 334 args.Add(&length); |
147 DEFINE_NATIVE_ENTRY(InternalByteArray_getUint16, 2) { | 335 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
148 GETTER(InternalByteArray, Smi, uint16_t); | 336 } |
149 } | 337 const Uint16Array& new_array = |
150 | 338 Uint16Array::Handle(Uint16Array::New(length.Value())); |
151 | 339 arguments->SetReturn(new_array); |
152 DEFINE_NATIVE_ENTRY(InternalByteArray_setUint16, 3) { | 340 } |
153 SETTER(InternalByteArray, Smi, Value, uint16_t); | 341 |
154 } | 342 |
155 | 343 DEFINE_NATIVE_ENTRY(Uint16Array_getIndexed, 2) { |
156 | 344 GETTER(Uint16Array, Smi, uint16_t); |
157 DEFINE_NATIVE_ENTRY(InternalByteArray_getInt32, 2) { | 345 } |
158 GETTER(InternalByteArray, Integer, int32_t); | 346 |
159 } | 347 |
160 | 348 DEFINE_NATIVE_ENTRY(Uint16Array_setIndexed, 3) { |
161 | 349 SETTER(Uint16Array, Smi, Value, uint16_t); |
162 DEFINE_NATIVE_ENTRY(InternalByteArray_setInt32, 3) { | 350 } |
163 SETTER(InternalByteArray, Integer, AsInt64Value, int32_t); | 351 |
164 } | 352 |
165 | 353 // Int32Array |
166 | 354 |
167 DEFINE_NATIVE_ENTRY(InternalByteArray_getUint32, 2) { | 355 DEFINE_NATIVE_ENTRY(Int32Array_new, 1) { |
168 GETTER(InternalByteArray, Integer, uint32_t); | 356 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
169 } | 357 if (length.Value() < 0) { |
170 | 358 GrowableArray<const Object*> args; |
171 | 359 args.Add(&length); |
172 DEFINE_NATIVE_ENTRY(InternalByteArray_setUint32, 3) { | 360 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
173 SETTER(InternalByteArray, Integer, AsInt64Value, uint32_t); | 361 } |
174 } | 362 const Int32Array& new_array = |
175 | 363 Int32Array::Handle(Int32Array::New(length.Value())); |
176 | 364 arguments->SetReturn(new_array); |
177 DEFINE_NATIVE_ENTRY(InternalByteArray_getInt64, 2) { | 365 } |
178 GETTER(InternalByteArray, Integer, int64_t); | 366 |
179 } | 367 |
180 | 368 DEFINE_NATIVE_ENTRY(Int32Array_getIndexed, 2) { |
181 | 369 GETTER(Int32Array, Integer, int32_t); |
182 DEFINE_NATIVE_ENTRY(InternalByteArray_setInt64, 3) { | 370 } |
183 SETTER(InternalByteArray, Integer, AsInt64Value, int64_t); | 371 |
184 } | 372 |
185 | 373 DEFINE_NATIVE_ENTRY(Int32Array_setIndexed, 3) { |
186 | 374 SETTER(Int32Array, Integer, AsInt64Value, int32_t); |
187 DEFINE_NATIVE_ENTRY(InternalByteArray_getUint64, 2) { | 375 } |
188 GETTER_UINT64(InternalByteArray); | 376 |
189 } | 377 |
190 | 378 // Uint32Array |
191 | 379 |
192 DEFINE_NATIVE_ENTRY(InternalByteArray_setUint64, 3) { | 380 DEFINE_NATIVE_ENTRY(Uint32Array_new, 1) { |
193 SETTER_UINT64(InternalByteArray); | 381 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
194 } | 382 if (length.Value() < 0) { |
195 | 383 GrowableArray<const Object*> args; |
196 | 384 args.Add(&length); |
197 DEFINE_NATIVE_ENTRY(InternalByteArray_getFloat32, 2) { | 385 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
198 GETTER(InternalByteArray, Double, float); | 386 } |
199 } | 387 const Uint32Array& new_array = |
200 | 388 Uint32Array::Handle(Uint32Array::New(length.Value())); |
201 | 389 arguments->SetReturn(new_array); |
202 DEFINE_NATIVE_ENTRY(InternalByteArray_setFloat32, 3) { | 390 } |
203 SETTER(InternalByteArray, Double, value, float); | 391 |
204 } | 392 |
205 | 393 DEFINE_NATIVE_ENTRY(Uint32Array_getIndexed, 2) { |
206 | 394 GETTER(Uint32Array, Integer, uint32_t); |
207 DEFINE_NATIVE_ENTRY(InternalByteArray_getFloat64, 2) { | 395 } |
208 GETTER(InternalByteArray, Double, double); | 396 |
209 } | 397 |
210 | 398 DEFINE_NATIVE_ENTRY(Uint32Array_setIndexed, 3) { |
211 | 399 SETTER(Uint32Array, Integer, AsInt64Value, uint32_t); |
212 DEFINE_NATIVE_ENTRY(InternalByteArray_setFloat64, 3) { | 400 } |
213 SETTER(InternalByteArray, Double, value, double); | 401 |
214 } | 402 |
215 | 403 // Int64Array |
216 | 404 |
217 DEFINE_NATIVE_ENTRY(ExternalByteArray_getInt8, 2) { | 405 DEFINE_NATIVE_ENTRY(Int64Array_new, 1) { |
218 GETTER(ExternalByteArray, Smi, int8_t); | 406 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
219 } | 407 if (length.Value() < 0) { |
220 | 408 GrowableArray<const Object*> args; |
221 | 409 args.Add(&length); |
222 DEFINE_NATIVE_ENTRY(ExternalByteArray_setInt8, 3) { | 410 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
223 SETTER(ExternalByteArray, Smi, Value, int8_t); | 411 } |
224 } | 412 const Int64Array& new_array = |
225 | 413 Int64Array::Handle(Int64Array::New(length.Value())); |
226 | 414 arguments->SetReturn(new_array); |
227 DEFINE_NATIVE_ENTRY(ExternalByteArray_getUint8, 2) { | 415 } |
228 GETTER(ExternalByteArray, Smi, uint8_t); | 416 |
229 } | 417 |
230 | 418 DEFINE_NATIVE_ENTRY(Int64Array_getIndexed, 2) { |
231 | 419 GETTER(Int64Array, Integer, int64_t); |
232 DEFINE_NATIVE_ENTRY(ExternalByteArray_setUint8, 3) { | 420 } |
233 SETTER(ExternalByteArray, Smi, Value, uint8_t); | 421 |
234 } | 422 |
235 | 423 DEFINE_NATIVE_ENTRY(Int64Array_setIndexed, 3) { |
236 | 424 SETTER(Int64Array, Integer, AsInt64Value, int64_t); |
237 DEFINE_NATIVE_ENTRY(ExternalByteArray_getInt16, 2) { | 425 } |
238 GETTER(ExternalByteArray, Smi, int16_t); | 426 |
239 } | 427 |
240 | 428 // Uint64Array |
241 | 429 |
242 DEFINE_NATIVE_ENTRY(ExternalByteArray_setInt16, 3) { | 430 DEFINE_NATIVE_ENTRY(Uint64Array_new, 1) { |
243 SETTER(ExternalByteArray, Smi, Value, int16_t); | 431 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
244 } | 432 if (length.Value() < 0) { |
245 | 433 GrowableArray<const Object*> args; |
246 | 434 args.Add(&length); |
247 DEFINE_NATIVE_ENTRY(ExternalByteArray_getUint16, 2) { | 435 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
248 GETTER(ExternalByteArray, Smi, uint16_t); | 436 } |
249 } | 437 const Uint64Array& new_array = |
250 | 438 Uint64Array::Handle(Uint64Array::New(length.Value())); |
251 | 439 arguments->SetReturn(new_array); |
252 DEFINE_NATIVE_ENTRY(ExternalByteArray_setUint16, 3) { | 440 } |
253 SETTER(ExternalByteArray, Smi, Value, uint16_t); | 441 |
254 } | 442 |
255 | 443 DEFINE_NATIVE_ENTRY(Uint64Array_getIndexed, 2) { |
256 | 444 GETTER_UINT64(Uint64Array); |
257 DEFINE_NATIVE_ENTRY(ExternalByteArray_getInt32, 2) { | 445 } |
258 GETTER(ExternalByteArray, Integer, int32_t); | 446 |
259 } | 447 |
260 | 448 DEFINE_NATIVE_ENTRY(Uint64Array_setIndexed, 3) { |
261 | 449 SETTER_UINT64(Uint64Array); |
262 DEFINE_NATIVE_ENTRY(ExternalByteArray_setInt32, 3) { | 450 } |
263 SETTER(ExternalByteArray, Integer, AsInt64Value, int32_t); | 451 |
264 } | 452 |
265 | 453 // Float32Array |
266 | 454 |
267 DEFINE_NATIVE_ENTRY(ExternalByteArray_getUint32, 2) { | 455 DEFINE_NATIVE_ENTRY(Float32Array_new, 1) { |
268 GETTER(ExternalByteArray, Integer, uint32_t); | 456 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
269 } | 457 if (length.Value() < 0) { |
270 | 458 GrowableArray<const Object*> args; |
271 | 459 args.Add(&length); |
272 DEFINE_NATIVE_ENTRY(ExternalByteArray_setUint32, 3) { | 460 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
273 SETTER(ExternalByteArray, Integer, AsInt64Value, uint32_t); | 461 } |
274 } | 462 const Float32Array& new_array = |
275 | 463 Float32Array::Handle(Float32Array::New(length.Value())); |
276 | 464 arguments->SetReturn(new_array); |
277 DEFINE_NATIVE_ENTRY(ExternalByteArray_getInt64, 2) { | 465 } |
278 GETTER(ExternalByteArray, Integer, int64_t); | 466 |
279 } | 467 |
280 | 468 DEFINE_NATIVE_ENTRY(Float32Array_getIndexed, 2) { |
281 | 469 GETTER(Float32Array, Double, float); |
282 DEFINE_NATIVE_ENTRY(ExternalByteArray_setInt64, 3) { | 470 } |
283 SETTER(ExternalByteArray, Integer, AsInt64Value, int64_t); | 471 |
284 } | 472 |
285 | 473 DEFINE_NATIVE_ENTRY(Float32Array_setIndexed, 3) { |
286 | 474 SETTER(Float32Array, Double, value, float); |
287 DEFINE_NATIVE_ENTRY(ExternalByteArray_getUint64, 2) { | 475 } |
288 GETTER_UINT64(ExternalByteArray); | 476 |
289 } | 477 |
290 | 478 // Float64Array |
291 | 479 |
292 DEFINE_NATIVE_ENTRY(ExternalByteArray_setUint64, 3) { | 480 DEFINE_NATIVE_ENTRY(Float64Array_new, 1) { |
293 SETTER_UINT64(ExternalByteArray); | 481 GET_NATIVE_ARGUMENT(Smi, length, arguments->At(0)); |
294 } | 482 if (length.Value() < 0) { |
295 | 483 GrowableArray<const Object*> args; |
296 | 484 args.Add(&length); |
297 DEFINE_NATIVE_ENTRY(ExternalByteArray_getFloat32, 2) { | 485 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
298 GETTER(ExternalByteArray, Double, float); | 486 } |
299 } | 487 const Float64Array& new_array = |
300 | 488 Float64Array::Handle(Float64Array::New(length.Value())); |
301 | 489 arguments->SetReturn(new_array); |
302 DEFINE_NATIVE_ENTRY(ExternalByteArray_setFloat32, 3) { | 490 } |
303 SETTER(ExternalByteArray, Double, value, float); | 491 |
304 } | 492 |
305 | 493 DEFINE_NATIVE_ENTRY(Float64Array_getIndexed, 2) { |
306 | 494 GETTER(Float64Array, Double, double); |
307 DEFINE_NATIVE_ENTRY(ExternalByteArray_getFloat64, 2) { | 495 } |
308 GETTER(ExternalByteArray, Double, double); | 496 |
309 } | 497 |
310 | 498 DEFINE_NATIVE_ENTRY(Float64Array_setIndexed, 3) { |
311 | 499 SETTER(Float64Array, Double, value, double); |
312 DEFINE_NATIVE_ENTRY(ExternalByteArray_setFloat64, 3) { | 500 } |
313 SETTER(ExternalByteArray, Double, value, double); | 501 |
| 502 |
| 503 // ExternalInt8Array |
| 504 |
| 505 DEFINE_NATIVE_ENTRY(ExternalInt8Array_getIndexed, 2) { |
| 506 GETTER(ExternalInt8Array, Smi, int8_t); |
| 507 } |
| 508 |
| 509 |
| 510 DEFINE_NATIVE_ENTRY(ExternalInt8Array_setIndexed, 3) { |
| 511 SETTER(ExternalInt8Array, Smi, Value, int8_t); |
| 512 } |
| 513 |
| 514 |
| 515 // ExternalUint8Array |
| 516 |
| 517 DEFINE_NATIVE_ENTRY(ExternalUint8Array_getIndexed, 2) { |
| 518 UNALIGNED_GETTER(ExternalUint8Array, Smi, uint8_t); |
| 519 } |
| 520 |
| 521 |
| 522 DEFINE_NATIVE_ENTRY(ExternalUint8Array_setIndexed, 3) { |
| 523 UNALIGNED_SETTER(ExternalUint8Array, Smi, Value, uint8_t); |
| 524 } |
| 525 |
| 526 |
| 527 // ExternalInt16Array |
| 528 |
| 529 DEFINE_NATIVE_ENTRY(ExternalInt16Array_getIndexed, 2) { |
| 530 GETTER(ExternalInt16Array, Smi, int16_t); |
| 531 } |
| 532 |
| 533 |
| 534 DEFINE_NATIVE_ENTRY(ExternalInt16Array_setIndexed, 3) { |
| 535 SETTER(ExternalInt16Array, Smi, Value, int16_t); |
| 536 } |
| 537 |
| 538 |
| 539 // ExternalUint16Array |
| 540 |
| 541 DEFINE_NATIVE_ENTRY(ExternalUint16Array_getIndexed, 2) { |
| 542 UNALIGNED_GETTER(ExternalUint16Array, Smi, uint16_t); |
| 543 } |
| 544 |
| 545 |
| 546 DEFINE_NATIVE_ENTRY(ExternalUint16Array_setIndexed, 3) { |
| 547 UNALIGNED_SETTER(ExternalUint16Array, Smi, Value, uint16_t); |
| 548 } |
| 549 |
| 550 |
| 551 // ExternalInt32Array |
| 552 |
| 553 DEFINE_NATIVE_ENTRY(ExternalInt32Array_getIndexed, 2) { |
| 554 GETTER(ExternalInt32Array, Integer, int32_t); |
| 555 } |
| 556 |
| 557 |
| 558 DEFINE_NATIVE_ENTRY(ExternalInt32Array_setIndexed, 3) { |
| 559 SETTER(ExternalInt32Array, Integer, AsInt64Value, int32_t); |
| 560 } |
| 561 |
| 562 |
| 563 // ExternalUint32Array |
| 564 |
| 565 DEFINE_NATIVE_ENTRY(ExternalUint32Array_getIndexed, 2) { |
| 566 UNALIGNED_GETTER(ExternalUint32Array, Integer, uint32_t); |
| 567 } |
| 568 |
| 569 |
| 570 DEFINE_NATIVE_ENTRY(ExternalUint32Array_setIndexed, 3) { |
| 571 UNALIGNED_SETTER(ExternalUint32Array, Integer, AsInt64Value, uint32_t); |
| 572 } |
| 573 |
| 574 |
| 575 // ExternalInt64Array |
| 576 |
| 577 DEFINE_NATIVE_ENTRY(ExternalInt64Array_getIndexed, 2) { |
| 578 GETTER(ExternalInt64Array, Integer, int64_t); |
| 579 } |
| 580 |
| 581 |
| 582 DEFINE_NATIVE_ENTRY(ExternalInt64Array_setIndexed, 3) { |
| 583 SETTER(ExternalInt64Array, Integer, AsInt64Value, int64_t); |
| 584 } |
| 585 |
| 586 |
| 587 // ExternalUint64Array |
| 588 |
| 589 DEFINE_NATIVE_ENTRY(ExternalUint64Array_getIndexed, 2) { |
| 590 GETTER_UINT64(ExternalUint64Array); |
| 591 } |
| 592 |
| 593 |
| 594 DEFINE_NATIVE_ENTRY(ExternalUint64Array_setIndexed, 3) { |
| 595 SETTER_UINT64(ExternalUint64Array); |
| 596 } |
| 597 |
| 598 |
| 599 // ExternalFloat32Array |
| 600 |
| 601 DEFINE_NATIVE_ENTRY(ExternalFloat32Array_getIndexed, 2) { |
| 602 GETTER(ExternalFloat32Array, Double, float); |
| 603 } |
| 604 |
| 605 |
| 606 DEFINE_NATIVE_ENTRY(ExternalFloat32Array_setIndexed, 3) { |
| 607 SETTER(ExternalFloat32Array, Double, value, float); |
| 608 } |
| 609 |
| 610 |
| 611 // ExternalFloat64Array |
| 612 |
| 613 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_getIndexed, 2) { |
| 614 GETTER(ExternalFloat64Array, Double, double); |
| 615 } |
| 616 |
| 617 |
| 618 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_setIndexed, 3) { |
| 619 SETTER(ExternalFloat64Array, Double, value, double); |
314 } | 620 } |
315 | 621 |
316 } // namespace dart | 622 } // namespace dart |
OLD | NEW |