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 "factory.h" | 5 #include "factory.h" |
6 | 6 |
7 #include "conversions.h" | 7 #include "conversions.h" |
8 #include "isolate-inl.h" | 8 #include "isolate-inl.h" |
9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
10 | 10 |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 Handle<String> first, | 435 Handle<String> first, |
436 Handle<String> second) { | 436 Handle<String> second) { |
437 DisallowHeapAllocation pointer_stays_valid; | 437 DisallowHeapAllocation pointer_stays_valid; |
438 SinkChar* sink = result->GetChars(); | 438 SinkChar* sink = result->GetChars(); |
439 String::WriteToFlat(*first, sink, 0, first->length()); | 439 String::WriteToFlat(*first, sink, 0, first->length()); |
440 String::WriteToFlat(*second, sink + first->length(), 0, second->length()); | 440 String::WriteToFlat(*second, sink + first->length(), 0, second->length()); |
441 return result; | 441 return result; |
442 } | 442 } |
443 | 443 |
444 | 444 |
445 Handle<ConsString> Factory::NewRawConsString(String::Encoding encoding) { | |
446 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING) | |
447 ? cons_ascii_string_map() : cons_string_map(); | |
448 return New<ConsString>(map, NEW_SPACE); | |
449 } | |
450 | |
451 | |
452 MaybeHandle<String> Factory::NewConsString(Handle<String> left, | 445 MaybeHandle<String> Factory::NewConsString(Handle<String> left, |
453 Handle<String> right) { | 446 Handle<String> right) { |
454 int left_length = left->length(); | 447 int left_length = left->length(); |
455 if (left_length == 0) return right; | 448 if (left_length == 0) return right; |
456 int right_length = right->length(); | 449 int right_length = right->length(); |
457 if (right_length == 0) return left; | 450 if (right_length == 0) return left; |
458 | 451 |
459 int length = left_length + right_length; | 452 int length = left_length + right_length; |
460 | 453 |
461 if (length == 2) { | 454 if (length == 2) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 return result; | 504 return result; |
512 } | 505 } |
513 | 506 |
514 return (is_one_byte_data_in_two_byte_string) | 507 return (is_one_byte_data_in_two_byte_string) |
515 ? ConcatStringContent<uint8_t>( | 508 ? ConcatStringContent<uint8_t>( |
516 NewRawOneByteString(length).ToHandleChecked(), left, right) | 509 NewRawOneByteString(length).ToHandleChecked(), left, right) |
517 : ConcatStringContent<uc16>( | 510 : ConcatStringContent<uc16>( |
518 NewRawTwoByteString(length).ToHandleChecked(), left, right); | 511 NewRawTwoByteString(length).ToHandleChecked(), left, right); |
519 } | 512 } |
520 | 513 |
521 Handle<ConsString> result = NewRawConsString( | 514 Handle<Map> map = (is_one_byte || is_one_byte_data_in_two_byte_string) |
522 (is_one_byte || is_one_byte_data_in_two_byte_string) | 515 ? cons_ascii_string_map() : cons_string_map(); |
523 ? String::ONE_BYTE_ENCODING | 516 Handle<ConsString> result = New<ConsString>(map, NEW_SPACE); |
524 : String::TWO_BYTE_ENCODING); | |
525 | 517 |
526 DisallowHeapAllocation no_gc; | 518 DisallowHeapAllocation no_gc; |
527 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); | 519 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); |
528 | 520 |
529 result->set_hash_field(String::kEmptyHashField); | 521 result->set_hash_field(String::kEmptyHashField); |
530 result->set_length(length); | 522 result->set_length(length); |
531 result->set_first(*left, mode); | 523 result->set_first(*left, mode); |
532 result->set_second(*right, mode); | 524 result->set_second(*right, mode); |
533 return result; | 525 return result; |
534 } | 526 } |
535 | 527 |
536 | 528 |
537 Handle<String> Factory::NewFlatConcatString(Handle<String> first, | 529 Handle<String> Factory::NewFlatConcatString(Handle<String> first, |
538 Handle<String> second) { | 530 Handle<String> second) { |
539 int total_length = first->length() + second->length(); | 531 int total_length = first->length() + second->length(); |
540 if (first->IsOneByteRepresentation() && second->IsOneByteRepresentation()) { | 532 if (first->IsOneByteRepresentation() && second->IsOneByteRepresentation()) { |
541 return ConcatStringContent<uint8_t>( | 533 return ConcatStringContent<uint8_t>( |
542 NewRawOneByteString(total_length).ToHandleChecked(), first, second); | 534 NewRawOneByteString(total_length).ToHandleChecked(), first, second); |
543 } else { | 535 } else { |
544 return ConcatStringContent<uc16>( | 536 return ConcatStringContent<uc16>( |
545 NewRawTwoByteString(total_length).ToHandleChecked(), first, second); | 537 NewRawTwoByteString(total_length).ToHandleChecked(), first, second); |
546 } | 538 } |
547 } | 539 } |
548 | 540 |
549 | 541 |
550 Handle<SlicedString> Factory::NewRawSlicedString(String::Encoding encoding) { | |
551 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING) | |
552 ? sliced_ascii_string_map() : sliced_string_map(); | |
553 return New<SlicedString>(map, NEW_SPACE); | |
554 } | |
555 | |
556 | |
557 Handle<String> Factory::NewProperSubString(Handle<String> str, | 542 Handle<String> Factory::NewProperSubString(Handle<String> str, |
558 int begin, | 543 int begin, |
559 int end) { | 544 int end) { |
560 #if VERIFY_HEAP | 545 #if VERIFY_HEAP |
561 if (FLAG_verify_heap) str->StringVerify(); | 546 if (FLAG_verify_heap) str->StringVerify(); |
562 #endif | 547 #endif |
563 ASSERT(begin > 0 || end < str->length()); | 548 ASSERT(begin > 0 || end < str->length()); |
564 | 549 |
565 str = String::Flatten(str); | 550 str = String::Flatten(str); |
566 | 551 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 583 |
599 int offset = begin; | 584 int offset = begin; |
600 | 585 |
601 if (str->IsSlicedString()) { | 586 if (str->IsSlicedString()) { |
602 Handle<SlicedString> slice = Handle<SlicedString>::cast(str); | 587 Handle<SlicedString> slice = Handle<SlicedString>::cast(str); |
603 str = Handle<String>(slice->parent(), isolate()); | 588 str = Handle<String>(slice->parent(), isolate()); |
604 offset += slice->offset(); | 589 offset += slice->offset(); |
605 } | 590 } |
606 | 591 |
607 ASSERT(str->IsSeqString() || str->IsExternalString()); | 592 ASSERT(str->IsSeqString() || str->IsExternalString()); |
608 Handle<SlicedString> slice = NewRawSlicedString( | 593 Handle<Map> map = str->IsOneByteRepresentation() ? sliced_ascii_string_map() |
609 str->IsOneByteRepresentation() ? String::ONE_BYTE_ENCODING | 594 : sliced_string_map(); |
610 : String::TWO_BYTE_ENCODING); | 595 Handle<SlicedString> slice = New<SlicedString>(map, NEW_SPACE); |
611 | 596 |
612 slice->set_hash_field(String::kEmptyHashField); | 597 slice->set_hash_field(String::kEmptyHashField); |
613 slice->set_length(length); | 598 slice->set_length(length); |
614 slice->set_parent(*str); | 599 slice->set_parent(*str); |
615 slice->set_offset(offset); | 600 slice->set_offset(offset); |
616 return slice; | 601 return slice; |
617 } | 602 } |
618 | 603 |
619 | 604 |
620 MaybeHandle<String> Factory::NewExternalStringFromAscii( | 605 MaybeHandle<String> Factory::NewExternalStringFromAscii( |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 JSObject::SetLocalPropertyIgnoreAttributes(prototype, | 955 JSObject::SetLocalPropertyIgnoreAttributes(prototype, |
971 constructor_string(), | 956 constructor_string(), |
972 function, | 957 function, |
973 DONT_ENUM).Assert(); | 958 DONT_ENUM).Assert(); |
974 } | 959 } |
975 | 960 |
976 return prototype; | 961 return prototype; |
977 } | 962 } |
978 | 963 |
979 | 964 |
| 965 |
| 966 Handle<JSObject> Factory::CopyJSObject(Handle<JSObject> object) { |
| 967 CALL_HEAP_FUNCTION(isolate(), |
| 968 isolate()->heap()->CopyJSObject(*object, NULL), |
| 969 JSObject); |
| 970 } |
| 971 |
| 972 |
| 973 Handle<JSObject> Factory::CopyJSObjectWithMemento(Handle<JSObject> object, |
| 974 Handle<AllocationSite> site) { |
| 975 CALL_HEAP_FUNCTION(isolate(), |
| 976 isolate()->heap()->CopyJSObject( |
| 977 *object, |
| 978 site.is_null() ? NULL : *site), |
| 979 JSObject); |
| 980 } |
| 981 |
| 982 |
| 983 Handle<FixedArray> Factory::CopyFixedArrayWithMap(Handle<FixedArray> array, |
| 984 Handle<Map> map) { |
| 985 CALL_HEAP_FUNCTION(isolate(), |
| 986 isolate()->heap()->CopyFixedArrayWithMap(*array, *map), |
| 987 FixedArray); |
| 988 } |
| 989 |
| 990 |
980 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { | 991 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { |
981 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); | 992 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); |
982 } | 993 } |
983 | 994 |
984 | 995 |
985 Handle<FixedArray> Factory::CopyAndTenureFixedCOWArray( | 996 Handle<FixedArray> Factory::CopyAndTenureFixedCOWArray( |
986 Handle<FixedArray> array) { | 997 Handle<FixedArray> array) { |
987 ASSERT(isolate()->heap()->InNewSpace(*array)); | 998 ASSERT(isolate()->heap()->InNewSpace(*array)); |
988 CALL_HEAP_FUNCTION(isolate(), | 999 CALL_HEAP_FUNCTION(isolate(), |
989 isolate()->heap()->CopyAndTenureFixedCOWArray(*array), | 1000 isolate()->heap()->CopyAndTenureFixedCOWArray(*array), |
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2328 return Handle<Object>::null(); | 2339 return Handle<Object>::null(); |
2329 } | 2340 } |
2330 | 2341 |
2331 | 2342 |
2332 Handle<Object> Factory::ToBoolean(bool value) { | 2343 Handle<Object> Factory::ToBoolean(bool value) { |
2333 return value ? true_value() : false_value(); | 2344 return value ? true_value() : false_value(); |
2334 } | 2345 } |
2335 | 2346 |
2336 | 2347 |
2337 } } // namespace v8::internal | 2348 } } // namespace v8::internal |
OLD | NEW |