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

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

Issue 16347017: Fix exception type to ArgumentError instead of out of memory when checking the length argment of ty… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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
« no previous file with comments | « no previous file | 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 24 matching lines...) Expand all
35 (length_in_bytes / element_size_in_bytes))); 35 (length_in_bytes / element_size_in_bytes)));
36 const Array& args = Array::Handle(Array::New(1)); 36 const Array& args = Array::Handle(Array::New(1));
37 args.SetAt(0, error); 37 args.SetAt(0, error);
38 Exceptions::ThrowByType(Exceptions::kRange, args); 38 Exceptions::ThrowByType(Exceptions::kRange, args);
39 } 39 }
40 } 40 }
41 41
42 42
43 // Checks to see if a length will not result in an OOM error. 43 // Checks to see if a length will not result in an OOM error.
44 static void LengthCheck(intptr_t len, intptr_t max) { 44 static void LengthCheck(intptr_t len, intptr_t max) {
45 if (len > max) { 45 if (len < 0 || len > max) {
46 const String& error = String::Handle(String::NewFormatted( 46 const String& error = String::Handle(String::NewFormatted(
47 "insufficient memory to allocate a TypedData object of length (%"Pd")", 47 "Length (%"Pd") of TypedData object must be in range [0..%"Pd"]",
48 len)); 48 len, max));
49 const Array& args = Array::Handle(Array::New(1));
50 args.SetAt(0, error);
51 Exceptions::ThrowByType(Exceptions::kOutOfMemory, args);
52 } else if (len < 0) {
53 const String& error = String::Handle(String::NewFormatted(
54 "%"Pd" must be greater than 0", len));
hausner 2013/06/11 20:20:14 Should the message include the word TypedData or w
siva 2013/06/11 20:33:39 It should be clear based on the stack trace. Dropp
55 const Array& args = Array::Handle(Array::New(1)); 49 const Array& args = Array::Handle(Array::New(1));
56 args.SetAt(0, error); 50 args.SetAt(0, error);
57 Exceptions::ThrowByType(Exceptions::kArgument, args); 51 Exceptions::ThrowByType(Exceptions::kArgument, args);
58 } 52 }
59 } 53 }
60 54
61 55
62 static void PeerFinalizer(Dart_WeakPersistentHandle handle, void* peer) { 56 static void PeerFinalizer(Dart_WeakPersistentHandle handle, void* peer) {
63 Dart_DeleteWeakPersistentHandle(handle); 57 Dart_DeleteWeakPersistentHandle(handle);
64 OS::AlignedFree(peer); 58 OS::AlignedFree(peer);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 value = bit_cast<double>( 421 value = bit_cast<double>(
428 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); 422 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value)));
429 } else { 423 } else {
430 value = bit_cast<double>( 424 value = bit_cast<double>(
431 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); 425 Utils::HostToBigEndian64(bit_cast<uint64_t>(value)));
432 } 426 }
433 return Double::New(value); 427 return Double::New(value);
434 } 428 }
435 429
436 } // namespace dart 430 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698