Skip to content

Commit

Permalink
Evaluate function declarations in catch statements properly (#54)
Browse files Browse the repository at this point in the history
Fixes #26

Signed-off-by: Robert Sipka <[email protected]>
  • Loading branch information
robertsipka authored and yichoi committed Jan 21, 2019
1 parent 40d4fa4 commit 93c2de5
Showing 1 changed file with 15 additions and 3 deletions.
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

0 comments on commit 93c2de5

Please sign in to comment.