diff --git a/.eslintignore b/.eslintignore index 38d3367e9d1779..a681716c667576 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,6 +4,7 @@ test/addons/??_*/ test/fixtures test/tmp*/ tools/eslint +tools/icu node_modules benchmark/tmp/ doc/**/*.js diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 6643b4649d0da5..b68d26574658c5 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -141,6 +141,7 @@ rules: }] no-tabs: error no-trailing-spaces: error + object-curly-spacing: [error, always] one-var-declaration-per-line: error operator-linebreak: [error, after] quotes: [error, single, avoid-escape] @@ -148,9 +149,9 @@ rules: semi-spacing: error space-before-blocks: [error, always] space-before-function-paren: [error, { - "anonymous": "never", - "named": "never", - "asyncArrow": "always" + anonymous: never, + named: never, + asyncArrow: always }] space-in-parens: [error, never] space-infix-ops: error diff --git a/.mailmap b/.mailmap index a2b1fce896f284..842d610df87b94 100644 --- a/.mailmap +++ b/.mailmap @@ -3,26 +3,36 @@ Aaron Heckmann Abe Fettig Akito Ito Alejandro Oviedo Garcia Alejandro Oviedo -Alex Hultman +Alex Hultman +Alex Jordan AJ Jordan Alex Kocharin Alex Kocharin +Alexander Marchenko axvm Alexey Kupershtokh Alexis Campailla Alexis Sellier Alexis Sellier +Alfred Cepeda ALJCepeda +Amery 子丶言 Andreas Offenhaeuser anoff Andy Bettisworth Angel Stoyanov atstojanov -Anna Henningsen +Anna Henningsen +Anna Magdalena Kedzierska AnnaMag Aria Stewart Arlo Breault +Arnaud Lefebvre BlackYoup Artem Zaytsev +Artur G Vieira Artur Vieira Arnout Kazemier <3rd-Eden@users.noreply.github.com> Asaf David asafdav2 Atsuo Fukaya Ben Lugavere blugavere -Ben Noordhuis +Ben Noordhuis +Ben Noordhuis Ben Taber +Benjamin Fleischer Benjamin Fleischer +Benjamin Gruenbaum Benjamin Waters Bert Belder Bert Belder @@ -30,7 +40,9 @@ Bert Belder Beth Griggs Bethany Griggs Beth Griggs Bethany N Griggs Beth Griggs BethGriggs +Bidisha Pyne Brad Decker brad-decker +Bradley Meck Bradley Farias Brandon Benvie Brandon Kobel kobelb Brendan Ashworth @@ -45,67 +57,88 @@ Charles Rudolph Chris Johnson Claudio Rodriguez Colin Ihrig +Christophe Naud-Dulude Chris911 Christopher Lenz Dan Kaplun Dan Williams Dan.Williams +Daniel Bevenius daniel.bevenius Daniel Berger Daniel Chcouri <333222@gmail.com> Daniel Gröber Daniel Gröber Daniel Pihlström -Daniel Wang +Daniel Wang firedfox +Daniel Wang firedfox Danny Nemer +Danny Nemer Dave Pacheco +David Cai DavidCai +David Mark Clements davidmarkclements +David Mark Clements davidmarkclements David Siegel +DC dcposch@dcpos.ch Domenic Denicola Domenic Denicola +Doug Wade doug.wade Eduard Burtescu Einar Otto Stangvik Elliott Cable Eric Phetteplace +Eugene Obrezkov ghaiklor EungJun Yi Evan Larkin Evan Lucas Evan Lucas FangDun Cai Fangdun Cai (Fundon) +Fangshi He hefangshi Farid Neshat Fedor Indutny Felix Böhm Felix Geisendörfer Felix Geisendörfer +Flandre Scarlet Flandre +Florian Margaine Florian MARGAINE Forrest L Norvell Friedemann Altrock Fuji Goro Gabriel de Perthuis +Gareth Ellis Gibson Fahnestock Gil Pedersen +Graham Fairweather Xotic750 Greg Sabia Tucker Hitesh Kanwathirtha Henry Chin Herbert Vojčík Icer Liang +Igor Savin kibertoad Igor Soarez Igor Zinkovsky -Imran Iqbal +Imran Iqbal Ionică Bizău Isaac Z. Schlueter Isaac Z. Schlueter Italo A. Casas -Jackson Tian +Jackson Tian Jake Verbaten +Jamen Marzonie Jamen Marz James Hartig James M Snell Jan Krems Jenna Vuong +JeongHoon Byun Outsider Jered Schmidt Jeremiah Senkpiel Jerry Chin +Jessica Quynh Tran jessicaquynh Jesús Leganés-Combarro 'piranna Jesús Leganés Combarro "piranna Joe Shaw Johan Bergström Johan Dahlberg Johann Hofmann John Barboza jBarz +John Barboza jBarz +John Gardner Alhadis Johnny Ray Austin Johnny Ray Jon Tippens legalcodes Jonas Pfenniger @@ -114,9 +147,13 @@ Jonathan Persson Jonathan Rentzsch Josh Erickson Joshua S. Weinstein +Joyee Cheung joyeecheung Juan Soto +Julien Klepatch jklepatch +Julien Waechter julien.waechter Junliang Yan Junliang Yan +Junshu Okamoto jun-oka Jérémy Lal Jérémy Lal Kai Sasaki Lewuathe @@ -125,38 +162,56 @@ Kathy Truong k3kathy Kazuyuki Yamada Keith M Wesolowski Kelsey Breseman +Kiyoshi Nomo kysnm Koichi Kobayashi Kris Kowal Kyle Robinson Young +Lakshmi Swetha Gopireddy LAKSHMI SWETHA GOPIREDDY Luke Bayes +Lydia Kats Lydia Katsamberis Maciej Małecki Malte-Thorben Bruns +Malte-Thorben Bruns skenqbx +Marcelo Gobelli decareano Marcin Cieślak Marcin Cieślak Marcin Zielinski marzelin Marti Martz Martial James Jefferson +Matt Lang matt-in-a-hat +Matthias Bastian piepmatz Mathias Buus Mathias Pettersson Matthew Lye Michael Bernstein +Michael Dawson Michael Wilber -Michaël Zasso +Michaël Zasso +Michael-Rainabba Richardson rainabba Micheil Smith Micleusanu Nicu +Miguel Angel Asencio Hurtado maasencioh Mikael Bourges-Sevenier +Minqi Pan P.S.V.R +Minwoo Jung JungMinu Miroslav Bajtoš Mitar Milutinovic Myles Borins Myles Borins Nebu Pookins +Netto Farah nettofarah Nicholas Kinsey Nikolai Vavilov +Noah Rose Ledesma Noah Rose +Noah Rose Ledesma Onne Gorter Paul Querna +Pedro Lima Pedro Victor +Pedro Lima Pedro lima Peter Flannery Phillip Johnsen Ratikesh Misra +Ravindra Barthwal Ravindra barthwal Ray Morgan Ray Solomon Raymond Feng @@ -169,8 +224,12 @@ Rod Machen Roman Klauke Roman Reiss Ron Korving +Ron Korving ronkorving Ryan Dahl Ryan Emery +Ryan Scheel Ryan Scheel +Ryan Scheel Ryan Scheel (Havvy) +Saad Quadri saadq Sakthipriyan Vairamani Sam Mikes Sam P Gallagher-Bishop @@ -180,6 +239,8 @@ Sambasiva Suda Sam Roberts San-Tai Hsu Santiago Gimeno +Sarah Meyer sarahmeyer +Sartrey Lee sartrey Scott Blomquist Segu Riluvan Sergey Kryzhanovsky @@ -188,21 +249,32 @@ Shigeki Ohtsu Shigeki Ohtsu Siddharth Mahendraker Simon Willison +Siobhan O'Donovan justshiv +solebox solebox <5013box@gmail.com> +Sreepurna Jasti +Sreepurna Jasti sreepurnajasti +Sreepurna Jasti sreepurnajasti Stanislav Opichal -Stefan Budeanu +Stefan Budeanu Stefan Bühler Steve Mao Steven R. Loomis Stewart X Addison Stewart Addison Stewart X Addison sxa555 Suramya shah ss22ever +Surya Panikkal surya panikkal +Surya Panikkal suryagh +Taehee Kang hugnosis Tanuja-Sawant +Taylor Woll taylor.woll +Thomas Watson Steen Thomas Watson Toby Stableford toboid Todd Kennedy TJ Holowaychuk TJ Holowaychuk Tadashi SAWADA Takahiro ANDO +Tarun Batra Tarun Ted Young Thomas Lee Thomas Reggi @@ -220,15 +292,21 @@ Viktor Karpov vitkarpov Vincent Voyer Vladimir de Turckheim vsemozhetbyt Vse Mozhet Byt +Wang Xinyong +Weijia Wang <381152119@qq.com> starkwang <381152119@qq.com> Willi Eggeling +xiaoyu <306766053@qq.com> Poker <306766053@qq.com> Yazhong Liu Yazhong Liu Yazhong Liu Yorkie Yazhong Liu Yorkie Yoshihiro KIKUCHI Yosuke Furukawa Yuichiro MASUI +Yuta Hiroto abouthiroppy +Zach Bjornson Zachary Scott Zoran Tomicic +Сковорода Никита Андреевич ChALkeR # These people didn't contribute patches to node directly, # but we've landed their v8 patches in the node repository: diff --git a/AUTHORS b/AUTHORS index ee864d2d8ff8db..977f3b619f4b00 100644 --- a/AUTHORS +++ b/AUTHORS @@ -611,7 +611,7 @@ Patrick Mooney Jicheng Li James Ferguson Julien Fontanet -Steven R. Loomis +Steven R. Loomis gyson Steve Sharp Victor Widell @@ -624,7 +624,6 @@ Ray Donnelly dead-horse Luis Reis sudodoki -Steven Loomis haoxin Artur Cistov MK Safi @@ -707,7 +706,7 @@ Shinnosuke Watanabe Bruno Jouhier René Kooi Petka Antonov -Ryan Scheel +Ryan Scheel Benjamin Gruenbaum Pavel Medvedev Russell Dempsey @@ -785,7 +784,7 @@ Sven Slootweg Dmitry Vasilyev Malcolm Ahoy Imran Iqbal -Stewart Addison +Stewart X Addison Matt Harrison Christopher J. Brody Salman Aljammaz @@ -971,10 +970,9 @@ James Lal Josh Leder Surya Panikkal vsemozhetbyt -Eugene Obrezkov Alex Lamar Ian Kronquist -DavidCai +David Cai Patrick Mueller Ben Page Juan Soto @@ -1088,7 +1086,7 @@ Paul Kiddie scott stern Danny Guo lrlna -matt-in-a-hat +Matt Lang Thomas van Lankveld Tarjei Husøy Wietse Venema @@ -1104,16 +1102,14 @@ Michael-Rainabba Richardson oogz Rene Weber Lauren Spiegel -Lydia Katsamberis +Lydia Kats mpmckenna8 nohmapp -Matt Lang Marc-Aurèle DARCHE fen Christopher Fujino Richard Hong Akito Ito -Lydia Kats Madhav Gharmalkar Mike Woods Daniel Stenberg @@ -1130,7 +1126,7 @@ Alex Jordan Mariusz 'koder' Chwalba Juan Andres Andrango larissayvette -jessicaquynh +Jessica Quynh Tran Ilya Frolov Tanuja-Sawant Bradley T. Hughes @@ -1141,7 +1137,6 @@ Marcin Zielinski Benji Marinacci Indrek Ardel Parambir Singh -maasencioh Niels Nielsen Marc Udoff Oliver Salzburg @@ -1155,7 +1150,7 @@ Gerges Beshay Isobel Redelmeier Brandon Kobel coderaiser -Pedro Victor +Pedro Lima Reza Akhavan Yangyang Liu Zeke Sikelianos @@ -1183,10 +1178,8 @@ Aaron Petcoff Rahat Ahmed monkick Adam Brunner -子丶言 atrioom Dan Koster -Pedro Lima Francis Gulotta Yosuke Saito mkamakura @@ -1202,6 +1195,7 @@ Ashton Kinslow Kevin Zurawel Wes Tyler shiya +Joyee Cheung Greg Valdez Bidur Adhikari Kyle Carter @@ -1226,14 +1220,13 @@ Jonathan Darling JDHarmon bjdelro Hitesh Kanwathirtha -davidmarkclements +David Mark Clements Cesar Hernandez Konstantin Likhter Richard Karmazin Hutson Betts Kent.Fan Jay Brownlee -Outsider Sarah Meyer Andreas Offenhaeuser Sean Villars @@ -1247,7 +1240,6 @@ Ethan Arrowood Dan Villa CodeTheInternet Eric Gonzalez -sxa555 rgoodwin Nigel Kibodeaux fmizzell @@ -1297,7 +1289,6 @@ James Tenenbaum pallxk Amar Zavery Prieto, Marcos -Joyee Cheung hveldstra Siddhartha Sahai Andy Chen @@ -1332,13 +1323,11 @@ René Schünemann Jeremy Yallop malen Kailean Courtney -sarahmeyer Fumiya KARASAWA John Barboza Paul Graham Nate Chris Story -Stewart X Addison Matthew Garrett David Goussev George Adams @@ -1362,7 +1351,6 @@ Josh Hollandsworth Sumit Goel stefan judis Mark -Jessica Quynh Tran Travis Meisenheimer Vinícius do Carmo Birunthan Mohanathas @@ -1384,7 +1372,6 @@ Umair Ishaq Timo Tijhof Sebastian Van Sande Daiki Arai -ALJCepeda Sebastian Roeder Toby Stableford Shubheksha Jalan @@ -1415,5 +1402,270 @@ Bradley Curran chiaki-yokoo Benjamin Fleischer maurice_hayward +Ali BARIN +Nemanja Stojanovic +Jeroen Mandersloot +Michael Cox +Clarence Dimitri CHARLES +Lukas Möller +Juwan Yoo +Matej Krajčovič +Alexander +Gaara +mr-spd +Christian d'Heureuse +Shahar Or +detailyang +liusi +Noj Vek +Ruslan Bekenev +Jyotman Singh +Lucas Lago +TheBeastOfCaerbannog +Morgan Brenner +Nick Peleh +Sorin Baltateanu +Chris Burkhart +Rj Bernaldo +John F. Mercer +Dejon "DJ" Gill +Ahmad Nassri +Tom Atkinson +Tobias Nießen +Joseph Gentle +Zero King +Raphael Okon +JR McEntee +Lovell Fuller +Jason Marsh +Vinay Hiremath +Gabriel Schulhof +alejandro +dave-k +Steven +Uppinder Chugh +Karl Cheng +Taylor Woll +Tarun Batra +Nao YONASHIRO +Christopher Luke +Sampson Gao +John Paul Bamberg +Cody Deckard +Fabio Campinho +Gautam krishna.R +Mateusz Konieczny +Sebastian Plesciuc +MapleUncle +Ahmed Taj elsir +Ivo von Putzer Reibegg +Alex Autem +kumarrishav +morrme +vperezma +Muhsin Abdul-Musawwir +thelady +Neehar Venugopal +WORMSS +Zahidul Islam +RobotMermaid +coreybeaumont +alohaglenn +weewey +Zuzana Svetlikova +Cameron Little +gwer +Walter Huang +Leo +Tony Rice +Olivier Martin +jeyanthinath +Aditya Anand +Oscar Martinez +cool88 +Steven Lehn +Łukasz Szewczak +Madara Uchiha +Gil Tayar +Glenn Schlereth +Artur G Vieira +Flarna +Sreepurna Jasti +Rafael Fragoso +Andrei Cioromila +Frank Lanitz +XadillaX +Akshay Iyer +Rick Bullotta +Rajaram Gaunker +Shadowbeetle +Chris Young +Ebrahim Byagowi +Timur Shemsedinov +Jesus Seijas +mskec +Peter Dave Hello +JongChan Choi +Yihong Wang +Ryan Kelly +Alexander O'Mara +James, please +Josh Ferge +Bidisha Pyne +David D Lowe +rmdm +Dávid Szakállas +JiaLi.Passion +Paul Bininda +Gautam Mittal <200mittalgautam@gmail.com> +Jamen Marzonie +Jacob Jones +Vladimir Trifonov +aniketshukla +realwakka +Gergely Nemeth +Samuel Reed +Anshul Guleria +Justin Beckwith +Scott McKenzie +Julien Klepatch +Dan Homola +Chris Young +cornholio <0@mcornholio.ru> +Tamás Hódi +DuanPengfei <2459714173@qq.com> +Ruben Bridgewater +Lakshmi Swetha Gopireddy +Rob Wu +Steven Winston +sallen450 +OriLev +Zongmin Lei +lena +Azard <330815461@qq.com> +Ezequiel Garcia +Kyle Farnung +Weijia Wang <381152119@qq.com> +Nataly Shrits +Jaime Bernardo +Natanael Log +MoonBall +kuroljov +Matt Sergeant +Eduardo Leggiero +Moogen Tian +Jimmy Thomson +David Drysdale +Roman Shoryn +Peter Czibik +章礼平 +Fraser Xu +Song, Bintao Garfield +Flandre Scarlet +akira.xue +Bang Wu +kadoufall +jiangplus +tobewhatwewant +blade254353074 +weiyuanyue +xinglong.wangwxl +vercent deng +boydfd +Superwoods +shaman +Zhang Weijie +Gunar C. Gessner +SkyAo +Devin Boyer +Helianthus21 <740051540@qq.com> +Oleksandr Kushchak +Nathan Jiang +mac-haojin +jkzing +zzz +Henry +Gautam Arora +Marc Hernández Cabot +Vincent Xue +Bougarfaoui El houcine +ziyun +Lyall Sun +Marcelo Gobelli +Sebastiaan Deckers +nanaya +xeodou +Peter Marshall +笑斌 +atever +vixony +Ching Hsu +rockcoder23 +Anton Paras +Pratik Jain +Shivanth MP +Kunal Pathak +erdun <494251936@qq.com> +Jiajie Hu +Matt Woicik +Franziska Hinkelmann +alexbostock +Matthew Alsup +Greg Alexander +dcharbonnier +Jared Kantrowitz +Guy Margalit +Azard +nishijayaraj +Nick Stanish +Mandeep Singh +Prakash Palaniappan +Keita Akutsu +Michael Albert +Eugene Ostroukhov +Vishal Bisht +Griffith Tchenpan +Oky Antoro +icarter09 +Pini Houri +Runite618 +phisixersai +hsmtkk +Miroslav Bajtoš +Sebastian Murphy +陈刚 +Jon Moss +George Sapkin +Aleh Zasypkin +Anand Suresh +sharababy +Abhishek Raj +Daniel Taveras +RefinedSoftwareLLC +Ankit Parashar +James Kyle +Daniil Shakir +sevenryze +hafiz +Kyle Lamse +Michał Wadas +Mohd Maqbool Alam +Ian Perkins +Jimmy Cann +Dave Olszewski +Anatoli Papirovski +Simon Brewster +creeperyang +Roy Marples +Piotr Mionskowski +Cyril Lakech +Eduard Bondarenko +Adina Shanholtz +Miguel Martins +Yury Popov +George Bezerra +Benjamin Coe +Tim Costa +Rahul Mishra # Generated by tools/update-authors.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b1e4c96ca8652..fe69f4fffd3272 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,8 @@ release. -8.5.0
+8.6.0
+8.5.0
8.4.0
8.3.0
8.2.1
diff --git a/COLLABORATOR_GUIDE.md b/COLLABORATOR_GUIDE.md index 5aa0fb49cd68a6..bded8a56d5c5d4 100644 --- a/COLLABORATOR_GUIDE.md +++ b/COLLABORATOR_GUIDE.md @@ -88,6 +88,12 @@ All pull requests that modify executable code should be subjected to continuous integration tests on the [project CI server](https://ci.nodejs.org/). +If any Collaborator objects to a change *without giving any additional +explanation or context*, and the objecting Collaborator fails to respond to +explicit requests for explanation or context within a reasonable period of +time, the objection may be dismissed. Note that this does not apply to +objections that are explained. + #### Useful CI Jobs * [`node-test-pull-request`](https://ci.nodejs.org/job/node-test-pull-request/) @@ -279,8 +285,8 @@ introduces the new core module. Pull requests introducing new core modules: * Must be left open for at least one week for review. -* Must be labeled using the `ctc-review` label. -* Must have signoff from at least two CTC members. +* Must be labeled using the `tsc-review` label. +* Must have signoff from at least two TSC members. New core modules must be landed with a [Stability Index][] of Experimental, and must remain Experimental until a semver-major release. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7f9bd33e055db1..26b083b867395d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,44 +1,215 @@ # Contributing to Node.js +Contributions to Node.js may come in many forms. Some contribute code changes, +others contribute docs, others help answer questions from users, help keep the +infrastructure running, or seek out ways of advocating for Node.js users of all +types. + +The Node.js project welcomes all contributions from anyone willing to work in +good faith both with other contributors and with the community. No contribution +is too small and all contributions are valued. + +This guide details the basic steps for getting started contributing to the +Node.js project's core `nodejs/node` GitHub Repository and describes what to +expect throughout each step of the process. + +* [Code of Conduct](#code-of-conduct) + * [Bad Actors](#bad-actors) +* [Issues](#issues) + * [Asking for General Help](#asking-for-general-help) + * [Discussing non-technical topics](#discussing-non-technical-topics) + * [Submitting a Bug Report](#submitting-a-bug-report) + * [Triaging a Bug Report](#triaging-a-bug-report) + * [Resolving a Bug Report](#resolving-a-bug-report) +* [Pull Requests](#pull-requests) + * [Dependencies](#dependencies) + * [Setting up your local environment](#setting-up-your-local-environment) + * [Step 1: Fork](#step-1-fork) + * [Step 2: Branch](#step-2-branch) + * [The Process of Making Changes](#the-process-of-making-changes) + * [Step 3: Code](#step-3-code) + * [Step 4: Commit](#step-4-commit) + * [Commit message guidelines](#commit-message-guidelines) + * [Step 5: Rebase](#step-5-rebase) + * [Step 6: Test](#step-6-test) + * [Step 7: Push](#step-7-push) + * [Step 8: Opening the Pull Request](#step-8-opening-the-pull-request) + * [Step 9: Discuss and Update](#step-9-discuss-and-update) + * [Approval and Request Changes Workflow](#approval-and-request-changes-workflow) + * [Step 10: Landing](#step-10-landing) + * [Reviewing Pull Requests](#reviewing-pull-requests) + * [Review a bit at a time](#review-a-bit-at-a-time) + * [Be aware of the person behind the code](#be-aware-of-the-person-behind-the-code) + * [Respect the minimum wait time for comments](#respect-the-minimum-wait-time-for-comments) + * [Abandoned or Stalled Pull Requests](#abandoned-or-stalled-pull-requests) + * [Approving a change](#approving-a-change) + * [Accept that there are different opinions about what belongs in Node.js](#accept-that-there-are-different-opinions-about-what-belongs-in-nodejs) + * [Performance is not everything](#performance-is-not-everything) + * [Continuous Integration Testing](#continuous-integration-testing) +* [Additional Notes](#additional-notes) + * [Commit Squashing](#commit-squashing) + * [Getting Approvals for your Pull Request](#getting-approvals-for-your-pull-request) + * [CI Testing](#ci-testing) + * [Waiting Until the Pull Request Gets Landed](#waiting-until-the-pull-request-gets-landed) + * [Check Out the Collaborator's Guide](#check-out-the-collaborators-guide) + * [Helpful Resources](#helpful-resources) +* [Developer's Certificate of Origin 1.1](#developers-certificate-of-origin-11) + ## Code of Conduct -Please read the -[Code of Conduct](https://github.com/nodejs/TSC/blob/master/CODE_OF_CONDUCT.md) -which explains the minimum behavior expectations for Node.js contributors. +The Node.js project has a [Code of Conduct][] that *all* contributors are +expected to follow. This code describes the *minimum* behavior expectations +for all contributors. -## Issue Contributions +As a contributor to Node.js, how you choose to act and interact towards your +fellow contributors, as well as to the community, will reflect back not only +on yourself but on the project as a whole. The Code of Conduct is designed and +intended, above all else, to help establish a culture within the project that +allows anyone and everyone who wants to contribute to feel safe doing so. -When opening issues or commenting on existing issues, please make sure -discussions are related to concrete technical issues with Node.js. +Should any individual act in any way that is considered in violation of the +[Code of Conduct][], corrective actions will be taken. It is possible, however, +for any individual to *act* in such a manner that is not in violation of the +strict letter of the Code of Conduct guidelines while still going completely +against the spirit of what that Code is intended to accomplish. -* For general help using Node.js, please file an issue at the -[Node.js help repository](https://github.com/nodejs/help/issues). +Open, diverse and inclusive communities live and die on the basis of trust. +Contributors can disagree with one another so long as they trust that those +disagreements are in good faith and everyone is working towards a common goal. -* Discussion of non-technical topics (such as intellectual property and -trademark) should use the -[Technical Steering Committee (TSC) repository](https://github.com/nodejs/TSC/issues). +### Bad actors -## Code Contributions +All contributors to Node.js tacitly agree to abide by both the letter and +spirit of the [Code of Conduct][]. Failure, or unwillingness, to do so will +result in contributions being respectfully declined. -This section will guide you through the contribution process. +A *bad actor* is someone who repeatedly violates the *spirit* of the Code of +Conduct through consistent failure to self-regulate the way in which they +interact with other contributors in the project. In doing so, bad actors +alienate other contributors, discourage collaboration, and generally reflect +poorly on the project as a whole. -### Step 1: Fork +Being a bad actor may be intentional or unintentional. Typically, unintentional +bad behavior can be easily corrected by being quick to apologize and correct +course *even if you are not entirely convinced you need to*. Giving other +contributors the benefit of the doubt and having a sincere willingness to admit +that you *might* be wrong is critical for any successful open collaboration. -Fork the project [on GitHub](https://github.com/nodejs/node) and clone your fork -locally. +Don't be a bad actor. -```text -$ git clone git@github.com:username/node.git -$ cd node -$ git remote add upstream https://github.com/nodejs/node.git +## Issues + +Issues in `nodejs/node` are the primary means by which bug reports and +general discussions are made. For any issue, there are fundamentally three +ways an individual can contribute: + +1. By opening the issue for discussion: For instance, if you believe that you + have uncovered a bug in Node.js, creating a new issue in the `nodejs/node` + issue tracker is the way to report it. +2. By helping to triage the issue: This can be done either by providing + supporting details (a test case that demonstrates a bug), or providing + suggestions on how to address the issue. +3. By helping to resolve the issue: Typically this is done either in the form + of demonstrating that the issue reported is not a problem after all, or more + often, by opening a Pull Request that changes some bit of something in + `nodejs/node` in a concrete and reviewable manner. + +### Asking for General Help + +Because the level of activity in the `nodejs/node` repository is so high, +questions or requests for general help using Node.js should be directed at +the [Node.js help repository][]. + +### Discussing non-technical topics + +Discussion of non-technical topics (such as intellectual property and trademark) +should be directed to the [Technical Steering Committee (TSC) repository][]. + +### Submitting a Bug Report + +When opening a new issue in the `nodejs/node` issue tracker, users will be +presented with a basic template that should be filled in. + +```markdown + + +* **Version**: +* **Platform**: +* **Subsystem**: + + ``` -#### Which branch? +If you believe that you have uncovered a bug in Node.js, please fill out this +form, following the template to the best of your ability. Do not worry if you +cannot answer every detail, just fill in what you can. + +The two most important pieces of information we need in order to properly +evaluate the report is a description of the behavior you are seeing and a simple +test case we can use to recreate the problem on our own. If we cannot recreate +the issue, it becomes impossible for us to fix. -For developing new features and bug fixes, the `master` branch should be pulled -and built upon. +In order to rule out the possibility of bugs introduced by userland code, test +cases should be limited, as much as possible, to using *only* Node.js APIs. +If the bug occurs only when you're using a specific userland module, there is +a very good chance that either (a) the module has a bug or (b) something in +Node.js changed that broke the module. -#### Dependencies +### Triaging a Bug Report + +Once an issue has been opened, it is not uncommon for there to be discussion +around it. Some contributors may have differing opinions about the issue, +including whether the behavior being seen is a bug or a feature. This discussion +is part of the process and should be kept focused, helpful and professional. + +Short, clipped responses—that provide neither additional context nor supporting +detail—are not helpful or professional. To many, such responses are simply +annoying and unfriendly. + +Contributors are encouraged to help one another make forward progress as much +as possible, empowering one another to solve issues collaboratively. If you +choose to comment on an issue that you feel either is not a problem that needs +to be fixed, or if you encounter information in an issue that you feel is +incorrect, explain *why* you feel that way with additional supporting context, +and be willing to be convinced that you may be wrong. By doing so, we can often +reach the correct outcome much faster. + +### Resolving a Bug Report + +In the vast majority of cases, issues are resolved by opening a Pull Request. +The process for opening and reviewing a Pull Request is similar to that of +opening and triaging issues, but carries with it a necessary review and approval +workflow that ensures that the proposed changes meet the minimal quality and +functional guidelines of the Node.js project. + +## Pull Requests + +Pull Requests are the way in which concrete changes are made to the code, +documentation, dependencies, and tools contained with the `nodejs/node` +repository. + +There are two fundamental components of the Pull Request process: one concrete +and technical, and one more process oriented. The concrete and technical +component involves the specific details of setting up your local environment +so that you can make the actual changes. This is where we will start. + +### Dependencies Node.js has several bundled dependencies in the *deps/* and the *tools/* directories that are not part of the project proper. Changes to files in those @@ -54,36 +225,80 @@ questions, and [#Node-dev](http://webchat.freenode.net/?channels=node-dev) for development of Node.js core specifically. -### Step 2: Branch +### Setting up your local environment + +To get started, you will need to have `git` installed locally. Depending on +your operating system, there are also a number of other dependencies required. +These are detailed in the [Building guide][]. + +Once you have `git` and are sure you have all of the necessary dependencies, +it's time to create a fork. -Create a branch and start hacking: +Before getting started, it is recommended to configure `git` so that it knows +who you are: ```text -$ git checkout -b my-branch -t origin/master +$ git config --global user.name "J. Random User" +$ git config --global user.email "j.random.user@example.com" ``` -Any text you write should follow the [Style Guide](doc/STYLE_GUIDE.md), -including comments and API documentation. +#### Step 1: Fork + +Fork the project [on GitHub](https://github.com/nodejs/node) and clone your fork +locally. + +```text +$ git clone git@github.com:username/node.git +$ cd node +$ git remote add upstream https://github.com/nodejs/node.git +$ git fetch upstream +``` -### Step 3: Commit +#### Step 2: Branch -Make sure git knows your name and email address: +As a best practice to keep your development environment as organized as +possible, create local branches to work within. These should also be created +directly off of the `master` branch. ```text -$ git config --global user.name "J. Random User" -$ git config --global user.email "j.random.user@example.com" +$ git checkout -b my-branch -t upstream/master ``` -Add and commit: +### The Process of Making Changes + +#### Step 3: Code + +The vast majority of Pull Requests opened against the `nodejs/node` +repository includes changes to either the C/C++ code contained in the `src` +directory, the JavaScript code contained in the `lib` directory, the +documentation in `docs/api` or tests within the `test` directory. + +If you are modifying code, please be sure to run `make lint` from time to +time to ensure that the changes follow the Node.js code style guide. + +Any documentation you write (including code comments and API documentation) +should follow the [Style Guide](doc/STYLE_GUIDE.md). Code samples included +in the API docs will also be checked when running `make lint` (or +`vcbuild.bat lint` on Windows). + +#### Step 4: Commit + +It is a recommended best practice to keep your changes as logically grouped +as possible within individual commits. There is no limit to the number of +commits any single Pull Request may have, and many contributors find it easier +to review changes that are split across multiple commits. ```text $ git add my/changed/files $ git commit ``` -### Commit message guidelines +Note that multiple commits often get squashed when they are landed (see the +notes about [commit squashing](#commit-squashing)). -The commit message should describe what changed and why. +##### Commit message guidelines + +A good commit message should describe what changed and why. 1. The first line should: - contain a short description of the change @@ -129,9 +344,16 @@ Fixes: https://github.com/nodejs/node/issues/1337 Refs: http://eslint.org/docs/rules/space-in-parens.html ``` -### Step 4: Rebase +If you are new to contributing to Node.js, please try to do your best at +conforming to these guidelines, but do not worry if you get something wrong. +One of the existing contributors will help get things situated and the +contributor landing the Pull Request will ensure that everything follows +the project guidelines. + +#### Step 5: Rebase -Use `git rebase` (not `git merge`) to synchronize your work with the main +As a best practice, once you have committed your changes, it is a good idea +to use `git rebase` (not `git merge`) to synchronize your work with the main repository. ```text @@ -139,20 +361,29 @@ $ git fetch upstream $ git rebase upstream/master ``` -### Step 5: Test +This ensures that your working branch has the latest changes from `nodejs/node` +master. -Bug fixes and features should come with tests. Read the -[guide for writing tests in Node.js](./doc/guides/writing-tests.md). Looking at -other tests to see how they should be structured can also help. Add your -tests in the `test/parallel/` directory if you are unsure where to put them. +#### Step 6: Test -To run the tests (including code linting) on Unix / macOS: +Bug fixes and features should always come with tests. A +[guide for writing tests in Node.js](./doc/guides/writing-tests.md) has been +provided to make the process easier. Looking at other tests to see how they +should be structured can also help. + +The `test` directory within the `nodejs/node` repository is complex and it is +often not clear where a new test file should go. When in doubt, add new tests +to the `test/parallel/` directory and the right location will be sorted out +later. + +Before submitting your changes in a Pull Request, always run the full Node.js +test suite. To run the tests (including code linting) on Unix / macOS: ```text $ ./configure && make -j4 test ``` -Windows: +And on Windows: ```text > vcbuild test @@ -189,24 +420,59 @@ $ ./node ./test/parallel/test-stream2-transform.js Remember to recompile with `make -j4` in between test runs if you change code in the `lib` or `src` directories. -### Step 6: Push +#### Step 7: Push + +Once you are sure your commits are ready to go, with passing tests and linting, +begin the process of opening a Pull Request by pushing your working branch to +your fork on GitHub. ```text $ git push origin my-branch ``` -Pull requests are usually reviewed within a few days. +#### Step 8: Opening the Pull Request -### Step 7: Discuss and update +From within GitHub, opening a new Pull Request will present you with a template +that should be filled out: -You will probably get feedback or requests for changes to your Pull Request. -This is a big part of the submission process so don't be discouraged! +```markdown + + +##### Checklist + + +- [ ] `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes +- [ ] tests and/or benchmarks are included +- [ ] documentation is changed or added +- [ ] commit message follows [commit guidelines](https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#commit-message-guidelines) + +##### Affected core subsystem(s) + +``` + +Please try to do your best at filling out the details, but feel free to skip +parts if you're not sure what to put. -To make changes to an existing Pull Request, make the changes to your branch. -When you push that branch to your fork, GitHub will automatically update the -Pull Request. +Once opened, Pull Requests are usually reviewed within a few days. -You can push more commits to your branch: +#### Step 9: Discuss and update + +You will probably get feedback or requests for changes to your Pull Request. +This is a big part of the submission process so don't be discouraged! Some +contributors may sign off on the Pull Request right away, others may have +more detailed comments or feedback. This is a necessary part of the process +in order to evaluate whether the changes are correct and necessary. + +To make changes to an existing Pull Request, make the changes to your local +branch, add a new commit with those changes, and push those to your fork. +GitHub will automatically update the Pull Request. ```text $ git add my/changed/files @@ -214,7 +480,8 @@ $ git commit $ git push origin my-branch ``` -Or you can rebase against master: +It is also frequently necessary to synchronize your Pull Request with other +changes that have landed in `master` by using `git rebase`: ```text $ git fetch --all @@ -222,8 +489,13 @@ $ git rebase origin/master $ git push --force-with-lease origin my-branch ``` -Or you can amend the last commit (for example if you want to change the commit -log). +**Important:** The `git push --force-with-lease` command is one of the few ways +to delete history in `git`. Before you use it, make sure you understand the +risks. If in doubt, you can always ask for guidance in the Pull Request or on +[IRC in the #node-dev channel][]. + +If you happen to make a mistake in any of your commits, do not worry. You can +amend the last commit (for example if you want to change the commit log). ```text $ git add any/changed/files @@ -231,28 +503,39 @@ $ git commit --amend $ git push --force-with-lease origin my-branch ``` -**Important:** The `git push --force-with-lease` command is one of the few ways -to delete history in git. Before you use it, make sure you understand the risks. -If in doubt, you can always ask for guidance in the Pull Request or on -[IRC in the #node-dev channel](https://webchat.freenode.net?channels=node-dev&uio=d4). +There are a number of more advanced mechanisms for managing commits using +`git rebase` that can be used, but are beyond the scope of this guide. Feel free to post a comment in the Pull Request to ping reviewers if you are awaiting an answer on something. If you encounter words or acronyms that seem unfamiliar, refer to this [glossary](https://sites.google.com/a/chromium.org/dev/glossary). -Note that multiple commits often get squashed when they are landed (see the -notes about [commit squashing](#commit-squashing)). +##### Approval and Request Changes Workflow -### Step 8: Landing +All Pull Requests require "sign off" in order to land. Whenever a contributor +reviews a Pull Request they may find specific details that they would like to +see changed or fixed. These may be as simple as fixing a typo, or may involve +substantive changes to the code you have written. In general, such requests +are intended to be helpful, but at times may come across as abrupt or unhelpful, +especially requests to change things that do not include concrete suggestions +on *how* to change them. -In order to land, a Pull Request needs to be reviewed and -[approved](#getting-approvals-for-your-pull-request) by +Try not to be discouraged. If you feel that a particular review is unfair, +say so, or contact one of the other contributors in the project and seek their +input. Often such comments are the result of the reviewer having only taken a +short amount of time to review and are not ill-intended. Such issues can often +be resolved with a bit of patience. That said, reviewers should be expected to +be helpful in their feedback, and feedback that is simply vague, dismissive and +unhelpful is likely safe to ignore. + +#### Step 10: Landing + +In order to land, a Pull Request needs to be reviewed and [approved][] by at least one Node.js Collaborator and pass a -[CI (Continuous Integration) test run](#ci-testing). -After that, as long as there are no objections -from a Collaborator, the Pull Request can be merged. If you find your -Pull Request waiting longer than you expect, see the +[CI (Continuous Integration) test run][]. After that, as long as there are no +objections from other contributors, the Pull Request can be merged. If you find +your Pull Request waiting longer than you expect, see the [notes about the waiting time](#waiting-until-the-pull-request-gets-landed). When a collaborator lands your Pull Request, they will post @@ -262,11 +545,178 @@ point, but don't worry. If you look at the branch you raised your Pull Request against (probably `master`), you should see a commit with your name on it. Congratulations and thanks for your contribution! +### Reviewing Pull Requests + +All Node.js contributors who choose to review and provide feedback on Pull +Requests have a responsibility to both the project and the individual making the +contribution. Reviews and feedback must be helpful, insightful, and geared +towards improving the contribution as opposed to simply blocking it or +stopping it. If there are reasons why you feel the PR should not land, explain +what those are. Do not expect to be able to block a Pull Request from advancing +simply because you say "No" without giving an explanation. It is also important +to be open to having your mind changed, and to being open to working with the +contributor to make the Pull Request better. + +Reviews that are dismissive or disrespectful of the contributor or any other +reviewers are strictly counter to the [Code of Conduct][]. + +When reviewing a Pull Request, the primary goals are for the codebase to improve +and for the person submitting the request to succeed. Even if a Pull Request +does not land, the submitters should come away from the experience feeling like +their effort was not wasted or unappreciated. Every Pull Request from a new +contributor is an opportunity to grow the community. + +#### Review a bit at a time. + +Do not overwhelm new contributors. + +It is tempting to micro-optimize and make everything about relative performance, +perfect grammar, or exact style matches. Do not succumb to that temptation. + +Focus first on the most significant aspects of the change: + +1. Does this change make sense for Node.js? +2. Does this change make Node.js better, even if only incrementally? +3. Are there clear bugs or larger scale issues that need attending to? + +When changes are necessary, *request* them, do not *demand* them, and do not +assume that the submitter already knows how to add a test or run a benchmark. + +Specific performance optimization techniques, coding styles and conventions +change over time. The first impression you give to a new contributor never does. + +Nits (requests for small changes that are not essential) are fine, but try to +avoid stalling the Pull Request. Most nits can typically be fixed by the +Node.js Collaborator landing the Pull Request but they can also be an +opportunity for the contributor to learn a bit more about the project. + +It is always good to clearly indicate nits when you comment: e.g. +`Nit: change foo() to bar(). But this is not blocking.` + +#### Be aware of the person behind the code + +Be aware that *how* you communicate requests and reviews in your feedback can +have a significant impact on the success of the Pull Request. Yes, we may land +a particular change that makes Node.js better, but the individual might just +not want to have anything to do with Node.js ever again. The goal is not just +having good code. + +#### Respect the minimum wait time for comments + +There is a minimum waiting time which we try to respect for non-trivial +changes, so that people who may have important input in such a distributed +project are able to respond. + +For non-trivial changes, Pull Requests must be left open for *at least* 48 +hours during the week, and 72 hours on a weekend. In most cases, when the +PR is relatively small and focused on a narrow set of changes, these periods +provide more than enough time to adequately review. Sometimes changes take far +longer to review, or need more specialized review from subject matter experts. +When in doubt, do not rush. + +Trivial changes, typically limited to small formatting changes or fixes to +documentation, may be landed within the minimum 48 hour window. + +#### Abandoned or Stalled Pull Requests + +If a Pull Request appears to be abandoned or stalled, it is polite to first +check with the contributor to see if they intend to continue the work before +checking if they would mind if you took it over (especially if it just has +nits left). When doing so, it is courteous to give the original contributor +credit for the work they started (either by preserving their name and email +address in the commit log, or by using an `Author: ` meta-data tag in the +commit. + +#### Approving a change + +Any Node.js core Collaborator (any GitHub user with commit rights in the +`nodejs/node` repository) is authorized to approve any other contributor's +work. Collaborators are not permitted to approve their own Pull Requests. + +Collaborators indicate that they have reviewed and approve of the changes in +a Pull Request either by using GitHub's Approval Workflow, which is preferred, +or by leaving an `LGTM` ("Looks Good To Me") comment. + +When explicitly using the "Changes requested" component of the GitHub Approval +Workflow, show empathy. That is, do not be rude or abrupt with your feedback +and offer concrete suggestions for improvement, if possible. If you're not +sure *how* a particular change can be improved, say so. + +Most importantly, after leaving such requests, it is courteous to make yourself +available later to check whether your comments have been addressed. + +If you see that requested changes have been made, you can clear another +collaborator's `Changes requested` review. + +Change requests that are vague, dismissive, or unconstructive may also be +dismissed if requests for greater clarification go unanswered within a +reasonable period of time. + +If you do not believe that the Pull Request should land at all, use +`Changes requested` to indicate that you are considering some of your comments +to block the PR from landing. When doing so, explain *why* you believe the +Pull Request should not land along with an explanation of what may be an +acceptable alternative course, if any. + +#### Accept that there are different opinions about what belongs in Node.js + +Opinions on this vary, even among the members of the Technical Steering +Committee. + +One general rule of thumb is that if Node.js itself needs it (due to historic +or functional reasons), then it belongs in Node.js. For instance, `url` +parsing is in Node.js because of HTTP protocol support. + +Also, functionality that either cannot be implemented outside of core in any +reasonable way, or only with significant pain. + +It is not uncommon for contributors to suggest new features they feel would +make Node.js better. These may or may not make sense to add, but as with all +changes, be courteous in how you communicate your stance on these. Comments +that make the contributor feel like they should have "known better" or +ridiculed for even trying run counter to the [Code of Conduct][]. + +#### Performance is not everything + +Node.js has always optimized for speed of execution. If a particular change +can be shown to make some part of Node.js faster, it's quite likely to be +accepted. Claims that a particular Pull Request will make things faster will +almost always be met by requests for performance [benchmark results][] that +demonstrate the improvement. + +That said, performance is not the only factor to consider. Node.js also +optimizes in favor of not breaking existing code in the ecosystem, and not +changing working functional code just for the sake of changing. + +If a particular Pull Request introduces a performance or functional +regression, rather than simply rejecting the Pull Request, take the time to +work *with* the contributor on improving the change. Offer feedback and +advice on what would make the Pull Request acceptable, and do not assume that +the contributor should already know how to do that. Be explicit in your +feedback. + +#### Continuous Integration Testing + +All Pull Requests that contain changes to code must be run through +continuous integration (CI) testing at [https://ci.nodejs.org/][]. + +Only Node.js core Collaborators with commit rights to the `nodejs/node` +repository may start a CI testing run. The specific details of how to do +this are included in the new Collaborator [Onboarding guide][]. + +Ideally, the code change will pass ("be green") on all platform configurations +supported by Node.js (there are over 30 platform configurations currently). +This means that all tests pass and there are no linting errors. In reality, +however, it is not uncommon for the CI infrastructure itself to fail on +specific platforms or for so-called "flaky" tests to fail ("be red"). It is +vital to visually inspect the results of all failed ("red") tests to determine +whether the failure was caused by the changes in the Pull Request. + ## Additional Notes ### Commit Squashing -When the commits in your Pull Request land, they will be squashed +When the commits in your Pull Request land, they may be squashed into one commit per logical change. Metadata will be added to the commit message (including links to the Pull Request, links to relevant issues, and the names of the reviewers). The commit history of your Pull Request, @@ -317,6 +767,14 @@ If you want to know more about the code review and the landing process, you can take a look at the [collaborator's guide](https://github.com/nodejs/node/blob/master/COLLABORATOR_GUIDE.md). +### Helpful Resources + +The following additional resources may be of assistance: + +* [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) +* [core-validate-commit](https://github.com/evanlucas/core-validate-commit) - + A utility that ensures commits follow the commit formatting guidelines. + ## Developer's Certificate of Origin 1.1 @@ -343,3 +801,17 @@ By making a contribution to this project, I certify that: personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. + +[approved]: #getting-approvals-for-your-pull-request +[benchmark results]: ./doc/guides/writing-and-running-benchmarks.md +[Building guide]: ./BUILDING.md +[CI (Continuous Integration) test run]: #ci-testing +[Code of Conduct]: https://github.com/nodejs/TSC/blob/master/CODE_OF_CONDUCT.md +[guide for writing tests in Node.js]: ./doc/guides/writing-tests.md +[https://ci.nodejs.org/]: https://ci.nodejs.org/ +[IRC in the #node-dev channel]: https://webchat.freenode.net?channels=node-dev&uio=d4 +[Node.js help repository]: https://github.com/nodejs/help/issues +[notes about the waiting time]: #waiting-until-the-pull-request-gets-landed +[Onboarding guide]: ./doc/onboarding.md +[on GitHub]: https://github.com/nodejs/node +[Technical Steering Committee (TSC) repository]: https://github.com/nodejs/TSC/issues diff --git a/Makefile b/Makefile index 274df0745871cf..825baa1ecb62a7 100644 --- a/Makefile +++ b/Makefile @@ -386,9 +386,6 @@ test-pummel: all test-internet: all $(PYTHON) tools/test.py internet -test-debugger: all - $(PYTHON) tools/test.py debugger - test-inspector: all $(PYTHON) tools/test.py inspector @@ -883,26 +880,32 @@ bench: bench-net bench-http bench-fs bench-tls bench-ci: bench -JSLINT_TARGETS = benchmark doc lib test tools +LINT_JS_TARGETS = benchmark doc lib test tools -jslint: +lint-js: @echo "Running JS linter..." $(NODE) tools/eslint/bin/eslint.js --cache --rulesdir=tools/eslint-rules --ext=.js,.mjs,.md \ - $(JSLINT_TARGETS) + $(LINT_JS_TARGETS) + +jslint: lint-js + @echo "Please use lint-js instead of jslint" -jslint-ci: +lint-js-ci: @echo "Running JS linter..." - $(NODE) tools/jslint.js $(PARALLEL_ARGS) -f tap -o test-eslint.tap \ - $(JSLINT_TARGETS) + $(NODE) tools/lint-js.js $(PARALLEL_ARGS) -f tap -o test-eslint.tap \ + $(LINT_JS_TARGETS) -CPPLINT_EXCLUDE ?= -CPPLINT_EXCLUDE += src/node_root_certs.h -CPPLINT_EXCLUDE += $(wildcard test/addons/??_*/*.cc test/addons/??_*/*.h) -CPPLINT_EXCLUDE += $(wildcard test/addons-napi/??_*/*.cc test/addons-napi/??_*/*.h) +jslint-ci: lint-js-ci + @echo "Please use lint-js-ci instead of jslint-ci" + +LINT_CPP_EXCLUDE ?= +LINT_CPP_EXCLUDE += src/node_root_certs.h +LINT_CPP_EXCLUDE += $(wildcard test/addons/??_*/*.cc test/addons/??_*/*.h) +LINT_CPP_EXCLUDE += $(wildcard test/addons-napi/??_*/*.cc test/addons-napi/??_*/*.h) # These files were copied more or less verbatim from V8. -CPPLINT_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h +LINT_CPP_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h -CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \ +LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \ src/*.c \ src/*.cc \ src/*.h \ @@ -920,19 +923,22 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \ tools/icu/*.h \ )) -cpplint: +lint-cpp: @echo "Running C++ linter..." - @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES) + @$(PYTHON) tools/cpplint.py $(LINT_CPP_FILES) @$(PYTHON) tools/check-imports.py -ifneq ("","$(wildcard tools/eslint/bin/eslint.js)") +cpplint: lint-cpp + @echo "Please use lint-cpp instead of cpplint" + +ifneq ("","$(wildcard tools/eslint/)") lint: @EXIT_STATUS=0 ; \ - $(MAKE) jslint || EXIT_STATUS=$$? ; \ - $(MAKE) cpplint || EXIT_STATUS=$$? ; \ + $(MAKE) lint-js || EXIT_STATUS=$$? ; \ + $(MAKE) lint-cpp || EXIT_STATUS=$$? ; \ exit $$EXIT_STATUS CONFLICT_RE=^>>>>>>> [0-9A-Fa-f]+|^<<<<<<< [A-Za-z]+ -lint-ci: jslint-ci cpplint +lint-ci: lint-js-ci lint-cpp @if ! ( grep -IEqrs "$(CONFLICT_RE)" benchmark deps doc lib src test tools ) \ && ! ( find . -maxdepth 1 -type f | xargs grep -IEqs "$(CONFLICT_RE)" ); then \ exit 0 ; \ @@ -946,7 +952,6 @@ lint: @echo "Linting is not available through the source tarball." @echo "Use the git repo instead:" \ "$ git clone https://github.com/nodejs/node.git" - exit 1 lint-ci: lint endif @@ -980,7 +985,6 @@ endif coverage-build \ coverage-clean \ coverage-test \ - cpplint \ dist \ distclean \ doc \ @@ -991,10 +995,11 @@ endif install \ install-bin \ install-includes \ - jslint \ - jslint-ci \ lint \ lint-ci \ + lint-cpp \ + lint-js \ + lint-js-ci \ list-gtests \ pkg \ release-only \ diff --git a/README.md b/README.md index ec1488345adb7b..0d03168c5452dc 100644 --- a/README.md +++ b/README.md @@ -134,12 +134,12 @@ $ grep node-vx.y.z.tar.gz SHASUMS256.txt | sha256sum -c - _(Where "node-vx.y.z.tar.gz" is the name of the file you have downloaded)_ -Additionally, Current and LTS releases (not Nightlies) have GPG signed -copies of SHASUMS256.txt files available as SHASUMS256.txt.asc. You can use -`gpg` to verify that the file has not been tampered with. +Additionally, Current and LTS releases (not Nightlies) have the GPG +detached signature of SHASUMS256.txt available as SHASUMS256.txt.sig. +You can use `gpg` to verify that SHASUMS256.txt has not been tampered with. -To verify a SHASUMS256.txt.asc, you will first need to import all of -the GPG keys of individuals authorized to create releases. They are +To verify SHASUMS256.txt has not been altered, you will first need to import +all of the GPG keys of individuals authorized to create releases. They are listed at the bottom of this README under [Release Team](#release-team). Use a command such as this to import the keys: @@ -150,10 +150,17 @@ $ gpg --keyserver pool.sks-keyservers.net --recv-keys DD8F2338BAE7501E3DD5AC78C2 _(See the bottom of this README for a full script to import active release keys)_ -You can then use `gpg --verify SHASUMS256.txt.asc` to verify that the -file has been signed by an authorized member of the Node.js team. +Next, download the SHASUMS256.txt.sig for the release: -Once verified, use the SHASUMS256.txt.asc file to get the checksum for +```console +$ curl -O https://nodejs.org/dist/vx.y.z/SHASUMS256.txt.sig +``` + +After downloading the appropriate SHASUMS256.txt and SHASUMS256.txt.sig files, +you can then use `gpg --verify SHASUMS256.txt.sig SHASUMS256.txt` to verify +that the file has been signed by an authorized member of the Node.js team. + +Once verified, use the SHASUMS256.txt file to get the checksum for the binary verification command above. ## Building Node.js @@ -461,6 +468,8 @@ For more information about the governance of the Node.js project, see **Sam Roberts** <vieuxtech@gmail.com> * [santigimeno](https://github.com/santigimeno) - **Santiago Gimeno** <santiago.gimeno@gmail.com> +* [sebdeckers](https://github.com/sebdeckers) - +**Sebastiaan Deckers** <sebdeckers83@gmail.com> * [seishun](https://github.com/seishun) - **Nikolai Vavilov** <vvnicholas@gmail.com> * [shigeki](https://github.com/shigeki) - diff --git a/benchmark/_benchmark_progress.js b/benchmark/_benchmark_progress.js index ffb2dfdf6511a9..24bb95dcd19f38 100644 --- a/benchmark/_benchmark_progress.js +++ b/benchmark/_benchmark_progress.js @@ -3,8 +3,8 @@ const readline = require('readline'); function pad(input, minLength, fill) { - var result = String(input); - var padding = fill.repeat(Math.max(0, minLength - result.length)); + const result = String(input); + const padding = fill.repeat(Math.max(0, minLength - result.length)); return `${padding}${result}`; } diff --git a/benchmark/_test-double-benchmarker.js b/benchmark/_test-double-benchmarker.js index a95ad9c8613db8..0a8c5f9264efc8 100644 --- a/benchmark/_test-double-benchmarker.js +++ b/benchmark/_test-double-benchmarker.js @@ -3,5 +3,5 @@ const http = require('http'); http.get(process.env.path, function() { - console.log(JSON.stringify({throughput: 1})); + console.log(JSON.stringify({ throughput: 1 })); }); diff --git a/benchmark/arrays/var-int.js b/benchmark/arrays/var-int.js index 795d4eb838de2f..a8acbf5ccbbcb1 100644 --- a/benchmark/arrays/var-int.js +++ b/benchmark/arrays/var-int.js @@ -23,7 +23,7 @@ function main(conf) { const n = +conf.n; bench.start(); - var arr = new clazz(n * 1e6); + const arr = new clazz(n * 1e6); for (var i = 0; i < 10; ++i) { run(); } diff --git a/benchmark/arrays/zero-float.js b/benchmark/arrays/zero-float.js index d61b0598a4ecf0..c8d7dbf7ed57d2 100644 --- a/benchmark/arrays/zero-float.js +++ b/benchmark/arrays/zero-float.js @@ -23,7 +23,7 @@ function main(conf) { const n = +conf.n; bench.start(); - var arr = new clazz(n * 1e6); + const arr = new clazz(n * 1e6); for (var i = 0; i < 10; ++i) { run(); } diff --git a/benchmark/arrays/zero-int.js b/benchmark/arrays/zero-int.js index 90d491e8073168..b16a6b6b72064e 100644 --- a/benchmark/arrays/zero-int.js +++ b/benchmark/arrays/zero-int.js @@ -23,7 +23,7 @@ function main(conf) { const n = +conf.n; bench.start(); - var arr = new clazz(n * 1e6); + const arr = new clazz(n * 1e6); for (var i = 0; i < 10; ++i) { run(); } diff --git a/benchmark/assert/deepequal-buffer.js b/benchmark/assert/deepequal-buffer.js index 9e86aa231e69d2..d4495af69b48ef 100644 --- a/benchmark/assert/deepequal-buffer.js +++ b/benchmark/assert/deepequal-buffer.js @@ -27,6 +27,8 @@ function main(conf) { data.copy(expectedWrong); switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/assert/deepequal-map.js b/benchmark/assert/deepequal-map.js index eae4a20605ca70..4976f2619834bf 100644 --- a/benchmark/assert/deepequal-map.js +++ b/benchmark/assert/deepequal-map.js @@ -46,6 +46,8 @@ function main(conf) { var values, values2; switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual_primitiveOnly': values = array.map((_, i) => [`str_${i}`, 123]); benchmark(assert.deepEqual, n, values); diff --git a/benchmark/assert/deepequal-object.js b/benchmark/assert/deepequal-object.js index d1a6cb69944055..2efa9452af88e1 100644 --- a/benchmark/assert/deepequal-object.js +++ b/benchmark/assert/deepequal-object.js @@ -37,6 +37,8 @@ function main(conf) { const expectedWrong = createObj(source, '4'); switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/assert/deepequal-prims-and-objs-big-array-set.js b/benchmark/assert/deepequal-prims-and-objs-big-array-set.js index 1e356cea51efd6..19337d7828236d 100644 --- a/benchmark/assert/deepequal-prims-and-objs-big-array-set.js +++ b/benchmark/assert/deepequal-prims-and-objs-big-array-set.js @@ -53,6 +53,8 @@ function main(conf) { const expectedWrongSet = new Set(expectedWrong); switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual_Array': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/assert/deepequal-prims-and-objs-big-loop.js b/benchmark/assert/deepequal-prims-and-objs-big-loop.js index 2800b51c491bcf..4a345f27c20f0e 100644 --- a/benchmark/assert/deepequal-prims-and-objs-big-loop.js +++ b/benchmark/assert/deepequal-prims-and-objs-big-loop.js @@ -34,6 +34,8 @@ function main(conf) { // Creates new array to avoid loop invariant code motion switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/assert/deepequal-set.js b/benchmark/assert/deepequal-set.js index ecf44c063dfecf..aa0ebc064886a2 100644 --- a/benchmark/assert/deepequal-set.js +++ b/benchmark/assert/deepequal-set.js @@ -47,6 +47,8 @@ function main(conf) { var values, values2; switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual_primitiveOnly': values = array.map((_, i) => `str_${i}`); benchmark(assert.deepEqual, n, values); diff --git a/benchmark/assert/deepequal-typedarrays.js b/benchmark/assert/deepequal-typedarrays.js index 5d51d53d13e70f..8e8cc4b083a73e 100644 --- a/benchmark/assert/deepequal-typedarrays.js +++ b/benchmark/assert/deepequal-typedarrays.js @@ -33,10 +33,13 @@ function main(conf) { const actual = new clazz(len); const expected = new clazz(len); const expectedWrong = Buffer.alloc(len); - expectedWrong[100] = 123; + const wrongIndex = Math.floor(len / 2); + expectedWrong[wrongIndex] = 123; var i; switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/assert/throws.js b/benchmark/assert/throws.js index 9043799256e196..075e227f886acc 100644 --- a/benchmark/assert/throws.js +++ b/benchmark/assert/throws.js @@ -22,6 +22,8 @@ function main(conf) { var i; switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'doesNotThrow': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/buffers/buffer-base64-encode.js b/benchmark/buffers/buffer-base64-encode.js index 6805737ba9fe87..509fcd9a33c9d4 100644 --- a/benchmark/buffers/buffer-base64-encode.js +++ b/benchmark/buffers/buffer-base64-encode.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); const bench = common.createBenchmark(main, { len: [64 * 1024 * 1024], diff --git a/benchmark/buffers/buffer-bytelength.js b/benchmark/buffers/buffer-bytelength.js index 44b0f9e389cdb7..fc6dfcf2301eaf 100644 --- a/benchmark/buffers/buffer-bytelength.js +++ b/benchmark/buffers/buffer-bytelength.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { encoding: ['utf8', 'base64', 'buffer'], len: [1, 2, 4, 16, 64, 256], // x16 n: [5e6] }); // 16 chars each -var chars = [ +const chars = [ 'hello brendan!!!', // 1 byte 'ΰαβγδεζηθικλμνξο', // 2 bytes '挰挱挲挳挴挵挶挷挸挹挺挻挼挽挾挿', // 3 bytes @@ -16,9 +16,9 @@ var chars = [ ]; function main(conf) { - var n = conf.n | 0; - var len = conf.len | 0; - var encoding = conf.encoding; + const n = conf.n | 0; + const len = conf.len | 0; + const encoding = conf.encoding; var strings = []; var results; @@ -26,9 +26,9 @@ function main(conf) { strings = [ Buffer.alloc(len * 16, 'a') ]; results = [ len * 16 ]; } else { - for (var string of chars) { + for (const string of chars) { // Strings must be built differently, depending on encoding - var data = string.repeat(len); + const data = string.repeat(len); if (encoding === 'utf8') { strings.push(data); } else if (encoding === 'base64') { @@ -45,9 +45,9 @@ function main(conf) { bench.start(); for (var i = 0; i < n; i++) { - var index = n % strings.length; + const index = n % strings.length; // Go! - var r = Buffer.byteLength(strings[index], encoding); + const r = Buffer.byteLength(strings[index], encoding); if (r !== results[index]) throw new Error('incorrect return value'); diff --git a/benchmark/buffers/buffer-compare.js b/benchmark/buffers/buffer-compare.js index 0a8c4c15e74b38..ad6519cd102340 100644 --- a/benchmark/buffers/buffer-compare.js +++ b/benchmark/buffers/buffer-compare.js @@ -20,9 +20,9 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { size: [16, 512, 1024, 4096, 16386], millions: [1] }); diff --git a/benchmark/buffers/buffer-indexof.js b/benchmark/buffers/buffer-indexof.js index cae8b964aebbcf..1545475269a025 100644 --- a/benchmark/buffers/buffer-indexof.js +++ b/benchmark/buffers/buffer-indexof.js @@ -1,6 +1,6 @@ 'use strict'; -var common = require('../common.js'); -var fs = require('fs'); +const common = require('../common.js'); +const fs = require('fs'); const path = require('path'); const searchStrings = [ @@ -21,7 +21,7 @@ const searchStrings = [ ' to the Caterpillar' ]; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { search: searchStrings, encoding: ['undefined', 'utf8', 'ucs2', 'binary'], type: ['buffer', 'string'], @@ -29,7 +29,7 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var iter = (conf.iter) * 100000; + const iter = (conf.iter) * 100000; var aliceBuffer = fs.readFileSync( path.resolve(__dirname, '../fixtures/alice.html') ); diff --git a/benchmark/buffers/buffer-iterate.js b/benchmark/buffers/buffer-iterate.js index 7b49bcca717c2b..4e911caa72ce14 100644 --- a/benchmark/buffers/buffer-iterate.js +++ b/benchmark/buffers/buffer-iterate.js @@ -1,16 +1,16 @@ 'use strict'; -var SlowBuffer = require('buffer').SlowBuffer; -var common = require('../common.js'); -var assert = require('assert'); +const SlowBuffer = require('buffer').SlowBuffer; +const common = require('../common.js'); +const assert = require('assert'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { size: [16, 512, 1024, 4096, 16386], type: ['fast', 'slow'], method: ['for', 'forOf', 'iterator'], n: [1e3] }); -var methods = { +const methods = { 'for': benchFor, 'forOf': benchForOf, 'iterator': benchIterator @@ -43,7 +43,7 @@ function benchForOf(buffer, n) { bench.start(); for (var k = 0; k < n; k++) { - for (var b of buffer) { + for (const b of buffer) { assert(b === 0); } } @@ -54,7 +54,7 @@ function benchIterator(buffer, n) { bench.start(); for (var k = 0; k < n; k++) { - var iter = buffer[Symbol.iterator](); + const iter = buffer[Symbol.iterator](); var cur = iter.next(); while (!cur.done) { diff --git a/benchmark/buffers/buffer-read.js b/benchmark/buffers/buffer-read.js index 67d86bad4eb05c..339da75befce4d 100644 --- a/benchmark/buffers/buffer-read.js +++ b/benchmark/buffers/buffer-read.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var types = [ +const types = [ 'UInt8', 'UInt16LE', 'UInt16BE', @@ -18,7 +18,7 @@ var types = [ 'DoubleBE' ]; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { noAssert: ['false', 'true'], buffer: ['fast', 'slow'], type: types, diff --git a/benchmark/buffers/buffer-slice.js b/benchmark/buffers/buffer-slice.js index 13dbf6a59b7c76..0067d02d8c7931 100644 --- a/benchmark/buffers/buffer-slice.js +++ b/benchmark/buffers/buffer-slice.js @@ -1,18 +1,18 @@ 'use strict'; -var common = require('../common.js'); -var SlowBuffer = require('buffer').SlowBuffer; +const common = require('../common.js'); +const SlowBuffer = require('buffer').SlowBuffer; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { type: ['fast', 'slow'], n: [1024] }); -var buf = Buffer.allocUnsafe(1024); -var slowBuf = new SlowBuffer(1024); +const buf = Buffer.allocUnsafe(1024); +const slowBuf = new SlowBuffer(1024); function main(conf) { - var n = +conf.n; - var b = conf.type === 'fast' ? buf : slowBuf; + const n = +conf.n; + const b = conf.type === 'fast' ? buf : slowBuf; bench.start(); for (var i = 0; i < n * 1024; i++) { b.slice(10, 256); diff --git a/benchmark/buffers/buffer-tojson.js b/benchmark/buffers/buffer-tojson.js index 1be59952c3fe60..19a6fe89474838 100644 --- a/benchmark/buffers/buffer-tojson.js +++ b/benchmark/buffers/buffer-tojson.js @@ -8,8 +8,8 @@ const bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var buf = Buffer.allocUnsafe(+conf.len); + const n = +conf.n; + const buf = Buffer.allocUnsafe(+conf.len); bench.start(); for (var i = 0; i < n; ++i) diff --git a/benchmark/buffers/buffer-write.js b/benchmark/buffers/buffer-write.js index 8fcfc43f70b5bc..b500a13dedcccd 100644 --- a/benchmark/buffers/buffer-write.js +++ b/benchmark/buffers/buffer-write.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var types = [ +const types = [ 'UInt8', 'UInt16LE', 'UInt16BE', @@ -18,7 +18,7 @@ var types = [ 'DoubleBE' ]; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { noAssert: ['false', 'true'], buffer: ['fast', 'slow'], type: types, @@ -32,7 +32,7 @@ const UINT8 = (INT8 * 2) + 1; const UINT16 = (INT16 * 2) + 1; const UINT32 = INT32; -var mod = { +const mod = { writeInt8: INT8, writeInt16BE: INT16, writeInt16LE: INT16, @@ -60,8 +60,8 @@ function main(conf) { } function benchInt(buff, fn, len, noAssert) { - var m = mod[fn]; - var testFunction = new Function('buff', ` + const m = mod[fn]; + const testFunction = new Function('buff', ` for (var i = 0; i !== ${len}; i++) { buff.${fn}(i & ${m}, 0, ${JSON.stringify(noAssert)}); } @@ -72,7 +72,7 @@ function benchInt(buff, fn, len, noAssert) { } function benchFloat(buff, fn, len, noAssert) { - var testFunction = new Function('buff', ` + const testFunction = new Function('buff', ` for (var i = 0; i !== ${len}; i++) { buff.${fn}(i, 0, ${JSON.stringify(noAssert)}); } diff --git a/benchmark/buffers/buffer_zero.js b/benchmark/buffers/buffer_zero.js index e624bbbcd43283..06ca50bbb99ee7 100644 --- a/benchmark/buffers/buffer_zero.js +++ b/benchmark/buffers/buffer_zero.js @@ -11,7 +11,7 @@ const zeroBuffer = Buffer.alloc(0); const zeroString = ''; function main(conf) { - var n = +conf.n; + const n = +conf.n; bench.start(); if (conf.type === 'buffer') diff --git a/benchmark/buffers/dataview-set.js b/benchmark/buffers/dataview-set.js index f9663e6a03953d..0dd4598ab7f1c5 100644 --- a/benchmark/buffers/dataview-set.js +++ b/benchmark/buffers/dataview-set.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var types = [ +const types = [ 'Uint8', 'Uint16LE', 'Uint16BE', @@ -18,7 +18,7 @@ var types = [ 'Float64BE' ]; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { type: types, millions: [1] }); @@ -30,7 +30,7 @@ const UINT8 = INT8 * 2; const UINT16 = INT16 * 2; const UINT32 = INT32 * 2; -var mod = { +const mod = { setInt8: INT8, setInt16: INT16, setInt32: INT32, diff --git a/benchmark/child_process/child-process-exec-stdout.js b/benchmark/child_process/child-process-exec-stdout.js index dcd352cfcf65e7..1e78d445f8376d 100644 --- a/benchmark/child_process/child-process-exec-stdout.js +++ b/benchmark/child_process/child-process-exec-stdout.js @@ -3,7 +3,7 @@ const common = require('../common.js'); const { exec, execSync } = require('child_process'); const isWindows = process.platform === 'win32'; -var messagesLength = [64, 256, 1024, 4096]; +const messagesLength = [64, 256, 1024, 4096]; // Windows does not support command lines longer than 8191 characters if (!isWindows) messagesLength.push(32768); diff --git a/benchmark/child_process/child-process-read.js b/benchmark/child_process/child-process-read.js index c1b834e4318fe1..91c9964e8d1414 100644 --- a/benchmark/child_process/child-process-read.js +++ b/benchmark/child_process/child-process-read.js @@ -7,7 +7,7 @@ const common = require('../common.js'); const os = require('os'); const child_process = require('child_process'); -var messagesLength = [64, 256, 1024, 4096]; +const messagesLength = [64, 256, 1024, 4096]; // Windows does not support that long arguments if (os.platform() !== 'win32') messagesLength.push(32768); diff --git a/benchmark/child_process/spawn-echo.js b/benchmark/child_process/spawn-echo.js index 72822f87db8aba..1ce40c3abf4541 100644 --- a/benchmark/child_process/spawn-echo.js +++ b/benchmark/child_process/spawn-echo.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common.js'); -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const bench = common.createBenchmark(main, { n: [1000] }); -var spawn = require('child_process').spawn; +const spawn = require('child_process').spawn; function main(conf) { - var n = +conf.n; + const n = +conf.n; bench.start(); go(n, n); @@ -16,7 +16,7 @@ function go(n, left) { if (--left === 0) return bench.end(n); - var child = spawn('echo', ['hello']); + const child = spawn('echo', ['hello']); child.on('exit', function(code) { if (code) process.exit(code); diff --git a/benchmark/cluster/echo.js b/benchmark/cluster/echo.js index 1aa06120e15087..07096d251db489 100644 --- a/benchmark/cluster/echo.js +++ b/benchmark/cluster/echo.js @@ -11,10 +11,10 @@ if (cluster.isMaster) { }); function main(conf) { - var n = +conf.n; - var workers = +conf.workers; - var sends = +conf.sendsPerBroadcast; - var expectedPerBroadcast = sends * workers; + const n = +conf.n; + const workers = +conf.workers; + const sends = +conf.sendsPerBroadcast; + const expectedPerBroadcast = sends * workers; var payload; var readies = 0; var broadcasts = 0; diff --git a/benchmark/crypto/aes-gcm-throughput.js b/benchmark/crypto/aes-gcm-throughput.js index 0cb32689510dd3..246455de78ad88 100644 --- a/benchmark/crypto/aes-gcm-throughput.js +++ b/benchmark/crypto/aes-gcm-throughput.js @@ -1,34 +1,34 @@ 'use strict'; -var common = require('../common.js'); -var crypto = require('crypto'); -var keylen = {'aes-128-gcm': 16, 'aes-192-gcm': 24, 'aes-256-gcm': 32}; -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const crypto = require('crypto'); +const keylen = { 'aes-128-gcm': 16, 'aes-192-gcm': 24, 'aes-256-gcm': 32 }; +const bench = common.createBenchmark(main, { n: [500], cipher: ['aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm'], len: [1024, 4 * 1024, 16 * 1024, 64 * 1024, 256 * 1024, 1024 * 1024] }); function main(conf) { - var message = Buffer.alloc(conf.len, 'b'); - var key = crypto.randomBytes(keylen[conf.cipher]); - var iv = crypto.randomBytes(12); - var associate_data = Buffer.alloc(16, 'z'); + const message = Buffer.alloc(conf.len, 'b'); + const key = crypto.randomBytes(keylen[conf.cipher]); + const iv = crypto.randomBytes(12); + const associate_data = Buffer.alloc(16, 'z'); bench.start(); AEAD_Bench(conf.cipher, message, associate_data, key, iv, conf.n, conf.len); } function AEAD_Bench(cipher, message, associate_data, key, iv, n, len) { - var written = n * len; - var bits = written * 8; - var mbits = bits / (1024 * 1024); + const written = n * len; + const bits = written * 8; + const mbits = bits / (1024 * 1024); for (var i = 0; i < n; i++) { - var alice = crypto.createCipheriv(cipher, key, iv); + const alice = crypto.createCipheriv(cipher, key, iv); alice.setAAD(associate_data); - var enc = alice.update(message); + const enc = alice.update(message); alice.final(); - var tag = alice.getAuthTag(); - var bob = crypto.createDecipheriv(cipher, key, iv); + const tag = alice.getAuthTag(); + const bob = crypto.createDecipheriv(cipher, key, iv); bob.setAuthTag(tag); bob.setAAD(associate_data); bob.update(enc); diff --git a/benchmark/crypto/cipher-stream.js b/benchmark/crypto/cipher-stream.js index 9fd88f1d864dff..ca36bd736d9aea 100644 --- a/benchmark/crypto/cipher-stream.js +++ b/benchmark/crypto/cipher-stream.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { writes: [500], cipher: [ 'AES192', 'AES256' ], type: ['asc', 'utf', 'buf'], @@ -17,24 +17,24 @@ function main(conf) { api = 'legacy'; } - var crypto = require('crypto'); - var assert = require('assert'); - var alice = crypto.getDiffieHellman('modp5'); - var bob = crypto.getDiffieHellman('modp5'); + const crypto = require('crypto'); + const assert = require('assert'); + const alice = crypto.getDiffieHellman('modp5'); + const bob = crypto.getDiffieHellman('modp5'); alice.generateKeys(); bob.generateKeys(); - var pubEnc = /^v0\.[0-8]/.test(process.version) ? 'binary' : null; - var alice_secret = alice.computeSecret(bob.getPublicKey(), pubEnc, 'hex'); - var bob_secret = bob.computeSecret(alice.getPublicKey(), pubEnc, 'hex'); + const pubEnc = /^v0\.[0-8]/.test(process.version) ? 'binary' : null; + const alice_secret = alice.computeSecret(bob.getPublicKey(), pubEnc, 'hex'); + const bob_secret = bob.computeSecret(alice.getPublicKey(), pubEnc, 'hex'); // alice_secret and bob_secret should be the same assert(alice_secret === bob_secret); - var alice_cipher = crypto.createCipher(conf.cipher, alice_secret); - var bob_cipher = crypto.createDecipher(conf.cipher, bob_secret); + const alice_cipher = crypto.createCipher(conf.cipher, alice_secret); + const bob_cipher = crypto.createDecipher(conf.cipher, bob_secret); var message; var encoding; @@ -54,7 +54,7 @@ function main(conf) { throw new Error(`unknown message type: ${conf.type}`); } - var fn = api === 'stream' ? streamWrite : legacyWrite; + const fn = api === 'stream' ? streamWrite : legacyWrite; // write data as fast as possible to alice, and have bob decrypt. // use old API for comparison to v0.8 @@ -70,8 +70,8 @@ function streamWrite(alice, bob, message, encoding, writes) { bob.on('end', function() { // Gbits - var bits = written * 8; - var gbits = bits / (1024 * 1024 * 1024); + const bits = written * 8; + const gbits = bits / (1024 * 1024 * 1024); bench.end(gbits); }); @@ -96,6 +96,6 @@ function legacyWrite(alice, bob, message, encoding, writes) { written += dec.length; dec = bob.final(); written += dec.length; - var gbits = written / (1024 * 1024 * 1024); + const gbits = written / (1024 * 1024 * 1024); bench.end(gbits); } diff --git a/benchmark/crypto/hash-stream-creation.js b/benchmark/crypto/hash-stream-creation.js index dfab32c8af7ea1..5ac5a4f70b5c55 100644 --- a/benchmark/crypto/hash-stream-creation.js +++ b/benchmark/crypto/hash-stream-creation.js @@ -1,10 +1,10 @@ // throughput benchmark // creates a single hasher, then pushes a bunch of data through it 'use strict'; -var common = require('../common.js'); -var crypto = require('crypto'); +const common = require('../common.js'); +const crypto = require('crypto'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { writes: [500], algo: [ 'sha256', 'md5' ], type: ['asc', 'utf', 'buf'], @@ -39,19 +39,19 @@ function main(conf) { throw new Error(`unknown message type: ${conf.type}`); } - var fn = api === 'stream' ? streamWrite : legacyWrite; + const fn = api === 'stream' ? streamWrite : legacyWrite; bench.start(); fn(conf.algo, message, encoding, conf.writes, conf.len, conf.out); } function legacyWrite(algo, message, encoding, writes, len, outEnc) { - var written = writes * len; - var bits = written * 8; - var gbits = bits / (1024 * 1024 * 1024); + const written = writes * len; + const bits = written * 8; + const gbits = bits / (1024 * 1024 * 1024); while (writes-- > 0) { - var h = crypto.createHash(algo); + const h = crypto.createHash(algo); h.update(message, encoding); var res = h.digest(outEnc); @@ -64,12 +64,12 @@ function legacyWrite(algo, message, encoding, writes, len, outEnc) { } function streamWrite(algo, message, encoding, writes, len, outEnc) { - var written = writes * len; - var bits = written * 8; - var gbits = bits / (1024 * 1024 * 1024); + const written = writes * len; + const bits = written * 8; + const gbits = bits / (1024 * 1024 * 1024); while (writes-- > 0) { - var h = crypto.createHash(algo); + const h = crypto.createHash(algo); if (outEnc !== 'buffer') h.setEncoding(outEnc); diff --git a/benchmark/crypto/hash-stream-throughput.js b/benchmark/crypto/hash-stream-throughput.js index cedaeb872f494d..21ec3c7902b367 100644 --- a/benchmark/crypto/hash-stream-throughput.js +++ b/benchmark/crypto/hash-stream-throughput.js @@ -1,10 +1,10 @@ // throughput benchmark // creates a single hasher, then pushes a bunch of data through it 'use strict'; -var common = require('../common.js'); -var crypto = require('crypto'); +const common = require('../common.js'); +const crypto = require('crypto'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { writes: [500], algo: ['sha1', 'sha256', 'sha512'], type: ['asc', 'utf', 'buf'], @@ -38,17 +38,17 @@ function main(conf) { throw new Error(`unknown message type: ${conf.type}`); } - var fn = api === 'stream' ? streamWrite : legacyWrite; + const fn = api === 'stream' ? streamWrite : legacyWrite; bench.start(); fn(conf.algo, message, encoding, conf.writes, conf.len); } function legacyWrite(algo, message, encoding, writes, len) { - var written = writes * len; - var bits = written * 8; - var gbits = bits / (1024 * 1024 * 1024); - var h = crypto.createHash(algo); + const written = writes * len; + const bits = written * 8; + const gbits = bits / (1024 * 1024 * 1024); + const h = crypto.createHash(algo); while (writes-- > 0) h.update(message, encoding); @@ -59,10 +59,10 @@ function legacyWrite(algo, message, encoding, writes, len) { } function streamWrite(algo, message, encoding, writes, len) { - var written = writes * len; - var bits = written * 8; - var gbits = bits / (1024 * 1024 * 1024); - var h = crypto.createHash(algo); + const written = writes * len; + const bits = written * 8; + const gbits = bits / (1024 * 1024 * 1024); + const h = crypto.createHash(algo); while (writes-- > 0) h.write(message, encoding); diff --git a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js index b1fc3393667e99..edab5ae08f7d63 100644 --- a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js +++ b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js @@ -1,13 +1,13 @@ 'use strict'; // throughput benchmark in signing and verifying -var common = require('../common.js'); -var crypto = require('crypto'); -var fs = require('fs'); -var path = require('path'); -var fixtures_keydir = path.resolve(__dirname, '../../test/fixtures/keys/'); -var keylen_list = ['1024', '2048', '4096']; -var RSA_PublicPem = {}; -var RSA_PrivatePem = {}; +const common = require('../common.js'); +const crypto = require('crypto'); +const fs = require('fs'); +const path = require('path'); +const fixtures_keydir = path.resolve(__dirname, '../../test/fixtures/keys/'); +const keylen_list = ['1024', '2048', '4096']; +const RSA_PublicPem = {}; +const RSA_PrivatePem = {}; keylen_list.forEach(function(key) { RSA_PublicPem[key] = @@ -16,27 +16,27 @@ keylen_list.forEach(function(key) { fs.readFileSync(`${fixtures_keydir}/rsa_private_${key}.pem`); }); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { n: [500], keylen: keylen_list, len: [16, 32, 64] }); function main(conf) { - var message = Buffer.alloc(conf.len, 'b'); + const message = Buffer.alloc(conf.len, 'b'); bench.start(); StreamWrite(conf.algo, conf.keylen, message, conf.n, conf.len); } function StreamWrite(algo, keylen, message, n, len) { - var written = n * len; - var bits = written * 8; - var kbits = bits / (1024); + const written = n * len; + const bits = written * 8; + const kbits = bits / (1024); - var privateKey = RSA_PrivatePem[keylen]; - var publicKey = RSA_PublicPem[keylen]; + const privateKey = RSA_PrivatePem[keylen]; + const publicKey = RSA_PublicPem[keylen]; for (var i = 0; i < n; i++) { - var enc = crypto.privateEncrypt(privateKey, message); + const enc = crypto.privateEncrypt(privateKey, message); crypto.publicDecrypt(publicKey, enc); } diff --git a/benchmark/crypto/rsa-sign-verify-throughput.js b/benchmark/crypto/rsa-sign-verify-throughput.js index f13dc2585a7227..bcde3a43d4d77a 100644 --- a/benchmark/crypto/rsa-sign-verify-throughput.js +++ b/benchmark/crypto/rsa-sign-verify-throughput.js @@ -1,13 +1,13 @@ 'use strict'; // throughput benchmark in signing and verifying -var common = require('../common.js'); -var crypto = require('crypto'); -var fs = require('fs'); -var path = require('path'); -var fixtures_keydir = path.resolve(__dirname, '../../test/fixtures/keys/'); -var keylen_list = ['1024', '2048']; -var RSA_PublicPem = {}; -var RSA_PrivatePem = {}; +const common = require('../common.js'); +const crypto = require('crypto'); +const fs = require('fs'); +const path = require('path'); +const fixtures_keydir = path.resolve(__dirname, '../../test/fixtures/keys/'); +const keylen_list = ['1024', '2048']; +const RSA_PublicPem = {}; +const RSA_PrivatePem = {}; keylen_list.forEach(function(key) { RSA_PublicPem[key] = @@ -16,27 +16,27 @@ keylen_list.forEach(function(key) { fs.readFileSync(`${fixtures_keydir}/rsa_private_${key}.pem`); }); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { writes: [500], - algo: ['RSA-SHA1', 'RSA-SHA224', 'RSA-SHA256', 'RSA-SHA384', 'RSA-SHA512'], + algo: ['SHA1', 'SHA224', 'SHA256', 'SHA384', 'SHA512'], keylen: keylen_list, len: [1024, 102400, 2 * 102400, 3 * 102400, 1024 * 1024] }); function main(conf) { - var message = Buffer.alloc(conf.len, 'b'); + const message = Buffer.alloc(conf.len, 'b'); bench.start(); StreamWrite(conf.algo, conf.keylen, message, conf.writes, conf.len); } function StreamWrite(algo, keylen, message, writes, len) { - var written = writes * len; - var bits = written * 8; - var kbits = bits / (1024); + const written = writes * len; + const bits = written * 8; + const kbits = bits / (1024); - var privateKey = RSA_PrivatePem[keylen]; - var s = crypto.createSign(algo); - var v = crypto.createVerify(algo); + const privateKey = RSA_PrivatePem[keylen]; + const s = crypto.createSign(algo); + const v = crypto.createVerify(algo); while (writes-- > 0) { s.update(message); diff --git a/benchmark/dgram/array-vs-concat.js b/benchmark/dgram/array-vs-concat.js index 681abd6afa13e0..7ee4e2d3acb6e1 100644 --- a/benchmark/dgram/array-vs-concat.js +++ b/benchmark/dgram/array-vs-concat.js @@ -7,7 +7,7 @@ const PORT = common.PORT; // `num` is the number of send requests to queue up each time. // Keep it reasonably high (>10) otherwise you're benchmarking the speed of // event loop cycles more than anything else. -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [64, 256, 512, 1024], num: [100], chunks: [1, 2, 4, 8], @@ -37,13 +37,13 @@ function main(conf) { server(); } -var dgram = require('dgram'); +const dgram = require('dgram'); function server() { var sent = 0; - var socket = dgram.createSocket('udp4'); + const socket = dgram.createSocket('udp4'); - var onsend = type === 'concat' ? onsendConcat : onsendMulti; + const onsend = type === 'concat' ? onsendConcat : onsendMulti; function onsendConcat() { if (sent++ % num === 0) { @@ -66,8 +66,8 @@ function server() { onsend(); setTimeout(function() { - var bytes = sent * len; - var gbits = (bytes * 8) / (1024 * 1024 * 1024); + const bytes = sent * len; + const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(gbits); process.exit(0); }, dur * 1000); diff --git a/benchmark/dgram/multi-buffer.js b/benchmark/dgram/multi-buffer.js index a0285c8c59e015..15f70760abfd9e 100644 --- a/benchmark/dgram/multi-buffer.js +++ b/benchmark/dgram/multi-buffer.js @@ -7,7 +7,7 @@ const PORT = common.PORT; // `num` is the number of send requests to queue up each time. // Keep it reasonably high (>10) otherwise you're benchmarking the speed of // event loop cycles more than anything else. -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [64, 256, 1024], num: [100], chunks: [1, 2, 4, 8], @@ -37,12 +37,12 @@ function main(conf) { server(); } -var dgram = require('dgram'); +const dgram = require('dgram'); function server() { var sent = 0; var received = 0; - var socket = dgram.createSocket('udp4'); + const socket = dgram.createSocket('udp4'); function onsend() { if (sent++ % num === 0) { @@ -57,8 +57,8 @@ function server() { onsend(); setTimeout(function() { - var bytes = (type === 'send' ? sent : received) * len; - var gbits = (bytes * 8) / (1024 * 1024 * 1024); + const bytes = (type === 'send' ? sent : received) * len; + const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(gbits); process.exit(0); }, dur * 1000); diff --git a/benchmark/dgram/offset-length.js b/benchmark/dgram/offset-length.js index 0445f7b70bec8b..7f5a02afe58107 100644 --- a/benchmark/dgram/offset-length.js +++ b/benchmark/dgram/offset-length.js @@ -7,7 +7,7 @@ const PORT = common.PORT; // `num` is the number of send requests to queue up each time. // Keep it reasonably high (>10) otherwise you're benchmarking the speed of // event loop cycles more than anything else. -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [1, 64, 256, 1024], num: [100], type: ['send', 'recv'], @@ -29,12 +29,12 @@ function main(conf) { server(); } -var dgram = require('dgram'); +const dgram = require('dgram'); function server() { var sent = 0; var received = 0; - var socket = dgram.createSocket('udp4'); + const socket = dgram.createSocket('udp4'); function onsend() { if (sent++ % num === 0) { @@ -49,8 +49,8 @@ function server() { onsend(); setTimeout(function() { - var bytes = (type === 'send' ? sent : received) * chunk.length; - var gbits = (bytes * 8) / (1024 * 1024 * 1024); + const bytes = (type === 'send' ? sent : received) * chunk.length; + const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(gbits); process.exit(0); }, dur * 1000); diff --git a/benchmark/dgram/single-buffer.js b/benchmark/dgram/single-buffer.js index e5fcac63f640fc..454662b5425df7 100644 --- a/benchmark/dgram/single-buffer.js +++ b/benchmark/dgram/single-buffer.js @@ -7,7 +7,7 @@ const PORT = common.PORT; // `num` is the number of send requests to queue up each time. // Keep it reasonably high (>10) otherwise you're benchmarking the speed of // event loop cycles more than anything else. -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [1, 64, 256, 1024], num: [100], type: ['send', 'recv'], @@ -29,12 +29,12 @@ function main(conf) { server(); } -var dgram = require('dgram'); +const dgram = require('dgram'); function server() { var sent = 0; var received = 0; - var socket = dgram.createSocket('udp4'); + const socket = dgram.createSocket('udp4'); function onsend() { if (sent++ % num === 0) { @@ -49,8 +49,8 @@ function server() { onsend(); setTimeout(function() { - var bytes = (type === 'send' ? sent : received) * chunk.length; - var gbits = (bytes * 8) / (1024 * 1024 * 1024); + const bytes = (type === 'send' ? sent : received) * chunk.length; + const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(gbits); process.exit(0); }, dur * 1000); diff --git a/benchmark/domain/domain-fn-args.js b/benchmark/domain/domain-fn-args.js index 20f452d67a6f9a..0b98d17674064c 100644 --- a/benchmark/domain/domain-fn-args.js +++ b/benchmark/domain/domain-fn-args.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../common.js'); -var domain = require('domain'); +const common = require('../common.js'); +const domain = require('domain'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { arguments: [0, 1, 2, 3], n: [10] }); -var bdomain = domain.create(); -var gargs = [1, 2, 3]; +const bdomain = domain.create(); +const gargs = [1, 2, 3]; function main(conf) { - var n = +conf.n; - var myArguments = gargs.slice(0, conf.arguments); + const n = +conf.n; + const myArguments = gargs.slice(0, conf.arguments); bench.start(); bdomain.enter(); diff --git a/benchmark/es/destructuring-object-bench.js b/benchmark/es/destructuring-object-bench.js index a3277aa6bfb99f..3edfa6d60bad92 100644 --- a/benchmark/es/destructuring-object-bench.js +++ b/benchmark/es/destructuring-object-bench.js @@ -9,13 +9,13 @@ const bench = common.createBenchmark(main, { function runNormal(n) { var i = 0; - var o = { x: 0, y: 1 }; + const o = { x: 0, y: 1 }; bench.start(); for (; i < n; i++) { /* eslint-disable no-unused-vars */ - var x = o.x; - var y = o.y; - var r = o.r || 2; + const x = o.x; + const y = o.y; + const r = o.r || 2; /* eslint-enable no-unused-vars */ } bench.end(n / 1e6); @@ -23,11 +23,11 @@ function runNormal(n) { function runDestructured(n) { var i = 0; - var o = { x: 0, y: 1 }; + const o = { x: 0, y: 1 }; bench.start(); for (; i < n; i++) { /* eslint-disable no-unused-vars */ - var { x, y, r = 2 } = o; + const { x, y, r = 2 } = o; /* eslint-enable no-unused-vars */ } bench.end(n / 1e6); diff --git a/benchmark/es/foreach-bench.js b/benchmark/es/foreach-bench.js index fea5318bc6669b..26c741b7066604 100644 --- a/benchmark/es/foreach-bench.js +++ b/benchmark/es/foreach-bench.js @@ -14,7 +14,7 @@ function useFor(n, items, count) { for (i = 0; i < n; i++) { for (j = 0; j < count; j++) { /* eslint-disable no-unused-vars */ - var item = items[j]; + const item = items[j]; /* esline-enable no-unused-vars */ } } diff --git a/benchmark/es/restparams-bench.js b/benchmark/es/restparams-bench.js index f5c49dd969b40a..d893af48f4df5f 100644 --- a/benchmark/es/restparams-bench.js +++ b/benchmark/es/restparams-bench.js @@ -9,8 +9,8 @@ const bench = common.createBenchmark(main, { }); function copyArguments() { - var len = arguments.length; - var args = new Array(len); + const len = arguments.length; + const args = new Array(len); for (var i = 0; i < len; i++) args[i] = arguments[i]; assert.strictEqual(args[0], 1); diff --git a/benchmark/events/ee-add-remove.js b/benchmark/events/ee-add-remove.js index 1140a81649f9a6..7b6ec35f29b636 100644 --- a/benchmark/events/ee-add-remove.js +++ b/benchmark/events/ee-add-remove.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common.js'); -var events = require('events'); +const common = require('../common.js'); +const events = require('events'); -var bench = common.createBenchmark(main, {n: [25e4]}); +const bench = common.createBenchmark(main, { n: [25e4] }); function main(conf) { - var n = conf.n | 0; + const n = conf.n | 0; - var ee = new events.EventEmitter(); - var listeners = []; + const ee = new events.EventEmitter(); + const listeners = []; var k; for (k = 0; k < 10; k += 1) @@ -16,7 +16,7 @@ function main(conf) { bench.start(); for (var i = 0; i < n; i += 1) { - var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; + const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; for (k = listeners.length; --k >= 0; /* empty */) { ee.on(dummy, listeners[k]); } diff --git a/benchmark/events/ee-emit-multi-args.js b/benchmark/events/ee-emit-multi-args.js index b423c216b1ed73..ffe6c16a402f07 100644 --- a/benchmark/events/ee-emit-multi-args.js +++ b/benchmark/events/ee-emit-multi-args.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common.js'); -var EventEmitter = require('events').EventEmitter; +const common = require('../common.js'); +const EventEmitter = require('events').EventEmitter; -var bench = common.createBenchmark(main, {n: [2e6]}); +const bench = common.createBenchmark(main, { n: [2e6] }); function main(conf) { - var n = conf.n | 0; + const n = conf.n | 0; - var ee = new EventEmitter(); + const ee = new EventEmitter(); for (var k = 0; k < 10; k += 1) ee.on('dummy', function() {}); diff --git a/benchmark/events/ee-emit.js b/benchmark/events/ee-emit.js index 87772222f0a467..9eef9f675605e2 100644 --- a/benchmark/events/ee-emit.js +++ b/benchmark/events/ee-emit.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common.js'); -var EventEmitter = require('events').EventEmitter; +const common = require('../common.js'); +const EventEmitter = require('events').EventEmitter; -var bench = common.createBenchmark(main, {n: [2e6]}); +const bench = common.createBenchmark(main, { n: [2e6] }); function main(conf) { - var n = conf.n | 0; + const n = conf.n | 0; - var ee = new EventEmitter(); + const ee = new EventEmitter(); for (var k = 0; k < 10; k += 1) ee.on('dummy', function() {}); diff --git a/benchmark/events/ee-listener-count-on-prototype.js b/benchmark/events/ee-listener-count-on-prototype.js index 269fd5a493ee34..708f62f06687fe 100644 --- a/benchmark/events/ee-listener-count-on-prototype.js +++ b/benchmark/events/ee-listener-count-on-prototype.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common.js'); -var EventEmitter = require('events').EventEmitter; +const common = require('../common.js'); +const EventEmitter = require('events').EventEmitter; -var bench = common.createBenchmark(main, {n: [5e7]}); +const bench = common.createBenchmark(main, { n: [5e7] }); function main(conf) { - var n = conf.n | 0; + const n = conf.n | 0; - var ee = new EventEmitter(); + const ee = new EventEmitter(); for (var k = 0; k < 5; k += 1) { ee.on('dummy0', function() {}); @@ -16,7 +16,7 @@ function main(conf) { bench.start(); for (var i = 0; i < n; i += 1) { - var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; + const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; ee.listenerCount(dummy); } bench.end(n); diff --git a/benchmark/events/ee-listeners-many.js b/benchmark/events/ee-listeners-many.js index 09e533de32bf9a..6cb0682b1ca9c3 100644 --- a/benchmark/events/ee-listeners-many.js +++ b/benchmark/events/ee-listeners-many.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common.js'); -var EventEmitter = require('events').EventEmitter; +const common = require('../common.js'); +const EventEmitter = require('events').EventEmitter; -var bench = common.createBenchmark(main, {n: [5e6]}); +const bench = common.createBenchmark(main, { n: [5e6] }); function main(conf) { - var n = conf.n | 0; + const n = conf.n | 0; - var ee = new EventEmitter(); + const ee = new EventEmitter(); ee.setMaxListeners(101); for (var k = 0; k < 50; k += 1) { @@ -17,7 +17,7 @@ function main(conf) { bench.start(); for (var i = 0; i < n; i += 1) { - var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; + const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; ee.listeners(dummy); } bench.end(n); diff --git a/benchmark/events/ee-listeners.js b/benchmark/events/ee-listeners.js index 56c0e85dad41a4..dff73de0b17fc4 100644 --- a/benchmark/events/ee-listeners.js +++ b/benchmark/events/ee-listeners.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common.js'); -var EventEmitter = require('events').EventEmitter; +const common = require('../common.js'); +const EventEmitter = require('events').EventEmitter; -var bench = common.createBenchmark(main, {n: [5e6]}); +const bench = common.createBenchmark(main, { n: [5e6] }); function main(conf) { - var n = conf.n | 0; + const n = conf.n | 0; - var ee = new EventEmitter(); + const ee = new EventEmitter(); for (var k = 0; k < 5; k += 1) { ee.on('dummy0', function() {}); @@ -16,7 +16,7 @@ function main(conf) { bench.start(); for (var i = 0; i < n; i += 1) { - var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; + const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; ee.listeners(dummy); } bench.end(n); diff --git a/benchmark/events/ee-once.js b/benchmark/events/ee-once.js index 56f7fb9e7c3a9e..d9e87a2b0843af 100644 --- a/benchmark/events/ee-once.js +++ b/benchmark/events/ee-once.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../common.js'); -var EventEmitter = require('events').EventEmitter; +const common = require('../common.js'); +const EventEmitter = require('events').EventEmitter; -var bench = common.createBenchmark(main, {n: [2e7]}); +const bench = common.createBenchmark(main, { n: [2e7] }); function main(conf) { - var n = conf.n | 0; + const n = conf.n | 0; - var ee = new EventEmitter(); + const ee = new EventEmitter(); function listener() {} bench.start(); for (var i = 0; i < n; i += 1) { - var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; + const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; ee.once(dummy, listener); ee.emit(dummy); } diff --git a/benchmark/fixtures/simple-http-server.js b/benchmark/fixtures/simple-http-server.js index 854d249ac803e0..5f56bebdafd75f 100644 --- a/benchmark/fixtures/simple-http-server.js +++ b/benchmark/fixtures/simple-http-server.js @@ -1,18 +1,18 @@ 'use strict'; -var http = require('http'); +const http = require('http'); -var fixed = 'C'.repeat(20 * 1024); -var storedBytes = Object.create(null); -var storedBuffer = Object.create(null); -var storedUnicode = Object.create(null); +const fixed = 'C'.repeat(20 * 1024); +const storedBytes = Object.create(null); +const storedBuffer = Object.create(null); +const storedUnicode = Object.create(null); -var useDomains = process.env.NODE_USE_DOMAINS; +const useDomains = process.env.NODE_USE_DOMAINS; // set up one global domain. if (useDomains) { var domain = require('domain'); - var gdom = domain.create(); + const gdom = domain.create(); gdom.on('error', function(er) { console.error('Error on global domain', er); throw er; @@ -22,19 +22,19 @@ if (useDomains) { module.exports = http.createServer(function(req, res) { if (useDomains) { - var dom = domain.create(); + const dom = domain.create(); dom.add(req); dom.add(res); } // URL format: /////chunkedEnc - var params = req.url.split('/'); - var command = params[1]; + const params = req.url.split('/'); + const command = params[1]; var body = ''; - var arg = params[2]; - var n_chunks = parseInt(params[3], 10); - var resHow = (params.length >= 5 ? params[4] : 'normal'); - var chunkedEnc = (params.length >= 6 && params[5] === 'false' ? false : true); + const arg = params[2]; + const n_chunks = parseInt(params[3], 10); + const resHow = params.length >= 5 ? params[4] : 'normal'; + const chunkedEnc = params.length >= 6 && params[5] === 'false' ? false : true; var status = 200; var n, i; @@ -96,7 +96,7 @@ module.exports = http.createServer(function(req, res) { // example: http://localhost:port/bytes/512/4 // sends a 512 byte body in 4 chunks of 128 bytes - var len = body.length; + const len = body.length; switch (resHow) { case 'setHeader': res.statusCode = status; @@ -128,7 +128,7 @@ module.exports = http.createServer(function(req, res) { } // send body in chunks if (n_chunks > 1) { - var step = Math.floor(len / n_chunks) || 1; + const step = Math.floor(len / n_chunks) || 1; for (i = 0, n = (n_chunks - 1); i < n; ++i) res.write(body.slice(i * step, i * step + step)); res.end(body.slice((n_chunks - 1) * step)); diff --git a/benchmark/fs/read-stream-throughput.js b/benchmark/fs/read-stream-throughput.js index bc55e44c1a18d7..6cacc026ef5e60 100644 --- a/benchmark/fs/read-stream-throughput.js +++ b/benchmark/fs/read-stream-throughput.js @@ -1,16 +1,16 @@ // test the throughput of the fs.WriteStream class. 'use strict'; -var path = require('path'); -var common = require('../common.js'); -var filename = path.resolve(__dirname, '.removeme-benchmark-garbage'); -var fs = require('fs'); -var filesize = 1000 * 1024 * 1024; -var assert = require('assert'); +const path = require('path'); +const common = require('../common.js'); +const filename = path.resolve(__dirname, '.removeme-benchmark-garbage'); +const fs = require('fs'); +const filesize = 1000 * 1024 * 1024; +const assert = require('assert'); var type, encoding, size; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { type: ['buf', 'asc', 'utf'], size: [1024, 4096, 65535, 1024 * 1024] }); @@ -38,7 +38,7 @@ function main(conf) { function runTest() { assert(fs.statSync(filename).size === filesize); - var rs = fs.createReadStream(filename, { + const rs = fs.createReadStream(filename, { highWaterMark: size, encoding: encoding }); @@ -60,7 +60,7 @@ function runTest() { } function makeFile() { - var buf = Buffer.allocUnsafe(filesize / 1024); + const buf = Buffer.allocUnsafe(filesize / 1024); if (encoding === 'utf8') { // ü for (var i = 0; i < buf.length; i++) { @@ -74,7 +74,7 @@ function makeFile() { try { fs.unlinkSync(filename); } catch (e) {} var w = 1024; - var ws = fs.createWriteStream(filename); + const ws = fs.createWriteStream(filename); ws.on('close', runTest); ws.on('drain', write); write(); diff --git a/benchmark/fs/readFileSync.js b/benchmark/fs/readFileSync.js index 7c8f5d240d1da9..8fd0b50421e761 100644 --- a/benchmark/fs/readFileSync.js +++ b/benchmark/fs/readFileSync.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../common.js'); -var fs = require('fs'); +const common = require('../common.js'); +const fs = require('fs'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { n: [60e4] }); function main(conf) { - var n = +conf.n; + const n = +conf.n; bench.start(); for (var i = 0; i < n; ++i) diff --git a/benchmark/fs/readfile.js b/benchmark/fs/readfile.js index 9fc8316743e285..d89061d6061b0c 100644 --- a/benchmark/fs/readfile.js +++ b/benchmark/fs/readfile.js @@ -3,19 +3,19 @@ // Yes, this is a silly benchmark. Most benchmarks are silly. 'use strict'; -var path = require('path'); -var common = require('../common.js'); -var filename = path.resolve(__dirname, '.removeme-benchmark-garbage'); -var fs = require('fs'); +const path = require('path'); +const common = require('../common.js'); +const filename = path.resolve(__dirname, '.removeme-benchmark-garbage'); +const fs = require('fs'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { dur: [5], len: [1024, 16 * 1024 * 1024], concurrent: [1, 10] }); function main(conf) { - var len = +conf.len; + const len = +conf.len; try { fs.unlinkSync(filename); } catch (e) {} var data = Buffer.alloc(len, 'x'); fs.writeFileSync(filename, data); diff --git a/benchmark/fs/write-stream-throughput.js b/benchmark/fs/write-stream-throughput.js index 3e54c09199409c..1bdb4bcd662181 100644 --- a/benchmark/fs/write-stream-throughput.js +++ b/benchmark/fs/write-stream-throughput.js @@ -1,21 +1,21 @@ // test the throughput of the fs.WriteStream class. 'use strict'; -var path = require('path'); -var common = require('../common.js'); -var filename = path.resolve(__dirname, '.removeme-benchmark-garbage'); -var fs = require('fs'); +const path = require('path'); +const common = require('../common.js'); +const filename = path.resolve(__dirname, '.removeme-benchmark-garbage'); +const fs = require('fs'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { dur: [5], type: ['buf', 'asc', 'utf'], size: [2, 1024, 65535, 1024 * 1024] }); function main(conf) { - var dur = +conf.dur; - var type = conf.type; - var size = +conf.size; + const dur = +conf.dur; + const type = conf.type; + const size = +conf.size; var encoding; var chunk; @@ -51,7 +51,7 @@ function main(conf) { f.on('close', done); f.on('finish', function() { ended = true; - var written = fs.statSync(filename).size / 1024; + const written = fs.statSync(filename).size / 1024; try { fs.unlinkSync(filename); } catch (e) {} bench.end(written / 1024); }); diff --git a/benchmark/http/_chunky_http_client.js b/benchmark/http/_chunky_http_client.js index d7c4e193c8c3c9..ee1f4f8caa2510 100644 --- a/benchmark/http/_chunky_http_client.js +++ b/benchmark/http/_chunky_http_client.js @@ -1,10 +1,10 @@ 'use strict'; // test HTTP throughput in fragmented header case -var common = require('../common.js'); -var net = require('net'); +const common = require('../common.js'); +const net = require('net'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [1, 4, 8, 16, 32, 64, 128], n: [5, 50, 500, 2000], type: ['send'], @@ -12,10 +12,10 @@ var bench = common.createBenchmark(main, { function main(conf) { - var len = +conf.len; - var num = +conf.n; + const len = +conf.len; + const num = +conf.n; var todo = []; - var headers = []; + const headers = []; // Chose 7 because 9 showed "Connection error" / "Connection closed" // An odd number could result in a better length dispersion. for (var i = 7; i <= 7 * 7 * 7; i *= 7) @@ -42,20 +42,20 @@ function main(conf) { todo.push(''); todo = todo.join('\r\n'); // Using odd numbers in many places may increase length coverage. - var chunksize = 37; + const chunksize = 37; for (i = 0; i < todo.length; i += chunksize) { - var cur = todo.slice(i, i + chunksize); + const cur = todo.slice(i, i + chunksize); channel.write(cur); } } - var min = 10; + const min = 10; var size = 0; - var mod = 317; - var mult = 17; - var add = 11; + const mod = 317; + const mult = 17; + const add = 11; var count = 0; - var PIPE = process.env.PIPE_NAME; + const PIPE = process.env.PIPE_NAME; var socket = net.connect(PIPE, function() { bench.start(); WriteHTTPHeaders(socket, 1, len); diff --git a/benchmark/http/check_invalid_header_char.js b/benchmark/http/check_invalid_header_char.js index bef44e63167078..d71bc6fc607ef5 100644 --- a/benchmark/http/check_invalid_header_char.js +++ b/benchmark/http/check_invalid_header_char.js @@ -27,12 +27,12 @@ const bench = common.createBenchmark(main, { 'foo\nbar', '\x7F' ], - n: [5e8], + n: [1e6], }); function main(conf) { - var n = +conf.n; - var key = conf.key; + const n = +conf.n; + const key = conf.key; bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/http/check_is_http_token.js b/benchmark/http/check_is_http_token.js index a317e05a4a12d2..92df3445b45c45 100644 --- a/benchmark/http/check_is_http_token.js +++ b/benchmark/http/check_is_http_token.js @@ -37,12 +37,12 @@ const bench = common.createBenchmark(main, { ':alternate-protocol', // fast bailout 'alternate-protocol:' // slow bailout ], - n: [5e8], + n: [1e6], }); function main(conf) { - var n = +conf.n; - var key = conf.key; + const n = +conf.n; + const key = conf.key; bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/http/chunked.js b/benchmark/http/chunked.js index 34a06a1a6d8320..1056f456ef827d 100644 --- a/benchmark/http/chunked.js +++ b/benchmark/http/chunked.js @@ -8,9 +8,9 @@ // Verify that our assumptions are valid. 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { n: [1, 4, 8, 16], len: [1, 64, 256], c: [100] @@ -18,9 +18,9 @@ var bench = common.createBenchmark(main, { function main(conf) { const http = require('http'); - var chunk = Buffer.alloc(conf.len, '8'); + const chunk = Buffer.alloc(conf.len, '8'); - var server = http.createServer(function(req, res) { + const server = http.createServer(function(req, res) { function send(left) { if (left === 0) return res.end(); res.write(chunk); diff --git a/benchmark/http/client-request-body.js b/benchmark/http/client-request-body.js index d521c8a2c847e3..a6849580cfb44d 100644 --- a/benchmark/http/client-request-body.js +++ b/benchmark/http/client-request-body.js @@ -1,10 +1,10 @@ // Measure the time it takes for the HTTP client to send a request body. 'use strict'; -var common = require('../common.js'); -var http = require('http'); +const common = require('../common.js'); +const http = require('http'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { dur: [5], type: ['asc', 'utf', 'buf'], len: [32, 256, 1024], @@ -12,8 +12,8 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var dur = +conf.dur; - var len = +conf.len; + const dur = +conf.dur; + const len = +conf.len; var encoding; var chunk; @@ -31,7 +31,7 @@ function main(conf) { } var nreqs = 0; - var options = { + const options = { headers: { 'Connection': 'keep-alive', 'Transfer-Encoding': 'chunked' }, agent: new http.Agent({ maxSockets: 1 }), host: '127.0.0.1', @@ -40,7 +40,7 @@ function main(conf) { method: 'POST' }; - var server = http.createServer(function(req, res) { + const server = http.createServer(function(req, res) { res.end(); }); server.listen(options.port, options.host, function() { @@ -50,7 +50,7 @@ function main(conf) { }); function pummel() { - var req = http.request(options, function(res) { + const req = http.request(options, function(res) { nreqs++; pummel(); // Line up next request. res.resume(); diff --git a/benchmark/http/cluster.js b/benchmark/http/cluster.js index 3a9392c4229667..352b1d2645008f 100644 --- a/benchmark/http/cluster.js +++ b/benchmark/http/cluster.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var PORT = common.PORT; +const common = require('../common.js'); +const PORT = common.PORT; -var cluster = require('cluster'); +const cluster = require('cluster'); if (cluster.isMaster) { var bench = common.createBenchmark(main, { // unicode confuses ab on os x. @@ -11,15 +11,15 @@ if (cluster.isMaster) { c: [50, 500] }); } else { - var port = parseInt(process.env.PORT || PORT); + const port = parseInt(process.env.PORT || PORT); require('../fixtures/simple-http-server.js').listen(port); } function main(conf) { process.env.PORT = PORT; var workers = 0; - var w1 = cluster.fork(); - var w2 = cluster.fork(); + const w1 = cluster.fork(); + const w2 = cluster.fork(); cluster.on('listening', function() { workers++; @@ -27,7 +27,7 @@ function main(conf) { return; setTimeout(function() { - var path = `/${conf.type}/${conf.len}`; + const path = `/${conf.type}/${conf.len}`; bench.http({ path: path, diff --git a/benchmark/http/create-clientrequest.js b/benchmark/http/create-clientrequest.js index f40ff9155dae50..d19a6fb43441ce 100644 --- a/benchmark/http/create-clientrequest.js +++ b/benchmark/http/create-clientrequest.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../common.js'); -var ClientRequest = require('http').ClientRequest; +const common = require('../common.js'); +const ClientRequest = require('http').ClientRequest; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [1, 8, 16, 32, 64, 128], n: [1e6] }); function main(conf) { - var len = +conf.len; - var n = +conf.n; + const len = +conf.len; + const n = +conf.n; - var path = '/'.repeat(len); - var opts = { path: path, createConnection: function() {} }; + const path = '/'.repeat(len); + const opts = { path: path, createConnection: function() {} }; bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/http/end-vs-write-end.js b/benchmark/http/end-vs-write-end.js index 163ad595a93aca..b7db1eaa7839e2 100644 --- a/benchmark/http/end-vs-write-end.js +++ b/benchmark/http/end-vs-write-end.js @@ -8,9 +8,9 @@ // Verify that our assumptions are valid. 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { type: ['asc', 'utf', 'buf'], len: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024], c: [100], @@ -20,7 +20,7 @@ var bench = common.createBenchmark(main, { function main(conf) { const http = require('http'); var chunk; - var len = conf.len; + const len = conf.len; switch (conf.type) { case 'buf': chunk = Buffer.alloc(len, 'x'); @@ -42,9 +42,9 @@ function main(conf) { res.end(chunk); } - var method = conf.method === 'write' ? write : end; + const method = conf.method === 'write' ? write : end; - var server = http.createServer(function(req, res) { + const server = http.createServer(function(req, res) { method(res); }); diff --git a/benchmark/http/http_server_for_chunky_client.js b/benchmark/http/http_server_for_chunky_client.js index cc632c02ec4222..f079544e03d48e 100644 --- a/benchmark/http/http_server_for_chunky_client.js +++ b/benchmark/http/http_server_for_chunky_client.js @@ -1,10 +1,10 @@ 'use strict'; -var assert = require('assert'); -var http = require('http'); -var fs = require('fs'); -var { fork } = require('child_process'); -var common = require('../common.js'); +const assert = require('assert'); +const http = require('http'); +const fs = require('fs'); +const { fork } = require('child_process'); +const common = require('../common.js'); const { PIPE, tmpDir } = require('../../test/common'); process.env.PIPE_NAME = PIPE; @@ -20,7 +20,7 @@ try { } catch (e) { /* ignore */ } server = http.createServer(function(req, res) { - var headers = { + const headers = { 'content-type': 'text/plain', 'content-length': '2' }; diff --git a/benchmark/http/simple.js b/benchmark/http/simple.js index 6dc69a2d8f6e85..238cd1885d3ca7 100644 --- a/benchmark/http/simple.js +++ b/benchmark/http/simple.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var PORT = common.PORT; +const common = require('../common.js'); +const PORT = common.PORT; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { // unicode confuses ab on os x. type: ['bytes', 'buffer'], len: [4, 1024, 102400], @@ -17,7 +17,7 @@ function main(conf) { var server = require('../fixtures/simple-http-server.js') .listen(process.env.PORT || common.PORT) .on('listening', function() { - var path = + const path = `/${conf.type}/${conf.len}/${conf.chunks}/${conf.res}/${conf.chunkedEnc}`; bench.http({ diff --git a/benchmark/http2/headers.js b/benchmark/http2/headers.js index 078e7a356a0df8..dc2fb3a0a1fd18 100644 --- a/benchmark/http2/headers.js +++ b/benchmark/http2/headers.js @@ -3,7 +3,7 @@ const common = require('../common.js'); const PORT = common.PORT; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { n: [1e3], nheaders: [0, 10, 100, 1000], }, { flags: ['--expose-http2', '--no-warnings'] }); diff --git a/benchmark/http2/respond-with-fd.js b/benchmark/http2/respond-with-fd.js index d7a312c78bf4da..2c4c767a96f7cc 100644 --- a/benchmark/http2/respond-with-fd.js +++ b/benchmark/http2/respond-with-fd.js @@ -7,7 +7,7 @@ const fs = require('fs'); const file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { requests: [100, 1000, 10000, 100000, 1000000], streams: [100, 200, 1000], clients: [1, 2] diff --git a/benchmark/http2/simple.js b/benchmark/http2/simple.js index d12b20fc5ac773..d0674fd95231b6 100644 --- a/benchmark/http2/simple.js +++ b/benchmark/http2/simple.js @@ -8,7 +8,7 @@ const fs = require('fs'); const file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { requests: [100, 1000, 10000, 100000], streams: [100, 200, 1000], clients: [1, 2] diff --git a/benchmark/http2/write.js b/benchmark/http2/write.js index df76794468b4de..03fe128c6b606e 100644 --- a/benchmark/http2/write.js +++ b/benchmark/http2/write.js @@ -3,7 +3,7 @@ const common = require('../common.js'); const PORT = common.PORT; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { streams: [100, 200, 1000], length: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024], }, { flags: ['--expose-http2', '--no-warnings'] }); diff --git a/benchmark/misc/console.js b/benchmark/misc/console.js index 9c7c54859082cd..8e9fbd8c543aad 100644 --- a/benchmark/misc/console.js +++ b/benchmark/misc/console.js @@ -12,7 +12,7 @@ const methods = [ 'restAndConcat' ]; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { method: methods, concat: [1, 0], n: [1000000] diff --git a/benchmark/misc/freelist.js b/benchmark/misc/freelist.js index 8c4aeb05ef0472..461f4b3e4c8960 100644 --- a/benchmark/misc/freelist.js +++ b/benchmark/misc/freelist.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { n: [100000] }, { flags: ['--expose-internals'] @@ -10,12 +10,12 @@ var bench = common.createBenchmark(main, { function main(conf) { const FreeList = require('internal/freelist'); - var n = conf.n; - var poolSize = 1000; - var list = new FreeList('test', poolSize, Object); + const n = conf.n; + const poolSize = 1000; + const list = new FreeList('test', poolSize, Object); var i; var j; - var used = []; + const used = []; // First, alloc `poolSize` items for (j = 0; j < poolSize; j++) { diff --git a/benchmark/misc/function_call/index.js b/benchmark/misc/function_call/index.js index 04f5627093893e..6a2595d2ae188d 100644 --- a/benchmark/misc/function_call/index.js +++ b/benchmark/misc/function_call/index.js @@ -4,8 +4,8 @@ // Note that JS speed goes up, while cxx speed stays about the same. 'use strict'; -var assert = require('assert'); -var common = require('../../common.js'); +const assert = require('assert'); +const common = require('../../common.js'); // this fails when we try to open with a different version of node, // which is quite common for benchmarks. so in that case, just @@ -17,7 +17,7 @@ try { console.error('misc/function_call.js Binding failed to load'); process.exit(0); } -var cxx = binding.hello; +const cxx = binding.hello; var c = 0; function js() { @@ -26,15 +26,15 @@ function js() { assert(js() === cxx()); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { type: ['js', 'cxx'], millions: [1, 10, 50] }); function main(conf) { - var n = +conf.millions * 1e6; + const n = +conf.millions * 1e6; - var fn = conf.type === 'cxx' ? cxx : js; + const fn = conf.type === 'cxx' ? cxx : js; bench.start(); for (var i = 0; i < n; i++) { fn(); diff --git a/benchmark/misc/startup.js b/benchmark/misc/startup.js index 34604911d250f3..b010f9fa469070 100644 --- a/benchmark/misc/startup.js +++ b/benchmark/misc/startup.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common.js'); -var spawn = require('child_process').spawn; -var path = require('path'); -var emptyJsFile = path.resolve(__dirname, '../../test/fixtures/semicolon.js'); +const common = require('../common.js'); +const spawn = require('child_process').spawn; +const path = require('path'); +const emptyJsFile = path.resolve(__dirname, '../../test/fixtures/semicolon.js'); -var bench = common.createBenchmark(startNode, { +const bench = common.createBenchmark(startNode, { dur: [1] }); function startNode(conf) { - var dur = +conf.dur; + const dur = +conf.dur; var go = true; var starts = 0; @@ -21,7 +21,7 @@ function startNode(conf) { start(); function start() { - var node = spawn(process.execPath || process.argv[0], [emptyJsFile]); + const node = spawn(process.execPath || process.argv[0], [emptyJsFile]); node.on('exit', function(exitCode) { if (exitCode !== 0) { throw new Error('Error during node startup'); diff --git a/benchmark/misc/util-extend-vs-object-assign.js b/benchmark/misc/util-extend-vs-object-assign.js index 41c15d7d2caa0c..f2a039bc5d71fc 100644 --- a/benchmark/misc/util-extend-vs-object-assign.js +++ b/benchmark/misc/util-extend-vs-object-assign.js @@ -23,7 +23,7 @@ function main(conf) { for (var i = 0; i < conf.type.length * 10; i += 1) fn({}, process.env); - var obj = new Proxy({}, { set: function(a, b, c) { return true; } }); + const obj = new Proxy({}, { set: function(a, b, c) { return true; } }); bench.start(); for (var j = 0; j < n; j += 1) diff --git a/benchmark/misc/v8-bench.js b/benchmark/misc/v8-bench.js index 97ff0c35c47e87..fe004251cb6cbe 100644 --- a/benchmark/misc/v8-bench.js +++ b/benchmark/misc/v8-bench.js @@ -1,11 +1,11 @@ // compare with "google-chrome deps/v8/benchmarks/run.html" 'use strict'; -var fs = require('fs'); -var path = require('path'); -var vm = require('vm'); -var common = require('../common.js'); +const fs = require('fs'); +const path = require('path'); +const vm = require('vm'); +const common = require('../common.js'); -var dir = path.join(__dirname, '..', '..', 'deps', 'v8', 'benchmarks'); +const dir = path.join(__dirname, '..', '..', 'deps', 'v8', 'benchmarks'); function load(filename, inGlobal) { var source = fs.readFileSync(path.join(dir, filename), 'utf8'); diff --git a/benchmark/module/module-loader.js b/benchmark/module/module-loader.js index 7c72ac1d5c6559..d40e36dc3e373e 100644 --- a/benchmark/module/module-loader.js +++ b/benchmark/module/module-loader.js @@ -1,19 +1,19 @@ 'use strict'; -var fs = require('fs'); -var path = require('path'); -var common = require('../common.js'); +const fs = require('fs'); +const path = require('path'); +const common = require('../common.js'); -var tmpDirectory = path.join(__dirname, '..', 'tmp'); -var benchmarkDirectory = path.join(tmpDirectory, 'nodejs-benchmark-module'); +const tmpDirectory = path.join(__dirname, '..', 'tmp'); +const benchmarkDirectory = path.join(tmpDirectory, 'nodejs-benchmark-module'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { thousands: [50], fullPath: ['true', 'false'], useCache: ['true', 'false'] }); function main(conf) { - var n = +conf.thousands * 1e3; + const n = +conf.thousands * 1e3; rmrf(tmpDirectory); try { fs.mkdirSync(tmpDirectory); } catch (e) {} @@ -69,7 +69,7 @@ function measureDir(n, useCache) { function rmrf(location) { try { - var things = fs.readdirSync(location); + const things = fs.readdirSync(location); things.forEach(function(thing) { var cur = path.join(location, thing), isDirectory = fs.statSync(cur).isDirectory(); diff --git a/benchmark/net/net-c2s-cork.js b/benchmark/net/net-c2s-cork.js index 51ad09ae9e52db..a6582caa16be56 100644 --- a/benchmark/net/net-c2s-cork.js +++ b/benchmark/net/net-c2s-cork.js @@ -1,10 +1,10 @@ // test the speed of .pipe() with sockets 'use strict'; -var common = require('../common.js'); -var PORT = common.PORT; +const common = require('../common.js'); +const PORT = common.PORT; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [4, 8, 16, 32, 64, 128, 512, 1024], type: ['buf'], dur: [5], @@ -40,7 +40,7 @@ function main(conf) { server(); } -var net = require('net'); +const net = require('net'); function Writer() { this.received = 0; @@ -65,15 +65,15 @@ Writer.prototype.emit = function() {}; Writer.prototype.prependListener = function() {}; function server() { - var writer = new Writer(); + const writer = new Writer(); // the actual benchmark. - var server = net.createServer(function(socket) { + const server = net.createServer(function(socket) { socket.pipe(writer); }); server.listen(PORT, function() { - var socket = net.connect(PORT); + const socket = net.connect(PORT); socket.on('connect', function() { bench.start(); @@ -81,8 +81,8 @@ function server() { send(); setTimeout(function() { - var bytes = writer.received; - var gbits = (bytes * 8) / (1024 * 1024 * 1024); + const bytes = writer.received; + const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(gbits); process.exit(0); }, dur * 1000); diff --git a/benchmark/net/net-c2s.js b/benchmark/net/net-c2s.js index 4bbea92121ac0a..140f9612ab1ed9 100644 --- a/benchmark/net/net-c2s.js +++ b/benchmark/net/net-c2s.js @@ -1,10 +1,10 @@ // test the speed of .pipe() with sockets 'use strict'; -var common = require('../common.js'); -var PORT = common.PORT; +const common = require('../common.js'); +const PORT = common.PORT; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5], @@ -40,7 +40,7 @@ function main(conf) { server(); } -var net = require('net'); +const net = require('net'); function Writer() { this.received = 0; @@ -66,8 +66,8 @@ Writer.prototype.prependListener = function() {}; function flow() { - var dest = this.dest; - var res = dest.write(chunk, encoding); + const dest = this.dest; + const res = dest.write(chunk, encoding); if (!res) dest.once('drain', this.flow); else @@ -87,24 +87,24 @@ Reader.prototype.pipe = function(dest) { function server() { - var reader = new Reader(); - var writer = new Writer(); + const reader = new Reader(); + const writer = new Writer(); // the actual benchmark. - var server = net.createServer(function(socket) { + const server = net.createServer(function(socket) { socket.pipe(writer); }); server.listen(PORT, function() { - var socket = net.connect(PORT); + const socket = net.connect(PORT); socket.on('connect', function() { bench.start(); reader.pipe(socket); setTimeout(function() { - var bytes = writer.received; - var gbits = (bytes * 8) / (1024 * 1024 * 1024); + const bytes = writer.received; + const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(gbits); process.exit(0); }, dur * 1000); diff --git a/benchmark/net/net-pipe.js b/benchmark/net/net-pipe.js index 507640f8cea236..a8ae50edfbfde0 100644 --- a/benchmark/net/net-pipe.js +++ b/benchmark/net/net-pipe.js @@ -1,10 +1,10 @@ // test the speed of .pipe() with sockets 'use strict'; -var common = require('../common.js'); -var PORT = common.PORT; +const common = require('../common.js'); +const PORT = common.PORT; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5], @@ -40,7 +40,7 @@ function main(conf) { server(); } -var net = require('net'); +const net = require('net'); function Writer() { this.received = 0; @@ -66,8 +66,8 @@ Writer.prototype.prependListener = function() {}; function flow() { - var dest = this.dest; - var res = dest.write(chunk, encoding); + const dest = this.dest; + const res = dest.write(chunk, encoding); if (!res) dest.once('drain', this.flow); else @@ -87,16 +87,16 @@ Reader.prototype.pipe = function(dest) { function server() { - var reader = new Reader(); - var writer = new Writer(); + const reader = new Reader(); + const writer = new Writer(); // the actual benchmark. - var server = net.createServer(function(socket) { + const server = net.createServer(function(socket) { socket.pipe(socket); }); server.listen(PORT, function() { - var socket = net.connect(PORT); + const socket = net.connect(PORT); socket.on('connect', function() { bench.start(); @@ -106,8 +106,8 @@ function server() { setTimeout(function() { // multiply by 2 since we're sending it first one way // then then back again. - var bytes = writer.received * 2; - var gbits = (bytes * 8) / (1024 * 1024 * 1024); + const bytes = writer.received * 2; + const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(gbits); process.exit(0); }, dur * 1000); diff --git a/benchmark/net/net-s2c.js b/benchmark/net/net-s2c.js index 9148a66f3af18f..9fec2d8577c098 100644 --- a/benchmark/net/net-s2c.js +++ b/benchmark/net/net-s2c.js @@ -1,10 +1,10 @@ // test the speed of .pipe() with sockets 'use strict'; -var common = require('../common.js'); -var PORT = common.PORT; +const common = require('../common.js'); +const PORT = common.PORT; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5] @@ -40,7 +40,7 @@ function main(conf) { server(); } -var net = require('net'); +const net = require('net'); function Writer() { this.received = 0; @@ -66,8 +66,8 @@ Writer.prototype.prependListener = function() {}; function flow() { - var dest = this.dest; - var res = dest.write(chunk, encoding); + const dest = this.dest; + const res = dest.write(chunk, encoding); if (!res) dest.once('drain', this.flow); else @@ -87,24 +87,24 @@ Reader.prototype.pipe = function(dest) { function server() { - var reader = new Reader(); - var writer = new Writer(); + const reader = new Reader(); + const writer = new Writer(); // the actual benchmark. - var server = net.createServer(function(socket) { + const server = net.createServer(function(socket) { reader.pipe(socket); }); server.listen(PORT, function() { - var socket = net.connect(PORT); + const socket = net.connect(PORT); socket.on('connect', function() { bench.start(); socket.pipe(writer); setTimeout(function() { - var bytes = writer.received; - var gbits = (bytes * 8) / (1024 * 1024 * 1024); + const bytes = writer.received; + const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(gbits); process.exit(0); }, dur * 1000); diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js index 87c6d5ec7e0ee7..9b2e926d690504 100644 --- a/benchmark/net/tcp-raw-c2s.js +++ b/benchmark/net/tcp-raw-c2s.js @@ -2,22 +2,22 @@ // as many bytes as we can in the specified time (default = 10s) 'use strict'; -var common = require('../common.js'); -var util = require('util'); +const common = require('../common.js'); +const util = require('util'); // if there are --dur=N and --len=N args, then // run the function with those settings. // if not, then queue up a bunch of child processes. -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5] }); -var TCP = process.binding('tcp_wrap').TCP; -var TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; -var WriteWrap = process.binding('stream_wrap').WriteWrap; -var PORT = common.PORT; +const TCP = process.binding('tcp_wrap').TCP; +const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; +const WriteWrap = process.binding('stream_wrap').WriteWrap; +const PORT = common.PORT; var dur; var len; @@ -36,7 +36,7 @@ function fail(err, syscall) { } function server() { - var serverHandle = new TCP(); + const serverHandle = new TCP(); var err = serverHandle.bind('127.0.0.1', PORT); if (err) fail(err, 'bind'); @@ -92,9 +92,9 @@ function client() { throw new Error(`invalid type: ${type}`); } - var clientHandle = new TCP(); - var connectReq = new TCPConnectWrap(); - var err = clientHandle.connect(connectReq, '127.0.0.1', PORT); + const clientHandle = new TCP(); + const connectReq = new TCPConnectWrap(); + const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); if (err) fail(err, 'connect'); @@ -110,7 +110,7 @@ function client() { }; function write() { - var writeReq = new WriteWrap(); + const writeReq = new WriteWrap(); writeReq.oncomplete = afterWrite; var err; switch (type) { diff --git a/benchmark/net/tcp-raw-pipe.js b/benchmark/net/tcp-raw-pipe.js index c6d319c64dd380..204b27b965a340 100644 --- a/benchmark/net/tcp-raw-pipe.js +++ b/benchmark/net/tcp-raw-pipe.js @@ -2,22 +2,22 @@ // as many bytes as we can in the specified time (default = 10s) 'use strict'; -var common = require('../common.js'); -var util = require('util'); +const common = require('../common.js'); +const util = require('util'); // if there are --dur=N and --len=N args, then // run the function with those settings. // if not, then queue up a bunch of child processes. -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5] }); -var TCP = process.binding('tcp_wrap').TCP; -var TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; -var WriteWrap = process.binding('stream_wrap').WriteWrap; -var PORT = common.PORT; +const TCP = process.binding('tcp_wrap').TCP; +const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; +const WriteWrap = process.binding('stream_wrap').WriteWrap; +const PORT = common.PORT; var dur; var len; @@ -35,7 +35,7 @@ function fail(err, syscall) { } function server() { - var serverHandle = new TCP(); + const serverHandle = new TCP(); var err = serverHandle.bind('127.0.0.1', PORT); if (err) fail(err, 'bind'); @@ -54,7 +54,7 @@ function server() { if (nread < 0) fail(nread, 'read'); - var writeReq = new WriteWrap(); + const writeReq = new WriteWrap(); writeReq.async = false; err = clientHandle.writeBuffer(writeReq, buffer); @@ -89,9 +89,9 @@ function client() { throw new Error(`invalid type: ${type}`); } - var clientHandle = new TCP(); - var connectReq = new TCPConnectWrap(); - var err = clientHandle.connect(connectReq, '127.0.0.1', PORT); + const clientHandle = new TCP(); + const connectReq = new TCPConnectWrap(); + const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); var bytes = 0; if (err) @@ -124,7 +124,7 @@ function client() { }; function write() { - var writeReq = new WriteWrap(); + const writeReq = new WriteWrap(); writeReq.oncomplete = afterWrite; var err; switch (type) { diff --git a/benchmark/net/tcp-raw-s2c.js b/benchmark/net/tcp-raw-s2c.js index 1c518a5c7fe426..412ded7355aa43 100644 --- a/benchmark/net/tcp-raw-s2c.js +++ b/benchmark/net/tcp-raw-s2c.js @@ -2,22 +2,22 @@ // as many bytes as we can in the specified time (default = 10s) 'use strict'; -var common = require('../common.js'); -var util = require('util'); +const common = require('../common.js'); +const util = require('util'); // if there are dur=N and len=N args, then // run the function with those settings. // if not, then queue up a bunch of child processes. -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { len: [102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5] }); -var TCP = process.binding('tcp_wrap').TCP; -var TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; -var WriteWrap = process.binding('stream_wrap').WriteWrap; -var PORT = common.PORT; +const TCP = process.binding('tcp_wrap').TCP; +const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; +const WriteWrap = process.binding('stream_wrap').WriteWrap; +const PORT = common.PORT; var dur; var len; @@ -35,7 +35,7 @@ function fail(err, syscall) { } function server() { - var serverHandle = new TCP(); + const serverHandle = new TCP(); var err = serverHandle.bind('127.0.0.1', PORT); if (err) fail(err, 'bind'); @@ -69,7 +69,7 @@ function server() { write(); function write() { - var writeReq = new WriteWrap(); + const writeReq = new WriteWrap(); writeReq.async = false; writeReq.oncomplete = afterWrite; var err; @@ -107,9 +107,9 @@ function server() { } function client() { - var clientHandle = new TCP(); - var connectReq = new TCPConnectWrap(); - var err = clientHandle.connect(connectReq, '127.0.0.1', PORT); + const clientHandle = new TCP(); + const connectReq = new TCPConnectWrap(); + const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); if (err) fail(err, 'connect'); diff --git a/benchmark/path/basename-posix.js b/benchmark/path/basename-posix.js index 10465b2c734a10..42e98c5932b028 100644 --- a/benchmark/path/basename-posix.js +++ b/benchmark/path/basename-posix.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { pathext: [ '', '/', @@ -19,11 +19,11 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.posix; + const n = +conf.n; + const p = path.posix; var input = String(conf.pathext); var ext; - var extIdx = input.indexOf('|'); + const extIdx = input.indexOf('|'); if (extIdx !== -1) { ext = input.slice(extIdx + 1); input = input.slice(0, extIdx); diff --git a/benchmark/path/basename-win32.js b/benchmark/path/basename-win32.js index 77bf326ed2bc84..6966e4fe81e1ac 100644 --- a/benchmark/path/basename-win32.js +++ b/benchmark/path/basename-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { pathext: [ '', 'C:\\', @@ -19,11 +19,11 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; + const n = +conf.n; + const p = path.win32; var input = String(conf.pathext); var ext; - var extIdx = input.indexOf('|'); + const extIdx = input.indexOf('|'); if (extIdx !== -1) { ext = input.slice(extIdx + 1); input = input.slice(0, extIdx); diff --git a/benchmark/path/dirname-posix.js b/benchmark/path/dirname-posix.js index a72aceb89ee7f9..98ad67056bffe4 100644 --- a/benchmark/path/dirname-posix.js +++ b/benchmark/path/dirname-posix.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ '', '/', @@ -16,9 +16,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.posix; - var input = String(conf.path); + const n = +conf.n; + const p = path.posix; + const input = String(conf.path); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/dirname-win32.js b/benchmark/path/dirname-win32.js index 11a89073e6e9c9..c09a3aff98de97 100644 --- a/benchmark/path/dirname-win32.js +++ b/benchmark/path/dirname-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ '', '\\', @@ -16,9 +16,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; - var input = String(conf.path); + const n = +conf.n; + const p = path.win32; + const input = String(conf.path); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/extname-posix.js b/benchmark/path/extname-posix.js index 25d53d08e190dc..4b6e056094267b 100644 --- a/benchmark/path/extname-posix.js +++ b/benchmark/path/extname-posix.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ '', '/', @@ -19,9 +19,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.posix; - var input = String(conf.path); + const n = +conf.n; + const p = path.posix; + const input = String(conf.path); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/extname-win32.js b/benchmark/path/extname-win32.js index d4a4638a68b842..fd54d485a9c025 100644 --- a/benchmark/path/extname-win32.js +++ b/benchmark/path/extname-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ '', '\\', @@ -19,9 +19,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; - var input = String(conf.path); + const n = +conf.n; + const p = path.win32; + const input = String(conf.path); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/format-posix.js b/benchmark/path/format-posix.js index 04f62077757921..fe20cc3c4fda9c 100644 --- a/benchmark/path/format-posix.js +++ b/benchmark/path/format-posix.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { props: [ ['/', '/home/user/dir', 'index.html', '.html', 'index'].join('|') ], @@ -10,10 +10,10 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.posix; - var props = String(conf.props).split('|'); - var obj = { + const n = +conf.n; + const p = path.posix; + const props = String(conf.props).split('|'); + const obj = { root: props[0] || '', dir: props[1] || '', base: props[2] || '', diff --git a/benchmark/path/format-win32.js b/benchmark/path/format-win32.js index 189fe9c34ff5b1..e59bee8669043e 100644 --- a/benchmark/path/format-win32.js +++ b/benchmark/path/format-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { props: [ ['C:\\', 'C:\\path\\dir', 'index.html', '.html', 'index'].join('|') ], @@ -10,10 +10,10 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; - var props = String(conf.props).split('|'); - var obj = { + const n = +conf.n; + const p = path.win32; + const props = String(conf.props).split('|'); + const obj = { root: props[0] || '', dir: props[1] || '', base: props[2] || '', diff --git a/benchmark/path/isAbsolute-posix.js b/benchmark/path/isAbsolute-posix.js index cff04746543fd6..956c8e0d1301e0 100644 --- a/benchmark/path/isAbsolute-posix.js +++ b/benchmark/path/isAbsolute-posix.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ '', '.', @@ -14,9 +14,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.posix; - var input = String(conf.path); + const n = +conf.n; + const p = path.posix; + const input = String(conf.path); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/isAbsolute-win32.js b/benchmark/path/isAbsolute-win32.js index 0eeeb64531720a..3c93b24220fe45 100644 --- a/benchmark/path/isAbsolute-win32.js +++ b/benchmark/path/isAbsolute-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ '', '.', @@ -15,9 +15,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; - var input = String(conf.path); + const n = +conf.n; + const p = path.win32; + const input = String(conf.path); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/join-posix.js b/benchmark/path/join-posix.js index 326789bf390439..02b348cdff42d5 100644 --- a/benchmark/path/join-posix.js +++ b/benchmark/path/join-posix.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { paths: [ ['/foo', 'bar', '', 'baz/asdf', 'quux', '..'].join('|') ], @@ -10,9 +10,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.posix; - var args = String(conf.paths).split('|'); + const n = +conf.n; + const p = path.posix; + const args = String(conf.paths).split('|'); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/join-win32.js b/benchmark/path/join-win32.js index 5042d270e11db7..96e4aeaa0ca2a9 100644 --- a/benchmark/path/join-win32.js +++ b/benchmark/path/join-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { paths: [ ['C:\\foo', 'bar', '', 'baz\\asdf', 'quux', '..'].join('|') ], @@ -10,9 +10,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; - var args = String(conf.paths).split('|'); + const n = +conf.n; + const p = path.win32; + const args = String(conf.paths).split('|'); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/makeLong-win32.js b/benchmark/path/makeLong-win32.js index 0cc6c66204447c..0c1ba38aedba6b 100644 --- a/benchmark/path/makeLong-win32.js +++ b/benchmark/path/makeLong-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ 'foo\\bar', 'C:\\foo', @@ -13,9 +13,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; - var input = String(conf.path); + const n = +conf.n; + const p = path.win32; + const input = String(conf.path); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/normalize-posix.js b/benchmark/path/normalize-posix.js index 541f7b9112e5f6..454a5ba9aebf05 100644 --- a/benchmark/path/normalize-posix.js +++ b/benchmark/path/normalize-posix.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ '', '.', @@ -15,9 +15,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.posix; - var input = String(conf.path); + const n = +conf.n; + const p = path.posix; + const input = String(conf.path); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/normalize-win32.js b/benchmark/path/normalize-win32.js index 3af2aca4344457..480856228aae6a 100644 --- a/benchmark/path/normalize-win32.js +++ b/benchmark/path/normalize-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ '', '.', @@ -15,9 +15,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; - var input = String(conf.path); + const n = +conf.n; + const p = path.win32; + const input = String(conf.path); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/parse-posix.js b/benchmark/path/parse-posix.js index 0130c16aa58444..4f1fb898b86af2 100644 --- a/benchmark/path/parse-posix.js +++ b/benchmark/path/parse-posix.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ '', '/', @@ -16,9 +16,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.posix; - var input = String(conf.path); + const n = +conf.n; + const p = path.posix; + const input = String(conf.path); for (var i = 0; i < n; i++) { p.parse(input); diff --git a/benchmark/path/parse-win32.js b/benchmark/path/parse-win32.js index fbcff5fd68b833..da48f78dd57b90 100644 --- a/benchmark/path/parse-win32.js +++ b/benchmark/path/parse-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { path: [ '', 'C:\\', @@ -17,9 +17,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; - var input = String(conf.path); + const n = +conf.n; + const p = path.win32; + const input = String(conf.path); for (var i = 0; i < n; i++) { p.parse(input); diff --git a/benchmark/path/relative-posix.js b/benchmark/path/relative-posix.js index 3fb6dc9ee13f73..1280b686bc55ae 100644 --- a/benchmark/path/relative-posix.js +++ b/benchmark/path/relative-posix.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { paths: [ ['/data/orandea/test/aaa', '/data/orandea/impl/bbb'].join('|'), ['/', '/var'].join('|'), @@ -16,11 +16,11 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.posix; + const n = +conf.n; + const p = path.posix; var from = String(conf.paths); var to = ''; - var delimIdx = from.indexOf('|'); + const delimIdx = from.indexOf('|'); if (delimIdx > -1) { to = from.slice(delimIdx + 1); from = from.slice(0, delimIdx); diff --git a/benchmark/path/relative-win32.js b/benchmark/path/relative-win32.js index fafda6d1ce46c4..f109cd9d96d15b 100644 --- a/benchmark/path/relative-win32.js +++ b/benchmark/path/relative-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { paths: [ ['C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb'].join('|'), ['C:\\', 'D:\\'].join('|'), @@ -14,11 +14,11 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; + const n = +conf.n; + const p = path.win32; var from = String(conf.paths); var to = ''; - var delimIdx = from.indexOf('|'); + const delimIdx = from.indexOf('|'); if (delimIdx > -1) { to = from.slice(delimIdx + 1); from = from.slice(0, delimIdx); diff --git a/benchmark/path/resolve-posix.js b/benchmark/path/resolve-posix.js index 61b809b6664dc8..4ef0d46e284e32 100644 --- a/benchmark/path/resolve-posix.js +++ b/benchmark/path/resolve-posix.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { paths: [ '', ['', ''].join('|'), @@ -13,9 +13,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.posix; - var args = String(conf.paths).split('|'); + const n = +conf.n; + const p = path.posix; + const args = String(conf.paths).split('|'); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/path/resolve-win32.js b/benchmark/path/resolve-win32.js index ccfeec696d9b3d..c7d8b4cbb75df0 100644 --- a/benchmark/path/resolve-win32.js +++ b/benchmark/path/resolve-win32.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var path = require('path'); +const common = require('../common.js'); +const path = require('path'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { paths: [ '', ['', ''].join('|'), @@ -13,9 +13,9 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var n = +conf.n; - var p = path.win32; - var args = String(conf.paths).split('|'); + const n = +conf.n; + const p = path.win32; + const args = String(conf.paths).split('|'); bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/process/memoryUsage.js b/benchmark/process/memoryUsage.js index d68ef339b4d10b..8b5aea871819ef 100644 --- a/benchmark/process/memoryUsage.js +++ b/benchmark/process/memoryUsage.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common.js'); -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const bench = common.createBenchmark(main, { n: [1e5] }); function main(conf) { - var n = +conf.n; + const n = +conf.n; bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/process/next-tick-breadth-args.js b/benchmark/process/next-tick-breadth-args.js index e617fcfc824f7f..fdb35987b99da2 100644 --- a/benchmark/process/next-tick-breadth-args.js +++ b/benchmark/process/next-tick-breadth-args.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common.js'); -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const bench = common.createBenchmark(main, { millions: [2] }); function main(conf) { - var N = +conf.millions * 1e6; + const N = +conf.millions * 1e6; var n = 0; function cb1(arg1) { diff --git a/benchmark/process/next-tick-breadth.js b/benchmark/process/next-tick-breadth.js index 87d130f3a7e102..8f8d0adc618dad 100644 --- a/benchmark/process/next-tick-breadth.js +++ b/benchmark/process/next-tick-breadth.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common.js'); -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const bench = common.createBenchmark(main, { millions: [2] }); function main(conf) { - var N = +conf.millions * 1e6; + const N = +conf.millions * 1e6; var n = 0; function cb() { diff --git a/benchmark/process/next-tick-depth-args.js b/benchmark/process/next-tick-depth-args.js index 06bea4676b3615..02f1d5ff0bab02 100644 --- a/benchmark/process/next-tick-depth-args.js +++ b/benchmark/process/next-tick-depth-args.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common.js'); -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const bench = common.createBenchmark(main, { millions: [12] }); diff --git a/benchmark/process/next-tick-depth.js b/benchmark/process/next-tick-depth.js index 824b7a8b69df86..e11beb4d0b1f31 100644 --- a/benchmark/process/next-tick-depth.js +++ b/benchmark/process/next-tick-depth.js @@ -1,6 +1,6 @@ 'use strict'; -var common = require('../common.js'); -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const bench = common.createBenchmark(main, { millions: [12] }); diff --git a/benchmark/querystring/querystring-parse.js b/benchmark/querystring/querystring-parse.js index eacbd7f92aa337..740dfc9d21b173 100644 --- a/benchmark/querystring/querystring-parse.js +++ b/benchmark/querystring/querystring-parse.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common.js'); -var querystring = require('querystring'); -var inputs = require('../fixtures/url-inputs.js').searchParams; +const common = require('../common.js'); +const querystring = require('querystring'); +const inputs = require('../fixtures/url-inputs.js').searchParams; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { type: Object.keys(inputs), n: [1e6], }); function main(conf) { - var type = conf.type; - var n = conf.n | 0; - var input = inputs[type]; + const type = conf.type; + const n = conf.n | 0; + const input = inputs[type]; var i; // Execute the function a "sufficient" number of times before the timed // loop to ensure the function is optimized just once. diff --git a/benchmark/querystring/querystring-stringify.js b/benchmark/querystring/querystring-stringify.js index 7e31a49e99e54c..97b8f1fc703ba2 100644 --- a/benchmark/querystring/querystring-stringify.js +++ b/benchmark/querystring/querystring-stringify.js @@ -1,17 +1,17 @@ 'use strict'; -var common = require('../common.js'); -var querystring = require('querystring'); +const common = require('../common.js'); +const querystring = require('querystring'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { type: ['noencode', 'encodemany', 'encodelast'], n: [1e7], }); function main(conf) { - var type = conf.type; - var n = conf.n | 0; + const type = conf.type; + const n = conf.n | 0; - var inputs = { + const inputs = { noencode: { foo: 'bar', baz: 'quux', @@ -28,11 +28,11 @@ function main(conf) { xyzzy: 'thu\u00AC' } }; - var input = inputs[type]; + const input = inputs[type]; // Force-optimize querystring.stringify() so that the benchmark doesn't get // disrupted by the optimizer kicking in halfway through. - for (var name in inputs) + for (const name in inputs) querystring.stringify(inputs[name]); bench.start(); diff --git a/benchmark/querystring/querystring-unescapebuffer.js b/benchmark/querystring/querystring-unescapebuffer.js index fe48a6f149bc6a..e37af180eef0ea 100644 --- a/benchmark/querystring/querystring-unescapebuffer.js +++ b/benchmark/querystring/querystring-unescapebuffer.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../common.js'); -var querystring = require('querystring'); +const common = require('../common.js'); +const querystring = require('querystring'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { input: [ 'there is nothing to unescape here', 'there%20are%20several%20spaces%20that%20need%20to%20be%20unescaped', @@ -13,8 +13,8 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var input = conf.input; - var n = conf.n | 0; + const input = conf.input; + const n = conf.n | 0; bench.start(); for (var i = 0; i < n; i += 1) diff --git a/benchmark/streams/transform-creation.js b/benchmark/streams/transform-creation.js index 0bc383d9aad876..bd5ac96fa71e32 100644 --- a/benchmark/streams/transform-creation.js +++ b/benchmark/streams/transform-creation.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../common.js'); -var Transform = require('stream').Transform; -var inherits = require('util').inherits; +const common = require('../common.js'); +const Transform = require('stream').Transform; +const inherits = require('util').inherits; -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { n: [1e6] }); @@ -14,7 +14,7 @@ inherits(MyTransform, Transform); MyTransform.prototype._transform = function() {}; function main(conf) { - var n = +conf.n; + const n = +conf.n; bench.start(); for (var i = 0; i < n; ++i) diff --git a/benchmark/string_decoder/string-decoder.js b/benchmark/string_decoder/string-decoder.js index 7a86fb6ef5499d..31cf7bf2f0a8a5 100644 --- a/benchmark/string_decoder/string-decoder.js +++ b/benchmark/string_decoder/string-decoder.js @@ -79,7 +79,7 @@ function main(conf) { } } - var nChunks = chunks.length; + const nChunks = chunks.length; bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/timers/immediate.js b/benchmark/timers/immediate.js index 7d85dc0325a8be..3ba4429260fb65 100644 --- a/benchmark/timers/immediate.js +++ b/benchmark/timers/immediate.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { thousands: [2000], type: ['depth', 'depth1', 'breadth', 'breadth1', 'breadth4', 'clear'] }); function main(conf) { - var N = +conf.thousands * 1e3; + const N = +conf.thousands * 1e3; switch (conf.type) { case 'depth': depth(N); diff --git a/benchmark/timers/timers-breadth.js b/benchmark/timers/timers-breadth.js index 1101ee7dbf8907..036c878191422c 100644 --- a/benchmark/timers/timers-breadth.js +++ b/benchmark/timers/timers-breadth.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { thousands: [500], }); function main(conf) { - var N = +conf.thousands * 1e3; + const N = +conf.thousands * 1e3; var n = 0; bench.start(); function cb() { diff --git a/benchmark/timers/timers-cancel-pooled.js b/benchmark/timers/timers-cancel-pooled.js index 47c9fea2cb5b61..2e834cc4db53fe 100644 --- a/benchmark/timers/timers-cancel-pooled.js +++ b/benchmark/timers/timers-cancel-pooled.js @@ -1,13 +1,13 @@ 'use strict'; -var common = require('../common.js'); -var assert = require('assert'); +const common = require('../common.js'); +const assert = require('assert'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { thousands: [500], }); function main(conf) { - var iterations = +conf.thousands * 1e3; + const iterations = +conf.thousands * 1e3; var timer = setTimeout(() => {}, 1); for (var i = 0; i < iterations; i++) { diff --git a/benchmark/timers/timers-cancel-unpooled.js b/benchmark/timers/timers-cancel-unpooled.js index 14cbad8256a634..ca3c0dbcd92c12 100644 --- a/benchmark/timers/timers-cancel-unpooled.js +++ b/benchmark/timers/timers-cancel-unpooled.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common.js'); -var assert = require('assert'); +const common = require('../common.js'); +const assert = require('assert'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { thousands: [100], }); function main(conf) { - var iterations = +conf.thousands * 1e3; + const iterations = +conf.thousands * 1e3; - var timersList = []; + const timersList = []; for (var i = 0; i < iterations; i++) { timersList.push(setTimeout(cb, i + 1)); } diff --git a/benchmark/timers/timers-depth.js b/benchmark/timers/timers-depth.js index d5efc5c672d502..42dc652b277781 100644 --- a/benchmark/timers/timers-depth.js +++ b/benchmark/timers/timers-depth.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { thousands: [1], }); function main(conf) { - var N = +conf.thousands * 1e3; + const N = +conf.thousands * 1e3; var n = 0; bench.start(); setTimeout(cb, 1); diff --git a/benchmark/timers/timers-insert-pooled.js b/benchmark/timers/timers-insert-pooled.js index 11c35319b11d69..80335a150a2a23 100644 --- a/benchmark/timers/timers-insert-pooled.js +++ b/benchmark/timers/timers-insert-pooled.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { thousands: [500], }); function main(conf) { - var iterations = +conf.thousands * 1e3; + const iterations = +conf.thousands * 1e3; bench.start(); diff --git a/benchmark/timers/timers-insert-unpooled.js b/benchmark/timers/timers-insert-unpooled.js index bdcd7e0ff79f27..98415625862075 100644 --- a/benchmark/timers/timers-insert-unpooled.js +++ b/benchmark/timers/timers-insert-unpooled.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../common.js'); -var assert = require('assert'); +const common = require('../common.js'); +const assert = require('assert'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { thousands: [100], }); function main(conf) { - var iterations = +conf.thousands * 1e3; + const iterations = +conf.thousands * 1e3; - var timersList = []; + const timersList = []; bench.start(); for (var i = 0; i < iterations; i++) { diff --git a/benchmark/timers/timers-timeout-pooled.js b/benchmark/timers/timers-timeout-pooled.js index feaec23237f13d..2e8753a0c3cda8 100644 --- a/benchmark/timers/timers-timeout-pooled.js +++ b/benchmark/timers/timers-timeout-pooled.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, { +const bench = common.createBenchmark(main, { thousands: [500], }); function main(conf) { - var iterations = +conf.thousands * 1e3; + const iterations = +conf.thousands * 1e3; var count = 0; for (var i = 0; i < iterations; i++) { diff --git a/benchmark/tls/throughput.js b/benchmark/tls/throughput.js index 2b8b2d537643a9..51feb85cbaccc1 100644 --- a/benchmark/tls/throughput.js +++ b/benchmark/tls/throughput.js @@ -1,6 +1,6 @@ 'use strict'; -var common = require('../common.js'); -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const bench = common.createBenchmark(main, { dur: [5], type: ['buf', 'asc', 'utf'], size: [2, 1024, 1024 * 1024] @@ -9,11 +9,11 @@ var bench = common.createBenchmark(main, { var dur, type, encoding, size; var server; -var path = require('path'); -var fs = require('fs'); -var cert_dir = path.resolve(__dirname, '../../test/fixtures'); +const path = require('path'); +const fs = require('fs'); +const cert_dir = path.resolve(__dirname, '../../test/fixtures'); var options; -var tls = require('tls'); +const tls = require('tls'); function main(conf) { dur = +conf.dur; @@ -48,7 +48,7 @@ function main(conf) { setTimeout(done, dur * 1000); var conn; server.listen(common.PORT, function() { - var opt = { port: common.PORT, rejectUnauthorized: false }; + const opt = { port: common.PORT, rejectUnauthorized: false }; conn = tls.connect(opt, function() { bench.start(); conn.on('drain', write); @@ -68,7 +68,7 @@ function main(conf) { } function done() { - var mbits = (received * 8) / (1024 * 1024); + const mbits = (received * 8) / (1024 * 1024); bench.end(mbits); if (conn) conn.destroy(); diff --git a/benchmark/tls/tls-connect.js b/benchmark/tls/tls-connect.js index 3acc79e73acac8..628b040ee88c9b 100644 --- a/benchmark/tls/tls-connect.js +++ b/benchmark/tls/tls-connect.js @@ -3,8 +3,8 @@ var fs = require('fs'), path = require('path'), tls = require('tls'); -var common = require('../common.js'); -var bench = common.createBenchmark(main, { +const common = require('../common.js'); +const bench = common.createBenchmark(main, { concurrency: [1, 10], dur: [5] }); @@ -20,8 +20,8 @@ function main(conf) { dur = +conf.dur; concurrency = +conf.concurrency; - var cert_dir = path.resolve(__dirname, '../../test/fixtures'); - var options = { + const cert_dir = path.resolve(__dirname, '../../test/fixtures'); + const options = { key: fs.readFileSync(`${cert_dir}/test_key.pem`), cert: fs.readFileSync(`${cert_dir}/test_cert.pem`), ca: [ fs.readFileSync(`${cert_dir}/test_ca.pem`) ], @@ -44,7 +44,7 @@ function onConnection(conn) { } function makeConnection() { - var options = { + const options = { port: common.PORT, rejectUnauthorized: false }; diff --git a/benchmark/url/legacy-vs-whatwg-url-get-prop.js b/benchmark/url/legacy-vs-whatwg-url-get-prop.js index 733a05a17305e7..229a4e60652b64 100644 --- a/benchmark/url/legacy-vs-whatwg-url-get-prop.js +++ b/benchmark/url/legacy-vs-whatwg-url-get-prop.js @@ -16,8 +16,8 @@ const bench = common.createBenchmark(main, { // remains a constant in the function, so here we must use the literal // instead to get a LoadNamedField. function useLegacy(n, input) { - var obj = url.parse(input); - var noDead = { + const obj = url.parse(input); + const noDead = { protocol: obj.protocol, auth: obj.auth, host: obj.host, @@ -45,8 +45,8 @@ function useLegacy(n, input) { } function useWHATWG(n, input) { - var obj = new URL(input); - var noDead = { + const obj = new URL(input); + const noDead = { protocol: obj.protocol, auth: `${obj.username}:${obj.password}`, host: obj.host, diff --git a/benchmark/url/legacy-vs-whatwg-url-serialize.js b/benchmark/url/legacy-vs-whatwg-url-serialize.js index 911e79794b84fb..35b459a10c0e0b 100644 --- a/benchmark/url/legacy-vs-whatwg-url-serialize.js +++ b/benchmark/url/legacy-vs-whatwg-url-serialize.js @@ -12,7 +12,7 @@ const bench = common.createBenchmark(main, { }); function useLegacy(n, input, prop) { - var obj = url.parse(input); + const obj = url.parse(input); var noDead = url.format(obj); bench.start(); for (var i = 0; i < n; i += 1) { @@ -23,7 +23,7 @@ function useLegacy(n, input, prop) { } function useWHATWG(n, input, prop) { - var obj = new URL(input); + const obj = new URL(input); var noDead = obj.toString(); bench.start(); for (var i = 0; i < n; i += 1) { diff --git a/benchmark/url/url-format.js b/benchmark/url/url-format.js index 771786d3350513..dc8e020879e400 100644 --- a/benchmark/url/url-format.js +++ b/benchmark/url/url-format.js @@ -3,8 +3,8 @@ const common = require('../common.js'); const url = require('url'); const inputs = { - slashes: {slashes: true, host: 'localhost'}, - file: {protocol: 'file:', pathname: '/foo'}, + slashes: { slashes: true, host: 'localhost' }, + file: { protocol: 'file:', pathname: '/foo' }, }; const bench = common.createBenchmark(main, { diff --git a/benchmark/url/url-searchparams-iteration.js b/benchmark/url/url-searchparams-iteration.js index 89919af7255184..0f4b71a0a183dd 100644 --- a/benchmark/url/url-searchparams-iteration.js +++ b/benchmark/url/url-searchparams-iteration.js @@ -33,7 +33,7 @@ function iterator(n) { bench.start(); for (var i = 0; i < n; i += 1) { - for (var pair of params) { + for (const pair of params) { noDead[0] = pair[0]; noDead[1] = pair[1]; } diff --git a/benchmark/util/format.js b/benchmark/util/format.js index 82e25b4c4c8127..6f171318ee28bf 100644 --- a/benchmark/util/format.js +++ b/benchmark/util/format.js @@ -2,35 +2,30 @@ const util = require('util'); const common = require('../common'); -const types = [ - 'string', - 'number', - 'object', - 'unknown', - 'no-replace' -]; -const bench = common.createBenchmark(main, { - n: [1e6], - type: types -}); const inputs = { - 'string': ['Hello, my name is %s', 'fred'], - 'number': ['Hi, I was born in %d', 1942], - 'object': ['An error occurred %j', {msg: 'This is an error', code: 'ERR'}], + 'string': ['Hello, my name is %s', 'Fred'], + 'string-2': ['Hello, %s is my name', 'Fred'], + 'number': ['Hi, I was born in %d', 1989], + 'replace-object': ['An error occurred %j', { msg: 'This is an error' }], 'unknown': ['hello %a', 'test'], - 'no-replace': [1, 2] + 'no-replace': [1, 2], + 'no-replace-2': ['foobar', 'yeah', 'mensch', 5], + 'only-objects': [{ msg: 'This is an error' }, { msg: 'This is an error' }], + 'many-%': ['replace%%%%s%%%%many%s%s%s', 'percent'], }; -function main(conf) { - const n = conf.n | 0; - const type = conf.type; +const bench = common.createBenchmark(main, { + n: [4e6], + type: Object.keys(inputs) +}); - const input = inputs[type]; +function main({ n, type }) { + const [first, second] = inputs[type]; bench.start(); for (var i = 0; i < n; i++) { - util.format(input[0], input[1]); + util.format(first, second); } bench.end(n); } diff --git a/benchmark/util/inspect-array.js b/benchmark/util/inspect-array.js index 44067b8b8f81da..751e2c3c2deb8f 100644 --- a/benchmark/util/inspect-array.js +++ b/benchmark/util/inspect-array.js @@ -4,23 +4,27 @@ const common = require('../common'); const util = require('util'); const bench = common.createBenchmark(main, { - n: [1e2], + n: [1e3], len: [1e5], type: [ 'denseArray', 'sparseArray', - 'mixedArray' + 'mixedArray', + 'denseArray_showHidden', ] }); -function main(conf) { - const { n, len, type } = conf; +function main({ n, len, type }) { var arr = Array(len); - var i; + var i, opts; switch (type) { + case 'denseArray_showHidden': + opts = { showHidden: true }; + arr = arr.fill('denseArray'); + break; case 'denseArray': - arr = arr.fill(0); + arr = arr.fill('denseArray'); break; case 'sparseArray': break; @@ -33,7 +37,7 @@ function main(conf) { } bench.start(); for (i = 0; i < n; i++) { - util.inspect(arr); + util.inspect(arr, opts); } bench.end(n); } diff --git a/benchmark/util/inspect-proxy.js b/benchmark/util/inspect-proxy.js index 805c520e28745c..5427df9952c250 100644 --- a/benchmark/util/inspect-proxy.js +++ b/benchmark/util/inspect-proxy.js @@ -3,42 +3,13 @@ const util = require('util'); const common = require('../common.js'); -const bench = common.createBenchmark(main, { - v: [1, 2], - n: [1e6] -}); +const bench = common.createBenchmark(main, { n: [1e6] }); -function twoDifferentProxies(n) { - // This one should be slower because we're looking up multiple proxies. - const proxyA = new Proxy({}, {get: () => {}}); - const proxyB = new Proxy({}, {get: () => {}}); +function main({ n }) { + const proxyA = new Proxy({}, { get: () => {} }); + const proxyB = new Proxy(() => {}, {}); bench.start(); for (var i = 0; i < n; i += 1) - util.inspect({a: proxyA, b: proxyB}, {showProxy: true}); + util.inspect({ a: proxyA, b: proxyB }, { showProxy: true }); bench.end(n); } - -function oneProxy(n) { - // This one should be a bit faster because of the internal caching. - const proxy = new Proxy({}, {get: () => {}}); - bench.start(); - for (var i = 0; i < n; i += 1) - util.inspect({a: proxy, b: proxy}, {showProxy: true}); - bench.end(n); -} - -function main(conf) { - const n = conf.n | 0; - const v = conf.v | 0; - - switch (v) { - case 1: - oneProxy(n); - break; - case 2: - twoDifferentProxies(n); - break; - default: - throw new Error('Should not get to here'); - } -} diff --git a/benchmark/util/inspect.js b/benchmark/util/inspect.js index 3312bd683ba81b..913850690ce655 100644 --- a/benchmark/util/inspect.js +++ b/benchmark/util/inspect.js @@ -1,16 +1,98 @@ 'use strict'; -var util = require('util'); +const util = require('util'); -var common = require('../common.js'); +const common = require('../common.js'); -var bench = common.createBenchmark(main, {n: [5e6]}); - -function main(conf) { - var n = conf.n | 0; +const opts = { + showHidden: { showHidden: true }, + colors: { colors: true }, + none: undefined +}; +const bench = common.createBenchmark(main, { + n: [2e6], + method: [ + 'Object', + 'Object_empty', + 'Object_deep_ln', + 'String', + 'String_complex', + 'String_boxed', + 'Date', + 'Set', + 'Error', + 'Array', + 'TypedArray', + 'TypedArray_extra' + ], + option: Object.keys(opts) +}); +function benchmark(n, obj, options) { bench.start(); for (var i = 0; i < n; i += 1) { - util.inspect({a: 'a', b: 'b', c: 'c', d: 'd'}); + util.inspect(obj, options); } bench.end(n); } + +function main({ method, n, option }) { + var obj; + const options = opts[option]; + switch (method) { + case 'Object': + benchmark(n, { a: 'a', b: 'b', c: 'c', d: 'd' }, options); + break; + case 'Object_empty': + benchmark(n, {}, options); + break; + case 'Object_deep_ln': + if (options) + options.depth = Infinity; + obj = { first: + { second: + { third: + { a: 'first', + b: 'second', + c: 'third', + d: 'fourth', + e: 'fifth', + f: 'sixth', + g: 'seventh' } } } }; + benchmark(n, obj, options || { depth: Infinity }); + break; + case 'String': + benchmark(n, 'Simple string', options); + break; + case 'String_complex': + benchmark(n, 'This string\nhas to be\tescaped!', options); + break; + case 'String_boxed': + benchmark(n, new String('string'), options); + break; + case 'Date': + benchmark(n, new Date(), options); + break; + case 'Set': + obj = new Set([5, 3]); + benchmark(n, obj, options); + break; + case 'Error': + benchmark(n, new Error('error'), options); + break; + case 'Array': + benchmark(n, Array(20).fill().map((_, i) => i), options); + break; + case 'TypedArray': + obj = new Uint8Array(Array(50).fill().map((_, i) => i)); + benchmark(n, obj, options); + break; + case 'TypedArray_extra': + obj = new Uint8Array(Array(50).fill().map((_, i) => i)); + obj.foo = 'bar'; + obj[Symbol('baz')] = 5; + benchmark(n, obj, options); + break; + default: + throw new Error(`Unsupported method "${method}"`); + } +} diff --git a/benchmark/util/normalize-encoding.js b/benchmark/util/normalize-encoding.js index 8c4d03478104b0..2cdfd54442114d 100644 --- a/benchmark/util/normalize-encoding.js +++ b/benchmark/util/normalize-encoding.js @@ -19,7 +19,7 @@ const inputs = [ const bench = common.createBenchmark(main, { input: inputs.concat(Object.keys(groupedInputs)), - n: [1e5] + n: [1e7] }, { flags: '--expose-internals' }); diff --git a/benchmark/vm/run-in-context.js b/benchmark/vm/run-in-context.js index d1d4b5a7abbf20..6e26a6d0ebeb38 100644 --- a/benchmark/vm/run-in-context.js +++ b/benchmark/vm/run-in-context.js @@ -12,7 +12,7 @@ const vm = require('vm'); function main(conf) { const n = +conf.n; - const options = conf.breakOnSigint ? {breakOnSigint: true} : {}; + const options = conf.breakOnSigint ? { breakOnSigint: true } : {}; const withSigintListener = !!conf.withSigintListener; process.removeAllListeners('SIGINT'); diff --git a/benchmark/vm/run-in-this-context.js b/benchmark/vm/run-in-this-context.js index f3a7e969287d50..a0c737f46954f1 100644 --- a/benchmark/vm/run-in-this-context.js +++ b/benchmark/vm/run-in-this-context.js @@ -12,7 +12,7 @@ const vm = require('vm'); function main(conf) { const n = +conf.n; - const options = conf.breakOnSigint ? {breakOnSigint: true} : {}; + const options = conf.breakOnSigint ? { breakOnSigint: true } : {}; const withSigintListener = !!conf.withSigintListener; process.removeAllListeners('SIGINT'); diff --git a/configure b/configure index cff6324a4d807c..4e3455056cfb98 100755 --- a/configure +++ b/configure @@ -843,8 +843,6 @@ def configure_node(o): want_snapshots = not options.without_snapshot o['variables']['want_separate_host_toolset'] = int( cross_compiling and want_snapshots) - o['variables']['want_separate_host_toolset_mkpeephole'] = int( - cross_compiling) if target_arch == 'arm': configure_arm(o) diff --git a/deps/nghttp2/nghttp2.gyp b/deps/nghttp2/nghttp2.gyp index 8e351609290848..8da81485e5f045 100644 --- a/deps/nghttp2/nghttp2.gyp +++ b/deps/nghttp2/nghttp2.gyp @@ -9,13 +9,16 @@ 'target_name': 'nghttp2', 'type': 'static_library', 'include_dirs': ['lib/includes'], + 'defines': [ + 'BUILDING_NGHTTP2', + 'NGHTTP2_STATICLIB', + ], 'conditions': [ ['OS=="win"', { 'defines': [ 'WIN32', '_WINDOWS', 'HAVE_CONFIG_H', - 'NGHTTP2_STATICLIB', ], 'msvs_settings': { 'VCCLCompilerTool': { @@ -28,6 +31,7 @@ }] ], 'direct_dependent_settings': { + 'defines': [ 'NGHTTP2_STATICLIB' ], 'include_dirs': [ 'lib/includes' ] }, 'sources': [ diff --git a/deps/v8/src/profiler/sampling-heap-profiler.h b/deps/v8/src/profiler/sampling-heap-profiler.h index 07840244ce5e91..3a347dd54ea5c4 100644 --- a/deps/v8/src/profiler/sampling-heap-profiler.h +++ b/deps/v8/src/profiler/sampling-heap-profiler.h @@ -172,8 +172,11 @@ class SamplingAllocationObserver : public AllocationObserver { void Step(int bytes_allocated, Address soon_object, size_t size) override { USE(heap_); DCHECK(heap_->gc_state() == Heap::NOT_IN_GC); - DCHECK(soon_object); - profiler_->SampleObject(soon_object, size); + if (soon_object) { + // TODO(ofrobots): it would be better to sample the next object rather + // than skipping this sample epoch if soon_object happens to be null. + profiler_->SampleObject(soon_object, size); + } } intptr_t GetNextStepSize() override { return GetNextSampleInterval(rate_); } diff --git a/doc/.eslintrc.yaml b/doc/.eslintrc.yaml index 1c5177d90642ad..b269eb14e625f4 100644 --- a/doc/.eslintrc.yaml +++ b/doc/.eslintrc.yaml @@ -1,8 +1,6 @@ ## Docs-specific linter rules rules: - object-curly-spacing: [error, always] - # ease some restrictions in doc examples no-restricted-properties: off no-undef: off diff --git a/doc/api/assert.md b/doc/api/assert.md index d019540ee6c9bf..5f331fdef35604 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -105,7 +105,7 @@ parameter is undefined, a default error message is assigned. added: v1.2.0 changes: - version: v8.5.0 - pr-url: https://github.com/nodejs/node/pull/12142 + pr-url: https://github.com/nodejs/node/pull/15001 description: Error names and messages are now properly compared - version: v8.0.0 pr-url: https://github.com/nodejs/node/pull/12142 @@ -124,7 +124,7 @@ changes: * `expected` {any} * `message` {any} -Generally identical to `assert.deepEqual()` with three exceptions: +Generally identical to `assert.deepEqual()` with a few exceptions: 1. Primitive values are compared using the [Strict Equality Comparison][] ( `===` ). Set values and Map keys are compared using the [SameValueZero][] @@ -132,6 +132,7 @@ Generally identical to `assert.deepEqual()` with three exceptions: 2. [`[[Prototype]]`][prototype-spec] of objects are compared using the [Strict Equality Comparison][] too. 3. [Type tags][Object.prototype.toString()] of objects should be the same. +4. [Object wrappers][] are compared both as objects and unwrapped values. ```js const assert = require('assert'); @@ -161,6 +162,11 @@ assert.deepEqual(date, fakeDate); assert.deepStrictEqual(date, fakeDate); // AssertionError: 2017-03-11T14:25:31.849Z deepStrictEqual Date {} // Different type tags + +assert.deepStrictEqual(new Number(1), new Number(2)); +// Fails because the wrapped number is unwrapped and compared as well. +assert.deepStrictEqual(new String('foo'), Object('foo')); +// OK because the object and the string are identical when unwrapped. ``` If the values are not equal, an `AssertionError` is thrown with a `message` @@ -641,3 +647,4 @@ For more information, see [enumerable "own" properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties [mdn-equality-guide]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness [prototype-spec]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots +[Object wrappers]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md index d09ef6ab8eff7e..f3e00951307ca9 100644 --- a/doc/api/async_hooks.md +++ b/doc/api/async_hooks.md @@ -36,7 +36,8 @@ const eid = async_hooks.executionAsyncId(); const tid = async_hooks.triggerAsyncId(); // Create a new AsyncHook instance. All of these callbacks are optional. -const asyncHook = async_hooks.createHook({ init, before, after, destroy }); +const asyncHook = + async_hooks.createHook({ init, before, after, destroy, promiseResolve }); // Allow callbacks of this AsyncHook instance to call. This is not an implicit // action after running the constructor, and must be explicitly run to begin @@ -65,6 +66,11 @@ function after(asyncId) { } // destroy is called when an AsyncWrap instance is destroyed. function destroy(asyncId) { } + +// promiseResolve is called only for promise resources, when the +// `resolve` function passed to the `Promise` constructor is invoked +// (either directly or through other means of resolving a promise). +function promiseResolve(asyncId) { } ``` #### `async_hooks.createHook(callbacks)` @@ -73,7 +79,11 @@ function destroy(asyncId) { } added: v8.1.0 --> -* `callbacks` {Object} the callbacks to register +* `callbacks` {Object} the [Hook Callbacks][] to register + * `init` {Function} The [`init` callback][]. + * `before` {Function} The [`before` callback][]. + * `after` {Function} The [`after` callback][]. + * `destroy` {Function} The [`destroy` callback][]. * Returns: `{AsyncHook}` instance used for disabling and enabling hooks Registers functions to be called for different lifetime events of each async @@ -87,6 +97,31 @@ be tracked then only the `destroy` callback needs to be passed. The specifics of all functions that can be passed to `callbacks` is in the section [`Hook Callbacks`][]. +```js +const async_hooks = require('async_hooks'); + +const asyncHook = async_hooks.createHook({ + init(asyncId, type, triggerAsyncId, resource) { }, + destroy(asyncId) { } +}); +``` + +Note that the callbacks will be inherited via the prototype chain: + +```js +class MyAsyncCallbacks { + init(asyncId, type, triggerAsyncId, resource) { } + destroy(asyncId) {} +} + +class MyAddedCallbacks extends MyAsyncCallbacks { + before(asyncId) { } + after(asyncId) { } +} + +const asyncHook = async_hooks.createHook(new MyAddedCallbacks()); +``` + ##### Error Handling If any `AsyncHook` callbacks throw, the application will print the stack trace @@ -187,11 +222,12 @@ require('net').createServer().listen(function() { this.close(); }); clearTimeout(setTimeout(() => {}, 10)); ``` -Every new resource is assigned a unique ID. +Every new resource is assigned an ID that is unique within the scope of the +current process. ###### `type` -The `type` is a string that represents the type of resource that caused +The `type` is a string identifying the type of resource that caused `init` to be called. Generally, it will correspond to the name of the resource's constructor. @@ -214,8 +250,8 @@ when listening to the hooks. ###### `triggerId` -`triggerAsyncId` is the `asyncId` of the resource that caused (or "triggered") the -new resource to initialize and that caused `init` to call. This is different +`triggerAsyncId` is the `asyncId` of the resource that caused (or "triggered") +the new resource to initialize and that caused `init` to call. This is different from `async_hooks.executionAsyncId()` that only shows *when* a resource was created, while `triggerAsyncId` shows *why* a resource was created. @@ -253,26 +289,27 @@ propagating what resource is responsible for the new resource's existence. ###### `resource` -`resource` is an object that represents the actual resource. This can contain -useful information such as the hostname for the `GETADDRINFOREQWRAP` resource -type, which will be used when looking up the ip for the hostname in -`net.Server.listen`. The API for getting this information is currently not -considered public, but using the Embedder API users can provide and document -their own resource objects. Such as resource object could for example contain -the SQL query being executed. +`resource` is an object that represents the actual async resource that has +been initialized. This can contain useful information that can vary based on +the value of `type`. For instance, for the `GETADDRINFOREQWRAP` resource type, +`resource` provides the hostname used when looking up the IP address for the +hostname in `net.Server.listen()`. The API for accessing this information is +currently not considered public, but using the Embedder API, users can provide +and document their own resource objects. Such a resource object could for +example contain the SQL query being executed. In the case of Promises, the `resource` object will have `promise` property that refers to the Promise that is being initialized, and a `parentId` property -that equals the `asyncId` of a parent Promise, if there is one, and -`undefined` otherwise. For example, in the case of `b = a.then(handler)`, -`a` is considered a parent Promise of `b`. +set to the `asyncId` of a parent Promise, if there is one, and `undefined` +otherwise. For example, in the case of `b = a.then(handler)`, `a` is considered +a parent Promise of `b`. *Note*: In some cases the resource object is reused for performance reasons, it is thus not safe to use it as a key in a `WeakMap` or add properties to it. -###### asynchronous context example +###### Asynchronous context example -Below is another example with additional information about the calls to +The following is an example with additional information about the calls to `init` between the `before` and `after` calls, specifically what the callback to `listen()` will look like. The output formatting is slightly more elaborate to make calling context easier to see. @@ -348,10 +385,10 @@ Only using `execution` to graph resource allocation results in the following: TTYWRAP(6) -> Timeout(4) -> TIMERWRAP(5) -> TickObject(3) -> root(1) ``` -The `TCPWRAP` isn't part of this graph; even though it was the reason for +The `TCPWRAP` is not part of this graph; even though it was the reason for `console.log()` being called. This is because binding to a port without a -hostname is actually synchronous, but to maintain a completely asynchronous API -the user's callback is placed in a `process.nextTick()`. +hostname is a *synchronous* operation, but to maintain a completely asynchronous +API the user's callback is placed in a `process.nextTick()`. The graph only shows *when* a resource was created, not *why*, so to track the *why* use `triggerAsyncId`. @@ -369,9 +406,10 @@ resource about to execute the callback. The `before` callback will be called 0 to N times. The `before` callback will typically be called 0 times if the asynchronous operation was cancelled -or for example if no connections are received by a TCP server. Asynchronous -like the TCP server will typically call the `before` callback multiple times, -while other operations like `fs.open()` will only call it once. +or, for example, if no connections are received by a TCP server. Persistent +asynchronous resources like a TCP server will typically call the `before` +callback multiple times, while other operations like `fs.open()` will only call +it only once. ##### `after(asyncId)` @@ -381,7 +419,7 @@ while other operations like `fs.open()` will only call it once. Called immediately after the callback specified in `before` is completed. *Note:* If an uncaught exception occurs during execution of the callback then -`after` will run after the `'uncaughtException'` event is emitted or a +`after` will run *after* the `'uncaughtException'` event is emitted or a `domain`'s handler runs. @@ -389,22 +427,55 @@ Called immediately after the callback specified in `before` is completed. * `asyncId` {number} -Called after the resource corresponding to `asyncId` is destroyed. It is also called -asynchronously from the embedder API `emitDestroy()`. +Called after the resource corresponding to `asyncId` is destroyed. It is also +called asynchronously from the embedder API `emitDestroy()`. + +*Note:* Some resources depend on garbage collection for cleanup, so if a +reference is made to the `resource` object passed to `init` it is possible that +`destroy` will never be called, causing a memory leak in the application. If +the resource does not depend on garbage collection, then this will not be an +issue. + +##### `promiseResolve(asyncId)` + +* `asyncId` {number} + +Called when the `resolve` function passed to the `Promise` constructor is +invoked (either directly or through other means of resolving a promise). + +Note that `resolve()` does not do any observable synchronous work. + +*Note:* This does not necessarily mean that the `Promise` is fulfilled or +rejected at this point, if the `Promise` was resolved by assuming the state +of another `Promise`. + +For example: + +```js +new Promise((resolve) => resolve(true)).then((a) => {}); +``` + +calls the following callbacks: -*Note:* Some resources depend on GC for cleanup, so if a reference is made to -the `resource` object passed to `init` it's possible that `destroy` is -never called, causing a memory leak in the application. Of course if -the resource doesn't depend on GC then this isn't an issue. +``` +init for PROMISE with id 5, trigger id: 1 + promise resolve 5 # corresponds to resolve(true) +init for PROMISE with id 6, trigger id: 5 # the Promise returned by then() + before 6 # the then() callback is entered + promise resolve 6 # the then() callback resolves the promise by returning + after 6 +``` #### `async_hooks.executionAsyncId()` -* Returns {number} the `asyncId` of the current execution context. Useful to track - when something calls. +* Returns {number} the `asyncId` of the current execution context. Useful to + track when something calls. For example: ```js +const async_hooks = require('async_hooks'); + console.log(async_hooks.executionAsyncId()); // 1 - bootstrap fs.open(path, 'r', (err, fd) => { console.log(async_hooks.executionAsyncId()); // 6 - open() @@ -453,10 +524,9 @@ const server = net.createServer((conn) => { ## JavaScript Embedder API -Library developers that handle their own I/O, a connection pool, or -callback queues will need to hook into the AsyncWrap API so that all the -appropriate callbacks are called. To accommodate this a JavaScript API is -provided. +Library developers that handle their own asychronous resources performing tasks +like I/O, connection pooling, or managing callback queues may use the `AsyncWrap` +JavaScript API so that all the appropriate callbacks are called. ### `class AsyncResource()` @@ -466,9 +536,9 @@ own resources. The `init` hook will trigger when an `AsyncResource` is instantiated. -It is important that `before`/`after` calls are unwound +*Note*: It is important that `before`/`after` calls are unwound in the same order they are called. Otherwise an unrecoverable exception -will occur and node will abort. +will occur and the process will abort. The following is an overview of the `AsyncResource` API. @@ -499,9 +569,9 @@ asyncResource.triggerAsyncId(); #### `AsyncResource(type[, triggerAsyncId])` * arguments - * `type` {string} the type of ascyc event - * `triggerAsyncId` {number} the ID of the execution context that created this async - event + * `type` {string} the type of async event + * `triggerAsyncId` {number} the ID of the execution context that created this + async event Example usage: @@ -531,9 +601,9 @@ class DBQuery extends AsyncResource { * Returns {undefined} -Call all `before` callbacks and let them know a new asynchronous execution -context is being entered. If nested calls to `emitBefore()` are made, the stack -of `asyncId`s will be tracked and properly unwound. +Call all `before` callbacks to notify that a new asynchronous execution context +is being entered. If nested calls to `emitBefore()` are made, the stack of +`asyncId`s will be tracked and properly unwound. #### `asyncResource.emitAfter()` @@ -542,9 +612,9 @@ of `asyncId`s will be tracked and properly unwound. Call all `after` callbacks. If nested calls to `emitBefore()` were made, then make sure the stack is unwound properly. Otherwise an error will be thrown. -If the user's callback throws an exception then `emitAfter()` will -automatically be called for all `asyncId`s on the stack if the error is handled by -a domain or `'uncaughtException'` handler. +If the user's callback throws an exception, `emitAfter()` will automatically be +called for all `asyncId`s on the stack if the error is handled by a domain or +`'uncaughtException'` handler. #### `asyncResource.emitDestroy()` @@ -564,4 +634,8 @@ never be called. * Returns {number} the same `triggerAsyncId` that is passed to the `AsyncResource` constructor. +[`after` callback]: #async_hooks_after_asyncid +[`before` callback]: #async_hooks_before_asyncid +[`destroy` callback]: #async_hooks_before_asyncid [`Hook Callbacks`]: #async_hooks_hook_callbacks +[`init` callback]: #async_hooks_init_asyncid_type_triggerasyncid_resource diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 363b10bc664b9f..0b01370f90f7ab 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -616,7 +616,7 @@ additional performance that [`Buffer.allocUnsafe()`] provides. ### Class Method: Buffer.allocUnsafeSlow(size) * `size` {integer} The desired length of the new `Buffer` diff --git a/doc/api/child_process.md b/doc/api/child_process.md old mode 100644 new mode 100755 index c7109901f4fd34..4e9415df0690be --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -356,6 +356,9 @@ output on this fd is expected to be line delimited JSON objects. *Note*: Unlike the fork(2) POSIX system call, `child_process.fork()` does not clone the current process. +*Note*: The `shell` option available in [`child_process.spawn()`][] is not +supported by `child_process.fork()` and will be ignored if set. + ### child_process.spawn(command[, args][, options]) - -Enable loading native modules compiled with the ABI-stable Node.js API (N-API) -(experimental). - ### `--abort-on-uncaught-exception` Node.js includes an out-of-process debugging utility accessible via a -[TCP-based protocol][] and built-in debugging client. To use it, start Node.js +[V8 Inspector][] and built-in debugging client. To use it, start Node.js with the `inspect` argument followed by the path to the script to debug; a prompt will be displayed indicating successful launch of the debugger: @@ -125,18 +125,18 @@ It is also possible to set a breakpoint in a file (module) that is not loaded yet: ```txt -$ node inspect test/fixtures/break-in-module/main.js +$ node inspect main.js < Debugger listening on ws://127.0.0.1:9229/4e3db158-9791-4274-8909-914f7facf3bd < For help see https://nodejs.org/en/docs/inspector < Debugger attached. -Break on start in test/fixtures/break-in-module/main.js:1 +Break on start in main.js:1 > 1 (function (exports, require, module, __filename, __dirname) { const mod = require('./mod.js'); 2 mod.hello(); 3 mod.hello(); debug> setBreakpoint('mod.js', 22) Warning: script 'mod.js' was not loaded yet. debug> c -break in test/fixtures/break-in-module/mod.js:22 +break in mod.js:22 20 // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 >22 exports.hello = function() { @@ -194,4 +194,4 @@ at the end of the URL is generated on the fly, it varies in different debugging sessions.) [Chrome Debugging Protocol]: https://chromedevtools.github.io/debugger-protocol-viewer/ -[TCP-based protocol]: #debugger_tcp_based_protocol +[V8 Inspector]: #debugger_v8_inspector_integration_for_node_js diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 5e0b63b13ee13e..8d6dbd347daab2 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -630,6 +630,29 @@ Type: Runtime *Note*: change was made while `async_hooks` was an experimental API. + +### DEP0076: tls.parseCertString() + +Type: Documentation-only + +`tls.parseCertString()` is a trivial parsing helper that was made public by +mistake. This function can usually be replaced with: + +```js +const querystring = require('querystring'); +querystring.parse(str, '\n', '='); +``` + +*Note*: This function is not completely equivalent to `querystring.parse()`. One +difference is that `querystring.parse()` does url encoding: + +```sh +> querystring.parse('%E5%A5%BD=1', '\n', '='); +{ '好': '1' } +> tls.parseCertString('%E5%A5%BD=1'); +{ '%E5%A5%BD': '1' } +``` + [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size [`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array [`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer @@ -660,7 +683,7 @@ Type: Runtime [`os.networkInterfaces`]: os.html#os_os_networkinterfaces [`os.tmpdir()`]: os.html#os_os_tmpdir [`punycode`]: punycode.html -[`require.extensions`]: globals.html#globals_require_extensions +[`require.extensions`]: modules.html#modules_require_extensions [`tls.CryptoStream`]: tls.html#tls_class_cryptostream [`tls.SecureContext`]: tls.html#tls_tls_createsecurecontext_options [`tls.SecurePair`]: tls.html#tls_class_securepair diff --git a/doc/api/dgram.md b/doc/api/dgram.md index 3f5664d8fc9090..a16a4b7c054236 100644 --- a/doc/api/dgram.md +++ b/doc/api/dgram.md @@ -372,6 +372,84 @@ added: v0.6.9 Sets or clears the `SO_BROADCAST` socket option. When set to `true`, UDP packets may be sent to a local interface's broadcast address. +### socket.setMulticastInterface(multicastInterface) + + +* `multicastInterface` {String} + +*Note: All references to scope in this section are refering to +[IPv6 Zone Indices][], which are defined by [RFC 4007][]. In string form, an IP +with a scope index is written as `'IP%scope'` where scope is an interface name or +interface number.* + +Sets the default outgoing multicast interface of the socket to a chosen +interface or back to system interface selection. The `multicastInterface` must +be a valid string representation of an IP from the socket's family. + +For IPv4 sockets, this should be the IP configured for the desired physical +interface. All packets sent to multicast on the socket will be sent on the +interface determined by the most recent successful use of this call. + +For IPv6 sockets, `multicastInterface` should include a scope to indicate the +interface as in the examples that follow. In IPv6, individual `send` calls can +also use explicit scope in addresses, so only packets sent to a multicast +address without specifying an explicit scope are affected by the most recent +successful use of this call. + +#### Examples: IPv6 Outgoing Multicast Interface + +On most systems, where scope format uses the interface name: + +```js +const socket = dgram.createSocket('udp6'); + +socket.bind(1234, () => { + socket.setMulticastInterface('::%eth1'); +}); +``` + +On Windows, where scope format uses an interface number: + +```js +const socket = dgram.createSocket('udp6'); + +socket.bind(1234, () => { + socket.setMulticastInterface('::%2'); +}); +``` + +#### Example: IPv4 Outgoing Multicast Interface +All systems use an IP of the host on the desired physical interface: +```js +const socket = dgram.createSocket('udp4'); + +socket.bind(1234, () => { + socket.setMulticastInterface('10.0.0.2'); +}); +``` + +#### Call Results + +A call on a socket that is not ready to send or no longer open may throw a *Not +running* [`Error`][]. + +If `multicastInterface` can not be parsed into an IP then an *EINVAL* +[`System Error`][] is thrown. + +On IPv4, if `multicastInterface` is a valid address but does not match any +interface, or if the address does not match the family then +a [`System Error`][] such as `EADDRNOTAVAIL` or `EPROTONOSUP` is thrown. + +On IPv6, most errors with specifying or omiting scope will result in the socket +continuing to use (or returning to) the system's default interface selection. + +A socket's address family's ANY address (IPv4 `'0.0.0.0'` or IPv6 `'::'`) can be +used to return control of the sockets default outgoing interface to the system +for future multicast packets. + + ### socket.setMulticastLoopback(flag) -* `options` {Object} -* `callback` {Function} Attached as a listener to `'message'` events. +* `options` {Object} Available options are: + * `type` {string} The family of socket. Must be either `'udp4'` or `'udp6'`. + Required. + * `reuseAddr` {boolean} When `true` [`socket.bind()`][] will reuse the + address, even if another process has already bound a socket on it. Optional. + Defaults to `false`. + * `lookup` {Function} Custom lookup function. Defaults to [`dns.lookup()`][]. + Optional. +* `callback` {Function} Attached as a listener for `'message'` events. Optional. * Returns: {dgram.Socket} -Creates a `dgram.Socket` object. The `options` argument is an object that -should contain a `type` field of either `udp4` or `udp6` and an optional -boolean `reuseAddr` field. - -When `reuseAddr` is `true` [`socket.bind()`][] will reuse the address, even if -another process has already bound a socket on it. `reuseAddr` defaults to -`false`. The optional `callback` function is added as a listener for `'message'` -events. - -Once the socket is created, calling [`socket.bind()`][] will instruct the -socket to begin listening for datagram messages. When `address` and `port` are -not passed to [`socket.bind()`][] the method will bind the socket to the "all -interfaces" address on a random port (it does the right thing for both `udp4` -and `udp6` sockets). The bound address and port can be retrieved using -[`socket.address().address`][] and [`socket.address().port`][]. +Creates a `dgram.Socket` object. Once the socket is created, calling +[`socket.bind()`][] will instruct the socket to begin listening for datagram +messages. When `address` and `port` are not passed to [`socket.bind()`][] the +method will bind the socket to the "all interfaces" address on a random port +(it does the right thing for both `udp4` and `udp6` sockets). The bound address +and port can be retrieved using [`socket.address().address`][] and +[`socket.address().port`][]. ### dgram.createSocket(type[, callback]) -Node contains support for ES Modules based upon the [the Node EP for ES Modules][]. +Node.js contains support for ES Modules based upon the +[Node.js EP for ES Modules][]. -Not all features of the EP are complete and will be landing as both VM support and implementation is ready. Error messages are still being polished. +Not all features of the EP are complete and will be landing as both VM support +and implementation is ready. Error messages are still being polished. ## Enabling -The `--experimental-modules` flag can be used to enable features for loading ESM modules. +The `--experimental-modules` flag can be used to enable features for loading +ESM modules. -Once this has been set, files ending with `.mjs` will be able to be loaded as ES Modules. +Once this has been set, files ending with `.mjs` will be able to be loaded +as ES Modules. ```sh node --experimental-modules my-app.mjs @@ -28,7 +32,9 @@ node --experimental-modules my-app.mjs ### Supported -Only the CLI argument for the main entry point to the program can be an entry point into an ESM graph. In the future `import()` can be used to create entry points into ESM graphs at run time. +Only the CLI argument for the main entry point to the program can be an entry +point into an ESM graph. In the future `import()` can be used to create entry +points into ESM graphs at run time. ### Unsupported @@ -43,11 +49,13 @@ Only the CLI argument for the main entry point to the program can be an entry po ### No NODE_PATH -`NODE_PATH` is not part of resolving `import` specifiers. Please use symlinks if this behavior is desired. +`NODE_PATH` is not part of resolving `import` specifiers. Please use symlinks +if this behavior is desired. ### No `require.extensions` -`require.extensions` is not used by `import`. The expectation is that loader hooks can provide this workflow in the future. +`require.extensions` is not used by `import`. The expectation is that loader +hooks can provide this workflow in the future. ### No `require.cache` @@ -55,9 +63,12 @@ Only the CLI argument for the main entry point to the program can be an entry po ### URL based paths -ESM are resolved and cached based upon [URL](url.spec.whatwg.org) semantics. This means that files containing special characters such as `#` and `?` need to be escaped. +ESM are resolved and cached based upon [URL](https://url.spec.whatwg.org/) +semantics. This means that files containing special characters such as `#` and +`?` need to be escaped. -Modules will be loaded multiple times if the `import` specifier used to resolve them have a different query or fragment. +Modules will be loaded multiple times if the `import` specifier used to resolve +them have a different query or fragment. ```js import './foo?query=1'; // loads ./foo with query of "?query=1" @@ -70,9 +81,11 @@ For now, only modules using the `file:` protocol can be loaded. All CommonJS, JSON, and C++ modules can be used with `import`. -Modules loaded this way will only be loaded once, even if their query or fragment string differs between `import` statements. +Modules loaded this way will only be loaded once, even if their query +or fragment string differs between `import` statements. -When loaded via `import` these modules will provide a single `default` export representing the value of `module.exports` at the time they finished evaluating. +When loaded via `import` these modules will provide a single `default` export +representing the value of `module.exports` at the time they finished evaluating. ```js import fs from 'fs'; @@ -85,4 +98,4 @@ fs.readFile('./foo.txt', (err, body) => { }); ``` -[the Node EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md +[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md diff --git a/doc/api/fs.md b/doc/api/fs.md index 0d9755d60900d3..034817b8b3bce7 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -1536,10 +1536,10 @@ object with an `encoding` property specifying the character encoding to use. Example: ```js -fs.mkdtemp('/tmp/foo-', (err, folder) => { +fs.mkdtemp(path.join(os.tmpdir(), 'foo-'), (err, folder) => { if (err) throw err; console.log(folder); - // Prints: /tmp/foo-itXde2 + // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2 }); ``` @@ -1551,7 +1551,7 @@ the `prefix` *must* end with a trailing platform-specific path separator ```js // The parent directory for the new temporary directory -const tmpDir = '/tmp'; +const tmpDir = os.tmpdir(); // This method is *INCORRECT*: fs.mkdtemp(tmpDir, (err, folder) => { diff --git a/doc/api/http.md b/doc/api/http.md index e646e291ac724c..3219893761c467 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -286,9 +286,9 @@ added: v0.1.17 This object is created internally and returned from [`http.request()`][]. It represents an _in-progress_ request whose header has already been queued. The -header is still mutable using the `setHeader(name, value)`, `getHeader(name)`, -`removeHeader(name)` API. The actual header will be sent along with the first -data chunk or when calling [`request.end()`][]. +header is still mutable using the [`setHeader(name, value)`][], + [`getHeader(name)`][], [`removeHeader(name)`][] API. The actual header will +be sent along with the first data chunk or when calling [`request.end()`][]. To get the response, add a listener for [`'response'`][] to the request object. [`'response'`][] will be emitted from the request object when the response @@ -321,14 +321,6 @@ added: v1.4.1 Emitted when the request has been aborted by the client. This event is only emitted on the first call to `abort()`. -### Event: 'aborted' - - -Emitted when the request has been aborted by the server and the network -socket has closed. - ### Event: 'connect' + +Emitted when the underlying socket times out from inactivity. This only notifies +that the socket has been idle. The request must be aborted manually. + +See also: [`request.setTimeout()`][] + ### Event: 'upgrade' + +* `name` {string} +* Returns: {string} + +Reads out a header on the request. Note that the name is case insensitive. + +Example: +```js +const contentType = request.getHeader('Content-Type'); +``` + +### request.removeHeader(name) + + +* `name` {string} + +Removes a header that's already defined into headers object. + +Example: +```js +request.removeHeader('Content-Type'); +``` + +### request.setHeader(name, value) + + +* `name` {string} +* `value` {string} + +Sets a single header value for headers object. If this header already exists in +the to-be-sent headers, its value will be replaced. Use an array of strings +here to send multiple headers with the same name. + +Example: +```js +request.setHeader('Content-Type', 'application/json'); +``` + +or + +```js +request.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']); +``` + ### request.setNoDelay([noDelay]) -Emitted when the request has been aborted by the client and the network -socket has closed. +Emitted when the request has been aborted and the network socket has closed. ### Event: 'close' -Call [`stream.pushStream()`][] with the given headers, and wraps the +Call [`http2stream.pushStream()`][] with the given headers, and wraps the given newly created [`Http2Stream`] on `Http2ServerRespose`. The callback will be called with an error with code `ERR_HTTP2_STREAM_CLOSED` @@ -2667,7 +2667,7 @@ if the stream is closed. [HTTP/2]: https://tools.ietf.org/html/rfc7540 [HTTPS]: https.html [Headers Object]: #http2_headers_object -[Http2Session and Sockets]: #http2_http2sesion_and_sockets +[Http2Session and Sockets]: #http2_http2session_and_sockets [Readable Stream]: stream.html#stream_class_stream_readable [Settings Object]: #http2_settings_object [Using options.selectPadding]: #http2_using_options_selectpadding @@ -2678,14 +2678,15 @@ if the stream is closed. [`ClientHttp2Stream`]: #http2_class_clienthttp2stream [`Duplex`]: stream.html#stream_class_stream_duplex [`EventEmitter`]: events.html#events_class_eventemitter +[`Http2ServerRequest`]: #http2_class_http2_http2serverrequest [`Http2Stream`]: #http2_class_http2stream [`ServerHttp2Stream`]: #http2_class_serverhttp2stream -[`ServerRequest`]: #http2_class_server_request [`TypeError`]: errors.html#errors_class_typeerror [`http2.SecureServer`]: #http2_class_http2secureserver [`http2.createSecureServer()`]: #http2_createsecureserver_options_onrequesthandler [`http2.Server`]: #http2_class_http2server [`http2.createServer()`]: #http2_createserver_options_onrequesthandler +[`http2stream.pushStream()`]: #http2_http2stream_pushstream_headers_options_callback [`net.Socket`]: net.html#net_class_net_socket [`request.socket.getPeerCertificate()`]: tls.html#tls_tlssocket_getpeercertificate_detailed [`response.end()`]: #http2_response_end_data_encoding_callback @@ -2695,7 +2696,6 @@ if the stream is closed. [`response.write(data, encoding)`]: http.html#http_response_write_chunk_encoding_callback [`response.writeContinue()`]: #http2_response_writecontinue [`response.writeHead()`]: #http2_response_writehead_statuscode_statusmessage_headers -[`stream.pushStream()`]: #http2_stream-pushstream [`tls.TLSSocket`]: tls.html#tls_class_tls_tlssocket [`tls.createServer()`]: tls.html#tls_tls_createserver_options_secureconnectionlistener [error code]: #error_codes diff --git a/doc/api/n-api.md b/doc/api/n-api.md index e3d7dcce32256b..7bd20c60b60ea1 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -41,7 +41,8 @@ The documentation for N-API is structured as follows: * [Working with JavaScript Properties][] * [Working with JavaScript Functions][] * [Object Wrap][] -* [Asynchronous Operations][] +* [Simple Asynchronous Operations][] +* [Custom Asynchronous Operations][] * [Promises][] * [Script Execution][] @@ -62,14 +63,6 @@ For example: #include ``` -As the feature is experimental it must be enabled with the -following command line -[option](https://nodejs.org/dist/latest-v8.x/docs/api/cli.html#cli_napi_modules): - -```bash ---napi-modules -``` - ## Basic N-API Data Types N-API exposes the following fundamental datatypes as abstractions that are @@ -264,7 +257,7 @@ It is intended only for logging purposes. added: v8.0.0 --> ```C -NAPI_EXTERN napi_status +napi_status napi_get_last_error_info(napi_env env, const napi_extended_error_info** result); ``` @@ -515,8 +508,8 @@ This API returns a JavaScript RangeError with the text provided. added: v8.0.0 --> ```C -NAPI_EXTERN napi_status napi_get_and_clear_last_exception(napi_env env, - napi_value* result); +napi_status napi_get_and_clear_last_exception(napi_env env, + napi_value* result); ``` - `[in] env`: The environment that the API is invoked under. @@ -531,7 +524,7 @@ This API returns true if an exception is pending. added: v8.0.0 --> ```C -NAPI_EXTERN napi_status napi_is_exception_pending(napi_env env, bool* result); +napi_status napi_is_exception_pending(napi_env env, bool* result); ``` - `[in] env`: The environment that the API is invoked under. @@ -551,11 +544,18 @@ thrown to immediately terminate the process. added: v8.2.0 --> ```C -NAPI_EXTERN NAPI_NO_RETURN void napi_fatal_error(const char* location, const char* message); +NAPI_NO_RETURN void napi_fatal_error(const char* location, + size_t location_len, + const char* message, + size_t message_len); ``` - `[in] location`: Optional location at which the error occurred. +- `[in] location_len`: The length of the location in bytes, or -1 if it is +null-terminated. - `[in] message`: The message associated with the error. +- `[in] message_len`: The length of the message in bytes, or -1 if it is +null-terminated. The function call does not return, the process will be terminated. @@ -718,10 +718,10 @@ reverse order from which they were created. added: v8.0.0 --> ```C -NAPI_EXTERN napi_status napi_escape_handle(napi_env env, - napi_escapable_handle_scope scope, - napi_value escapee, - napi_value* result); +napi_status napi_escape_handle(napi_env env, + napi_escapable_handle_scope scope, + napi_value escapee, + napi_value* result); ``` - `[in] env`: The environment that the API is invoked under. @@ -787,7 +787,7 @@ NODE_EXTERN napi_status napi_create_reference(napi_env env, - `[in] env`: The environment that the API is invoked under. - `[in] value`: `napi_value` representing the Object to which we want -a reference to. +a reference. - `[in] initial_refcount`: Initial reference count for the new reference. - `[out] result`: `napi_ref` pointing to the new reference. @@ -873,7 +873,7 @@ JavaScript Object associated with the `napi_ref`. Otherise, result will be NULL. ## Module registration -N-API modules are registered in the same manner as other modules +N-API modules are registered in a manner similar to other modules except that instead of using the `NODE_MODULE` macro the following is used: @@ -885,32 +885,39 @@ The next difference is the signature for the `Init` method. For a N-API module it is as follows: ```C -void Init(napi_env env, napi_value exports, napi_value module, void* priv); +napi_value Init(napi_env env, napi_value exports); ``` -As with any other module, functions are exported by either adding them to -the `exports` or `module` objects passed to the `Init` method. +The return value from `Init` is treated as the `exports` object for the module. +The `Init` method is passed an empty object via the `exports` parameter as a +convenience. If `Init` returns NULL, the parameter passed as `exports` is +exported by the module. N-API modules cannot modify the `module` object but can +specify anything as the `exports` property of the module. For example, to add the method `hello` as a function so that it can be called as a method provided by the addon: ```C -void Init(napi_env env, napi_value exports, napi_value module, void* priv) { +napi_value Init(napi_env env, napi_value exports) { napi_status status; napi_property_descriptor desc = {"hello", Method, 0, 0, 0, napi_default, 0}; + if (status != napi_ok) return nullptr; status = napi_define_properties(env, exports, 1, &desc); + if (status != napi_ok) return nullptr; + return exports; } ``` For example, to set a function to be returned by the `require()` for the addon: ```C -void Init(napi_env env, napi_value exports, napi_value module, void* priv) { +napi_value Init(napi_env env, napi_value exports) { + napi_value method; napi_status status; - napi_property_descriptor desc = - {"exports", Method, 0, 0, 0, napi_default, 0}; - status = napi_define_properties(env, module, 1, &desc); + status = napi_create_function(env, "exports", Method, NULL, &method)); + if (status != napi_ok) return nullptr; + return method; } ``` @@ -919,28 +926,30 @@ For example, to define a class so that new instances can be created ```C // NOTE: partial example, not all referenced code is included - -napi_status status; -napi_property_descriptor properties[] = { +napi_value Init(napi_env env, napi_value exports) { + napi_status status; + napi_property_descriptor properties[] = { { "value", nullptr, GetValue, SetValue, 0, napi_default, 0 }, DECLARE_NAPI_METHOD("plusOne", PlusOne), DECLARE_NAPI_METHOD("multiply", Multiply), -}; + }; -napi_value cons; -status = - napi_define_class(env, "MyObject", New, nullptr, 3, properties, &cons); -if (status != napi_ok) return; + napi_value cons; + status = + napi_define_class(env, "MyObject", New, nullptr, 3, properties, &cons); + if (status != napi_ok) return nullptr; -status = napi_create_reference(env, cons, 1, &constructor); -if (status != napi_ok) return; + status = napi_create_reference(env, cons, 1, &constructor); + if (status != napi_ok) return nullptr; -status = napi_set_named_property(env, exports, "MyObject", cons); -if (status != napi_ok) return; + status = napi_set_named_property(env, exports, "MyObject", cons); + if (status != napi_ok) return nullptr; + + return exports; +} ``` -For more details on setting properties on either the `exports` or `module` -objects, see the section on +For more details on setting properties on objects, see the section on [Working with JavaScript Properties][]. For more details on building addon modules in general, refer to the existing API @@ -1238,6 +1247,7 @@ added: v8.0.0 ```C napi_status napi_create_function(napi_env env, const char* utf8name, + size_t length, napi_callback cb, void* data, napi_value* result) @@ -1246,6 +1256,8 @@ napi_status napi_create_function(napi_env env, - `[in] env`: The environment that the API is invoked under. - `[in] utf8name`: A string representing the name of the function encoded as UTF8. +- `[in] length`: The length of the utf8name in bytes, or -1 if it is +null-terminated. - `[in] cb`: A function pointer to the native function to be invoked when the created function is invoked from JavaScript. - `[in] data`: Optional arbitrary context data to be passed into the native @@ -1469,10 +1481,10 @@ of the ECMAScript Language Specification. added: v8.0.0 --> ```C -NAPI_EXTERN napi_status napi_create_string_latin1(napi_env env, - const char* str, - size_t length, - napi_value* result); +napi_status napi_create_string_latin1(napi_env env, + const char* str, + size_t length, + napi_value* result); ``` - `[in] env`: The environment that the API is invoked under. @@ -1802,11 +1814,11 @@ JavaScript Number added: v8.0.0 --> ```C -NAPI_EXTERN napi_status napi_get_value_string_latin1(napi_env env, - napi_value value, - char* buf, - size_t bufsize, - size_t* result) +napi_status napi_get_value_string_latin1(napi_env env, + napi_value value, + char* buf, + size_t bufsize, + size_t* result) ``` - `[in] env`: The environment that the API is invoked under. @@ -2337,7 +2349,7 @@ napi_status status = napi_status_generic_failure; // const obj = {}; napi_value obj; -status = napi_create_obj(env, &obj); +status = napi_create_object(env, &obj); if (status != napi_ok) return status; // Create napi_values for 123 and 456 @@ -2348,9 +2360,9 @@ status = napi_create_int32(env, 456, &barValue); if (status != napi_ok) return status; // Set the properties -napi_property_descriptors descriptors[] = { - { "foo", fooValue, 0, 0, 0, napi_default, 0 }, - { "bar", barValue, 0, 0, 0, napi_default, 0 } +napi_property_descriptor descriptors[] = { + { "foo", nullptr, 0, 0, 0, fooValue, napi_default, 0 }, + { "bar", nullptr, 0, 0, 0, barValue, napi_default, 0 } } status = napi_define_properties(env, obj, @@ -2781,8 +2793,8 @@ in as arguments to the function. Returns `napi_ok` if the API succeeded. This method allows a JavaScript function object to be called from a native -add-on. This is an primary mechanism of calling back *from* the add-on's -native code *into* JavaScript. For special cases like calling into JavaScript +add-on. This is the primary mechanism of calling back *from* the add-on's +native code *into* JavaScript. For the special case of calling into JavaScript after an async operation, see [`napi_make_callback`][]. A sample use case might look as follows. Consider the following JavaScript @@ -2918,25 +2930,24 @@ Returns `napi_ok` if the API succeeded. This method is used within a callback function to retrieve details about the call like the arguments and the `this` pointer from a given callback info. -### *napi_is_construct_call* +### *napi_get_new_target* ```C -napi_status napi_is_construct_call(napi_env env, - napi_callback_info cbinfo, - bool* result) +napi_status napi_get_new_target(napi_env env, + napi_callback_info cbinfo, + napi_value* result) ``` - `[in] env`: The environment that the API is invoked under. - `[in] cbinfo`: The callback info passed into the callback function. -- `[out] result`: Whether the native function is being invoked as -a constructor call. +- `[out] result`: The `new.target` of the constructor call. Returns `napi_ok` if the API succeeded. -This API checks if the the current callback was due to a -consructor call. +This API returns the `new.target` of the constructor call. If the current +callback is not a constructor call, the result is `nullptr`. ### *napi_new_instance* -```C -napi_status napi_make_callback(napi_env env, - napi_value recv, - napi_value func, - int argc, - const napi_value* argv, - napi_value* result) -``` - -- `[in] env`: The environment that the API is invoked under. -- `[in] recv`: The `this` object passed to the called function. -- `[in] func`: `napi_value` representing the JavaScript function -to be invoked. -- `[in] argc`: The count of elements in the `argv` array. -- `[in] argv`: Array of JavaScript values as `napi_value` -representing the arguments to the function. -- `[out] result`: `napi_value` representing the JavaScript object returned. - -Returns `napi_ok` if the API succeeded. - -This method allows a JavaScript function object to be called from a native -add-on. This API is similar to `napi_call_function`. However, it is used to call -*from* native code back *into* JavaScript *after* returning from an async -operation (when there is no other script on the stack). It is a fairly simple -wrapper around `node::MakeCallback`. - -For an example on how to use `napi_make_callback`, see the section on -[Asynchronous Operations][]. - ## Object Wrap N-API offers a way to "wrap" C++ classes and instances so that the class @@ -3050,6 +3028,7 @@ added: v8.0.0 ```C napi_status napi_define_class(napi_env env, const char* utf8name, + size_t length, napi_callback constructor, void* data, size_t property_count, @@ -3061,6 +3040,8 @@ napi_status napi_define_class(napi_env env, - `[in] utf8name`: Name of the JavaScript constructor function; this is not required to be the same as the C++ class name, though it is recommended for clarity. + - `[in] length`: The length of the utf8name in bytes, or -1 if it is +null-terminated. - `[in] constructor`: Callback function that handles constructing instances of the class. (This should be a static method on the class, not an actual C++ constructor function.) @@ -3205,7 +3186,7 @@ restoring the JavaScript object's prototype chain. If a finalize callback was associated with the wrapping, it will no longer be called when the JavaScript object becomes garbage-collected. -## Asynchronous Operations +## Simple Asynchronous Operations Addon modules often need to leverage async helpers from libuv as part of their implementation. This allows them to schedule work to be executed asynchronously @@ -3241,8 +3222,8 @@ Once created the async worker can be queued for execution using the [`napi_queue_async_work`][] function: ```C -NAPI_EXTERN napi_status napi_queue_async_work(napi_env env, - napi_async_work work); +napi_status napi_queue_async_work(napi_env env, + napi_async_work work); ``` [`napi_cancel_async_work`][] can be used if the work needs @@ -3256,10 +3237,15 @@ callback invocation, even when it was cancelled. ### napi_create_async_work ```C -NAPI_EXTERN napi_status napi_create_async_work(napi_env env, + napi_value async_resource, + napi_value async_resource_name, napi_async_execute_callback execute, napi_async_complete_callback complete, void* data, @@ -3267,6 +3253,10 @@ napi_status napi_create_async_work(napi_env env, ``` - `[in] env`: The environment that the API is invoked under. +- `[in] async_resource`: An optional object associated with the async work + that will be passed to possible async_hooks [`init` hooks][]. +- `[in] async_resource_name`: An identifier for the kind of resource that is +being provided for diagnostic information exposed by the `async_hooks` API. - `[in] execute`: The native function which should be called to excute the logic asynchronously. - `[in] complete`: The native function which will be called when the @@ -3282,13 +3272,21 @@ This API allocates a work object that is used to execute logic asynchronously. It should be freed using [`napi_delete_async_work`][] once the work is no longer required. +`async_resource_name` should be a null-terminated, UTF-8-encoded string. + +*Note*: The `async_resource_name` identifier is provided by the user and should +be representative of the type of async work being performed. It is also +recommended to apply namespacing to the identifier, e.g. by including the +module name. See the [`async_hooks` documentation][async_hooks `type`] +for more information. + ### napi_delete_async_work ```C -NAPI_EXTERN napi_status napi_delete_async_work(napi_env env, - napi_async_work work); +napi_status napi_delete_async_work(napi_env env, + napi_async_work work); ``` - `[in] env`: The environment that the API is invoked under. @@ -3303,8 +3301,8 @@ This API frees a previously allocated work object. added: v8.0.0 --> ```C -NAPI_EXTERN napi_status napi_queue_async_work(napi_env env, - napi_async_work work); +napi_status napi_queue_async_work(napi_env env, + napi_async_work work); ``` - `[in] env`: The environment that the API is invoked under. @@ -3320,8 +3318,8 @@ for execution. added: v8.0.0 --> ```C -NAPI_EXTERN napi_status napi_cancel_async_work(napi_env env, - napi_async_work work); +napi_status napi_cancel_async_work(napi_env env, + napi_async_work work); ``` - `[in] env`: The environment that the API is invoked under. @@ -3336,6 +3334,93 @@ the `complete` callback will be invoked with a status value of `napi_cancelled`. The work should not be deleted before the `complete` callback invocation, even if it has been successfully cancelled. +## Custom Asynchronous Operations +The simple asynchronous work APIs above may not be appropriate for every +scenario, because with those the async execution still happens on the main +event loop. When using any other async mechanism, the following APIs are +necessary to ensure an async operation is properly tracked by the runtime. + +### *napi_async_init** + +```C +napi_status napi_async_init(napi_env env, + napi_value async_resource, + napi_value async_resource_name, + napi_async_context* result) +``` + +- `[in] env`: The environment that the API is invoked under. +- `[in] async_resource`: An optional object associated with the async work + that will be passed to possible `async_hooks` [`init` hooks][]. +- `[in] async_resource_name`: Required identifier for the kind of resource + that is being provided for diagnostic information exposed by the + `async_hooks` API. +- `[out] result`: The initialized async context. + +Returns `napi_ok` if the API succeeded. + +### *napi_async_destroy** + +```C +napi_status napi_async_destroy(napi_env env, + napi_async_context async_context); +``` + +- `[in] env`: The environment that the API is invoked under. +- `[in] async_context`: The async context to be destroyed. + +Returns `napi_ok` if the API succeeded. + +### *napi_make_callback* + +```C +napi_status napi_make_callback(napi_env env, + napi_async_context async_context, + napi_value recv, + napi_value func, + int argc, + const napi_value* argv, + napi_value* result) +``` + +- `[in] env`: The environment that the API is invoked under. +- `[in] async_context`: Context for the async operation that is + invoking the callback. This should normally be a value previously + obtained from [`napi_async_init`][]. However `NULL` is also allowed, + which indicates the current async context (if any) is to be used + for the callback. +- `[in] recv`: The `this` object passed to the called function. +- `[in] func`: `napi_value` representing the JavaScript function +to be invoked. +- `[in] argc`: The count of elements in the `argv` array. +- `[in] argv`: Array of JavaScript values as `napi_value` +representing the arguments to the function. +- `[out] result`: `napi_value` representing the JavaScript object returned. + +Returns `napi_ok` if the API succeeded. + +This method allows a JavaScript function object to be called from a native +add-on. This API is similar to `napi_call_function`. However, it is used to call +*from* native code back *into* JavaScript *after* returning from an async +operation (when there is no other script on the stack). It is a fairly simple +wrapper around `node::MakeCallback`. + +Note it is *not* necessary to use `napi_make_callback` from within a +`napi_async_complete_callback`; in that situation the callback's async +context has already been set up, so a direct call to `napi_call_function` +is sufficient and appropriate. Use of the `napi_make_callback` function +may be required when implementing custom async behavior that does not use +`napi_create_async_work`. + ## Version Management ### napi_get_node_version @@ -3351,7 +3436,6 @@ typedef struct { const char* release; } napi_node_version; -NAPI_EXTERN napi_status napi_get_node_version(napi_env env, const napi_node_version** version); ``` @@ -3372,8 +3456,8 @@ The returned buffer is statically allocated and does not need to be freed. added: v8.0.0 --> ```C -NAPI_EXTERN napi_status napi_get_version(napi_env env, - uint32_t* result); +napi_status napi_get_version(napi_env env, + uint32_t* result); ``` - `[in] env`: The environment that the API is invoked under. @@ -3481,9 +3565,9 @@ deferred = NULL; added: v8.5.0 --> ```C -NAPI_EXTERN napi_status napi_create_promise(napi_env env, - napi_deferred* deferred, - napi_value* promise); +napi_status napi_create_promise(napi_env env, + napi_deferred* deferred, + napi_value* promise); ``` - `[in] env`: The environment that the API is invoked under. @@ -3501,9 +3585,9 @@ This API creates a deferred object and a JavaScript promise. added: v8.5.0 --> ```C -NAPI_EXTERN napi_status napi_resolve_deferred(napi_env env, - napi_deferred deferred, - napi_value resolution); +napi_status napi_resolve_deferred(napi_env env, + napi_deferred deferred, + napi_value resolution); ``` - `[in] env`: The environment that the API is invoked under. @@ -3524,9 +3608,9 @@ The deferred object is freed upon successful completion. added: v8.5.0 --> ```C -NAPI_EXTERN napi_status napi_reject_deferred(napi_env env, - napi_deferred deferred, - napi_value rejection); +napi_status napi_reject_deferred(napi_env env, + napi_deferred deferred, + napi_value rejection); ``` - `[in] env`: The environment that the API is invoked under. @@ -3547,9 +3631,9 @@ The deferred object is freed upon successful completion. added: v8.5.0 --> ```C -NAPI_EXTERN napi_status napi_is_promise(napi_env env, - napi_value promise, - bool* is_promise); +napi_status napi_is_promise(napi_env env, + napi_value promise, + bool* is_promise); ``` - `[in] env`: The environment that the API is invoked under. @@ -3577,7 +3661,8 @@ NAPI_EXTERN napi_status napi_run_script(napi_env env, - `[out] result`: The value resulting from having executed the script. [Promises]: #n_api_promises -[Asynchronous Operations]: #n_api_asynchronous_operations +[Simple Asynchronous Operations]: #n_api_simple_asynchronous_operations +[Custom Asynchronous Operations]: #n_api_custom_asynchronous_operations [Basic N-API Data Types]: #n_api_basic_n_api_data_types [ECMAScript Language Specification]: https://tc39.github.io/ecma262/ [Error Handling]: #n_api_error_handling @@ -3636,3 +3721,5 @@ NAPI_EXTERN napi_status napi_run_script(napi_env env, [`napi_wrap`]: #n_api_napi_wrap [`process.release`]: process.html#process_process_release +[`init` hooks]: async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource +[async_hooks `type`]: async_hooks.html#async_hooks_type diff --git a/doc/api/net.md b/doc/api/net.md index 36280c06493350..9fda2c3ebbbdfe 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -591,7 +591,8 @@ For TCP connections, available `options` are: For [IPC][] connections, available `options` are: * `path` {string} Required. Path the client should connect to. - See [Identifying paths for IPC connections][]. + See [Identifying paths for IPC connections][]. If provided, the TCP-specific + options above are ignored. Returns `socket`. @@ -1000,7 +1001,7 @@ If `allowHalfOpen` is set to `true`, when the other end of the socket sends a FIN packet, the server will only send a FIN packet back when [`socket.end()`][] is explicitly called, until then the connection is half-closed (non-readable but still writable). See [`'end'`][] event -and [RFC 1122][half-closed] for more information. +and [RFC 1122][half-closed] (section 4.2.2.13) for more information. If `pauseOnConnect` is set to `true`, then the socket associated with each incoming connection will be paused, and no data will be read from its handle. @@ -1125,7 +1126,7 @@ Returns true if input is a version 6 IP address, otherwise returns false. [Identifying paths for IPC connections]: #net_identifying_paths_for_ipc_connections [Readable Stream]: stream.html#stream_class_stream_readable [duplex stream]: stream.html#stream_class_stream_duplex -[half-closed]: https://tools.ietf.org/html/rfc1122#section-4.2.2.13 +[half-closed]: https://tools.ietf.org/html/rfc1122 [socket(7)]: http://man7.org/linux/man-pages/man7/socket.7.html [unspecified IPv4 address]: https://en.wikipedia.org/wiki/0.0.0.0 [unspecified IPv6 address]: https://en.wikipedia.org/wiki/IPv6_address#Unspecified_address diff --git a/doc/api/os.md b/doc/api/os.md index 28eff6a13f0b60..818e0204491c6c 100644 --- a/doc/api/os.md +++ b/doc/api/os.md @@ -338,7 +338,7 @@ The `os.release()` method returns a string identifying the operating system release. *Note*: On POSIX systems, the operating system release is determined by -calling uname(3). On Windows, `GetVersionExW()` is used. Please see +calling [uname(3)][]. On Windows, `GetVersionExW()` is used. Please see https://en.wikipedia.org/wiki/Uname#Examples for more information. ## os.tmpdir() @@ -374,11 +374,12 @@ added: v0.3.3 * Returns: {string} The `os.type()` method returns a string identifying the operating system name -as returned by uname(3). For example `'Linux'` on Linux, `'Darwin'` on macOS and -`'Windows_NT'` on Windows. +as returned by [uname(3)][]. For example `'Linux'` on Linux, `'Darwin'` on macOS +and `'Windows_NT'` on Windows. Please see https://en.wikipedia.org/wiki/Uname#Examples for additional -information about the output of running uname(3) on various operating systems. +information about the output of running [uname(3)][] on various operating +systems. ## os.uptime() + +* `err` {Error} An error. +* `callback` {Function} A callback function that takes an optional error + argument which is invoked when the readable is destroyed. + #### readable.push(chunk[, encoding])