Commit Graph

162 Commits

Author SHA1 Message Date
Tor Andersson
0c03f9c057 Add missing break statement. 2019-03-29 19:40:44 +01:00
Tor Andersson
bb65f18fcc Set 'lightweight' and 'arguments' during compile pass.
Avoid doing a separate analysis pass by using the same bytecode for both
lightweight and non-lightweight functions.
2019-03-22 14:00:20 +01:00
Tor Andersson
f5de9d4d2e Remove line opcode in favor of storing the line for each instruction. 2019-03-22 14:00:20 +01:00
Tor Andersson
20d0fa04df Simplify opcodes: numbers and integer constants. 2019-03-22 14:00:20 +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
Tor Andersson
5de1f97c52 Set appropriate internal class property of arguments object. 2019-03-18 14:11:34 +01:00
Tor Andersson
6a592abfc4 Use emitarg instead of emitraw to emit opcode arguments. 2019-03-07 16:08:06 +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
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
Tor Andersson
40b73014d9 Fix 699549: Integer overflow in Array.prototype.sort().
Check size calculation for overflow before allocating memory buffer.
2018-07-23 11:30:22 +02:00
Tor Andersson
49271d3cf2 Add js_iserror function. 2018-07-03 12:00:57 +02:00
Tor Andersson
be0685e89e Optimize js_isarrayindex.
Avoid floating point number conversions.
2017-05-23 13:15:11 +02:00
Tor Andersson
2e7550e718 Fix bounds checks for string object array accesses. 2017-04-21 11:04:43 +02:00
Tor Andersson
1062e70c86 Track strictness during runtime based on 'use strict' pragma. 2017-04-17 23:27:00 +02:00
Tor Andersson
75cab70afd Handle undefined this at the OP_THIS level.
Don't distinguish lax mode code by pushing the global object.
Always push undefined and let the calling code promote an undefined
this to the global object instead.
2017-04-17 14:57:38 +02:00
Tor Andersson
9e9f168cbb Add strictness check when setting a property that only has a getter. 2017-04-17 14:55:12 +02:00
Tor Andersson
4006739a28 Fix 697497: Ensure array length is positive.
As a side effect when changing to using regular integers (and avoid the
nightmare of mixing signed and unsigned) we accidentally allowed negative
array lengths.
2017-01-24 14:52:27 +01:00
Tor Andersson
77ab465f1c Fix 697401: Error when dropping extra arguments to lightweight functions. 2017-01-12 14:47:01 +01: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
a4158ae6ff Fix call stack overflow triggering off-by-one too late.
Thanks to katlogic <kat@lua.cz> for spotting the error.
2016-07-04 15:19:08 +02:00
Tor Andersson
1b5cc3a082 Improve debugging stack trace print-out. 2016-04-28 13:33:58 +02:00
Tor Andersson
4b68d52351 Add js_iscoercible function. 2016-04-28 12:48:09 +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
2db68ab80f Chain if-else statements in has/put/delproperty. 2016-03-01 21:51:38 +01:00
Tor Andersson
0fd82b60cf Make js_try, js_savetry and js_endtry public functions/macros. 2016-01-18 13:34: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
d800b59f0f Clean up stack on errors in js_pcall and js_pconstruct.
Exactly one value will remain on the stack after js_pcall: either
the return value or the error object.
2016-01-06 13:43:59 +01:00
Tor Andersson
c1c637b739 Implement js_replace.
js_replace moves the value at top of the stack to the specified
stack slot.
2015-12-17 11:24:40 +01:00
Tor Andersson
d9ed73fd71 strict mode: 'this' is undefined for normal function calls.
Global (script) code still uses the global object as 'this'.
Eval still uses the calling context's 'this'.
2015-01-14 13:05:12 +01:00
Tor Andersson
44c0e12d62 strict mode: Check duplicate property names.
Also simplify object initialiser opcode set.
2015-01-14 13:05:12 +01:00
Tor Andersson
91dc20d3e3 strict mode: Errors on read-only and non-configurable properties. 2015-01-14 13:05:12 +01:00
Tor Andersson
b51b05b216 strict mode: No automatic creation of global variables. 2015-01-14 13:05:12 +01:00
Tor Andersson
7bdfc5e2db strict mode: No arguments.callee property.
Strictly speaking, access to arguments.callee and arguments.caller
should throw a TypeError, but that's a bit overkill.
2015-01-14 13:05:12 +01:00
Tor Andersson
40dd4a252f Add eval op-code to implement proper 'this' binding for eval code. 2015-01-08 15:55:57 +01:00
Tor Andersson
e673ae661f Clean up some error messages. 2015-01-08 15:25:04 +01:00
Tor Andersson
cb6facdf9c Remove redundant type checking in iterator opcode. 2015-01-08 15:18:19 +01:00
Tor Andersson
9281c68b68 Use offsetof instead of hardcoded short string length. 2015-01-05 17:32:09 +01:00
Tor Andersson
3ceaeb153d Use manual loop instead of memcpy/strcpy when creating short strings.
Due to our slightly icky struct layout, some versions of gcc barf and
generate crashing code when using strcpy and memcpy. I suspect gcc tries
to do some weird optimizations that fail because we intentionally
overwrite the 'pad' data in the js_Value struct for short strings.
2015-01-05 17:09:46 +01:00
Tor Andersson
15ef29e7c0 Use memcpy instead of strcpy when copying short strings. 2015-01-02 13:47:56 +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
8c566e168c Fix bug in js_pushlstring. 2014-11-29 20:00:53 +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
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
3fe6635426 Differentiate between "global code" and "eval code" scripts.
Add a separate js_loadeval for "eval code" scripts, and let
js_do/loadstring create "global code" scripts.

js_newscript called with the NULL scope is equivalent to 'eval code'.
js_newscript called with the J->GE scape is equivalent to 'global code'.
js_newfunction is created with the lexical scope, i.e. 'function code'.
2014-10-27 16:12:16 +01:00
Tor Andersson
790103815f Add public property iterator function. 2014-10-16 13:50:44 +02:00
Tor Andersson
8a659b2821 Typedef instruction and check addresses and literals for overflow when emitting code. 2014-10-09 15:08:02 +02:00