Commit graph

738 commits

Author SHA1 Message Date
Ben Wiederhake
801058e514 LibJS: Soothe gcc about printf-%s on (non-)nullptr 2020-07-28 19:10:10 +02:00
Andreas Kling
3ee6ed965f LibJS: Use allocate_without_global_object for primitive cell types
More steps towards multiple global object support. Primitive cells
like strings, bigints, etc, don't actually have any connection to
the global object. Use the explicit API to clarify this.
2020-07-25 13:12:17 +02:00
Nico Weber
c4d9d5cc54 Browser: Escape JS source operators for HTML display in console
Console inputs to try before and after this patch:
- `0xffff & 0xff`
- `"a & b"`
- `"<div>"`
- `a &` (to see the escaping in the error hint)
2020-07-23 23:01:16 +02:00
Andreas Kling
aaf6014ae1 LibJS: Simplify Cell::initialize()
Remove the Interpreter& argument and pass only GlobalObject&. We can
find everything we need via the global object anyway.
2020-07-23 17:31:08 +02:00
Nico Weber
79a5ba58a5 LibJS: Add tests for bitwise & and ^
And fix some edge case conversion bugs found by the tests.
2020-07-23 13:06:49 +02:00
Nico Weber
b9ce56aee6 LibWeb: Make btoa() and atob() correctly handle values between 128 and 255
btoa() takes a byte string, so it must decode the UTF-8 argument into
a Vector<u8> before calling encode_base64.

Likewise, in atob() decode_base64 returns a byte string, so that needs
to be converted to UTF-8.

With this, `btoa(String.fromCharCode(255))` is '/w==' as it should
be, and `atob(btoa(String.fromCharCode(255))) == String.fromCharCode(255)`
remains true.
2020-07-22 19:22:00 +02:00
Nico Weber
9e32ad6c99 LibJS: Fix \x escapes of bytes with high bit set
With this, typing `"\xff"` into Browser's console no longer
makes the app crash.

While here, also make the \u handler call append_codepoint()
instead of calling an overload where it's not immediately clear
which overload is getting called. This has no behavior change.
2020-07-22 19:21:35 +02:00
Nico Weber
248b79d687 LibJS: Add FIXMEs to a few functions that need UTF-16 handling 2020-07-22 17:26:34 +02:00
Nico Weber
979e02c0a8 LibJS: Implement String.prototype.charCodeAt
It's broken for strings with characters outside 7-bit ASCII, but
it's broken in the same way as several existing functions (e.g.
charAt()), so that's probably ok for now.
2020-07-22 15:48:01 +02:00
Matthew Olsson
02305d01ea LibJS: Add Number.prototype.toString 2020-07-15 18:24:55 +02:00
Matthew Olsson
6075defd55 LibJS: Add Symbol.hasInstance tests 2020-07-14 20:15:19 +02:00
Matthew Olsson
b0296735a5 LibJS: Implement Symbol.hasInstance 2020-07-14 20:15:19 +02:00
Matthew Olsson
dd49ec17a2 LibJS: Implement spec-complient instance_of operation 2020-07-14 20:15:19 +02:00
Matthew Olsson
a51b2393f2 LibJS: Integrate iterator protocol into language features
Finally use Symbol.iterator protocol in language features :) currently
only used in for-of loops and spread expressions, but will have more
uses later (Maps, Sets, Array.from, etc).
2020-07-14 17:58:42 +02:00
Matthew Olsson
4c3a415dc3 LibJS: Add String Iterator tests 2020-07-13 15:07:29 +02:00
Matthew Olsson
c831fb17bf LibJS: Add StringIterator 2020-07-13 15:07:29 +02:00
Matthew Olsson
43d955014d LibJS: Implement Symbol.toStringTag 2020-07-11 23:13:29 +02:00
Matthew Olsson
5ecd504f4e LibJS: Implement spec-compliant Object.prototype.toString 2020-07-11 23:13:29 +02:00
Matthew Olsson
531fdb2e82 LibJS: Prefer "define_property" over "put" 2020-07-11 18:54:13 +02:00
Matthew Olsson
c485c86015 LibJS: Use macros to enumerate well-known symbols
Not only is this a much nicer api (can't pass a typo'd string into the
get_well_known_symbol function), it is also a bit more performant since
there are no hashmap lookups.
2020-07-11 18:54:13 +02:00
Matthew Olsson
2ea85355fe LibJS: Start implementing iterable framework, add ArrayIterator
With the addition of symbol keys, work can now be done on starting to
implement the well-known symbol functionality. The most important of
these well-known symbols is by far Symbol.iterator.

