2017-08-12 16:48:01 +00:00
|
|
|
/*
|
2020-08-29 13:27:11 +00:00
|
|
|
* Copyright (C) 2009-2018 Apple Inc. All rights reserved.
|
2017-08-12 16:48:01 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
|
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "CodeBlock.h"
|
|
|
|
#include "FunctionCodeBlock.h"
|
2020-08-29 13:27:11 +00:00
|
|
|
#include "FunctionOverrides.h"
|
2022-10-23 02:55:20 +00:00
|
|
|
#include "JSCJSValueInlines.h"
|
2017-08-12 16:48:01 +00:00
|
|
|
|
|
|
|
namespace JSC {
|
|
|
|
|
2018-01-03 05:16:05 +00:00
|
|
|
const ClassInfo FunctionExecutable::s_info = { "FunctionExecutable", &ScriptExecutable::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(FunctionExecutable) };
|
2017-08-12 16:48:01 +00:00
|
|
|
|
2022-10-23 02:55:20 +00:00
|
|
|
FunctionExecutable::FunctionExecutable(VM& vm, const SourceCode& source, UnlinkedFunctionExecutable* unlinkedExecutable, Intrinsic intrinsic, bool isInsideOrdinaryFunction)
|
|
|
|
: ScriptExecutable(vm.functionExecutableStructure.get(), vm, source, unlinkedExecutable->isInStrictContext(), unlinkedExecutable->derivedContextType(), false, isInsideOrdinaryFunction || !unlinkedExecutable->isArrowFunction(), EvalContextType::None, intrinsic)
|
2017-08-12 16:48:01 +00:00
|
|
|
, m_unlinkedExecutable(vm, this, unlinkedExecutable)
|
|
|
|
{
|
|
|
|
RELEASE_ASSERT(!source.isNull());
|
|
|
|
ASSERT(source.length());
|
|
|
|
}
|
|
|
|
|
2020-08-29 13:27:11 +00:00
|
|
|
void FunctionExecutable::finishCreation(VM& vm, ScriptExecutable* topLevelExecutable)
|
2017-08-12 16:48:01 +00:00
|
|
|
{
|
|
|
|
Base::finishCreation(vm);
|
2020-08-29 13:27:11 +00:00
|
|
|
m_topLevelExecutable.set(vm, this, topLevelExecutable ? topLevelExecutable : this);
|
2017-08-12 16:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FunctionExecutable::destroy(JSCell* cell)
|
|
|
|
{
|
|
|
|
static_cast<FunctionExecutable*>(cell)->FunctionExecutable::~FunctionExecutable();
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionCodeBlock* FunctionExecutable::baselineCodeBlockFor(CodeSpecializationKind kind)
|
|
|
|
{
|
2020-08-29 13:27:11 +00:00
|
|
|
ExecutableToCodeBlockEdge* edge;
|
2017-08-12 16:48:01 +00:00
|
|
|
if (kind == CodeForCall)
|
2020-08-29 13:27:11 +00:00
|
|
|
edge = m_codeBlockForCall.get();
|
2017-08-12 16:48:01 +00:00
|
|
|
else {
|
|
|
|
RELEASE_ASSERT(kind == CodeForConstruct);
|
2020-08-29 13:27:11 +00:00
|
|
|
edge = m_codeBlockForConstruct.get();
|
2017-08-12 16:48:01 +00:00
|
|
|
}
|
2020-08-29 13:27:11 +00:00
|
|
|
if (!edge)
|
2022-10-23 02:55:20 +00:00
|
|
|
return nullptr;
|
2020-08-29 13:27:11 +00:00
|
|
|
return static_cast<FunctionCodeBlock*>(edge->codeBlock()->baselineAlternative());
|
2017-08-12 16:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FunctionExecutable::visitChildren(JSCell* cell, SlotVisitor& visitor)
|
|
|
|
{
|
|
|
|
FunctionExecutable* thisObject = jsCast<FunctionExecutable*>(cell);
|
|
|
|
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
|
2020-08-29 13:27:11 +00:00
|
|
|
Base::visitChildren(thisObject, visitor);
|
|
|
|
visitor.append(thisObject->m_topLevelExecutable);
|
|
|
|
visitor.append(thisObject->m_codeBlockForCall);
|
|
|
|
visitor.append(thisObject->m_codeBlockForConstruct);
|
2017-08-12 16:48:01 +00:00
|
|
|
visitor.append(thisObject->m_unlinkedExecutable);
|
2020-08-29 13:27:11 +00:00
|
|
|
if (RareData* rareData = thisObject->m_rareData.get()) {
|
|
|
|
visitor.append(rareData->m_cachedPolyProtoStructure);
|
|
|
|
if (TemplateObjectMap* map = rareData->m_templateObjectMap.get()) {
|
|
|
|
auto locker = holdLock(thisObject->cellLock());
|
|
|
|
for (auto& entry : *map)
|
|
|
|
visitor.append(entry.value);
|
|
|
|
}
|
|
|
|
}
|
2017-08-12 16:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FunctionExecutable* FunctionExecutable::fromGlobalCode(
|
2022-10-23 02:55:20 +00:00
|
|
|
const Identifier& name, JSGlobalObject* globalObject, const SourceCode& source,
|
2020-08-29 13:27:11 +00:00
|
|
|
JSObject*& exception, int overrideLineNumber, Optional<int> functionConstructorParametersEndPosition)
|
2017-08-12 16:48:01 +00:00
|
|
|
{
|
|
|
|
UnlinkedFunctionExecutable* unlinkedExecutable =
|
|
|
|
UnlinkedFunctionExecutable::fromGlobalCode(
|
2022-10-23 02:55:20 +00:00
|
|
|
name, globalObject, source, exception, overrideLineNumber, functionConstructorParametersEndPosition);
|
2017-08-12 16:48:01 +00:00
|
|
|
if (!unlinkedExecutable)
|
|
|
|
return nullptr;
|
|
|
|
|
2022-10-23 02:55:20 +00:00
|
|
|
return unlinkedExecutable->link(globalObject->vm(), nullptr, source, overrideLineNumber);
|
2020-08-29 13:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FunctionExecutable::RareData& FunctionExecutable::ensureRareDataSlow()
|
|
|
|
{
|
|
|
|
ASSERT(!m_rareData);
|
2022-10-23 02:55:20 +00:00
|
|
|
auto rareData = makeUnique<RareData>();
|
2020-08-29 13:27:11 +00:00
|
|
|
rareData->m_lineCount = lineCount();
|
|
|
|
rareData->m_endColumn = endColumn();
|
|
|
|
rareData->m_parametersStartOffset = parametersStartOffset();
|
|
|
|
rareData->m_typeProfilingStartOffset = typeProfilingStartOffset();
|
|
|
|
rareData->m_typeProfilingEndOffset = typeProfilingEndOffset();
|
|
|
|
WTF::storeStoreFence();
|
|
|
|
m_rareData = WTFMove(rareData);
|
|
|
|
return *m_rareData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FunctionExecutable::overrideInfo(const FunctionOverrideInfo& overrideInfo)
|
|
|
|
{
|
|
|
|
auto& rareData = ensureRareData();
|
|
|
|
m_source = overrideInfo.sourceCode;
|
|
|
|
rareData.m_lineCount = overrideInfo.lineCount;
|
|
|
|
rareData.m_endColumn = overrideInfo.endColumn;
|
|
|
|
rareData.m_parametersStartOffset = overrideInfo.parametersStartOffset;
|
|
|
|
rareData.m_typeProfilingStartOffset = overrideInfo.typeProfilingStartOffset;
|
|
|
|
rareData.m_typeProfilingEndOffset = overrideInfo.typeProfilingEndOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto FunctionExecutable::ensureTemplateObjectMap(VM&) -> TemplateObjectMap&
|
|
|
|
{
|
|
|
|
RareData& rareData = ensureRareData();
|
|
|
|
return ensureTemplateObjectMapImpl(rareData.m_templateObjectMap);
|
2017-08-12 16:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace JSC
|