/*
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2014 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#include "CallFrame.h"
#include "CommonIdentifiers.h"
#include "Identifier.h"
-#include "JSNumberCell.h"
#include "PropertyDescriptor.h"
#include "PropertySlot.h"
-#include "RopeImpl.h"
+#include "Structure.h"
+#include <array>
+#include <wtf/text/StringView.h>
namespace JSC {
- class JSString;
+class JSString;
+class JSRopeString;
+class LLIntOffsetsExtractor;
+
+JSString* jsEmptyString(VM*);
+JSString* jsEmptyString(ExecState*);
+JSString* jsString(VM*, const String&); // returns empty string if passed null string
+JSString* jsString(ExecState*, const String&); // returns empty string if passed null string
+
+JSString* jsSingleCharacterString(VM*, UChar);
+JSString* jsSingleCharacterString(ExecState*, UChar);
+JSString* jsSubstring(VM*, const String&, unsigned offset, unsigned length);
+JSString* jsSubstring(ExecState*, const String&, unsigned offset, unsigned length);
+JSString* jsSubstring8(VM*, const String&, unsigned offset, unsigned length);
+JSString* jsSubstring8(ExecState*, const String&, unsigned offset, unsigned length);
+
+// Non-trivial strings are two or more characters long.
+// These functions are faster than just calling jsString.
+JSString* jsNontrivialString(VM*, const String&);
+JSString* jsNontrivialString(ExecState*, const String&);
+JSString* jsNontrivialString(ExecState*, String&&);
+
+// Should be used for strings that are owned by an object that will
+// likely outlive the JSValue this makes, such as the parse tree or a
+// DOM object that contains a String
+JSString* jsOwnedString(VM*, const String&);
+JSString* jsOwnedString(ExecState*, const String&);
+
+JSRopeString* jsStringBuilder(VM*);
+
+bool isJSString(JSValue);
+JSString* asString(JSValue);
+
+struct StringViewWithUnderlyingString {
+ StringView view;
+ String underlyingString;
+};
+
+class JSString : public JSCell {
+public:
+ friend class JIT;
+ friend class VM;
+ friend class SpecializedThunkJIT;
+ friend class JSRopeString;
+ friend class MarkStack;
+ friend class SlotVisitor;
+ friend struct ThunkHelpers;
+
+ typedef JSCell Base;
+ static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | StructureIsImmortal;
+
+ static const bool needsDestruction = true;
+ static void destroy(JSCell*);
+
+private:
+ JSString(VM& vm, PassRefPtr<StringImpl> value)
+ : JSCell(vm, vm.stringStructure.get())
+ , m_flags(0)
+ , m_value(value)
+ {
+ }
- JSString* jsEmptyString(JSGlobalData*);
- JSString* jsEmptyString(ExecState*);
- JSString* jsString(JSGlobalData*, const UString&); // returns empty string if passed null string
- JSString* jsString(ExecState*, const UString&); // returns empty string if passed null string
+ JSString(VM& vm)
+ : JSCell(vm, vm.stringStructure.get())
+ , m_flags(0)
+ {
+ }
- JSString* jsSingleCharacterString(JSGlobalData*, UChar);
- JSString* jsSingleCharacterString(ExecState*, UChar);
- JSString* jsSingleCharacterSubstring(ExecState*, const UString&, unsigned offset);
- JSString* jsSubstring(JSGlobalData*, const UString&, unsigned offset, unsigned length);
- JSString* jsSubstring(ExecState*, const UString&, unsigned offset, unsigned length);
+ void finishCreation(VM& vm, size_t length)
+ {
+ ASSERT(!m_value.isNull());
+ Base::finishCreation(vm);
+ m_length = length;
+ setIs8Bit(m_value.impl()->is8Bit());
+ vm.m_newStringsSinceLastHashCons++;
+ }
- // Non-trivial strings are two or more characters long.
- // These functions are faster than just calling jsString.
- JSString* jsNontrivialString(JSGlobalData*, const UString&);
- JSString* jsNontrivialString(ExecState*, const UString&);
- JSString* jsNontrivialString(JSGlobalData*, const char*);
- JSString* jsNontrivialString(ExecState*, const char*);
+ void finishCreation(VM& vm, size_t length, size_t cost)
+ {
+ ASSERT(!m_value.isNull());
+ Base::finishCreation(vm);
+ m_length = length;
+ setIs8Bit(m_value.impl()->is8Bit());
+ Heap::heap(this)->reportExtraMemoryAllocated(cost);
+ vm.m_newStringsSinceLastHashCons++;
+ }
- // Should be used for strings that are owned by an object that will
- // likely outlive the JSValue this makes, such as the parse tree or a
- // DOM object that contains a UString
- JSString* jsOwnedString(JSGlobalData*, const UString&);
- JSString* jsOwnedString(ExecState*, const UString&);
+protected:
+ void finishCreation(VM& vm)
+ {
+ Base::finishCreation(vm);
+ m_length = 0;
+ setIs8Bit(true);
+ vm.m_newStringsSinceLastHashCons++;
+ }
- typedef void (*JSStringFinalizerCallback)(JSString*, void* context);
- JSString* jsStringWithFinalizer(ExecState*, const UString&, JSStringFinalizerCallback callback, void* context);
+public:
+ static JSString* create(VM& vm, PassRefPtr<StringImpl> value)
+ {
+ ASSERT(value);
+ int32_t length = value->length();
+ RELEASE_ASSERT(length >= 0);
+ size_t cost = value->cost();
+ JSString* newString = new (NotNull, allocateCell<JSString>(vm.heap)) JSString(vm, value);
+ newString->finishCreation(vm, length, cost);
+ return newString;
+ }
+ static JSString* createHasOtherOwner(VM& vm, PassRefPtr<StringImpl> value)
+ {
+ ASSERT(value);
+ size_t length = value->length();
+ JSString* newString = new (NotNull, allocateCell<JSString>(vm.heap)) JSString(vm, value);
+ newString->finishCreation(vm, length);
+ return newString;
+ }
- class JS_EXPORTCLASS JSString : public JSCell {
- public:
- friend class JIT;
- friend class JSGlobalData;
- friend class SpecializedThunkJIT;
- friend struct ThunkHelpers;
-
- class RopeBuilder {
- public:
- RopeBuilder(unsigned fiberCount)
- : m_index(0)
- , m_rope(RopeImpl::tryCreateUninitialized(fiberCount))
- {
- }
+ Identifier toIdentifier(ExecState*) const;
+ AtomicString toAtomicString(ExecState*) const;
+ RefPtr<AtomicStringImpl> toExistingAtomicString(ExecState*) const;
- bool isOutOfMemory() { return !m_rope; }
+ class SafeView;
+ SafeView view(ExecState*) const;
+ StringViewWithUnderlyingString viewWithUnderlyingString(ExecState&) const;
- void append(RopeImpl::Fiber& fiber)
- {
- ASSERT(m_rope);
- m_rope->initializeFiber(m_index, fiber);
- }
- void append(const UString& string)
- {
- ASSERT(m_rope);
- m_rope->initializeFiber(m_index, string.rep());
- }
- void append(JSString* jsString)
- {
- if (jsString->isRope()) {
- for (unsigned i = 0; i < jsString->m_fiberCount; ++i)
- append(jsString->m_other.m_fibers[i]);
- } else
- append(jsString->string());
- }
+ const String& value(ExecState*) const;
+ const String& tryGetValue() const;
+ const StringImpl* tryGetValueImpl() const;
+ unsigned length() const { return m_length; }
- PassRefPtr<RopeImpl> release()
- {
- ASSERT(m_index == m_rope->fiberCount());
- return m_rope.release();
- }
+ JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
+ bool toBoolean() const { return !!m_length; }
+ bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
+ JSObject* toObject(ExecState*, JSGlobalObject*) const;
+ double toNumber(ExecState*) const;
- unsigned length() { return m_rope->length(); }
-
- private:
- unsigned m_index;
- RefPtr<RopeImpl> m_rope;
- };
-
- class RopeIterator {
- public:
- RopeIterator() { }
-
- RopeIterator(RopeImpl::Fiber* fibers, size_t fiberCount)
- {
- ASSERT(fiberCount);
- m_workQueue.append(WorkItem(fibers, fiberCount));
- skipRopes();
- }
-
- RopeIterator& operator++()
- {
- WorkItem& item = m_workQueue.last();
- ASSERT(!RopeImpl::isRope(item.fibers[item.i]));
- if (++item.i == item.fiberCount)
- m_workQueue.removeLast();
- skipRopes();
- return *this;
- }
-
- UStringImpl* operator*()
- {
- WorkItem& item = m_workQueue.last();
- RopeImpl::Fiber fiber = item.fibers[item.i];
- ASSERT(!RopeImpl::isRope(fiber));
- return static_cast<UStringImpl*>(fiber);
- }
-
- bool operator!=(const RopeIterator& other) const
- {
- return m_workQueue != other.m_workQueue;
- }
-
- private:
- struct WorkItem {
- WorkItem(RopeImpl::Fiber* fibers, size_t fiberCount)
- : fibers(fibers)
- , fiberCount(fiberCount)
- , i(0)
- {
- }
-
- bool operator!=(const WorkItem& other) const
- {
- return fibers != other.fibers || fiberCount != other.fiberCount || i != other.i;
- }
-
- RopeImpl::Fiber* fibers;
- size_t fiberCount;
- size_t i;
- };
-
- void skipRopes()
- {
- if (m_workQueue.isEmpty())
- return;
-
- while (1) {
- WorkItem& item = m_workQueue.last();
- RopeImpl::Fiber fiber = item.fibers[item.i];
- if (!RopeImpl::isRope(fiber))
- break;
- RopeImpl* rope = static_cast<RopeImpl*>(fiber);
- if (++item.i == item.fiberCount)
- m_workQueue.removeLast();
- m_workQueue.append(WorkItem(rope->fibers(), rope->fiberCount()));
- }
- }
-
- Vector<WorkItem, 16> m_workQueue;
- };
-
- ALWAYS_INLINE JSString(JSGlobalData* globalData, const UString& value)
- : JSCell(globalData->stringStructure.get())
- , m_length(value.size())
- , m_value(value)
- , m_fiberCount(0)
- {
- ASSERT(!m_value.isNull());
- Heap::heap(this)->reportExtraMemoryCost(value.cost());
- }
+ bool getStringPropertySlot(ExecState*, PropertyName, PropertySlot&);
+ bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
+ bool getStringPropertyDescriptor(ExecState*, PropertyName, PropertyDescriptor&);
- enum HasOtherOwnerType { HasOtherOwner };
- JSString(JSGlobalData* globalData, const UString& value, HasOtherOwnerType)
- : JSCell(globalData->stringStructure.get())
- , m_length(value.size())
- , m_value(value)
- , m_fiberCount(0)
- {
- ASSERT(!m_value.isNull());
- }
- JSString(JSGlobalData* globalData, PassRefPtr<UStringImpl> value, HasOtherOwnerType)
- : JSCell(globalData->stringStructure.get())
- , m_length(value->length())
- , m_value(value)
- , m_fiberCount(0)
- {
- ASSERT(!m_value.isNull());
- }
- JSString(JSGlobalData* globalData, PassRefPtr<RopeImpl> rope)
- : JSCell(globalData->stringStructure.get())
- , m_length(rope->length())
- , m_fiberCount(1)
- {
- m_other.m_fibers[0] = rope.releaseRef();
- }
- // This constructor constructs a new string by concatenating s1 & s2.
- // This should only be called with fiberCount <= 3.
- JSString(JSGlobalData* globalData, unsigned fiberCount, JSString* s1, JSString* s2)
- : JSCell(globalData->stringStructure.get())
- , m_length(s1->length() + s2->length())
- , m_fiberCount(fiberCount)
- {
- ASSERT(fiberCount <= s_maxInternalRopeLength);
- unsigned index = 0;
- appendStringInConstruct(index, s1);
- appendStringInConstruct(index, s2);
- ASSERT(fiberCount == index);
- }
- // This constructor constructs a new string by concatenating s1 & s2.
- // This should only be called with fiberCount <= 3.
- JSString(JSGlobalData* globalData, unsigned fiberCount, JSString* s1, const UString& u2)
- : JSCell(globalData->stringStructure.get())
- , m_length(s1->length() + u2.size())
- , m_fiberCount(fiberCount)
- {
- ASSERT(fiberCount <= s_maxInternalRopeLength);
- unsigned index = 0;
- appendStringInConstruct(index, s1);
- appendStringInConstruct(index, u2);
- ASSERT(fiberCount == index);
- }
- // This constructor constructs a new string by concatenating s1 & s2.
- // This should only be called with fiberCount <= 3.
- JSString(JSGlobalData* globalData, unsigned fiberCount, const UString& u1, JSString* s2)
- : JSCell(globalData->stringStructure.get())
- , m_length(u1.size() + s2->length())
- , m_fiberCount(fiberCount)
- {
- ASSERT(fiberCount <= s_maxInternalRopeLength);
- unsigned index = 0;
- appendStringInConstruct(index, u1);
- appendStringInConstruct(index, s2);
- ASSERT(fiberCount == index);
- }
- // This constructor constructs a new string by concatenating v1, v2 & v3.
- // This should only be called with fiberCount <= 3 ... which since every
- // value must require a fiberCount of at least one implies that the length
- // for each value must be exactly 1!
- JSString(ExecState* exec, JSValue v1, JSValue v2, JSValue v3)
- : JSCell(exec->globalData().stringStructure.get())
- , m_length(0)
- , m_fiberCount(s_maxInternalRopeLength)
- {
- unsigned index = 0;
- appendValueInConstructAndIncrementLength(exec, index, v1);
- appendValueInConstructAndIncrementLength(exec, index, v2);
- appendValueInConstructAndIncrementLength(exec, index, v3);
- ASSERT(index == s_maxInternalRopeLength);
- }
+ bool canGetIndex(unsigned i) { return i < m_length; }
+ JSString* getIndex(ExecState*, unsigned);
- // This constructor constructs a new string by concatenating u1 & u2.
- JSString(JSGlobalData* globalData, const UString& u1, const UString& u2)
- : JSCell(globalData->stringStructure.get())
- , m_length(u1.size() + u2.size())
- , m_fiberCount(2)
- {
- unsigned index = 0;
- appendStringInConstruct(index, u1);
- appendStringInConstruct(index, u2);
- ASSERT(index <= s_maxInternalRopeLength);
- }
+ static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
+ {
+ return Structure::create(vm, globalObject, proto, TypeInfo(StringType, StructureFlags), info());
+ }
- // This constructor constructs a new string by concatenating u1, u2 & u3.
- JSString(JSGlobalData* globalData, const UString& u1, const UString& u2, const UString& u3)
- : JSCell(globalData->stringStructure.get())
- , m_length(u1.size() + u2.size() + u3.size())
- , m_fiberCount(s_maxInternalRopeLength)
- {
- unsigned index = 0;
- appendStringInConstruct(index, u1);
- appendStringInConstruct(index, u2);
- appendStringInConstruct(index, u3);
- ASSERT(index <= s_maxInternalRopeLength);
- }
+ static size_t offsetOfLength() { return OBJECT_OFFSETOF(JSString, m_length); }
+ static size_t offsetOfFlags() { return OBJECT_OFFSETOF(JSString, m_flags); }
+ static size_t offsetOfValue() { return OBJECT_OFFSETOF(JSString, m_value); }
- JSString(JSGlobalData* globalData, const UString& value, JSStringFinalizerCallback finalizer, void* context)
- : JSCell(globalData->stringStructure.get())
- , m_length(value.size())
- , m_value(value)
- , m_fiberCount(0)
- {
- ASSERT(!m_value.isNull());
- // nasty hack because we can't union non-POD types
- m_other.m_finalizerCallback = finalizer;
- m_other.m_finalizerContext = context;
- Heap::heap(this)->reportExtraMemoryCost(value.cost());
- }
+ DECLARE_EXPORT_INFO;
- ~JSString()
- {
- ASSERT(vptr() == JSGlobalData::jsStringVPtr);
- for (unsigned i = 0; i < m_fiberCount; ++i)
- RopeImpl::deref(m_other.m_fibers[i]);
+ static void dumpToStream(const JSCell*, PrintStream&);
+ static void visitChildren(JSCell*, SlotVisitor&);
- if (!m_fiberCount && m_other.m_finalizerCallback)
- m_other.m_finalizerCallback(this, m_other.m_finalizerContext);
- }
+ enum {
+ HashConsLock = 1u << 2,
+ IsHashConsSingleton = 1u << 1,
+ Is8Bit = 1u
+ };
- const UString& value(ExecState* exec) const
- {
- if (isRope())
- resolveRope(exec);
- return m_value;
- }
- const UString& tryGetValue() const
- {
- if (isRope())
- resolveRope(0);
- return m_value;
- }
- unsigned length() { return m_length; }
+protected:
+ friend class JSValue;
- bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
- bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
- bool getStringPropertyDescriptor(ExecState*, const Identifier& propertyName, PropertyDescriptor&);
+ bool isRope() const { return m_value.isNull(); }
+ bool isSubstring() const;
+ bool is8Bit() const { return m_flags & Is8Bit; }
+ void setIs8Bit(bool flag) const
+ {
+ if (flag)
+ m_flags |= Is8Bit;
+ else
+ m_flags &= ~Is8Bit;
+ }
+ bool shouldTryHashCons();
+ bool isHashConsSingleton() const { return m_flags & IsHashConsSingleton; }
+ void clearHashConsSingleton() { m_flags &= ~IsHashConsSingleton; }
+ void setHashConsSingleton() { m_flags |= IsHashConsSingleton; }
+ bool tryHashConsLock();
+ void releaseHashConsLock();
- bool canGetIndex(unsigned i) { return i < m_length; }
- JSString* getIndex(ExecState*, unsigned);
- JSString* getIndexSlowCase(ExecState*, unsigned);
+ mutable unsigned m_flags;
- JSValue replaceCharacter(ExecState*, UChar, const UString& replacement);
+ // A string is represented either by a String or a rope of fibers.
+ unsigned m_length;
+ mutable String m_value;
- static PassRefPtr<Structure> createStructure(JSValue proto) { return Structure::create(proto, TypeInfo(StringType, OverridesGetOwnPropertySlot | NeedsThisConversion), AnonymousSlotCount); }
+private:
+ friend class LLIntOffsetsExtractor;
- private:
- enum VPtrStealingHackType { VPtrStealingHack };
- JSString(VPtrStealingHackType)
- : JSCell(0)
- , m_fiberCount(0)
- {
- }
+ static JSValue toThis(JSCell*, ExecState*, ECMAMode);
+
+ String& string() { ASSERT(!isRope()); return m_value; }
+ StringView unsafeView(ExecState&) const;
+
+ friend JSValue jsString(ExecState*, JSString*, JSString*);
+ friend JSString* jsSubstring(ExecState*, JSString*, unsigned offset, unsigned length);
+};
+
+class JSRopeString final : public JSString {
+ friend class JSString;
- void resolveRope(ExecState*) const;
- JSString* substringFromRope(ExecState*, unsigned offset, unsigned length);
+ friend JSRopeString* jsStringBuilder(VM*);
- void appendStringInConstruct(unsigned& index, const UString& string)
+public:
+ class RopeBuilder {
+ public:
+ RopeBuilder(VM& vm)
+ : m_vm(vm)
+ , m_jsString(jsStringBuilder(&vm))
+ , m_index(0)
{
- UStringImpl* impl = string.rep();
- impl->ref();
- m_other.m_fibers[index++] = impl;
}
- void appendStringInConstruct(unsigned& index, JSString* jsString)
+ bool append(JSString* jsString)
{
- if (jsString->isRope()) {
- for (unsigned i = 0; i < jsString->m_fiberCount; ++i) {
- RopeImpl::Fiber fiber = jsString->m_other.m_fibers[i];
- fiber->ref();
- m_other.m_fibers[index++] = fiber;
- }
- } else
- appendStringInConstruct(index, jsString->string());
+ if (m_index == JSRopeString::s_maxInternalRopeLength)
+ expand();
+ if (static_cast<int32_t>(m_jsString->length() + jsString->length()) < 0) {
+ m_jsString = nullptr;
+ return false;
+ }
+ m_jsString->append(m_vm, m_index++, jsString);
+ return true;
}
- void appendValueInConstructAndIncrementLength(ExecState* exec, unsigned& index, JSValue v)
+ JSRopeString* release()
{
- if (v.isString()) {
- ASSERT(asCell(v)->isString());
- JSString* s = static_cast<JSString*>(asCell(v));
- ASSERT(s->size() == 1);
- appendStringInConstruct(index, s);
- m_length += s->length();
- } else {
- UString u(v.toString(exec));
- UStringImpl* impl = u.rep();
- impl->ref();
- m_other.m_fibers[index++] = impl;
- m_length += u.size();
- }
+ RELEASE_ASSERT(m_jsString);
+ JSRopeString* tmp = m_jsString;
+ m_jsString = 0;
+ return tmp;
}
- virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
- virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
- virtual bool toBoolean(ExecState*) const;
- virtual double toNumber(ExecState*) const;
- virtual JSObject* toObject(ExecState*) const;
- virtual UString toString(ExecState*) const;
-
- virtual JSObject* toThisObject(ExecState*) const;
-
- // Actually getPropertySlot, not getOwnPropertySlot (see JSCell).
- virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
- virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
- virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
-
- static const unsigned s_maxInternalRopeLength = 3;
-
- // A string is represented either by a UString or a RopeImpl.
- unsigned m_length;
- mutable UString m_value;
- mutable unsigned m_fiberCount;
- // This structure exists to support a temporary workaround for a GC issue.
- struct JSStringFinalizerStruct {
- JSStringFinalizerStruct() : m_finalizerCallback(0) {}
- union {
- mutable RopeImpl::Fiber m_fibers[s_maxInternalRopeLength];
- struct {
- JSStringFinalizerCallback m_finalizerCallback;
- void* m_finalizerContext;
- };
- };
- } m_other;
-
- bool isRope() const { return m_fiberCount; }
- UString& string() { ASSERT(!isRope()); return m_value; }
- unsigned size() { return m_fiberCount ? m_fiberCount : 1; }
-
- friend JSValue jsString(ExecState* exec, JSString* s1, JSString* s2);
- friend JSValue jsString(ExecState* exec, const UString& u1, JSString* s2);
- friend JSValue jsString(ExecState* exec, JSString* s1, const UString& u2);
- friend JSValue jsString(ExecState* exec, Register* strings, unsigned count);
- friend JSValue jsString(ExecState* exec, JSValue thisValue, const ArgList& args);
- friend JSString* jsStringWithFinalizer(ExecState*, const UString&, JSStringFinalizerCallback callback, void* context);
- friend JSString* jsSubstring(ExecState* exec, JSString* s, unsigned offset, unsigned length);
+ unsigned length() const { return m_jsString->m_length; }
+
+ private:
+ void expand();
+
+ VM& m_vm;
+ JSRopeString* m_jsString;
+ size_t m_index;
};
- JSString* asString(JSValue);
+private:
+ JSRopeString(VM& vm)
+ : JSString(vm)
+ {
+ }
- // When an object is created from a different DLL, MSVC changes vptr to a "local" one right after invoking a constructor,
- // see <http://groups.google.com/group/microsoft.public.vc.language/msg/55cdcefeaf770212>.
- // This breaks isJSString(), and we don't need that hack anyway, so we change vptr back to primary one.
- // The below function must be called by any inline function that invokes a JSString constructor.
-#if COMPILER(MSVC) && !defined(BUILDING_JavaScriptCore)
- inline JSString* fixupVPtr(JSGlobalData* globalData, JSString* string) { string->setVPtr(globalData->jsStringVPtr); return string; }
-#else
- inline JSString* fixupVPtr(JSGlobalData*, JSString* string) { return string; }
-#endif
+ void finishCreation(VM& vm, JSString* s1, JSString* s2)
+ {
+ Base::finishCreation(vm);
+ m_length = s1->length() + s2->length();
+ setIs8Bit(s1->is8Bit() && s2->is8Bit());
+ setIsSubstring(false);
+ fiber(0).set(vm, this, s1);
+ fiber(1).set(vm, this, s2);
+ fiber(2).clear();
+ }
- inline JSString* asString(JSValue value)
+ void finishCreation(VM& vm, JSString* s1, JSString* s2, JSString* s3)
{
- ASSERT(asCell(value)->isString());
- return static_cast<JSString*>(asCell(value));
+ Base::finishCreation(vm);
+ m_length = s1->length() + s2->length() + s3->length();
+ setIs8Bit(s1->is8Bit() && s2->is8Bit() && s3->is8Bit());
+ setIsSubstring(false);
+ fiber(0).set(vm, this, s1);
+ fiber(1).set(vm, this, s2);
+ fiber(2).set(vm, this, s3);
}
- inline JSString* jsEmptyString(JSGlobalData* globalData)
+ void finishCreation(ExecState& exec, JSString& base, unsigned offset, unsigned length)
{
- return globalData->smallStrings.emptyString(globalData);
+ VM& vm = exec.vm();
+ Base::finishCreation(vm);
+ ASSERT(!sumOverflows<int32_t>(offset, length));
+ ASSERT(offset + length <= base.length());
+ m_length = length;
+ setIs8Bit(base.is8Bit());
+ setIsSubstring(true);
+ if (base.isSubstring()) {
+ JSRopeString& baseRope = static_cast<JSRopeString&>(base);
+ substringBase().set(vm, this, baseRope.substringBase().get());
+ substringOffset() = baseRope.substringOffset() + offset;
+ } else {
+ substringBase().set(vm, this, &base);
+ substringOffset() = offset;
+
+ // For now, let's not allow substrings with a rope base.
+ // Resolve non-substring rope bases so we don't have to deal with it.
+ // FIXME: Evaluate if this would be worth adding more branches.
+ if (base.isRope())
+ static_cast<JSRopeString&>(base).resolveRope(&exec);
+ }
}
- inline JSString* jsSingleCharacterString(JSGlobalData* globalData, UChar c)
+ void finishCreation(VM& vm)
{
- if (c <= 0xFF)
- return globalData->smallStrings.singleCharacterString(globalData, c);
- return fixupVPtr(globalData, new (globalData) JSString(globalData, UString(&c, 1)));
+ JSString::finishCreation(vm);
+ setIsSubstring(false);
+ fiber(0).clear();
+ fiber(1).clear();
+ fiber(2).clear();
}
- inline JSString* jsSingleCharacterSubstring(ExecState* exec, const UString& s, unsigned offset)
+ void append(VM& vm, size_t index, JSString* jsString)
{
- JSGlobalData* globalData = &exec->globalData();
- ASSERT(offset < static_cast<unsigned>(s.size()));
- UChar c = s.data()[offset];
- if (c <= 0xFF)
- return globalData->smallStrings.singleCharacterString(globalData, c);
- return fixupVPtr(globalData, new (globalData) JSString(globalData, UString(UStringImpl::create(s.rep(), offset, 1))));
+ fiber(index).set(vm, this, jsString);
+ m_length += jsString->m_length;
+ RELEASE_ASSERT(static_cast<int32_t>(m_length) >= 0);
+ setIs8Bit(is8Bit() && jsString->is8Bit());
}
- inline JSString* jsNontrivialString(JSGlobalData* globalData, const char* s)
+ static JSRopeString* createNull(VM& vm)
{
- ASSERT(s);
- ASSERT(s[0]);
- ASSERT(s[1]);
- return fixupVPtr(globalData, new (globalData) JSString(globalData, s));
+ JSRopeString* newString = new (NotNull, allocateCell<JSRopeString>(vm.heap)) JSRopeString(vm);
+ newString->finishCreation(vm);
+ return newString;
}
- inline JSString* jsNontrivialString(JSGlobalData* globalData, const UString& s)
+public:
+ static JSString* create(VM& vm, JSString* s1, JSString* s2)
+ {
+ JSRopeString* newString = new (NotNull, allocateCell<JSRopeString>(vm.heap)) JSRopeString(vm);
+ newString->finishCreation(vm, s1, s2);
+ return newString;
+ }
+ static JSString* create(VM& vm, JSString* s1, JSString* s2, JSString* s3)
{
- ASSERT(s.size() > 1);
- return fixupVPtr(globalData, new (globalData) JSString(globalData, s));
+ JSRopeString* newString = new (NotNull, allocateCell<JSRopeString>(vm.heap)) JSRopeString(vm);
+ newString->finishCreation(vm, s1, s2, s3);
+ return newString;
}
- inline JSString* JSString::getIndex(ExecState* exec, unsigned i)
+ static JSString* create(ExecState& exec, JSString& base, unsigned offset, unsigned length)
{
- ASSERT(canGetIndex(i));
- if (isRope())
- return getIndexSlowCase(exec, i);
- ASSERT(i < m_value.size());
- return jsSingleCharacterSubstring(exec, m_value, i);
+ JSRopeString* newString = new (NotNull, allocateCell<JSRopeString>(exec.vm().heap)) JSRopeString(exec.vm());
+ newString->finishCreation(exec, base, offset, length);
+ return newString;
}
- inline JSString* jsString(JSGlobalData* globalData, const UString& s)
+ void visitFibers(SlotVisitor&);
+
+ static ptrdiff_t offsetOfFibers() { return OBJECT_OFFSETOF(JSRopeString, u); }
+
+ static const unsigned s_maxInternalRopeLength = 3;
+
+private:
+ friend JSValue jsStringFromRegisterArray(ExecState*, Register*, unsigned);
+ friend JSValue jsStringFromArguments(ExecState*, JSValue);
+
+ JS_EXPORT_PRIVATE void resolveRope(ExecState*) const;
+ JS_EXPORT_PRIVATE void resolveRopeToAtomicString(ExecState*) const;
+ JS_EXPORT_PRIVATE RefPtr<AtomicStringImpl> resolveRopeToExistingAtomicString(ExecState*) const;
+ void resolveRopeSlowCase8(LChar*) const;
+ void resolveRopeSlowCase(UChar*) const;
+ void outOfMemory(ExecState*) const;
+ void resolveRopeInternal8(LChar*) const;
+ void resolveRopeInternal8NoSubstring(LChar*) const;
+ void resolveRopeInternal16(UChar*) const;
+ void resolveRopeInternal16NoSubstring(UChar*) const;
+ void clearFibers() const;
+ StringView unsafeView(ExecState&) const;
+ StringViewWithUnderlyingString viewWithUnderlyingString(ExecState&) const;
+
+ WriteBarrierBase<JSString>& fiber(unsigned i) const
{
- int size = s.size();
- if (!size)
- return globalData->smallStrings.emptyString(globalData);
- if (size == 1) {
- UChar c = s.data()[0];
- if (c <= 0xFF)
- return globalData->smallStrings.singleCharacterString(globalData, c);
- }
- return fixupVPtr(globalData, new (globalData) JSString(globalData, s));
+ ASSERT(!isSubstring());
+ ASSERT(i < s_maxInternalRopeLength);
+ return u[i].string;
}
- inline JSString* jsStringWithFinalizer(ExecState* exec, const UString& s, JSStringFinalizerCallback callback, void* context)
+ WriteBarrierBase<JSString>& substringBase() const
{
- ASSERT(s.size() && (s.size() > 1 || s.data()[0] > 0xFF));
- JSGlobalData* globalData = &exec->globalData();
- return fixupVPtr(globalData, new (globalData) JSString(globalData, s, callback, context));
+ return u[1].string;
}
-
- inline JSString* jsSubstring(ExecState* exec, JSString* s, unsigned offset, unsigned length)
+
+ uintptr_t& substringOffset() const
{
- ASSERT(offset <= static_cast<unsigned>(s->length()));
- ASSERT(length <= static_cast<unsigned>(s->length()));
- ASSERT(offset + length <= static_cast<unsigned>(s->length()));
- JSGlobalData* globalData = &exec->globalData();
- if (!length)
- return globalData->smallStrings.emptyString(globalData);
- if (s->isRope())
- return s->substringFromRope(exec, offset, length);
- return jsSubstring(globalData, s->m_value, offset, length);
- }
-
- inline JSString* jsSubstring(JSGlobalData* globalData, const UString& s, unsigned offset, unsigned length)
+ return u[2].number;
+ }
+
+ static uintptr_t notSubstringSentinel()
{
- ASSERT(offset <= static_cast<unsigned>(s.size()));
- ASSERT(length <= static_cast<unsigned>(s.size()));
- ASSERT(offset + length <= static_cast<unsigned>(s.size()));
- if (!length)
- return globalData->smallStrings.emptyString(globalData);
- if (length == 1) {
- UChar c = s.data()[offset];
- if (c <= 0xFF)
- return globalData->smallStrings.singleCharacterString(globalData, c);
- }
- return fixupVPtr(globalData, new (globalData) JSString(globalData, UString(UStringImpl::create(s.rep(), offset, length)), JSString::HasOtherOwner));
+ return 0;
}
- inline JSString* jsOwnedString(JSGlobalData* globalData, const UString& s)
+ static uintptr_t substringSentinel()
{
- int size = s.size();
- if (!size)
- return globalData->smallStrings.emptyString(globalData);
- if (size == 1) {
- UChar c = s.data()[0];
- if (c <= 0xFF)
- return globalData->smallStrings.singleCharacterString(globalData, c);
- }
- return fixupVPtr(globalData, new (globalData) JSString(globalData, s, JSString::HasOtherOwner));
+ return 1;
}
- inline JSString* jsEmptyString(ExecState* exec) { return jsEmptyString(&exec->globalData()); }
- inline JSString* jsString(ExecState* exec, const UString& s) { return jsString(&exec->globalData(), s); }
- inline JSString* jsSingleCharacterString(ExecState* exec, UChar c) { return jsSingleCharacterString(&exec->globalData(), c); }
- inline JSString* jsSubstring(ExecState* exec, const UString& s, unsigned offset, unsigned length) { return jsSubstring(&exec->globalData(), s, offset, length); }
- inline JSString* jsNontrivialString(ExecState* exec, const UString& s) { return jsNontrivialString(&exec->globalData(), s); }
- inline JSString* jsNontrivialString(ExecState* exec, const char* s) { return jsNontrivialString(&exec->globalData(), s); }
- inline JSString* jsOwnedString(ExecState* exec, const UString& s) { return jsOwnedString(&exec->globalData(), s); }
+ bool isSubstring() const
+ {
+ return u[0].number == substringSentinel();
+ }
- ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+ void setIsSubstring(bool isSubstring)
{
- if (propertyName == exec->propertyNames().length) {
- slot.setValue(jsNumber(exec, m_length));
- return true;
- }
+ u[0].number = isSubstring ? substringSentinel() : notSubstringSentinel();
+ }
- bool isStrictUInt32;
- unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
- if (isStrictUInt32 && i < m_length) {
- slot.setValue(getIndex(exec, i));
- return true;
- }
+ mutable union {
+ uintptr_t number;
+ WriteBarrierBase<JSString> string;
+ } u[s_maxInternalRopeLength];
+};
+
+class JSString::SafeView {
+public:
+ SafeView();
+ explicit SafeView(ExecState&, const JSString&);
+ operator StringView() const;
+ StringView get() const;
+
+private:
+ ExecState* m_state { nullptr };
+
+ // The following pointer is marked "volatile" to make the compiler leave it on the stack
+ // or in a register as long as this object is alive, even after the last use of the pointer.
+ // That's needed to prevent garbage collecting the string and possibly deleting the block
+ // with the characters in it, and then using the StringView after that.
+ const JSString* volatile m_string { nullptr };
+};
+
+JS_EXPORT_PRIVATE JSString* jsStringWithCacheSlowCase(VM&, StringImpl&);
+
+inline const StringImpl* JSString::tryGetValueImpl() const
+{
+ return m_value.impl();
+}
+
+inline JSString* asString(JSValue value)
+{
+ ASSERT(value.asCell()->isString());
+ return jsCast<JSString*>(value.asCell());
+}
+
+inline JSString* jsEmptyString(VM* vm)
+{
+ return vm->smallStrings.emptyString();
+}
+
+ALWAYS_INLINE JSString* jsSingleCharacterString(VM* vm, UChar c)
+{
+ if (c <= maxSingleCharacterString)
+ return vm->smallStrings.singleCharacterString(c);
+ return JSString::create(*vm, String(&c, 1).impl());
+}
+
+inline JSString* jsNontrivialString(VM* vm, const String& s)
+{
+ ASSERT(s.length() > 1);
+ return JSString::create(*vm, s.impl());
+}
+
+inline JSString* jsNontrivialString(VM* vm, String&& s)
+{
+ ASSERT(s.length() > 1);
+ return JSString::create(*vm, s.releaseImpl());
+}
+
+ALWAYS_INLINE Identifier JSString::toIdentifier(ExecState* exec) const
+{
+ return Identifier::fromString(exec, toAtomicString(exec));
+}
+
+ALWAYS_INLINE AtomicString JSString::toAtomicString(ExecState* exec) const
+{
+ if (isRope())
+ static_cast<const JSRopeString*>(this)->resolveRopeToAtomicString(exec);
+ return AtomicString(m_value);
+}
+
+ALWAYS_INLINE RefPtr<AtomicStringImpl> JSString::toExistingAtomicString(ExecState* exec) const
+{
+ if (isRope())
+ return static_cast<const JSRopeString*>(this)->resolveRopeToExistingAtomicString(exec);
+ if (m_value.impl()->isAtomic())
+ return static_cast<AtomicStringImpl*>(m_value.impl());
+ return AtomicStringImpl::lookUp(m_value.impl());
+}
+
+inline const String& JSString::value(ExecState* exec) const
+{
+ if (isRope())
+ static_cast<const JSRopeString*>(this)->resolveRope(exec);
+ return m_value;
+}
+
+inline const String& JSString::tryGetValue() const
+{
+ if (isRope())
+ static_cast<const JSRopeString*>(this)->resolveRope(0);
+ return m_value;
+}
+
+inline JSString* JSString::getIndex(ExecState* exec, unsigned i)
+{
+ ASSERT(canGetIndex(i));
+ return jsSingleCharacterString(exec, unsafeView(*exec)[i]);
+}
+
+inline JSString* jsString(VM* vm, const String& s)
+{
+ int size = s.length();
+ if (!size)
+ return vm->smallStrings.emptyString();
+ if (size == 1) {
+ UChar c = s.characterAt(0);
+ if (c <= maxSingleCharacterString)
+ return vm->smallStrings.singleCharacterString(c);
+ }
+ return JSString::create(*vm, s.impl());
+}
+
+inline JSString* jsSubstring(ExecState* exec, JSString* s, unsigned offset, unsigned length)
+{
+ ASSERT(offset <= static_cast<unsigned>(s->length()));
+ ASSERT(length <= static_cast<unsigned>(s->length()));
+ ASSERT(offset + length <= static_cast<unsigned>(s->length()));
+ VM& vm = exec->vm();
+ if (!length)
+ return vm.smallStrings.emptyString();
+ if (!offset && length == s->length())
+ return s;
+ return JSRopeString::create(*exec, *s, offset, length);
+}
+
+inline JSString* jsSubstring8(VM* vm, const String& s, unsigned offset, unsigned length)
+{
+ ASSERT(offset <= static_cast<unsigned>(s.length()));
+ ASSERT(length <= static_cast<unsigned>(s.length()));
+ ASSERT(offset + length <= static_cast<unsigned>(s.length()));
+ if (!length)
+ return vm->smallStrings.emptyString();
+ if (length == 1) {
+ UChar c = s.characterAt(offset);
+ if (c <= maxSingleCharacterString)
+ return vm->smallStrings.singleCharacterString(c);
+ }
+ return JSString::createHasOtherOwner(*vm, StringImpl::createSubstringSharingImpl8(s.impl(), offset, length));
+}
+
+inline JSString* jsSubstring(VM* vm, const String& s, unsigned offset, unsigned length)
+{
+ ASSERT(offset <= static_cast<unsigned>(s.length()));
+ ASSERT(length <= static_cast<unsigned>(s.length()));
+ ASSERT(offset + length <= static_cast<unsigned>(s.length()));
+ if (!length)
+ return vm->smallStrings.emptyString();
+ if (length == 1) {
+ UChar c = s.characterAt(offset);
+ if (c <= maxSingleCharacterString)
+ return vm->smallStrings.singleCharacterString(c);
+ }
+ return JSString::createHasOtherOwner(*vm, StringImpl::createSubstringSharingImpl(s.impl(), offset, length));
+}
+
+inline JSString* jsOwnedString(VM* vm, const String& s)
+{
+ int size = s.length();
+ if (!size)
+ return vm->smallStrings.emptyString();
+ if (size == 1) {
+ UChar c = s.characterAt(0);
+ if (c <= maxSingleCharacterString)
+ return vm->smallStrings.singleCharacterString(c);
+ }
+ return JSString::createHasOtherOwner(*vm, s.impl());
+}
+
+inline JSRopeString* jsStringBuilder(VM* vm)
+{
+ return JSRopeString::createNull(*vm);
+}
+
+inline JSString* jsEmptyString(ExecState* exec) { return jsEmptyString(&exec->vm()); }
+inline JSString* jsString(ExecState* exec, const String& s) { return jsString(&exec->vm(), s); }
+inline JSString* jsSingleCharacterString(ExecState* exec, UChar c) { return jsSingleCharacterString(&exec->vm(), c); }
+inline JSString* jsSubstring8(ExecState* exec, const String& s, unsigned offset, unsigned length) { return jsSubstring8(&exec->vm(), s, offset, length); }
+inline JSString* jsSubstring(ExecState* exec, const String& s, unsigned offset, unsigned length) { return jsSubstring(&exec->vm(), s, offset, length); }
+inline JSString* jsNontrivialString(ExecState* exec, const String& s) { return jsNontrivialString(&exec->vm(), s); }
+inline JSString* jsNontrivialString(ExecState* exec, String&& s) { return jsNontrivialString(&exec->vm(), WTF::move(s)); }
+inline JSString* jsOwnedString(ExecState* exec, const String& s) { return jsOwnedString(&exec->vm(), s); }
+
+ALWAYS_INLINE JSString* jsStringWithCache(ExecState* exec, const String& s)
+{
+ VM& vm = exec->vm();
+ StringImpl* stringImpl = s.impl();
+ if (!stringImpl || !stringImpl->length())
+ return jsEmptyString(&vm);
+
+ if (stringImpl->length() == 1) {
+ UChar singleCharacter = (*stringImpl)[0u];
+ if (singleCharacter <= maxSingleCharacterString)
+ return vm.smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter));
+ }
- return false;
+ if (JSString* lastCachedString = vm.lastCachedString.get()) {
+ if (lastCachedString->tryGetValueImpl() == stringImpl)
+ return lastCachedString;
}
-
- ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
- {
- if (propertyName < m_length) {
- slot.setValue(getIndex(exec, propertyName));
- return true;
- }
- return false;
+ return jsStringWithCacheSlowCase(vm, *stringImpl);
+}
+
+ALWAYS_INLINE JSString* jsStringWithCache(ExecState* exec, const AtomicString& s)
+{
+ return jsStringWithCache(exec, s.string());
+}
+
+ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, PropertyName propertyName, PropertySlot& slot)
+{
+ if (propertyName == exec->propertyNames().length) {
+ slot.setValue(this, DontEnum | DontDelete | ReadOnly, jsNumber(m_length));
+ return true;
}
- inline bool isJSString(JSGlobalData* globalData, JSValue v) { return v.isCell() && v.asCell()->vptr() == globalData->jsStringVPtr; }
+ Optional<uint32_t> index = parseIndex(propertyName);
+ if (index && index.value() < m_length) {
+ slot.setValue(this, DontDelete | ReadOnly, getIndex(exec, index.value()));
+ return true;
+ }
- // --- JSValue inlines ----------------------------
+ return false;
+}
- inline UString JSValue::toString(ExecState* exec) const
- {
- if (isString())
- return static_cast<JSString*>(asCell())->value(exec);
- if (isInt32())
- return exec->globalData().numericStrings.add(asInt32());
- if (isDouble())
- return exec->globalData().numericStrings.add(asDouble());
- if (isTrue())
- return "true";
- if (isFalse())
- return "false";
- if (isNull())
- return "null";
- if (isUndefined())
- return "undefined";
- ASSERT(isCell());
- return asCell()->toString(exec);
- }
-
- inline UString JSValue::toPrimitiveString(ExecState* exec) const
- {
- if (isString())
- return static_cast<JSString*>(asCell())->value(exec);
- if (isInt32())
- return exec->globalData().numericStrings.add(asInt32());
- if (isDouble())
- return exec->globalData().numericStrings.add(asDouble());
- if (isTrue())
- return "true";
- if (isFalse())
- return "false";
- if (isNull())
- return "null";
- if (isUndefined())
- return "undefined";
- ASSERT(isCell());
- return asCell()->toPrimitive(exec, NoPreference).toString(exec);
+ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
+{
+ if (propertyName < m_length) {
+ slot.setValue(this, DontDelete | ReadOnly, getIndex(exec, propertyName));
+ return true;
+ }
+
+ return false;
+}
+
+inline bool isJSString(JSValue v)
+{
+ return v.isCell() && v.asCell()->type() == StringType;
+}
+
+ALWAYS_INLINE StringView JSRopeString::unsafeView(ExecState& state) const
+{
+ if (isSubstring()) {
+ if (is8Bit())
+ return StringView(substringBase()->m_value.characters8() + substringOffset(), m_length);
+ return StringView(substringBase()->m_value.characters16() + substringOffset(), m_length);
+ }
+ resolveRope(&state);
+ return m_value;
+}
+
+ALWAYS_INLINE StringViewWithUnderlyingString JSRopeString::viewWithUnderlyingString(ExecState& state) const
+{
+ if (isSubstring()) {
+ auto& base = substringBase()->m_value;
+ if (is8Bit())
+ return { { base.characters8() + substringOffset(), m_length }, base };
+ return { { base.characters16() + substringOffset(), m_length }, base };
}
+ resolveRope(&state);
+ return { m_value, m_value };
+}
+
+ALWAYS_INLINE StringView JSString::unsafeView(ExecState& state) const
+{
+ if (isRope())
+ return static_cast<const JSRopeString*>(this)->unsafeView(state);
+ return m_value;
+}
+
+ALWAYS_INLINE StringViewWithUnderlyingString JSString::viewWithUnderlyingString(ExecState& state) const
+{
+ if (isRope())
+ return static_cast<const JSRopeString&>(*this).viewWithUnderlyingString(state);
+ return { m_value, m_value };
+}
+
+inline bool JSString::isSubstring() const
+{
+ return isRope() && static_cast<const JSRopeString*>(this)->isSubstring();
+}
+
+inline JSString::SafeView::SafeView()
+{
+}
+
+inline JSString::SafeView::SafeView(ExecState& state, const JSString& string)
+ : m_state(&state)
+ , m_string(&string)
+{
+}
+
+inline JSString::SafeView::operator StringView() const
+{
+ return m_string->unsafeView(*m_state);
+}
+
+inline StringView JSString::SafeView::get() const
+{
+ return *this;
+}
+
+ALWAYS_INLINE JSString::SafeView JSString::view(ExecState* exec) const
+{
+ return SafeView(*exec, *this);
+}
+
+// --- JSValue inlines ----------------------------
+
+inline bool JSValue::toBoolean(ExecState* exec) const
+{
+ if (isInt32())
+ return asInt32();
+ if (isDouble())
+ return asDouble() > 0.0 || asDouble() < 0.0; // false for NaN
+ if (isCell())
+ return asCell()->toBoolean(exec);
+ return isTrue(); // false, null, and undefined all convert to false.
+}
+
+inline JSString* JSValue::toString(ExecState* exec) const
+{
+ if (isString())
+ return jsCast<JSString*>(asCell());
+ return toStringSlowCase(exec);
+}
+
+inline String JSValue::toWTFString(ExecState* exec) const
+{
+ if (isString())
+ return static_cast<JSString*>(asCell())->value(exec);
+ return toWTFStringSlowCase(exec);
+}
} // namespace JSC