Commit Graph
734 Commits
Author SHA1 Message Date
Tor Andersson 09b3fcb1e7 Bug 706075: Fix errors in property deletion.
1) Copy "level" from the replacement node.
2) Fix rebalancing by using exact algorithm from AA-tree paper.
2022-11-14 17:43:58 +01:00
Tor Andersson f882c6c5fe Rename private functions to avoid problems with MSYS stdio.h. 2022-11-09 16:01:43 +01:00
Tor Andersson 66d98a5f8e Fix Array.prototype.slice when deleteCount is missing.
Use behavior from newer JS specifications.
2022-11-07 16:25:09 +01:00
Tor Andersson c067e1299c Avoid using the string interning table.
Make a copy of the property name in the same allocation as the property slot.
Make a copy of the internal string value of String objects.
2022-11-07 16:25:09 +01:00
Tor Andersson 0e611cdc0c 1.3.2 patch release for UAF bug fix. 1.3.2 2022-11-07 16:24:56 +01:00
Tor Andersson edb50ad66f Bug 706057: Fix use-after-free in getOwnPropertyDescriptor.
getOwnPropertyDescriptor should create the descriptor object by
using [[DefineOwnProperty]], and not by looking through the prototype
chain where it may invoke getters and setters on the Object.prototype.

If there exists an Object.prototype.get property with a setter, that method is
invoked when it shouldn't. A malicious getter here can delete the property
currently being processed in getOwnPropertyDescriptor, and we'll end up
with a use-after-free bug.

Avoid this problem by following the spec and use js_defproperty rather than
js_setproperty to define own properties in getOwnPropertyDescriptor and
related functions.
2022-11-07 13:44:24 +01:00
Tor Andersson bf4ac94207 Set length of output array Array.prototype.map. 2022-10-26 20:42:29 +02:00
Tor Andersson 69e2767d0a Make a patch release for important iterator bug fix. 1.3.1 2022-10-20 18:19:41 +02:00
Tor Andersson 8b5ba20957 Issue #166: Use special iterator for string and array indices.
Add a scratch buffer to js_State to hold temporary strings.
2022-10-20 18:14:54 +02:00
Ismael Luceno d592c785c0 Enable choice of library version for shell
Default behavior is unchanged, but enables to chose the dynamic version by
passing "libmujs=libmujs.so" to make.
2022-10-17 14:53:27 +02:00
Ismael Luceno 1138515255 Use $(@D) instead of $(dir $@) 2022-10-17 14:53:27 +02:00
Ismael Luceno 4d3165baf5 Bug 705905: Compute VERSION using Make. 2022-10-17 14:52:13 +02:00
Tor Andersson ebf235bfea Bump version number. 1.3.0 2022-10-11 18:18:55 +02:00
Sebastian Rasmussen bbb2c511e5 Avoid freeing buffer twice in case of error. 2022-10-11 18:09:38 +02:00
Tor Andersson 3f71a1c946 Fast path for "simple" arrays.
An array without holes and with only integer properties can be represented
with a "flat" array part that allows for O(1) property access.

If we ever add a non-integer property, create holes in the array,
the whole array is unpacked into a normal string-keyed object.

Also add fast integer indexing to be used on these arrays, before falling
back to converting the integer to a string property lookup.

Use JS_ARRAYLIMIT to restrict size of arrays to avoid integer overflows and out
of memory thrashing.
2022-09-08 13:54:14 +02:00
Tor Andersson ac03b95b18 Bug 705775: Fix double fclose in pretty-printing tool. 2022-08-23 11:16:42 +02:00
Wessel Dankers 1cbf19e7a9 Makefile: fix parallel builds
The parent directory wasn't created when generating the .pc file,
causing it to fail in highly parallel builds.
2022-08-05 13:13:21 +02:00
Tor Andersson 3451b6ca96 Guard state initialization with try to avoid panic in initialization. 2022-06-09 15:53:51 +02:00
Tor Andersson 88f6d86b6c Add js_isbooleanobject and js_isdateobject functions. 2022-05-25 16:33:53 +02:00
Tor Andersson f5b3c703e1 Issue #161: Cope with empty programs in mujs-pp. 2022-05-17 15:57:55 +02:00
Tor Andersson 910acc807c Issue #161: Don't fclose a FILE that is NULL. 2022-05-17 15:53:30 +02:00
Tor Andersson 160ae29578 Issue #162: Check stack overflow during regexp compilation.
Only bother checking during the first compilation pass that counts
the size of the program.
2022-05-17 15:32:16 +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 76e400fb67 Add "console" object to mujs shell. 2022-03-10 17:42:25 +01:00
Tor Andersson 434ae67268 Issue #156: Fix check for duplicate formal parameters when strict.
Duplicate var and function declarations are still allowed.
2022-03-10 17:42:00 +01:00
Tor Andersson 4586e81832 Some minor optimizations to Ap_join. 2022-02-23 14:58:49 +01:00
Avi Halachmi (:avih) a2b628c9cb array join: avoid strcat, speedup from O(N^2) to O(N)
Previously, each iteration (except the 1st) did this amount of calls:
  2x strlen(result-so-far) + 2x strlen(element) + strlen(sep)
Where except one strlen(element) they're implicit inside strcat, and
of sizes which we already know.

