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

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

Issue 15741019: Ensures that Bigints returned to Dart are all checked by Integer::AsValidInteger. (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
« runtime/lib/integers.cc ('K') | « runtime/lib/integers.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 SetRangeCheck(dst_offset_in_bytes, 103 SetRangeCheck(dst_offset_in_bytes,
104 length_in_bytes, 104 length_in_bytes,
105 dst_array.LengthInBytes(), 105 dst_array.LengthInBytes(),
106 element_size_in_bytes); 106 element_size_in_bytes);
107 TypedData::Copy<DstType, SrcType>(dst_array, dst_offset_in_bytes, 107 TypedData::Copy<DstType, SrcType>(dst_array, dst_offset_in_bytes,
108 src_array, src_offset_in_bytes, 108 src_array, src_offset_in_bytes,
109 length_in_bytes); 109 length_in_bytes);
110 return Bool::True().raw(); 110 return Bool::True().raw();
111 } 111 }
112 112
113
Ivan Posva 2013/05/23 21:37:54 ditto
zra 2013/05/23 22:14:38 Not sure what this is dittoing.
113 DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) { 114 DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) {
114 GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0)); 115 GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0));
115 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); 116 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1));
116 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); 117 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2));
117 GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3)); 118 GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3));
118 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); 119 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4));
119 120
120 if (length.Value() < 0) { 121 if (length.Value() < 0) {
121 const String& error = String::Handle(String::NewFormatted( 122 const String& error = String::Handle(String::NewFormatted(
122 "length (%"Pd") must be non-negative", length.Value())); 123 "length (%"Pd") must be non-negative", length.Value()));
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 const ExternalTypedData& array = ExternalTypedData::Cast(instance); \ 249 const ExternalTypedData& array = ExternalTypedData::Cast(instance); \
249 ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \ 250 ASSERT(RangeCheck(offsetInBytes.Value(), array.LengthInBytes())); \
250 value = array.getter(offsetInBytes.Value()); \ 251 value = array.getter(offsetInBytes.Value()); \
251 } else { \ 252 } else { \
252 const String& error = String::Handle(String::NewFormatted( \ 253 const String& error = String::Handle(String::NewFormatted( \
253 "Expected a TypedData object but found %s", instance.ToCString())); \ 254 "Expected a TypedData object but found %s", instance.ToCString())); \
254 const Array& args = Array::Handle(Array::New(1)); \ 255 const Array& args = Array::Handle(Array::New(1)); \
255 args.SetAt(0, error); \ 256 args.SetAt(0, error); \
256 Exceptions::ThrowByType(Exceptions::kArgument, args); \ 257 Exceptions::ThrowByType(Exceptions::kArgument, args); \
257 } \ 258 } \
258 Integer& result = Integer::Handle(); \ 259 const Bigint& result = \
Ivan Posva 2013/05/23 21:37:54 This instance feels like it would be better served
zra 2013/05/23 22:14:38 Done.
259 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { \ 260 Bigint::Handle(BigintOperations::NewFromUint64(value)); \
260 result = BigintOperations::NewFromUint64(value); \ 261 return result.AsValidInteger(); \
261 } else { \
262 result = Integer::New(value); \
263 } \
264 return result.raw(); \
265 } \ 262 } \
266 263
267 264
268 // TODO(asiva): Consider truncating the bigint value if it does not fit into 265 // TODO(asiva): Consider truncating the bigint value if it does not fit into
269 // a uint64_t value (see ASSERT(BigintOperations::FitsIntoUint64(bigint))). 266 // a uint64_t value (see ASSERT(BigintOperations::FitsIntoUint64(bigint))).
270 #define TYPED_DATA_UINT64_SETTER(setter, object) \ 267 #define TYPED_DATA_UINT64_SETTER(setter, object) \
271 DEFINE_NATIVE_ENTRY(TypedData_##setter, 3) { \ 268 DEFINE_NATIVE_ENTRY(TypedData_##setter, 3) { \
272 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \ 269 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \
273 GET_NON_NULL_NATIVE_ARGUMENT(Smi, offsetInBytes, arguments->NativeArgAt(1)); \ 270 GET_NON_NULL_NATIVE_ARGUMENT(Smi, offsetInBytes, arguments->NativeArgAt(1)); \
274 GET_NON_NULL_NATIVE_ARGUMENT(object, value, arguments->NativeArgAt(2)); \ 271 GET_NON_NULL_NATIVE_ARGUMENT(object, value, arguments->NativeArgAt(2)); \
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 value = BigintOperations::AbsToUint64(bigint); 395 value = BigintOperations::AbsToUint64(bigint);
399 } else { 396 } else {
400 ASSERT(host_value.IsMint() || host_value.IsSmi()); 397 ASSERT(host_value.IsMint() || host_value.IsSmi());
401 value = host_value.AsInt64Value(); 398 value = host_value.AsInt64Value();
402 } 399 }
403 if (little_endian.value()) { 400 if (little_endian.value()) {
404 value = Utils::HostToLittleEndian64(value); 401 value = Utils::HostToLittleEndian64(value);
405 } else { 402 } else {
406 value = Utils::HostToBigEndian64(value); 403 value = Utils::HostToBigEndian64(value);
407 } 404 }
408 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { 405 const Bigint& result = Bigint::Handle(BigintOperations::NewFromUint64(value));
Ivan Posva 2013/05/23 21:37:54 ditto
zra 2013/05/23 22:14:38 Done.
409 return BigintOperations::NewFromUint64(value); 406 return result.AsValidInteger();
410 }
411 return Integer::New(value);
412 } 407 }
413 408
414 409
415 DEFINE_NATIVE_ENTRY(ByteData_ToEndianFloat32, 2) { 410 DEFINE_NATIVE_ENTRY(ByteData_ToEndianFloat32, 2) {
416 GET_NON_NULL_NATIVE_ARGUMENT(Double, host_value, arguments->NativeArgAt(0)); 411 GET_NON_NULL_NATIVE_ARGUMENT(Double, host_value, arguments->NativeArgAt(0));
417 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); 412 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1));
418 float value = host_value.value(); 413 float value = host_value.value();
419 if (little_endian.value()) { 414 if (little_endian.value()) {
420 value = bit_cast<float>( 415 value = bit_cast<float>(
421 Utils::HostToLittleEndian32(bit_cast<uint32_t>(value))); 416 Utils::HostToLittleEndian32(bit_cast<uint32_t>(value)));
(...skipping 13 matching lines...) Expand all
435 value = bit_cast<double>( 430 value = bit_cast<double>(
436 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); 431 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value)));
437 } else { 432 } else {
438 value = bit_cast<double>( 433 value = bit_cast<double>(
439 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); 434 Utils::HostToBigEndian64(bit_cast<uint64_t>(value)));
440 } 435 }
441 return Double::New(value); 436 return Double::New(value);
442 } 437 }
443 438
444 } // namespace dart 439 } // namespace dart
OLDNEW
« runtime/lib/integers.cc ('K') | « runtime/lib/integers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698