Changeset 210958 in webkit
- Timestamp:
- Jan 20, 2017 3:43:24 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r210951 r210958 1 2017-01-20 Skachkov Oleksandr <gskachkov@gmail.com> 2 3 Super property access in base class constructor doesn't work 4 https://bugs.webkit.org/show_bug.cgi?id=166665 5 6 Reviewed by Ryosuke Niwa. 7 8 * js/class-syntax-super-expected.txt: 9 * js/script-tests/class-syntax-super.js: 10 1 11 2017-01-19 Said Abou-Hallawa <sabouhallawa@apple.com> 2 12 -
trunk/LayoutTests/js/class-syntax-super-expected.txt
r204058 r210958 23 23 PASS (new x).method1():::ReferenceError: Cannot delete a super property 24 24 PASS (new x).method2():::ReferenceError: Cannot delete a super property 25 PASS (new (class { constructor() { super.property = "ABC"; } })).property === "ABC" 26 PASS (new (class extends Base { constructor() { super(); super.property = "ABC"; } })).property === "ABC" 27 PASS (new (class { constructor() { var arr = () => super.property = "ABC"; arr(); } })).property === "ABC" 28 PASS (new (class { constructor() { var async_arr = async () => super.property = "ABC"; async_arr(); } })).property === "ABC" 29 PASS (new (class { constructor() { eval('super.property = "ABC"'); } })).property === "ABC" 30 PASS (new (class { constructor() { var arr = () => eval('super.property = "ABC"'); arr(); } })).property === "ABC" 25 31 PASS new (class { constructor() { return undefined; } }) instanceof Object 26 32 PASS new (class { constructor() { return 1; } }) instanceof Object -
trunk/LayoutTests/js/script-tests/class-syntax-super.js
r204058 r210958 106 106 shouldThrow('(new x).method1()', '"ReferenceError: Cannot delete a super property"'); 107 107 shouldThrow('(new x).method2()', '"ReferenceError: Cannot delete a super property"'); 108 shouldBeTrue('(new (class { constructor() { super.property = "ABC"; } })).property === "ABC"'); 109 shouldBeTrue('(new (class extends Base { constructor() { super(); super.property = "ABC"; } })).property === "ABC"'); 110 shouldBeTrue('(new (class { constructor() { var arr = () => super.property = "ABC"; arr(); } })).property === "ABC"'); 111 shouldBeTrue('(new (class { constructor() { var async_arr = async () => super.property = "ABC"; async_arr(); } })).property === "ABC"'); 112 shouldBeTrue('(new (class { constructor() { eval(\'super.property = "ABC"\'); } })).property === "ABC"'); 113 shouldBeTrue('(new (class { constructor() { var arr = () => eval(\'super.property = "ABC"\'); arr(); } })).property === "ABC"'); 108 114 shouldBeTrue('new (class { constructor() { return undefined; } }) instanceof Object'); 109 115 shouldBeTrue('new (class { constructor() { return 1; } }) instanceof Object'); -
trunk/Source/JavaScriptCore/ChangeLog
r210949 r210958 1 2017-01-20 Skachkov Oleksandr <gskachkov@gmail.com> 2 3 Super property access in base class constructor doesn't work 4 https://bugs.webkit.org/show_bug.cgi?id=166665 5 6 Reviewed by Ryosuke Niwa. 7 8 Allow to use super inside of the constructor for classes 9 without parent class. 10 Parser checks if super used within the constructor and 11 add this information to function metedata, and later it is used 12 during byte code generation. 13 14 * bytecompiler/NodesCodegen.cpp: 15 (JSC::ClassExprNode::emitBytecode): 16 * parser/Parser.cpp: 17 (JSC::Parser<LexerType>::parseFunctionBody): 18 (JSC::Parser<LexerType>::parseFunctionInfo): 19 * parser/Parser.h: 20 (JSC::Scope::usesEval): 21 (JSC::Scope::fillParametersForSourceProviderCache): 22 (JSC::Scope::restoreFromSourceProviderCache): 23 (JSC::Parser::adjustSuperBindingForBaseConstructor): 24 * parser/SourceProviderCacheItem.h: 25 (JSC::SourceProviderCacheItem::SourceProviderCacheItem): 26 1 27 2017-01-19 Chris Dumez <cdumez@apple.com> 2 28 -
trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
r210925 r210958 3682 3682 3683 3683 RefPtr<RegisterID> constructor; 3684 bool needsHomeObject = false; 3684 3685 3685 3686 // FIXME: Make the prototype non-configurable & non-writable. … … 3691 3692 constructor = generator.emitNode(dst, m_constructorExpression); 3692 3693 if (m_classHeritage) { 3694 needsHomeObject = true; 3693 3695 RefPtr<RegisterID> isDerivedConstructor = generator.newTemporary(); 3694 3696 generator.emitUnaryOp(op_not, isDerivedConstructor.get(), 3695 3697 generator.emitUnaryOp(op_eq_null, isDerivedConstructor.get(), superclass.get())); 3696 3698 generator.emitDirectPutById(constructor.get(), generator.propertyNames().builtinNames().isDerivedConstructorPrivateName(), isDerivedConstructor.get(), PropertyNode::Unknown); 3697 } 3699 } else if (metadata->superBinding() == SuperBinding::Needed) 3700 needsHomeObject = true; 3698 3701 } else { 3699 3702 if (m_classHeritage) { … … 3750 3753 generator.emitLabel(superclassIsNullLabel.get()); 3751 3754 generator.emitDirectPutById(prototype.get(), generator.propertyNames().underscoreProto, protoParent.get(), PropertyNode::Unknown); 3752 3755 } 3756 3757 if (needsHomeObject) 3753 3758 emitPutHomeObject(generator, constructor.get(), prototype.get()); 3754 }3755 3759 3756 3760 RefPtr<RegisterID> constructorNameRegister = generator.emitLoad(nullptr, propertyNames.constructor); -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r210535 r210958 1864 1864 if (match(CLOSEBRACE)) { 1865 1865 unsigned endColumn = tokenColumn(); 1866 return context.createFunctionMetadata(startLocation, tokenLocation(), startColumn, endColumn, functionKeywordStart, functionNameStart, parametersStart, strictMode(), constructorKind, superBinding, parameterCount, functionLength, parseMode, isArrowFunctionBodyExpression); 1866 SuperBinding functionSuperBinding = adjustSuperBindingForBaseConstructor(constructorKind, superBinding, currentScope()); 1867 return context.createFunctionMetadata(startLocation, tokenLocation(), startColumn, endColumn, functionKeywordStart, functionNameStart, parametersStart, strictMode(), constructorKind, functionSuperBinding, parameterCount, functionLength, parseMode, isArrowFunctionBodyExpression); 1867 1868 } 1868 1869 } … … 1882 1883 } 1883 1884 unsigned endColumn = tokenColumn(); 1884 return context.createFunctionMetadata(startLocation, tokenLocation(), startColumn, endColumn, functionKeywordStart, functionNameStart, parametersStart, strictMode(), constructorKind, superBinding, parameterCount, functionLength, parseMode, isArrowFunctionBodyExpression); 1885 SuperBinding functionSuperBinding = adjustSuperBindingForBaseConstructor(constructorKind, superBinding, currentScope()); 1886 return context.createFunctionMetadata(startLocation, tokenLocation(), startColumn, endColumn, functionKeywordStart, functionNameStart, parametersStart, strictMode(), constructorKind, functionSuperBinding, parameterCount, functionLength, parseMode, isArrowFunctionBodyExpression); 1885 1887 } 1886 1888 … … 2082 2084 else 2083 2085 functionBodyType = StandardFunctionBodyBlock; 2084 2086 2087 SuperBinding functionSuperBinding = adjustSuperBindingForBaseConstructor(constructorKind, expectedSuperBinding, cachedInfo->needsSuperBinding, cachedInfo->usesEval, cachedInfo->innerArrowFunctionFeatures); 2088 2085 2089 functionInfo.body = context.createFunctionMetadata( 2086 2090 startLocation, endLocation, startColumn, bodyEndColumn, 2087 2091 functionKeywordStart, functionNameStart, parametersStart, 2088 cachedInfo->strictMode, constructorKind, expectedSuperBinding,2092 cachedInfo->strictMode, constructorKind, functionSuperBinding, 2089 2093 cachedInfo->parameterCount, cachedInfo->functionLength, 2090 2094 mode, functionBodyType == ArrowFunctionBodyExpression); -
trunk/Source/JavaScriptCore/parser/Parser.h
r210151 r210958 315 315 } 316 316 bool isLexicalScope() { return m_isLexicalScope; } 317 bool usesEval() { return m_usesEval; } 317 318 318 319 const HashSet<UniquedStringImpl*>& closedVariableCandidates() const { return m_closedVariableCandidates; } … … 684 685 parameters.needsFullActivation = m_needsFullActivation; 685 686 parameters.innerArrowFunctionFeatures = m_innerArrowFunctionFeatures; 687 parameters.needsSuperBinding = m_needsSuperBinding; 686 688 for (const UniquedStringImplPtrSet& set : m_usedVariables) 687 689 copyCapturedVariablesToVector(set, parameters.usedVariables); … … 707 709 m_innerArrowFunctionFeatures = info->innerArrowFunctionFeatures; 708 710 m_needsFullActivation = info->needsFullActivation; 711 m_needsSuperBinding = info->needsSuperBinding; 709 712 UniquedStringImplPtrSet& destSet = m_usedVariables.last(); 710 713 for (unsigned i = 0; i < info->usedVariablesCount; ++i) … … 1599 1602 return token.m_type == AWAIT && (!m_parserState.allowAwait || currentScope()->isAsyncFunctionBoundary() || m_scriptMode == JSParserScriptMode::Module); 1600 1603 } 1604 1605 ALWAYS_INLINE SuperBinding adjustSuperBindingForBaseConstructor(ConstructorKind constructorKind, SuperBinding superBinding, ScopeRef functionScope) 1606 { 1607 return adjustSuperBindingForBaseConstructor(constructorKind, superBinding, functionScope->needsSuperBinding(), functionScope->usesEval(), functionScope->innerArrowFunctionFeatures()); 1608 } 1609 1610 ALWAYS_INLINE SuperBinding adjustSuperBindingForBaseConstructor(ConstructorKind constructorKind, SuperBinding superBinding, bool scopeNeedsSuperBinding, bool currentScopeUsesEval, InnerArrowFunctionCodeFeatures innerArrowFunctionFeatures) 1611 { 1612 SuperBinding methodSuperBinding = superBinding; 1613 1614 if (constructorKind == ConstructorKind::Base) { 1615 bool isSuperUsedInInnerArrowFunction = innerArrowFunctionFeatures & SuperPropertyInnerArrowFunctionFeature; 1616 methodSuperBinding = (scopeNeedsSuperBinding || isSuperUsedInInnerArrowFunction || currentScopeUsesEval) ? SuperBinding::Needed : SuperBinding::NotNeeded; 1617 } 1618 1619 return methodSuperBinding; 1620 } 1601 1621 1602 1622 const char* disallowedIdentifierAwaitReason() -
trunk/Source/JavaScriptCore/parser/SourceProviderCacheItem.h
r206525 r210958 45 45 bool usesEval; 46 46 bool strictMode; 47 bool needsSuperBinding; 47 48 InnerArrowFunctionCodeFeatures innerArrowFunctionFeatures; 48 49 Vector<UniquedStringImpl*, 8> usedVariables; … … 89 90 unsigned parameterCount : 31; 90 91 unsigned expectedSuperBinding : 1; // SuperBinding 92 bool needsSuperBinding: 1; 91 93 unsigned functionLength; 92 94 unsigned lastTokenLineStartOffset; … … 130 132 , parameterCount(parameters.parameterCount) 131 133 , expectedSuperBinding(static_cast<unsigned>(parameters.expectedSuperBinding)) 134 , needsSuperBinding(parameters.needsSuperBinding) 132 135 , functionLength(parameters.functionLength) 133 136 , lastTokenLineStartOffset(parameters.lastTokenLineStartOffset)
Note: See TracChangeset
for help on using the changeset viewer.