When parsing TemplateLiteral in TaggedTemplateExpression, we should not throw SyntaxError.

* Set value as undefined when there is SyntaxError
* Fix memory leak related with throwing esprima::Error

Signed-off-by: Seonghyun Kim <sh8281.kim@samsung.com>
This commit is contained in:
Seonghyun Kim 2020-05-27 16:44:06 +09:00 committed by Hyukwoo Park
commit 39e10484d7
9 changed files with 194 additions and 123 deletions

View file

@ -285,14 +285,15 @@ ScriptParser::InitializeScriptResult ScriptParser::initializeScript(StringView s
result.script = script;
return result;
} catch (esprima::Error& orgError) {
} catch (esprima::Error* orgError) {
// reset ASTAllocator
m_context->astAllocator().reset();
GC_enable();
ScriptParser::InitializeScriptResult result;
result.parseErrorCode = orgError.errorCode;
result.parseErrorMessage = orgError.message;
result.parseErrorCode = orgError->errorCode;
result.parseErrorMessage = orgError->message;
delete orgError;
return result;
}
}
@ -311,12 +312,14 @@ void ScriptParser::generateFunctionByteCode(ExecutionState& state, InterpretedCo
// Parsing
try {
functionNode = esprima::parseSingleFunction(m_context, codeBlock, scopeContext, stackSizeRemain);
} catch (esprima::Error& orgError) {
} catch (esprima::Error* orgError) {
// reset ASTAllocator
m_context->astAllocator().reset();
GC_enable();
ErrorObject::throwBuiltinError(state, ErrorObject::SyntaxError, orgError.message->toUTF8StringData().data());
auto str = orgError->message->toUTF8StringData();
delete orgError;
ErrorObject::throwBuiltinError(state, ErrorObject::SyntaxError, str.data());
RELEASE_ASSERT_NOT_REACHED();
}