Skip to content

Conversation

@Leko
Copy link
Contributor

@LekoLeko commented Nov 27, 2017

This is part of Nodefest's Code and Learn nodejs/code-and-learn#72

Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function

  • test/parallel/test-assert.js
  • test/parallel/test-domain-top-level-error-handler-clears-stack.js
  • test/parallel/test-querystring.js
  • test/parallel/test-whatwg-url-searchparams-getall.js
  • test/parallel/test-writeint.js
  • test/parallel/test-zerolengthbufferbug.js
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

Among the list of [Code and Learn](nodejs/code-and-learn#72 (comment)), I solved the unfinished task of replacing function with arrow function
@nodejs-github-botnodejs-github-bot added the test Issues and PRs related to the tests. label Nov 27, 2017
@vsemozhetbytvsemozhetbyt added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Nov 27, 2017
functionmakeBlock(f){
constargs=Array.prototype.slice.call(arguments,1);
returnfunction(){
return()=>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes this lexical. Is it OK here?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review.

I think that it is OK because test passed locally.
It is not called with neither .call nor .apply in this file.
This code equivalent to:

return()=>{returnf.apply(null,args);};

Should I replace this with null ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, for a clarity, but let's see what others think)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it.
Please let us know what others think.

// having an identical prototype property
constnbRoot={
toString: function(){return`${this.first}${this.last}`;}
toString: ()=>{return`${this.first}${this.last}`;}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review.
I was mistaken.

I'll fix this problem with like:

toString(){return`${this.first}${this.last}`;}

*/
/* eslint-disable */
test(function(){
test(()=>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the comment above, it seems we should not change this fragment.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifications to them should be upstreamed first.

I'm sorry to have missed it.
I'll revert changes in this file.

},'getAll() basics');

test(function(){
test(()=>{
Copy link
Contributor

@vsemozhetbytvsemozhetbytNov 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime.
These tests are copied from WPT. I should not changed it directly.
testAssertionMessage(/abc/gim,'/abc/gim');
testAssertionMessage(functionf(){},'[Function: f]');
testAssertionMessage(function(){},'[Function]');
testAssertionMessage(()=>{},'[Function]');
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it should be reverted because function(){} and () =>{} are should be tested both.
This PR changes only syntax, should not change test case.
So it better of separated by another PR.

What do you think about it ?

testAssertionMessage(/abc/gim,'/abc/gim');
testAssertionMessage(functionf(){},'[Function: f]');
testAssertionMessage(function(){},'[Function]');
testAssertionMessage(()=>{},'[Function]');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my humble opinion, this check would be better to not replace arrow function. Because assert message also should have '[Function]' when function(){} is input.
We would be better to check both function style arrow function and normal function.

makeBlock does not need `this`. update `this` with `null` to clarify the intent.
@mscdexmscdex added assert Issues and PRs related to the assert subsystem. domain Issues and PRs related to the domain subsystem. querystring Issues and PRs related to the built-in querystring module. labels Nov 27, 2017
@vsemozhetbyt
Copy link
Contributor

`function(){}` and `() =>{}` are should be tested both. See also #17345 (comment)
@vsemozhetbyt
Copy link
Contributor

@vsemozhetbyt
Copy link
Contributor

Hmm. It seems CI does not post status to PR currently.

@Leko
Copy link
ContributorAuthor

Leko commented Nov 27, 2017

Yesterday, status integration is worked fine.
What's happen ... ? 🤔

@Leko
Copy link
ContributorAuthor

Leko commented Nov 29, 2017

Hi @vsemozhetbyt.
Should I take any action to merge this PR ?

@vsemozhetbyt
Copy link
Contributor

@Leko Sorry for the delay. Let's run the CI again. If it is green, we will land it today.

https://ci.nodejs.org/job/node-test-pull-request/11798/

@Leko
Copy link
ContributorAuthor

Leko commented Nov 29, 2017

@vsemozhetbyt I got it. Thank you for quick reply !

@vsemozhetbyt
Copy link
Contributor

One CI failure seems unrelated. Landing...

vsemozhetbyt pushed a commit that referenced this pull request Nov 29, 2017
1. Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function: nodejs/code-and-learn#72 (comment) 2. Replace arrow function with shorter property syntax Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime. 3. Replace this with null makeBlock does not need `this`. update `this` with `null` to clarify the intent. PR-URL: #17345 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yosuke Furukawa <[email protected]>
@vsemozhetbyt
Copy link
Contributor

Squashed and landed in 3c62f33

Thank you, @Leko!

MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
1. Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function: nodejs/code-and-learn#72 (comment) 2. Replace arrow function with shorter property syntax Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime. 3. Replace this with null makeBlock does not need `this`. update `this` with `null` to clarify the intent. PR-URL: #17345 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yosuke Furukawa <[email protected]>
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
1. Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function: nodejs/code-and-learn#72 (comment) 2. Replace arrow function with shorter property syntax Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime. 3. Replace this with null makeBlock does not need `this`. update `this` with `null` to clarify the intent. PR-URL: #17345 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yosuke Furukawa <[email protected]>
@MylesBorinsMylesBorins mentioned this pull request Dec 12, 2017
gibfahn pushed a commit that referenced this pull request Dec 19, 2017
1. Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function: nodejs/code-and-learn#72 (comment) 2. Replace arrow function with shorter property syntax Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime. 3. Replace this with null makeBlock does not need `this`. update `this` with `null` to clarify the intent. PR-URL: #17345 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yosuke Furukawa <[email protected]>
@gibfahngibfahn mentioned this pull request Dec 20, 2017
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
1. Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function: nodejs/code-and-learn#72 (comment) 2. Replace arrow function with shorter property syntax Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime. 3. Replace this with null makeBlock does not need `this`. update `this` with `null` to clarify the intent. PR-URL: #17345 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yosuke Furukawa <[email protected]>
@gibfahngibfahn mentioned this pull request Dec 20, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assertIssues and PRs related to the assert subsystem.code-and-learnIssues related to the Code-and-Learn events and PRs submitted during the events.domainIssues and PRs related to the domain subsystem.querystringIssues and PRs related to the built-in querystring module.testIssues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@Leko@vsemozhetbyt@yosuke-furukawa@addaleax@maclover7@mscdex@gibfahn@nodejs-github-bot