Skip to content

Commit

Permalink
Add missing exception check in ScriptExecutable::newCodeBlockFor
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=255259
rdar://107856292

Reviewed by Mark Lam and Yusuke Suzuki.

ModuleProgramExecutable::getUnlinkedCodeBlock can throw runtime errors.
We should handle those.

* Source/JavaScriptCore/runtime/ScriptExecutable.cpp:
(JSC::ScriptExecutable::newCodeBlockFor):

Canonical link: https://commits.webkit.org/262796@main
  • Loading branch information
Yijia Huang committed Apr 11, 2023
1 parent 22c8b78 commit 8b60968
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 2 additions & 3 deletions Source/JavaScriptCore/runtime/ModuleProgramExecutable.cpp
Expand Up @@ -42,7 +42,7 @@ ModuleProgramExecutable::ModuleProgramExecutable(JSGlobalObject* globalObject, c
}


UnlinkedModuleProgramCodeBlock* ModuleProgramExecutable::getUnlinkedCodeBlock(JSGlobalObject* globalObject, PossibleExceptionsExpected possibleExceptionsExpected)
UnlinkedModuleProgramCodeBlock* ModuleProgramExecutable::getUnlinkedCodeBlock(JSGlobalObject* globalObject)
{
VM& vm = globalObject->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
Expand All @@ -59,7 +59,6 @@ UnlinkedModuleProgramCodeBlock* ModuleProgramExecutable::getUnlinkedCodeBlock(JS
globalObject->debugger()->sourceParsed(globalObject, source().provider(), error.line(), error.message());

if (error.isValid()) {
RELEASE_ASSERT(possibleExceptionsExpected == PossibleExceptionsExpected::Yes);
throwVMError(globalObject, throwScope, error.toErrorObject(globalObject, source()));
return nullptr;
}
Expand All @@ -76,7 +75,7 @@ ModuleProgramExecutable* ModuleProgramExecutable::create(JSGlobalObject* globalO
VM& vm = globalObject->vm();
ModuleProgramExecutable* executable = new (NotNull, allocateCell<ModuleProgramExecutable>(vm)) ModuleProgramExecutable(globalObject, source);
executable->finishCreation(vm);
executable->getUnlinkedCodeBlock(globalObject, PossibleExceptionsExpected::Yes); // This generates and binds unlinked code block.
executable->getUnlinkedCodeBlock(globalObject); // This generates and binds unlinked code block.
return executable;
}

Expand Down
3 changes: 1 addition & 2 deletions Source/JavaScriptCore/runtime/ModuleProgramExecutable.h
Expand Up @@ -52,8 +52,7 @@ class ModuleProgramExecutable final : public GlobalExecutable {
return bitwise_cast<ModuleProgramCodeBlock*>(Base::codeBlock());
}

enum class PossibleExceptionsExpected { Yes, No };
UnlinkedModuleProgramCodeBlock* getUnlinkedCodeBlock(JSGlobalObject*, PossibleExceptionsExpected);
UnlinkedModuleProgramCodeBlock* getUnlinkedCodeBlock(JSGlobalObject*);

UnlinkedModuleProgramCodeBlock* unlinkedCodeBlock() const
{
Expand Down
7 changes: 3 additions & 4 deletions Source/JavaScriptCore/runtime/ScriptExecutable.cpp
Expand Up @@ -274,8 +274,8 @@ CodeBlock* ScriptExecutable::newCodeBlockFor(CodeSpecializationKind kind, JSFunc
RELEASE_ASSERT(!executable->m_codeBlock);
RELEASE_ASSERT(!function);

UnlinkedModuleProgramCodeBlock* unlinkedCodeBlock = executable->getUnlinkedCodeBlock(globalObject, ModuleProgramExecutable::PossibleExceptionsExpected::No);
EXCEPTION_ASSERT(!throwScope.exception());
UnlinkedModuleProgramCodeBlock* unlinkedCodeBlock = executable->getUnlinkedCodeBlock(globalObject);
RETURN_IF_EXCEPTION(throwScope, nullptr);
ASSERT(executable->unlinkedCodeBlock());
RELEASE_AND_RETURN(throwScope, ModuleProgramCodeBlock::create(vm, executable, unlinkedCodeBlock, scope));
}
Expand Down Expand Up @@ -303,8 +303,7 @@ CodeBlock* ScriptExecutable::newCodeBlockFor(CodeSpecializationKind kind, JSFunc
executable->m_unlinkedExecutable->features(),
executable->m_unlinkedExecutable->lexicalScopeFeatures(),
executable->m_unlinkedExecutable->hasCapturedVariables(),
lastLine(), endColumn());
// FIXME: We should remove this and add ASSERT(unlinkedCodeBlock).
lastLine(), endColumn());
if (!unlinkedCodeBlock) {
throwException(globalObject, throwScope, error.toErrorObject(globalObject, executable->source()));
return nullptr;
Expand Down

0 comments on commit 8b60968

Please sign in to comment.