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
Stephan Unverwerth
07f838dc4e
LibJS: Implement automatic semicolon insertion
2020-04-17 15:22:31 +02:00
Andreas Kling
72df9c7417
LibJS: Dump a JavaScript backtrace when throwing exceptions
2020-04-16 20:23:03 +02:00
Kesse Jones
b0b204822f
LibJS: Add String.prototype.substring
2020-04-16 18:47:24 +02:00
Andreas Kling
60d1ef6af4
LibJS: Remove no-op code in ScriptFunction constructor
2020-04-16 16:58:44 +02:00
Kesse Jones
7725b1970e
LibJS: Add String.prototype.concat
2020-04-16 16:36:51 +02:00
Andreas Kling
e72a537033
LibJS: Make Value::m_type default to Type::Empty
...
This is not effectful since all constructors overwrite the type anyway,
but it seems reasonable that the default value of m_type would match
what Value() would give you.
2020-04-16 16:11:11 +02:00
Andreas Kling
1b391d78ae
LibJS: Allow cells to mark null pointers
...
This simplifies the cell visiting functions by letting them not worry
about the pointers they pass to the visitor being null.
2020-04-16 16:10:38 +02:00
Andreas Kling
13865c7c3d
LibJS: Remove unreachable code in Interpreter::enter_scope()
...
Functions are handled and short-circuited at the head of enter_scope().
2020-04-16 10:25:00 +02:00
Andreas Kling
9b9086dcf0
LibJS: Oops, fix StringPrototype build
2020-04-16 10:24:32 +02:00
Andreas Kling
1108dd1659
LibJS: Add some missing |this| checks in StringPrototype
...
Also some style tweaks
2020-04-16 10:04:21 +02:00
Linus Groh
640a24dce8
LibJS: Remove outdated FIXME now that we have lexical environments
2020-04-16 09:41:07 +02:00
Andreas Kling
54c95d44ce
LibJS: Functions with no variables don't need to create environment
...
Just hand out the parent environment instead.
2020-04-15 22:17:17 +02:00
Andreas Kling
ed80952cb6
LibJS: Introduce LexicalEnvironment
...
This patch replaces the old variable lookup logic with a new one based
on lexical environments.
This brings us closer to the way JavaScript is actually specced, and
also gives us some basic support for closures.
The interpreter's call stack frames now have a pointer to the lexical
environment for that frame. Each lexical environment can have a chain
of parent environments.
Before calling a Function, we first ask it to create_environment().
This gives us a new LexicalEnvironment for that function, which has the
function's lexical parent's environment as its parent. This allows
inner functions to access variables in their outer function:
function foo() { <-- LexicalEnvironment A
var x = 1;
function() { <-- LexicalEnvironment B (parent: A)
console.log(x);
}
}
If we return the result of a function expression from a function, that
new function object will keep a reference to its parent environment,
which is how we get closures. :^)
I'm pretty sure I didn't get everything right here, but it's a pretty
good start. This is quite a bit slower than before, but also correcter!
2020-04-15 22:07:20 +02:00
Linus Groh
cea950fd70
LibJS: Support empty values in array expression
2020-04-15 21:23:06 +02:00
Linus Groh
d30db07048
LibJS: Implement void operator
2020-04-15 19:12:51 +02:00
Andreas Kling
beda751d33
LibJS: Math.round() should call round() instead of roundf()
...
Neither LibM functions are very strong right now, but let's at least
call the right one.
2020-04-15 19:12:10 +02:00
Linus Groh
a8406aa117
LibJS: Check length property of Array.prototype.join in its test
...
I assume this was copied from the Array.prototype.push() test :^)
2020-04-15 12:20:08 +02:00
Andreas Kling
ad2aac5fde
LibJS: Add Array.prototype.join()
...
And share the code with Array.prototype.toString() :^)
2020-04-15 10:06:01 +02:00
Andreas Kling
fa30355194
LibJS: Adding two values should convert them to primitives first
2020-04-15 09:48:25 +02:00
Andreas Kling
63499c2c9f
LibJS: Pass the Interpreter& to binary/logical/unary helpers
2020-04-15 09:28:41 +02:00
Kesse Jones
994f1a79ad
LibJS: Add String.prototype.{trim, trimStart, trimEnd} ( #1792 )
2020-04-15 08:47:40 +02:00
Linus Groh
1dee4d0049
LibJS: Redirect stderr to /dev/null when running js in run-tests
...
This "mutes" output from dbg() calls - which is not an issue inside
serenity itself but if the script is run on the host machine and stdout
and stderr are displayed in the same terminal window.
2020-04-14 18:38:55 +02:00
Linus Groh
823fb9d9aa
LibJS: Add missing load("test-common.js") to comments-basic.js
...
This fixes the test which is currently failing with
"ReferenceError: 'assert' not known".
2020-04-14 17:26:57 +02:00
Linus Groh
f7df521073
LibJS: Add Array.prototype.map()
2020-04-14 13:40:04 +02:00
Linus Groh
f03d005bc4
LibJS: Add Array.prototype.filter()
2020-04-14 13:40:04 +02:00
Linus Groh
866172a721
LibJS: Add Array.prototype.forEach()
2020-04-14 13:40:04 +02:00
Linus Groh
29253bf932
LibJS: Add Array.prototype.unshift()
2020-04-14 13:40:04 +02:00