Skip to content

fs: remove unnecessary usage of .hasOwnProperty() - #635

Closed
jonathanong wants to merge 1 commit into
nodejs:v1.xfrom
jonathanong:fs-remove-hasownproperty
Closed

fs: remove unnecessary usage of .hasOwnProperty()#635
jonathanong wants to merge 1 commit into
nodejs:v1.xfrom
jonathanong:fs-remove-hasownproperty

Conversation

@jonathanong

Copy link
Copy Markdown
Contributor

on a mission to remove all instances of util._extend() and allow options to have prototypes.

AFAIK, .hasOwnProperty() is unnecessary here.

@vkurchatkin

Copy link
Copy Markdown
Contributor

maybe add a test for this to prevent regressions?

@vkurchatkinvkurchatkin added the fs Issues and PRs related to the fs subsystem / file system. label Jan 28, 2015
@domenic

Copy link
Copy Markdown
Contributor

ES6 style would be === undefined not in. Would suggest that for easier refactoring to ES6 defaults when they become available.

@jonathanong

Copy link
Copy Markdown
ContributorAuthor

okay i'll change it to @domenic's recommendations.

@vkurchatkin what tests, specifically?

@vkurchatkin

Copy link
Copy Markdown
Contributor

@domenic not the same thing. what if { someOption: undefined } means that option should be undefined, not default value

@jonathanong like, that you pass Object.create(options) and this works

@jonathanong

Copy link
Copy Markdown
ContributorAuthor

@domenic actually, would == null be better? an explanation would be nice :D i have a feeling some people set value options to null, and doing === would break backwards compat

@domenic

Copy link
Copy Markdown
Contributor

@vkurchatkin in ES2015, undefined is specifically used to trigger defaults.

null is not used to trigger defaults. In general null is "in-alphabet" whereas undefined is the default-triggering sentinel value.

@domenic

Copy link
Copy Markdown
Contributor

Concrete examples:

functionf(x=1,y=2){console.log(x,y);}functiong({ x =1, y =2}){console.log(x,y);}f();// 1, 2f(undefined,undefined);// 1, 2f(null,null);// null, nullg({x: undefined,y: undefined});// 1, 2g({});// 1, 2g({x: null,x: null});// null, null

@vkurchatkin

Copy link
Copy Markdown
Contributor

@domenic thanks! we should do the same, guess. But I'm afraid that in same cases swapping hasOwnProperty with === undefined would be a breaking change

@kevinmartin

Copy link
Copy Markdown

I agree with @domenic that === undefined is the way to go. It's the correct way going forward with ES6 to make use of default values. The only thing this would "potentially" break is if there is a value where the default is null but someone enters (and means for the value to specifically be) undefined.

I don't see that as a problem either way, because the only variable that it would affect is this.fd. The reason why it doesn't affect it is because every function that utilizes this.fd (except SyncWriteStream.prototype.write for some reason), does a util.isNumber() check on this.fd. Therefore it doesn't matter if it's null or undefined

@piscisaureus

Copy link
Copy Markdown
Contributor

What is different in ES6 that makes hasOwnProperty unnecessary?

@vkurchatkin

Copy link
Copy Markdown
Contributor

@piscisaureus it's not about ES6, I think. @jonathanong want's to get reed of hasOwnProperty so that options could be inherited. @domenic says that it's not ES6 way to use in instead. If you write something like this:

functionfn({ option1, encoding='utf8'}){}

encoding will be utf8 for fn({ encoding:undefined })

@vkurchatkin

Copy link
Copy Markdown
Contributor

@jonathanong ping

@jonathanong

Copy link
Copy Markdown
ContributorAuthor

@vkurchatkin sup? Which direction should I take this PR?

@vkurchatkin

Copy link
Copy Markdown
Contributor
  1. Use === undefined
  2. Add some tests where options are inherited

Comment threadlib/fs.js

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

added this because i realized that without it, all my .hasOwnProperty() stuff is futile

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is fine since ReadableStream doesn't use .hasOwnProperty

@tellnes

Copy link
Copy Markdown
Contributor

@jonathanong I think something has gone wrong with your rebaseing.

@vkurchatkin

Copy link
Copy Markdown
Contributor

LGTM

@vkurchatkinvkurchatkin added the semver-minor PRs that contain new features and should be released in the next minor version. label Feb 23, 2015
vkurchatkin pushed a commit that referenced this pull request Mar 5, 2015
PR-URL: #635
Reviewed-By: Vladimir Kurchatkin <vladimir.kurchatkin@gmail.com>
@vkurchatkin

Copy link
Copy Markdown
Contributor

Landed in 4d0329e

@rvaggrvagg mentioned this pull request Mar 5, 2015
@jonathanong
jonathanong deleted the fs-remove-hasownproperty branch March 5, 2015 17:01
rvagg added a commit that referenced this pull request Mar 6, 2015
Notable changes:
* buffer: New `Buffer#indexOf()` method, modelled off `Array#indexOf()`.
Accepts a String, Buffer or a Number. Strings are interpreted as UTF8.
(Trevor Norris) #561
* fs: `options` object properties in `'fs'` methods no longer perform a
`hasOwnProperty()` check, thereby allowing options objects to have
prototype properties that apply. (Jonathan Ong)
#635
* tls: A likely TLS memory leak was reported by PayPal. Some of the recent
changes in stream_wrap appear to be to blame. The initial fix is in
#1078, you can track the progress
toward closing the leak at
#1075 (Fedor Indutny).
* npm: Upgrade npm to 2.7.0. See npm CHANGELOG.md:
https://github.com/npm/npm/blob/master/CHANGELOG.md#v270-2015-02-26
for details including why this is a semver-minor when it could have
been semver-major.
* TC: Colin Ihrig (@cjihrig) resigned from the TC due to his desire to do
more code and fewer meetings.
brendanashworth added a commit to brendanashworth/io.js that referenced this pull request Mar 14, 2015
This commit does various changes to cleanup and prep the 8ff6b81 for
merging, which include updating the commit to follow new codebase
guidelines. The following are the changes:
doc/api/http.markdown:
- document options
lib/http.js:
- no changes
lib/_http_server.js
- changes regarding isObject (nodejs#647) and hasOwnProperty (nodejs#635)
- take tls option rather than guessing based on options
test/simple/test-https-from-http.js:
- moved to parallel directory, crypto test, removed copyright banner
test/parallel/test-http-server.js:
- adjust for tls option
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fsIssues and PRs related to the fs subsystem / file system.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@jonathanong@vkurchatkin@domenic@kevinmartin@piscisaureus@tellnes