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

Unified Diff: runtime/lib/byte_array.cc

Issue 9235067: Use ByteArray's native for Socket and File. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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
Index: runtime/lib/byte_array.cc
===================================================================
--- runtime/lib/byte_array.cc (revision 3811)
+++ runtime/lib/byte_array.cc (working copy)
@@ -30,20 +30,41 @@
}
-static void RangeCheck(const ByteArray& array, const Smi& index,
+static void RangeCheck(const ByteArray& array,
+ intptr_t index,
intptr_t num_bytes) {
- if ((index.Value() < 0) || ((index.Value() + num_bytes) > array.Length())) {
+ if (!Utils::RangeCheck(index, num_bytes, array.Length())) {
GrowableArray<const Object*> arguments;
- arguments.Add(&index);
+ const Smi &index_object = Smi::Handle(Smi::New(index));
+ arguments.Add(&index_object);
Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments);
}
}
+DEFINE_NATIVE_ENTRY(ByteArray_setRange, 5) {
+ ByteArray& dst = ByteArray::CheckedHandle(arguments->At(0));
+ GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(1));
+ GET_NATIVE_ARGUMENT(Smi, length, arguments->At(2));
+ GET_NATIVE_ARGUMENT(ByteArray, src, arguments->At(3));
+ GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(4));
+ intptr_t length_value = length.Value();
+ intptr_t src_start_value = src_start.Value();
+ intptr_t dst_start_value = dst_start.Value();
+ if (length_value < 0) {
+ GrowableArray<const Object*> args;
+ Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
+ }
+ RangeCheck(src, src_start_value, length_value);
+ RangeCheck(dst, dst_start_value, length_value);
+ ByteArray::Copy(dst, dst_start_value, src, src_start_value, length_value);
+}
+
+
#define GETTER(ArrayT, ObjectT, ValueT) \
GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \
GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); \
- RangeCheck(array, index, sizeof(ValueT)); \
+ RangeCheck(array, index.Value(), sizeof(ValueT)); \
ValueT result = array.UnalignedAt<ValueT>(index.Value()); \
arguments->SetReturn(ObjectT::Handle(ObjectT::New(result)));
@@ -51,7 +72,7 @@
#define SETTER(ArrayT, ObjectT, Getter, ValueT) \
GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \
GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); \
- RangeCheck(array, index, sizeof(ValueT)); \
+ RangeCheck(array, index.Value(), sizeof(ValueT)); \
GET_NATIVE_ARGUMENT(ObjectT, value, arguments->At(2)); \
array.SetUnalignedAt<ValueT>(index.Value(), value.Getter());

Powered by Google App Engine
This is Rietveld 408576698