Skip to content

Commit

Permalink
REGRESSION(273782@main): Missing exception check in commonCallDirectE…
Browse files Browse the repository at this point in the history
…val()

https://bugs.webkit.org/show_bug.cgi?id=268942
<rdar://problem/122493988>

Reviewed by Yusuke Suzuki.

Since eval() may throw an exception, 273782@main moving throwScope.release() to come after it broke
exception scope validation. Also, we would like to avoid calling setUpCall() in case of exception,
reserving it only for indirect eval().

This change adds LLINT_CALL_CHECK_EXCEPTION() to fix both issues, and also makes eval() consistently
return empty JSValue() in case of exception, which is non-observable code tweak.

* Source/JavaScriptCore/interpreter/Interpreter.cpp:
(JSC::eval):
* Source/JavaScriptCore/llint/LLIntSlowPaths.cpp:
(JSC::LLInt::commonCallDirectEval):

Canonical link: https://commits.webkit.org/274264@main
  • Loading branch information
Alexey Shvayka committed Feb 8, 2024
1 parent 142d2a8 commit 0bf3769
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ JSValue eval(CallFrame* callFrame, JSValue thisValue, JSScope* callerScopeChain,
if (!globalObject->evalEnabled()) {
globalObject->globalObjectMethodTable()->reportViolationForUnsafeEval(globalObject, programString);
throwException(globalObject, scope, createEvalError(globalObject, globalObject->evalDisabledErrorMessage()));
return jsUndefined();
return { };
}
String programSource = programString->value(globalObject);
RETURN_IF_EXCEPTION(scope, JSValue());
Expand Down Expand Up @@ -179,7 +179,7 @@ JSValue eval(CallFrame* callFrame, JSValue thisValue, JSScope* callerScopeChain,
eval = DirectEvalExecutable::create(globalObject, makeSource(programSource, callerBaselineCodeBlock->source().provider()->sourceOrigin(), sourceTaintedOrigin), derivedContextType, callerUnlinkedCodeBlock->needsClassFieldInitializer(), callerUnlinkedCodeBlock->privateBrandRequirement(), isArrowFunctionContext, callerBaselineCodeBlock->ownerExecutable()->isInsideOrdinaryFunction(), evalContextType, &variablesUnderTDZ, &privateNameEnvironment, ecmaMode);
EXCEPTION_ASSERT(!!scope.exception() == !eval);
if (!eval)
return jsUndefined();
return { };

// Skip the eval cache if tainted since another eval call could have a different taintedness.
if (sourceTaintedOrigin == SourceTaintedOrigin::Untainted)
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/llint/LLIntSlowPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,7 @@ static inline UGPRPair commonCallDirectEval(CallFrame* callFrame, const JSInstru
JSScope* callerScopeChain = jsCast<JSScope*>(getOperand(callFrame, bytecode.m_scope));
JSValue thisValue = getOperand(callFrame, bytecode.m_thisValue);
JSValue result = eval(calleeFrame, thisValue, callerScopeChain, bytecode.m_ecmaMode);
LLINT_CALL_CHECK_EXCEPTION(globalObject);
if (!result)
RELEASE_AND_RETURN(throwScope, setUpCall(calleeFrame, CodeForCall, calleeAsValue));

Expand Down

0 comments on commit 0bf3769

Please sign in to comment.