Commit Graph

59 Commits

Author SHA1 Message Date
Tor Andersson
278590fcb4 Merge the small private header files into jsi.h 2023-01-04 17:29:22 +01:00
Tor Andersson
3451b6ca96 Guard state initialization with try to avoid panic in initialization. 2022-06-09 15:53:51 +02:00
Tor Andersson
db110ea88e Bug 705052: Don't use private STACK/TOP macros in jsstate.c
These convenience macros are defined and used in jsrun.c, and should not
be used in other files.
2022-03-16 11:34:18 +01:00
Tor Andersson
9dd965b679 Add special error handling for safe 'protected' functions. 2021-07-23 16:23:08 +02:00
Tor Andersson
e00c9ba79c Don't call realloc with size=0 to free data.
Newer versions of the C spec and POSIX have changed the behavior of
realloc called with size 0 to be implementation defined.
2021-04-17 21:42:49 +02:00
Tor Andersson
9f34a074eb Revert "Bug 701886: Always create new scope for eval()."
This reverts commit d248b0ce18.
2021-03-04 12:08:42 +01:00
Avi Halachmi (:avih)
b5eccea611 gc: use proportional instead of fixed threshold
The problem with a fixed count value is that it result in varying
degrees of performance and memory impact proportions depending on
the usage pattern of each script.

E.g. if a script keeps using the same 1M objects, then a threshold of
10K objects will result in GC cycles which free only 1% of objects,
which is hugely wasteful in terms of performance. On the other hand,
if a script only uses 100 objects then a threshold of 10K means it
uses 100 times more memory than it actually needs before GC triggers.

Now the threshold is a target memory usage factor (of the minimum
needed memory) which GC tries to aim at. This makes the GC impact
have constant proportions.

The default aims at a memory usage factor of 5, i.e. 80% garbage
and 20% remaining on each GC cycle.

The factor is only a target/goal because the actual overhead is not
known until GC completes. However, most scripts exhibit consistent
enough behavior such that the real overhead is within 10% or less of
the goal even when the usage pattern changes over time.

Within the v8 bench test suite, the actual GC threshold count varies
between ~50K to ~500K, where only one test (raytrace.js) stabilizes on
less than 10K (the previous fixed default) - at about 9K and its score
decreases by ~5%.

The splay.js score increases about x12 fold (or x50 fold from the
previous commit which counts properties), other tests quite a bit
less or none at all, and the overall score increases by nearly 40%.

Also, change the count type from int to unsigned int to get twice the
range. Preferably we should make it even bigger, maybe uint64_t.

For instance the splay.js v8 bench test surpasses million non-garbage
allocations within few seconds (that's why its score increased so much
with a proportional overhead), and the default GC threshold is 5 times
that number.
2020-07-23 12:40:09 +02:00
Tor Andersson
8ee595bee7 Bug 701355: Fix separate compilation issues that have crept in.
We normally build as one compilation unit with "one.c" but we should
still be able to build each source file as a separate compilation unit
if desired.
2020-01-10 11:09:22 +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
Tor Andersson
c695b53a75 Issue 117: Skip first line if it starts with a shebang when loading files.
A file that starts with #! is going to be a syntax error anyway, so we
won't be changing the behavior of any other valid source files with this
fix.
2020-01-02 14:30:43 +01:00
Tor Andersson
14dc9355bd Issue 102: Fix ASAN build when using GCC.
GCC's address sanitizer sets the __SANITIZE_ADDRESS__ macro instead.
2019-06-12 17:23:46 +02:00
Tor Andersson
eeea83a807 Issue 102: Workaround for address-sanitizer default realloc behavior. 2019-06-11 15:48:39 +02:00
Tor Andersson
b9e14e53a0 Revert "Pacify valgrind: it doesn't know realloc(p, 0) is equivalent to free(p)."
This reverts commit 86feee5b7b.
2019-04-05 18:36:26 +02:00
Tor Andersson
d4655ae888 Show system error message in js_loadfile. 2018-09-04 11:27:34 +02:00
Tor Andersson
dcb3f03e90 Inherit strictness from invoking function in eval. 2018-09-03 16:10:02 +02:00
Tor Andersson
b46ee8d829 Add more js_tryxxx conversion functions. 2018-04-27 16:59:35 +02: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
134134e899 Don't do unprotected js_tostring calls in js_dostring/file.
Since js_tostring can invoke a toString method, we should guard against
uncaught exceptions when trying to convert the error object to a string.

Add a public function, js_trystring that does a "safe" conversion
to a string.
2017-05-09 14:47:19 +02:00
Tor Andersson
f18f2c0c99 Don't force 'this' to be the global object in js_dostring/dofile.
Set it to 'undefined' so the behavior will be according to strictness.
2017-05-09 13:52:11 +02:00
Tor Andersson
8a26e20943 Compile functions with per-function strictness.
Recognize 'use strict' pragma.
Move strictness checks into compiler from parser.
2017-04-17 23:27:00 +02:00
Tor Andersson
86feee5b7b Pacify valgrind: it doesn't know realloc(p, 0) is equivalent to free(p). 2016-12-27 13:49:20 +01: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
1b5cc3a082 Improve debugging stack trace print-out. 2016-04-28 13:33:58 +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
0b9d3be3d0 Remove 'report' argument from js_dostring. 2015-12-16 11:49:52 +01:00
Tor Andersson
ffa8de1fc9 strict mode: eval code is evaluated in its own scope.
Create a closure for eval code instead of letting it abuse the function's
own scope (as is done by setting scope to NULL).
2015-01-14 13:05:12 +01:00
Tor Andersson
8f790df9e5 Add strict mode flag to constructor. 2015-01-14 13:04:46 +01:00
Tor Andersson
b005928523 Add paranoid asserts to check js_Value struct layout and alignment. 2015-01-05 19:59:00 +01:00
Tor Andersson
5e3e9fdde4 Check error for all fseek/ftell calls. 2015-01-05 13:03:30 +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
84faaff8ff Add user context pointer and flag argument to js_State constructor. 2014-11-29 16:12:30 +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
a381ba1963 Change error message prefix to 'mujs:'. 2014-09-25 14:19:31 +02:00
Tor Andersson
1f137b8e48 Improve MuJS interactive shell.
Add read/readline/write/quit functions.
Add CommonJS style modules with require function.
2014-07-31 16:52:26 +02:00
Tor Andersson
41693fa6bd Add protected functions to load and call code.
So that clients don't need to know about js_try.
2014-03-06 22:22:25 +01:00
Tor Andersson
222ae8067b Add user customisable panic function.
Intended to let the user longjmp to their own error recovery, if an
error occurs in an unprotected call.

Protected calls so far are only js_newstate, js_dofile and js_dostring.
2014-03-06 22:00:39 +01: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
e766ed71f8 Always open files in binary mode.
Fix for win32 where CRLF and text mode wreaks havoc with fseek/ftell.
2014-02-25 13:44:53 +01:00
Tor Andersson
d5b83c3bf2 Implement Function constructor. 2014-02-07 11:44:39 +01:00
Tor Andersson
7159bcd774 Make sure to pop error object when we catch them at the top level dofile call. 2014-01-25 15:00:29 +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
5cdcc20936 Simplistic REPL. 2014-01-21 15:15:22 +01:00
Tor Andersson
3a92e13e47 Rename files and move a few functions around. 2014-01-21 13:58:32 +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
8aa0627557 Add Error builtin objects and exception stack. 2014-01-20 00:13:47 +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
Tor Andersson
f487a7db10 Set prototype internal property when creating objects. 2014-01-17 19:41:41 +01:00