Chromium Code Reviews| 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 class FlatContent { | |
| 5825 public: | |
| 5826 explicit FlatContent(Vector<const char> chars) | |
| 5827 : buffer_(Vector<const byte>::cast(chars)), | |
| 5828 state_(ASCII) { } | |
| 5829 explicit FlatContent(Vector<const uc16> chars) | |
| 5830 : buffer_(Vector<const byte>::cast(chars)), | |
| 5831 state_(TWO_BYTE) { } | |
| 5832 FlatContent() : buffer_(), state_(NON_FLAT) { } | |
| 5833 | |
| 5834 bool IsFlat() { return state_ != NON_FLAT; } | |
| 5835 bool IsAscii() { return state_ == ASCII; } | |
| 5836 bool IsTwoByte() { return state_ == TWO_BYTE; } | |
| 5837 | |
| 5838 Vector<const char> ToAsciiVector() { | |
| 5839 ASSERT_EQ(ASCII, state_); | |
| 5840 return Vector<const char>::cast(buffer_); | |
| 5841 } | |
| 5842 Vector<const uc16> ToUC16Vector() { | |
| 5843 ASSERT_EQ(TWO_BYTE, state_); | |
| 5844 return Vector<const uc16>::cast(buffer_); | |
| 5845 } | |
| 5846 | |
| 5847 private: | |
| 5848 enum State { NON_FLAT, ASCII, TWO_BYTE }; | |
| 5849 Vector<const byte> buffer_; | |
| 5850 State state_; | |
| 5851 }; | |
| 5852 | |
| 5823 // Get and set the length of the string. | 5853 // Get and set the length of the string. |
| 5824 inline int length(); | 5854 inline int length(); |
| 5825 inline void set_length(int value); | 5855 inline void set_length(int value); |
| 5826 | 5856 |
| 5827 // Get and set the hash field of the string. | 5857 // Get and set the hash field of the string. |
| 5828 inline uint32_t hash_field(); | 5858 inline uint32_t hash_field(); |
| 5829 inline void set_hash_field(uint32_t value); | 5859 inline void set_hash_field(uint32_t value); |
| 5830 | 5860 |
| 5831 inline bool IsAsciiRepresentation(); | 5861 inline bool IsAsciiRepresentation(); |
| 5832 inline bool IsTwoByteRepresentation(); | 5862 inline bool IsTwoByteRepresentation(); |
| 5833 | 5863 |
| 5834 // Returns whether this string has ascii chars, i.e. all of them can | 5864 // 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 | 5865 // be ASCII encoded. This might be the case even if the string is |
| 5836 // two-byte. Such strings may appear when the embedder prefers | 5866 // two-byte. Such strings may appear when the embedder prefers |
| 5837 // two-byte external representations even for ascii data. | 5867 // two-byte external representations even for ASCII data. |
| 5838 // | 5868 // |
| 5839 // NOTE: this should be considered only a hint. False negatives are | 5869 // NOTE: this should be considered only a hint. False negatives are |
| 5840 // possible. | 5870 // possible. |
| 5841 inline bool HasOnlyAsciiChars(); | 5871 inline bool HasOnlyAsciiChars(); |
| 5842 | 5872 |
| 5843 // Get and set individual two byte chars in the string. | 5873 // Get and set individual two byte chars in the string. |
| 5844 inline void Set(int index, uint16_t value); | 5874 inline void Set(int index, uint16_t value); |
| 5845 // Get individual two byte char in the string. Repeated calls | 5875 // Get individual two byte char in the string. Repeated calls |
| 5846 // to this method are not efficient unless the string is flat. | 5876 // to this method are not efficient unless the string is flat. |
| 5847 inline uint16_t Get(int index); | 5877 inline uint16_t Get(int index); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 5861 // | 5891 // |
| 5862 // Use FlattenString from Handles.cc to flatten even in case an | 5892 // Use FlattenString from Handles.cc to flatten even in case an |
| 5863 // allocation failure happens. | 5893 // allocation failure happens. |
| 5864 inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); | 5894 inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
| 5865 | 5895 |
| 5866 // Convenience function. Has exactly the same behavior as | 5896 // Convenience function. Has exactly the same behavior as |
| 5867 // TryFlatten(), except in the case of failure returns the original | 5897 // TryFlatten(), except in the case of failure returns the original |
| 5868 // string. | 5898 // string. |
| 5869 inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); | 5899 inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| 5870 | 5900 |
| 5871 Vector<const char> ToAsciiVector(); | 5901 FlatContent GetFlatContent(); |
|
Vitaly Repeshko
2011/08/23 10:28:28
This needs some documentation.
A couple of option
Lasse Reichstein
2011/08/23 12:01:55
Absolutely.
| |
| 5872 Vector<const uc16> ToUC16Vector(); | |
| 5873 | 5902 |
| 5874 // Mark the string as an undetectable object. It only applies to | 5903 // Mark the string as an undetectable object. It only applies to |
| 5875 // ascii and two byte string types. | 5904 // ascii and two byte string types. |
| 5876 bool MarkAsUndetectable(); | 5905 bool MarkAsUndetectable(); |
| 5877 | 5906 |
| 5878 // Return a substring. | 5907 // Return a substring. |
| 5879 MUST_USE_RESULT MaybeObject* SubString(int from, | 5908 MUST_USE_RESULT MaybeObject* SubString(int from, |
| 5880 int to, | 5909 int to, |
| 5881 PretenureFlag pretenure = NOT_TENURED); | 5910 PretenureFlag pretenure = NOT_TENURED); |
| 5882 | 5911 |
| (...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7313 } else { | 7342 } else { |
| 7314 value &= ~(1 << bit_position); | 7343 value &= ~(1 << bit_position); |
| 7315 } | 7344 } |
| 7316 return value; | 7345 return value; |
| 7317 } | 7346 } |
| 7318 }; | 7347 }; |
| 7319 | 7348 |
| 7320 } } // namespace v8::internal | 7349 } } // namespace v8::internal |
| 7321 | 7350 |
| 7322 #endif // V8_OBJECTS_H_ | 7351 #endif // V8_OBJECTS_H_ |
| OLD | NEW |