| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 207 } |
| 208 | 208 |
| 209 | 209 |
| 210 DEFINE_NATIVE_ENTRY(String_toUpperCase, 1) { | 210 DEFINE_NATIVE_ENTRY(String_toUpperCase, 1) { |
| 211 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); | 211 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); |
| 212 ASSERT(!receiver.IsNull()); | 212 ASSERT(!receiver.IsNull()); |
| 213 return String::ToUpperCase(receiver); | 213 return String::ToUpperCase(receiver); |
| 214 } | 214 } |
| 215 | 215 |
| 216 | 216 |
| 217 DEFINE_NATIVE_ENTRY(Strings_concatAll, 1) { | 217 DEFINE_NATIVE_ENTRY(Strings_concatAll, 3) { |
| 218 GET_NON_NULL_NATIVE_ARGUMENT(Array, strings, arguments->NativeArgAt(0)); | 218 GET_NON_NULL_NATIVE_ARGUMENT(Instance, argument, arguments->NativeArgAt(0)); |
| 219 ASSERT(!strings.IsNull()); | 219 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start, arguments->NativeArgAt(1)); |
| 220 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end, arguments->NativeArgAt(2)); |
| 221 const intptr_t start_ix = start.Value(); |
| 222 const intptr_t end_ix = end.Value(); |
| 223 if (start_ix < 0) { |
| 224 const Array& args = Array::Handle(Array::New(1)); |
| 225 args.SetAt(0, start); |
| 226 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 227 } |
| 228 Array& strings = Array::Handle(); |
| 229 intptr_t length = -1; |
| 230 if (argument.IsArray()) { |
| 231 strings ^= argument.raw(); |
| 232 length = strings.Length(); |
| 233 } else if (argument.IsGrowableObjectArray()) { |
| 234 const GrowableObjectArray& g_array = GrowableObjectArray::Cast(argument); |
| 235 strings = g_array.data(); |
| 236 length = g_array.Length(); |
| 237 } else { |
| 238 const Array& args = Array::Handle(Array::New(1)); |
| 239 args.SetAt(0, argument); |
| 240 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 241 } |
| 242 if (end_ix > length) { |
| 243 const Array& args = Array::Handle(Array::New(1)); |
| 244 args.SetAt(0, end); |
| 245 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 246 } |
| 247 #if defined(DEBUG) |
| 220 // Check that the array contains strings. | 248 // Check that the array contains strings. |
| 221 Instance& elem = Instance::Handle(); | 249 Instance& elem = Instance::Handle(); |
| 222 for (intptr_t i = 0; i < strings.Length(); i++) { | 250 for (intptr_t i = start_ix; i < end_ix; i++) { |
| 223 elem ^= strings.At(i); | 251 elem ^= strings.At(i); |
| 224 if (!elem.IsString()) { | 252 ASSERT(elem.IsString()); |
| 225 const Array& args = Array::Handle(Array::New(1)); | |
| 226 args.SetAt(0, elem); | |
| 227 Exceptions::ThrowByType(Exceptions::kArgument, args); | |
| 228 } | |
| 229 } | 253 } |
| 230 return String::ConcatAll(strings); | 254 #endif |
| 255 return String::ConcatAllRange(strings, start_ix, end_ix, Heap::kNew); |
| 231 } | 256 } |
| 232 | 257 |
| 233 | 258 |
| 234 DEFINE_NATIVE_ENTRY(StringBuffer_createStringFromUint16Array, 3) { | 259 DEFINE_NATIVE_ENTRY(StringBuffer_createStringFromUint16Array, 3) { |
| 235 GET_NON_NULL_NATIVE_ARGUMENT(TypedData, codeUnits, arguments->NativeArgAt(0)); | 260 GET_NON_NULL_NATIVE_ARGUMENT(TypedData, codeUnits, arguments->NativeArgAt(0)); |
| 236 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1)); | 261 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1)); |
| 237 GET_NON_NULL_NATIVE_ARGUMENT(Bool, isLatin1, arguments->NativeArgAt(2)); | 262 GET_NON_NULL_NATIVE_ARGUMENT(Bool, isLatin1, arguments->NativeArgAt(2)); |
| 238 intptr_t array_length = codeUnits.Length(); | 263 intptr_t array_length = codeUnits.Length(); |
| 239 intptr_t length_value = length.Value(); | 264 intptr_t length_value = length.Value(); |
| 240 if (length_value < 0 || length_value > array_length) { | 265 if (length_value < 0 || length_value > array_length) { |
| 241 const Array& args = Array::Handle(Array::New(1)); | 266 const Array& args = Array::Handle(Array::New(1)); |
| 242 args.SetAt(0, length); | 267 args.SetAt(0, length); |
| 243 Exceptions::ThrowByType(Exceptions::kRange, args); | 268 Exceptions::ThrowByType(Exceptions::kRange, args); |
| 244 } | 269 } |
| 245 const String& result = isLatin1.value() | 270 const String& result = isLatin1.value() |
| 246 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) | 271 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) |
| 247 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); | 272 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); |
| 248 NoGCScope no_gc; | 273 NoGCScope no_gc; |
| 249 | 274 |
| 250 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); | 275 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); |
| 251 String::Copy(result, 0, data_position, length_value); | 276 String::Copy(result, 0, data_position, length_value); |
| 252 return result.raw(); | 277 return result.raw(); |
| 253 } | 278 } |
| 254 | 279 |
| 255 } // namespace dart | 280 } // namespace dart |
| OLD | NEW |