Commit Graph

77 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
368fe83737 Bug 703461: Escape '/' characters in regular expression source. 2021-02-03 18:11:46 +01: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
gardhr
8c868344b2 Issue 114: Allow compile time limits to be configured. 2019-11-28 11:39:55 +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
5de1f97c52 Set appropriate internal class property of arguments object. 2019-03-18 14:11:34 +01:00
Tor Andersson
914ae72a24 Improve line number tracking in parser.
Associate statements with their initial keyword, and expressions
with their operator token.
2019-03-07 16:08:06 +01:00
Tor Andersson
d04cbf3cc7 Add pretty-printing command line tool. 2018-04-23 18:24:31 +02:00
Tor Andersson
66cf4ccd82 Fix issue #61: Silence misleading indentation warning.
Add NULL check to pexpi to simplify call sites.
2018-01-22 13:37:09 +01:00
Tor Andersson
4792d16f17 Fix 698191: don't call pexp with NULL expression in jsdump.c 2017-07-05 13:37:40 +02:00
Tor Andersson
c1bd06728a Don't truncate error messages. 2017-04-20 00:21:27 +02:00
Tor Andersson
7e00def3c3 Fix 697486: Workaround non-c99 compilers griping about trailing commas. 2017-01-24 14:50:22 +01:00
Tor Andersson
12a66c0a21 Fix printf format warnings.
We can't print function pointer addresses at all, since converting
a function pointer to a void* is forbidden with ANSI C, so we only
print the function name.
2016-12-27 13:49:21 +01:00
Tor Andersson
a5c747f1d4 Fix 697171: missed an operand in the bytecode debugger dump. 2016-10-25 14:08:27 +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
44c0e12d62 strict mode: Check duplicate property names.
Also simplify object initialiser opcode set.
2015-01-14 13:05:12 +01:00
Tor Andersson
0ac4cce8b0 Fix bound checks in jsdump. 2015-01-02 13:39:11 +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
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
8a659b2821 Typedef instruction and check addresses and literals for overflow when emitting code. 2014-10-09 15:08:02 +02:00
Tor Andersson
01d85a4994 Move nelem() macro into jsi.h 2014-02-26 17:35:18 +01:00
Tor Andersson
45e3a31950 Some -pedantic warning fixes.
Drop the use of 'inline' in most places... place some trust in the
compiler.
2014-02-25 01:23:52 +01:00
Tor Andersson
e4a6860f6e More signedness fixes. 2014-02-25 00:22:17 +01:00
Tor Andersson
588fdd18d6 Small cleanups. 2014-02-18 14:38:50 +01:00
Tor Andersson
759d609588 Fixes. 2014-02-12 16:26:47 +01:00
Tor Andersson
be3ed5250c Some cleanups. 2014-02-10 23:51:34 +01:00
Tor Andersson
e45115faee Handle variable shadowing. 2014-02-10 18:54:52 +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
e39e0bdcd1 Separate generic AST_IDENTIFIER and EXP_IDENTIFIER.
Use EXP_IDENTIFIER for the primary expression, and AST_IDENTIFIER for
non-expression uses.
2014-02-10 15:44:40 +01:00
Tor Andersson
06e821df4a Quote strings properly in jsdump. 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
b659aa50e1 Compile ES5 getters and setters. 2014-02-06 13:56:50 +01:00
Tor Andersson
ca3c7e4341 Auto-generate the AST name list. 2014-02-06 13:39:13 +01:00
Tor Andersson
03b291f6e8 K&R style braces in pretty printer.
Good style for Javascript advocates opening braces on the same line,
because there is less danger of intersecting badly with automatic
semicolon insertion.
2014-02-04 16:56:44 +01:00
Tor Andersson
96667d99b1 Use precedence table when pretty-printing syntax. 2014-02-04 15:05:03 +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
34b9fda6f8 Create special initializer opcodes for brevity.
Pop the key and value, don't pop the object.
2014-01-25 00:58:14 +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
546ee1e6c2 Fix switch test-chain stack leftovers. Fix iterator on null and undefined. 2014-01-24 01:48:24 +01:00
Tor Andersson
2b209d3f55 Omit needless setjmp guard over catch block in try/catch statement.
Make the catch opcodes only set the scope chain, and add explicit
try/endtry opcodes for the catch block in try/catch/finally statements.
2014-01-23 17:08:59 +01:00
Tor Andersson
40572172a5 Add 'string' operand versions of get/set/del property opcodes. 2014-01-23 17:08:59 +01:00
Tor Andersson
cf9867c833 Implement try/catch/finally exception handling.
TODO: return/break/continue and finally.
2014-01-22 18:04:11 +01:00
Tor Andersson
f1e1171eef Clean up stack and with/endwith balancing on abrupt exits. 2014-01-22 16:24:45 +01:00
Tor Andersson
5cdcc20936 Simplistic REPL. 2014-01-21 15:15: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
759acbd4dd Add enum-to-string functions for syntax tree and opcodes. 2014-01-20 16:18:49 +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