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 3220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3231 HandleScope scope(isolate); | 3231 HandleScope scope(isolate); |
3232 ASSERT(args.length() == 1); | 3232 ASSERT(args.length() == 1); |
3233 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 3233 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
3234 Handle<Object> result; | 3234 Handle<Object> result; |
3235 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, JSObject::Freeze(object)); | 3235 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, JSObject::Freeze(object)); |
3236 return *result; | 3236 return *result; |
3237 } | 3237 } |
3238 | 3238 |
3239 | 3239 |
3240 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_StringCharCodeAt) { | 3240 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_StringCharCodeAt) { |
3241 SealHandleScope shs(isolate); | 3241 HandleScope handle_scope(isolate); |
3242 ASSERT(args.length() == 2); | 3242 ASSERT(args.length() == 2); |
3243 | 3243 |
3244 CONVERT_ARG_CHECKED(String, subject, 0); | 3244 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
3245 CONVERT_NUMBER_CHECKED(uint32_t, i, Uint32, args[1]); | 3245 CONVERT_NUMBER_CHECKED(uint32_t, i, Uint32, args[1]); |
3246 | 3246 |
3247 // Flatten the string. If someone wants to get a char at an index | 3247 // Flatten the string. If someone wants to get a char at an index |
3248 // in a cons string, it is likely that more indices will be | 3248 // in a cons string, it is likely that more indices will be |
3249 // accessed. | 3249 // accessed. |
3250 Object* flat; | 3250 subject = String::Flatten(subject); |
3251 { MaybeObject* maybe_flat = subject->TryFlatten(); | |
3252 if (!maybe_flat->ToObject(&flat)) return maybe_flat; | |
3253 } | |
3254 subject = String::cast(flat); | |
3255 | 3251 |
3256 if (i >= static_cast<uint32_t>(subject->length())) { | 3252 if (i >= static_cast<uint32_t>(subject->length())) { |
3257 return isolate->heap()->nan_value(); | 3253 return isolate->heap()->nan_value(); |
3258 } | 3254 } |
3259 | 3255 |
3260 return Smi::FromInt(subject->Get(i)); | 3256 return Smi::FromInt(subject->Get(i)); |
3261 } | 3257 } |
3262 | 3258 |
3263 | 3259 |
3264 RUNTIME_FUNCTION(MaybeObject*, Runtime_CharFromCode) { | 3260 RUNTIME_FUNCTION(MaybeObject*, Runtime_CharFromCode) { |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4203 HandleScope scope(isolate); | 4199 HandleScope scope(isolate); |
4204 ASSERT(args.length() == 4); | 4200 ASSERT(args.length() == 4); |
4205 | 4201 |
4206 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 4202 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
4207 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); | 4203 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); |
4208 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); | 4204 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); |
4209 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); | 4205 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); |
4210 | 4206 |
4211 ASSERT(regexp->GetFlags().is_global()); | 4207 ASSERT(regexp->GetFlags().is_global()); |
4212 | 4208 |
4213 if (!subject->IsFlat()) subject = FlattenGetString(subject); | 4209 subject = String::Flatten(subject); |
4214 | 4210 |
4215 if (replacement->length() == 0) { | 4211 if (replacement->length() == 0) { |
4216 if (subject->HasOnlyOneByteChars()) { | 4212 if (subject->HasOnlyOneByteChars()) { |
4217 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>( | 4213 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>( |
4218 isolate, subject, regexp, last_match_info); | 4214 isolate, subject, regexp, last_match_info); |
4219 } else { | 4215 } else { |
4220 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>( | 4216 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>( |
4221 isolate, subject, regexp, last_match_info); | 4217 isolate, subject, regexp, last_match_info); |
4222 } | 4218 } |
4223 } | 4219 } |
4224 | 4220 |
4225 if (!replacement->IsFlat()) replacement = FlattenGetString(replacement); | 4221 replacement = String::Flatten(replacement); |
4226 | 4222 |
4227 return StringReplaceGlobalRegExpWithString( | 4223 return StringReplaceGlobalRegExpWithString( |
4228 isolate, subject, regexp, replacement, last_match_info); | 4224 isolate, subject, regexp, replacement, last_match_info); |
4229 } | 4225 } |
4230 | 4226 |
4231 | 4227 |
4232 // This may return an empty MaybeHandle if an exception is thrown or | 4228 // This may return an empty MaybeHandle if an exception is thrown or |
4233 // we abort due to reaching the recursion limit. | 4229 // we abort due to reaching the recursion limit. |
4234 MaybeHandle<String> StringReplaceOneCharWithString(Isolate* isolate, | 4230 MaybeHandle<String> StringReplaceOneCharWithString(Isolate* isolate, |
4235 Handle<String> subject, | 4231 Handle<String> subject, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4289 const int kRecursionLimit = 0x1000; | 4285 const int kRecursionLimit = 0x1000; |
4290 bool found = false; | 4286 bool found = false; |
4291 Handle<String> result; | 4287 Handle<String> result; |
4292 if (StringReplaceOneCharWithString( | 4288 if (StringReplaceOneCharWithString( |
4293 isolate, subject, search, replace, &found, kRecursionLimit) | 4289 isolate, subject, search, replace, &found, kRecursionLimit) |
4294 .ToHandle(&result)) { | 4290 .ToHandle(&result)) { |
4295 return *result; | 4291 return *result; |
4296 } | 4292 } |
4297 if (isolate->has_pending_exception()) return Failure::Exception(); | 4293 if (isolate->has_pending_exception()) return Failure::Exception(); |
4298 | 4294 |
4299 subject = FlattenGetString(subject); | 4295 subject = String::Flatten(subject); |
4300 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 4296 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
4301 isolate, result, | 4297 isolate, result, |
4302 StringReplaceOneCharWithString( | 4298 StringReplaceOneCharWithString( |
4303 isolate, subject, search, replace, &found, kRecursionLimit)); | 4299 isolate, subject, search, replace, &found, kRecursionLimit)); |
4304 return *result; | 4300 return *result; |
4305 } | 4301 } |
4306 | 4302 |
4307 | 4303 |
4308 // Perform string match of pattern on subject, starting at start index. | 4304 // Perform string match of pattern on subject, starting at start index. |
4309 // Caller must ensure that 0 <= start_index <= sub->length(), | 4305 // Caller must ensure that 0 <= start_index <= sub->length(), |
4310 // and should check that pat->length() + start_index <= sub->length(). | 4306 // and should check that pat->length() + start_index <= sub->length(). |
4311 int Runtime::StringMatch(Isolate* isolate, | 4307 int Runtime::StringMatch(Isolate* isolate, |
4312 Handle<String> sub, | 4308 Handle<String> sub, |
4313 Handle<String> pat, | 4309 Handle<String> pat, |
4314 int start_index) { | 4310 int start_index) { |
4315 ASSERT(0 <= start_index); | 4311 ASSERT(0 <= start_index); |
4316 ASSERT(start_index <= sub->length()); | 4312 ASSERT(start_index <= sub->length()); |
4317 | 4313 |
4318 int pattern_length = pat->length(); | 4314 int pattern_length = pat->length(); |
4319 if (pattern_length == 0) return start_index; | 4315 if (pattern_length == 0) return start_index; |
4320 | 4316 |
4321 int subject_length = sub->length(); | 4317 int subject_length = sub->length(); |
4322 if (start_index + pattern_length > subject_length) return -1; | 4318 if (start_index + pattern_length > subject_length) return -1; |
4323 | 4319 |
4324 if (!sub->IsFlat()) FlattenString(sub); | 4320 sub = String::Flatten(sub); |
4325 if (!pat->IsFlat()) FlattenString(pat); | 4321 pat = String::Flatten(pat); |
4326 | 4322 |
4327 DisallowHeapAllocation no_gc; // ensure vectors stay valid | 4323 DisallowHeapAllocation no_gc; // ensure vectors stay valid |
4328 // Extract flattened substrings of cons strings before determining asciiness. | 4324 // Extract flattened substrings of cons strings before determining asciiness. |
4329 String::FlatContent seq_sub = sub->GetFlatContent(); | 4325 String::FlatContent seq_sub = sub->GetFlatContent(); |
4330 String::FlatContent seq_pat = pat->GetFlatContent(); | 4326 String::FlatContent seq_pat = pat->GetFlatContent(); |
4331 | 4327 |
4332 // dispatch on type of strings | 4328 // dispatch on type of strings |
4333 if (seq_pat.IsAscii()) { | 4329 if (seq_pat.IsAscii()) { |
4334 Vector<const uint8_t> pat_vector = seq_pat.ToOneByteVector(); | 4330 Vector<const uint8_t> pat_vector = seq_pat.ToOneByteVector(); |
4335 if (seq_sub.IsAscii()) { | 4331 if (seq_sub.IsAscii()) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4425 uint32_t sub_length = sub->length(); | 4421 uint32_t sub_length = sub->length(); |
4426 | 4422 |
4427 if (start_index + pat_length > sub_length) { | 4423 if (start_index + pat_length > sub_length) { |
4428 start_index = sub_length - pat_length; | 4424 start_index = sub_length - pat_length; |
4429 } | 4425 } |
4430 | 4426 |
4431 if (pat_length == 0) { | 4427 if (pat_length == 0) { |
4432 return Smi::FromInt(start_index); | 4428 return Smi::FromInt(start_index); |
4433 } | 4429 } |
4434 | 4430 |
4435 if (!sub->IsFlat()) FlattenString(sub); | 4431 sub = String::Flatten(sub); |
4436 if (!pat->IsFlat()) FlattenString(pat); | 4432 pat = String::Flatten(pat); |
4437 | 4433 |
4438 int position = -1; | 4434 int position = -1; |
4439 DisallowHeapAllocation no_gc; // ensure vectors stay valid | 4435 DisallowHeapAllocation no_gc; // ensure vectors stay valid |
4440 | 4436 |
4441 String::FlatContent sub_content = sub->GetFlatContent(); | 4437 String::FlatContent sub_content = sub->GetFlatContent(); |
4442 String::FlatContent pat_content = pat->GetFlatContent(); | 4438 String::FlatContent pat_content = pat->GetFlatContent(); |
4443 | 4439 |
4444 if (pat_content.IsAscii()) { | 4440 if (pat_content.IsAscii()) { |
4445 Vector<const uint8_t> pat_vector = pat_content.ToOneByteVector(); | 4441 Vector<const uint8_t> pat_vector = pat_content.ToOneByteVector(); |
4446 if (sub_content.IsAscii()) { | 4442 if (sub_content.IsAscii()) { |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4751 | 4747 |
4752 | 4748 |
4753 // This is only called for StringReplaceGlobalRegExpWithFunction. This sets | 4749 // This is only called for StringReplaceGlobalRegExpWithFunction. This sets |
4754 // lastMatchInfoOverride to maintain the last match info, so we don't need to | 4750 // lastMatchInfoOverride to maintain the last match info, so we don't need to |
4755 // set any other last match array info. | 4751 // set any other last match array info. |
4756 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExecMultiple) { | 4752 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExecMultiple) { |
4757 HandleScope handles(isolate); | 4753 HandleScope handles(isolate); |
4758 ASSERT(args.length() == 4); | 4754 ASSERT(args.length() == 4); |
4759 | 4755 |
4760 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); | 4756 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); |
4761 if (!subject->IsFlat()) FlattenString(subject); | |
4762 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 4757 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
4763 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 2); | 4758 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 2); |
4764 CONVERT_ARG_HANDLE_CHECKED(JSArray, result_array, 3); | 4759 CONVERT_ARG_HANDLE_CHECKED(JSArray, result_array, 3); |
4765 | 4760 |
| 4761 subject = String::Flatten(subject); |
4766 ASSERT(regexp->GetFlags().is_global()); | 4762 ASSERT(regexp->GetFlags().is_global()); |
4767 | 4763 |
4768 if (regexp->CaptureCount() == 0) { | 4764 if (regexp->CaptureCount() == 0) { |
4769 return SearchRegExpMultiple<false>( | 4765 return SearchRegExpMultiple<false>( |
4770 isolate, subject, regexp, last_match_info, result_array); | 4766 isolate, subject, regexp, last_match_info, result_array); |
4771 } else { | 4767 } else { |
4772 return SearchRegExpMultiple<true>( | 4768 return SearchRegExpMultiple<true>( |
4773 isolate, subject, regexp, last_match_info, result_array); | 4769 isolate, subject, regexp, last_match_info, result_array); |
4774 } | 4770 } |
4775 } | 4771 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4869 } else { | 4865 } else { |
4870 return isolate->heap()->false_value(); | 4866 return isolate->heap()->false_value(); |
4871 } | 4867 } |
4872 } | 4868 } |
4873 | 4869 |
4874 | 4870 |
4875 // Returns a single character string where first character equals | 4871 // Returns a single character string where first character equals |
4876 // string->Get(index). | 4872 // string->Get(index). |
4877 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) { | 4873 static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) { |
4878 if (index < static_cast<uint32_t>(string->length())) { | 4874 if (index < static_cast<uint32_t>(string->length())) { |
4879 string->TryFlatten(); | 4875 Factory* factory = string->GetIsolate()->factory(); |
4880 return string->GetIsolate()->factory()->LookupSingleCharacterStringFromCode( | 4876 return factory->LookupSingleCharacterStringFromCode( |
4881 string->Get(index)); | 4877 String::Flatten(string)->Get(index)); |
4882 } | 4878 } |
4883 return Execution::CharAt(string, index); | 4879 return Execution::CharAt(string, index); |
4884 } | 4880 } |
4885 | 4881 |
4886 | 4882 |
4887 Handle<Object> Runtime::GetElementOrCharAt(Isolate* isolate, | 4883 Handle<Object> Runtime::GetElementOrCharAt(Isolate* isolate, |
4888 Handle<Object> object, | 4884 Handle<Object> object, |
4889 uint32_t index) { | 4885 uint32_t index) { |
4890 // Handle [] indexing on Strings | 4886 // Handle [] indexing on Strings |
4891 if (object->IsString()) { | 4887 if (object->IsString()) { |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5303 bool has_exception; | 5299 bool has_exception; |
5304 Handle<Object> number = | 5300 Handle<Object> number = |
5305 Execution::ToNumber(isolate, value, &has_exception); | 5301 Execution::ToNumber(isolate, value, &has_exception); |
5306 if (has_exception) return MaybeHandle<Object>(); // exception | 5302 if (has_exception) return MaybeHandle<Object>(); // exception |
5307 value = number; | 5303 value = number; |
5308 } | 5304 } |
5309 } | 5305 } |
5310 return JSObject::SetElement(js_object, index, value, attr, | 5306 return JSObject::SetElement(js_object, index, value, attr, |
5311 strict_mode, true, set_mode); | 5307 strict_mode, true, set_mode); |
5312 } else { | 5308 } else { |
5313 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); | 5309 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); |
5314 return JSReceiver::SetProperty(js_object, name, value, attr, strict_mode); | 5310 return JSReceiver::SetProperty(js_object, name, value, attr, strict_mode); |
5315 } | 5311 } |
5316 } | 5312 } |
5317 | 5313 |
5318 // Call-back into JavaScript to convert the key to a string. | 5314 // Call-back into JavaScript to convert the key to a string. |
5319 bool has_pending_exception = false; | 5315 bool has_pending_exception = false; |
5320 Handle<Object> converted = | 5316 Handle<Object> converted = |
5321 Execution::ToString(isolate, key, &has_pending_exception); | 5317 Execution::ToString(isolate, key, &has_pending_exception); |
5322 if (has_pending_exception) return MaybeHandle<Object>(); // exception | 5318 if (has_pending_exception) return MaybeHandle<Object>(); // exception |
5323 Handle<String> name = Handle<String>::cast(converted); | 5319 Handle<String> name = Handle<String>::cast(converted); |
(...skipping 29 matching lines...) Expand all Loading... |
5353 return JSObject::SetElement(js_object, index, value, attr, | 5349 return JSObject::SetElement(js_object, index, value, attr, |
5354 SLOPPY, false, DEFINE_PROPERTY); | 5350 SLOPPY, false, DEFINE_PROPERTY); |
5355 } | 5351 } |
5356 | 5352 |
5357 if (key->IsName()) { | 5353 if (key->IsName()) { |
5358 Handle<Name> name = Handle<Name>::cast(key); | 5354 Handle<Name> name = Handle<Name>::cast(key); |
5359 if (name->AsArrayIndex(&index)) { | 5355 if (name->AsArrayIndex(&index)) { |
5360 return JSObject::SetElement(js_object, index, value, attr, | 5356 return JSObject::SetElement(js_object, index, value, attr, |
5361 SLOPPY, false, DEFINE_PROPERTY); | 5357 SLOPPY, false, DEFINE_PROPERTY); |
5362 } else { | 5358 } else { |
5363 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); | 5359 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); |
5364 return JSObject::SetLocalPropertyIgnoreAttributes(js_object, name, | 5360 return JSObject::SetLocalPropertyIgnoreAttributes( |
5365 value, attr); | 5361 js_object, name, value, attr); |
5366 } | 5362 } |
5367 } | 5363 } |
5368 | 5364 |
5369 // Call-back into JavaScript to convert the key to a string. | 5365 // Call-back into JavaScript to convert the key to a string. |
5370 bool has_pending_exception = false; | 5366 bool has_pending_exception = false; |
5371 Handle<Object> converted = | 5367 Handle<Object> converted = |
5372 Execution::ToString(isolate, key, &has_pending_exception); | 5368 Execution::ToString(isolate, key, &has_pending_exception); |
5373 if (has_pending_exception) return MaybeHandle<Object>(); // exception | 5369 if (has_pending_exception) return MaybeHandle<Object>(); // exception |
5374 Handle<String> name = Handle<String>::cast(converted); | 5370 Handle<String> name = Handle<String>::cast(converted); |
5375 | 5371 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5408 name = Handle<Name>::cast(key); | 5404 name = Handle<Name>::cast(key); |
5409 } else { | 5405 } else { |
5410 // Call-back into JavaScript to convert the key to a string. | 5406 // Call-back into JavaScript to convert the key to a string. |
5411 bool has_pending_exception = false; | 5407 bool has_pending_exception = false; |
5412 Handle<Object> converted = Execution::ToString( | 5408 Handle<Object> converted = Execution::ToString( |
5413 isolate, key, &has_pending_exception); | 5409 isolate, key, &has_pending_exception); |
5414 if (has_pending_exception) return MaybeHandle<Object>(); | 5410 if (has_pending_exception) return MaybeHandle<Object>(); |
5415 name = Handle<String>::cast(converted); | 5411 name = Handle<String>::cast(converted); |
5416 } | 5412 } |
5417 | 5413 |
5418 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); | 5414 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); |
5419 return JSReceiver::DeleteProperty(receiver, name, mode); | 5415 return JSReceiver::DeleteProperty(receiver, name, mode); |
5420 } | 5416 } |
5421 | 5417 |
5422 | 5418 |
5423 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetHiddenProperty) { | 5419 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetHiddenProperty) { |
5424 HandleScope scope(isolate); | 5420 HandleScope scope(isolate); |
5425 RUNTIME_ASSERT(args.length() == 3); | 5421 RUNTIME_ASSERT(args.length() == 3); |
5426 | 5422 |
5427 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 5423 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
5428 CONVERT_ARG_HANDLE_CHECKED(String, key, 1); | 5424 CONVERT_ARG_HANDLE_CHECKED(String, key, 1); |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6256 CONVERT_ARG_HANDLE_CHECKED(SeqString, string, 0); | 6252 CONVERT_ARG_HANDLE_CHECKED(SeqString, string, 0); |
6257 CONVERT_SMI_ARG_CHECKED(new_length, 1); | 6253 CONVERT_SMI_ARG_CHECKED(new_length, 1); |
6258 return *SeqString::Truncate(string, new_length); | 6254 return *SeqString::Truncate(string, new_length); |
6259 } | 6255 } |
6260 | 6256 |
6261 | 6257 |
6262 RUNTIME_FUNCTION(MaybeObject*, Runtime_URIEscape) { | 6258 RUNTIME_FUNCTION(MaybeObject*, Runtime_URIEscape) { |
6263 HandleScope scope(isolate); | 6259 HandleScope scope(isolate); |
6264 ASSERT(args.length() == 1); | 6260 ASSERT(args.length() == 1); |
6265 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); | 6261 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
6266 Handle<String> string = FlattenGetString(source); | 6262 Handle<String> string = String::Flatten(source); |
6267 ASSERT(string->IsFlat()); | 6263 ASSERT(string->IsFlat()); |
6268 Handle<String> result; | 6264 Handle<String> result; |
6269 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 6265 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
6270 isolate, result, | 6266 isolate, result, |
6271 string->IsOneByteRepresentationUnderneath() | 6267 string->IsOneByteRepresentationUnderneath() |
6272 ? URIEscape::Escape<uint8_t>(isolate, source) | 6268 ? URIEscape::Escape<uint8_t>(isolate, source) |
6273 : URIEscape::Escape<uc16>(isolate, source)); | 6269 : URIEscape::Escape<uc16>(isolate, source)); |
6274 return *result; | 6270 return *result; |
6275 } | 6271 } |
6276 | 6272 |
6277 | 6273 |
6278 RUNTIME_FUNCTION(MaybeObject*, Runtime_URIUnescape) { | 6274 RUNTIME_FUNCTION(MaybeObject*, Runtime_URIUnescape) { |
6279 HandleScope scope(isolate); | 6275 HandleScope scope(isolate); |
6280 ASSERT(args.length() == 1); | 6276 ASSERT(args.length() == 1); |
6281 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); | 6277 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
6282 Handle<String> string = FlattenGetString(source); | 6278 Handle<String> string = String::Flatten(source); |
6283 ASSERT(string->IsFlat()); | 6279 ASSERT(string->IsFlat()); |
6284 Handle<String> result; | 6280 Handle<String> result; |
6285 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 6281 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
6286 isolate, result, | 6282 isolate, result, |
6287 string->IsOneByteRepresentationUnderneath() | 6283 string->IsOneByteRepresentationUnderneath() |
6288 ? URIUnescape::Unescape<uint8_t>(isolate, source) | 6284 ? URIUnescape::Unescape<uint8_t>(isolate, source) |
6289 : URIUnescape::Unescape<uc16>(isolate, source)); | 6285 : URIUnescape::Unescape<uc16>(isolate, source)); |
6290 return *result; | 6286 return *result; |
6291 } | 6287 } |
6292 | 6288 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6566 } // namespace | 6562 } // namespace |
6567 | 6563 |
6568 | 6564 |
6569 template <class Converter> | 6565 template <class Converter> |
6570 MUST_USE_RESULT static MaybeObject* ConvertCase( | 6566 MUST_USE_RESULT static MaybeObject* ConvertCase( |
6571 Arguments args, | 6567 Arguments args, |
6572 Isolate* isolate, | 6568 Isolate* isolate, |
6573 unibrow::Mapping<Converter, 128>* mapping) { | 6569 unibrow::Mapping<Converter, 128>* mapping) { |
6574 HandleScope handle_scope(isolate); | 6570 HandleScope handle_scope(isolate); |
6575 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); | 6571 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); |
6576 s = FlattenGetString(s); | 6572 s = String::Flatten(s); |
6577 int length = s->length(); | 6573 int length = s->length(); |
6578 // Assume that the string is not empty; we need this assumption later | 6574 // Assume that the string is not empty; we need this assumption later |
6579 if (length == 0) return *s; | 6575 if (length == 0) return *s; |
6580 | 6576 |
6581 // Simpler handling of ASCII strings. | 6577 // Simpler handling of ASCII strings. |
6582 // | 6578 // |
6583 // NOTE: This assumes that the upper/lower case of an ASCII | 6579 // NOTE: This assumes that the upper/lower case of an ASCII |
6584 // character is also ASCII. This is currently the case, but it | 6580 // character is also ASCII. This is currently the case, but it |
6585 // might break in the future if we implement more context and locale | 6581 // might break in the future if we implement more context and locale |
6586 // dependent upper/lower conversions. | 6582 // dependent upper/lower conversions. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6640 | 6636 |
6641 | 6637 |
6642 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) { | 6638 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringTrim) { |
6643 HandleScope scope(isolate); | 6639 HandleScope scope(isolate); |
6644 ASSERT(args.length() == 3); | 6640 ASSERT(args.length() == 3); |
6645 | 6641 |
6646 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); | 6642 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); |
6647 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1); | 6643 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1); |
6648 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2); | 6644 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2); |
6649 | 6645 |
6650 string = FlattenGetString(string); | 6646 string = String::Flatten(string); |
6651 int length = string->length(); | 6647 int length = string->length(); |
6652 | 6648 |
6653 int left = 0; | 6649 int left = 0; |
6654 UnicodeCache* unicode_cache = isolate->unicode_cache(); | 6650 UnicodeCache* unicode_cache = isolate->unicode_cache(); |
6655 if (trimLeft) { | 6651 if (trimLeft) { |
6656 while (left < length && | 6652 while (left < length && |
6657 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(left))) { | 6653 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(left))) { |
6658 left++; | 6654 left++; |
6659 } | 6655 } |
6660 } | 6656 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6696 isolate->factory()->NewJSArrayWithElements( | 6692 isolate->factory()->NewJSArrayWithElements( |
6697 Handle<FixedArray>::cast(cached_answer)); | 6693 Handle<FixedArray>::cast(cached_answer)); |
6698 return *result; | 6694 return *result; |
6699 } | 6695 } |
6700 } | 6696 } |
6701 | 6697 |
6702 // The limit can be very large (0xffffffffu), but since the pattern | 6698 // The limit can be very large (0xffffffffu), but since the pattern |
6703 // isn't empty, we can never create more parts than ~half the length | 6699 // isn't empty, we can never create more parts than ~half the length |
6704 // of the subject. | 6700 // of the subject. |
6705 | 6701 |
6706 if (!subject->IsFlat()) FlattenString(subject); | 6702 subject = String::Flatten(subject); |
| 6703 pattern = String::Flatten(pattern); |
6707 | 6704 |
6708 static const int kMaxInitialListCapacity = 16; | 6705 static const int kMaxInitialListCapacity = 16; |
6709 | 6706 |
6710 ZoneScope zone_scope(isolate->runtime_zone()); | 6707 ZoneScope zone_scope(isolate->runtime_zone()); |
6711 | 6708 |
6712 // Find (up to limit) indices of separator and end-of-string in subject | 6709 // Find (up to limit) indices of separator and end-of-string in subject |
6713 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); | 6710 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); |
6714 ZoneList<int> indices(initial_capacity, zone_scope.zone()); | 6711 ZoneList<int> indices(initial_capacity, zone_scope.zone()); |
6715 if (!pattern->IsFlat()) FlattenString(pattern); | |
6716 | 6712 |
6717 FindStringIndicesDispatch(isolate, *subject, *pattern, | 6713 FindStringIndicesDispatch(isolate, *subject, *pattern, |
6718 &indices, limit, zone_scope.zone()); | 6714 &indices, limit, zone_scope.zone()); |
6719 | 6715 |
6720 if (static_cast<uint32_t>(indices.length()) < limit) { | 6716 if (static_cast<uint32_t>(indices.length()) < limit) { |
6721 indices.Add(subject_length, zone_scope.zone()); | 6717 indices.Add(subject_length, zone_scope.zone()); |
6722 } | 6718 } |
6723 | 6719 |
6724 // The list indices now contains the end of each part to create. | 6720 // The list indices now contains the end of each part to create. |
6725 | 6721 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6796 | 6792 |
6797 | 6793 |
6798 // Converts a String to JSArray. | 6794 // Converts a String to JSArray. |
6799 // For example, "foo" => ["f", "o", "o"]. | 6795 // For example, "foo" => ["f", "o", "o"]. |
6800 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToArray) { | 6796 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToArray) { |
6801 HandleScope scope(isolate); | 6797 HandleScope scope(isolate); |
6802 ASSERT(args.length() == 2); | 6798 ASSERT(args.length() == 2); |
6803 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); | 6799 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); |
6804 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); | 6800 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); |
6805 | 6801 |
6806 s = FlattenGetString(s); | 6802 s = String::Flatten(s); |
6807 const int length = static_cast<int>(Min<uint32_t>(s->length(), limit)); | 6803 const int length = static_cast<int>(Min<uint32_t>(s->length(), limit)); |
6808 | 6804 |
6809 Handle<FixedArray> elements; | 6805 Handle<FixedArray> elements; |
6810 int position = 0; | 6806 int position = 0; |
6811 if (s->IsFlat() && s->IsOneByteRepresentation()) { | 6807 if (s->IsFlat() && s->IsOneByteRepresentation()) { |
6812 // Try using cached chars where possible. | 6808 // Try using cached chars where possible. |
6813 Object* obj; | 6809 Object* obj; |
6814 { MaybeObject* maybe_obj = | 6810 { MaybeObject* maybe_obj = |
6815 isolate->heap()->AllocateUninitializedFixedArray(length); | 6811 isolate->heap()->AllocateUninitializedFixedArray(length); |
6816 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 6812 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7670 } else { | 7666 } else { |
7671 result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER); | 7667 result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER); |
7672 } | 7668 } |
7673 ASSERT(result == | 7669 ASSERT(result == |
7674 StringCharacterStreamCompare(x->GetIsolate()->runtime_state(), x, y)); | 7670 StringCharacterStreamCompare(x->GetIsolate()->runtime_state(), x, y)); |
7675 return result; | 7671 return result; |
7676 } | 7672 } |
7677 | 7673 |
7678 | 7674 |
7679 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_StringCompare) { | 7675 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_StringCompare) { |
7680 SealHandleScope shs(isolate); | 7676 HandleScope shs(isolate); |
7681 ASSERT(args.length() == 2); | 7677 ASSERT(args.length() == 2); |
7682 | 7678 |
7683 CONVERT_ARG_CHECKED(String, x, 0); | 7679 CONVERT_ARG_CHECKED(String, x, 0); |
7684 CONVERT_ARG_CHECKED(String, y, 1); | 7680 CONVERT_ARG_CHECKED(String, y, 1); |
7685 | 7681 |
7686 isolate->counters()->string_compare_runtime()->Increment(); | 7682 isolate->counters()->string_compare_runtime()->Increment(); |
7687 | 7683 |
7688 // A few fast case tests before we flatten. | 7684 // A few fast case tests before we flatten. |
7689 if (x == y) return Smi::FromInt(EQUAL); | 7685 if (x == y) return Smi::FromInt(EQUAL); |
7690 if (y->length() == 0) { | 7686 if (y->length() == 0) { |
(...skipping 1953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9644 // time is milliseconds. Therefore, we floor the result of getting | 9640 // time is milliseconds. Therefore, we floor the result of getting |
9645 // the OS time. | 9641 // the OS time. |
9646 double millis = std::floor(OS::TimeCurrentMillis()); | 9642 double millis = std::floor(OS::TimeCurrentMillis()); |
9647 return isolate->heap()->NumberFromDouble(millis); | 9643 return isolate->heap()->NumberFromDouble(millis); |
9648 } | 9644 } |
9649 | 9645 |
9650 | 9646 |
9651 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateParseString) { | 9647 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateParseString) { |
9652 HandleScope scope(isolate); | 9648 HandleScope scope(isolate); |
9653 ASSERT(args.length() == 2); | 9649 ASSERT(args.length() == 2); |
9654 | |
9655 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); | 9650 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); |
9656 FlattenString(str); | |
9657 | |
9658 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1); | 9651 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1); |
9659 | 9652 |
9660 JSObject::EnsureCanContainHeapObjectElements(output); | 9653 JSObject::EnsureCanContainHeapObjectElements(output); |
9661 RUNTIME_ASSERT(output->HasFastObjectElements()); | 9654 RUNTIME_ASSERT(output->HasFastObjectElements()); |
9662 | 9655 |
| 9656 str = String::Flatten(str); |
9663 DisallowHeapAllocation no_gc; | 9657 DisallowHeapAllocation no_gc; |
9664 | 9658 |
9665 FixedArray* output_array = FixedArray::cast(output->elements()); | 9659 FixedArray* output_array = FixedArray::cast(output->elements()); |
9666 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); | 9660 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); |
9667 bool result; | 9661 bool result; |
9668 String::FlatContent str_content = str->GetFlatContent(); | 9662 String::FlatContent str_content = str->GetFlatContent(); |
9669 if (str_content.IsAscii()) { | 9663 if (str_content.IsAscii()) { |
9670 result = DateParser::Parse(str_content.ToOneByteVector(), | 9664 result = DateParser::Parse(str_content.ToOneByteVector(), |
9671 output_array, | 9665 output_array, |
9672 isolate->unicode_cache()); | 9666 isolate->unicode_cache()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9745 return isolate->heap()->ToBoolean( | 9739 return isolate->heap()->ToBoolean( |
9746 !JSGlobalObject::cast(global)->IsDetached()); | 9740 !JSGlobalObject::cast(global)->IsDetached()); |
9747 } | 9741 } |
9748 | 9742 |
9749 | 9743 |
9750 RUNTIME_FUNCTION(MaybeObject*, Runtime_ParseJson) { | 9744 RUNTIME_FUNCTION(MaybeObject*, Runtime_ParseJson) { |
9751 HandleScope scope(isolate); | 9745 HandleScope scope(isolate); |
9752 ASSERT_EQ(1, args.length()); | 9746 ASSERT_EQ(1, args.length()); |
9753 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); | 9747 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
9754 | 9748 |
9755 source = Handle<String>(FlattenGetString(source)); | 9749 source = String::Flatten(source); |
9756 // Optimized fast case where we only have ASCII characters. | 9750 // Optimized fast case where we only have ASCII characters. |
9757 Handle<Object> result; | 9751 Handle<Object> result; |
9758 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 9752 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
9759 isolate, result, | 9753 isolate, result, |
9760 source->IsSeqOneByteString() ? JsonParser<true>::Parse(source) | 9754 source->IsSeqOneByteString() ? JsonParser<true>::Parse(source) |
9761 : JsonParser<false>::Parse(source)); | 9755 : JsonParser<false>::Parse(source)); |
9762 return *result; | 9756 return *result; |
9763 } | 9757 } |
9764 | 9758 |
9765 | 9759 |
(...skipping 4805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14571 OS::Abort(); | 14565 OS::Abort(); |
14572 UNREACHABLE(); | 14566 UNREACHABLE(); |
14573 return NULL; | 14567 return NULL; |
14574 } | 14568 } |
14575 | 14569 |
14576 | 14570 |
14577 RUNTIME_FUNCTION(MaybeObject*, Runtime_FlattenString) { | 14571 RUNTIME_FUNCTION(MaybeObject*, Runtime_FlattenString) { |
14578 HandleScope scope(isolate); | 14572 HandleScope scope(isolate); |
14579 ASSERT(args.length() == 1); | 14573 ASSERT(args.length() == 1); |
14580 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); | 14574 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); |
14581 FlattenString(str); | 14575 return *String::Flatten(str); |
14582 return isolate->heap()->undefined_value(); | |
14583 } | 14576 } |
14584 | 14577 |
14585 | 14578 |
14586 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyContextDisposed) { | 14579 RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyContextDisposed) { |
14587 HandleScope scope(isolate); | 14580 HandleScope scope(isolate); |
14588 ASSERT(args.length() == 0); | 14581 ASSERT(args.length() == 0); |
14589 isolate->heap()->NotifyContextDisposed(); | 14582 isolate->heap()->NotifyContextDisposed(); |
14590 return isolate->heap()->undefined_value(); | 14583 return isolate->heap()->undefined_value(); |
14591 } | 14584 } |
14592 | 14585 |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15229 } | 15222 } |
15230 } | 15223 } |
15231 | 15224 |
15232 | 15225 |
15233 void Runtime::OutOfMemory() { | 15226 void Runtime::OutOfMemory() { |
15234 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); | 15227 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); |
15235 UNREACHABLE(); | 15228 UNREACHABLE(); |
15236 } | 15229 } |
15237 | 15230 |
15238 } } // namespace v8::internal | 15231 } } // namespace v8::internal |
OLD | NEW |