Now each iteration does one strlen(element), and no strcat.

The big speedup is avoiding strlen of the result so far (twice) on
each iteration - O(N^2), but the other extra 2x strlen can add up too.

Join of an array of 2000 strings of 80 chars each:
  Windows: before: 80ms, after: 2ms
  Linux:   before: 20ms, after: 2ms
Measured using Date.now()
2022-02-16 12:31:25 +02:00
Tor Andersson dd0a0972b4 Add JS_VERSION_MAJOR/MINOR/PATCH defines to mujs.h
A macro JS_CHECKVERSION(major, minor, patch) can be used to test the
version if your code depends on API features added in a given version.

#if JS_CHECKVERSION(1, 2, 0)
    ... use new API ...
#else
    ... don't use new API ...
#endif
1.2.0
2021-12-08 12:56:12 +01:00
Tor Andersson 1780d0ea73 Bug 704756: Don't trust function.length property!
Calling js_call with n < 0 led to us popping a negative number of items
from the stack, which could make us miss the stack size check.

Sanitize all uses of function.length in Function.prototype.apply and
Function.prototype.bind.
2021-12-08 12:56:12 +01:00
Tor Andersson 70bd7ea61c Minor cleanups. 2021-12-06 16:41:36 +01:00
Tor Andersson 78e56b7854 Bug 704748: Save original object in stack slot for returning after constructor.
The object in the 'this' slot may be overwritten if the constructor converts
it to a primitive value. Save the original object in an explicit stack slot
to keep it safe for returning afterwards.
2021-12-06 16:40:44 +01:00
Tor Andersson eed8a67a49 Bug 704750 and 704751: Save transient js_toobject in stack slot.
Prevent use-after-free if GC is triggered while a js_toobject is held.

This is the same stack clobbering approach used for js_tostring, etc.
2021-12-06 15:42:08 +01:00
李通洲 70a299c76b Build shared libs as dylib on macOS 2021-12-06 11:58:41 +01:00
Tor Andersson df8559e7bd Bug 704749: Clear jump list after patching jump addresses.
Since we can emit a statement multiple times when compiling try/finally
we have to use a new patch list for each instance.
2021-12-06 11:48:32 +01:00
Tor Andersson 90a63426ee Issue #152: Work around GCC compiler bug introduced in 2015.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103052 for details.
2021-11-05 12:59:02 +01:00
Tor Andersson e7ba87678f Silence harmless GCC warnings. 2021-11-05 12:59:02 +01:00
Tor Andersson 3bd234c685 Math.random: Use Lehmer LCG instead of borrowing the hack from musl.
For simplicity of implementation, use the minimal standard generator
described in "Random Number Generators: Good ones are hard to find"
by Park & Miller (ACM 1988, Volume 31, Number 10).
2021-11-05 12:59:02 +01:00
Tor Andersson fe8cac61e3 Add user data to C functions with extended constructor.
Accessible from C with js_currentfunctiondata(J).
2021-11-04 13:08:51 +01:00
Tor Andersson daa2241087 Increase default string limit to 256M. 2021-09-20 14:08:39 +02:00
Tor Andersson b06a5e9b02 Bug 704238: Limit max string lengths.
Check string length when creating strings to not exceed a maximum,
so we avoid integer overflows when concatenating strings.

The string limit must be small enough that we'll not integer overflow
in one concatenation (A + B + 1 must not overflow while still
exceeding the string limit).

Set the limit to 64KB for now.

If we need 2GB strings then we will have to use double or int64 variables
when calculating string lengths.
2021-09-07 18:02:28 +02:00
Tor Andersson 453d28fcc0 Don't use realloc(p, 0) to mean free() in default regex allocator. 2021-08-01 13:58:34 +02:00
Tor Andersson 9dd965b679 Add special error handling for safe 'protected' functions. 2021-07-23 16:23:08 +02:00
Tor Andersson 822061539a Fix leaks if js_try runs out of exception stack space.
Since js_try can throw to its surrounding exception scope if it runs out
of space in the exception stack, we need to make sure to allocate
resources guarded by the try inside the try not outside it.
2021-07-23 12:43:15 +02:00
Tor Andersson a9d88e54af Handle try stack errors like stack overflow errors.
Don't create a new object, because that may cause a cascade of
other errors since we're at the limit.
2021-07-23 11:42:35 +02:00
Tor Andersson 2a1804ea26 Generate new tables for isalpha/toupper/tolower from UnicodeDate.txt 2021-07-20 15:01:53 +02:00
Tor Andersson 1b8aae1d3c Restore missing copyright headers! 2021-07-20 11:24:40 +02:00
Tor Andersson d4a599edea Issue 150: Fix regexp.exec bugs. 2021-07-08 18:13:35 +02:00
Tor Andersson c3ce563aa9 Debug print whether a function is strict. 2021-07-08 18:13:12 +02:00
Tor Andersson c3715ce3db Fix error in Array.prototype.toString(). 1.1.3 2021-06-08 13:41:51 +02:00
Robin Watts 6625d1ea02 Disable const warnings in Visual Studio.
Visual Studio is overzealous (i.e. wrong) in many of its const
warnings.
2021-06-03 12:45:04 +01:00