FunctionExecutable.h [plain text]
#pragma once
#include "ExecutableToCodeBlockEdge.h"
#include "ScriptExecutable.h"
#include "SourceCode.h"
#include <wtf/Box.h>
namespace JSC {
class FunctionExecutable final : public ScriptExecutable {
friend class JIT;
friend class LLIntOffsetsExtractor;
public:
typedef ScriptExecutable Base;
static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
template<typename CellType>
static IsoSubspace* subspaceFor(VM& vm)
{
return &vm.functionExecutableSpace.space;
}
static FunctionExecutable* create(
VM& vm, const SourceCode& source, UnlinkedFunctionExecutable* unlinkedExecutable,
unsigned lastLine, unsigned endColumn, Intrinsic intrinsic)
{
FunctionExecutable* executable = new (NotNull, allocateCell<FunctionExecutable>(vm.heap)) FunctionExecutable(vm, source, unlinkedExecutable, lastLine, endColumn, intrinsic);
executable->finishCreation(vm);
return executable;
}
static FunctionExecutable* fromGlobalCode(
const Identifier& name, ExecState&, const SourceCode&,
JSObject*& exception, int overrideLineNumber);
static void destroy(JSCell*);
UnlinkedFunctionExecutable* unlinkedExecutable() const
{
return m_unlinkedExecutable.get();
}
FunctionCodeBlock* eitherCodeBlock()
{
ExecutableToCodeBlockEdge* edge;
if (m_codeBlockForCall)
edge = m_codeBlockForCall.get();
else
edge = m_codeBlockForConstruct.get();
return bitwise_cast<FunctionCodeBlock*>(ExecutableToCodeBlockEdge::unwrap(edge));
}
bool isGeneratedForCall() const
{
return !!m_codeBlockForCall;
}
FunctionCodeBlock* codeBlockForCall()
{
return bitwise_cast<FunctionCodeBlock*>(ExecutableToCodeBlockEdge::unwrap(m_codeBlockForCall.get()));
}
bool isGeneratedForConstruct() const
{
return !!m_codeBlockForConstruct;
}
FunctionCodeBlock* codeBlockForConstruct()
{
return bitwise_cast<FunctionCodeBlock*>(ExecutableToCodeBlockEdge::unwrap(m_codeBlockForConstruct.get()));
}
bool isGeneratedFor(CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return isGeneratedForCall();
ASSERT(kind == CodeForConstruct);
return isGeneratedForConstruct();
}
FunctionCodeBlock* codeBlockFor(CodeSpecializationKind kind)
{
if (kind == CodeForCall)
return codeBlockForCall();
ASSERT(kind == CodeForConstruct);
return codeBlockForConstruct();
}
FunctionCodeBlock* baselineCodeBlockFor(CodeSpecializationKind);
FunctionCodeBlock* profiledCodeBlockFor(CodeSpecializationKind kind)
{
return baselineCodeBlockFor(kind);
}
RefPtr<TypeSet> returnStatementTypeSet()
{
if (!m_returnStatementTypeSet)
m_returnStatementTypeSet = TypeSet::create();
return m_returnStatementTypeSet;
}
FunctionMode functionMode() { return m_unlinkedExecutable->functionMode(); }
bool isBuiltinFunction() const { return m_unlinkedExecutable->isBuiltinFunction(); }
ConstructAbility constructAbility() const { return m_unlinkedExecutable->constructAbility(); }
bool isClass() const { return !classSource().isNull(); }
bool isArrowFunction() const { return parseMode() == SourceParseMode::ArrowFunctionMode; }
bool isGetter() const { return parseMode() == SourceParseMode::GetterMode; }
bool isSetter() const { return parseMode() == SourceParseMode::SetterMode; }
bool isGenerator() const { return isGeneratorParseMode(parseMode()); }
bool isAsyncGenerator() const { return SourceParseModeSet(SourceParseMode::AsyncGeneratorWrapperFunctionMode, SourceParseMode::AsyncGeneratorBodyMode).contains(parseMode()); }
bool isMethod() const { return parseMode() == SourceParseMode::MethodMode; }
bool hasCallerAndArgumentsProperties() const
{
return !isStrictMode() && parseMode() == SourceParseMode::NormalFunctionMode && !isClassConstructorFunction();
}
bool hasPrototypeProperty() const
{
return SourceParseModeSet(
SourceParseMode::NormalFunctionMode,
SourceParseMode::GeneratorBodyMode,
SourceParseMode::GeneratorWrapperFunctionMode,
SourceParseMode::GeneratorWrapperMethodMode,
SourceParseMode::AsyncGeneratorWrapperFunctionMode,
SourceParseMode::AsyncGeneratorBodyMode
).contains(parseMode()) || isClass();
}
DerivedContextType derivedContextType() const { return m_unlinkedExecutable->derivedContextType(); }
bool isClassConstructorFunction() const { return m_unlinkedExecutable->isClassConstructorFunction(); }
const Identifier& name() { return m_unlinkedExecutable->name(); }
const Identifier& ecmaName() { return m_unlinkedExecutable->ecmaName(); }
const Identifier& inferredName() { return m_unlinkedExecutable->inferredName(); }
unsigned parameterCount() const { return m_unlinkedExecutable->parameterCount(); } SourceParseMode parseMode() const { return m_unlinkedExecutable->parseMode(); }
JSParserScriptMode scriptMode() const { return m_unlinkedExecutable->scriptMode(); }
const SourceCode& classSource() const { return m_unlinkedExecutable->classSource(); }
static void visitChildren(JSCell*, SlotVisitor&);
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
{
return Structure::create(vm, globalObject, proto, TypeInfo(FunctionExecutableType, StructureFlags), info());
}
unsigned parametersStartOffset() const { return m_parametersStartOffset; }
void overrideParameterAndTypeProfilingStartEndOffsets(unsigned parametersStartOffset, unsigned typeProfilingStartOffset, unsigned typeProfilingEndOffset)
{
m_parametersStartOffset = parametersStartOffset;
m_typeProfilingStartOffset = typeProfilingStartOffset;
m_typeProfilingEndOffset = typeProfilingEndOffset;
}
DECLARE_INFO;
InferredValue* singletonFunction() { return m_singletonFunction.get(); }
Structure* cachedPolyProtoStructure() { return m_cachedPolyProtoStructure.get(); }
void setCachedPolyProtoStructure(VM& vm, Structure* structure) { m_cachedPolyProtoStructure.set(vm, this, structure); }
InlineWatchpointSet& ensurePolyProtoWatchpoint()
{
if (!m_polyProtoWatchpoint)
m_polyProtoWatchpoint = Box<InlineWatchpointSet>::create(IsWatched);
return *m_polyProtoWatchpoint;
}
Box<InlineWatchpointSet> sharedPolyProtoWatchpoint() const { return m_polyProtoWatchpoint; }
private:
friend class ExecutableBase;
FunctionExecutable(
VM&, const SourceCode&, UnlinkedFunctionExecutable*,
unsigned lastLine, unsigned endColumn, Intrinsic);
void finishCreation(VM&);
friend class ScriptExecutable;
unsigned m_parametersStartOffset;
WriteBarrier<UnlinkedFunctionExecutable> m_unlinkedExecutable;
WriteBarrier<ExecutableToCodeBlockEdge> m_codeBlockForCall;
WriteBarrier<ExecutableToCodeBlockEdge> m_codeBlockForConstruct;
RefPtr<TypeSet> m_returnStatementTypeSet;
WriteBarrier<InferredValue> m_singletonFunction;
WriteBarrier<Structure> m_cachedPolyProtoStructure;
Box<InlineWatchpointSet> m_polyProtoWatchpoint;
};
}