InternalFunction.h [plain text]
#pragma once
#include "CodeSpecializationKind.h"
#include "JSDestructibleObject.h"
namespace JSC {
class FunctionPrototype;
class InternalFunction : public JSNonFinalObject {
friend class JIT;
friend class LLIntOffsetsExtractor;
public:
using Base = JSNonFinalObject;
static constexpr unsigned StructureFlags = Base::StructureFlags | ImplementsHasInstance | ImplementsDefaultHasInstance | OverridesGetCallData;
template<typename CellType, SubspaceAccess>
static IsoSubspace* subspaceFor(VM& vm)
{
static_assert(sizeof(CellType) == sizeof(InternalFunction), "InternalFunction subclasses that add fields need to override subspaceFor<>()");
return &vm.internalFunctionSpace;
}
DECLARE_EXPORT_INFO;
JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
JS_EXPORT_PRIVATE const String& name();
const String displayName(VM&);
const String calculatedDisplayName(VM&);
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
{
return Structure::create(vm, globalObject, proto, TypeInfo(InternalFunctionType, StructureFlags), info());
}
JS_EXPORT_PRIVATE static Structure* createSubclassStructure(JSGlobalObject*, JSObject* newTarget, Structure*);
JS_EXPORT_PRIVATE static InternalFunction* createFunctionThatMasqueradesAsUndefined(VM&, JSGlobalObject*, unsigned length, const String& name, NativeFunction);
TaggedNativeFunction nativeFunctionFor(CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return m_functionForCall;
ASSERT(kind == CodeForConstruct);
return m_functionForConstruct;
}
static ptrdiff_t offsetOfNativeFunctionFor(CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return OBJECT_OFFSETOF(InternalFunction, m_functionForCall);
ASSERT(kind == CodeForConstruct);
return OBJECT_OFFSETOF(InternalFunction, m_functionForConstruct);
}
static ptrdiff_t offsetOfGlobalObject()
{
return OBJECT_OFFSETOF(InternalFunction, m_globalObject);
}
JSGlobalObject* globalObject() const { return m_globalObject.get(); }
protected:
JS_EXPORT_PRIVATE InternalFunction(VM&, Structure*, NativeFunction functionForCall, NativeFunction functionForConstruct = nullptr);
enum class PropertyAdditionMode { WithStructureTransition, WithoutStructureTransition };
JS_EXPORT_PRIVATE void finishCreation(VM&, unsigned length, const String& name, PropertyAdditionMode = PropertyAdditionMode::WithStructureTransition);
JS_EXPORT_PRIVATE static CallData getConstructData(JSCell*);
JS_EXPORT_PRIVATE static CallData getCallData(JSCell*);
TaggedNativeFunction m_functionForCall;
TaggedNativeFunction m_functionForConstruct;
WriteBarrier<JSString> m_originalName;
WriteBarrier<JSGlobalObject> m_globalObject;
};
JS_EXPORT_PRIVATE JSGlobalObject* getFunctionRealm(VM&, JSObject*);
}