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

Side by Side 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, 10 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "vm/exceptions.h" 7 #include "vm/exceptions.h"
8 #include "vm/native_entry.h" 8 #include "vm/native_entry.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 10
(...skipping 12 matching lines...) Expand all
23 GrowableArray<const Object*> args; 23 GrowableArray<const Object*> args;
24 args.Add(&length); 24 args.Add(&length);
25 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 25 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
26 } 26 }
27 const InternalByteArray& new_array = 27 const InternalByteArray& new_array =
28 InternalByteArray::Handle(InternalByteArray::New(length.Value())); 28 InternalByteArray::Handle(InternalByteArray::New(length.Value()));
29 arguments->SetReturn(new_array); 29 arguments->SetReturn(new_array);
30 } 30 }
31 31
32 32
33 static void RangeCheck(const ByteArray& array, const Smi& index, 33 static void RangeCheck(const ByteArray& array, const Smi& index,
Ivan Posva 2012/02/01 01:05:27 Why not just use intptr_t as parameters here?
Anders Johnsen 2012/02/01 02:12:11 We use the Smi object to cast the error (line 37).
Ivan Posva 2012/02/01 20:01:34 Create a new Integer handle when you really need t
Anders Johnsen 2012/02/01 20:20:41 Done.
34 intptr_t num_bytes) { 34 intptr_t num_bytes) {
35 if ((index.Value() < 0) || ((index.Value() + num_bytes) > array.Length())) { 35 if (!Utils::RangeCheck(index.Value(), num_bytes, array.Length())) {
36 GrowableArray<const Object*> arguments; 36 GrowableArray<const Object*> arguments;
37 arguments.Add(&index); 37 arguments.Add(&index);
38 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments); 38 Exceptions::ThrowByType(Exceptions::kIndexOutOfRange, arguments);
39 } 39 }
40 } 40 }
41 41
42 42
43 DEFINE_NATIVE_ENTRY(ByteArray_setRange, 5) {
44 ByteArray& dst = ByteArray::CheckedHandle(arguments->At(0));
45 GET_NATIVE_ARGUMENT(ByteArray, src, arguments->At(1));
46 GET_NATIVE_ARGUMENT(Smi, src_start, arguments->At(2));
47 GET_NATIVE_ARGUMENT(Smi, dst_start, arguments->At(3));
48 GET_NATIVE_ARGUMENT(Smi, count, arguments->At(4));
Ivan Posva 2012/02/01 01:05:27 intptr_t count_value = count.Value(); and friends.
Anders Johnsen 2012/02/01 02:12:11 Emm okay, I'm getting some conflicting comments on
49 if (count.Value() < 0) {
50 GrowableArray<const Object*> args;
51 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
52 }
53 RangeCheck(src, src_start, count.Value());
54 RangeCheck(dst, dst_start, count.Value());
55 ByteArray::Copy(
56 dst, dst_start.Value(), src, src_start.Value(), count.Value());
57 }
58
59
43 #define GETTER(ArrayT, ObjectT, ValueT) \ 60 #define GETTER(ArrayT, ObjectT, ValueT) \
44 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ 61 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \
45 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); \ 62 GET_NATIVE_ARGUMENT(Smi, index, arguments->At(1)); \
46 RangeCheck(array, index, sizeof(ValueT)); \ 63 RangeCheck(array, index, sizeof(ValueT)); \
47 ValueT result = array.UnalignedAt<ValueT>(index.Value()); \ 64 ValueT result = array.UnalignedAt<ValueT>(index.Value()); \
48 arguments->SetReturn(ObjectT::Handle(ObjectT::New(result))); 65 arguments->SetReturn(ObjectT::Handle(ObjectT::New(result)));
49 66
50 67
51 #define SETTER(ArrayT, ObjectT, Getter, ValueT) \ 68 #define SETTER(ArrayT, ObjectT, Getter, ValueT) \
52 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \ 69 GET_NATIVE_ARGUMENT(ArrayT, array, arguments->At(0)); \
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 DEFINE_NATIVE_ENTRY(ExternalByteArray_getFloat64, 2) { 266 DEFINE_NATIVE_ENTRY(ExternalByteArray_getFloat64, 2) {
250 GETTER(ExternalByteArray, Double, double); 267 GETTER(ExternalByteArray, Double, double);
251 } 268 }
252 269
253 270
254 DEFINE_NATIVE_ENTRY(ExternalByteArray_setFloat64, 3) { 271 DEFINE_NATIVE_ENTRY(ExternalByteArray_setFloat64, 3) {
255 SETTER(ExternalByteArray, Double, value, double); 272 SETTER(ExternalByteArray, Double, value, double);
256 } 273 }
257 274
258 } // namespace dart 275 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698