This patch adds IteratorPrototype, as well as ArrayIterator and
ArrayIteratorPrototype. In the future, sometime after StringIterator has
also been added, this will allow us to use Symbol.iterator directly in
for..of loops, enabling the use of custom iterator objects. Also makes
adding iterator support to native objects much easier (as will have to
be done for Map and Set, when they get added).
2020-07-11 18:54:13 +02:00
Matthew Olsson
51bfc6c6b3 LibJS: Renamed Object::GetOwnPropertyReturnMode to Object::PropertyKind
This enum will be used by iterators, so it makes sense to use a more
general name.
2020-07-11 18:54:13 +02:00
Linus Groh
7241b9ca0c LibJS: Remove a few superfluous exception checks
We don't need to check for exceptions when defining properties on an
array we literally created ourselves a few lines earlier.
2020-07-11 18:38:51 +02:00
Matthew Olsson
119386ffb0 LibJS: Add tests for symbol object integration 2020-07-09 23:33:00 +02:00
Matthew Olsson
7a1d485b19 LibJS: Integrate Symbols into objects as valid keys
This allows objects properties to be created for symbol keys in addition
to just plain strings/numbers
2020-07-09 23:33:00 +02:00
Matthew Olsson
9783a4936c LibJS: Add test for well-known symbols 2020-07-09 23:29:28 +02:00
Matthew Olsson
ffb569fd5d LibJS: Uncomment remaining symbol tests 2020-07-09 23:29:28 +02:00
Matthew Olsson
d9db6bec42 LibJS: Move global symbol map from SymbolObject to Interpreter
This allows different instances of the Interpreter to have their own
global symbols. Also makes Symbol non-copyable and non-moveable.
2020-07-09 23:29:28 +02:00
Matthew Olsson
93ebd320ef LibJS: Object.preventExtensions should allow property modfication
Existing properties on a non-extensible object should be changable and
deletable.
2020-07-07 10:47:10 +02:00
Linus Groh
461d90d042 LibJS: Convert Array tests to new testing framework 2020-07-06 23:40:35 +02:00
Linus Groh
8ebdf685a6 LibJS: Split isNaN tests into multiple sections 2020-07-06 23:40:35 +02:00
Matthew Olsson
1ef573eb30 LibJS: Indent tests with 4 spaces instead of 2 2020-07-06 23:40:35 +02:00
Matthew Olsson
15de2eda2b LibJS: Convert all remaining non-Array tests to the new system :) 2020-07-06 23:40:35 +02:00
Matthew Olsson
918f4affd5 LibJS: Convert remaining top-level tests to new system 2020-07-06 23:40:35 +02:00
Matthew Olsson
6d58c48c2f test-js: Use prettier and format all files 2020-07-06 23:40:35 +02:00
Matthew Olsson
a2dbd955f2 test-js: Display messages from console.log in test output
This will help greatly with debugging!
2020-07-06 23:40:35 +02:00
Matthew Olsson
82fa65135a test-js: Allow skipping tests with "test.skip(name, callback)"
Skipped tests count as a "pass" rather than a "fail" (i.e. a test suite
with a skipped test will pass), however it does display a message when
the test is printing.

This is intended for tests which _should_ work, but currently do not.
This should be preferred over "// FIXME" notes if possible.
2020-07-06 23:40:35 +02:00
Matthew Olsson
cf537311e4 test-js: Remove run-tests.sh
The shell script is no longer necessary -- simply run "test-js" from
inside Serenity, or $SERENITY_ROOT/Build/Meta/Lagom/test-js from the
host.
2020-07-06 23:40:35 +02:00
Matthew Olsson
26acc8ba88 LibJS/test-js: Clean up test-js code
This commit also exposes JSONObject's implementation of stringify to the
public, so that it can be used by test-js without having to go through
the interpreter's environment.
2020-07-06 23:40:35 +02:00
Matthew Olsson
4c6fd49169 LibJS: Fix String.raw.length 2020-07-06 23:40:35 +02:00
Matthew Olsson
3f97d75778 LibJS: Convert most builtin tests to new system 2020-07-06 23:40:35 +02:00
Linus Groh
46581773c1 LibJS: Convert Reflect object tests to new testing framework 2020-07-06 23:40:35 +02:00
Matthew Olsson
fc08222f46 LibJS: Add more test matchers 2020-07-06 23:40:35 +02:00
Matthew Olsson
5e971c91e3 LibJS: Hide some debug output behind flags
This hides some Object.cpp output, as well as removing the "debugger"
debug output.
2020-07-06 23:40:35 +02:00
Matthew Olsson
449a1cf3a2 LibJS: Convert Proxy tests 2020-07-06 23:40:35 +02:00
Matthew Olsson
b86faeaeef LibJS: Add test-common.js tests, remove unused matchers
Now that test-common.js is quite a bit more complicated, we need tests
for test-common to make sure all of the matchers behave correctly
2020-07-06 23:40:35 +02:00
Matthew Olsson
eea6041302 LibJS: Convert some top-level tests to the new system
First test conversions! These look really good :)
2020-07-06 23:40:35 +02:00
Matthew Olsson
4b8a3e6d78 LibJS: Refactor run-tests.sh to use the new test-js program 2020-07-06 23:40:35 +02:00
Matthew Olsson
b9cf7a833f LibJS/test-js: Create test-js program, prepare for test suite refactor
This moves most of the work from run-tests.sh to test-js.cpp. This way,
we have a lot more control over how the test suite runs, as well as how
it outputs. This should result in some cool functionality!

This commit also refactors test-common.js to mimic the jest library.
This should allow tests to be much more expressive :)
2020-07-06 23:40:35 +02:00
Matthew Olsson
6af3fff0c2 LibJS: Reformat run-tests.sh output
- Use emojis instead of the pass/fail text
- Fix the new version of the script to run inside Serenity
- Don't print erroneous output after 'Output:'; start on a newline
instead
- Skip 'run-tests.sh' while testing
2020-07-03 19:30:13 +02:00