Chromium Code Reviews| 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 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { | 13 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { |
| 14 GET_NATIVE_ARGUMENT(Array, a, arguments->At(0)); | 14 GET_NATIVE_ARGUMENT(Array, a, arguments->At(0)); |
| 15 // TODO(srdjan): Check that parameterized type is an int. | 15 // TODO(srdjan): Check that parameterized type is an int. |
| 16 Zone* zone = Isolate::Current()->current_zone(); | 16 Zone* zone = Isolate::Current()->current_zone(); |
| 17 intptr_t len = a.Length(); | 17 intptr_t len = a.Length(); |
| 18 | 18 |
| 19 // Unbox the array and determine the maximum element width. | 19 // Unbox the array and determine the maximum element width. |
| 20 bool is_one_byte_string = true; | 20 bool is_one_byte_string = true; |
| 21 bool is_two_byte_string = true; | 21 bool is_two_byte_string = true; |
| 22 | |
| 23 const intptr_t kMaxLen = kIntptrMax / sizeof(uint32_t); | |
| 24 if (len > kMaxLen) { | |
| 25 // This should never happen because the native argument type is an | |
| 26 // Array, which is our standard list implementation. It should | |
|
cshapiro
2012/07/19 05:49:01
This is further strengthened by the size of an arr
turnidge
2012/07/31 23:21:45
Removed. Fixed in a forthcoming CL that changes z
| |
| 27 // not be able to grow so large as to trigger this. | |
| 28 FATAL1("StringBase_createFromCodePoints saw unexpectedly large len=%ld", | |
| 29 len); | |
| 30 } | |
| 31 | |
| 22 uint32_t* temp = reinterpret_cast<uint32_t*>( | 32 uint32_t* temp = reinterpret_cast<uint32_t*>( |
| 23 zone->Allocate(len * sizeof(uint32_t))); // NOLINT | 33 zone->Allocate(len * sizeof(uint32_t))); // NOLINT |
| 24 Smi& element = Smi::Handle(); | 34 Smi& element = Smi::Handle(); |
| 25 for (intptr_t i = 0; i < len; i++) { | 35 for (intptr_t i = 0; i < len; i++) { |
| 26 const Object& index_object = Object::Handle(a.At(i)); | 36 const Object& index_object = Object::Handle(a.At(i)); |
| 27 if (!index_object.IsSmi()) { | 37 if (!index_object.IsSmi()) { |
| 28 GrowableArray<const Object*> args; | 38 GrowableArray<const Object*> args; |
| 29 args.Add(&index_object); | 39 args.Add(&index_object); |
| 30 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 40 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 31 } | 41 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 GrowableArray<const Object*> args; | 158 GrowableArray<const Object*> args; |
| 149 args.Add(&elem); | 159 args.Add(&elem); |
| 150 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 160 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 151 } | 161 } |
| 152 } | 162 } |
| 153 const String& result = String::Handle(String::ConcatAll(strings)); | 163 const String& result = String::Handle(String::ConcatAll(strings)); |
| 154 arguments->SetReturn(result); | 164 arguments->SetReturn(result); |
| 155 } | 165 } |
| 156 | 166 |
| 157 } // namespace dart | 167 } // namespace dart |
| OLD | NEW |