OLD | NEW |
---|---|
1 // Copyright (c) 2013, 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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 UNREACHABLE(); | 157 UNREACHABLE(); |
158 return Bool::False().raw(); | 158 return Bool::False().raw(); |
159 } | 159 } |
160 | 160 |
161 | 161 |
162 // We check the length parameter against a possible maximum length for the | 162 // We check the length parameter against a possible maximum length for the |
163 // array based on available physical addressable memory on the system. The | 163 // array based on available physical addressable memory on the system. The |
164 // maximum possible length is a scaled value of kSmiMax which is set up based | 164 // maximum possible length is a scaled value of kSmiMax which is set up based |
165 // on whether the underlying architecture is 32-bit or 64-bit. | 165 // on whether the underlying architecture is 32-bit or 64-bit. |
166 #define TYPED_DATA_NEW(name) \ | 166 #define TYPED_DATA_NEW(name) \ |
167 DEFINE_NATIVE_ENTRY(TypedData_##name##_new, 1) { \ | 167 DEFINE_NATIVE_ENTRY(TypedData_##name##_new, 2) { \ |
168 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); \ | 168 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1)); \ |
siva
2016/03/10 08:22:53
Can you add a comment that the first argument is t
Florian Schneider
2016/03/10 08:37:17
Done.
| |
169 intptr_t cid = kTypedData##name##Cid; \ | 169 intptr_t cid = kTypedData##name##Cid; \ |
170 intptr_t len = length.Value(); \ | 170 intptr_t len = length.Value(); \ |
171 intptr_t max = TypedData::MaxElements(cid); \ | 171 intptr_t max = TypedData::MaxElements(cid); \ |
172 LengthCheck(len, max); \ | 172 LengthCheck(len, max); \ |
173 return TypedData::New(cid, len); \ | 173 return TypedData::New(cid, len); \ |
174 } \ | 174 } \ |
175 | 175 |
176 | 176 |
177 // We check the length parameter against a possible maximum length for the | 177 // We check the length parameter against a possible maximum length for the |
178 // array based on available physical addressable memory on the system. The | 178 // array based on available physical addressable memory on the system. The |
179 // maximum possible length is a scaled value of kSmiMax which is set up based | 179 // maximum possible length is a scaled value of kSmiMax which is set up based |
180 // on whether the underlying architecture is 32-bit or 64-bit. | 180 // on whether the underlying architecture is 32-bit or 64-bit. |
181 #define EXT_TYPED_DATA_NEW(name) \ | 181 #define EXT_TYPED_DATA_NEW(name) \ |
182 DEFINE_NATIVE_ENTRY(ExternalTypedData_##name##_new, 1) { \ | 182 DEFINE_NATIVE_ENTRY(ExternalTypedData_##name##_new, 2) { \ |
183 const int kAlignment = 16; \ | 183 const int kAlignment = 16; \ |
184 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); \ | 184 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1)); \ |
185 intptr_t cid = kExternalTypedData##name##Cid; \ | 185 intptr_t cid = kExternalTypedData##name##Cid; \ |
186 intptr_t len = length.Value(); \ | 186 intptr_t len = length.Value(); \ |
187 intptr_t max = ExternalTypedData::MaxElements(cid); \ | 187 intptr_t max = ExternalTypedData::MaxElements(cid); \ |
188 LengthCheck(len, max); \ | 188 LengthCheck(len, max); \ |
189 intptr_t len_bytes = len * ExternalTypedData::ElementSizeInBytes(cid); \ | 189 intptr_t len_bytes = len * ExternalTypedData::ElementSizeInBytes(cid); \ |
190 uint8_t* data = OS::AllocateAlignedArray<uint8_t>(len_bytes, kAlignment); \ | 190 uint8_t* data = OS::AllocateAlignedArray<uint8_t>(len_bytes, kAlignment); \ |
191 const ExternalTypedData& obj = \ | 191 const ExternalTypedData& obj = \ |
192 ExternalTypedData::Handle(ExternalTypedData::New(cid, data, len)); \ | 192 ExternalTypedData::Handle(ExternalTypedData::New(cid, data, len)); \ |
193 obj.AddFinalizer(data, PeerFinalizer); \ | 193 obj.AddFinalizer(data, PeerFinalizer); \ |
194 return obj.raw(); \ | 194 return obj.raw(); \ |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 value = bit_cast<double>( | 390 value = bit_cast<double>( |
391 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); | 391 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); |
392 } else { | 392 } else { |
393 value = bit_cast<double>( | 393 value = bit_cast<double>( |
394 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); | 394 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); |
395 } | 395 } |
396 return Double::New(value); | 396 return Double::New(value); |
397 } | 397 } |
398 | 398 |
399 } // namespace dart | 399 } // namespace dart |
OLD | NEW |