Changeset 269922 in webkit for trunk/Source/JavaScriptCore/bytecompiler
- Timestamp:
- Nov 17, 2020, 1:37:39 PM (5 years ago)
- Location:
- trunk/Source/JavaScriptCore/bytecompiler
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r269115 r269922 382 382 383 383 bool shouldCaptureAllOfTheThings = shouldEmitDebugHooks() || codeBlock->usesEval(); 384 bool needsArguments = ((functionNode->usesArguments() && !codeBlock->isArrowFunction()) || codeBlock->usesEval() || (functionNode->usesArrowFunction() && !codeBlock->isArrowFunction() && isArgumentsUsedInInnerArrowFunction())) && parseMode != SourceParseMode:: InstanceFieldInitializerMode;384 bool needsArguments = ((functionNode->usesArguments() && !codeBlock->isArrowFunction()) || codeBlock->usesEval() || (functionNode->usesArrowFunction() && !codeBlock->isArrowFunction() && isArgumentsUsedInInnerArrowFunction())) && parseMode != SourceParseMode::ClassFieldInitializerMode; 385 385 386 386 if (isGeneratorOrAsyncFunctionBodyParseMode(parseMode)) { … … 614 614 615 615 bool shouldCreateArgumensVariable = !haveParameterNamedArguments 616 && !SourceParseModeSet(SourceParseMode::ArrowFunctionMode, SourceParseMode::AsyncArrowFunctionMode, SourceParseMode:: InstanceFieldInitializerMode).contains(m_codeBlock->parseMode());616 && !SourceParseModeSet(SourceParseMode::ArrowFunctionMode, SourceParseMode::AsyncArrowFunctionMode, SourceParseMode::ClassFieldInitializerMode).contains(m_codeBlock->parseMode()); 617 617 shouldCreateArgumentsVariableInParameterScope = shouldCreateArgumensVariable && !isSimpleParameterList; 618 618 // Do not create arguments variable in case of Arrow function. Value will be loaded from parent scope … … 3134 3134 } 3135 3135 3136 RegisterID* BytecodeGenerator::emitNew InstanceFieldInitializerFunction(RegisterID* dst, Vector<JSTextPosition>&& instanceFieldLocations, bool isDerived)3136 RegisterID* BytecodeGenerator::emitNewClassFieldInitializerFunction(RegisterID* dst, Vector<JSTextPosition>&& classFieldLocations, bool isDerived) 3137 3137 { 3138 3138 DerivedContextType newDerivedContextType; … … 3147 3147 3148 3148 auto variablesUnderTDZ = getVariablesUnderTDZ(); 3149 SourceParseMode parseMode = SourceParseMode:: InstanceFieldInitializerMode;3149 SourceParseMode parseMode = SourceParseMode::ClassFieldInitializerMode; 3150 3150 ConstructAbility constructAbility = ConstructAbility::CannotConstruct; 3151 3151 … … 3154 3154 metadata.finishParsing(m_scopeNode->source(), Identifier(), FunctionMode::MethodDefinition); 3155 3155 auto initializer = UnlinkedFunctionExecutable::create(m_vm, m_scopeNode->source(), &metadata, isBuiltinFunction() ? UnlinkedBuiltinFunction : UnlinkedNormalFunction, constructAbility, scriptMode(), WTFMove(variablesUnderTDZ), newDerivedContextType, NeedsClassFieldInitializer::No); 3156 initializer->set InstanceFieldLocations(WTFMove(instanceFieldLocations));3156 initializer->setClassFieldLocations(WTFMove(classFieldLocations)); 3157 3157 3158 3158 unsigned index = m_codeBlock->addFunctionExpr(initializer); … … 4475 4475 RegisterID* BytecodeGenerator::emitLoadArrowFunctionLexicalEnvironment(const Identifier& identifier) 4476 4476 { 4477 ASSERT(m_codeBlock->isArrowFunction() || m_codeBlock->isArrowFunctionContext() || constructorKind() == ConstructorKind::Extends || m_codeType == EvalCode || m_codeBlock->parseMode() == SourceParseMode:: InstanceFieldInitializerMode);4477 ASSERT(m_codeBlock->isArrowFunction() || m_codeBlock->isArrowFunctionContext() || constructorKind() == ConstructorKind::Extends || m_codeType == EvalCode || m_codeBlock->parseMode() == SourceParseMode::ClassFieldInitializerMode); 4478 4478 4479 4479 return emitResolveScope(nullptr, variable(identifier, ThisResolutionType::Scoped)); -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r269115 r269922 583 583 } 584 584 585 RegisterID* emitDefineClassElements(PropertyListNode* n, RegisterID* constructor, RegisterID* prototype, Vector<JSTextPosition>& instanceFieldLocations )585 RegisterID* emitDefineClassElements(PropertyListNode* n, RegisterID* constructor, RegisterID* prototype, Vector<JSTextPosition>& instanceFieldLocations, Vector<JSTextPosition>& staticFieldLocations) 586 586 { 587 587 ASSERT(constructor->refCount() && prototype->refCount()); … … 590 590 if (UNLIKELY(n->needsDebugHook())) 591 591 emitDebugHook(n); 592 return n->emitBytecode(*this, constructor, prototype, &instanceFieldLocations );592 return n->emitBytecode(*this, constructor, prototype, &instanceFieldLocations, &staticFieldLocations); 593 593 } 594 594 … … 777 777 RegisterID* emitNewFunctionExpression(RegisterID* dst, FuncExprNode*); 778 778 RegisterID* emitNewDefaultConstructor(RegisterID* dst, ConstructorKind, const Identifier& name, const Identifier& ecmaName, const SourceCode& classSource, NeedsClassFieldInitializer); 779 RegisterID* emitNew InstanceFieldInitializerFunction(RegisterID* dst, Vector<JSTextPosition>&& instanceFieldLocations, bool isDerived);779 RegisterID* emitNewClassFieldInitializerFunction(RegisterID* dst, Vector<JSTextPosition>&& classFieldLocations, bool isDerived); 780 780 RegisterID* emitNewArrowFunctionExpression(RegisterID*, ArrowFuncExprNode*); 781 781 RegisterID* emitNewMethodDefinition(RegisterID* dst, MethodDefinitionNode*); -
trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
r269801 r269922 187 187 static RegisterID* emitHomeObjectForCallee(BytecodeGenerator& generator) 188 188 { 189 if ((generator.isDerivedClassContext() || generator.isDerivedConstructorContext()) && generator.parseMode() != SourceParseMode:: InstanceFieldInitializerMode) {189 if ((generator.isDerivedClassContext() || generator.isDerivedConstructorContext()) && generator.parseMode() != SourceParseMode::ClassFieldInitializerMode) { 190 190 RegisterID* derivedConstructor = generator.emitLoadDerivedConstructorFromArrowFunctionLexicalEnvironment(); 191 191 return generator.emitGetById(generator.newTemporary(), derivedConstructor, generator.propertyNames().builtinNames().homeObjectPrivateName()); … … 578 578 } 579 579 580 RegisterID* PropertyListNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dstOrConstructor, RegisterID* prototype, Vector<JSTextPosition>* instanceFieldLocations )580 RegisterID* PropertyListNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dstOrConstructor, RegisterID* prototype, Vector<JSTextPosition>* instanceFieldLocations, Vector<JSTextPosition>* staticFieldLocations) 581 581 { 582 582 PropertyListNode* p = this; … … 593 593 ASSERT(instanceFieldLocations); 594 594 instanceFieldLocations->append(p->position()); 595 continue; 596 } 597 598 if (p->isStaticClassField()) { 599 ASSERT(staticFieldLocations); 600 staticFieldLocations->append(p->position()); 595 601 continue; 596 602 } … … 650 656 ASSERT(node->m_type & PropertyNode::Constant); 651 657 instanceFieldLocations->append(p->position()); 658 continue; 659 } 660 661 if (p->isStaticClassField()) { 662 ASSERT(staticFieldLocations); 663 staticFieldLocations->append(p->position()); 652 664 continue; 653 665 } … … 745 757 void PropertyListNode::emitPutConstantProperty(BytecodeGenerator& generator, RegisterID* newObj, PropertyNode& node) 746 758 { 747 // Private fields are handled in the synthetic instanceFieldInitializer function, not here.759 // Private fields are handled in a synthetic classFieldInitializer function, not here. 748 760 ASSERT(!(node.type() & PropertyNode::Private)); 749 761 … … 801 813 { 802 814 ASSERT(node.isComputedClassField()); 803 RefPtr<RegisterID> propertyExpr;804 815 805 816 // The 'name' refers to a synthetic private name in the class scope, where the property key is saved for later use. … … 808 819 ASSERT(!var.local()); 809 820 810 propertyExpr = generator.emitNode(node.m_expression); 811 RegisterID* propertyName = generator.emitToPropertyKey(generator.newTemporary(), propertyExpr.get()); 821 RefPtr<RegisterID> propertyExpr = generator.emitNode(node.m_expression); 822 RefPtr<RegisterID> propertyName = generator.emitToPropertyKey(generator.newTemporary(), propertyExpr.get()); 823 824 if (node.isStaticClassField()) { 825 Ref<Label> validPropertyNameLabel = generator.newLabel(); 826 RefPtr<RegisterID> prototypeString = generator.emitLoad(nullptr, JSValue(generator.addStringConstant(generator.propertyNames().prototype))); 827 generator.emitJumpIfFalse(generator.emitBinaryOp<OpStricteq>(generator.newTemporary(), prototypeString.get(), propertyName.get(), OperandTypes(ResultType::stringType(), ResultType::stringType())), validPropertyNameLabel.get()); 828 generator.emitThrowTypeError("Cannot declare a static field named 'prototype'"); 829 generator.emitLabel(validPropertyNameLabel.get()); 830 } 812 831 813 832 RefPtr<RegisterID> scope = generator.emitResolveScope(nullptr, var); 814 generator.emitPutToScope(scope.get(), var, propertyName , ThrowIfNotFound, InitializationMode::ConstInitialization);833 generator.emitPutToScope(scope.get(), var, propertyName.get(), ThrowIfNotFound, InitializationMode::ConstInitialization); 815 834 } 816 835 … … 4947 4966 generator.emitCallDefineProperty(constructor.get(), prototypeNameRegister.get(), prototype.get(), nullptr, nullptr, 0, m_position); 4948 4967 4968 Vector<JSTextPosition> staticFieldLocations; 4949 4969 if (m_classElements) { 4950 4970 m_classElements->emitDeclarePrivateFieldNames(generator, generator.scopeRegister()); 4951 4971 4952 4972 Vector<JSTextPosition> instanceFieldLocations; 4953 generator.emitDefineClassElements(m_classElements, constructor.get(), prototype.get(), instanceFieldLocations );4973 generator.emitDefineClassElements(m_classElements, constructor.get(), prototype.get(), instanceFieldLocations, staticFieldLocations); 4954 4974 if (!instanceFieldLocations.isEmpty()) { 4955 RefPtr<RegisterID> instanceFieldInitializer = generator.emitNew InstanceFieldInitializerFunction(generator.newTemporary(), WTFMove(instanceFieldLocations), m_classHeritage);4975 RefPtr<RegisterID> instanceFieldInitializer = generator.emitNewClassFieldInitializerFunction(generator.newTemporary(), WTFMove(instanceFieldLocations), m_classHeritage); 4956 4976 4957 4977 // FIXME: Skip this if the initializer function isn't going to need a home object (no eval or super properties) … … 4963 4983 } 4964 4984 4965 if (m_needsLexicalScope) { 4966 if (!m_name.isNull()) { 4967 Variable classNameVar = generator.variable(m_name); 4968 RELEASE_ASSERT(classNameVar.isResolved()); 4969 RefPtr<RegisterID> scope = generator.emitResolveScope(nullptr, classNameVar); 4970 generator.emitPutToScope(scope.get(), classNameVar, constructor.get(), ThrowIfNotFound, InitializationMode::Initialization); 4971 } 4985 if (m_needsLexicalScope && !m_name.isNull()) { 4986 Variable classNameVar = generator.variable(m_name); 4987 RELEASE_ASSERT(classNameVar.isResolved()); 4988 RefPtr<RegisterID> scope = generator.emitResolveScope(nullptr, classNameVar); 4989 generator.emitPutToScope(scope.get(), classNameVar, constructor.get(), ThrowIfNotFound, InitializationMode::Initialization); 4990 } 4991 4992 if (!staticFieldLocations.isEmpty()) { 4993 RefPtr<RegisterID> staticFieldInitializer = generator.emitNewClassFieldInitializerFunction(generator.newTemporary(), WTFMove(staticFieldLocations), m_classHeritage); 4994 // FIXME: Skip this if the initializer function isn't going to need a home object (no eval or super properties) 4995 // https://bugs.webkit.org/show_bug.cgi?id=196867 4996 emitPutHomeObject(generator, staticFieldInitializer.get(), constructor.get()); 4997 4998 CallArguments args(generator, nullptr); 4999 generator.move(args.thisRegister(), constructor.get()); 5000 generator.emitCall(generator.newTemporary(), staticFieldInitializer.get(), NoExpectedFunction, args, position(), position(), position(), DebuggableCall::No); 5001 } 5002 5003 if (m_needsLexicalScope) 4972 5004 generator.popLexicalScope(this); 4973 }4974 5005 4975 5006 return generator.move(generator.finalDestination(dst, constructor.get()), constructor.get());
Note:
See TracChangeset
for help on using the changeset viewer.