| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 3236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3247 RUNTIME_FUNCTION(MaybeObject*, Runtime_ObjectFreeze) { | 3247 RUNTIME_FUNCTION(MaybeObject*, Runtime_ObjectFreeze) { |
| 3248 HandleScope scope(isolate); | 3248 HandleScope scope(isolate); |
| 3249 ASSERT(args.length() == 1); | 3249 ASSERT(args.length() == 1); |
| 3250 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 3250 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 3251 Handle<Object> result; | 3251 Handle<Object> result; |
| 3252 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, JSObject::Freeze(object)); | 3252 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, JSObject::Freeze(object)); |
| 3253 return *result; | 3253 return *result; |
| 3254 } | 3254 } |
| 3255 | 3255 |
| 3256 | 3256 |
| 3257 MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate, | |
| 3258 Object* char_code) { | |
| 3259 if (char_code->IsNumber()) { | |
| 3260 return isolate->heap()->LookupSingleCharacterStringFromCode( | |
| 3261 NumberToUint32(char_code) & 0xffff); | |
| 3262 } | |
| 3263 return isolate->heap()->empty_string(); | |
| 3264 } | |
| 3265 | |
| 3266 | |
| 3267 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_StringCharCodeAt) { | 3257 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_StringCharCodeAt) { |
| 3268 SealHandleScope shs(isolate); | 3258 SealHandleScope shs(isolate); |
| 3269 ASSERT(args.length() == 2); | 3259 ASSERT(args.length() == 2); |
| 3270 | 3260 |
| 3271 CONVERT_ARG_CHECKED(String, subject, 0); | 3261 CONVERT_ARG_CHECKED(String, subject, 0); |
| 3272 CONVERT_NUMBER_CHECKED(uint32_t, i, Uint32, args[1]); | 3262 CONVERT_NUMBER_CHECKED(uint32_t, i, Uint32, args[1]); |
| 3273 | 3263 |
| 3274 // Flatten the string. If someone wants to get a char at an index | 3264 // Flatten the string. If someone wants to get a char at an index |
| 3275 // in a cons string, it is likely that more indices will be | 3265 // in a cons string, it is likely that more indices will be |
| 3276 // accessed. | 3266 // accessed. |
| 3277 Object* flat; | 3267 Object* flat; |
| 3278 { MaybeObject* maybe_flat = subject->TryFlatten(); | 3268 { MaybeObject* maybe_flat = subject->TryFlatten(); |
| 3279 if (!maybe_flat->ToObject(&flat)) return maybe_flat; | 3269 if (!maybe_flat->ToObject(&flat)) return maybe_flat; |
| 3280 } | 3270 } |
| 3281 subject = String::cast(flat); | 3271 subject = String::cast(flat); |
| 3282 | 3272 |
| 3283 if (i >= static_cast<uint32_t>(subject->length())) { | 3273 if (i >= static_cast<uint32_t>(subject->length())) { |
| 3284 return isolate->heap()->nan_value(); | 3274 return isolate->heap()->nan_value(); |
| 3285 } | 3275 } |
| 3286 | 3276 |
| 3287 return Smi::FromInt(subject->Get(i)); | 3277 return Smi::FromInt(subject->Get(i)); |
| 3288 } | 3278 } |
| 3289 | 3279 |
| 3290 | 3280 |
| 3291 RUNTIME_FUNCTION(MaybeObject*, Runtime_CharFromCode) { | 3281 RUNTIME_FUNCTION(MaybeObject*, Runtime_CharFromCode) { |
| 3292 SealHandleScope shs(isolate); | 3282 HandleScope handlescope(isolate); |
| 3293 ASSERT(args.length() == 1); | 3283 ASSERT(args.length() == 1); |
| 3294 return CharFromCode(isolate, args[0]); | 3284 if (args[0]->IsNumber()) { |
| 3285 uint32_t code = NumberToUint32(args[0]) & 0xffff; |
| 3286 return *isolate->factory()->LookupSingleCharacterStringFromCode(code); |
| 3287 } |
| 3288 return isolate->heap()->empty_string(); |
| 3295 } | 3289 } |
| 3296 | 3290 |
| 3297 | 3291 |
| 3298 class FixedArrayBuilder { | 3292 class FixedArrayBuilder { |
| 3299 public: | 3293 public: |
| 3300 explicit FixedArrayBuilder(Isolate* isolate, int initial_capacity) | 3294 explicit FixedArrayBuilder(Isolate* isolate, int initial_capacity) |
| 3301 : array_(isolate->factory()->NewFixedArrayWithHoles(initial_capacity)), | 3295 : array_(isolate->factory()->NewFixedArrayWithHoles(initial_capacity)), |
| 3302 length_(0), | 3296 length_(0), |
| 3303 has_non_smi_elements_(false) { | 3297 has_non_smi_elements_(false) { |
| 3304 // Require a non-zero initial size. Ensures that doubling the size to | 3298 // Require a non-zero initial size. Ensures that doubling the size to |
| (...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4893 return isolate->heap()->false_value(); | 4887 return isolate->heap()->false_value(); |
| 4894 } | 4888 } |
| 4895 } | 4889 } |
| 4896 | 4890 |
| 4897 | 4891 |
| 4898 // Returns a single character string where first character equals | 4892 // Returns a single character string where first character equals |
| 4899 // string->Get(index). | 4893 // string->Get(index). |
| 4900 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) { | 4894 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) { |
| 4901 if (index < static_cast<uint32_t>(string->length())) { | 4895 if (index < static_cast<uint32_t>(string->length())) { |
| 4902 string->TryFlatten(); | 4896 string->TryFlatten(); |
| 4903 return LookupSingleCharacterStringFromCode( | 4897 return string->GetIsolate()->factory()->LookupSingleCharacterStringFromCode( |
| 4904 string->GetIsolate(), | |
| 4905 string->Get(index)); | 4898 string->Get(index)); |
| 4906 } | 4899 } |
| 4907 return Execution::CharAt(string, index); | 4900 return Execution::CharAt(string, index); |
| 4908 } | 4901 } |
| 4909 | 4902 |
| 4910 | 4903 |
| 4911 Handle<Object> Runtime::GetElementOrCharAt(Isolate* isolate, | 4904 Handle<Object> Runtime::GetElementOrCharAt(Isolate* isolate, |
| 4912 Handle<Object> object, | 4905 Handle<Object> object, |
| 4913 uint32_t index) { | 4906 uint32_t index) { |
| 4914 // Handle [] indexing on Strings | 4907 // Handle [] indexing on Strings |
| (...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6864 } else { | 6857 } else { |
| 6865 MemsetPointer(elements->data_start(), | 6858 MemsetPointer(elements->data_start(), |
| 6866 isolate->heap()->undefined_value(), | 6859 isolate->heap()->undefined_value(), |
| 6867 length); | 6860 length); |
| 6868 } | 6861 } |
| 6869 } else { | 6862 } else { |
| 6870 elements = isolate->factory()->NewFixedArray(length); | 6863 elements = isolate->factory()->NewFixedArray(length); |
| 6871 } | 6864 } |
| 6872 for (int i = position; i < length; ++i) { | 6865 for (int i = position; i < length; ++i) { |
| 6873 Handle<Object> str = | 6866 Handle<Object> str = |
| 6874 LookupSingleCharacterStringFromCode(isolate, s->Get(i)); | 6867 isolate->factory()->LookupSingleCharacterStringFromCode(s->Get(i)); |
| 6875 elements->set(i, *str); | 6868 elements->set(i, *str); |
| 6876 } | 6869 } |
| 6877 | 6870 |
| 6878 #ifdef DEBUG | 6871 #ifdef DEBUG |
| 6879 for (int i = 0; i < length; ++i) { | 6872 for (int i = 0; i < length; ++i) { |
| 6880 ASSERT(String::cast(elements->get(i))->length() == 1); | 6873 ASSERT(String::cast(elements->get(i))->length() == 1); |
| 6881 } | 6874 } |
| 6882 #endif | 6875 #endif |
| 6883 | 6876 |
| 6884 return *isolate->factory()->NewJSArrayWithElements(elements); | 6877 return *isolate->factory()->NewJSArrayWithElements(elements); |
| (...skipping 8376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15261 } | 15254 } |
| 15262 } | 15255 } |
| 15263 | 15256 |
| 15264 | 15257 |
| 15265 void Runtime::OutOfMemory() { | 15258 void Runtime::OutOfMemory() { |
| 15266 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); | 15259 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); |
| 15267 UNREACHABLE(); | 15260 UNREACHABLE(); |
| 15268 } | 15261 } |
| 15269 | 15262 |
| 15270 } } // namespace v8::internal | 15263 } } // namespace v8::internal |
| OLD | NEW |