Commit graph

1458 commits

Author SHA1 Message Date
Linus Groh
502d1f5165 LibJS: Implement bitwise right shift operator (>>) 2020-04-23 19:38:13 +02:00
Linus Groh
f0e7404480 LibJS: Implement bitwise left shift operator (<<) 2020-04-23 19:38:13 +02:00
Linus Groh
97366f4dd4 LibJS: Add Math.pow() 2020-04-23 19:38:13 +02:00
Kesse Jones
687096cadd LibJS: Add Array.prototype.includes 2020-04-23 19:30:16 +02:00
Kesse Jones
6d308113b8 LibJS: Fix Array.prototype.indexOf fromIndex negative
If negative fromIndex considers displacement from the end of the array
without decreasing 1 of de size.
2020-04-23 11:06:10 +02:00
Linus Groh
7540203ae8 LibJS: Add isFinite() 2020-04-23 11:03:42 +02:00
Linus Groh
8ff2881b1a LibJS: Let isNaN() with no argument return true, add tests 2020-04-23 11:03:42 +02:00
Linus Groh
418092a71a LibJS: Implement Array length setter 2020-04-23 09:47:23 +02:00
Linus Groh
a1b820b11c LibJS: Improve UpdateExpression::execute()
- Let undefined variables throw a ReferenceError by using
  Identifier::execute() rather than doing variable lookup manually and
  ASSERT()ing
- Coerce value to number rather than ASSERT()ing
- Make code DRY
- Add tests
2020-04-22 13:09:59 +02:00
Kesse Jones
b2305cb67d LibJS: Add Array.prototype.lastIndexOf 2020-04-22 13:08:00 +02:00
Linus Groh
038051d205 LibJS: Parse while statements 2020-04-22 11:48:14 +02:00
Andreas Kling
627fd6374b LibJS: Add Uint8ClampedArray :^)
This is a special kind of byte array that clamps its values to 0...255
It will be used for HTML ImageData objects.

I made Object::put_by_index() and get_by_index() virtual for this.
We'll probably need to make non-numeric property name lookups virtual
as well, but this solves my current problem well enough.
2020-04-21 23:47:39 +02:00
Jack Karamanian
1fa0c7304d LibJS: Implement Function.prototype.bind() 2020-04-21 12:23:07 +02:00
Jack Karamanian
b3800829da LibJS: Prepend callee's bound arguments to the CallFrame and set the
this_value to the callee's bound |this| in CallExpression::execute()
2020-04-21 12:23:07 +02:00
Jack Karamanian
5750edd859 LibJS: Allow Function objects to be constructed with a bound |this|
value and bound arguments

This allows Function objects produced by Function.prototype.bind, as well
as arrow functions to track their |this| values and bound arguments.
2020-04-21 12:23:07 +02:00
Linus Groh
13f806b1b0 LibJS: Rename global_call_fram to global_call_frame
Seems to be a typo.
2020-04-21 09:43:56 +02:00
Linus Groh
9722cac9fe LibJS: Let run-tests return 1 when not all tests pass 2020-04-20 22:44:13 +02:00
Andreas Kling
f78a92c5a9 LibJS: Remove default parameter from assertThrowsError() for now
We don't support these yet, and it broke all the tests. :^)
2020-04-20 20:33:21 +02:00
Linus Groh
cff68af965 LibJS: Add JSDoc to test-common.js 2020-04-20 17:31:49 +02:00
Kesse Jones
df6696f576 LibJS: Add Array.prototype.reverse 2020-04-20 17:26:46 +02:00
Kesse Jones
579975fd1e LibJS: Add Array.prototype.indexOf 2020-04-20 11:55:18 +02:00
Linus Groh
d3e3f5b421 LibJS: Add tests for String.prototype.repeat() 2020-04-20 11:41:25 +02:00
Linus Groh
a893c6ff0d LibJS: Throw RangeError in String.prototype.repeat() if count is invalid 2020-04-20 11:41:25 +02:00
Linus Groh
0718f216af LibJS: Add assertThrowsError() test function 2020-04-20 11:38:01 +02:00
AnotherTest
992467cca3 LibJS: Do not assume that a call frame exists in {get,set}_variable 2020-04-19 17:36:37 +02:00
Andreas Kling
69566bd4d6 LibJS: Allow passing "js" flags to run-tests
This allows us to run "run-tests -g" for testing with GC after every
heap allocation. This may flush out bugs that would otherwise not
occur if GC'ing only occasionally.
2020-04-19 17:34:33 +02:00
Andreas Kling
f7a1696087 LibJS: Add MarkedValueList and use it for argument passing
A MarkedValueList is basically a Vector<JS::Value> that registers with
the Heap and makes sure that the stored values don't get GC'd.

