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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 if (len < 0 || len > max) { | 36 if (len < 0 || len > max) { |
37 const String& error = String::Handle(String::NewFormatted( | 37 const String& error = String::Handle(String::NewFormatted( |
38 "length (%"Pd") must be in the range [0..%"Pd"]", len, max)); | 38 "length (%"Pd") must be in the range [0..%"Pd"]", len, max)); |
39 GrowableArray<const Object*> args; | 39 GrowableArray<const Object*> args; |
40 args.Add(&error); | 40 args.Add(&error); |
41 Exceptions::ThrowByType(Exceptions::kArgument, args); | 41 Exceptions::ThrowByType(Exceptions::kArgument, args); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 | 45 |
46 #define GETTER_ARGUMENTS(ArrayT, ValueT) \ | 46 #define GETTER_ARGUMENTS(ArrayT, ValueT) \ |
47 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->NativeArgAt(0)); \ | 47 GET_NON_NULL_NATIVE_ARGUMENT(ArrayT, array, arguments->NativeArgAt(0)); \ |
48 GET_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); | 48 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); |
49 | 49 |
50 | 50 |
51 #define SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT) \ | 51 #define SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT) \ |
52 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->NativeArgAt(0)); \ | 52 GET_NON_NULL_NATIVE_ARGUMENT(ArrayT, array, arguments->NativeArgAt(0)); \ |
53 GET_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); \ | 53 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index, arguments->NativeArgAt(1)); \ |
54 GET_NATIVE_ARGUMENT(ObjectT, value_object, arguments->NativeArgAt(2)); | 54 GET_NON_NULL_NATIVE_ARGUMENT( \ |
| 55 ObjectT, value_object, arguments->NativeArgAt(2)); |
55 | 56 |
56 | 57 |
57 #define GETTER(ArrayT, ObjectT, ValueT) \ | 58 #define GETTER(ArrayT, ObjectT, ValueT) \ |
58 GETTER_ARGUMENTS(ArrayT, ValueT); \ | 59 GETTER_ARGUMENTS(ArrayT, ValueT); \ |
59 RangeCheck(array, index.Value() * sizeof(ValueT), sizeof(ValueT)); \ | 60 RangeCheck(array, index.Value() * sizeof(ValueT), sizeof(ValueT)); \ |
60 ValueT result = array.At(index.Value()); \ | 61 ValueT result = array.At(index.Value()); \ |
61 return ObjectT::New(result); | 62 return ObjectT::New(result); |
62 | 63 |
63 | 64 |
64 #define SETTER(ArrayT, ObjectT, Getter, ValueT) \ | 65 #define SETTER(ArrayT, ObjectT, Getter, ValueT) \ |
65 SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT); \ | 66 SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT); \ |
66 RangeCheck(array, index.Value() * sizeof(ValueT), sizeof(ValueT)); \ | 67 RangeCheck(array, index.Value() * sizeof(ValueT), sizeof(ValueT)); \ |
67 ValueT value = value_object.Getter(); \ | 68 ValueT value = value_object.Getter(); \ |
68 array.SetAt(index.Value(), value); \ | 69 array.SetAt(index.Value(), value); \ |
69 return Object::null(); | 70 return Object::null(); |
70 | 71 |
71 | 72 |
72 #define UNALIGNED_GETTER(ArrayT, ObjectT, ValueT) \ | 73 #define UNALIGNED_GETTER(ArrayT, ObjectT, ValueT) \ |
73 GETTER_ARGUMENTS(ArrayT, ValueT); \ | 74 GETTER_ARGUMENTS(ArrayT, ValueT); \ |
74 RangeCheck(array, index.Value(), sizeof(ValueT)); \ | 75 RangeCheck(array, index.Value(), sizeof(ValueT)); \ |
75 ValueT result; \ | 76 ValueT result; \ |
76 ByteArray::Copy(&result, array, index.Value(), sizeof(ValueT)); \ | 77 ByteArray::Copy(&result, array, index.Value(), sizeof(ValueT)); \ |
77 return ObjectT::New(result); | 78 return ObjectT::New(result); |
78 | 79 |
79 | 80 |
80 #define UNALIGNED_SETTER(ArrayT, ObjectT, Getter, ValueT) \ | 81 #define UNALIGNED_SETTER(ArrayT, ObjectT, Getter, ValueT) \ |
81 SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT); \ | 82 SETTER_ARGUMENTS(ArrayT, ObjectT, ValueT); \ |
82 RangeCheck(array, index.Value(), sizeof(ValueT)); \ | 83 RangeCheck(array, index.Value(), sizeof(ValueT)); \ |
83 ValueT src = value_object.Getter(); \ | 84 ValueT src = value_object.Getter(); \ |
84 ByteArray::Copy(array, index.Value(), &src, sizeof(ValueT)); \ | 85 ByteArray::Copy(array, index.Value(), &src, sizeof(ValueT)); \ |
85 return Integer::New(index.Value() + sizeof(ValueT)); | 86 return Integer::New(index.Value() + sizeof(ValueT)); |
86 | 87 |
87 | 88 |
88 #define UINT64_TO_INTEGER(value, integer) \ | 89 #define UINT64_TO_INTEGER(value, integer) \ |
89 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { \ | 90 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { \ |
90 result = BigintOperations::NewFromUint64(value); \ | 91 result = BigintOperations::NewFromUint64(value); \ |
91 } else if (value > static_cast<uint64_t>(Smi::kMaxValue)) { \ | 92 } else if (value > static_cast<uint64_t>(Smi::kMaxValue)) { \ |
92 result = Mint::New(value); \ | 93 result = Mint::New(value); \ |
93 } else { \ | 94 } else { \ |
94 result = Smi::New(value); \ | 95 result = Smi::New(value); \ |
95 } | 96 } |
96 | 97 |
97 | 98 |
98 #define GETTER_UINT64(ArrayT) \ | 99 #define GETTER_UINT64(ArrayT) \ |
99 GETTER_ARGUMENTS(ArrayT, uint64_t); \ | 100 GETTER_ARGUMENTS(ArrayT, uint64_t); \ |
100 intptr_t size = sizeof(uint64_t); \ | 101 intptr_t size = sizeof(uint64_t); \ |
101 RangeCheck(array, index.Value() * size, size); \ | 102 RangeCheck(array, index.Value() * size, size); \ |
102 uint64_t value = array.At(index.Value()); \ | 103 uint64_t value = array.At(index.Value()); \ |
103 Integer& result = Integer::Handle(); \ | 104 Integer& result = Integer::Handle(); \ |
104 UINT64_TO_INTEGER(value, result); \ | 105 UINT64_TO_INTEGER(value, result); \ |
105 return result.raw(); | 106 return result.raw(); |
106 | 107 |
107 | 108 |
108 #define UNALIGNED_GETTER_UINT64(ArrayT) \ | 109 #define UNALIGNED_GETTER_UINT64(ArrayT) \ |
109 GETTER_ARGUMENTS(ArrayT, uint64_t); \ | 110 GETTER_ARGUMENTS(ArrayT, uint64_t); \ |
110 RangeCheck(array, index.Value(), sizeof(uint64_t)); \ | 111 RangeCheck(array, index.Value(), sizeof(uint64_t)); \ |
111 uint64_t value; \ | 112 uint64_t value; \ |
112 ByteArray::Copy(&value, array, index.Value(), sizeof(uint64_t)); \ | 113 ByteArray::Copy(&value, array, index.Value(), sizeof(uint64_t)); \ |
113 Integer& result = Integer::Handle(); \ | 114 Integer& result = Integer::Handle(); \ |
114 UINT64_TO_INTEGER(value, result); \ | 115 UINT64_TO_INTEGER(value, result); \ |
115 return result.raw(); | 116 return result.raw(); |
116 | 117 |
117 | 118 |
118 #define INTEGER_TO_UINT64(integer, uint64) \ | 119 #define INTEGER_TO_UINT64(integer, uint64) \ |
119 if (integer.IsBigint()) { \ | 120 if (integer.IsBigint()) { \ |
120 Bigint& bigint = Bigint::Handle(); \ | 121 Bigint& bigint = Bigint::Handle(); \ |
121 bigint ^= integer.raw(); \ | 122 bigint ^= integer.raw(); \ |
122 ASSERT(BigintOperations::FitsIntoUint64(bigint)); \ | 123 ASSERT(BigintOperations::FitsIntoUint64(bigint)); \ |
123 value = BigintOperations::AbsToUint64(bigint); \ | 124 value = BigintOperations::AbsToUint64(bigint); \ |
124 } else { \ | 125 } else { \ |
125 ASSERT(integer.IsMint() || integer.IsSmi()); \ | 126 ASSERT(integer.IsMint() || integer.IsSmi()); \ |
126 value = integer.AsInt64Value(); \ | 127 value = integer.AsInt64Value(); \ |
127 } \ | 128 } \ |
128 | 129 |
129 | 130 |
130 #define SETTER_UINT64(ArrayT) \ | 131 #define SETTER_UINT64(ArrayT) \ |
131 SETTER_ARGUMENTS(ArrayT, Integer, uint64_t); \ | 132 SETTER_ARGUMENTS(ArrayT, Integer, uint64_t); \ |
132 intptr_t size = sizeof(uint64_t); \ | 133 intptr_t size = sizeof(uint64_t); \ |
133 RangeCheck(array, index.Value() * size, size); \ | 134 RangeCheck(array, index.Value() * size, size); \ |
134 uint64_t value; \ | 135 uint64_t value; \ |
135 INTEGER_TO_UINT64(value_object, value); \ | 136 INTEGER_TO_UINT64(value_object, value); \ |
136 array.SetAt(index.Value(), value); \ | 137 array.SetAt(index.Value(), value); \ |
137 return Object::null(); | 138 return Object::null(); |
138 | 139 |
139 | 140 |
140 #define UNALIGNED_SETTER_UINT64(ArrayT) \ | 141 #define UNALIGNED_SETTER_UINT64(ArrayT) \ |
141 SETTER_ARGUMENTS(ArrayT, Integer, uint64_t); \ | 142 SETTER_ARGUMENTS(ArrayT, Integer, uint64_t); \ |
142 RangeCheck(array, index.Value(), sizeof(uint64_t)); \ | 143 RangeCheck(array, index.Value(), sizeof(uint64_t)); \ |
143 uint64_t value; \ | 144 uint64_t value; \ |
144 INTEGER_TO_UINT64(value_object, value); \ | 145 INTEGER_TO_UINT64(value_object, value); \ |
145 ByteArray::Copy(array, index.Value(), &value, sizeof(uint64_t)); \ | 146 ByteArray::Copy(array, index.Value(), &value, sizeof(uint64_t)); \ |
146 return Integer::New(index.Value() + sizeof(uint64_t)); | 147 return Integer::New(index.Value() + sizeof(uint64_t)); |
147 | 148 |
148 | 149 |
149 DEFINE_NATIVE_ENTRY(ByteArray_getLength, 1) { | 150 DEFINE_NATIVE_ENTRY(ByteArray_getLength, 1) { |
150 GET_NATIVE_ARGUMENT(ByteArray, array, arguments->NativeArgAt(0)); | 151 GET_NON_NULL_NATIVE_ARGUMENT(ByteArray, array, arguments->NativeArgAt(0)); |
151 return Smi::New(array.Length()); | 152 return Smi::New(array.Length()); |
152 } | 153 } |
153 | 154 |
154 | 155 |
155 DEFINE_NATIVE_ENTRY(ByteArray_getInt8, 2) { | 156 DEFINE_NATIVE_ENTRY(ByteArray_getInt8, 2) { |
156 UNALIGNED_GETTER(ByteArray, Smi, int8_t); | 157 UNALIGNED_GETTER(ByteArray, Smi, int8_t); |
157 } | 158 } |
158 | 159 |
159 | 160 |
160 DEFINE_NATIVE_ENTRY(ByteArray_setInt8, 3) { | 161 DEFINE_NATIVE_ENTRY(ByteArray_setInt8, 3) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 248 } |
248 | 249 |
249 | 250 |
250 DEFINE_NATIVE_ENTRY(ByteArray_setFloat64, 3) { | 251 DEFINE_NATIVE_ENTRY(ByteArray_setFloat64, 3) { |
251 UNALIGNED_SETTER(ByteArray, Double, value, double); | 252 UNALIGNED_SETTER(ByteArray, Double, value, double); |
252 } | 253 } |
253 | 254 |
254 | 255 |
255 DEFINE_NATIVE_ENTRY(ByteArray_setRange, 5) { | 256 DEFINE_NATIVE_ENTRY(ByteArray_setRange, 5) { |
256 ByteArray& dst = ByteArray::CheckedHandle(arguments->NativeArgAt(0)); | 257 ByteArray& dst = ByteArray::CheckedHandle(arguments->NativeArgAt(0)); |
257 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); | 258 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); |
258 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); | 259 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); |
259 GET_NATIVE_ARGUMENT(ByteArray, src, arguments->NativeArgAt(3)); | 260 GET_NON_NULL_NATIVE_ARGUMENT(ByteArray, src, arguments->NativeArgAt(3)); |
260 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); | 261 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); |
261 intptr_t length_value = length.Value(); | 262 intptr_t length_value = length.Value(); |
262 intptr_t src_start_value = src_start.Value(); | 263 intptr_t src_start_value = src_start.Value(); |
263 intptr_t dst_start_value = dst_start.Value(); | 264 intptr_t dst_start_value = dst_start.Value(); |
264 if (length_value < 0) { | 265 if (length_value < 0) { |
265 const String& error = String::Handle(String::NewFormatted( | 266 const String& error = String::Handle(String::NewFormatted( |
266 "length (%"Pd") must be non-negative", length_value)); | 267 "length (%"Pd") must be non-negative", length_value)); |
267 GrowableArray<const Object*> args; | 268 GrowableArray<const Object*> args; |
268 args.Add(&error); | 269 args.Add(&error); |
269 Exceptions::ThrowByType(Exceptions::kArgument, args); | 270 Exceptions::ThrowByType(Exceptions::kArgument, args); |
270 } | 271 } |
271 RangeCheck(src, src_start_value, length_value); | 272 RangeCheck(src, src_start_value, length_value); |
272 RangeCheck(dst, dst_start_value, length_value); | 273 RangeCheck(dst, dst_start_value, length_value); |
273 ByteArray::Copy(dst, dst_start_value, src, src_start_value, length_value); | 274 ByteArray::Copy(dst, dst_start_value, src, src_start_value, length_value); |
274 return Object::null(); | 275 return Object::null(); |
275 } | 276 } |
276 | 277 |
277 | 278 |
278 // Int8Array | 279 // Int8Array |
279 | 280 |
280 DEFINE_NATIVE_ENTRY(Int8Array_new, 1) { | 281 DEFINE_NATIVE_ENTRY(Int8Array_new, 1) { |
281 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 282 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
282 intptr_t len = length.Value(); | 283 intptr_t len = length.Value(); |
283 LengthCheck(len, Int8Array::kMaxElements); | 284 LengthCheck(len, Int8Array::kMaxElements); |
284 return Int8Array::New(len); | 285 return Int8Array::New(len); |
285 } | 286 } |
286 | 287 |
287 | 288 |
288 DEFINE_NATIVE_ENTRY(Int8Array_newTransferable, 1) { | 289 DEFINE_NATIVE_ENTRY(Int8Array_newTransferable, 1) { |
289 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 290 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
290 intptr_t len = length.Value(); | 291 intptr_t len = length.Value(); |
291 LengthCheck(len, Int8Array::kMaxElements); | 292 LengthCheck(len, Int8Array::kMaxElements); |
292 int8_t* bytes = OS::AllocateAlignedArray<int8_t>( | 293 int8_t* bytes = OS::AllocateAlignedArray<int8_t>( |
293 len, | 294 len, |
294 ExternalByteArrayData<int8_t>::kAlignment); | 295 ExternalByteArrayData<int8_t>::kAlignment); |
295 return ExternalInt8Array::New(bytes, | 296 return ExternalInt8Array::New(bytes, |
296 len, | 297 len, |
297 bytes, | 298 bytes, |
298 OS::AlignedFree); | 299 OS::AlignedFree); |
299 } | 300 } |
300 | 301 |
301 | 302 |
302 DEFINE_NATIVE_ENTRY(Int8Array_getIndexed, 2) { | 303 DEFINE_NATIVE_ENTRY(Int8Array_getIndexed, 2) { |
303 GETTER(Int8Array, Smi, int8_t); | 304 GETTER(Int8Array, Smi, int8_t); |
304 } | 305 } |
305 | 306 |
306 | 307 |
307 DEFINE_NATIVE_ENTRY(Int8Array_setIndexed, 3) { | 308 DEFINE_NATIVE_ENTRY(Int8Array_setIndexed, 3) { |
308 SETTER(Int8Array, Smi, Value, int8_t); | 309 SETTER(Int8Array, Smi, Value, int8_t); |
309 } | 310 } |
310 | 311 |
311 | 312 |
312 // Uint8Array | 313 // Uint8Array |
313 | 314 |
314 DEFINE_NATIVE_ENTRY(Uint8Array_new, 1) { | 315 DEFINE_NATIVE_ENTRY(Uint8Array_new, 1) { |
315 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 316 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
316 intptr_t len = length.Value(); | 317 intptr_t len = length.Value(); |
317 LengthCheck(len, Uint8Array::kMaxElements); | 318 LengthCheck(len, Uint8Array::kMaxElements); |
318 return Uint8Array::New(len); | 319 return Uint8Array::New(len); |
319 } | 320 } |
320 | 321 |
321 | 322 |
322 DEFINE_NATIVE_ENTRY(Uint8Array_newTransferable, 1) { | 323 DEFINE_NATIVE_ENTRY(Uint8Array_newTransferable, 1) { |
323 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 324 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
324 intptr_t len = length.Value(); | 325 intptr_t len = length.Value(); |
325 LengthCheck(len, Uint8Array::kMaxElements); | 326 LengthCheck(len, Uint8Array::kMaxElements); |
326 uint8_t* bytes = OS::AllocateAlignedArray<uint8_t>( | 327 uint8_t* bytes = OS::AllocateAlignedArray<uint8_t>( |
327 len, | 328 len, |
328 ExternalByteArrayData<uint8_t>::kAlignment); | 329 ExternalByteArrayData<uint8_t>::kAlignment); |
329 return ExternalUint8Array::New(bytes, | 330 return ExternalUint8Array::New(bytes, |
330 len, | 331 len, |
331 bytes, | 332 bytes, |
332 OS::AlignedFree); | 333 OS::AlignedFree); |
333 } | 334 } |
334 | 335 |
335 | 336 |
336 DEFINE_NATIVE_ENTRY(Uint8Array_getIndexed, 2) { | 337 DEFINE_NATIVE_ENTRY(Uint8Array_getIndexed, 2) { |
337 GETTER(Uint8Array, Smi, uint8_t); | 338 GETTER(Uint8Array, Smi, uint8_t); |
338 } | 339 } |
339 | 340 |
340 | 341 |
341 DEFINE_NATIVE_ENTRY(Uint8Array_setIndexed, 3) { | 342 DEFINE_NATIVE_ENTRY(Uint8Array_setIndexed, 3) { |
342 SETTER(Uint8Array, Smi, Value, uint8_t); | 343 SETTER(Uint8Array, Smi, Value, uint8_t); |
343 } | 344 } |
344 | 345 |
345 | 346 |
346 // Uint8ClampedArray | 347 // Uint8ClampedArray |
347 | 348 |
348 DEFINE_NATIVE_ENTRY(Uint8ClampedArray_new, 1) { | 349 DEFINE_NATIVE_ENTRY(Uint8ClampedArray_new, 1) { |
349 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 350 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
350 intptr_t len = length.Value(); | 351 intptr_t len = length.Value(); |
351 LengthCheck(len, Uint8ClampedArray::kMaxElements); | 352 LengthCheck(len, Uint8ClampedArray::kMaxElements); |
352 return Uint8ClampedArray::New(len); | 353 return Uint8ClampedArray::New(len); |
353 } | 354 } |
354 | 355 |
355 | 356 |
356 DEFINE_NATIVE_ENTRY(Uint8ClampedArray_newTransferable, 1) { | 357 DEFINE_NATIVE_ENTRY(Uint8ClampedArray_newTransferable, 1) { |
357 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 358 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
358 intptr_t len = length.Value(); | 359 intptr_t len = length.Value(); |
359 LengthCheck(len, Uint8ClampedArray::kMaxElements); | 360 LengthCheck(len, Uint8ClampedArray::kMaxElements); |
360 uint8_t* bytes = OS::AllocateAlignedArray<uint8_t>( | 361 uint8_t* bytes = OS::AllocateAlignedArray<uint8_t>( |
361 len, | 362 len, |
362 ExternalByteArrayData<uint8_t>::kAlignment); | 363 ExternalByteArrayData<uint8_t>::kAlignment); |
363 return ExternalUint8ClampedArray::New(bytes, | 364 return ExternalUint8ClampedArray::New(bytes, |
364 len, | 365 len, |
365 bytes, | 366 bytes, |
366 OS::AlignedFree); | 367 OS::AlignedFree); |
367 } | 368 } |
368 | 369 |
369 | 370 |
370 DEFINE_NATIVE_ENTRY(Uint8ClampedArray_getIndexed, 2) { | 371 DEFINE_NATIVE_ENTRY(Uint8ClampedArray_getIndexed, 2) { |
371 GETTER(Uint8ClampedArray, Smi, uint8_t); | 372 GETTER(Uint8ClampedArray, Smi, uint8_t); |
372 } | 373 } |
373 | 374 |
374 | 375 |
375 DEFINE_NATIVE_ENTRY(Uint8ClampedArray_setIndexed, 3) { | 376 DEFINE_NATIVE_ENTRY(Uint8ClampedArray_setIndexed, 3) { |
376 SETTER(Uint8ClampedArray, Smi, Value, uint8_t); | 377 SETTER(Uint8ClampedArray, Smi, Value, uint8_t); |
377 } | 378 } |
378 | 379 |
379 | 380 |
380 // Int16Array | 381 // Int16Array |
381 | 382 |
382 DEFINE_NATIVE_ENTRY(Int16Array_new, 1) { | 383 DEFINE_NATIVE_ENTRY(Int16Array_new, 1) { |
383 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 384 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
384 intptr_t len = length.Value(); | 385 intptr_t len = length.Value(); |
385 LengthCheck(len, Int16Array::kMaxElements); | 386 LengthCheck(len, Int16Array::kMaxElements); |
386 return Int16Array::New(len); | 387 return Int16Array::New(len); |
387 } | 388 } |
388 | 389 |
389 | 390 |
390 DEFINE_NATIVE_ENTRY(Int16Array_newTransferable, 1) { | 391 DEFINE_NATIVE_ENTRY(Int16Array_newTransferable, 1) { |
391 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 392 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
392 intptr_t len = length.Value(); | 393 intptr_t len = length.Value(); |
393 LengthCheck(len, Int16Array::kMaxElements); | 394 LengthCheck(len, Int16Array::kMaxElements); |
394 int16_t* bytes = OS::AllocateAlignedArray<int16_t>( | 395 int16_t* bytes = OS::AllocateAlignedArray<int16_t>( |
395 len, | 396 len, |
396 ExternalByteArrayData<int16_t>::kAlignment); | 397 ExternalByteArrayData<int16_t>::kAlignment); |
397 return ExternalInt16Array::New(bytes, | 398 return ExternalInt16Array::New(bytes, |
398 len, | 399 len, |
399 bytes, | 400 bytes, |
400 OS::AlignedFree); | 401 OS::AlignedFree); |
401 } | 402 } |
402 | 403 |
403 | 404 |
404 DEFINE_NATIVE_ENTRY(Int16Array_getIndexed, 2) { | 405 DEFINE_NATIVE_ENTRY(Int16Array_getIndexed, 2) { |
405 GETTER(Int16Array, Smi, int16_t); | 406 GETTER(Int16Array, Smi, int16_t); |
406 } | 407 } |
407 | 408 |
408 | 409 |
409 DEFINE_NATIVE_ENTRY(Int16Array_setIndexed, 3) { | 410 DEFINE_NATIVE_ENTRY(Int16Array_setIndexed, 3) { |
410 SETTER(Int16Array, Smi, Value, int16_t); | 411 SETTER(Int16Array, Smi, Value, int16_t); |
411 } | 412 } |
412 | 413 |
413 | 414 |
414 // Uint16Array | 415 // Uint16Array |
415 | 416 |
416 DEFINE_NATIVE_ENTRY(Uint16Array_new, 1) { | 417 DEFINE_NATIVE_ENTRY(Uint16Array_new, 1) { |
417 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 418 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
418 intptr_t len = length.Value(); | 419 intptr_t len = length.Value(); |
419 LengthCheck(len, Uint16Array::kMaxElements); | 420 LengthCheck(len, Uint16Array::kMaxElements); |
420 return Uint16Array::New(len); | 421 return Uint16Array::New(len); |
421 } | 422 } |
422 | 423 |
423 | 424 |
424 DEFINE_NATIVE_ENTRY(Uint16Array_newTransferable, 1) { | 425 DEFINE_NATIVE_ENTRY(Uint16Array_newTransferable, 1) { |
425 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 426 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
426 intptr_t len = length.Value(); | 427 intptr_t len = length.Value(); |
427 LengthCheck(len, Uint16Array::kMaxElements); | 428 LengthCheck(len, Uint16Array::kMaxElements); |
428 uint16_t* bytes = OS::AllocateAlignedArray<uint16_t>( | 429 uint16_t* bytes = OS::AllocateAlignedArray<uint16_t>( |
429 len, | 430 len, |
430 ExternalByteArrayData<uint16_t>::kAlignment); | 431 ExternalByteArrayData<uint16_t>::kAlignment); |
431 return ExternalUint16Array::New(bytes, | 432 return ExternalUint16Array::New(bytes, |
432 len, | 433 len, |
433 bytes, | 434 bytes, |
434 OS::AlignedFree); | 435 OS::AlignedFree); |
435 } | 436 } |
436 | 437 |
437 | 438 |
438 DEFINE_NATIVE_ENTRY(Uint16Array_getIndexed, 2) { | 439 DEFINE_NATIVE_ENTRY(Uint16Array_getIndexed, 2) { |
439 GETTER(Uint16Array, Smi, uint16_t); | 440 GETTER(Uint16Array, Smi, uint16_t); |
440 } | 441 } |
441 | 442 |
442 | 443 |
443 DEFINE_NATIVE_ENTRY(Uint16Array_setIndexed, 3) { | 444 DEFINE_NATIVE_ENTRY(Uint16Array_setIndexed, 3) { |
444 SETTER(Uint16Array, Smi, Value, uint16_t); | 445 SETTER(Uint16Array, Smi, Value, uint16_t); |
445 } | 446 } |
446 | 447 |
447 | 448 |
448 // Int32Array | 449 // Int32Array |
449 | 450 |
450 DEFINE_NATIVE_ENTRY(Int32Array_new, 1) { | 451 DEFINE_NATIVE_ENTRY(Int32Array_new, 1) { |
451 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 452 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
452 intptr_t len = length.Value(); | 453 intptr_t len = length.Value(); |
453 LengthCheck(len, Int32Array::kMaxElements); | 454 LengthCheck(len, Int32Array::kMaxElements); |
454 return Int32Array::New(len); | 455 return Int32Array::New(len); |
455 } | 456 } |
456 | 457 |
457 | 458 |
458 DEFINE_NATIVE_ENTRY(Int32Array_newTransferable, 1) { | 459 DEFINE_NATIVE_ENTRY(Int32Array_newTransferable, 1) { |
459 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 460 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
460 intptr_t len = length.Value(); | 461 intptr_t len = length.Value(); |
461 LengthCheck(len, Int32Array::kMaxElements); | 462 LengthCheck(len, Int32Array::kMaxElements); |
462 int32_t* bytes = OS::AllocateAlignedArray<int32_t>( | 463 int32_t* bytes = OS::AllocateAlignedArray<int32_t>( |
463 len, | 464 len, |
464 ExternalByteArrayData<int32_t>::kAlignment); | 465 ExternalByteArrayData<int32_t>::kAlignment); |
465 return ExternalInt32Array::New(bytes, | 466 return ExternalInt32Array::New(bytes, |
466 len, | 467 len, |
467 bytes, | 468 bytes, |
468 OS::AlignedFree); | 469 OS::AlignedFree); |
469 } | 470 } |
470 | 471 |
471 | 472 |
472 DEFINE_NATIVE_ENTRY(Int32Array_getIndexed, 2) { | 473 DEFINE_NATIVE_ENTRY(Int32Array_getIndexed, 2) { |
473 GETTER(Int32Array, Integer, int32_t); | 474 GETTER(Int32Array, Integer, int32_t); |
474 } | 475 } |
475 | 476 |
476 | 477 |
477 DEFINE_NATIVE_ENTRY(Int32Array_setIndexed, 3) { | 478 DEFINE_NATIVE_ENTRY(Int32Array_setIndexed, 3) { |
478 SETTER(Int32Array, Integer, AsInt64Value, int32_t); | 479 SETTER(Int32Array, Integer, AsInt64Value, int32_t); |
479 } | 480 } |
480 | 481 |
481 | 482 |
482 // Uint32Array | 483 // Uint32Array |
483 | 484 |
484 DEFINE_NATIVE_ENTRY(Uint32Array_new, 1) { | 485 DEFINE_NATIVE_ENTRY(Uint32Array_new, 1) { |
485 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 486 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
486 intptr_t len = length.Value(); | 487 intptr_t len = length.Value(); |
487 LengthCheck(len, Uint32Array::kMaxElements); | 488 LengthCheck(len, Uint32Array::kMaxElements); |
488 return Uint32Array::New(len); | 489 return Uint32Array::New(len); |
489 } | 490 } |
490 | 491 |
491 | 492 |
492 DEFINE_NATIVE_ENTRY(Uint32Array_newTransferable, 1) { | 493 DEFINE_NATIVE_ENTRY(Uint32Array_newTransferable, 1) { |
493 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 494 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
494 intptr_t len = length.Value(); | 495 intptr_t len = length.Value(); |
495 LengthCheck(len, Uint32Array::kMaxElements); | 496 LengthCheck(len, Uint32Array::kMaxElements); |
496 uint32_t* bytes = OS::AllocateAlignedArray<uint32_t>( | 497 uint32_t* bytes = OS::AllocateAlignedArray<uint32_t>( |
497 len, | 498 len, |
498 ExternalByteArrayData<uint32_t>::kAlignment); | 499 ExternalByteArrayData<uint32_t>::kAlignment); |
499 return ExternalUint32Array::New(bytes, | 500 return ExternalUint32Array::New(bytes, |
500 len, | 501 len, |
501 bytes, | 502 bytes, |
502 OS::AlignedFree); | 503 OS::AlignedFree); |
503 } | 504 } |
504 | 505 |
505 | 506 |
506 DEFINE_NATIVE_ENTRY(Uint32Array_getIndexed, 2) { | 507 DEFINE_NATIVE_ENTRY(Uint32Array_getIndexed, 2) { |
507 GETTER(Uint32Array, Integer, uint32_t); | 508 GETTER(Uint32Array, Integer, uint32_t); |
508 } | 509 } |
509 | 510 |
510 | 511 |
511 DEFINE_NATIVE_ENTRY(Uint32Array_setIndexed, 3) { | 512 DEFINE_NATIVE_ENTRY(Uint32Array_setIndexed, 3) { |
512 SETTER(Uint32Array, Integer, AsInt64Value, uint32_t); | 513 SETTER(Uint32Array, Integer, AsInt64Value, uint32_t); |
513 } | 514 } |
514 | 515 |
515 | 516 |
516 // Int64Array | 517 // Int64Array |
517 | 518 |
518 DEFINE_NATIVE_ENTRY(Int64Array_new, 1) { | 519 DEFINE_NATIVE_ENTRY(Int64Array_new, 1) { |
519 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 520 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
520 intptr_t len = length.Value(); | 521 intptr_t len = length.Value(); |
521 LengthCheck(len, Int64Array::kMaxElements); | 522 LengthCheck(len, Int64Array::kMaxElements); |
522 return Int64Array::New(len); | 523 return Int64Array::New(len); |
523 } | 524 } |
524 | 525 |
525 | 526 |
526 DEFINE_NATIVE_ENTRY(Int64Array_newTransferable, 1) { | 527 DEFINE_NATIVE_ENTRY(Int64Array_newTransferable, 1) { |
527 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 528 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
528 intptr_t len = length.Value(); | 529 intptr_t len = length.Value(); |
529 LengthCheck(len, Int64Array::kMaxElements); | 530 LengthCheck(len, Int64Array::kMaxElements); |
530 int64_t* bytes = OS::AllocateAlignedArray<int64_t>( | 531 int64_t* bytes = OS::AllocateAlignedArray<int64_t>( |
531 len, | 532 len, |
532 ExternalByteArrayData<int64_t>::kAlignment); | 533 ExternalByteArrayData<int64_t>::kAlignment); |
533 return ExternalInt64Array::New(bytes, | 534 return ExternalInt64Array::New(bytes, |
534 len, | 535 len, |
535 bytes, | 536 bytes, |
536 OS::AlignedFree); | 537 OS::AlignedFree); |
537 } | 538 } |
538 | 539 |
539 | 540 |
540 DEFINE_NATIVE_ENTRY(Int64Array_getIndexed, 2) { | 541 DEFINE_NATIVE_ENTRY(Int64Array_getIndexed, 2) { |
541 GETTER(Int64Array, Integer, int64_t); | 542 GETTER(Int64Array, Integer, int64_t); |
542 } | 543 } |
543 | 544 |
544 | 545 |
545 DEFINE_NATIVE_ENTRY(Int64Array_setIndexed, 3) { | 546 DEFINE_NATIVE_ENTRY(Int64Array_setIndexed, 3) { |
546 SETTER(Int64Array, Integer, AsInt64Value, int64_t); | 547 SETTER(Int64Array, Integer, AsInt64Value, int64_t); |
547 } | 548 } |
548 | 549 |
549 | 550 |
550 // Uint64Array | 551 // Uint64Array |
551 | 552 |
552 DEFINE_NATIVE_ENTRY(Uint64Array_new, 1) { | 553 DEFINE_NATIVE_ENTRY(Uint64Array_new, 1) { |
553 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 554 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
554 intptr_t len = length.Value(); | 555 intptr_t len = length.Value(); |
555 LengthCheck(len, Uint64Array::kMaxElements); | 556 LengthCheck(len, Uint64Array::kMaxElements); |
556 return Uint64Array::New(len); | 557 return Uint64Array::New(len); |
557 } | 558 } |
558 | 559 |
559 | 560 |
560 DEFINE_NATIVE_ENTRY(Uint64Array_newTransferable, 1) { | 561 DEFINE_NATIVE_ENTRY(Uint64Array_newTransferable, 1) { |
561 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 562 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
562 intptr_t len = length.Value(); | 563 intptr_t len = length.Value(); |
563 LengthCheck(len, Uint64Array::kMaxElements); | 564 LengthCheck(len, Uint64Array::kMaxElements); |
564 uint64_t* bytes = OS::AllocateAlignedArray<uint64_t>( | 565 uint64_t* bytes = OS::AllocateAlignedArray<uint64_t>( |
565 len, | 566 len, |
566 ExternalByteArrayData<uint64_t>::kAlignment); | 567 ExternalByteArrayData<uint64_t>::kAlignment); |
567 return ExternalUint64Array::New(bytes, | 568 return ExternalUint64Array::New(bytes, |
568 len, | 569 len, |
569 bytes, | 570 bytes, |
570 OS::AlignedFree); | 571 OS::AlignedFree); |
571 } | 572 } |
572 | 573 |
573 | 574 |
574 DEFINE_NATIVE_ENTRY(Uint64Array_getIndexed, 2) { | 575 DEFINE_NATIVE_ENTRY(Uint64Array_getIndexed, 2) { |
575 GETTER_UINT64(Uint64Array); | 576 GETTER_UINT64(Uint64Array); |
576 } | 577 } |
577 | 578 |
578 | 579 |
579 DEFINE_NATIVE_ENTRY(Uint64Array_setIndexed, 3) { | 580 DEFINE_NATIVE_ENTRY(Uint64Array_setIndexed, 3) { |
580 SETTER_UINT64(Uint64Array); | 581 SETTER_UINT64(Uint64Array); |
581 } | 582 } |
582 | 583 |
583 | 584 |
584 // Float32Array | 585 // Float32Array |
585 | 586 |
586 DEFINE_NATIVE_ENTRY(Float32Array_new, 1) { | 587 DEFINE_NATIVE_ENTRY(Float32Array_new, 1) { |
587 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 588 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
588 intptr_t len = length.Value(); | 589 intptr_t len = length.Value(); |
589 LengthCheck(len, Float32Array::kMaxElements); | 590 LengthCheck(len, Float32Array::kMaxElements); |
590 return Float32Array::New(len); | 591 return Float32Array::New(len); |
591 } | 592 } |
592 | 593 |
593 | 594 |
594 DEFINE_NATIVE_ENTRY(Float32Array_newTransferable, 1) { | 595 DEFINE_NATIVE_ENTRY(Float32Array_newTransferable, 1) { |
595 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 596 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
596 intptr_t len = length.Value(); | 597 intptr_t len = length.Value(); |
597 LengthCheck(len, Float32Array::kMaxElements); | 598 LengthCheck(len, Float32Array::kMaxElements); |
598 float* bytes = OS::AllocateAlignedArray<float>( | 599 float* bytes = OS::AllocateAlignedArray<float>( |
599 len, | 600 len, |
600 ExternalByteArrayData<float>::kAlignment); | 601 ExternalByteArrayData<float>::kAlignment); |
601 return ExternalFloat32Array::New(bytes, | 602 return ExternalFloat32Array::New(bytes, |
602 len, | 603 len, |
603 bytes, | 604 bytes, |
604 OS::AlignedFree); | 605 OS::AlignedFree); |
605 } | 606 } |
606 | 607 |
607 | 608 |
608 DEFINE_NATIVE_ENTRY(Float32Array_getIndexed, 2) { | 609 DEFINE_NATIVE_ENTRY(Float32Array_getIndexed, 2) { |
609 GETTER(Float32Array, Double, float); | 610 GETTER(Float32Array, Double, float); |
610 } | 611 } |
611 | 612 |
612 | 613 |
613 DEFINE_NATIVE_ENTRY(Float32Array_setIndexed, 3) { | 614 DEFINE_NATIVE_ENTRY(Float32Array_setIndexed, 3) { |
614 SETTER(Float32Array, Double, value, float); | 615 SETTER(Float32Array, Double, value, float); |
615 } | 616 } |
616 | 617 |
617 | 618 |
618 // Float64Array | 619 // Float64Array |
619 | 620 |
620 DEFINE_NATIVE_ENTRY(Float64Array_new, 1) { | 621 DEFINE_NATIVE_ENTRY(Float64Array_new, 1) { |
621 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 622 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
622 intptr_t len = length.Value(); | 623 intptr_t len = length.Value(); |
623 LengthCheck(len, Float64Array::kMaxElements); | 624 LengthCheck(len, Float64Array::kMaxElements); |
624 return Float64Array::New(len); | 625 return Float64Array::New(len); |
625 } | 626 } |
626 | 627 |
627 | 628 |
628 DEFINE_NATIVE_ENTRY(Float64Array_newTransferable, 1) { | 629 DEFINE_NATIVE_ENTRY(Float64Array_newTransferable, 1) { |
629 GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); | 630 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
630 intptr_t len = length.Value(); | 631 intptr_t len = length.Value(); |
631 LengthCheck(len, Float64Array::kMaxElements); | 632 LengthCheck(len, Float64Array::kMaxElements); |
632 double* bytes = OS::AllocateAlignedArray<double>( | 633 double* bytes = OS::AllocateAlignedArray<double>( |
633 len, | 634 len, |
634 ExternalByteArrayData<double>::kAlignment); | 635 ExternalByteArrayData<double>::kAlignment); |
635 return ExternalFloat64Array::New(bytes, | 636 return ExternalFloat64Array::New(bytes, |
636 len, | 637 len, |
637 bytes, | 638 bytes, |
638 OS::AlignedFree); | 639 OS::AlignedFree); |
639 } | 640 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_getIndexed, 2) { | 763 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_getIndexed, 2) { |
763 GETTER(ExternalFloat64Array, Double, double); | 764 GETTER(ExternalFloat64Array, Double, double); |
764 } | 765 } |
765 | 766 |
766 | 767 |
767 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_setIndexed, 3) { | 768 DEFINE_NATIVE_ENTRY(ExternalFloat64Array_setIndexed, 3) { |
768 SETTER(ExternalFloat64Array, Double, value, double); | 769 SETTER(ExternalFloat64Array, Double, value, double); |
769 } | 770 } |
770 | 771 |
771 } // namespace dart | 772 } // namespace dart |
OLD | NEW |