diff options
Diffstat (limited to 'js/public/StableStringChars.h')
-rw-r--r-- | js/public/StableStringChars.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/js/public/StableStringChars.h b/js/public/StableStringChars.h index 5c50df18cb..84429041da 100644 --- a/js/public/StableStringChars.h +++ b/js/public/StableStringChars.h @@ -53,10 +53,15 @@ class MOZ_STACK_CLASS JS_PUBLIC_API AutoStableStringChars final { const char16_t* twoByteChars_; const Latin1Char* latin1Chars_; }; + MOZ_INIT_OUTSIDE_CTOR uint32_t length_; mozilla::Maybe<js::Vector<uint8_t, InlineCapacity>> ownChars_; enum State { Uninitialized, Latin1, TwoByte }; State state_; + // Prevent the string that owns s's chars from being collected (by storing it + // in s_) or deduplicated. + void holdStableChars(JSLinearString* s); + public: explicit AutoStableStringChars(JSContext* cx) : s_(cx), state_(Uninitialized) {} @@ -99,7 +104,10 @@ class MOZ_STACK_CLASS JS_PUBLIC_API AutoStableStringChars final { return true; } - size_t length() const { return GetStringLength(s_); } + size_t length() const { + MOZ_ASSERT(state_ != Uninitialized); + return length_; + } private: AutoStableStringChars(const AutoStableStringChars& other) = delete; |