Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: runtime/lib/typed_data.cc

Issue 14962008: Fix issue 5275: The VM must always generate the most compact form of an integer (Smi, Mint or Bigin… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } else { \ 251 } else { \
252 const String& error = String::Handle(String::NewFormatted( \ 252 const String& error = String::Handle(String::NewFormatted( \
253 "Expected a TypedData object but found %s", instance.ToCString())); \ 253 "Expected a TypedData object but found %s", instance.ToCString())); \
254 const Array& args = Array::Handle(Array::New(1)); \ 254 const Array& args = Array::Handle(Array::New(1)); \
255 args.SetAt(0, error); \ 255 args.SetAt(0, error); \
256 Exceptions::ThrowByType(Exceptions::kArgument, args); \ 256 Exceptions::ThrowByType(Exceptions::kArgument, args); \
257 } \ 257 } \
258 Integer& result = Integer::Handle(); \ 258 Integer& result = Integer::Handle(); \
259 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { \ 259 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { \
260 result = BigintOperations::NewFromUint64(value); \ 260 result = BigintOperations::NewFromUint64(value); \
261 } else if (value > static_cast<uint64_t>(Smi::kMaxValue)) { \
262 result = Mint::New(value); \
263 } else { \ 261 } else { \
264 result = Smi::New(value); \ 262 result = Integer::New(value); \
265 } \ 263 } \
266 return result.raw(); \ 264 return result.raw(); \
267 } \ 265 } \
268 266
269 267
270 // TODO(asiva): Consider truncating the bigint value if it does not fit into 268 // TODO(asiva): Consider truncating the bigint value if it does not fit into
271 // a uint64_t value (see ASSERT(BigintOperations::FitsIntoUint64(bigint))). 269 // a uint64_t value (see ASSERT(BigintOperations::FitsIntoUint64(bigint))).
272 #define TYPED_DATA_UINT64_SETTER(setter, object) \ 270 #define TYPED_DATA_UINT64_SETTER(setter, object) \
273 DEFINE_NATIVE_ENTRY(TypedData_##setter, 3) { \ 271 DEFINE_NATIVE_ENTRY(TypedData_##setter, 3) { \
274 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \ 272 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 ASSERT(host_value.IsMint() || host_value.IsSmi()); 400 ASSERT(host_value.IsMint() || host_value.IsSmi());
403 value = host_value.AsInt64Value(); 401 value = host_value.AsInt64Value();
404 } 402 }
405 if (little_endian.value()) { 403 if (little_endian.value()) {
406 value = Utils::HostToLittleEndian64(value); 404 value = Utils::HostToLittleEndian64(value);
407 } else { 405 } else {
408 value = Utils::HostToBigEndian64(value); 406 value = Utils::HostToBigEndian64(value);
409 } 407 }
410 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { 408 if (value > static_cast<uint64_t>(Mint::kMaxValue)) {
411 return BigintOperations::NewFromUint64(value); 409 return BigintOperations::NewFromUint64(value);
412 } else if (value > static_cast<uint64_t>(Smi::kMaxValue)) {
413 return Mint::New(value);
414 } 410 }
415 return Smi::New(value); 411 return Integer::New(value);
416 } 412 }
417 413
418 414
419 DEFINE_NATIVE_ENTRY(ByteData_ToEndianFloat32, 2) { 415 DEFINE_NATIVE_ENTRY(ByteData_ToEndianFloat32, 2) {
420 GET_NON_NULL_NATIVE_ARGUMENT(Double, host_value, arguments->NativeArgAt(0)); 416 GET_NON_NULL_NATIVE_ARGUMENT(Double, host_value, arguments->NativeArgAt(0));
421 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); 417 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1));
422 float value = host_value.value(); 418 float value = host_value.value();
423 if (little_endian.value()) { 419 if (little_endian.value()) {
424 value = bit_cast<float>( 420 value = bit_cast<float>(
425 Utils::HostToLittleEndian32(bit_cast<uint32_t>(value))); 421 Utils::HostToLittleEndian32(bit_cast<uint32_t>(value)));
(...skipping 13 matching lines...) Expand all
439 value = bit_cast<double>( 435 value = bit_cast<double>(
440 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); 436 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value)));
441 } else { 437 } else {
442 value = bit_cast<double>( 438 value = bit_cast<double>(
443 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); 439 Utils::HostToBigEndian64(bit_cast<uint64_t>(value)));
444 } 440 }
445 return Double::New(value); 441 return Double::New(value);
446 } 442 }
447 443
448 } // namespace dart 444 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698