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

Unified Diff: runtime/lib/string.cc

Issue 533483003: Cleanup throwing of the RangeError in the runtime to remove duplicated code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/simd128.cc ('k') | runtime/lib/typed_data.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string.cc
diff --git a/runtime/lib/string.cc b/runtime/lib/string.cc
index 19222eb8c1d9db2bc6cc71d0c13fd35806462aa8..cb292b626eda724cbdbebddb857ba6d436a087f6 100644
--- a/runtime/lib/string.cc
+++ b/runtime/lib/string.cc
@@ -234,21 +234,15 @@ DEFINE_NATIVE_ENTRY(String_getLength, 1) {
static int32_t StringValueAt(const String& str, const Integer& index) {
if (index.IsSmi()) {
- const Smi& smi = Smi::Cast(index);
- intptr_t index = smi.Value();
- if ((index < 0) || (index >= str.Length())) {
- const Array& args = Array::Handle(Array::New(1));
- args.SetAt(0, smi);
- Exceptions::ThrowByType(Exceptions::kRange, args);
+ const intptr_t index_value = Smi::Cast(index).Value();
+ if ((0 <= index_value) && (index_value < str.Length())) {
+ return str.CharAt(index_value);
}
- return str.CharAt(index);
- } else {
- // An index larger than Smi is always illegal.
- const Array& args = Array::Handle(Array::New(1));
- args.SetAt(0, index);
- Exceptions::ThrowByType(Exceptions::kRange, args);
- return 0;
}
+
+ // An index larger than Smi is always illegal.
+ Exceptions::ThrowRangeError("index", index, 0, str.Length());
+ return 0;
}
@@ -336,9 +330,7 @@ DEFINE_NATIVE_ENTRY(StringBuffer_createStringFromUint16Array, 3) {
intptr_t array_length = codeUnits.Length();
intptr_t length_value = length.Value();
if (length_value < 0 || length_value > array_length) {
- const Array& args = Array::Handle(Array::New(1));
- args.SetAt(0, length);
- Exceptions::ThrowByType(Exceptions::kRange, args);
+ Exceptions::ThrowRangeError("length", length, 0, array_length + 1);
}
const String& result = isLatin1.value()
? String::Handle(OneByteString::New(length_value, Heap::kNew))
« no previous file with comments | « runtime/lib/simd128.cc ('k') | runtime/lib/typed_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698