#pragma once
#include "JSWrapperObject.h"
#include "JSString.h"
namespace JSC {
class StringObject : public JSWrapperObject {
public:
using Base = JSWrapperObject;
static constexpr unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | OverridesAnyFormOfGetPropertyNames;
template<typename, SubspaceAccess mode>
static IsoSubspace* subspaceFor(VM& vm)
{
return &vm.stringObjectSpace;
}
static StringObject* create(VM& vm, Structure* structure)
{
JSString* string = jsEmptyString(vm);
StringObject* object = new (NotNull, allocateCell<StringObject>(vm.heap)) StringObject(vm, structure);
object->finishCreation(vm, string);
return object;
}
static StringObject* create(VM& vm, Structure* structure, JSString* string)
{
StringObject* object = new (NotNull, allocateCell<StringObject>(vm.heap)) StringObject(vm, structure);
object->finishCreation(vm, string);
return object;
}
static StringObject* create(VM&, JSGlobalObject*, JSString*);
JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, JSGlobalObject*, PropertyName, PropertySlot&);
JS_EXPORT_PRIVATE static bool getOwnPropertySlotByIndex(JSObject*, JSGlobalObject*, unsigned propertyName, PropertySlot&);
JS_EXPORT_PRIVATE static bool put(JSCell*, JSGlobalObject*, PropertyName, JSValue, PutPropertySlot&);
JS_EXPORT_PRIVATE static bool putByIndex(JSCell*, JSGlobalObject*, unsigned propertyName, JSValue, bool shouldThrow);
JS_EXPORT_PRIVATE static bool deleteProperty(JSCell*, JSGlobalObject*, PropertyName, DeletePropertySlot&);
JS_EXPORT_PRIVATE static bool deletePropertyByIndex(JSCell*, JSGlobalObject*, unsigned propertyName);
JS_EXPORT_PRIVATE static void getOwnPropertyNames(JSObject*, JSGlobalObject*, PropertyNameArray&, EnumerationMode);
JS_EXPORT_PRIVATE static void getOwnNonIndexPropertyNames(JSObject*, JSGlobalObject*, PropertyNameArray&, EnumerationMode);
JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, JSGlobalObject*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
static String toStringName(const JSObject*, JSGlobalObject*);
DECLARE_EXPORT_INFO;
JSString* internalValue() const { return asString(JSWrapperObject::internalValue()); }
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(StringObjectType, StructureFlags), info());
}
protected:
JS_EXPORT_PRIVATE void finishCreation(VM&, JSString*);
JS_EXPORT_PRIVATE StringObject(VM&, Structure*);
};
static_assert(sizeof(StringObject) == sizeof(JSWrapperObject));
JS_EXPORT_PRIVATE StringObject* constructString(VM&, JSGlobalObject*, JSValue);
static inline JSString* jsStringWithReuse(JSGlobalObject* globalObject, JSValue originalValue, const String& string)
{
if (originalValue.isString()) {
ASSERT(asString(originalValue)->value(globalObject) == string);
return asString(originalValue);
}
return jsString(getVM(globalObject), string);
}
static inline JSString* jsSubstring(JSGlobalObject* globalObject, JSValue originalValue, const String& string, unsigned offset, unsigned length)
{
if (originalValue.isString()) {
ASSERT(asString(originalValue)->value(globalObject) == string);
return jsSubstring(globalObject, asString(originalValue), offset, length);
}
return jsSubstring(getVM(globalObject), string, offset, length);
}
}