[webkit-changes] [WebKit/WebKit] e40427: [JSC] Duplicate lexical bindings should only be al...

Commit Queue noreply at github.com
Fri Sep 29 15:36:03 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: e4042719d2be336648b0e8f374903c07727ee5eb
      https://github.com/WebKit/WebKit/commit/e4042719d2be336648b0e8f374903c07727ee5eb
  Author: Alexey Shvayka <ashvayka at apple.com>
  Date:   2023-09-29 (Fri, 29 Sep 2023)

  Changed paths:
    M JSTests/test262/expectations.yaml
    M LayoutTests/js/parser-syntax-check-expected.txt
    M LayoutTests/js/script-tests/parser-syntax-check.js
    M Source/JavaScriptCore/parser/Parser.h
    M Source/JavaScriptCore/parser/VariableEnvironment.h

  Log Message:
  -----------
  [JSC] Duplicate lexical bindings should only be allowed for FunctionDeclarations
https://bugs.webkit.org/show_bug.cgi?id=262394
<rdar://problem/116252189>

Reviewed by Yusuke Suzuki.

Per Annex B [1], duplicate lexical declarations are only allowed in sloppy mode and when bound by
FunctionDeclaration parse nodes. Async / generator functions are defined using different nodes [2].

This patch introduces IsFunctionDeclaration bit to VariableEnvironmentEntry to differentiate pre-ES6
functions from generator / async functions and throw early errors when duplicate declarations include
the latter ones.

While the only observable change is:

```diff
-     if (strictMode() || !addResult.iterator->value.isFunction())
+     if (strictMode() || !addResult.iterator->value.isFunctionDeclaration() || !isFunctionDeclaration)
          result |= DeclarationResult::InvalidDuplicateDeclaration;
  }

+ if (isFunctionDeclaration)
+     addResult.iterator->value.setIsFunctionDeclaration();
```

isFunctionDeclaration parameter is only revelant when declareFunction() if called on a lexical scope,
and the function has another boolean parameter that significantly impacts its behavior, so this patch
also splits declareFunction() into two methods rather than degrading code quality even further.

Aligns JSC with V8 and SpiderMonkey.

[1]: https://tc39.es/ecma262/#sec-block-duplicates-allowed-static-semantics
[2]: https://tc39.es/ecma262/#prod-GeneratorDeclaration

* JSTests/test262/expectations.yaml: Mark 30 tests as passing.
* LayoutTests/js/parser-syntax-check-expected.txt:
* LayoutTests/js/script-tests/parser-syntax-check.js:
* Source/JavaScriptCore/parser/Parser.h:
(JSC::Scope::declareFunctionAsVar):
(JSC::Scope::declareFunctionAsLet):
(JSC::Parser::declareFunction):
(JSC::Scope::declareFunction): Deleted.
* Source/JavaScriptCore/parser/VariableEnvironment.h:
(JSC::VariableEnvironmentEntry::isFunctionDeclaration const):
(JSC::VariableEnvironmentEntry::setIsFunctionDeclaration):

Canonical link: https://commits.webkit.org/268671@main




More information about the webkit-changes mailing list