#pragma once
#include "JSString.h"
namespace JSC {
inline JSString::~JSString()
{
if (isRope())
return;
valueInternal().~String();
}
bool JSString::equal(JSGlobalObject* globalObject, JSString* other) const
{
if (isRope() || other->isRope())
return equalSlowCase(globalObject, other);
return WTF::equal(*valueInternal().impl(), *other->valueInternal().impl());
}
template<typename StringType>
inline JSValue jsMakeNontrivialString(VM& vm, StringType&& string)
{
return jsNontrivialString(vm, std::forward<StringType>(string));
}
template<typename StringType, typename... StringTypes>
inline JSValue jsMakeNontrivialString(JSGlobalObject* globalObject, StringType&& string, StringTypes&&... strings)
{
VM& vm = getVM(globalObject);
auto scope = DECLARE_THROW_SCOPE(vm);
String result = tryMakeString(std::forward<StringType>(string), std::forward<StringTypes>(strings)...);
if (UNLIKELY(!result))
return throwOutOfMemoryError(globalObject, scope);
ASSERT(result.length() <= JSString::MaxLength);
return jsNontrivialString(vm, WTFMove(result));
}
template <typename CharacterType>
inline JSString* repeatCharacter(JSGlobalObject* globalObject, CharacterType character, unsigned repeatCount)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
CharacterType* buffer = nullptr;
auto impl = StringImpl::tryCreateUninitialized(repeatCount, buffer);
if (!impl) {
throwOutOfMemoryError(globalObject, scope);
return nullptr;
}
std::fill_n(buffer, repeatCount, character);
RELEASE_AND_RETURN(scope, jsString(vm, WTFMove(impl)));
}
}