-
Notifications
You must be signed in to change notification settings - Fork 683
Implement Date constructor. #322
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2015 Samsung Electronics Co., Ltd. | ||
// Copyright 2015 University of Szeged. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
assert (Date.length == 7); | ||
assert (Object.prototype.toString.call (Date.prototype) === '[object Date]'); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we also have at least one test case which throws an error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @galpeter, can you give me an example for what kind of test do you want? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LaszloLango, maybe something like this: d = new Date("asasd");
d = new Date({toString: function() { throw new Error("foo"); }}); and of course check if it is a valid value/error was thrown There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @galpeter, what will be the correct error in the first case? It's not throwing an error with the current implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @galpeter, updated the tests, please check. In the first case the primitive value of Date will be |
||
var d; | ||
|
||
try | ||
{ | ||
d = new Date({toString: function() { throw new Error("foo"); }}); | ||
assert (false); | ||
} | ||
catch (e) | ||
{ | ||
assert (e instanceof Error); | ||
assert (e.message === "foo"); | ||
} | ||
|
||
// FIXME: Add assert statements when getters for Date are finished. | ||
d = Date("abcd"); | ||
// assert (isNaN(d.valueOf())); | ||
|
||
d = Date(); | ||
// assert (!isNaN(d.valueOf())); | ||
d = Date("2015-01-01"); | ||
// assert (d.valueOf() == 1420070400000); | ||
|
||
d = Date(1420070400000); | ||
// assert (d.valueOf() == 1420070400000); | ||
|
||
d = Date(2015,0,1,0,0,0,0); | ||
// assert (d.valueOf() == 1420070400000); | ||
|
||
d = new Date(); | ||
// assert (isNaN(d.valueOf())); | ||
|
||
d = new Date("2015-01-01"); | ||
// assert (d.valueOf() == 1420070400000); | ||
|
||
d = new Date(1420070400000); | ||
// assert (d.valueOf() == 1420070400000); | ||
|
||
d = new Date(2015,0,1,0,0,0,0); | ||
// assert (d.valueOf() == 1420070400000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use
ECMA_SET_NON_NULL_POINTER
in the case, asprim_value_num_p
is notNULL
.