Commit Graph

745 Commits

Author SHA1 Message Date
Tor Andersson
f190f88ee2 Simplify Makefile. 2023-01-09 16:09:28 +01:00
Tor Andersson
bb6a85a31c Issue #171: Compile sparse array initializers correctly.
Don't initialize the holes with "undefined".
Elided array entries should be skipped altogether.
2023-01-09 14:44:02 +01:00
Tor Andersson
32f3e71169 Issue #171: Fix Object.keys implementation for flat arrays and strings.
Object.keys was not producing keys for the array part of a flat array.
It was also producing an array of numbers rather than strings for
string objects.
2023-01-05 15:48:28 +01:00
Tor Andersson
2e2738b293 Change js_Value to union to avoid some compiler optimization warnings.
Use a union of a union and the padding + type tag, to let the shrstr
object size be the full 16 bytes to avoid compiler complaints about
stepping out of bounds of the array when it optimizes heavily.
2023-01-05 15:32:41 +01:00
Tor Andersson
dd149b98bd Split debug printing of bytecode etc into "pp" tool. 2023-01-05 15:32:41 +01:00
Tor Andersson
d283465777 Regenerate Unicode data from latest UnicodeData.txt 2023-01-04 17:29:22 +01:00
Tor Andersson
278590fcb4 Merge the small private header files into jsi.h 2023-01-04 17:29:22 +01:00
Tor Andersson
71ffe07495 Fix longjmp warnings. 2023-01-04 17:29:22 +01:00
Tor Andersson
88b31f342d Allow holes at the end of a simple array.
Don't unflatten when creating with a = new Array(10).
Don't unflatten when deleting the last element.
2023-01-04 17:28:23 +01:00
Tor Andersson
7d9888b739 Return "undefined" from C functions if no return value is pushed.
Don't return the last input argument in this case.
2023-01-04 17:28:23 +01:00
Tor Andersson
bd037ab7aa Bug 706081: Fix off by one in size calculation. 2022-11-16 21:12:23 +01:00
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