Ignore:
Timestamp:
Oct 14, 2015, 10:30:43 PM (10 years ago)
Author:
Yusuke Suzuki
Message:

[ES6] Class method should not declare any variables to upper scope.
https://bugs.webkit.org/show_bug.cgi?id=150115

Reviewed by Geoffrey Garen.

In the current implementation, class methods attempt to declare variables to an upper scope with their method names.
But this is not specified behavior in the ES6 spec.

And as a result, previously, we attempted to declare variables with invalid identifiers.
For example, class A { 1() { } } attempt to declare a variable with name 1.
This (declaring variables with incorrect names) is not allowed in the lexical environment.
And it fires assertions in https://bugs.webkit.org/show_bug.cgi?id=150089.

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseClass): Deleted.

  • tests/stress/class-method-does-not-declare-variable-to-upper-scope.js: Added.

(shouldBe):
(A.prototype.method):
(A.staticMethod):
(A):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r191037 r191086  
    20162016            bool isConstructor = !isStaticMethod && *ident == propertyNames.constructor;
    20172017            failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SourceParseMode::MethodMode, false, isConstructor ? constructorKind : ConstructorKind::None, SuperBinding::Needed, methodStart, methodInfo, StandardFunctionParseType)), "Cannot parse this method");
    2018             failIfTrue(!computedPropertyName && (declareVariable(ident) & DeclarationResult::InvalidStrictMode), "Cannot declare a method named '", methodInfo.name->impl(), "'");
    20192018            methodInfo.name = isConstructor ? className : ident;
    20202019
Note: See TracChangeset for help on using the changeset viewer.