Before this change, we were unsafely keeping Vector<JS::Value> in some
places, which is out-of-reach for the live reference finding logic
since Vector puts its elements on the heap by default.

We now pass all the JavaScript tests even when running with "js -g",
which does a GC on every heap allocation.
2020-04-19 17:34:33 +02:00
Andreas Kling
afdba94f63 LibJS: Fix expectations in the function-TypeError.js test
They now match the new, more verbose error messages.
2020-04-19 14:51:47 +02:00
Andreas Kling
b251091a6a LibJS: CallExpression shouldn't throw TypeError or non-constructor call
This unbreaks the entire test suite. :^)
2020-04-19 14:51:47 +02:00
Andreas Kling
2a9e29fbb8 LibJS: Add DeferGC, a RAII way to prevent GC temporarily 2020-04-19 12:09:32 +02:00
Linus Groh
03f2024b6e LibJS: Improve CallExpression::execute()'s error messages 2020-04-19 11:00:39 +02:00
Kesse Jones
856ab9c600 LibJS: Add Array.prototype.slice 2020-04-19 02:09:06 +02:00
Linus Groh
71d6459b7f LibJS: Use AK::String::index_of() for StringPrototype::index_of() 2020-04-18 22:24:22 +02:00
Stephan Unverwerth
bf5b251684 LibJS: Allow reserved words as keys in object expressions. 2020-04-18 22:23:20 +02:00
Stephan Unverwerth
cebb619f8e LibJS: Fix parsing of IfStatement, fixes #1829 2020-04-18 14:04:24 +02:00
Andreas Kling
3072f9fd82 LibJS: Move the empty object shape from Interpreter to GlobalObject
The big remaining hurdle before a GlobalObject-agnostic Interpreter is
the fact that Interpreter owns and vends the GlobalObject :^)
2020-04-18 13:59:20 +02:00
Andreas Kling
fca08bd000 LibJS: Move builtin prototypes to the global object
This moves us towards being able to run JavaScript in different global
objects without allocating a separate GC heap.
2020-04-18 13:24:45 +02:00
Linus Groh
d14ddb6461 LibJS: Implement nullish coalescing operator (??) 2020-04-18 12:34:13 +02:00
Andreas Kling
30de1f610d LibJS: Use enumerator macro to mark all constructors in GlobalObject
We were forgetting to mark the String constructor! So this patch fixes
that and ensures we won't forget anyone in the future.
2020-04-18 11:02:05 +02:00
Andreas Kling
bc1ece7f37 LibJS+LibWeb: Pass prototype to Object constructor
Everyone who constructs an Object must now pass a prototype object when
applicable. There's still a fair amount of code that passes something
fetched from the Interpreter, but this brings us closer to being able
to detach prototypes from Interpreter eventually.
2020-04-18 11:00:55 +02:00
Andreas Kling
f6d57c82f6 LibJS: Pass prototype to Function constructors 2020-04-18 10:28:22 +02:00
Andreas Kling
205ac0090d LibJS: Pass prototype to Error constructors 2020-04-18 10:28:22 +02:00
Andreas Kling
0df4d2823a LibJS: Pass prototype to Date constructor 2020-04-18 10:28:22 +02:00
Andreas Kling
2a15323029 LibJS: Pass prototype to BooleanObject constructor 2020-04-18 10:28:22 +02:00
Andreas Kling
298c606200 LibJS: Pass prototype to StringObject constructor 2020-04-18 10:28:22 +02:00
Andreas Kling
cf702a13b9 LibJS: Pass prototype to NumberObject constructor 2020-04-18 10:28:22 +02:00
Andreas Kling
2d7b495244 LibJS: Make Array constructor take its prototype
Let's start moving towards native JS objects taking their prototype as
a constructor argument.

This will eventually allow us to move prototypes off of Interpreter and
into GlobalObject.
2020-04-18 10:28:22 +02:00
Kesse Jones
4931c0feda LibJS: Add Array.prototype.concat 2020-04-17 16:14:28 +02:00
Stephan Unverwerth
63e1ea7819
LibJS: Add test for semicolon insertion (#1828) 2020-04-17 15:52:38 +02:00
Stephan Unverwerth
19cdda8000 LibJS: Fix semicolon insertion 2020-04-17 15:32:20 +02:00