| 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 #ifndef V8_FACTORY_H_ | 5 #ifndef V8_FACTORY_H_ |
| 6 #define V8_FACTORY_H_ | 6 #define V8_FACTORY_H_ |
| 7 | 7 |
| 8 #include "src/isolate.h" | 8 #include "src/isolate.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 template<class StringTableKey> | 79 template<class StringTableKey> |
| 80 Handle<String> InternalizeStringWithKey(StringTableKey* key); | 80 Handle<String> InternalizeStringWithKey(StringTableKey* key); |
| 81 | 81 |
| 82 | 82 |
| 83 // String creation functions. Most of the string creation functions take | 83 // String creation functions. Most of the string creation functions take |
| 84 // a Heap::PretenureFlag argument to optionally request that they be | 84 // a Heap::PretenureFlag argument to optionally request that they be |
| 85 // allocated in the old generation. The pretenure flag defaults to | 85 // allocated in the old generation. The pretenure flag defaults to |
| 86 // DONT_TENURE. | 86 // DONT_TENURE. |
| 87 // | 87 // |
| 88 // Creates a new String object. There are two String encodings: ASCII and | 88 // Creates a new String object. There are two String encodings: one-byte and |
| 89 // two byte. One should choose between the three string factory functions | 89 // two-byte. One should choose between the three string factory functions |
| 90 // based on the encoding of the string buffer that the string is | 90 // based on the encoding of the string buffer that the string is |
| 91 // initialized from. | 91 // initialized from. |
| 92 // - ...FromAscii initializes the string from a buffer that is ASCII | 92 // - ...FromOneByte initializes the string from a buffer that is Latin1 |
| 93 // encoded (it does not check that the buffer is ASCII encoded) and | 93 // encoded (it does not check that the buffer is Latin1 encoded) and |
| 94 // the result will be ASCII encoded. | 94 // the result will be Latin1 encoded. |
| 95 // - ...FromUtf8 initializes the string from a buffer that is UTF-8 | 95 // - ...FromUtf8 initializes the string from a buffer that is UTF-8 |
| 96 // encoded. If the characters are all single-byte characters, the | 96 // encoded. If the characters are all ASCII characters, the result |
| 97 // result will be ASCII encoded, otherwise it will converted to two | 97 // will be Latin1 encoded, otherwise it will converted to two-byte. |
| 98 // byte. | 98 // - ...FromTwoByte initializes the string from a buffer that is two-byte |
| 99 // - ...FromTwoByte initializes the string from a buffer that is two | 99 // encoded. If the characters are all Latin1 characters, the result |
| 100 // byte encoded. If the characters are all single-byte characters, | 100 // will be converted to Latin1, otherwise it will be left as two-byte. |
| 101 // the result will be converted to ASCII, otherwise it will be left as | |
| 102 // two byte. | |
| 103 // | 101 // |
| 104 // ASCII strings are pretenured when used as keys in the SourceCodeCache. | 102 // One-byte strings are pretenured when used as keys in the SourceCodeCache. |
| 105 MUST_USE_RESULT MaybeHandle<String> NewStringFromOneByte( | 103 MUST_USE_RESULT MaybeHandle<String> NewStringFromOneByte( |
| 106 Vector<const uint8_t> str, | 104 Vector<const uint8_t> str, |
| 107 PretenureFlag pretenure = NOT_TENURED); | 105 PretenureFlag pretenure = NOT_TENURED); |
| 108 | 106 |
| 109 template<size_t N> | 107 template <size_t N> |
| 110 inline Handle<String> NewStringFromStaticAscii( | 108 inline Handle<String> NewStringFromStaticChars( |
| 111 const char (&str)[N], | 109 const char (&str)[N], PretenureFlag pretenure = NOT_TENURED) { |
| 112 PretenureFlag pretenure = NOT_TENURED) { | |
| 113 DCHECK(N == StrLength(str) + 1); | 110 DCHECK(N == StrLength(str) + 1); |
| 114 return NewStringFromOneByte( | 111 return NewStringFromOneByte(STATIC_CHAR_VECTOR(str), pretenure) |
| 115 STATIC_ASCII_VECTOR(str), pretenure).ToHandleChecked(); | 112 .ToHandleChecked(); |
| 116 } | 113 } |
| 117 | 114 |
| 118 inline Handle<String> NewStringFromAsciiChecked( | 115 inline Handle<String> NewStringFromAsciiChecked( |
| 119 const char* str, | 116 const char* str, |
| 120 PretenureFlag pretenure = NOT_TENURED) { | 117 PretenureFlag pretenure = NOT_TENURED) { |
| 121 return NewStringFromOneByte( | 118 return NewStringFromOneByte( |
| 122 OneByteVector(str), pretenure).ToHandleChecked(); | 119 OneByteVector(str), pretenure).ToHandleChecked(); |
| 123 } | 120 } |
| 124 | 121 |
| 125 | 122 |
| 126 // Allocates and fully initializes a String. There are two String | 123 // Allocates and fully initializes a String. There are two String encodings: |
| 127 // encodings: ASCII and two byte. One should choose between the three string | 124 // one-byte and two-byte. One should choose between the threestring |
| 128 // allocation functions based on the encoding of the string buffer used to | 125 // allocation functions based on the encoding of the string buffer used to |
| 129 // initialized the string. | 126 // initialized the string. |
| 130 // - ...FromAscii initializes the string from a buffer that is ASCII | 127 // - ...FromOneByte initializes the string from a buffer that is Latin1 |
| 131 // encoded (it does not check that the buffer is ASCII encoded) and the | 128 // encoded (it does not check that the buffer is Latin1 encoded) and the |
| 132 // result will be ASCII encoded. | 129 // result will be Latin1 encoded. |
| 133 // - ...FromUTF8 initializes the string from a buffer that is UTF-8 | 130 // - ...FromUTF8 initializes the string from a buffer that is UTF-8 |
| 134 // encoded. If the characters are all single-byte characters, the | 131 // encoded. If the characters are all ASCII characters, the result |
| 135 // result will be ASCII encoded, otherwise it will converted to two | 132 // will be Latin1 encoded, otherwise it will converted to two-byte. |
| 136 // byte. | |
| 137 // - ...FromTwoByte initializes the string from a buffer that is two-byte | 133 // - ...FromTwoByte initializes the string from a buffer that is two-byte |
| 138 // encoded. If the characters are all single-byte characters, the | 134 // encoded. If the characters are all Latin1 characters, the |
| 139 // result will be converted to ASCII, otherwise it will be left as | 135 // result will be converted to Latin1, otherwise it will be left as |
| 140 // two-byte. | 136 // two-byte. |
| 141 | 137 |
| 142 // TODO(dcarney): remove this function. | 138 // TODO(dcarney): remove this function. |
| 143 MUST_USE_RESULT inline MaybeHandle<String> NewStringFromAscii( | 139 MUST_USE_RESULT inline MaybeHandle<String> NewStringFromAscii( |
| 144 Vector<const char> str, | 140 Vector<const char> str, |
| 145 PretenureFlag pretenure = NOT_TENURED) { | 141 PretenureFlag pretenure = NOT_TENURED) { |
| 146 return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure); | 142 return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure); |
| 147 } | 143 } |
| 148 | 144 |
| 149 // UTF8 strings are pretenured when used for regexp literal patterns and | 145 // UTF8 strings are pretenured when used for regexp literal patterns and |
| (...skipping 25 matching lines...) Expand all Loading... |
| 175 uint32_t hash_field); | 171 uint32_t hash_field); |
| 176 | 172 |
| 177 MUST_USE_RESULT Handle<String> NewInternalizedStringImpl( | 173 MUST_USE_RESULT Handle<String> NewInternalizedStringImpl( |
| 178 Handle<String> string, int chars, uint32_t hash_field); | 174 Handle<String> string, int chars, uint32_t hash_field); |
| 179 | 175 |
| 180 // Compute the matching internalized string map for a string if possible. | 176 // Compute the matching internalized string map for a string if possible. |
| 181 // Empty handle is returned if string is in new space or not flattened. | 177 // Empty handle is returned if string is in new space or not flattened. |
| 182 MUST_USE_RESULT MaybeHandle<Map> InternalizedStringMapForString( | 178 MUST_USE_RESULT MaybeHandle<Map> InternalizedStringMapForString( |
| 183 Handle<String> string); | 179 Handle<String> string); |
| 184 | 180 |
| 185 // Allocates and partially initializes an ASCII or TwoByte String. The | 181 // Allocates and partially initializes an one-byte or two-byte String. The |
| 186 // characters of the string are uninitialized. Currently used in regexp code | 182 // characters of the string are uninitialized. Currently used in regexp code |
| 187 // only, where they are pretenured. | 183 // only, where they are pretenured. |
| 188 MUST_USE_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString( | 184 MUST_USE_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString( |
| 189 int length, | 185 int length, |
| 190 PretenureFlag pretenure = NOT_TENURED); | 186 PretenureFlag pretenure = NOT_TENURED); |
| 191 MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString( | 187 MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString( |
| 192 int length, | 188 int length, |
| 193 PretenureFlag pretenure = NOT_TENURED); | 189 PretenureFlag pretenure = NOT_TENURED); |
| 194 | 190 |
| 195 // Creates a single character string where the character has given code. | 191 // Creates a single character string where the character has given code. |
| 196 // A cache is used for ASCII codes. | 192 // A cache is used for Latin1 codes. |
| 197 Handle<String> LookupSingleCharacterStringFromCode(uint32_t code); | 193 Handle<String> LookupSingleCharacterStringFromCode(uint32_t code); |
| 198 | 194 |
| 199 // Create a new cons string object which consists of a pair of strings. | 195 // Create a new cons string object which consists of a pair of strings. |
| 200 MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left, | 196 MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left, |
| 201 Handle<String> right); | 197 Handle<String> right); |
| 202 | 198 |
| 203 // Create a new string object which holds a proper substring of a string. | 199 // Create a new string object which holds a proper substring of a string. |
| 204 Handle<String> NewProperSubString(Handle<String> str, | 200 Handle<String> NewProperSubString(Handle<String> str, |
| 205 int begin, | 201 int begin, |
| 206 int end); | 202 int end); |
| 207 | 203 |
| 208 // Create a new string object which holds a substring of a string. | 204 // Create a new string object which holds a substring of a string. |
| 209 Handle<String> NewSubString(Handle<String> str, int begin, int end) { | 205 Handle<String> NewSubString(Handle<String> str, int begin, int end) { |
| 210 if (begin == 0 && end == str->length()) return str; | 206 if (begin == 0 && end == str->length()) return str; |
| 211 return NewProperSubString(str, begin, end); | 207 return NewProperSubString(str, begin, end); |
| 212 } | 208 } |
| 213 | 209 |
| 214 // Creates a new external String object. There are two String encodings | 210 // Creates a new external String object. There are two String encodings |
| 215 // in the system: ASCII and two byte. Unlike other String types, it does | 211 // in the system: one-byte and two-byte. Unlike other String types, it does |
| 216 // not make sense to have a UTF-8 factory function for external strings, | 212 // not make sense to have a UTF-8 factory function for external strings, |
| 217 // because we cannot change the underlying buffer. Note that these strings | 213 // because we cannot change the underlying buffer. Note that these strings |
| 218 // are backed by a string resource that resides outside the V8 heap. | 214 // are backed by a string resource that resides outside the V8 heap. |
| 219 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromAscii( | 215 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromOneByte( |
| 220 const ExternalAsciiString::Resource* resource); | 216 const ExternalOneByteString::Resource* resource); |
| 221 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromTwoByte( | 217 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromTwoByte( |
| 222 const ExternalTwoByteString::Resource* resource); | 218 const ExternalTwoByteString::Resource* resource); |
| 223 | 219 |
| 224 // Create a symbol. | 220 // Create a symbol. |
| 225 Handle<Symbol> NewSymbol(); | 221 Handle<Symbol> NewSymbol(); |
| 226 Handle<Symbol> NewPrivateSymbol(); | 222 Handle<Symbol> NewPrivateSymbol(); |
| 227 Handle<Symbol> NewPrivateOwnSymbol(); | 223 Handle<Symbol> NewPrivateOwnSymbol(); |
| 228 | 224 |
| 229 // Create a global (but otherwise uninitialized) context. | 225 // Create a global (but otherwise uninitialized) context. |
| 230 Handle<Context> NewNativeContext(); | 226 Handle<Context> NewNativeContext(); |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 // Reinitialize a JSProxy into an (empty) JS object of respective type and | 700 // Reinitialize a JSProxy into an (empty) JS object of respective type and |
| 705 // size, but keeping the original prototype. The receiver must have at least | 701 // size, but keeping the original prototype. The receiver must have at least |
| 706 // the size of the new object. The object is reinitialized and behaves as an | 702 // the size of the new object. The object is reinitialized and behaves as an |
| 707 // object that has been freshly allocated. | 703 // object that has been freshly allocated. |
| 708 void ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, int size); | 704 void ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, int size); |
| 709 }; | 705 }; |
| 710 | 706 |
| 711 } } // namespace v8::internal | 707 } } // namespace v8::internal |
| 712 | 708 |
| 713 #endif // V8_FACTORY_H_ | 709 #endif // V8_FACTORY_H_ |
| OLD | NEW |