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

Date.prototype.valueOf called on incompatible Proxy #44

Closed
gregwebs opened this Issue Apr 19, 2012 · 6 comments

Comments

Projects
None yet
3 participants
@gregwebs

gregwebs commented Apr 19, 2012

I am trying to define some contracts that return dates. I am using the date.js library. If I define DateC = Any, it works fine.

If I define:

DateC = ?({ 
  clone: -> Self
  addSeconds: (Num) -> Self
  getMilliseconds: -> Num 
})

I get this error:

Date.prototype.valueOf called on incompatible Proxy
[Break On This Error]   

if (data.date[i].startDate != null && data.date[i].startDate != "") {

startDate here should be the date object. Am I missing an equality operator in my contract?

@disnet

This comment has been minimized.

Owner

disnet commented Apr 24, 2012

Apparently the current implementation of Proxies in both SpiderMonkey and V8 doesn't support the Date object. This is the JS builtin, the bug has nothing to do with the date.js library.

Support for the Date object should be coming with the new direct Proxies. Here's a bug link for direct Proxies in SpiderMonkey so Firefox should have support soon. No public bug for V8 that I could find. Hopefully they're working on it.

@gregwebs

This comment has been minimized.

gregwebs commented Apr 24, 2012

is a Date a "primitive" then, as per the docs stating that contracts can't be put on primitives?

@disnet

This comment has been minimized.

Owner

disnet commented Apr 24, 2012

Note quite. Date is an "irregular object" (like array, function, and the DOM) that doesn't behave quite like a regular JS object should. Direct proxies won't (as far as I know) let us proxy primitives but it will let us better proxy the irregular objects.

@gregwebs

This comment has been minimized.

gregwebs commented Apr 24, 2012

Then can the documentation be updated to specifically mention the irregular options?

disnet added a commit that referenced this issue Apr 24, 2012

@gregwebs

This comment has been minimized.

gregwebs commented Apr 24, 2012

thanks!

@gregwebs gregwebs closed this Apr 24, 2012

@BrendanEich

This comment has been minimized.

BrendanEich commented Nov 20, 2012

Direct proxies are supported in SpiderMonkey. You must call new Proxy(target, handler) -- the 'new' is required. It seems you can make a Date instance be the target without exceptions, but I haven't tested extensively, or in particular the contracts.coffee testcase here -- just a quick js shell session.

/be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment