Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate function declarations in catch statements properly #54

Merged
merged 1 commit into from
Jan 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/runtime/GlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,24 @@ Value GlobalObject::evalLocal(ExecutionState& state, const Value& arg, Value thi
const char* s = "eval input";
ExecutionContext* pec = state.executionContext();
bool isDirectCall = true;
bool callInGlobal = true;
bool isEvalCodeInFunction = false;
bool strictFromOutside = state.inStrictMode();
while (pec) {
if (pec->lexicalEnvironment()->record()->isDeclarativeEnvironmentRecord()) {
strictFromOutside = pec->inStrictMode();
callInGlobal = false;
DeclarativeEnvironmentRecord* record = pec->lexicalEnvironment()->record()->asDeclarativeEnvironmentRecord();
if (record->isEvalTarget()) {
isEvalCodeInFunction = true;
break;
}

LexicalEnvironment* env = pec->lexicalEnvironment();

while (!env->record()->isEvalTarget()) {
env = env->outerEnvironment();
}

isEvalCodeInFunction = !env->record()->isGlobalEnvironmentRecord();
break;
} else if (pec->lexicalEnvironment()->record()->isGlobalEnvironmentRecord()) {
strictFromOutside = pec->inStrictMode();
Expand All @@ -265,7 +277,7 @@ Value GlobalObject::evalLocal(ExecutionState& state, const Value& arg, Value thi
#else
size_t stackRemainApprox = STACK_LIMIT_FROM_BASE - (currentStackBase - state.stackBase());
#endif
ScriptParser::ScriptParserResult parserResult = parser.parse(StringView(arg.asString(), 0, arg.asString()->length()), String::fromUTF8(s, strlen(s)), parentCodeBlock, strictFromOutside, !callInGlobal, stackRemainApprox);
ScriptParser::ScriptParserResult parserResult = parser.parse(StringView(arg.asString(), 0, arg.asString()->length()), String::fromUTF8(s, strlen(s)), parentCodeBlock, strictFromOutside, isEvalCodeInFunction, stackRemainApprox);
if (parserResult.m_error) {
ErrorObject* err = ErrorObject::createError(state, parserResult.m_error->errorCode, parserResult.m_error->message);
state.throwException(err);
Expand Down