Bug 147051 - Add support for new.target.
Summary: Add support for new.target.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-07-17 14:42 PDT by Keith Miller
Modified: 2015-07-21 13:23 PDT (History)
5 users (show)

See Also:


Attachments
Patch (11.37 KB, patch)
2015-07-17 14:54 PDT, Keith Miller
no flags Details | Formatted Diff | Diff
Patch (11.35 KB, patch)
2015-07-17 14:59 PDT, Keith Miller
ysuzuki: review-
Details | Formatted Diff | Diff
Patch (11.49 KB, patch)
2015-07-20 10:34 PDT, Keith Miller
no flags Details | Formatted Diff | Diff
Patch (11.49 KB, patch)
2015-07-20 10:37 PDT, Keith Miller
no flags Details | Formatted Diff | Diff
Patch (11.52 KB, patch)
2015-07-20 10:45 PDT, Keith Miller
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Keith Miller 2015-07-17 14:42:58 PDT
ES6 specifies a new expression new.target that is used to get the target of a "new" call, this is analogus to a this for constructors. For example, if someone called "new function Foo() { print(new.target) }" the resulting output would be the same as "print(Foo.toString())".
Comment 1 Keith Miller 2015-07-17 14:54:03 PDT
Created attachment 256992 [details]
Patch
Comment 2 WebKit Commit Bot 2015-07-17 14:55:56 PDT
Attachment 256992 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/ChangeLog:1:  ChangeLog entry has no bug number  [changelog/bugnumber] [5]
ERROR: Source/JavaScriptCore/parser/Parser.cpp:2918:  Missing space before ( in if(  [whitespace/parens] [5]
Total errors found: 2 in 10 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Keith Miller 2015-07-17 14:59:44 PDT
Created attachment 256994 [details]
Patch

Fixed a url issue.
Comment 4 Yusuke Suzuki 2015-07-18 14:57:08 PDT
Comment on attachment 256994 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256994&action=review

Looks nice! only few nits.

> Source/JavaScriptCore/parser/Parser.cpp:2929
> +    if (newCount && m_token.m_type == DOT) {

Let's use `match(DOT)`.

> Source/JavaScriptCore/parser/Parser.cpp:2931
> +        const Identifier* ident = m_token.m_data.ident;

Before extracting ident* from m_token, using `if (match(IDENT))` is preferable.
Comment 5 Saam Barati 2015-07-19 12:03:03 PDT
Comment on attachment 256994 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256994&action=review

> Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:190
> +RegisterID* TargetNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst)

Nit: Can we call this NewTargetNode?
Comment 6 Keith Miller 2015-07-20 10:34:59 PDT
Created attachment 257097 [details]
Patch

Made the changes recommended. Also, improved the error message if the user puts the wrong identifier after "new."
Comment 7 Keith Miller 2015-07-20 10:37:28 PDT
Created attachment 257098 [details]
Patch

Had an extra period in the error message.
Comment 8 Keith Miller 2015-07-20 10:45:40 PDT
Created attachment 257099 [details]
Patch

I realized that if I was going the node to NewTargetNode I should also change the expression generator to newTargetExpr.
Comment 9 Saam Barati 2015-07-20 12:00:37 PDT
Comment on attachment 257099 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=257099&action=review

> Source/JavaScriptCore/parser/ASTBuilder.h:183
> +    ExpressionNode* newTargetExpr(const JSTokenLocation location)

small nit: We usually try to name things that create AST nodes "createX".
So here, "createNewTargetNode" or "createNewTargetExpression".
Comment 10 Keith Miller 2015-07-20 12:21:41 PDT
Comment on attachment 257099 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=257099&action=review

>> Source/JavaScriptCore/parser/ASTBuilder.h:183
>> +    ExpressionNode* newTargetExpr(const JSTokenLocation location)
> 
> small nit: We usually try to name things that create AST nodes "createX".
> So here, "createNewTargetNode" or "createNewTargetExpression".

Is there a reason why thisExpr and superExpr don't follow this rule? I named my function "newTargetExpr" since new.target is similar to this but for constructors, so I was trying to emulate those functions.
Comment 11 Yusuke Suzuki 2015-07-20 17:32:46 PDT
Comment on attachment 257099 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=257099&action=review

>>> Source/JavaScriptCore/parser/ASTBuilder.h:183
>>> +    ExpressionNode* newTargetExpr(const JSTokenLocation location)
>> 
>> small nit: We usually try to name things that create AST nodes "createX".
>> So here, "createNewTargetNode" or "createNewTargetExpression".
> 
> Is there a reason why thisExpr and superExpr don't follow this rule? I named my function "newTargetExpr" since new.target is similar to this but for constructors, so I was trying to emulate those functions.

Ah, I guess they are just overlooked ones. Could you rename them to createThisExpr, createSuperExpr etc. at the same time?
Comment 12 Keith Miller 2015-07-21 09:50:33 PDT
Comment on attachment 257099 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=257099&action=review

>>>> Source/JavaScriptCore/parser/ASTBuilder.h:183
>>>> +    ExpressionNode* newTargetExpr(const JSTokenLocation location)
>>> 
>>> small nit: We usually try to name things that create AST nodes "createX".
>>> So here, "createNewTargetNode" or "createNewTargetExpression".
>> 
>> Is there a reason why thisExpr and superExpr don't follow this rule? I named my function "newTargetExpr" since new.target is similar to this but for constructors, so I was trying to emulate those functions.
> 
> Ah, I guess they are just overlooked ones. Could you rename them to createThisExpr, createSuperExpr etc. at the same time?

I'm not a huge fan of mixing new code with refactors, in case things get rolled out. I'll throw another patch up with that fix.
Comment 13 Yusuke Suzuki 2015-07-21 10:29:02 PDT
Comment on attachment 257099 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=257099&action=review

r+

>>>>> Source/JavaScriptCore/parser/ASTBuilder.h:183
>>>>> +    ExpressionNode* newTargetExpr(const JSTokenLocation location)
>>>> 
>>>> small nit: We usually try to name things that create AST nodes "createX".
>>>> So here, "createNewTargetNode" or "createNewTargetExpression".
>>> 
>>> Is there a reason why thisExpr and superExpr don't follow this rule? I named my function "newTargetExpr" since new.target is similar to this but for constructors, so I was trying to emulate those functions.
>> 
>> Ah, I guess they are just overlooked ones. Could you rename them to createThisExpr, createSuperExpr etc. at the same time?
> 
> I'm not a huge fan of mixing new code with refactors, in case things get rolled out. I'll throw another patch up with that fix.

Make sense.
Comment 14 WebKit Commit Bot 2015-07-21 11:20:00 PDT
Comment on attachment 257099 [details]
Patch

Clearing flags on attachment: 257099

Committed r187108: <http://trac.webkit.org/changeset/187108>
Comment 15 WebKit Commit Bot 2015-07-21 11:20:04 PDT
All reviewed patches have been landed.  Closing bug.
Comment 16 Keith Miller 2015-07-21 13:23:50 PDT
rdar://problem/21880884