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()
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
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.
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.
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).
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.
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.
The underlying string of the "source" property of a regular expression
object can be freed if the regexp is garbage collected.
This could lead to a use-after-free, because the accessor incorrectly
assumed that the regexp source was an interned (thus never freed) string.
Fix this by calling js_pushstring instead of the faster but unsafe
js_pushliteral.
Many thanks to Connor Nelson for spotting this!
GCC with -O2 optimizes away the if(exp<-maxExponent) branch completely,
so we don't end up with the expected '512' value for overflowing
exponents. Limit the exponent parsing to MAX_INT instead to prevent
signed overflow from tripping up over-eager optimizing compilers.
- 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'.
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
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.
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"