Commit Graph

20 Commits

Author SHA1 Message Date
Tor Andersson
2f3d5550a4 Use automatic length in "digits" array in Np_toString.
Hard coding the length to 36 does not match the length of the
initializer, which includes the string zero terminator.

Fixes github issue #48.
2017-09-26 12:50:29 +02:00
Tor Andersson
81388eb40d Add stdint.h MSVC workaround for jsnumber.c also. 2017-08-09 16:10:33 +02:00
Tor Andersson
fea0707d20 Support 'radix' argument for Number.prototype.toString.
The conversion is not very accurate, but should work well enough
for most purposes.
2017-07-20 16:44:40 +02: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
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
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
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
64cd586798 Add static to some functions that should have it. 2014-10-28 12:35:24 +01:00
Tor Andersson
83dd92f085 Add and use dtoa function from plan9/libfmt. 2014-03-18 15:38:35 +01:00
Tor Andersson
375c8a8e08 Use explicit MAX/MIN_VALUE constants.
DBL_MIN is bigger than 5e-324 which is given in the spec.
2014-03-13 14:48:39 +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
b24fe47378 Handle NaN and Infinity in Number.toFixed and friends. 2014-03-06 21:40:37 +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
d59d0e2721 Make argc/undefined checks more resilient. 2014-02-07 15:45:08 +01:00
Tor Andersson
90b54a9eec Add userdata class.
js_newuserdata(J, tag, ptr) creates a userdata object, wrapping the ptr.
It takes the prototype for the new object from the top of the stack, just
like js_newcconstructor does.

js_touserdata(J, tag, idx) extracts the userdata pointer. Throws a
TypeError if the object is not a userdata object with a matching tag.

js_isuserdata(J, tag, idx) checks if a value on the stack is a userdata
object with a matching tag.
2014-01-24 17:11:49 +01:00
Tor Andersson
195816c208 Set property attributes on built-in objects and respect DontEnum. 2014-01-23 17:53:22 +01:00
Tor Andersson
7389d25b1a Fix typos. 2014-01-21 16:36:15 +01:00
Tor Andersson
3a92e13e47 Rename files and move a few functions around. 2014-01-21 13:58:32 +01:00