Commit Graph

48 Commits

Author SHA1 Message Date
Tor Andersson
9f34a074eb Revert "Bug 701886: Always create new scope for eval()."
This reverts commit d248b0ce18.
2021-03-04 12:08:42 +01:00
Tor Andersson
331c5ecbac Issue 133: Eliminate recursion in GC scanning phase.
Use a queue instead of recursion to scan reachable objects.
2020-05-27 12:32:32 +02:00
Tor Andersson
d248b0ce18 Bug 701886: Always create new scope for eval().
Distinguish eval code from script code.
2020-01-02 14:37:05 +01:00
Tor Andersson
5de1f97c52 Set appropriate internal class property of arguments object. 2019-03-18 14:11:34 +01:00
Tor Andersson
bd9920c571 Handle null/undefined in OP_NEXTITER rather than creating empty iterator.
Only create an iterator for coercible types in OP_ITERATOR, and then
detect the lack of a real iterator in OP_NEXTITER.
Thus we don't need to allocate and push an empty iterator object for
these cases.
2019-01-07 13:28:22 +01:00
Tor Andersson
7be32a0f5f Bug 700441: Handle null and undefined expressions in for-in statement. 2019-01-04 10:58:30 +01: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
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
aba6644234 Add delete callback to userdata objects. 2016-03-01 21:52:00 +01:00
Tor Andersson
4e6c74b551 Add userdata has/put callbacks for custom properties.
This goes beyond defining accessors, and allows capturing all property
accesses. With these callbacks, things like typed arrays can be
implemented.
2016-01-11 17:02:43 +01: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
9281c68b68 Use offsetof instead of hardcoded short string length. 2015-01-05 17:32:09 +01: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
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
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
7bb55ad356 Add js_itoa for faster conversion of unsigned int to string. 2014-11-29 12:39:57 +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
9f181651fb Track array sparseness to be smarter in jsV_resizearray. 2014-11-07 16:00:45 +01:00
Tor Andersson
a9e6b4cd01 Fix bug in maintaining property enumeration list.
The tail pointer in the linked list head was mismanaged, leading
to using free memory when properties are inserted after deleting
a property such that the tail points to the deleted node.
2014-11-01 13:03:40 +01:00
Tor Andersson
93cc0584df Add portable strtod implementation.
Ignore locale problems with strtod.
2014-09-01 16:56:38 +02:00
Tor Andersson
8f7c649985 Move ToPrimitive hint flags into jsvalue.h 2014-06-11 12:58:40 +02:00
Tor Andersson
83dd92f085 Add and use dtoa function from plan9/libfmt. 2014-03-18 15:38:35 +01:00
Tor Andersson
dc386479da Add and use js_touint16. 2014-03-06 22:33:37 +01:00
Tor Andersson
598de57d76 Fix ToNumber from strings and parseInt and parseFloat.
Follow the spec more strictly, and don't rely on strtod's grammar.

GNU libc strtod accepts 0x prefixes, INF, INFINITY and much more which
we don't want, so pre-filter the string we pass to strtod.
2014-02-27 13:49:22 +01:00
Tor Andersson
c7e9ab0b05 Fix signed/unsigned comparison warnings. 2014-02-24 23:55:58 +01:00
Tor Andersson
588fdd18d6 Small cleanups. 2014-02-18 14:38:50 +01:00
Tor Andersson
b8aa34d919 JSON skeleton. 2014-02-10 13:41:28 +01:00
Tor Andersson
b219aef882 Add virtual string array index properties for characters. 2014-02-07 16:40:22 +01:00
Tor Andersson
411b8b5b9c Use length property of cfunctions to make sure we have at least N args.
So we don't get temporary stack values that shadow undefined arguments.
2014-02-07 14:24:45 +01:00
Tor Andersson
979c7bc1bd Implement extensible object attribute. 2014-02-07 10:57:52 +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
e17dcbba7c Encapsulate all regexp state in js_Regexp struct. 2014-02-05 13:57:44 +01:00
Tor Andersson
f10f1f06c8 aoeu 2014-02-05 13:22:41 +01:00
Tor Andersson
8e10640e9e Add RegExp class (with no actual regex implementation hooked up). 2014-01-28 17:19:09 +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
9103b4f4de Add 'own' argument to iterator.
If set, it will only create an iterator for own properties.
If unset, it will iterate over all properties in the prototype
chain.
2014-01-25 17:46:43 +01:00
Tor Andersson
f66986d3d8 Implement a smarter deletion of properties when resizing an array. 2014-01-25 17:40:37 +01:00
Tor Andersson
ac6cc9f7b7 Automagically update Array length property. 2014-01-24 22:33:07 +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
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
a65416046c Make instanceof a public function. 2014-01-23 09:13:39 +01:00
Tor Andersson
c55b4e18bc Implement instanceof expression. 2014-01-23 00:16:21 +01:00
Tor Andersson
a6a5bd7994 Add prefixes and remove duplicate functions.
Allows compiling all sources as one big blob.
2014-01-22 03:14:37 +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
f77a6e7e8e Implement value stack and use it in the interpreter.
We can now run simple programs that don't use function calls.
2014-01-14 18:17:06 +01:00
Tor Andersson
a4cc139e1c Add js_Object with js_Property binary search tree.
Use object to represent a variable record and implement variable
loading and storing in the interpreter.
2014-01-13 21:32:33 +01:00