-
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() call with ...spread syntax should be direct
https://bugs.webkit.org/show_bug.cgi?id=268028 <rdar://problem/121547890> Reviewed by Justin Michaud. Before this change, EvalFunctionCallNode was emitting op_call_varargs for calls with ...spread syntax, rather than op_call_direct_eval, thus always performing indirect eval. Per spec [1], that was wrong: CoverCallExpressionAndAsyncArrowHead production matches ...spread syntax as well. Since global eval() function takes only one parameter, and we would like to avoid introducing yet another call bytecode just for this very rare case, this change emits op_spread to perform full iteration and passes first argument into op_call_direct_eval, conditional on callee function to be built-in eval() from the lexical realm. To perform this check, we need a LinkTimeConstant and the globalObject->evalFunction() to share the same JSFunction, which is tricky since m_linkTimeConstants stores stateful LazyProperty object directly, without a pointer, and their initializers should be stateless. That is why initializeEvalFunction() is introduced. [1]: https://tc39.es/ecma262/#sec-function-calls-runtime-semantics-evaluation * JSTests/stress/direct-eval-spread.js: Added. * JSTests/test262/expectations.yaml: Mark 6 tests as passing. * Source/JavaScriptCore/builtins/BuiltinNames.h: * Source/JavaScriptCore/bytecode/LinkTimeConstant.h: * Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitJumpIfNotEvalFunction): (JSC::BytecodeGenerator::emitCall): * Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h: * Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp: (JSC::EvalFunctionCallNode::emitBytecode): * Source/JavaScriptCore/runtime/JSGlobalObject.cpp: (JSC::initializeEvalFunction): (JSC::JSGlobalObject::init): (JSC::JSGlobalObject::visitChildrenImpl): * Source/JavaScriptCore/runtime/JSGlobalObject.h: (JSC::JSGlobalObject::evalFunction const): Deleted. * Source/JavaScriptCore/runtime/JSGlobalObjectInlines.h: (JSC::JSGlobalObject::evalFunction const): Canonical link: https://commits.webkit.org/273788@main
- Loading branch information
Alexey Shvayka
committed
Jan 30, 2024
1 parent
106249c
commit bb825e0
Showing
10 changed files
with
75 additions
and
19 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,30 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error(`Bad value: ${actual}!`); | ||
} | ||
|
||
var xx = 0; | ||
var xxx = 0; | ||
|
||
function* genFn() { | ||
yield "x++"; | ||
yield "throw new Error()"; | ||
yield xx++; | ||
} | ||
|
||
var x = 0; | ||
|
||
(function() { | ||
var x = 0; | ||
|
||
for (var i = 0; i < 1e5; i++) { | ||
eval(...genFn()); | ||
eval(...genFn(), (() => xxx++)()); | ||
} | ||
|
||
shouldBe(x, 1e5 * 2); | ||
shouldBe(xx, 1e5 * 2); | ||
shouldBe(xxx, 1e5); | ||
})(); | ||
|
||
shouldBe(x, 0); |
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
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