-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: fix constructor/instanceof checks #3385
Conversation
LGTM. is there anywhere else we are relying on similar functionality? |
Yeah, I guess I'll fix those up too while I'm in there. |
332647b
to
68e2f1e
Compare
|
||
function isMap(obj) { | ||
obj = getConstructorOf(obj); | ||
while (typeof obj !== undefined && obj !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be typeof obj !== 'undefined'
or obj !== undefined
, like above?
Updated to fix the other constructor/instanceof checks. CI: https://ci.nodejs.org/view/iojs/job/node-test-pull-request/515 |
68e2f1e
to
0450980
Compare
Just curious, but I wonder if the |
Updated again to fix typo. CI: https://ci.nodejs.org/view/iojs/job/node-test-pull-request/516 |
This doesn't seem better than |
0450980
to
f8cb886
Compare
@vkurchatkin That won't work for Promises though. I've now replaced |
@mscdex I don't know if Map and Set can be subclassed, but I think your first version had the advantage to catch this: class MyMap extends Map {}
util.inspect(new MyMap) |
@targos They can be and apparently CI after replacing Map/Set check implementations: https://ci.nodejs.org/view/iojs/job/node-test-pull-request/517/ |
I'm still a little concerned about using |
@evanlucas Unreliable in what way? We're already using the same method in other |
maybe I'm thinking about once |
LGTM if CI is happy |
As much as depending on |
@jasnell Well, previously I was walking the prototype chain (similar to what I'm currently doing for checking for promises), but I'm not sure what the performance differences are. |
Yeah, like I said, I'm not sure there's a better way. It just makes me sad to be forced to rely on toString checks |
Kicked off another CI run, just to be sure since the last one came up red: https://ci.nodejs.org/job/node-test-pull-request/567/ |
@mscdex .. hmm... thinking... would this qualify as a semver-minor or major? it likely shouldn't but want to be sure |
Wow, looks like there's something missing from a previous commit... an addon test is looking for a debug module... |
Personally I would see this as a bug fix, so I wouldn't see it as a |
Very odd... testing a clean build locally on osx... |
@mscdex ... not seeing the same failure locally on osx ... can you test on your end? |
FWIW calling into native is cheap, the call itself is simple enough: void CheckIsPromise(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(args[0]->IsPromise());
} And this method is more definitive. |
New CI: https://ci.nodejs.org/job/node-test-pull-request/676/ @mscdex ... did you see the last comment from @trevnorris ? |
f8cb886
to
cdd15fb
Compare
@jasnell I've removed the js |
@@ -316,7 +319,7 @@ function formatValue(ctx, value, recurseTimes) { | |||
formatter = formatMap; | |||
} else { | |||
// Only create a mirror if the object superficially looks like a Promise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment isn't relevant anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? A mirror is still only created if it's been determined the object is a promise. Do you mean the "superficially" part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, now the check isn't superficial. Also the comment isn't in the right context. It is not obvious here that we create an object mirror.
I know the change was made earlier but do you mind moving it to the inspectPromise
declaration ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think it's fine the way it is.
LGTM. CI is red but the failures do not appear to be related. |
These new checks are similar to the one introduced in 089d688, but for other types of objects. Specifically, if an object was created in a different context, the constructor object will not be the same as the constructor object in the current context, so we have to compare constructor names instead.
cdd15fb
to
7b775da
Compare
@targos I've updated the comment about Promises. LGTY? |
I ran through CI one more time and only saw a few unrelated errors on Windows. |
LGTM |
These new checks are similar to the one introduced in 089d688, but for other types of objects. Specifically, if an object was created in a different context, the constructor object will not be the same as the constructor object in the current context, so we have to compare constructor names instead. PR-URL: #3385 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Landed in 82b8355. |
These new checks are similar to the one introduced in 089d688, but for other types of objects. Specifically, if an object was created in a different context, the constructor object will not be the same as the constructor object in the current context, so we have to compare constructor names instead. PR-URL: #3385 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
These new checks are similar to the one introduced in 089d688, but for other types of objects. Specifically, if an object was created in a different context, the constructor object will not be the same as the constructor object in the current context, so we have to compare constructor names instead. PR-URL: #3385 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
These new checks are similar to the one introduced in 089d688, but for other types of objects. Specifically, if an object was created in a different context, the constructor object will not be the same as the constructor object in the current context, so we have to compare constructor names instead. PR-URL: #3385 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
These new checks are similar to the one introduced in 089d688, but for other types of objects. Specifically, if an object was created in a different context, the constructor object will not be the same as the constructor object in the current context, so we have to compare constructor names instead. PR-URL: nodejs#3385 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
util: fix constructor/instanceof checks
These new checks are similar to the one introduced in 089d688, but for other types of objects. Specifically, if an object was created in a different context, the constructor object will not be the same as the constructor object in the current context, so we have to compare constructor names instead.