OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/jsregexp-inl.h" | 8 #include "src/jsregexp-inl.h" |
9 #include "src/jsregexp.h" | 9 #include "src/jsregexp.h" |
10 #include "src/runtime/runtime-utils.h" | 10 #include "src/runtime/runtime-utils.h" |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 for (int j = 0; j < length; ++j) { | 794 for (int j = 0; j < length; ++j) { |
795 Object* element = elements->get(j); | 795 Object* element = elements->get(j); |
796 DCHECK(element == Smi::FromInt(0) || | 796 DCHECK(element == Smi::FromInt(0) || |
797 (element->IsString() && String::cast(element)->LooksValid())); | 797 (element->IsString() && String::cast(element)->LooksValid())); |
798 } | 798 } |
799 #endif | 799 #endif |
800 return i; | 800 return i; |
801 } | 801 } |
802 | 802 |
803 | 803 |
804 // Converts a String to JSArray. | 804 Handle<JSArray> Runtime::StringToArray(Isolate* isolate, Handle<String> s, |
805 // For example, "foo" => ["f", "o", "o"]. | 805 uint32_t limit) { |
806 RUNTIME_FUNCTION(Runtime_StringToArray) { | |
807 HandleScope scope(isolate); | |
808 DCHECK(args.length() == 2); | |
809 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); | |
810 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); | |
811 | |
812 s = String::Flatten(s); | 806 s = String::Flatten(s); |
813 const int length = static_cast<int>(Min<uint32_t>(s->length(), limit)); | 807 const int length = static_cast<int>(Min<uint32_t>(s->length(), limit)); |
814 | 808 |
815 Handle<FixedArray> elements; | 809 Handle<FixedArray> elements; |
816 int position = 0; | 810 int position = 0; |
817 if (s->IsFlat() && s->IsOneByteRepresentation()) { | 811 if (s->IsFlat() && s->IsOneByteRepresentation()) { |
818 // Try using cached chars where possible. | 812 // Try using cached chars where possible. |
819 elements = isolate->factory()->NewUninitializedFixedArray(length); | 813 elements = isolate->factory()->NewUninitializedFixedArray(length); |
820 | 814 |
821 DisallowHeapAllocation no_gc; | 815 DisallowHeapAllocation no_gc; |
(...skipping 16 matching lines...) Expand all Loading... |
838 isolate->factory()->LookupSingleCharacterStringFromCode(s->Get(i)); | 832 isolate->factory()->LookupSingleCharacterStringFromCode(s->Get(i)); |
839 elements->set(i, *str); | 833 elements->set(i, *str); |
840 } | 834 } |
841 | 835 |
842 #ifdef DEBUG | 836 #ifdef DEBUG |
843 for (int i = 0; i < length; ++i) { | 837 for (int i = 0; i < length; ++i) { |
844 DCHECK(String::cast(elements->get(i))->length() == 1); | 838 DCHECK(String::cast(elements->get(i))->length() == 1); |
845 } | 839 } |
846 #endif | 840 #endif |
847 | 841 |
848 return *isolate->factory()->NewJSArrayWithElements(elements); | 842 return isolate->factory()->NewJSArrayWithElements(elements); |
849 } | 843 } |
850 | 844 |
851 | 845 |
| 846 // Converts a String to JSArray. |
| 847 // For example, "foo" => ["f", "o", "o"]. |
| 848 RUNTIME_FUNCTION(Runtime_StringToArray) { |
| 849 HandleScope scope(isolate); |
| 850 DCHECK(args.length() == 2); |
| 851 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); |
| 852 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); |
| 853 |
| 854 return *Runtime::StringToArray(isolate, s, limit); |
| 855 } |
| 856 |
| 857 |
852 static inline bool ToUpperOverflows(uc32 character) { | 858 static inline bool ToUpperOverflows(uc32 character) { |
853 // y with umlauts and the micro sign are the only characters that stop | 859 // y with umlauts and the micro sign are the only characters that stop |
854 // fitting into one-byte when converting to uppercase. | 860 // fitting into one-byte when converting to uppercase. |
855 static const uc32 yuml_code = 0xff; | 861 static const uc32 yuml_code = 0xff; |
856 static const uc32 micro_code = 0xb5; | 862 static const uc32 micro_code = 0xb5; |
857 return (character == yuml_code || character == micro_code); | 863 return (character == yuml_code || character == micro_code); |
858 } | 864 } |
859 | 865 |
860 | 866 |
861 template <class Converter> | 867 template <class Converter> |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 return __RT_impl_Runtime_StringAdd(args, isolate); | 1302 return __RT_impl_Runtime_StringAdd(args, isolate); |
1297 } | 1303 } |
1298 | 1304 |
1299 | 1305 |
1300 RUNTIME_FUNCTION(RuntimeReference_IsStringWrapperSafeForDefaultValueOf) { | 1306 RUNTIME_FUNCTION(RuntimeReference_IsStringWrapperSafeForDefaultValueOf) { |
1301 UNIMPLEMENTED(); | 1307 UNIMPLEMENTED(); |
1302 return NULL; | 1308 return NULL; |
1303 } | 1309 } |
1304 } | 1310 } |
1305 } // namespace v8::internal | 1311 } // namespace v8::internal |
OLD | NEW |