-
Notifications
You must be signed in to change notification settings - Fork 151
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
remove check for function named 'BN' #134
Conversation
utACK. |
ut? |
ut => "untested" :) i.e. the code looks good, but I haven't actually checked out the code and ran tests personally. I think I picked up the term from the Bitcoin repo. |
ah |
@@ -56,7 +56,7 @@ | |||
|
|||
BN.isBN = function isBN (num) { | |||
return num !== null && typeof num === 'object' && | |||
num.constructor.name === 'BN' && Array.isArray(num.words); | |||
num.constructor.name === BN.name && Array.isArray(num.words); |
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.
You know what I learned recently? This thing does not work in IE: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name .
Looks like we may need to fallback to using just Array.isArray()
.
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.
You could still have a constant exported in BN and check against that.
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.
Like some magic value?
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.
Not entirely sure if it would make sense using a function reference, but it might be handy: num.isBN === BN.isBN
This shouldn't work if num
is an instance of a different BN - do we want that to work or fail?
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.
If we wanted to check against just one instance of BN
- we would use obj instance of BN
, right? 😉
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.
Well that seems to have good browser support :)
The question is still there: that will still reject BN instances of different versions. I am pretty sure that in some browserified instances that will happen. I think it is the desired behaviour, but I don't think many libraries are prepared for this.
@calvinmetcalf @jprichardson @indutny in the previous in line comment, as a suggestion this came up: Would that work in all cases? It rejects any instances from a different BN version, which I think is fine, but has its own drawbacks - I assume many projects aren't prepared for that either. |
@axis |
@indutny @calvinmetcalf @jprichardson @fanatid ping. A decision and fix could be useful ;) |
I've reversed my position on this. I think |
@jprichardson yeah but most/all people don't use --keep-fnames so it would just end up broken in reality, so I'd be in favor of this |
Considering recent stability of assert(other.name === this.constructor.name && Array.isArray(other.words) && !(other instanceof BN), 'Looks like you have a version mismatch'); What do you guys think about this? |
+1 I like it On Fri, May 20, 2016 at 4:58 PM Fedor Indutny notifications@github.com
|
@calvinmetcalf @indutny I think this can be closed then? |
I think yes, thank you! |
fix #133 and thus browserify/browserify-sign#27