#pragma once
#include "JSFunction.h"
namespace JSC {
JSC_DECLARE_HOST_FUNCTION(boundThisNoArgsFunctionCall);
JSC_DECLARE_HOST_FUNCTION(boundFunctionCall);
JSC_DECLARE_HOST_FUNCTION(boundThisNoArgsFunctionConstruct);
JSC_DECLARE_HOST_FUNCTION(boundFunctionConstruct);
JSC_DECLARE_HOST_FUNCTION(isBoundFunction);
JSC_DECLARE_HOST_FUNCTION(hasInstanceBoundFunction);
class JSBoundFunction final : public JSFunction {
public:
typedef JSFunction Base;
static constexpr unsigned StructureFlags = Base::StructureFlags & ~ImplementsDefaultHasInstance;
static_assert(StructureFlags & ImplementsHasInstance, "");
template<typename CellType, SubspaceAccess mode>
static IsoSubspace* subspaceFor(VM& vm)
{
return vm.boundFunctionSpace<mode>();
}
static JSBoundFunction* create(VM&, JSGlobalObject*, JSObject* targetFunction, JSValue boundThis, JSImmutableButterfly* boundArgs, double length, JSString* nameMayBeNull);
static bool customHasInstance(JSObject*, JSGlobalObject*, JSValue);
JSObject* targetFunction() { return m_targetFunction.get(); }
JSValue boundThis() { return m_boundThis.get(); }
JSImmutableButterfly* boundArgs() { return m_boundArgs.get(); } JSArray* boundArgsCopy(JSGlobalObject*);
JSString* nameMayBeNull() { return m_nameMayBeNull.get(); }
const String& nameString()
{
if (!m_nameMayBeNull)
return emptyString();
ASSERT(!m_nameMayBeNull->isRope());
bool allocationAllowed = false;
return m_nameMayBeNull->tryGetValue(allocationAllowed);
}
double length(VM&) { return m_length; }
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
ASSERT(globalObject);
return Structure::create(vm, globalObject, prototype, TypeInfo(JSFunctionType, StructureFlags), info());
}
static ptrdiff_t offsetOfTargetFunction() { return OBJECT_OFFSETOF(JSBoundFunction, m_targetFunction); }
static ptrdiff_t offsetOfBoundThis() { return OBJECT_OFFSETOF(JSBoundFunction, m_boundThis); }
static ptrdiff_t offsetOfBoundArgs() { return OBJECT_OFFSETOF(JSBoundFunction, m_boundArgs); }
DECLARE_INFO;
private:
JSBoundFunction(VM&, NativeExecutable*, JSGlobalObject*, Structure*, JSObject* targetFunction, JSValue boundThis, JSImmutableButterfly* boundArgs, JSString* nameMayBeNull, double length);
void finishCreation(VM&);
static void visitChildren(JSCell*, SlotVisitor&);
WriteBarrier<JSObject> m_targetFunction;
WriteBarrier<Unknown> m_boundThis;
WriteBarrier<JSImmutableButterfly> m_boundArgs;
WriteBarrier<JSString> m_nameMayBeNull;
double m_length;
};
JSC_DECLARE_HOST_FUNCTION(boundFunctionCall);
JSC_DECLARE_HOST_FUNCTION(boundFunctionConstruct);
JSC_DECLARE_HOST_FUNCTION(boundThisNoArgsFunctionCall);
JSC_DECLARE_HOST_FUNCTION(boundThisNoArgsFunctionConstruct);
}