Changeset 198324 in webkit


Ignore:
Timestamp:
Mar 17, 2016 2:46:07 AM (8 years ago)
Author:
gskachkov@gmail.com
Message:

Invoking super()/super inside of the eval should not lead to SyntaxError
https://bugs.webkit.org/show_bug.cgi?id=153864

Reviewed by Saam Barati.

Source/JavaScriptCore:

Added support of the invoking super/super() inside of the eval within class.
Also support cases when eval is invoked in constructor, class method directly
or via arrow function. Access to the new.target in eval is not part of this patch
and will be implemented in https://bugs.webkit.org/show_bug.cgi?id=155545

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitLoadArrowFunctionLexicalEnvironment):
(JSC::BytecodeGenerator::isThisUsedInInnerArrowFunction):
(JSC::BytecodeGenerator::isNewTargetUsedInInnerArrowFunction):
(JSC::BytecodeGenerator::isSuperUsedInInnerArrowFunction):
(JSC::BytecodeGenerator::isSuperCallUsedInInnerArrowFunction):
(JSC::BytecodeGenerator::emitPutThisToArrowFunctionContextScope):

  • interpreter/Interpreter.cpp:

(JSC::eval):

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::Parser):
(JSC::Parser<LexerType>::parseFunctionInfo):
(JSC::Parser<LexerType>::parseMemberExpression):

  • parser/Parser.h:

(JSC::Scope::Scope):
(JSC::Scope::isEvalContext):
(JSC::Scope::setIsEvalContext):
(JSC::parse):

  • runtime/CodeCache.cpp:

(JSC::CodeCache::getGlobalCodeBlock):

  • tests/stress/arrowfunction-lexical-bind-supercall-4.js:
  • tests/stress/arrowfunction-lexical-bind-superproperty.js:
  • tests/stress/class-syntax-super-in-eval.js: Added.
  • tests/stress/generator-with-super.js:

LayoutTests:

  • js/class-syntax-super-expected.txt:
  • js/script-tests/class-syntax-super.js:
Location:
trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r198309 r198324  
     12016-03-17  Skachkov Oleksandr  <gskachkov@gmail.com>
     2
     3        Invoking super()/super inside of the eval should not lead to SyntaxError
     4        https://bugs.webkit.org/show_bug.cgi?id=153864
     5
     6        Reviewed by Saam Barati.
     7
     8        * js/class-syntax-super-expected.txt:
     9        * js/script-tests/class-syntax-super.js:
     10
    1112016-03-16  Zalan Bujtas  <zalan@apple.com>
    212
  • trunk/LayoutTests/js/class-syntax-super-expected.txt

    r194881 r198324  
    66PASS (new Base) instanceof Base
    77PASS (new Derived) instanceof Derived
     8PASS (new DerivedWithEval) instanceof DerivedWithEval
     9PASS (new DerivedWithEval(true)):::ReferenceError: Cannot access uninitialized variable.
    810PASS (new Derived).callBaseMethod():::baseMethodValue
    911PASS x = (new Derived).callBaseMethod; x():::baseMethodValue
     
    4244PASS function x() { super.method(); }:::SyntaxError: super can only be used in a method of a derived class.
    4345PASS function x() { super(); }:::SyntaxError: Cannot call super() outside of a class constructor.
     46PASS eval("super.method()"):::SyntaxError: super is only valid inside functions.
     47PASS eval("super()"):::SyntaxError: super is only valid inside functions.
     48PASS (function () { eval("super.method()");})():::SyntaxError: super is only valid inside functions.
     49PASS (function () { eval("super()");})():::SyntaxError: super is only valid inside functions.
     50PASS new (class { constructor() { (function () { eval("super()");})(); } }):::SyntaxError: super is only valid inside functions.
     51PASS (new (class { method() { (function () { eval("super.method()");})(); }})).method():::SyntaxError: super is only valid inside functions.
    4452PASS successfullyParsed
    4553
  • trunk/LayoutTests/js/script-tests/class-syntax-super.js

    r194881 r198324  
    4040    if (eval(s) === true)
    4141        testPassed(s);
    42     else 
     42    else
    4343        testFailed(s);
    4444}
     
    4747    if (eval(s) === false)
    4848        testPassed(s);
    49     else 
     49    else
    5050        testFailed(s);
    5151}
     
    7777}
    7878
     79class DerivedWithEval extends Base {
     80    constructor(throwTDZ) {
     81      if (throwTDZ)
     82        this.id = '';
     83
     84      eval("super()");
     85    }
     86}
     87
    7988shouldBeTrue('(new Base) instanceof Base');
    8089shouldBeTrue('(new Derived) instanceof Derived');
     90shouldBeTrue('(new DerivedWithEval) instanceof DerivedWithEval');
     91shouldThrow('(new DerivedWithEval(true))', '"ReferenceError: Cannot access uninitialized variable."');
    8192shouldBe('(new Derived).callBaseMethod()', 'baseMethodValue');
    8293shouldBe('x = (new Derived).callBaseMethod; x()', 'baseMethodValue');
     
    116127shouldThrow('function x() { super.method(); }', '"SyntaxError: super can only be used in a method of a derived class."');
    117128shouldThrow('function x() { super(); }', '"SyntaxError: Cannot call super() outside of a class constructor."');
     129shouldThrow('eval("super.method()")', '"SyntaxError: super is only valid inside functions."');
     130shouldThrow('eval("super()")', '"SyntaxError: super is only valid inside functions."');
     131
     132shouldThrow('(function () { eval("super.method()");})()', '"SyntaxError: super is only valid inside functions."');
     133shouldThrow('(function () { eval("super()");})()', '"SyntaxError: super is only valid inside functions."');
     134
     135shouldThrow('new (class { constructor() { (function () { eval("super()");})(); } })', '"SyntaxError: super is only valid inside functions."');
     136shouldThrow('(new (class { method() { (function () { eval("super.method()");})(); }})).method()', '"SyntaxError: super is only valid inside functions."');
    118137
    119138var successfullyParsed = true;
  • trunk/Source/JavaScriptCore/ChangeLog

    r198296 r198324  
     12016-03-17  Skachkov Oleksandr  <gskachkov@gmail.com>
     2
     3        Invoking super()/super inside of the eval should not lead to SyntaxError
     4        https://bugs.webkit.org/show_bug.cgi?id=153864
     5
     6        Reviewed by Saam Barati.
     7
     8        Added support of the invoking super/super() inside of the eval within class.
     9        Also support cases when eval is invoked in constructor, class method directly
     10        or via arrow function. Access to the new.target in eval is not part of this patch
     11        and will be implemented in https://bugs.webkit.org/show_bug.cgi?id=155545
     12
     13        * bytecompiler/BytecodeGenerator.cpp:
     14        (JSC::BytecodeGenerator::BytecodeGenerator):
     15        (JSC::BytecodeGenerator::emitLoadArrowFunctionLexicalEnvironment):
     16        (JSC::BytecodeGenerator::isThisUsedInInnerArrowFunction):
     17        (JSC::BytecodeGenerator::isNewTargetUsedInInnerArrowFunction):
     18        (JSC::BytecodeGenerator::isSuperUsedInInnerArrowFunction):
     19        (JSC::BytecodeGenerator::isSuperCallUsedInInnerArrowFunction):
     20        (JSC::BytecodeGenerator::emitPutThisToArrowFunctionContextScope):
     21        * interpreter/Interpreter.cpp:
     22        (JSC::eval):
     23        * parser/Parser.cpp:
     24        (JSC::Parser<LexerType>::Parser):
     25        (JSC::Parser<LexerType>::parseFunctionInfo):
     26        (JSC::Parser<LexerType>::parseMemberExpression):
     27        * parser/Parser.h:
     28        (JSC::Scope::Scope):
     29        (JSC::Scope::isEvalContext):
     30        (JSC::Scope::setIsEvalContext):
     31        (JSC::parse):
     32        * runtime/CodeCache.cpp:
     33        (JSC::CodeCache::getGlobalCodeBlock):
     34        * tests/stress/arrowfunction-lexical-bind-supercall-4.js:
     35        * tests/stress/arrowfunction-lexical-bind-superproperty.js:
     36        * tests/stress/class-syntax-super-in-eval.js: Added.
     37        * tests/stress/generator-with-super.js:
     38
    1392016-03-15  Filip Pizlo  <fpizlo@apple.com>
    240
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r198288 r198324  
    622622    }
    623623    codeBlock->adoptVariables(variables);
     624   
     625    if (evalNode->usesSuperCall() || evalNode->usesNewTarget())
     626        m_newTargetRegister = addVar();
    624627
    625628    pushTDZVariables(*parentScopeTDZVariables, TDZCheckOptimization::DoNotOptimize);
    626 
    627     if (codeBlock->isArrowFunctionContext() && evalNode->usesThis())
     629   
     630    if (codeBlock->isArrowFunctionContext() && (evalNode->usesThis() || evalNode->usesSuperProperty()))
    628631        emitLoadThisFromArrowFunctionLexicalEnvironment();
    629632
    630     if (needsToUpdateArrowFunctionContext() && !codeBlock->isArrowFunctionContext()) {
     633    if (evalNode->usesSuperCall() || evalNode->usesNewTarget())
     634        emitLoadNewTargetFromArrowFunctionLexicalEnvironment();
     635
     636    if (needsToUpdateArrowFunctionContext() && !codeBlock->isArrowFunctionContext() && !isDerivedConstructorContext()) {
    631637        initializeArrowFunctionContextScopeIfNeeded();
    632638        emitPutThisToArrowFunctionContextScope();
     
    41034109RegisterID* BytecodeGenerator::emitLoadArrowFunctionLexicalEnvironment(const Identifier& identifier)
    41044110{
    4105     ASSERT(m_codeBlock->isArrowFunction() || m_codeBlock->isArrowFunctionContext() || constructorKind() == ConstructorKind::Derived);
     4111    ASSERT(m_codeBlock->isArrowFunction() || m_codeBlock->isArrowFunctionContext() || constructorKind() == ConstructorKind::Derived || m_codeType == EvalCode);
    41064112
    41074113    return emitResolveScope(nullptr, variable(identifier, ThisResolutionType::Scoped));
     
    41274133}
    41284134   
    4129 bool BytecodeGenerator::isThisUsedInInnerArrowFunction() 
     4135bool BytecodeGenerator::isThisUsedInInnerArrowFunction()
    41304136{
    41314137    return m_scopeNode->doAnyInnerArrowFunctionsUseThis() || m_scopeNode->doAnyInnerArrowFunctionsUseSuperProperty() || m_scopeNode->doAnyInnerArrowFunctionsUseSuperCall() || m_scopeNode->doAnyInnerArrowFunctionsUseEval() || m_codeBlock->usesEval();
     
    41394145bool BytecodeGenerator::isNewTargetUsedInInnerArrowFunction()
    41404146{
    4141     return m_scopeNode->doAnyInnerArrowFunctionsUseNewTarget() || m_scopeNode->doAnyInnerArrowFunctionsUseSuperCall();
     4147    return m_scopeNode->doAnyInnerArrowFunctionsUseNewTarget() || m_scopeNode->doAnyInnerArrowFunctionsUseSuperCall() || m_scopeNode->doAnyInnerArrowFunctionsUseEval() || m_codeBlock->usesEval();
    41424148}
    41434149
    41444150bool BytecodeGenerator::isSuperUsedInInnerArrowFunction()
    41454151{
    4146     return m_scopeNode->doAnyInnerArrowFunctionsUseSuperCall() || m_scopeNode->doAnyInnerArrowFunctionsUseSuperProperty();
     4152    return m_scopeNode->doAnyInnerArrowFunctionsUseSuperCall() || m_scopeNode->doAnyInnerArrowFunctionsUseSuperProperty() || m_scopeNode->doAnyInnerArrowFunctionsUseEval() || m_codeBlock->usesEval();
    41474153}
    41484154
    41494155bool BytecodeGenerator::isSuperCallUsedInInnerArrowFunction()
    41504156{
    4151     return m_scopeNode->doAnyInnerArrowFunctionsUseSuperCall();
     4157    return m_scopeNode->doAnyInnerArrowFunctionsUseSuperCall() || m_scopeNode->doAnyInnerArrowFunctionsUseEval() || m_codeBlock->usesEval();
    41524158}
    41534159   
     
    41764182void BytecodeGenerator::emitPutThisToArrowFunctionContextScope()
    41774183{
    4178     if (isThisUsedInInnerArrowFunction()) {
     4184    if (isThisUsedInInnerArrowFunction() || (m_scopeNode->usesSuperCall() && m_codeType == EvalCode)) {
    41794185        ASSERT(isDerivedConstructorContext() || m_arrowFunctionContextLexicalEnvironmentRegister != nullptr);
    41804186
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r198228 r198324  
    181181        // If the literal parser bailed, it should not have thrown exceptions.
    182182        ASSERT(!callFrame->vm().exception());
    183 
    184         eval = callerCodeBlock->evalCodeCache().getSlow(callFrame, callerCodeBlock, callerCodeBlock->isStrictMode(), thisTDZMode, callerCodeBlock->unlinkedCodeBlock()->derivedContextType(), callerCodeBlock->unlinkedCodeBlock()->isArrowFunction(), sourceCode, callerScopeChain);
     183        bool isInArrowFunctionContext = callerCodeBlock->unlinkedCodeBlock()->isArrowFunction() || callerCodeBlock->unlinkedCodeBlock()->isArrowFunctionContext();
     184
     185        DerivedContextType derivedContextType = callerCodeBlock->unlinkedCodeBlock()->derivedContextType();
     186       
     187        if (!isInArrowFunctionContext && callerCodeBlock->unlinkedCodeBlock()->isClassContext()) {
     188            derivedContextType = callerCodeBlock->unlinkedCodeBlock()->isConstructor()
     189                ? DerivedContextType::DerivedConstructorContext
     190                : DerivedContextType::DerivedMethodContext;
     191        }
     192
     193        eval = callerCodeBlock->evalCodeCache().getSlow(callFrame, callerCodeBlock, callerCodeBlock->isStrictMode(), thisTDZMode, derivedContextType, isInArrowFunctionContext, sourceCode, callerScopeChain);
    185194
    186195        if (!eval)
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r198233 r198324  
    193193
    194194template <typename LexerType>
    195 Parser<LexerType>::Parser(
    196     VM* vm, const SourceCode& source, JSParserBuiltinMode builtinMode,
    197     JSParserStrictMode strictMode, SourceParseMode parseMode, SuperBinding superBinding,
    198     ConstructorKind defaultConstructorKind, ThisTDZMode thisTDZMode)
     195Parser<LexerType>::Parser(VM* vm, const SourceCode& source, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, SourceParseMode parseMode, SuperBinding superBinding, ConstructorKind defaultConstructorKind, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isEvalContext)
    199196    : m_vm(vm)
    200197    , m_source(&source)
     
    220217    ScopeRef scope = pushScope();
    221218    scope->setSourceParseMode(parseMode);
     219    scope->setIsEvalContext(isEvalContext);
     220   
     221    if (derivedContextType == DerivedContextType::DerivedConstructorContext) {
     222        scope->setConstructorKind(ConstructorKind::Derived);
     223        scope->setExpectedSuperBinding(SuperBinding::Needed);
     224    }
     225   
     226    if (derivedContextType == DerivedContextType::DerivedMethodContext)
     227        scope->setExpectedSuperBinding(SuperBinding::Needed);
    222228
    223229    if (strictMode == JSParserStrictMode::Strict)
     
    20682074    if (!m_lexer->isReparsingFunction()) {
    20692075        if (functionScope->hasDirectSuper()) {
    2070             ConstructorKind functionConstructorKind = functionBodyType == StandardFunctionBodyBlock
     2076            ScopeRef scopeRef = closestParentOrdinaryFunctionNonLexicalScope();
     2077            ConstructorKind functionConstructorKind = functionBodyType == StandardFunctionBodyBlock && !scopeRef->isEvalContext()
    20712078                ? constructorKind
    2072                 : closestParentOrdinaryFunctionNonLexicalScope()->constructorKind();
     2079                : scopeRef->constructorKind();
    20732080            semanticFailIfTrue(functionConstructorKind == ConstructorKind::None, "Cannot call super() outside of a class constructor");
    20742081            semanticFailIfTrue(functionConstructorKind != ConstructorKind::Derived, "Cannot call super() in a base class constructor");
    20752082        }
    20762083        if (functionScope->needsSuperBinding()) {
    2077             SuperBinding functionSuperBinding = functionBodyType == StandardFunctionBodyBlock
     2084            ScopeRef scopeRef = closestParentOrdinaryFunctionNonLexicalScope();
     2085            SuperBinding functionSuperBinding = functionBodyType == StandardFunctionBodyBlock && !scopeRef->isEvalContext()
    20782086                ? expectedSuperBinding
    2079                 : closestParentOrdinaryFunctionNonLexicalScope()->expectedSuperBinding();
     2087                : scopeRef->expectedSuperBinding();
    20802088            semanticFailIfTrue(functionSuperBinding == SuperBinding::NotNeeded, "super can only be used in a method of a derived class");
    20812089        }
     
    38383846
    38393847    if (baseIsSuper) {
    3840         semanticFailIfFalse(currentScope()->isFunction(), "super is only valid inside functions");
     3848        ScopeRef scopeRef = closestParentOrdinaryFunctionNonLexicalScope();
     3849        // FIXME: Change error message for more suitable. https://bugs.webkit.org/show_bug.cgi?id=155491
     3850        semanticFailIfFalse(currentScope()->isFunction() || (scopeRef->isEvalContext() && scopeRef->expectedSuperBinding() == SuperBinding::Needed), "super is only valid inside functions");
    38413851        base = context.createSuperExpr(location);
    38423852        next();
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r197915 r198324  
    178178        , m_isValidStrictMode(true)
    179179        , m_hasArguments(false)
     180        , m_isEvalContext(false)
    180181        , m_constructorKind(static_cast<unsigned>(ConstructorKind::None))
    181182        , m_expectedSuperBinding(static_cast<unsigned>(SuperBinding::NotNeeded))
     
    205206        , m_isValidStrictMode(rhs.m_isValidStrictMode)
    206207        , m_hasArguments(rhs.m_hasArguments)
     208        , m_isEvalContext(rhs.m_isEvalContext)
    207209        , m_constructorKind(rhs.m_constructorKind)
    208210        , m_expectedSuperBinding(rhs.m_expectedSuperBinding)
     
    526528    void setInnerArrowFunctionUsesNewTarget() { m_innerArrowFunctionFeatures |= NewTargetInnerArrowFunctionFeature; }
    527529    void setInnerArrowFunctionUsesArguments() { m_innerArrowFunctionFeatures |= ArgumentsInnerArrowFunctionFeature; }
     530   
     531    bool isEvalContext() const { return m_isEvalContext; }
     532    void setIsEvalContext(bool isEvalContext) { m_isEvalContext = isEvalContext; }
    528533
    529534    void setInnerArrowFunctionUsesEvalAndUseArgumentsIfNeeded()
     
    708713    bool m_isValidStrictMode : 1;
    709714    bool m_hasArguments : 1;
     715    bool m_isEvalContext : 1;
    710716    unsigned m_constructorKind : 2;
    711717    unsigned m_expectedSuperBinding : 2;
     
    764770
    765771public:
    766     Parser(
    767         VM*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, SourceParseMode, SuperBinding,
    768         ConstructorKind defaultConstructorKind = ConstructorKind::None, ThisTDZMode = ThisTDZMode::CheckIfNeeded);
     772    Parser(VM*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, SourceParseMode, SuperBinding, ConstructorKind defaultConstructorKind = ConstructorKind::None, ThisTDZMode = ThisTDZMode::CheckIfNeeded, DerivedContextType = DerivedContextType::None, bool isEvalContext = false);
    769773    ~Parser();
    770774
     
    15291533    int m_numConstants;
    15301534    ExpressionErrorClassifier* m_expressionErrorClassifier;
     1535    bool m_isEvalContext;
    15311536   
    15321537    struct DepthManager {
     
    16471652    JSParserStrictMode strictMode, SourceParseMode parseMode, SuperBinding superBinding,
    16481653    ParserError& error, JSTextPosition* positionBeforeLastNewline = nullptr,
    1649     ConstructorKind defaultConstructorKind = ConstructorKind::None,
    1650     ThisTDZMode thisTDZMode = ThisTDZMode::CheckIfNeeded)
     1654    ConstructorKind defaultConstructorKind = ConstructorKind::None, ThisTDZMode thisTDZMode = ThisTDZMode::CheckIfNeeded,
     1655    DerivedContextType derivedContextType = DerivedContextType::None)
    16511656{
    16521657    SamplingRegion samplingRegion("Parsing");
     
    16541659    ASSERT(!source.provider()->source().isNull());
    16551660    if (source.provider()->source().is8Bit()) {
    1656         Parser<Lexer<LChar>> parser(vm, source, builtinMode, strictMode, parseMode, superBinding, defaultConstructorKind, thisTDZMode);
     1661        Parser<Lexer<LChar>> parser(vm, source, builtinMode, strictMode, parseMode, superBinding, defaultConstructorKind, thisTDZMode, derivedContextType, isEvalNode<ParsedNode>());
    16571662        std::unique_ptr<ParsedNode> result = parser.parse<ParsedNode>(error, name, parseMode);
    16581663        if (positionBeforeLastNewline)
     
    16651670    }
    16661671    ASSERT_WITH_MESSAGE(defaultConstructorKind == ConstructorKind::None, "BuiltinExecutables::createDefaultConstructor should always use a 8-bit string");
    1667     Parser<Lexer<UChar>> parser(vm, source, builtinMode, strictMode, parseMode, superBinding, defaultConstructorKind, thisTDZMode);
     1672    Parser<Lexer<UChar>> parser(vm, source, builtinMode, strictMode, parseMode, superBinding, defaultConstructorKind, thisTDZMode, derivedContextType, isEvalNode<ParsedNode>());
    16681673    std::unique_ptr<ParsedNode> result = parser.parse<ParsedNode>(error, name, parseMode);
    16691674    if (positionBeforeLastNewline)
  • trunk/Source/JavaScriptCore/runtime/CodeCache.cpp

    r197308 r198324  
    101101        return unlinkedCodeBlock;
    102102    }
    103 
    104103    typedef typename CacheTypes<UnlinkedCodeBlockType>::RootNode RootNode;
     104    DerivedContextType derivedContextType = executable->derivedContextType();
    105105    std::unique_ptr<RootNode> rootNode = parse<RootNode>(
    106         &vm, source, Identifier(), builtinMode, strictMode,
    107         CacheTypes<UnlinkedCodeBlockType>::parseMode, SuperBinding::NotNeeded, error, nullptr, ConstructorKind::None, thisTDZMode);
     106        &vm, source, Identifier(), builtinMode, strictMode, CacheTypes<UnlinkedCodeBlockType>::parseMode, SuperBinding::NotNeeded, error, nullptr, ConstructorKind::None, thisTDZMode, derivedContextType);
    108107    if (!rootNode)
    109108        return nullptr;
  • trunk/Source/JavaScriptCore/tests/stress/arrowfunction-lexical-bind-supercall-4.js

    r197410 r198324  
    3232        var arrow = () => eval('(() => super())()');
    3333        arrow();
    34         return {};
     34        return {
     35          value : 'constructor-value'
     36        };
    3537    }
    3638};
     
    5254};
    5355
    54 // FIXME: Arrow function does not support using of eval with super/super()
    55 // https://bugs.webkit.org/show_bug.cgi?id=153977
    56 /*
     56
    5757for (var i=0; i < 1000; i++) {
    5858    new B(true);
    5959    var c = new C();
    60     testCase(typeof c.id, 'undefined', 'Error during set value in eval #1');
     60    testCase(c.value, 'constructor-value', 'Error during set value in eval #1.0');
     61    testCase(typeof c.id, 'undefined', 'Error during set value in eval #1.1');
    6162    var d = new D();
    62     testCase(d.id, 'new-value', 'Error during set value in eval #2');
     63    testCase(d.idValue, testValue, 'Error during set value in eval #2.0');
     64    testCase(d.id, 'new-value', 'Error during set value in eval #2.1');
    6365    var e = new E();
    64     testCase(e.id, 'new-value', 'Error during set value in eval #3');
     66    testCase(e.idValue, testValue, 'Error during set value in eval #3.0');
     67    testCase(e.id, 'new-value', 'Error during set value in eval #3.0');
    6568}
    66 */
    6769
    68 var testException = function (value, index) {
     70var testException = function (Klass, value, index) {
    6971    var exception;
    7072    try {
    71         new B(value);
     73        new Klass(value);
    7274    } catch (e) {
    7375        exception = e;
     
    8183
    8284for (var i=0; i < 1000; i++) {
    83     testException(false, i);
     85    testException(B, false, i);
    8486}
    8587
     
    140142let h = new H();
    141143testCase(h.someValue, testValue, 'Error: not correct binding superProperty&this in constructor');
     144
     145class I extends A {
     146  constructor (beforeSuper) {
     147      if (beforeSuper) {
     148          eval('(() => super())()');
     149          testCase(this.idValue, testValue, "Error: super() should create this and put value into idValue property");
     150      } else {
     151          this.idValue = 'testValue';
     152          eval('(() => super())()');
     153      }
     154  }
     155};
     156
     157let ic = new I(true);
     158testCase(ic.idValue, testValue, 'Error: not correct binding superProperty&this in constructor');
     159
     160for (var i=0; i < 1000; i++) {
     161    testException(I, false, i);
     162}
  • trunk/Source/JavaScriptCore/tests/stress/arrowfunction-lexical-bind-superproperty.js

    r197554 r198324  
    229229    testCase(error, true, 'Error: using "super" property before super() should lead to error');
    230230}
     231
     232class K extends A {
     233    newMethodArrowEval() {
     234        var arrow = () => eval('super.getValue()');
     235        var r = arrow();
     236        return r;
     237    }
     238    newMethodArrowDoubleEval() {
     239      var arrow = () => eval("eval('super.getValue()')");
     240      var r = arrow();
     241      return r;
     242    }
     243    newMethodArrowEvalEvalArrow() {
     244      var arrow = () => eval("eval('(() => super.getValue())()')");
     245      var r = arrow();
     246      return r;
     247    }
     248    newMethodArrowEvalEvalArrowEval() {
     249      var arrow  = () => eval("eval('(() => eval(\"super.getValue()\"))()')");
     250      var r = arrow();
     251      return r;
     252    }
     253    newMethodEval() {
     254        var r = eval("super.getValue()");
     255        return r;
     256    }
     257    newMethodEvalEval() {
     258        var r = eval("eval('super.getValue()')");
     259        return r;
     260    }
     261    newMethodEvalArrow() {
     262        var r = eval("(() => super.getValue())()");
     263        return r;
     264    }
     265    newMethodEvalEvalArrow() {
     266        var r = eval("eval('(() => super.getValue())()')");
     267        return r;
     268    }
     269    newMethodEvalEvalArrowEval() {
     270        var r = eval("eval('(() => eval(\"(super.getValue())\"))()')");
     271        return r;
     272    }
     273}
     274
     275var k = new K();
     276
     277for (var i = 0; i < 1000; i++) {
     278    testCase(k.newMethodArrowEval() , testValue, 'Error: Error in lexical bind with eval and arrow function #1');
     279    testCase(k.newMethodArrowDoubleEval() , testValue, 'Error: Error in lexical bind with eval and arrow function #2');
     280    testCase(k.newMethodArrowEvalEvalArrow() , testValue, 'Error: Error in lexical bind with eval and arrow function #3');
     281    testCase(k.newMethodArrowEvalEvalArrowEval() , testValue, 'Error: Error in lexical bind with eval and arrow function #4');
     282
     283    testCase(k.newMethodEval() , testValue, 'Error: Error in lexical bind with eval and arrow function #5');
     284    testCase(k.newMethodEvalEval() , testValue, 'Error: Error in lexical bind with eval and arrow function #6');
     285    testCase(k.newMethodEvalArrow() , testValue, 'Error: Error in lexical bind with eval and arrow function #7');
     286    testCase(k.newMethodEvalEvalArrow() , testValue, 'Error: Error in lexical bind with eval and arrow function 8');
     287    testCase(k.newMethodEvalEvalArrowEval() , testValue, 'Error: Error in lexical bind with eval and arrow function #9');
     288}
  • trunk/Source/JavaScriptCore/tests/stress/generator-with-super.js

    r192937 r198324  
    4141
    4242    let a = new A();
    43     shouldThrow(() => {
    44         a.gen().next();
    45     }, `SyntaxError: super is only valid inside functions.`);
     43    shouldBe(a.gen().next().value, 42);
    4644}());
    4745
Note: See TracChangeset for help on using the changeset viewer.