Ignore:
Timestamp:
Jul 21, 2015, 11:18:42 AM (10 years ago)
Author:
[email protected]
Message:

Add support for the new.target syntax.
https://bugs.webkit.org/show_bug.cgi?id=147051

Patch by Keith Miller <[email protected]> on 2015-07-21
Reviewed by Yusuke Suzuki.

Add support for new.target. Essentially the implementation is, before constructor calls,
the target of a "new" is placed where "this" noramlly goes in the calling convention.
Then in the constructor before object is initialized we move the target of the "new"
into a local variable.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):

  • bytecompiler/NodesCodegen.cpp:

(JSC::NewTargetNode::emitBytecode):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::newTargetExpr):

  • parser/NodeConstructors.h:

(JSC::NewTargetNode::NewTargetNode):

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

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

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::newTargetExpr):

  • runtime/CommonIdentifiers.h:
  • tests/stress/new-target.js: Added.

(test):
(call):
(Constructor.subCall):
(Constructor.SubConstructor):
(Constructor):
(noAssign):
(doWeirdThings):
(SuperClass):
(SubClass):

File:
1 edited

Legend:

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

    r187014 r187108  
    28842884#endif
    28852885
     2886    bool baseIsNewTarget = false;
     2887    if (newCount && match(DOT)) {
     2888        next();
     2889        if (match(IDENT)) {
     2890            const Identifier* ident = m_token.m_data.ident;
     2891            if (m_vm->propertyNames->target == *ident) {
     2892                semanticFailIfFalse(currentScope()->isFunction(), "new.target is only valid inside functions");
     2893                baseIsNewTarget = true;
     2894                base = context.newTargetExpr(location);
     2895                newCount--;
     2896                next();
     2897            } else
     2898                failWithMessage("\"new.\" can only followed with target");
     2899        } else
     2900            failDueToUnexpectedToken();
     2901    }
     2902
    28862903    if (baseIsSuper) {
    28872904        base = context.superExpr(location);
    28882905        next();
    28892906        currentScope()->setNeedsSuperBinding();
    2890     } else
     2907    } else if (!baseIsNewTarget)
    28912908        base = parsePrimaryExpression(context);
    28922909
Note: See TracChangeset for help on using the changeset viewer.