Commit Graph

31 Commits

Author SHA1 Message Date
Tor Andersson
b4297c0dec Fix 699557: Pause garbage collector during Ap_sort.
The temporary array we use for sorting cannot be seen by the GC, and that
violates the constraint that all js_Value values must always be reachable
from the stack or global environment.

Temporarily turning off the GC will let us use the temporary array for
fast sorting using qsort(), without tripping over this violation.
2018-07-25 12:00:33 +02:00
Sebastian Rasmussen
e8dad5a39e Make js_freestate() not segfault on NULL argument. 2017-07-05 02:45:15 +08:00
Tor Andersson
fb32b5c893 Add a js_setreport callback function to report warnings.
Don't print error and warning messages directly to stderr.
2017-05-16 12:03:38 +02:00
Tor Andersson
2b4d05a575 Revert 'Maintain order of property enumeration by keeping a linked list.'
Reduce memory use per property by not keeping the properties in two
parallel data structures. Maintaining the order of insertion is not
required by the spec, and is not a very useful feature.
2017-05-09 13:52:11 +02:00
Tor Andersson
fd003eceda Fix 697381: check allocation when compiling regular expressions.
Also use allocator callback function.
2016-12-02 14:58:17 -05:00
Tor Andersson
5c337af4b3 Fix bug 697142: Stale string pointer stored in regexp object.
Make sure to make a copy of the source pattern string.
A case we missed when adding short and memory strings to the runtime.
The code assumed all strings passed to it were either literal or interned.
2016-09-21 16:04:14 +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
eed7619158 Rename our internal regex.h to not collide with system regex.h. 2015-08-14 12:05:09 +02:00
Tor Andersson
c6d17c7f00 Add finalize callback to userdata objects.
When a userdata object is garbage collected, we should invoke a callback
to client code to let it know that the associated userdata pointer is no
longer in use.
2015-01-14 13:04:15 +01:00
Tor Andersson
720aec8cd4 Fix memory leak when freeing js_State. 2015-01-02 13:38:19 +01:00
Tor Andersson
6538308087 Add short strings (with data embedded in js_Value).
Allows js_tostring to avoid either interning strings converted from
numbers or creating lots of garbage collected strings.
2014-11-29 16:01:36 +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
aba272ac95 Fix bug where some environment records were not marked by GC.
Environments when calling a function were saved in a local variable.
Therefore the garbage collector did not see them in its list of roots
to follow, resulting in environments being freed while still in use.
2014-09-24 16:02:04 +02:00
Tor Andersson
abd59674cc Allow custom allocator. 2014-02-28 17:14:11 +01:00
Tor Andersson
67b33c5a86 Handle malloc failure by throwing exceptions. 2014-02-28 14:24:13 +01:00
Tor Andersson
e4a6860f6e More signedness fixes. 2014-02-25 00:22:17 +01:00
Tor Andersson
2ac601d07e Prepare for regular expression library.
Wrap the posix regex calls with the desired API.
2014-02-20 15:07:37 +01:00
Tor Andersson
68862386d8 Implement lightweight functions.
When a function does not use eval, arguments, with and has no inner
functions it does not need a closure. We can call it without creating
a variable object if we store local variables on the stack instead.
2014-02-10 18:00:13 +01:00
Tor Andersson
d35cef7df9 Implement getters and setters.
Does not work properly for setters on inherited properties.
2014-02-06 16:03:44 +01:00
Tor Andersson
6c37f967b4 Use POSIX regcomp/regexec.
A temporary measure, since POSIX regexes (a) don't have the same
syntax as javascript's regexes, and (b) don't work on UTF-8 (unless
the setlocale crap is configured correctly, and the implementation
supports it), and (c) doesn't work on windows.
2014-01-30 16:53:00 +01:00
Tor Andersson
8ade82bdfa Maintain order of property enumeration by keeping a linked list.
Match behaviour with other JS implementations.
2014-01-28 13:58:19 +01:00
Tor Andersson
fac3f501e4 Add js_hasproperty function. 2014-01-25 22:57:39 +01:00
Tor Andersson
3cef8607dc Add a registry for stashing hidden javascript objects from C code. 2014-01-24 16:17:43 +01:00
Tor Andersson
7a45bb4363 Free iterator nodes as they are being iterated over. 2014-01-23 23:04:59 +01:00
Tor Andersson
0fd3f364ec Add iterator object class for internal use in for-in loops.
Flatten all enumerable properties in object prototype chain
into a linked list to enumerate.
2014-01-23 10:07:22 +01:00
Tor Andersson
b262cc3673 Rename many jsR functions to jsV.
Danger! jsV work on values internally without the stack.

Also rearrange how C-constructors are created.
2014-01-20 17:44:56 +01:00
Tor Andersson
40a12fba0d Split header into js.h public and jsi.h private. Start cleaning up
private function prefixes.
2014-01-20 16:13:09 +01:00
Tor Andersson
95ac24c7cf Put js_Object contents in a union. 2014-01-19 13:29:38 +01:00
Tor Andersson
24f48308ce Support 'typeof' operator. 2014-01-18 17:38:40 +01:00
Tor Andersson
704d16409f Collect garbage. 2014-01-18 00:02:04 +01:00
Tor Andersson
96ca91ec7c Garbage collector lists. 2014-01-17 23:02:14 +01:00