OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 } | 42 } |
43 } | 43 } |
44 utf32_array[i] = value; | 44 utf32_array[i] = value; |
45 } | 45 } |
46 if (is_one_byte_string) { | 46 if (is_one_byte_string) { |
47 return OneByteString::New(utf32_array, array_len, Heap::kNew); | 47 return OneByteString::New(utf32_array, array_len, Heap::kNew); |
48 } | 48 } |
49 return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew); | 49 return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew); |
50 } | 50 } |
51 | 51 |
52 | |
srdjan
2013/03/05 16:02:21
Why remove the line?
Lasse Reichstein Nielsen
2013/03/05 16:56:56
That was where I originally had the new method. Gu
| |
53 DEFINE_NATIVE_ENTRY(StringBase_substringUnchecked, 3) { | 52 DEFINE_NATIVE_ENTRY(StringBase_substringUnchecked, 3) { |
54 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); | 53 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); |
55 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); | 54 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); |
56 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); | 55 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); |
57 | 56 |
58 intptr_t start = start_obj.Value(); | 57 intptr_t start = start_obj.Value(); |
59 intptr_t end = end_obj.Value(); | 58 intptr_t end = end_obj.Value(); |
60 return String::SubString(receiver, start, (end - start)); | 59 return String::SubString(receiver, start, (end - start)); |
61 } | 60 } |
62 | 61 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 elem ^= strings.At(i); | 189 elem ^= strings.At(i); |
191 if (!elem.IsString()) { | 190 if (!elem.IsString()) { |
192 const Array& args = Array::Handle(Array::New(1)); | 191 const Array& args = Array::Handle(Array::New(1)); |
193 args.SetAt(0, elem); | 192 args.SetAt(0, elem); |
194 Exceptions::ThrowByType(Exceptions::kArgument, args); | 193 Exceptions::ThrowByType(Exceptions::kArgument, args); |
195 } | 194 } |
196 } | 195 } |
197 return String::ConcatAll(strings); | 196 return String::ConcatAll(strings); |
198 } | 197 } |
199 | 198 |
199 DEFINE_NATIVE_ENTRY(StringBuffer_createStringFromUint16Array, 2) { | |
srdjan
2013/03/05 16:02:21
Check if you can create OneByteString instead of T
Lasse Reichstein Nielsen
2013/03/05 16:56:56
Will do.
| |
200 GET_NON_NULL_NATIVE_ARGUMENT(Uint16Array, a, arguments->NativeArgAt(0)); | |
201 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smiLength, arguments->NativeArgAt(1)); | |
202 intptr_t array_len = a.Length(); | |
203 int32_t length = smiLength.Value(); | |
204 if (length < 0 || length > array_len) { | |
srdjan
2013/03/05 16:02:21
Add parenthesis (length < 0) || (length > array_le
Lasse Reichstein Nielsen
2013/03/05 16:56:56
Will do.
| |
205 const Array& args = Array::Handle(Array::New(1)); | |
206 args.SetAt(0, smiLength); | |
207 Exceptions::ThrowByType(Exceptions::kRange, args); | |
208 } | |
209 // TODO(lrn): Pass parameter saying whether the data is Latin1, and | |
210 // use OneByteString::New in that case. | |
211 const String& result = String::Handle(TwoByteString::New(length, Heap::kNew)); | |
212 NoGCScope no_gc; | |
213 uint16_t* data_position = reinterpret_cast<uint16_t*>( | |
214 reinterpret_cast<char*>(a.raw()) + | |
215 Uint16Array::data_offset() - kHeapObjectTag); | |
216 String::Copy(result, 0, data_position, length); | |
217 return result.raw(); | |
218 } | |
219 | |
200 } // namespace dart | 220 } // namespace dart |
OLD | NEW |