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

Test that Date.prototype.toString throws for non-Date receiver #924

Merged
merged 3 commits into from
Jun 29, 2017

Conversation

littledan
Copy link
Member

Pending discussion of tc39/ecma262#849. Not ready to merge yet!

Test passes in V8.

Copy link
Member

@leobalter leobalter left a comment

Choose a reason for hiding this comment

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

The tests are fine, I just found some nitpicks.

One thing I'm missing from Date#toString is a test that confirms the type of the returned value after a successful call. This can be done in a follow up PR, anyway.

// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: #sec-date.prototype.tostring
Copy link
Member

Choose a reason for hiding this comment

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

we need to remove the # here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@@ -0,0 +1,12 @@
// Copyright (C) 2017 V8 project authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

nitpick for consistency: the V8 project authors

- // Copyright (C) 2017 V8 project authors. All rights reserved.
+ // Copyright (C) 2017 the V8 project authors. All rights reserved.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

/*---
esid: #sec-date.prototype.tostring
description: Date.prototype.toString throws a TypeError on non-Date receivers
---*/
Copy link
Member

Choose a reason for hiding this comment

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

The info tag is being valuable for reviews (even after the PR phase). If you don't mind, I would like to add the following:

+info: |
+  Date.prototype.toString ( )
+
+  1. Let tv be ? thisTimeValue(this value).

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

description: Date.prototype.toString throws a TypeError on non-Date receivers
---*/

assert.throws(TypeError, () => Date.prototype.toString());
Copy link
Member

Choose a reason for hiding this comment

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

good catch! I hope we never give Date.prototype a [[DateValue]] internal slot anymore, even worse with a NaN value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interestingly, this is the only case that ChakraCore fails.

assert.throws(TypeError, () => Date.prototype.toString());
assert.throws(TypeError, () => Date.prototype.toString.call(undefined));
assert.throws(TypeError, () => Date.prototype.toString.call(0));
assert.throws(TypeError, () => Date.prototype.toString.call({}));
Copy link
Member

Choose a reason for hiding this comment

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

I would like to suggest 2 special cases we can add in here:

Date.prototype.toString.call("Tue Mar 21 2017 12:16:43 GMT-0400 (EDT)")
Date.prototype.toString.call(1490113011493)

It seems silly but they're still parseable values.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

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

Successfully merging this pull request may close these issues.

2 participants