Changeset 186037 in webkit for trunk/Source/JavaScriptCore/runtime/JSString.h
- Timestamp:
- Jun 27, 2015, 3:53:12 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/JSString.h
r185899 r186037 48 48 JSString* jsSubstring(VM*, const String&, unsigned offset, unsigned length); 49 49 JSString* jsSubstring(ExecState*, const String&, unsigned offset, unsigned length); 50 JSString* jsSubstring8(VM*, const String&, unsigned offset, unsigned length); 51 JSString* jsSubstring8(ExecState*, const String&, unsigned offset, unsigned length); 50 52 51 53 // Non-trivial strings are two or more characters long. … … 62 64 63 65 JSRopeString* jsStringBuilder(VM*); 66 67 bool isJSString(JSValue); 68 JSString* asString(JSValue); 64 69 65 70 struct StringViewWithUnderlyingString { … … 149 154 AtomicString toAtomicString(ExecState*) const; 150 155 RefPtr<AtomicStringImpl> toExistingAtomicString(ExecState*) const; 151 StringView view(ExecState*) const; 156 157 class SafeView; 158 SafeView view(ExecState*) const; 152 159 StringViewWithUnderlyingString viewWithUnderlyingString(ExecState&) const; 160 153 161 const String& value(ExecState*) const; 154 162 const String& tryGetValue() const; … … 221 229 222 230 String& string() { ASSERT(!isRope()); return m_value; } 231 StringView unsafeView(ExecState&) const; 223 232 224 233 friend JSValue jsString(ExecState*, JSString*, JSString*); … … 390 399 void resolveRopeInternal16NoSubstring(UChar*) const; 391 400 void clearFibers() const; 392 StringView view(ExecState*) const;401 StringView unsafeView(ExecState&) const; 393 402 StringViewWithUnderlyingString viewWithUnderlyingString(ExecState&) const; 394 403 … … 436 445 }; 437 446 447 class JSString::SafeView { 448 public: 449 SafeView(); 450 explicit SafeView(ExecState&, const JSString&); 451 operator StringView() const; 452 StringView get() const; 453 454 private: 455 ExecState* m_state { nullptr }; 456 457 // The following pointer is marked "volatile" to make the compiler leave it on the stack 458 // or in a register as long as this object is alive, even after the last use of the pointer. 459 // That's needed to prevent garbage collecting the string and possibly deleting the block 460 // with the characters in it, and then using the StringView after that. 461 const JSString* volatile m_string { nullptr }; 462 }; 463 464 JS_EXPORT_PRIVATE JSString* jsStringWithCacheSlowCase(VM&, StringImpl&); 438 465 439 466 inline const StringImpl* JSString::tryGetValueImpl() const … … 441 468 return m_value.impl(); 442 469 } 443 444 JSString* asString(JSValue);445 470 446 471 inline JSString* asString(JSValue value) … … 512 537 { 513 538 ASSERT(canGetIndex(i)); 514 return jsSingleCharacterString(exec, view(exec)[i]);539 return jsSingleCharacterString(exec, unsafeView(*exec)[i]); 515 540 } 516 541 … … 598 623 inline JSString* jsOwnedString(ExecState* exec, const String& s) { return jsOwnedString(&exec->vm(), s); } 599 624 600 JS_EXPORT_PRIVATE JSString* jsStringWithCacheSlowCase(VM&, StringImpl&);601 602 625 ALWAYS_INLINE JSString* jsStringWithCache(ExecState* exec, const String& s) 603 626 { … … 652 675 } 653 676 654 inline bool isJSString(JSValue v) { return v.isCell() && v.asCell()->type() == StringType; } 677 inline bool isJSString(JSValue v) 678 { 679 return v.isCell() && v.asCell()->type() == StringType; 680 } 681 682 ALWAYS_INLINE StringView JSRopeString::unsafeView(ExecState& state) const 683 { 684 if (isSubstring()) { 685 if (is8Bit()) 686 return StringView(substringBase()->m_value.characters8() + substringOffset(), m_length); 687 return StringView(substringBase()->m_value.characters16() + substringOffset(), m_length); 688 } 689 resolveRope(&state); 690 return m_value; 691 } 692 693 ALWAYS_INLINE StringViewWithUnderlyingString JSRopeString::viewWithUnderlyingString(ExecState& state) const 694 { 695 if (isSubstring()) { 696 auto& base = substringBase()->m_value; 697 if (is8Bit()) 698 return { { base.characters8() + substringOffset(), m_length }, base }; 699 return { { base.characters16() + substringOffset(), m_length }, base }; 700 } 701 resolveRope(&state); 702 return { m_value, m_value }; 703 } 704 705 ALWAYS_INLINE StringView JSString::unsafeView(ExecState& state) const 706 { 707 if (isRope()) 708 return static_cast<const JSRopeString*>(this)->unsafeView(state); 709 return m_value; 710 } 711 712 ALWAYS_INLINE StringViewWithUnderlyingString JSString::viewWithUnderlyingString(ExecState& state) const 713 { 714 if (isRope()) 715 return static_cast<const JSRopeString&>(*this).viewWithUnderlyingString(state); 716 return { m_value, m_value }; 717 } 718 719 inline bool JSString::isSubstring() const 720 { 721 return isRope() && static_cast<const JSRopeString*>(this)->isSubstring(); 722 } 723 724 inline JSString::SafeView::SafeView() 725 { 726 } 727 728 inline JSString::SafeView::SafeView(ExecState& state, const JSString& string) 729 : m_state(&state) 730 , m_string(&string) 731 { 732 } 733 734 inline JSString::SafeView::operator StringView() const 735 { 736 return m_string->unsafeView(*m_state); 737 } 738 739 inline StringView JSString::SafeView::get() const 740 { 741 return *this; 742 } 743 744 ALWAYS_INLINE JSString::SafeView JSString::view(ExecState* exec) const 745 { 746 return SafeView(*exec, *this); 747 } 655 748 656 749 // --- JSValue inlines ---------------------------- … … 681 774 } 682 775 683 ALWAYS_INLINE StringView JSRopeString::view(ExecState* exec) const684 {685 if (isSubstring()) {686 if (is8Bit())687 return StringView(substringBase()->m_value.characters8() + substringOffset(), m_length);688 return StringView(substringBase()->m_value.characters16() + substringOffset(), m_length);689 }690 resolveRope(exec);691 return StringView(m_value);692 }693 694 ALWAYS_INLINE StringViewWithUnderlyingString JSRopeString::viewWithUnderlyingString(ExecState& state) const695 {696 if (isSubstring()) {697 auto& base = substringBase()->m_value;698 if (is8Bit())699 return { { base.characters8() + substringOffset(), m_length }, base };700 return { { base.characters16() + substringOffset(), m_length }, base };701 }702 resolveRope(&state);703 return { m_value, m_value };704 }705 706 ALWAYS_INLINE StringView JSString::view(ExecState* exec) const707 {708 if (isRope())709 return static_cast<const JSRopeString*>(this)->view(exec);710 return StringView(m_value);711 }712 713 ALWAYS_INLINE StringViewWithUnderlyingString JSString::viewWithUnderlyingString(ExecState& state) const714 {715 if (isRope())716 return static_cast<const JSRopeString&>(*this).viewWithUnderlyingString(state);717 return { m_value, m_value };718 }719 720 inline bool JSString::isSubstring() const721 {722 return isRope() && static_cast<const JSRopeString*>(this)->isSubstring();723 }724 725 776 } // namespace JSC 726 777
Note:
See TracChangeset
for help on using the changeset viewer.