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

PaperScript throws error when using [object]==null #1043

Closed
ktsuttlemyre opened this issue Apr 30, 2016 · 2 comments
Closed

PaperScript throws error when using [object]==null #1043

ktsuttlemyre opened this issue Apr 30, 2016 · 2 comments

Comments

@ktsuttlemyre
Copy link

I am using this library for large integers https://github.com/peterolson/BigInteger.js
PaperScript will throw an error when I write

var n=bigInt('1000')
if(n==null){ //this line throws an error
   alert('this alert will never show')
}

However if I switch the condition to say

var n=bigInt('1000')
if(null==n){ //this line does not error
   alert('this alert will never show')
}

The error
BigInteger.js:688 Uncaught TypeError: Cannot read property 'value' of nullSmallInteger.compare
BigInteger.js:688BigInteger.equals
BigInteger.js:700t
paper-full.min.js:38setCanonicalPath
VM1729:306update
VM1729:251(anonymous function)
truncated for convince .......

It seems, PaperScript assumes an object in the first position with an equals function will be able to handle any input given to the equals function.
Ex if(__$__(n, "==" , null)) {
This may be a huge assumption on the PaperScript interpreter as JavaScript can handle this expression correctly.

@lehni
Copy link
Member

lehni commented Jun 10, 2016

Here the sketch for this issue.

@lehni
Copy link
Member

lehni commented Jun 10, 2016

The problem is that the bigInt class defines an equals() method that is unable to handle null, and PaperScript currently translates == to such left.equals(right) calls.

We've already moved to special signatures for all math calls (__add()& co.), so we just have to do the same for equals, to mark these special equals methods that are able to behave like == does.

@lehni lehni closed this as completed in 964d8cf Jun 10, 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

No branches or pull requests

2 participants