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

Add JSDate implementation with tests #45

Merged
merged 8 commits into from
Sep 14, 2020
Merged

Add JSDate implementation with tests #45

merged 8 commits into from
Sep 14, 2020

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Sep 13, 2020

This doesn't 100% match the JS API, for example getMonth/setMonth etc accessor methods are converted to properties, but the rest of it matches in the naming. I didn't expose API parts that MDN marks as non-standard or not consistent across browsers and JS implementations.

@MaxDesiatov MaxDesiatov marked this pull request as ready for review September 13, 2020 20:28
@MaxDesiatov MaxDesiatov requested a review from j-f1 September 13, 2020 20:28
@MaxDesiatov MaxDesiatov added the enhancement New feature or request label Sep 13, 2020
MaxDesiatov and others added 2 commits September 13, 2020 23:07
Co-authored-by: Jed Fox <git@twopointzero.us>
Co-authored-by: Jed Fox <git@twopointzero.us>
@MaxDesiatov MaxDesiatov requested a review from j-f1 September 13, 2020 22:09
Copy link
Member

@j-f1 j-f1 left a comment

Choose a reason for hiding this comment

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

LGTM!

@MaxDesiatov MaxDesiatov merged commit 36f6bdb into master Sep 14, 2020
@MaxDesiatov MaxDesiatov deleted the jsdate branch September 14, 2020 09:48
MaxDesiatov added a commit that referenced this pull request Sep 15, 2020
Depends on #45. This is also a prerequisite for a future `JSPromise` PR with tests.

I intentionally didn't match the JS API in this PR, as a special care is needed to hold a reference to the timer closure and to call `.release()` on it. Here, a user is supposed to hold a reference to a `JSTimer` instance for it to stay valid. The API is also intentionally simple, the timer is started right away, and the only way to invalidate the timer is to bring its reference count to zero.

If you see a better way to manage closures passed to `setTimeout` and `setInterval`, I'd be happy to consider that.

Also, Node.js and browser APIs are slightly different. `setTimeout`/`setInterval` return an object in Node.js, while browsers return a number. Fortunately, `clearTimeout` and `clearInterval` take corresponding types as their arguments, and we can store either as `JSValue`, so we can treat both cases uniformly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants