-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JSC] eval() function from another realm shouldn't cause direct eval …
…call https://bugs.webkit.org/show_bug.cgi?id=268027 <rdar://problem/121546048> Reviewed by Yusuke Suzuki. Whether eval() is direct or not is determined by SameValue() in [1] that compares the function to `%eval%`, which denotes [2] specifically the eval() function of current global object, not any built-in eval(). This change tightens the check for direct eval() and aligns JSC with V8 and SpiderMonkey. Since Interpreter::eval() has tricky way of resolving global object, accounting for DFG inlining code blocks, the callee check was moved there, ensuring all call sites handle empty JSValue. [1]: https://tc39.es/ecma262/#sec-function-calls-runtime-semantics-evaluation (step 6.a) [2]: https://tc39.es/ecma262/#sec-well-known-intrinsic-objects * JSTests/stress/direct-eval-cross-realm.js: Added. * JSTests/test262/expectations.yaml: Mark 1 test as passing. * Source/JavaScriptCore/jit/JITOperations.cpp: (JSC::JSC_DEFINE_JIT_OPERATION): * Source/JavaScriptCore/llint/LLIntSlowPaths.cpp: (JSC::LLInt::commonCallDirectEval): * Source/JavaScriptCore/runtime/JSFunctionInlines.h: (JSC::isHostFunction): Deleted. Canonical link: https://commits.webkit.org/273782@main
- Loading branch information
Alexey Shvayka
committed
Jan 30, 2024
1 parent
6405dde
commit 4737a82
Showing
6 changed files
with
37 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error(`Bad value: ${actual}!`); | ||
} | ||
|
||
(function() { | ||
function maybeReplaceEval(i) { | ||
if (i === (1e5 / 2)) { | ||
eval = otherEval; | ||
} | ||
} | ||
|
||
function isDirectEval() { | ||
return true; | ||
} | ||
|
||
var otherGlobal = createGlobalObject(); | ||
otherGlobal.i = 0; | ||
otherGlobal.maybeReplaceEval = maybeReplaceEval; | ||
otherGlobal.isDirectEval = () => false; | ||
|
||
var otherEval = otherGlobal.eval; | ||
var eval = globalThis.eval; | ||
|
||
for (var i = 0; i < 1e5; i++) { | ||
eval("maybeReplaceEval(i)"); | ||
shouldBe(eval("isDirectEval()"), i < (1e5 / 2)); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters