Chromium Code Reviews| 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/factory.h" | 5 #include "src/factory.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
| 9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 813 return slice; | 813 return slice; |
| 814 } | 814 } |
| 815 | 815 |
| 816 | 816 |
| 817 MaybeHandle<String> Factory::NewExternalStringFromOneByte( | 817 MaybeHandle<String> Factory::NewExternalStringFromOneByte( |
| 818 const ExternalOneByteString::Resource* resource) { | 818 const ExternalOneByteString::Resource* resource) { |
| 819 size_t length = resource->length(); | 819 size_t length = resource->length(); |
| 820 if (length > static_cast<size_t>(String::kMaxLength)) { | 820 if (length > static_cast<size_t>(String::kMaxLength)) { |
| 821 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String); | 821 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String); |
| 822 } | 822 } |
| 823 if (length == 0) return empty_string(); | |
|
Jakob Kummerow
2017/02/08 01:41:57
Our public API would be fine with a DCHECK here, b
| |
| 823 | 824 |
| 824 Handle<Map> map; | 825 Handle<Map> map; |
| 825 if (resource->IsCompressible()) { | 826 if (resource->IsCompressible()) { |
| 826 // TODO(hajimehoshi): Rename this to 'uncached_external_one_byte_string_map' | 827 // TODO(hajimehoshi): Rename this to 'uncached_external_one_byte_string_map' |
| 827 map = short_external_one_byte_string_map(); | 828 map = short_external_one_byte_string_map(); |
| 828 } else { | 829 } else { |
| 829 map = external_one_byte_string_map(); | 830 map = external_one_byte_string_map(); |
| 830 } | 831 } |
| 831 Handle<ExternalOneByteString> external_string = | 832 Handle<ExternalOneByteString> external_string = |
| 832 New<ExternalOneByteString>(map, NEW_SPACE); | 833 New<ExternalOneByteString>(map, NEW_SPACE); |
| 833 external_string->set_length(static_cast<int>(length)); | 834 external_string->set_length(static_cast<int>(length)); |
| 834 external_string->set_hash_field(String::kEmptyHashField); | 835 external_string->set_hash_field(String::kEmptyHashField); |
| 835 external_string->set_resource(resource); | 836 external_string->set_resource(resource); |
| 836 | 837 |
| 837 return external_string; | 838 return external_string; |
| 838 } | 839 } |
| 839 | 840 |
| 840 | 841 |
| 841 MaybeHandle<String> Factory::NewExternalStringFromTwoByte( | 842 MaybeHandle<String> Factory::NewExternalStringFromTwoByte( |
| 842 const ExternalTwoByteString::Resource* resource) { | 843 const ExternalTwoByteString::Resource* resource) { |
| 843 size_t length = resource->length(); | 844 size_t length = resource->length(); |
| 844 if (length > static_cast<size_t>(String::kMaxLength)) { | 845 if (length > static_cast<size_t>(String::kMaxLength)) { |
| 845 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String); | 846 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String); |
| 846 } | 847 } |
| 848 if (length == 0) return empty_string(); | |
| 847 | 849 |
| 848 // For small strings we check whether the resource contains only | 850 // For small strings we check whether the resource contains only |
| 849 // one byte characters. If yes, we use a different string map. | 851 // one byte characters. If yes, we use a different string map. |
| 850 static const size_t kOneByteCheckLengthLimit = 32; | 852 static const size_t kOneByteCheckLengthLimit = 32; |
| 851 bool is_one_byte = length <= kOneByteCheckLengthLimit && | 853 bool is_one_byte = length <= kOneByteCheckLengthLimit && |
| 852 String::IsOneByte(resource->data(), static_cast<int>(length)); | 854 String::IsOneByte(resource->data(), static_cast<int>(length)); |
| 853 Handle<Map> map; | 855 Handle<Map> map; |
| 854 if (resource->IsCompressible()) { | 856 if (resource->IsCompressible()) { |
| 855 // TODO(hajimehoshi): Rename these to 'uncached_external_string_...'. | 857 // TODO(hajimehoshi): Rename these to 'uncached_external_string_...'. |
| 856 map = is_one_byte ? short_external_string_with_one_byte_data_map() | 858 map = is_one_byte ? short_external_string_with_one_byte_data_map() |
| (...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2846 Handle<AccessorInfo> prototype = | 2848 Handle<AccessorInfo> prototype = |
| 2847 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); | 2849 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); |
| 2848 Descriptor d = Descriptor::AccessorConstant( | 2850 Descriptor d = Descriptor::AccessorConstant( |
| 2849 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); | 2851 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); |
| 2850 map->AppendDescriptor(&d); | 2852 map->AppendDescriptor(&d); |
| 2851 } | 2853 } |
| 2852 } | 2854 } |
| 2853 | 2855 |
| 2854 } // namespace internal | 2856 } // namespace internal |
| 2855 } // namespace v8 | 2857 } // namespace v8 |
| OLD | NEW |