Commit Graph

31 Commits

Author SHA1 Message Date
Tor Andersson
d11c71072e Bug 703458: Handle NaN in Date accessors. 2021-02-03 17:07:28 +01:00
Tor Andersson
6a9eedea88 Fix type error in jsdate.js InLeapYear that led to bad calculations.
InLeapYear was passing the time in millis as an integer, which lead to
overflow errors and wrong results.
2020-08-24 14:27:39 +02:00
Tor Andersson
fe71080c59 Bug 698496: Handle leap years correctly in the Date constructor.
InLeapYear expects the parameter to be a timestamp and not a year.
Use DaysInYear instead.

Thanks to Robert Rosendahl for spotting this.
2020-01-10 11:22:09 +01:00
isRyven
d9f555652a Fix date setMonth and setUTCMonth processed wrong optional argument 2020-01-02 12:42:09 +01:00
Tor Andersson
ffe0ca7d7f Issue 95: Improve error message when trying to call a non-callable. 2019-03-18 14:11:34 +01:00
Konstantin Baladurin
dbc0931a5c Fix Date.prototype.setHours 2018-07-19 12:21:43 +02:00
Tor Andersson
2cb57c6e71 Fix issue #56: MacOS X not detected as a Unix for gettimeofday().
Add ifdef check for __APPLE__ since MacOS X doesn't define __unix__.
2017-12-11 14:15:01 +01:00
Tor Andersson
872cef584d Bug 697700: Fix typo and add more range checks in parseDateTime. 2017-03-29 15:56:39 +02:00
Tor Andersson
8f62ea10a0 Fix 697496: Check NAN before accessing array in MakeDay(). 2017-01-24 14:52:27 +01:00
Tor Andersson
f32bcea8f4 Avoid C++ comments. 2017-01-24 14:48:14 +01:00
Tor Andersson
a2fcfd69fe Define built-in functions with the full name.
Improves error messages and stack traces.
2016-04-28 12:57:22 +02:00
Tor Andersson
3e3c382a0c Avoid using 'unsigned int'.
Mixing signed and unsigned ints is just a plain headache.
2016-04-27 16:26:00 +02:00
Tor Andersson
c90c32326e Fix bugs introduced when moving from argc to js_gettop.
The 'length' field of a function is used to fill in missing arguments
with undefined; this does not mesh well with functions that query for
missing arguments using js_gettop. Set their lengths to 0 instead.
2016-04-15 12:18:34 +02:00
Tor Andersson
78ed7e6a99 Use fabs rather than integer abs for taking absolute value of floats. 2015-09-14 11:57:51 +02:00
Tor Andersson
031513b25b Add stack traces to error objects.
Revert 'add context and flag argument to js_newstate' commit.

The context argument just adds clutter. The flag which was intended
for JS_DEBUG and/or JS_STRICT shouldn't be necessary.

js_newcfunction and js_newcconstructor need an extra argument, the
name of the function to use in stack traces.
2014-12-03 01:18:21 +01:00
Tor Andersson
4eae3ec10c Make js_toprimitive (and by consequence js_tonumber/string/...) in-place.
Any coercion between types may overwrite the stack slot with the coerced
value. This is usually not a problem, but if you need to preserve the
original value, you should copy it to another stack slot before running
any functions that may coerce the type (anything involving ToPrimitive).

This change lets us avoid interning the result of toString().

If we later add short strings (embedded in js_Value and js_Property
structs) then we can also avoid creating a garbage collected string or
interning the result of js_tostring on a number.
2014-11-29 13:59:09 +01:00
Tor Andersson
0cbd5326f2 Garbage collect (some) strings.
Separate literal/interned and garbage collected string types in js_Value.

js_pushintern/js_tointern are convenience functions to push/pop strings and
automatically intern them (so that the string pointers are guaranteed to be
stable).

js_pushliteral should push stable strings (either interned or actual literals).

js_pushstring will copy the string into garbage collected memory.

The pointer returned by js_tostring is guaranteed to be stable only for as long as
the stack slot it came from remains untouched.

Some uses will always cause a string to be interned:

 * Using it as a property name.
 * Wrapping it in a new String() object.
 * Strings returned by toString().
	ToPrimitive must not clobber the stack, so the result has to be unrooted.
 * Numbers converted to strings (by js_tostring)
	Likewise, we have nowhere to store the temporary string here.
	Passing in a scratch buffer to js_tostring could help this problem.
	Mostly an issue with array accesses (OP_GETPROP, etc) so an auxiliary
	function and we don't have to clutter the API needlessly.
2014-11-28 17:10:08 +01:00
Tor Andersson
6afabf445c Fix ifdef order to allow building jsdate on cygwin. 2014-11-17 15:31:14 +01:00
Tor Andersson
5dbd120154 Fix several constructors.
"is/was supplied/specified" is different from "is not undefined" which
is used in most of the spec.
2014-03-13 13:36:29 +01:00
Tor Andersson
d366e4b852 Don't pass argc to functions. Use js_gettop instead. 2014-03-12 16:40:48 +01:00
Tor Andersson
d608b2f9aa Check bounds of date elements in Date.parse(). 2014-03-04 00:24:00 +01:00
Tor Andersson
9eb0a65fcf Improve date parsing.
Handle partial year specifications, as in the spec.

Date part:
	YYYY
	YYYY-MM
	YYYY-MM-DD

Optional time part:
	THH:mm
	THH:mm:ss
	THH:mm:ss.sss

Optional timezone part:
	Z
	+HH:mm
	-HH:mm
2014-03-03 23:54:26 +01:00
Tor Andersson
e4cafa6d26 Always use ISO 8601 formats for date string formatting.
Simplifies the date formatting code and makes it possible
to round-trip Date.parse(new Date().toString()).
2014-03-03 23:09:44 +01:00
Tor Andersson
5961e39073 Fix fmod use with negative (pre-1970) times. 2014-03-03 19:14:35 +01:00
Tor Andersson
5b567dd5cf Make date formatting and parsing re-entrant and libc independent.
localtime is not re-entrant, and doesn't work with negative (pre-1970)
time stamps on windows. Replace with our own simplified variant.

Parse date string format manually rather than using scanf.
Only accept ISO 8601 format.
2014-03-03 18:30:48 +01:00
Tor Andersson
b4223dfb47 Use gettimeofday/_ftime if available for more accurate times. 2014-02-28 20:21:31 +01:00
Tor Andersson
70b0d8b902 Change C functions to not have a return value.
They should always push a return value on the JS stack.
2014-02-25 00:56:33 +01:00
Tor Andersson
c7e9ab0b05 Fix signed/unsigned comparison warnings. 2014-02-24 23:55:58 +01:00
Tor Andersson
0ddbab57c4 Date.prototype.toJSON(). 2014-02-10 13:41:28 +01:00
Tor Andersson
c1fd029e45 Fix whitespace. 2014-01-28 23:31:19 +01:00
Tor Andersson
de3aa34aed Add Date class.
Missing setXXX functions.
2014-01-28 00:43:32 +01:00