Commit Graph

680 Commits

Author SHA1 Message Date
Avi Halachmi (:avih)
292415b625 test262: improve quoting, handle spaces at files/arguments
- Don't coalesce IFS nor interpret backslash at the output of `find'.
- The argument of -m and -l can now be arbitrary.
- The TC39 test262 path and/or files can now be arbitrary.

Previously any of those broke on IFS chars at the value.
Now the only issue is (unlikely) newline at filenames - from `find'.
2021-04-20 00:14:17 +02:00
Avi Halachmi (:avih)
d5f6b3b66e test262: remove incorrect shift
It remained accidentally when the script changed from custom
arguments parsing to using getopts.
2021-04-20 00:14:17 +02:00
Avi Halachmi (:avih)
857ffd39b0 tools: add test262 and harness
tools: add test262-harness.js to run a single test

Usage: mujs <this-file> -- [-f] [-l file1.js -l ...] suit-root test-file
-f: print full paths/stacktraces if possible
-l: load a js file after the harness and before the test (to override things)

tools: add test-262 launcher

It can run the entire suite or just a sub-folder or one file, and by
default it skips tests which are known to crash/hang.

test262-harness: @negative: match regex if exists

Some @negative tests add a regex which needs to match the error.
This wasn't tested, and now it is. This results in few more failures.

The actual string to compare is not documented, but it appears to be
err.message for plain Error(..) where the message is always compared
to "NotEarlyError" (equals/different), and err.name for anything else.

test262 launcher: minor improvements and custom mujs path

- Use getopts instead of custom arguments parsing
- Support -m path/to/mujs
- Change -s (skip bad tests) to -b, and add -B to run only bad tests
  (useful when trying to update the known bad tests list).
- Combine stderr to stdout on a per-test basis (mujs function warnings)
- Exit with error if failures > 0

test262: remove 5 tests which no longer crash/hang

test262 and harness: support -s to print failed source

test262 and harness: convert spaces to tabs
2021-04-19 12:57:43 +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
Connor Nelson
6d1404397f Prevent negative table indexing in js_strtol 1.1.1 2021-04-12 19:22:04 -07:00
Connor Nelson
f93d24539b Fix js_strtol 2021-03-27 11:12:05 +01:00
Sebastian Rasmussen
72e95a48e3 Add user.make for persistent custom settings. 2021-03-26 16:41:43 +01:00
Sebastian Rasmussen
d1160c7933 Improve gitignore. 2021-03-26 16:41:43 +01:00
Tor Andersson
3d29cd2f2f Issue #135: Expose type of value as an enum with js_type().
This matches the values used by the 'typeof' operator.
2021-03-26 15:47:35 +01:00
Tor Andersson
33ffe6efeb Inline doubles and interned string pointers in the byte code.
Avoid linearly searched per function string and number tables.
2021-03-26 14:35:14 +01:00
Tor Andersson
06a6f9fb11 Issue #120: Optimize array construction bytecode.
Use a specialized array initializer that pushes values to the end
of the array instead of using a lot of setprop. This avoids the need
to create a lot of number constants for the array indices.
2021-03-26 12:05:35 +01:00
Tor Andersson
4c7f6be433 Issue #139: Parse integers with floats to support large numbers.
Add a js_strtol which parses integers with bases 2..36 using simple
double precision arithmetic with no overflow checks.
2021-03-25 14:43:07 +01:00
Tor Andersson
1616c18484 Some Makefile tweaks.
Change default optimization flag to -O2.

Use XCFLAGS and XCPPFLAGS to add to the definitions:

  make XCPPFLAGS=-I/foo/bar XCFLAGS=-mfoo-bar

Set CFLAGS on the make command line if you want to override completely:

  make CFLAGS="-O3 -m32"

If you want to override them with the system environment variables:

  make CFLAGS="$CFLAGS"
2021-03-25 14:43:07 +01:00
isRyven
625542e463 fix split doesn't convert context to string if no argument is passed 2021-03-24 15:43:04 +01:00
Tor Andersson
7ebc570d01 regexp: Dump character class definitions in -DTEST build. 2021-03-24 15:35:39 +01:00
Connor Nelson
94000c669a Fix crash when length is negative 2021-03-23 12:47:49 -07:00
Tor Andersson
364acef42e Bug 703670: Throw when redefining non-configurable/readonly properties.
Add an explicit 'throw' argument to jsR_defproperty to throw in
non-strict mode too.
2021-03-10 18:10:34 +01:00
Tor Andersson
c9d05aabba Bug 703675: RegExp.prototype should be a regular expression object. 2021-03-10 17:29:50 +01:00
Tor Andersson
a34fdf2af8 Bug 701886: Don't redefine/reset existing vars in script code.
If a var is already declared in the same scope, don't redeclare it.
Should fix issues with "var" used in eval() code.
2021-03-04 12:20:46 +01: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
Tor Andersson
80e222d91d Support externally set CFLAGS, CPPFLAGS, and LDFLAGS. 1.1.0 2021-02-04 10:02:18 +01:00
Tor Andersson
368fe83737 Bug 703461: Escape '/' characters in regular expression source. 2021-02-03 18:11:46 +01:00
Tor Andersson
ccf7fa6c10 Bug 703457: Fix typo in uriMark definition used by encodeURI(Component).
Silly copy & paste error.
2021-02-03 17:44:23 +01:00
Tor Andersson
2eb4fd2272 Bug 703459: Handle undefined argument to Error constructor. 2021-02-03 17:31:50 +01:00
Tor Andersson
d11c71072e Bug 703458: Handle NaN in Date accessors. 2021-02-03 17:07:28 +01:00
Tor Andersson
d3a99000e0 Bug 703371: Add '-' to list of quoted escape characters in regex parser. 2021-01-25 17:53:29 +01:00
Tor Andersson
789f30b587 Bug 703376: Don't allow creating new properties on transient objects. 2021-01-25 14:38:15 +01:00
Tor Andersson
a09d8697db Bug 697702: Add workaround for MSVC not having unistd.h 2021-01-12 14:54:50 +01:00
Tor Andersson
6871e5b41c Issue #141: Add missing end-of-string checks in regexp lexer. 1.0.9 2020-09-08 10:50:17 +02:00
Tor Andersson
6a9eedea88 Fix type error in jsdate.js InLeapYear that led to bad calculations.
InLeapYear was passing the time in millis as an integer, which lead to
overflow errors and wrong results.
1.0.8
2020-08-24 14:27:39 +02: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
Avi Halachmi (:avih)
c4c1524e97 gc: don't ignore property allocations count
They're not negligible in the overall count.

This decreases the performance of scripts which use objects with many
properties because the GC threshold remains the same (10K) but it's
reached quicker due to counting more allocations, so GC is more
frequent and wastes more overall time.

Good example of the performance impact is the splay.js v8 bench test,
where this commit reduces its score by a factor of 5.

We're not changing the threshold because it's arbitrary anyway, but the
next commit will change it in a way which allows more proportional
control of the GC overhead.
2020-07-23 12:40:09 +02:00
Avi Halachmi (:avih)
ed33bc01d5 gc: fix incorrect free of some objects
When scanning an iterator object, the iterated object was marked
unconditionally. Now it's marked only if it's not already marked - like
all other object markings.

This code was incorrect for some years, but wasn't really an issue
before commit 331c5ec because marking an object twice simply used some
more CPU cycles but otherwise without issues - unless there were cycles,
and apparently typically/always there never were cycles with iterators,
so it was hard/impossible to behave badly.

However, since 331c5ec, marking an object means inserting it into a
linked list where the list nodes are part of the object, therefore
marking the same object twice now creates a broken linked list.

A broken list means that some objects are skipped while scanned, which
means they don't get marked even when they should, and as a result
freed incorrectly while still referenced by other objects, resulting in
random errors related to use-after-free.
2020-07-06 11:04:32 +02:00
Tor Andersson
ad3817fcc3 Silence gcc warning about overflow. 2020-07-06 11:04:32 +02:00
Tor Andersson
9f3e141d80 Fix typo in lexlinecomment where it did not detect EOF properly. 2020-06-25 13:29:53 +02:00
Tor Andersson
ac25ac54fa Fix typo in comment. 2020-05-27 17:07:41 +02:00
Sebastian Rasmussen
02bdafb46c Fix a number of typos. 2020-05-27 12:32:32 +02:00
Tor Andersson
832e069049 Support 4-byte UTF-8 sequences.
The following functions are no longer restricted to 16-bit integer values:

	String.fromCharCode()
	String.prototype.charCodeAt()

repr() will not escape SMP characters, as doing so would require conversion to
surrogate pairs, but will encode these characters as UTF-8. Unicode characters
in the BMP will still be escaped with \uXXXX as before.

JSON.stringify() only escapes control characters, so will represent all non-ASCII
characters as UTF-8.

We do no automatic conversions to/from surrogate pairs. Code that worked with
surrogate pairs should not be affected by these changes.
2020-05-27 12:32:32 +02:00
Tor Andersson
0261579d78 Support embedded 0 in strings by using modified UTF-8. 2020-05-27 12:32:32 +02:00
Tor Andersson
331c5ecbac Issue 133: Eliminate recursion in GC scanning phase.
Use a queue instead of recursion to scan reachable objects.
2020-05-27 12:32:32 +02:00
Tor Andersson
8c5f2f24c7 Don't allow setting a property when the prototype's property is read-only. 2020-05-27 12:32:32 +02:00
Tor Andersson
90aca80865 Fix potential memory corruption when jsV_newmemstring fails to allocate.
Don't change the value until the allocation has succeeded.
1.0.7
2020-03-17 14:10:18 +01:00
Tor Andersson
8f12e045f6 Return "[object Iterator]" when running toString on an iterator value. 2020-03-17 14:10:18 +01:00
Tor Andersson
84752905b9 Document the expected behavior of js_Put correctly. 2020-03-17 13:11:18 +01:00
Tor Andersson
fe63f4cb3c Note that js_Report callback must not throw an exception.
Nor should it call any functions that may throw exceptions.
2020-03-17 13:11:18 +01:00
Tor Andersson
e3f04e7f96 Check for empty string in js_isarrayindex. 2020-02-19 10:24:33 +01:00
Tor Andersson
11c894d0c1 Tweak default recursion limit. 2020-01-23 12:06:06 +01:00
Tor Andersson
6f93cab7ff Fix enumerability of Error and Function properties.
The Error.message, Error.stackTrace, Function.prototype properties were
defined with the wrong attributes.

x
2020-01-23 12:06:06 +01:00
Tor Andersson
e082e6e61c Check for leading zero in js_isarrayindex that caused false positives.
We're supposed to check whether a string turned into an integer and back
is itself, while also returning the value of the integer. We were
unintentionally allowing integers with leading zero through.
2020-01-20 12:39:58 +01:00
Tor Andersson
fe71080c59 Bug 698496: Handle leap years correctly in the Date constructor.
InLeapYear expects the parameter to be a timestamp and not a year.
Use DaysInYear instead.

Thanks to Robert Rosendahl for spotting this.
2020-01-10 11:22:09 +01:00