Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

calvinmetcalf
Copy link
Collaborator

@jprichardson
Copy link
Collaborator

utACK.

@calvinmetcalf
Copy link
Collaborator Author

ut?

@jprichardson
Copy link
Collaborator

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.

@calvinmetcalf
Copy link
Collaborator Author

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);
Copy link
Owner

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().

Copy link
Contributor

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.

Copy link
Owner

Choose a reason for hiding this comment

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

Like some magic value?

Copy link
Contributor

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?

Copy link
Owner

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? 😉

Copy link
Contributor

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.

@axic
Copy link
Contributor

axic commented Apr 13, 2016

@calvinmetcalf @jprichardson @indutny in the previous in line comment, as a suggestion this came up: num instanceof BN.

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.

@fanatid
Copy link
Collaborator

fanatid commented Apr 14, 2016

@axis instanceof is not good here
bitpay/bitcore-lib#21

@axic
Copy link
Contributor

axic commented May 19, 2016

@indutny @calvinmetcalf @jprichardson @fanatid ping. A decision and fix could be useful ;)

@jprichardson
Copy link
Collaborator

I've reversed my position on this. I think function.constructor.name is a good idea to keep. Uglify allows you to not touch this --keep-fnames and IE users can always shim. The nice thing is that different BN.js dependencies than can be used and we don't get caught with instanceof bugs. My two cents.

@calvinmetcalf
Copy link
Collaborator Author

@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

@indutny
Copy link
Owner

indutny commented May 20, 2016

Considering recent stability of bn.js versions, I'm inclined to say that we may want to just do instanceof, and add an assert like this:

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?

@calvinmetcalf
Copy link
Collaborator Author

+1 I like it

On Fri, May 20, 2016 at 4:58 PM Fedor Indutny notifications@github.com
wrote:

Considering recent stability of bn.js versions, I'm inclined to say that
we may want to just do instanceof, and add an assert like this:

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?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#134 (comment)

@axic
Copy link
Contributor

axic commented Jul 13, 2016

@calvinmetcalf @indutny I think this can be closed then?

@indutny
Copy link
Owner

indutny commented Jul 13, 2016

I think yes, thank you!

@indutny indutny closed this Jul 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BN.isBN() breaks code when minified
5 participants