Ignore:
Timestamp:
Apr 2, 2021, 2:20:45 PM (4 years ago)
Author:
Alexey Shvayka
Message:

Reduce bytecode instruction count emitted for class extends
https://bugs.webkit.org/show_bug.cgi?id=223884

Reviewed by Yusuke Suzuki.

JSTests:

  • ChakraCore/test/Error/validate_line_column.baseline-jsc:

Source/JavaScriptCore:

This patch adds a variant of globalFuncSetPrototypeDirect() that throws on
invalid Prototype values (instead of ignoring them) and utilizes it in
ClassExprNode::emitBytecode(), removing equivalent checks.

Throwing for invalid superclass.prototype value after setting the Prototype
of constructor is unobservable because it's a newly created extensible object
and superclass is a proven object.

The fact that Prototype set can throw only in case of superclass.prototype
allows keeping descriptive error message via custom appender. To find "extends"
in a source code, ClassExprNode is made an instance of ThrowableExpressionData.

This change reduces the number of emitted bytecodes by 4, and fixes IsConstructor's
error [1] to point to correct source code location.

[1]: https://tc39.es/ecma262/#sec-runtime-semantics-classdefinitionevaluation (step 5.f)

  • builtins/BuiltinNames.h:
  • bytecode/LinkTimeConstant.h:
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::emitDirectSetPrototypeOf):

  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/NodesCodegen.cpp:

(JSC::PropertyListNode::emitPutConstantProperty):
(JSC::ClassExprNode::emitBytecode):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createClassExpr):

  • parser/Nodes.h:
  • parser/Parser.cpp:

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

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::createClassExpr):

  • runtime/ExceptionHelpers.cpp:

(JSC::invalidPrototypeSourceAppender):
(JSC::createInvalidPrototypeError):

  • runtime/ExceptionHelpers.h:
  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::JSC_DEFINE_HOST_FUNCTION):

  • runtime/JSGlobalObjectFunctions.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/ASTBuilder.h

    r273225 r275439  
    413413
    414414    ClassExprNode* createClassExpr(const JSTokenLocation& location, const ParserClassInfo<ASTBuilder>& classInfo, VariableEnvironment& classEnvironment, ExpressionNode* constructor,
    415         ExpressionNode* parentClass, PropertyListNode* classElements)
     415        ExpressionNode* parentClass, PropertyListNode* classElements, const JSTextPosition& start, const JSTextPosition& divot, const JSTextPosition& end)
    416416    {
    417417        SourceCode source = m_sourceCode->subExpression(classInfo.startOffset, classInfo.endOffset, classInfo.startLine, classInfo.startColumn);
    418         return new (m_parserArena) ClassExprNode(location, *classInfo.className, source, classEnvironment, constructor, parentClass, classElements);
     418        ClassExprNode* node = new (m_parserArena) ClassExprNode(location, *classInfo.className, source, classEnvironment, constructor, parentClass, classElements);
     419        setExceptionLocation(node, start, divot, end);
     420        return node;
    419421    }
    420422
Note: See TracChangeset for help on using the changeset viewer.