Branch: refs/heads/main Home: https://github.com/WebKit/WebKit Commit: a4c5231dbae7cb9180fc5c02f8438bcce3f2cd52 https://github.com/WebKit/WebKit/commit/a4c5231dbae7cb9180fc5c02f8438bcce3f2cd52 Author: Alexey Shvayka <ashva...@apple.com> Date: 2023-09-27 (Wed, 27 Sep 2023)
Changed paths: M JSTests/mozilla/ecma_3/Function/scope-001.js M JSTests/mozilla/js1_5/Scope/regress-184107.js M JSTests/mozilla/mozilla-tests.yaml M JSTests/stress/can-declare-global-function-invoked-before-any-func-decl-is-hoisted-eval.js A JSTests/stress/can-declare-global-function-invoked-before-any-func-decl-is-hoisted-global.js M JSTests/stress/can-declare-global-var-invoked-before-any-func-decl-is-hoisted-eval.js A JSTests/stress/can-declare-global-var-invoked-before-any-func-decl-is-hoisted-global.js M JSTests/stress/can-declare-global-var-invoked-during-func-decl-hoisting-eval.js A JSTests/stress/can-declare-global-var-invoked-during-func-decl-hoisting-global.js A JSTests/stress/sloppy-mode-function-hoisting-global-code-2.js A JSTests/stress/sloppy-mode-function-hoisting-global-code.js M JSTests/stress/sloppy-mode-function-hoisting.js M JSTests/test262/expectations.yaml M LayoutTests/accessibility/insert-children-assert.html M LayoutTests/fast/dom/MutationObserver/disconnect-observer-while-mutation-records-are-enqueued-crash.html M LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-types-with-hints.tentative-expected.txt M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp M Source/JavaScriptCore/parser/Parser.cpp M Source/JavaScriptCore/parser/Parser.h M Source/JavaScriptCore/runtime/ProgramExecutable.cpp Log Message: ----------- [JSC] Implement Annex B block-level function hoisting for global scope https://bugs.webkit.org/show_bug.cgi?id=163209 <rdar://problem/53234438> Reviewed by Yusuke Suzuki. This change expands existing (and recently revamped) block-level function hoisting infrastructure to global scope code, removing the extremely troublesome hack that used to unconditionally set the scope of a block-level function declaration in global code to the top-level `var` scope instead of lexical, which caused plenty of bug reports. GlobalDeclarationInstantiation [1] implementation was tweaked to properly handle all the "phantom" isSloppyModeHoistedFunction() variables, which are used merely to compute used / captured variables, and not treat them like `var`s to avoid throwing spec-noncompliant errors. Since there is no way to account for lexical declarations from another <script> in the parser [2], nor for non-extensible global object, emitResolveScopeForHoistingFuncDeclInEval() for global code has to emit same unresolved scope check as for declarations in eval(). Aligns JSC with the spec, V8, and SpiderMonkey. [1]: https://tc39.es/ecma262/#sec-globaldeclarationinstantiation [2]: https://tc39.es/ecma262/#sec-web-compat-globaldeclarationinstantiation (step 12.b.ii.2.a) * JSTests/mozilla/ecma_3/Function/scope-001.js: * JSTests/mozilla/js1_5/Scope/regress-184107.js: * JSTests/mozilla/mozilla-tests.yaml: * JSTests/stress/can-declare-global-function-invoked-before-any-func-decl-is-hoisted-eval.js: * JSTests/stress/can-declare-global-function-invoked-before-any-func-decl-is-hoisted-global.js: Added. * JSTests/stress/can-declare-global-var-invoked-before-any-func-decl-is-hoisted-eval.js: * JSTests/stress/can-declare-global-var-invoked-before-any-func-decl-is-hoisted-global.js: Added. * JSTests/stress/can-declare-global-var-invoked-during-func-decl-hoisting-eval.js: * JSTests/stress/can-declare-global-var-invoked-during-func-decl-hoisting-global.js: Added. * JSTests/stress/sloppy-mode-function-hoisting-global-code.js: Added. * JSTests/stress/sloppy-mode-function-hoisting-global-code-2.js: Added. Separate file is necessary to skip bytecode cache assertion for scripts that throw SyntaxError. See https://commits.webkit.org/r244241. * JSTests/stress/sloppy-mode-function-hoisting.js: * JSTests/test262/expectations.yaml: Mark 172 tests as passing. * LayoutTests/accessibility/insert-children-assert.html: Adjust test that relied on previous incorrect behavior of block-level function declaration being hoisted to top-level `var` scope before FunctionDeclaration is evaluated. * LayoutTests/fast/dom/MutationObserver/disconnect-observer-while-mutation-records-are-enqueued-crash.html: Ditto. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-types-with-hints.tentative-expected.txt: * Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::hoistSloppyModeFunctionIfNecessary): (JSC::BytecodeGenerator::emitResolveScopeForHoistingFuncDeclInEval): Hoist the common logic between FunctionCode and EvalCode. * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionDeclarationStatement): (JSC::Parser<LexerType>::parseFunctionDeclaration): * Source/JavaScriptCore/parser/Parser.h: (JSC::Parser::declareFunction): * Source/JavaScriptCore/runtime/ProgramExecutable.cpp: (JSC::ProgramExecutable::initializeGlobalProperties): Canonical link: https://commits.webkit.org/268553@main _______________________________________________ webkit-changes mailing list webkit-changes@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-changes