OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 5771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5782 inline explicit StringShape(InstanceType t); | 5782 inline explicit StringShape(InstanceType t); |
5783 inline bool IsSequential(); | 5783 inline bool IsSequential(); |
5784 inline bool IsExternal(); | 5784 inline bool IsExternal(); |
5785 inline bool IsCons(); | 5785 inline bool IsCons(); |
5786 inline bool IsExternalAscii(); | 5786 inline bool IsExternalAscii(); |
5787 inline bool IsExternalTwoByte(); | 5787 inline bool IsExternalTwoByte(); |
5788 inline bool IsSequentialAscii(); | 5788 inline bool IsSequentialAscii(); |
5789 inline bool IsSequentialTwoByte(); | 5789 inline bool IsSequentialTwoByte(); |
5790 inline bool IsSymbol(); | 5790 inline bool IsSymbol(); |
5791 inline StringRepresentationTag representation_tag(); | 5791 inline StringRepresentationTag representation_tag(); |
| 5792 inline uint32_t encoding_tag(); |
5792 inline uint32_t full_representation_tag(); | 5793 inline uint32_t full_representation_tag(); |
5793 inline uint32_t size_tag(); | 5794 inline uint32_t size_tag(); |
5794 #ifdef DEBUG | 5795 #ifdef DEBUG |
5795 inline uint32_t type() { return type_; } | 5796 inline uint32_t type() { return type_; } |
5796 inline void invalidate() { valid_ = false; } | 5797 inline void invalidate() { valid_ = false; } |
5797 inline bool valid() { return valid_; } | 5798 inline bool valid() { return valid_; } |
5798 #else | 5799 #else |
5799 inline void invalidate() { } | 5800 inline void invalidate() { } |
5800 #endif | 5801 #endif |
5801 | 5802 |
(...skipping 11 matching lines...) Expand all Loading... |
5813 // The String abstract class captures JavaScript string values: | 5814 // The String abstract class captures JavaScript string values: |
5814 // | 5815 // |
5815 // Ecma-262: | 5816 // Ecma-262: |
5816 // 4.3.16 String Value | 5817 // 4.3.16 String Value |
5817 // A string value is a member of the type String and is a finite | 5818 // A string value is a member of the type String and is a finite |
5818 // ordered sequence of zero or more 16-bit unsigned integer values. | 5819 // ordered sequence of zero or more 16-bit unsigned integer values. |
5819 // | 5820 // |
5820 // All string values have a length field. | 5821 // All string values have a length field. |
5821 class String: public HeapObject { | 5822 class String: public HeapObject { |
5822 public: | 5823 public: |
| 5824 // Representation of the flat content of a String. |
| 5825 // A non-flat string doesn't have flat content. |
| 5826 // A flat string has content that's encoded as a sequence of either |
| 5827 // ASCII chars or two-byte UC16. |
| 5828 // Returned by String::GetFlatContent(). |
| 5829 class FlatContent { |
| 5830 public: |
| 5831 // Returns true if the string is flat and this structure contains content. |
| 5832 bool IsFlat() { return state_ != NON_FLAT; } |
| 5833 // Returns true if the structure contains ASCII content. |
| 5834 bool IsAscii() { return state_ == ASCII; } |
| 5835 // Returns true if the structure contains two-byte content. |
| 5836 bool IsTwoByte() { return state_ == TWO_BYTE; } |
| 5837 |
| 5838 // Return the ASCII content of the string. Only use if IsAscii() returns |
| 5839 // true. |
| 5840 Vector<const char> ToAsciiVector() { |
| 5841 ASSERT_EQ(ASCII, state_); |
| 5842 return Vector<const char>::cast(buffer_); |
| 5843 } |
| 5844 // Return the two-byte content of the string. Only use if IsTwoByte() |
| 5845 // returns true. |
| 5846 Vector<const uc16> ToUC16Vector() { |
| 5847 ASSERT_EQ(TWO_BYTE, state_); |
| 5848 return Vector<const uc16>::cast(buffer_); |
| 5849 } |
| 5850 |
| 5851 private: |
| 5852 enum State { NON_FLAT, ASCII, TWO_BYTE }; |
| 5853 |
| 5854 // Constructors only used by String::GetFlatContent(). |
| 5855 explicit FlatContent(Vector<const char> chars) |
| 5856 : buffer_(Vector<const byte>::cast(chars)), |
| 5857 state_(ASCII) { } |
| 5858 explicit FlatContent(Vector<const uc16> chars) |
| 5859 : buffer_(Vector<const byte>::cast(chars)), |
| 5860 state_(TWO_BYTE) { } |
| 5861 FlatContent() : buffer_(), state_(NON_FLAT) { } |
| 5862 |
| 5863 Vector<const byte> buffer_; |
| 5864 State state_; |
| 5865 |
| 5866 friend class String; |
| 5867 }; |
| 5868 |
5823 // Get and set the length of the string. | 5869 // Get and set the length of the string. |
5824 inline int length(); | 5870 inline int length(); |
5825 inline void set_length(int value); | 5871 inline void set_length(int value); |
5826 | 5872 |
5827 // Get and set the hash field of the string. | 5873 // Get and set the hash field of the string. |
5828 inline uint32_t hash_field(); | 5874 inline uint32_t hash_field(); |
5829 inline void set_hash_field(uint32_t value); | 5875 inline void set_hash_field(uint32_t value); |
5830 | 5876 |
5831 inline bool IsAsciiRepresentation(); | 5877 inline bool IsAsciiRepresentation(); |
5832 inline bool IsTwoByteRepresentation(); | 5878 inline bool IsTwoByteRepresentation(); |
5833 | 5879 |
5834 // Returns whether this string has ascii chars, i.e. all of them can | 5880 // Returns whether this string has only ASCII chars, i.e. all of them can |
5835 // be ascii encoded. This might be the case even if the string is | 5881 // be ASCII encoded. This might be the case even if the string is |
5836 // two-byte. Such strings may appear when the embedder prefers | 5882 // two-byte. Such strings may appear when the embedder prefers |
5837 // two-byte external representations even for ascii data. | 5883 // two-byte external representations even for ASCII data. |
5838 // | 5884 // |
5839 // NOTE: this should be considered only a hint. False negatives are | 5885 // NOTE: this should be considered only a hint. False negatives are |
5840 // possible. | 5886 // possible. |
5841 inline bool HasOnlyAsciiChars(); | 5887 inline bool HasOnlyAsciiChars(); |
5842 | 5888 |
5843 // Get and set individual two byte chars in the string. | 5889 // Get and set individual two byte chars in the string. |
5844 inline void Set(int index, uint16_t value); | 5890 inline void Set(int index, uint16_t value); |
5845 // Get individual two byte char in the string. Repeated calls | 5891 // Get individual two byte char in the string. Repeated calls |
5846 // to this method are not efficient unless the string is flat. | 5892 // to this method are not efficient unless the string is flat. |
5847 inline uint16_t Get(int index); | 5893 inline uint16_t Get(int index); |
(...skipping 13 matching lines...) Expand all Loading... |
5861 // | 5907 // |
5862 // Use FlattenString from Handles.cc to flatten even in case an | 5908 // Use FlattenString from Handles.cc to flatten even in case an |
5863 // allocation failure happens. | 5909 // allocation failure happens. |
5864 inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); | 5910 inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
5865 | 5911 |
5866 // Convenience function. Has exactly the same behavior as | 5912 // Convenience function. Has exactly the same behavior as |
5867 // TryFlatten(), except in the case of failure returns the original | 5913 // TryFlatten(), except in the case of failure returns the original |
5868 // string. | 5914 // string. |
5869 inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); | 5915 inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
5870 | 5916 |
5871 Vector<const char> ToAsciiVector(); | 5917 // Tries to return the content of a flat string as a structure holding either |
5872 Vector<const uc16> ToUC16Vector(); | 5918 // a flat vector of char or of uc16. |
| 5919 // If the string isn't flat, and therefore doesn't have flat content, the |
| 5920 // returned structure will report so, and can't provide a vector of either |
| 5921 // kind. |
| 5922 FlatContent GetFlatContent(const AssertNoAllocation& safety_promise); |
5873 | 5923 |
5874 // Mark the string as an undetectable object. It only applies to | 5924 // Mark the string as an undetectable object. It only applies to |
5875 // ascii and two byte string types. | 5925 // ascii and two byte string types. |
5876 bool MarkAsUndetectable(); | 5926 bool MarkAsUndetectable(); |
5877 | 5927 |
5878 // Return a substring. | 5928 // Return a substring. |
5879 MUST_USE_RESULT MaybeObject* SubString(int from, | 5929 MUST_USE_RESULT MaybeObject* SubString(int from, |
5880 int to, | 5930 int to, |
5881 PretenureFlag pretenure = NOT_TENURED); | 5931 PretenureFlag pretenure = NOT_TENURED); |
5882 | 5932 |
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7313 } else { | 7363 } else { |
7314 value &= ~(1 << bit_position); | 7364 value &= ~(1 << bit_position); |
7315 } | 7365 } |
7316 return value; | 7366 return value; |
7317 } | 7367 } |
7318 }; | 7368 }; |
7319 | 7369 |
7320 } } // namespace v8::internal | 7370 } } // namespace v8::internal |
7321 | 7371 |
7322 #endif // V8_OBJECTS_H_ | 7372 #endif // V8_OBJECTS_H_ |
OLD | NEW |