Commit graph

470 commits

Author SHA1 Message Date
Linus Groh
b32761f2e0 LibJS: Consider non-extensible objects in Reflect.setPrototypeOf() 2020-06-02 13:51:02 +02:00
Linus Groh
c1248a7fd8 LibJS: Implement Reflect.{isExtensible,preventExtensions}() 2020-06-02 13:51:02 +02:00
Linus Groh
b958e4f573 LibJS: Disallow changing the prototype of non-extensible objects
Object::set_prototype() now returns a boolean indicating success.
Setting the prototype to an identical object is always considered
successful, even if the object is non-extensible.
2020-06-02 13:51:02 +02:00
Linus Groh
8cf1ded478 LibJS: Don't assume Object.setPrototypeOf() prototype value is an object
We're crashing otherwise. Also it was not possible to set the prototype
to null.
2020-06-02 13:51:02 +02:00
Linus Groh
1a64bdd80c LibJS: Return specified object from Object.setPrototypeOf()
We were leaking an empty value.
2020-06-02 13:51:02 +02:00
Matthew Olsson
d5ae73a63b LibJS: Add Object.{isExtensible,preventExtensions}() 2020-06-02 08:50:26 +02:00
Matthew Olsson
ab576e610c LibJS: Rewrite Parser.parse_object_expression()
This rewrite drastically increases the accuracy of object literals.
Additionally, an "assertIsSyntaxError" function has been added to
test-common.js to assist in testing syntax errors.
2020-06-01 13:11:21 +02:00
Linus Groh
e33820b557 LibJS: Add String.fromCharCode() 2020-05-31 02:19:52 +02:00
Andreas Kling
29ab518003 LibJS: Show run-tests progress in the taskbar
Use the window progress escape sequence to indicate how far along in
the test collection we are while running tests. :^)
2020-05-30 23:00:35 +02:00
Jack Karamanian
d4e97b17ab LibJS: Use a non-arrow function to check the |this| value in the
callback for Array.prototype.{reduce,reduceRight}

Arrow functions always retain the |this| binding.

Running this code in Node:

[1, 2].reduce(() => { "use strict"; console.log(this === undefined) }

Output: false
2020-05-30 10:33:24 +02:00
Jack Karamanian
4a49c8412c LibJS: Add tests ensuring the |this| value can't be set for arrow
functions in Function.prototype.{call,apply}
2020-05-30 10:33:24 +02:00
Jack Karamanian
f4129ac422 LibJS: Use the function's bound |this| and bound arguments in
Interpreter::call()
2020-05-30 10:33:24 +02:00
Jack Karamanian
3ffb0a4e87 LibJS: Throw a TypeError when an arrow function is used as a constructor 2020-05-30 10:33:24 +02:00
Jack Karamanian
1110b1b444 LibJS: Don't define the "prototype" property for arrow functions 2020-05-30 10:33:24 +02:00
Jack Karamanian
45ccd9f8d9 LibJS: Set the bound |this| value to the |this| value of the current
scope for arrow functions
2020-05-30 10:33:24 +02:00
Matthew Olsson
4e331a1fcf LibJS: Object.getOwnPropertyDescriptor works properly with accessors 2020-05-30 10:32:52 +02:00
Marcin Gasperowicz
4e8de753c9 LibJS: Parse arrow function expression with correct precedence
The parser was chomping on commas present after the arrow function expression. eg. [x=>x,2] would parse as [x=>(x,2)] instead of [(x=>x),2].

This is not the case anymore. I've added a small test to prove this.
2020-05-30 00:33:18 +02:00
Matthew Olsson
d52ea37717 LibJS: Integrate labels into the Interpreter
The interpreter now considers a statement or block's label when
considering whether or not to break. All statements can be labelled.
2020-05-29 16:20:32 +02:00
Matthew Olsson
10bf4ba3dc LibJS: Parse labelled statements
All statements now have an optional label string that can be null.
2020-05-29 16:20:32 +02:00
Matthew Olsson
5cd01ed79e LibJS: New expressions look for expressions with correct precedence 2020-05-29 15:56:39 +02:00
Linus Groh
1dd44210b7 LibJS: Add Array.prototype.toLocaleString() 2020-05-29 08:00:02 +02:00
Linus Groh
70d2add22f LibJS: Add Object.prototype.toLocaleString() 2020-05-29 08:00:02 +02:00
Matthew Olsson
664085b719 LibJS: Fix conditional expression precedence
This fixes the following from parsing incorrectly due to the comma
that occurs after the conditional:

  let o = {
    foo: true ? 1 : 2,
    bar: 'baz',
  };
2020-05-29 07:57:14 +02:00
Linus Groh
8ff4587f65 LibJS: Throw in strict mode when assigning property to primitive value 2020-05-29 07:45:22 +02:00
Marcin Gasperowicz
eadce65e04
LibJS: Implement standard semantics for relational operators (#2417)
Previously, the relational operators where casting any value to double
and comparing the results according to C++ semantics.

This patch makes the relational operators in JS behave according to the
standard specification.

Since we don't have BigInt yet, the implementation doesn't take it into
account. 

Moved PreferredType from Object to Value. Value::to_primitive now
passes preferred_type to Object::to_primitive.
2020-05-28 17:19:59 +02:00
Matthew Olsson
786722149b LibJS: Add strict mode
Adds the ability for a scope (either a function or the entire program)
to be in strict mode. Scopes default to non-strict mode.

There are two ways to determine the strict-ness of the JS engine:

1. In the parser, this can be accessed with the parser_state variable
   m_is_strict_mode boolean. If true, the Parser is currently parsing in
   strict mode. This is done so that the Parser can generate syntax
   errors at parse time, which is required in some cases.

2. With Interpreter.is_strict_mode(). This allows strict mode checking
   at runtime as opposed to compile time.

Additionally, in order to test this, a global isStrictMode() function
has been added to the JS ReplObject under the test-mode flag.
2020-05-28 17:18:42 +02:00
Matthew Olsson
5ae9419a06 LibJS: Object index properties have descriptors; Handle sparse indices
This patch adds an IndexedProperties object for storing indexed
properties within an Object. This accomplishes two goals: indexed
properties now have an associated descriptor, and objects now gracefully
handle sparse properties.

The IndexedProperties class is a wrapper around two other classes, one
for simple indexed properties storage, and one for general indexed
property storage. Simple indexed property storage is the common-case,
and is simply a vector of properties which all have attributes of
default_attributes (writable, enumerable, and configurable).

General indexed property storage is for a collection of indexed
properties where EITHER one or more properties have attributes other
than default_attributes OR there is a property with a large index (in
particular, large is '200' or higher).

Indexed properties are now treated relatively the same as storage within
the various Object methods. Additionally, there is a custom iterator
class for IndexedProperties which makes iteration easy. The iterator
skips empty values by default, but can be configured otherwise.
Likewise, it evaluates getters by default, but can be set not to.
2020-05-28 17:17:13 +02:00
Angel
199a6b40b3 LibJS: Add Array.prototype.fill 2020-05-26 20:34:44 +02:00
Luke
f9f7cb4583 LibJS: Add Array.prototype.splice
Adds splice to Array.prototype according to the specification:
https://tc39.es/ecma262/#sec-array.prototype.splice
2020-05-26 12:47:11 +02:00
Linus Groh
07af2e6b2c LibJS: Implement basic for..in and for..of loops 2020-05-25 18:45:36 +02:00
Linus Groh
92fd140cb2 LibJS: Make Array.prototype.includes() generic 2020-05-24 23:51:14 +02:00
Linus Groh
e78bc2f6fd LibJS: Make Array.prototype.lastIndexOf() generic 2020-05-24 23:51:14 +02:00
Linus Groh
9b9b6a4cff LibJS: Make Array.prototype.indexOf() generic 2020-05-24 23:51:14 +02:00
Marcin Gasperowicz
99991761fd LibJS: add Array.prototype.reduceRight()
This patch adds `Array.prototype.reduceRight()` method to LibJS Runtime. The implementation is (to my best knowledge) conformant to https://tc39.es/ecma262/#sec-array.prototype.reduceright.

Short test in `LibJS/Tests/Array.prototype-generic-functions.js` demonstrates that the function can be applied to other objects besides `Array`.
2020-05-24 20:58:14 +02:00
Marcin Gasperowicz
27c71d2627
LibJS: Add Array.prototype.reduce() (#2334)
This patch adds `Array.prototype.reduce()` method to LibJS Runtime.
The implementation is (to my best knowledge) comformant to ECMA262.

The test `Array.prototype-generic-functions.js` demonstrates that the
function can be applied to other objects besides `Array`.
2020-05-23 16:41:25 +02:00
Linus Groh
00fe7f82c0 LibJS: Treat NaN in Value::to_i32() as zero
Let's treat it as zero like the ECMAScript spec does in toInteger().

That way we can use to_i32() and don't have to care about weird input
input values where a number is expected, i.e.

"foo".charAt() === "f"
"foo".charAt("bar") === "f"
"foo".charAt(0) === "f"
2020-05-23 16:39:17 +02:00
Linus Groh
843e000f18 LibJS: Fix Array.prototype.lastIndexOf() implementation 2020-05-23 00:02:13 +02:00
Linus Groh
6a4280e6e5 LibJS: Treat missing arg in Array.prototype.{indexOf,lastIndexOf}() as undefined 2020-05-23 00:02:13 +02:00
Linus Groh
040c75a3cc LibJS: Make Array.prototype.{join,toString}() generic 2020-05-22 17:43:44 +02:00
Linus Groh
e9ee06b19e LibJS: Make Array.prototype.pop() generic 2020-05-22 17:43:44 +02:00
Linus Groh
4334a1b208 LibJS: Make Array.prototype.push() generic 2020-05-22 17:43:44 +02:00
Linus Groh
9f7a6e116a LibJS: Let Array.prototype.join() ignore additional arguments
I.e.

array.join("x", "y", "z") === array.join("x")

rather than

array.join("x", "y", "z") === array.join()
2020-05-22 17:43:44 +02:00
Matthew Olsson
c35732c011 LibJS: Add object literal getter/setter shorthand
Adds support for the following syntax:

let foo = {
    get x() {
        // ...
    },
    set x(value) {
        // ...
    }
}
2020-05-22 10:59:05 +02:00
Linus Groh
27913154ea LibJS: Disallow multiple parameters in paren-less arrow function
Fixes #2323.
2020-05-22 00:50:57 +02:00
Matthew Olsson
45dfa094e9 LibJS: Add getter/setter support
This patch adds a GetterSetterPair object. Values can now store pointers
to objects of this type. These objects are created when using
Object.defineProperty and providing an accessor descriptor.
2020-05-21 22:56:18 +02:00
Linus Groh
a4d04cc748 LibJS: Refactor Array.prototype callback functions and make them generic 2020-05-21 22:50:14 +02:00
Linus Groh
5db9becc4a LibJS: Treat missing arg in Array.prototype.includes() as undefined 2020-05-21 22:50:14 +02:00
Luke
57d15acd4c LibJS: Add Array.prototype.every 2020-05-21 19:44:59 +02:00
Matthew Olsson
e415dd4e9c LibJS: Handle hex and unicode escape sequences in string literals
Introduces the following syntax:

'\x55'
'\u26a0'
'\u{1f41e}'
2020-05-18 17:58:17 +02:00
Linus Groh
b3090678a9 LibJS: Add Math.clz32() 2020-05-18 17:57:28 +02:00
Linus Groh
452dbbc463 LibJS: Add Math.expm1() 2020-05-18 17:57:28 +02:00
Linus Groh
e375766f98 LibJS: Add Math.exp() 2020-05-18 17:57:28 +02:00
Linus Groh
b27834cf16 LibJS: Add Math.sign() 2020-05-18 17:57:28 +02:00
Linus Groh
4569e88bea LibJS: Throw TypeError when coercing symbol to number 2020-05-18 09:39:55 +02:00
Linus Groh
476094922b LibJS: Pass Interpreter& to Value::to_number() et al.
This patch is unfortunately rather large and might make some things feel
bloated, but it is necessary to fix a few flaws in LibJS, primarily
blindly coercing values to numbers without exception checks - i.e.

interpreter.argument(0).to_i32();  // can fail!!!

Some examples where the interpreter would actually crash:

var o = { toString: () => { throw Error() } };
+o;
o - 1;
"foo".charAt(o);
"bar".repeat(o);

To fix this, we now have the following...

to_double(Interpreter&)
to_i32()
to_i32(Interpreter&)
to_size_t()
to_size_t(Interpreter&)

...and a whole lot of exception checking.

There's intentionally no to_double(), use as_double() directly instead.

This way we still can use these convenient utility functions but don't
need to check for exceptions if we are sure the value already is a
number.

Fixes #2267.
2020-05-18 09:39:55 +02:00
mattco98
4ced126704 LibJS: Add symbol objects
This commit adds the following classes: SymbolObject, SymbolConstructor,
SymbolPrototype, and Symbol. This commit does not introduce any
new functionality to the Object class, so they cannot be used as
property keys in objects.
2020-05-17 18:05:15 +02:00
Linus Groh
73eef31f49 LibJS: Add Number.parseFloat() 2020-05-17 16:21:38 +02:00
Linus Groh
6f6b089aa0 LibJS: Add parseFloat() 2020-05-17 16:21:33 +02:00
Linus Groh
b299c75d45 LibJS: Make Object.prototype.constructor non-enumerable 2020-05-16 21:22:34 +02:00
Andreas Kling
de7827faf7 LibM: Fix floor() and floorf() for negative numbers
And add a LibJS test to exercise the code. :^)
2020-05-15 22:05:59 +02:00
Andreas Kling
c6ddbd1f3e LibJS: Add side-effect-free version of Value::to_string()
There are now two API's on Value:

- Value::to_string(Interpreter&) -- may throw.
- Value::to_string_without_side_effects() -- will never throw.

These are some pretty big sweeping changes, so it's possible that I did
some part the wrong way. We'll work it out as we go. :^)

Fixes #2123.
2020-05-15 13:50:42 +02:00
Linus Groh
33defef267 LibJS: Let parser keep track of errors
Rather than printing them to stderr directly the parser now keeps a
Vector<Error>, which allows the "owner" of the parser to consume them
individually after parsing.

The Error struct has a message, line number, column number and a
to_string() helper function to format this information into a meaningful
error message.

The Function() constructor will now include an error message when
throwing a SyntaxError.
2020-05-15 09:53:52 +02:00
Sergey Bugaev
450a2a0f9c Build: Switch to CMake :^)
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-14 20:15:18 +02:00
Linus Groh
de42ddfd93 LibJS: Trim whitespace from string before coercing to number 2020-05-13 09:36:20 +02:00
Linus Groh
0c14ee035c LibJS: Make string to number coercion work for doubles 2020-05-13 09:36:20 +02:00
Linus Groh
7b8765c311 LibJS: Make the Function() constructor throw a SyntaxError, not return 2020-05-13 09:34:25 +02:00
Linus Groh
d69ed91790 LibJS: Check AssignmentExpression LHS in parser
There are many cases which shouldn't even parse, like

null = ...
true = ...
false = ...
123 = ...
"foo" = ...

However this *is* valid syntax:

foo() = ...

So we still have to keep the current code doing a runtime check if the
LHS value is a resolvable reference. I believe this was declared valid
syntax to *in theory* allow functions returning references - though in
practice that isn't a thing.

Fixes #2204.
2020-05-13 01:15:29 +02:00
Linus Groh
8ffdcce0d0 LibJS: Parse comma operator into SequenceExpression 2020-05-11 18:36:28 +02:00
Linus Groh
e333b60064 LibJS: Add Array.of() 2020-05-08 20:06:49 +02:00
Linus Groh
ca22476d9d LibJS: Add Array.isArray() 2020-05-08 20:06:49 +02:00
Linus Groh
01fd6ce045 LibJS: Support multiple arguments in Array constructor 2020-05-08 20:06:49 +02:00
Matthew Olsson
532d4bc0ab LibJS: Spec-compliant equality comparisons
The ECMAScript spec defines multiple equality operations which are used
all over the spec; this patch introduces them. Of course, the two
primary equality operations are AbtractEquals ('==') and StrictEquals
('==='), which have been renamed to 'abstract_eq' and 'strict_eq' in
this patch.

In support of the two operations mentioned above, the following have
also been added: SameValue, SameValueZero, and SameValueNonNumeric.
These are important to have, because they are used elsewhere in the spec
aside from the two primary equality comparisons.
2020-05-08 09:49:20 +02:00
Yonatan Goldschmidt
b184f12aaf LibJS: Limit scope of 'for' loop variables
This required 2 changes:
1. In the parser, create a new variable scope, so the variable is
   declared in it instead of the scope in which the 'for' is found.
2. On execute, push the variable into the newly created block. Existing
   code created an empty block (no variables, no arguments) which
   allows Interpreter::enter_scope() to skip the creation of a new
   environment, therefore when the variable initializer is executed, it
   sets the variable to the outer scope. By attaching the variable to
   the new block, the block gets a new environment.

This is only needed for 'let' / 'const' declarations, since 'var'
declarations are expected to leak.

Fixes: #2103
2020-05-07 23:31:49 +02:00
Matthew Olsson
ab652fa1ee LibJS: Add String.raw 2020-05-07 23:05:55 +02:00
Matthew Olsson
b5f1df57ed LibJS: Add raw strings to tagged template literals
When calling a function with a tagged template, the first array that is
passed in now contains a "raw" property with the raw, escaped strings.
2020-05-07 23:05:55 +02:00
Emanuele Torre
6bbd0a18a1 LibJS: Fix shellcheck warnings in Tests/run-tests 2020-05-07 12:20:41 +02:00
Matthew Olsson
107ca2e4ba LibJS: Add function call spreading
Adds support for the following syntax:

    myFunction(...x, ...[1, 2, 3], ...o.foo, ...'abcd')
2020-05-06 19:19:02 +02:00
Matthew Olsson
838390171c LibJS: Function.length respects default and rest parameters
"[Function.length is] the number of formal parameters. This number
excludes the rest parameter and only includes parameters before
the first one with a default value." - MDN
2020-05-06 17:40:56 +02:00
Linus Groh
4d20cf57db LibJS: Implement tagged template literals (foobar)
To make processing tagged template literals easier, template literals
will now add one empty StringLiteral before and after each template
expression *if* there's no other string - e.g.:

`${foo}` -> "", foo, ""
`test${foo}${bar}test` -> "test", foo, "", bar, "test"

This also matches the behaviour of many other parsers.
2020-05-06 14:49:53 +02:00
Matthew Olsson
419bce6915 LibJS: Fix syntax error for arrow function non-decl variable assignment
A regression was introduced in dc9b4da where the parser would
incorrectly parse the assignment of arrow functions to (non-declaration)
variables. For example, consider:

    a = () => {}

Because the parser was aware of default parameters, in
try_parse_arrow_function, the equals sign would be interpreted as a
default argument, leading to incorrect parsing of the overall
expression. Also resulted in some funny behavior
(a = () => {} => {} worked just fine!).

The simple fix is to only look for default parameters if the arrow
function is required to have parenthesis.
2020-05-06 12:21:29 +02:00
Linus Groh
72d2bd56ce LibJS: Implement modulo assignment operator (%=) 2020-05-05 11:12:27 +02:00
Linus Groh
a2e1f1a872 LibJS: Implement exponentiation assignment operator (**=) 2020-05-05 11:12:27 +02:00
Linus Groh
3e754a15d4 LibJS: Implement bitwise assignment operators (&=, |=, ^=) 2020-05-05 11:12:27 +02:00
Linus Groh
8e4301dea6 LibJS: Add test for assignment operators 2020-05-05 11:12:27 +02:00
Linus Groh
454c1e6bbe LibJS: Implement rest parameters 2020-05-04 23:30:52 +02:00
mattco98
adb4accab3 LibJS: Add template literals
Adds fully functioning template literals. Because template literals
contain expressions, most of the work has to be done in the Lexer rather
than the Parser. And because of the complexity of template literals
(expressions, nesting, escapes, etc), the Lexer needs to have some
template-related state.

When entering a new template literal, a TemplateLiteralStart token is
emitted. When inside a literal, all text will be parsed up until a '${'
or '`' (or EOF, but that's a syntax error) is seen, and then a
TemplateLiteralExprStart token is emitted. At this point, the Lexer
proceeds as normal, however it keeps track of the number of opening
and closing curly braces it has seen in order to determine the close
of the expression. Once it finds a matching curly brace for the '${',
a TemplateLiteralExprEnd token is emitted and the state is updated
accordingly.

When the Lexer is inside of a template literal, but not an expression,
and sees a '`', this must be the closing grave: a TemplateLiteralEnd
token is emitted.

The state required to correctly parse template strings consists of a
vector (for nesting) of two pieces of information: whether or not we
are in a template expression (as opposed to a template string); and
the count of the number of unmatched open curly braces we have seen
(only applicable if the Lexer is currently in a template expression).

TODO: Add support for template literal newlines in the JS REPL (this will
cause a syntax error currently):

    > `foo
    > bar`
    'foo
    bar'
2020-05-04 16:46:31 +02:00
Linus Groh
32742709dc LibJS: Support empty statements
We already skipped random semicolons in Parser::parse_program(), but now
they are properly matched and parsed as empty statements - and thus
recognized as a valid body of an if / else / while / ... statement.
2020-05-03 12:57:48 +02:00
Linus Groh
25cf0da2fb LibJS: Set name of anonymous functions during assignment 2020-05-03 11:41:56 +02:00
Matthew Olsson
5e66f1900b LibJS: Add function default arguments
Adds the ability for function arguments to have default values. This
works for standard functions as well as arrow functions. Default values
are not printed in a <function>.toString() call, as nodes cannot print
their source string representation.
2020-05-03 00:44:57 +02:00
Linus Groh
99be27b4a1 LibJS: Add "name" property to functions 2020-05-02 20:41:31 +02:00
Linus Groh
ae05dc8abc LibJS: Name functions created by "Function" "anonymous"
...as it is supposed to be.
2020-05-02 20:41:31 +02:00
Linus Groh
43c1fa9965 LibJS: Implement (no-op) debugger statement 2020-05-01 22:07:13 +02:00
Linus Groh
79b829637e LibJS: Implement most of the Reflect object 2020-05-01 16:54:01 +02:00
Linus Groh
1ba2e6768d LibJS: Implement indexed access for StringObject 2020-05-01 16:54:01 +02:00
Kesse Jones
6dbb5df81f LibJS: Add String.prototype.lastIndexOf 2020-05-01 16:50:37 +02:00
Matthew Olsson
28ef654d13 LibJS: Add object literal method shorthand 2020-05-01 12:28:40 +02:00
mattco98
683a0696f3 LibJS: Add Object.{keys,values,entries}() 2020-04-30 09:53:16 +02:00
Linus Groh
8159f45f6e LibJS: Make String.prototype.slice() generic 2020-04-29 19:14:36 +02:00
Linus Groh
cfdb7b8806 LibJS: Make (most) String.prototype functions generic
I.e. they don't require the |this| value to be a string object and
"can be transferred to other kinds of objects for use as a method" as
the spec describes it.
2020-04-29 18:53:21 +02:00
mattco98
95abcc3722 LibJS: Implement correct object property ordering
This commit introduces a way to get an object's own properties in the
correct order. The "correct order" for JS object properties is first all
array-like index properties (numeric keys) sorted by insertion order,
followed by all string properties sorted by insertion order.

Objects also now print correctly in the repl! Before this commit:

courage ~/js-tests $ js
> ({ foo: 1, bar: 2, baz: 3 })
{ bar: 2, foo: 1, baz: 3 }

After:

courage ~/js-tests $ js
> ({ foo: 1, bar: 2, baz: 3 })
{ foo: 1, bar: 2, baz: 3 }
2020-04-29 18:47:03 +02:00
Kesse Jones
58f6f50de4 LibJS: Add String.prototype.slice 2020-04-29 18:35:18 +02:00
Linus Groh
d4ec38097f LibJS: Return undefined in Array.prototype.{pop,shift} for empty values 2020-04-29 09:38:25 +02:00
Linus Groh
da0ab16f01 LibJS: Don't handle arrays separately in Value::to_number()
Now that Array.prototype.join() is producing the correct results we
can remove the separate code path for arrays in Value::to_number()
and treat them like all other objects - using to_primitive() with
number as the preferred type and then calling to_number() on the
result.

This is how the spec descibes it.

This also means we don't crash anymore when trying to coerce
[<empty>] to a number - it now does the following:

[<empty>] - to string - "" - to number - 0
[<empty>, <empty>] - to string - "," - to number - NaN
2020-04-29 01:30:59 +02:00
Linus Groh
6d6cd64689 LibJS: Skip undefined and null in join_array_with_separator()
This it being used in Array.prototype.{join,toString}() - and now
adhering to the spec: [undefined, null].join() === ","
2020-04-29 01:30:59 +02:00
Linus Groh
8ad11df89f LibJS: Handle exception in for loop test execution 2020-04-28 23:11:18 +02:00
mattco98
104969a9f5 LibJS: Add spreading in object literals
Supports spreading strings, arrays, and other objects within object
literals.
2020-04-28 20:37:21 +02:00
Linus Groh
3152559422 LibJS: Call Array.prototype.findIndex() callback for empty elements
If the array value at the current index is empty, the callback will
be called with undefined as value.
2020-04-28 20:15:38 +02:00
Linus Groh
823cc7bc1c LibJS: Call Array.prototype.find() callback for empty elements
If the array value at the current index is empty, the callback will
be called with undefined as value.
2020-04-28 20:15:38 +02:00
Linus Groh
ad8abce8a5 LibJS: Let Array.prototype.map() resize new array before loop
Currently we would create an empty array of size 0 and appening results
of the callback function while skipping empty values.

This is incorrect, we should be initializing a full array of the correct
size beforehand and then inserting the results while still skipping
empty values.

Wrong: new Array(5).map(() => {}) // []
Right: new Array(5).map(() => {}) // [<empty> * 5]
2020-04-28 20:15:38 +02:00
Linus Groh
0a0ba64383 LibJS: Handle Object.prototype.hasOwnProperty() with no arg correctly
I.e. the same as hasOwnProperty(undefined) or
hasOwnProperty("undefined") :^)
2020-04-28 20:03:50 +02:00
Linus Groh
30fe1b5d58 LibJS: Support spreading of strings and string objects 2020-04-28 15:35:24 +02:00
Andreas Kling
24cce3674b LibJS: Support o.f++ :^)
This patch teaches UpdateExpression how to use a Reference. Some other
changes were necessary to keep tests working:
A Reference can now also refer to a local or global variable. This is
not fully aligned with the spec since we don't have a Record concept.
2020-04-28 15:07:08 +02:00
Andreas Kling
3c4a9e421f LibJS: Allow "delete someGlobalVariable"
This is solved by allowing Identifier nodes to produce a Reference with
the global object as base.
2020-04-28 15:07:08 +02:00
Linus Groh
3a12a8a348 LibJS: Make Number.isInteger() test pass on Serenity
The parser doesn't like many decimals, an issue with our strtod()
implementation. Let's use division instead - all tests green again :^)
2020-04-28 14:49:43 +02:00
Kesse Jones
1c4d776ccc LibJS: Add Array.prototype.some 2020-04-28 13:11:10 +02:00
Linus Groh
c14fedd562 LibJS: Add bounds check to Array.prototype.{find,findIndex}
The number of iterations is limited to the initial array size, but we
still need to check if the array did shrink since then before accessing
each element.

Fixes #1992.
2020-04-28 13:08:19 +02:00
mattco98
80fecc615a LibJS: Add spreading in array literals
Implement the syntax and behavor necessary to support array literals
such as [...[1, 2, 3]]. A type error is thrown if the target of the
spread operator does not evaluate to an array (though it should
eventually just check for an iterable).

Note that the spread token's name is TripleDot, since the '...' token is
used for two features: spread and rest. Calling it anything involving
'spread' or 'rest' would be a bit confusing.
2020-04-27 11:32:18 +02:00
Kesse Jones
36c00e8078 LibJS: Add Array.prototype.findIndex 2020-04-27 11:23:23 +02:00
Linus Groh
14c7988eea LibJS: Implement Number.isInteger() 2020-04-26 20:36:59 +02:00
Linus Groh
7bd6b58b29 LibJS: Implement Number.isNaN()
Like the global isNaN() without the number coercion.
2020-04-26 20:36:59 +02:00
Linus Groh
c350f5ae67 LibJS: Implement Number.isFinite()
Like the global isFinite() without the number coercion.
2020-04-26 20:36:59 +02:00
Andreas Kling
2778d077e5 LibJS: Grow storage when adding a property to uniquely-shaped Object
Normally the storage would be expanded by set_shape() upon transition
to a new shape, but if the shape is already unique, there is no new
transition so we have to expand the storage manually.
2020-04-26 19:05:08 +02:00
Andreas Kling
f897c41092 LibJS: Implement basic support for the "delete" operator
It turns out "delete" is actually a unary op :)
This patch implements deletion of object properties, it doesn't yet
work for casually deleting properties from the global object.

When deleting a property from an object, we switch that object to
having a unique shape, no longer sharing shapes with others.
Once an object has a unique shape, it no longer needs to care about
shape transitions.
2020-04-26 15:51:07 +02:00
Linus Groh
38ba13e912 LibJS: Implement Object.is()
Basically === with two particularities: comparing NaN to itself is
considered equal and comparing +0 and -0 is not.
2020-04-26 13:53:05 +02:00
Kesse Jones
838127df35 LibJS: Add String.prototype.includes 2020-04-25 16:54:25 +02:00
Kesse Jones
b0ca174d49 LibJS: Add Array.prototype.find 2020-04-24 17:10:19 +02:00
Linus Groh
746dd5b190 LibJS: Implement computed properties in object expressions 2020-04-23 23:56:04 +02:00
Linus Groh
11728b7db5 LibJS: Implement 'in' operator 2020-04-23 19:38:13 +02:00
Linus Groh
396ecfa2d7 LibJS: Implement bitwise unsigned right shift operator (>>>) 2020-04-23 19:38:13 +02:00
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
Jack Karamanian
1fa0c7304d LibJS: Implement Function.prototype.bind() 2020-04-21 12:23:07 +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
0718f216af LibJS: Add assertThrowsError() test function 2020-04-20 11:38:01 +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
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
Kesse Jones
856ab9c600 LibJS: Add Array.prototype.slice 2020-04-19 02:09:06 +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
Linus Groh
d14ddb6461 LibJS: Implement nullish coalescing operator (??) 2020-04-18 12:34:13 +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
Kesse Jones
b0b204822f LibJS: Add String.prototype.substring 2020-04-16 18:47:24 +02:00
Kesse Jones
7725b1970e LibJS: Add String.prototype.concat 2020-04-16 16:36:51 +02:00
Linus Groh
640a24dce8 LibJS: Remove outdated FIXME now that we have lexical environments 2020-04-16 09:41:07 +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
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
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
Linus Groh
5da1a40ccf LibJS: Support multiple arguments in Array.prototype.push() 2020-04-14 13:40:04 +02:00
Brian Gianforcaro
d74ad81402 js/LibJS: Move test functions to pure javascript.
The addition of assert functions to Userland/js
was done before we had load(..) implemented. Now
that it exists, it seems like the right move the
test helper functions to pure javascript instead
of poluting js with random global functions.
2020-04-14 12:55:31 +02:00
Stephan Unverwerth
9477efe970 LibJS: Handle HTML-style comments 2020-04-14 12:54:09 +02:00
Stephan Unverwerth
8f82f6c574 LibJS: Add more number test cases for #1680 2020-04-13 17:23:22 +02:00
Andreas Kling
ac7459cb40 LibJS: Hoist variable declarations to the nearest relevant scope
"var" declarations are hoisted to the nearest function scope, while
"let" and "const" are hoisted to the nearest block scope.

This is done by the parser, which keeps two scope stacks, one stack
for the current var scope and one for the current let/const scope.

When the interpreter enters a scope, we walk all of the declarations
and insert them into the variable environment.

We don't support the temporal dead zone for let/const yet.
2020-04-13 17:22:23 +02:00
Linus Groh
b9415dc0e9 LibJS: Use assertNotReached() in tests 2020-04-13 16:28:50 +02:00
Linus Groh
92a9fe0e49 LibJS: Fix test files indentation (4 spaces) 2020-04-13 16:28:50 +02:00
Brian Gianforcaro
2a65db7c12
LibJS: Implement Error.prototype.name setter (#1776)
The MDN example for creating a custom error type in javascript uses:

    function CustomError(foo, message, fileName, lineNumber) {
        var instance = new Error(message, fileName, lineNumber);
        instance.name = 'CustomError';
        instance.foo = foo;
        Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
        return instance;
    }

The name property on the Error prototype needs to be settable for
this to work properly.
2020-04-13 11:19:53 +02:00
Stephan Unverwerth
bbd592cb6c LibJS: Tweak FunctionPrototype::to_string and constructors
The output of FunctionPrototype::to_string is now more in line
with the output in Firefox. The builtin constructors have been
extended to include their function name in the output.
2020-04-13 01:14:21 +02:00
Brian Gianforcaro
0d41e542b7 LibJS: Throw on assignment of an const variable
Was stubbed out as an assert, should be handled with a runtime exception.
2020-04-13 01:12:31 +02:00
Linus Groh
f226746394 LibJS: Handle Infinity in Value::to_number() 2020-04-12 14:39:38 +02:00
4ourbit
02c9f4c951
LibJS: Improve Object.defineProperty test 2020-04-10 23:33:02 +02:00
Linus Groh
31505dde7e LibJS: Add String.prototype.pad{Start,End}() 2020-04-10 16:37:04 +02:00
Linus Groh
7636dee2cb LibJS: Remove assert function from Object.defineProperty() test 2020-04-10 16:37:04 +02:00
Linus Groh
0243ac5d04 LibJS: Remove mock String.prototype from tests 2020-04-10 15:51:39 +02:00
Linus Groh
32c27afdf0 LibJS: Add String.prototype.toString() 2020-04-10 15:49:40 +02:00
Andreas Kling
6f3ea75569 LibJS: Add String constructor :^) 2020-04-10 14:14:02 +02:00
Andreas Kling
070a8f2689 LibJS: Boolean, Number and String prototypes should have values too
It appears that calling .valueOf() on an objectified primitive's
prototype should return a value after all.

This matches what other engines are doing.
2020-04-10 13:09:35 +02:00
Barney Wilks
4f48fcdb94 LibJS: Add tests for exception if assignment LHS is invalid 2020-04-10 11:27:10 +02:00
Andreas Kling
8286f8b996 LibJS: Add property configuration transitions
Object.defineProperty() can now change the attributes of a property
already on the object. Internally this becomes a shape transition with
the TransitionType::Configure. Such transitions don't expand the
property storage capacity, but rather simply keep attributes up to date
when generating a property table.
2020-04-10 00:36:06 +02:00
Andreas Kling
e6d920d87d LibJS: Add Object.defineProperty() and start caring about attributes
We now care (a little bit) about the "configurable" and "writable"
property attributes.

Property attributes are stored together with the property name in
the Shape object. Forward transitions are not attribute-savvy and will
cause poor Shape reuse in the case of multiple same-name properties
with different attributes.

Oh, and this patch also adds Object.getOwnPropertyDescriptor() :^)
2020-04-10 00:36:06 +02:00
Linus Groh
c06a6c67d5 LibJS: Add globalThis
We already have "global" as a way to access the global object in js(1)
(both REPL and script mode). This replaces it with "globalThis", which
is available in all environments, not just js.
2020-04-09 15:58:49 +02:00
Linus Groh
531335f57c LibJS: Handle empty values in Array.prototype.toString() 2020-04-08 20:01:42 +02:00
Andreas Kling
f07f8d5a44 LibJS: Add "constructor" property to constructor prototypes 2020-04-08 11:08:07 +02:00
Linus Groh
5ecc7e6a1c LibJS: Add Number.isSafeInteger() 2020-04-07 21:28:43 +02:00
Linus Groh
b7032b4972 LibJS: Add Number constants 2020-04-07 21:28:43 +02:00
Linus Groh
f631f6a2e6 LibJS: Add Number() 2020-04-07 17:25:50 +02:00
DexesTTP
e586dc285a LibJS: Allow parsing numeric and string literals in object expressions
Also updated the object-basic.js test to include this change
2020-04-07 09:05:16 +02:00
Linus Groh
22f20cd51d LibJS: Add String.prototype.toUpperCase() 2020-04-07 08:50:35 +02:00
Jack Karamanian
edae926cb0 LibJS: Add Boolean constructor object 2020-04-07 08:41:25 +02:00
Jack Karamanian
57bd194e5a LibJS: Return false for NaN numbers in Value::to_boolean() 2020-04-07 08:41:25 +02:00
DexesTTP
4a9485f830 LibJS: Fix impossible member access for negative integers
The PropertyName class able to match a number or an array can only
accept positive numerical values. However, the computed_property_name
method sometimes returned negative values.

This commit also adds a basic object access test case.
2020-04-06 21:45:20 +02:00
Andreas Kling
cb18b2c74d LibJS: Add String.prototype.toLowerCase() 2020-04-06 20:46:08 +02:00
Emanuele Torre
1d6c8724b9 LibJS: Fix some tests for Math.min()
In some of the tests in Math.min.js, we were testing Math.max() instead
of Math.min()
2020-04-06 15:14:34 +02:00
Linus Groh
f5dacfbb5b LibJS: Add Math.{cos,sin,tan}() 2020-04-06 10:58:16 +02:00
Andreas Kling
003741db1c LibJS: Add Math.min() 2020-04-06 08:26:26 +02:00
Linus Groh
9e7dcaa106 LibJS: Return -Infinity in Math.max() with no argument 2020-04-05 19:30:47 +02:00
Andreas Kling
8bfee015bc LibJS: Make Object::to_string() call the "toString" property if present 2020-04-05 18:19:56 +02:00
Andreas Kling
a7b21ec0f4 LibJS: Add Array.prototype.toString() 2020-04-05 18:07:41 +02:00
Linus Groh
4509350391 LibJS: Remove assert function from exponentiation-basic.js 2020-04-05 16:01:46 +02:00
Linus Groh
30ba2c7cec LibJS: Simplify Math-constants.js test
By borrowing an "expect close" function from LibM/TestMath.cpp, we can
make this a lot simpler. Also the parser now understands decimals!
2020-04-05 16:01:46 +02:00
Linus Groh
0d7a1c3157 LibJS: Update to-number-basic.js test
Uncomment lines that are now parsing correctly :^)
2020-04-05 16:01:46 +02:00
Stephan Unverwerth
500f6d9e3a LibJS: Add numeric literal parsing for different bases and exponents 2020-04-05 16:01:22 +02:00
Linus Groh
0403845d3e LibJS: Implement exponentiation (** operator) 2020-04-05 15:32:06 +02:00
Brian Gianforcaro
bc40908d32 LibJS: Use the native assert() implementation now avaiable in 'js -t'
Switch the LibJS test suite to use the native assert implementation
surfaced inside the js repl when it's launched in test mode.
2020-04-05 15:28:45 +02:00
Brian Gianforcaro
1e67efc5c1 Lagom: Add clang address/memory/undefined-behavior analyzer support
Adding the ability to turn on Clang analyzer support in the Lagom build.
Right now the following are working warning free on the LibJS test suite:

 -DENABLE_MEMORY_SANITIZER:BOOL=ON

 -DENABLE_ADDRESS_SANITIZER:BOOL=ON

The following analyzer produces errors when running the LibJS test suite:

 -DENABLE_UNDEFINED_SANITIZER:BOOL=ON
2020-04-05 12:49:06 +02:00
Andreas Kling
058c614110 LibJS: Fix missing paren in modulo-basic.js test 2020-04-05 11:19:00 +02:00
Brian Gianforcaro
240a5b5fd7 LibJS: Add support for Math.ceil() and Math.trunc()
Introduce support for the both of these Math methods.
Math.trunc is implemented in terms of Math.ceil or Math.floor
based on the input value. Added tests as well.
2020-04-05 10:56:23 +02:00
Brian Gianforcaro
b8cef3a2d3 LibJS: Add support for floating point modulous
This change implements floating point mod based on the algorithm
used in LibM's fmod() implementation. To avoid taking a dependency
on LibM from LibJS I reimplemented the formula in LibJS.

I've incuded some of the example MDM test cases as well.
This surfaced and issue handling NaN which I've fixed as well.
2020-04-05 10:38:13 +02:00
Brian Gianforcaro
41bfff1abe LibJS: Correctness fixes for bitwise_or, address FIXME's in test. 2020-04-05 10:37:02 +02:00
Brian Gianforcaro
4e54d0ff21 LibJS: Add support for arbitrary arguments to Math.max
Address the FIXME in MathObject::max to handle an arbitrary
number of arguments. Also adding a test case to verify the
behavior of Math.max() while I'm here.
2020-04-05 09:28:58 +02:00
Andreas Kling
9ebd066ac8 LibJS: Add support for "continue" inside "for" statements :^) 2020-04-05 00:22:42 +02:00
Andreas Kling
e3b92caa6d LibJS: Make "break" actually work inside "switch" 2020-04-05 00:09:48 +02:00
Andreas Kling
97cd1173fa LibJS: Add String.prototype.indexOf() 2020-04-04 23:44:29 +02:00
Andreas Kling
d4dfe7e525 LibJS: Add Math.sqrt() 2020-04-04 22:44:48 +02:00
Andreas Kling
d155491122 LibJS: Add basic Array constructor
We only support Array() with 0 or 1 parameters so far.
2020-04-04 22:28:21 +02:00
Andreas Kling
5e40aa182b LibJS: Support VariableDeclaration with multiple declarators
This patch adds support in the parser and interpreter for this:

    var a = 1, b = 2, c = a + b;

VariableDeclaration is now a sequence of VariableDeclarators. :^)
2020-04-04 21:47:12 +02:00
Andreas Kling
f8393b80e3 LibJS: Add support for do..while statements 2020-04-04 21:29:23 +02:00
Andreas Kling
644ff1bbfd LibJS: Add basic support for modulo (%) in binary expressions 2020-04-04 21:17:34 +02:00
Andreas Kling
9c8363bb5f LibJS: Allow "for" statement without curly braces around body 2020-04-04 21:09:06 +02:00
Linus Groh
2944039d6b LibJS: Add Function() and Function.prototype 2020-04-04 15:58:49 +02:00
Linus Groh
4d931b524d LibJS: Add length property to ScriptFunction 2020-04-04 15:58:49 +02:00
Stephan Unverwerth
520311eb8b LibJS: Add short circuit logical evaluation
When evaluating logical binop expressions, the rhs must not be
evaluated if the lhs leads to the whole expression not being
truthy.
2020-04-03 19:17:52 +02:00
Linus Groh
6e5f9e20eb LibJS: Fix logical expressions
The current implementation of logical AND (&&) and logical OR (||)
always returns a boolean - this is not correct.
2020-04-03 16:32:36 +02:00
Linus Groh
a58640ce6b LibJS: Parse binary bitwise operators
The Lexer and AST already have all the functionality required in place,
so this is just updating Parser::match_secondary_expression() and
Parser::parse_expression() to handle TokenType::{Ampersand,Pipe,Caret},
as well as adding some tests.
2020-04-03 14:10:09 +02:00
Andreas Kling
0622181d1f LibJS: Implement ConditionalExpression (ternary "?:" operator) 2020-04-03 12:15:14 +02:00
Linus Groh
94afcb54de LibJS: Implement Error.prototype.toString() 2020-04-03 09:07:05 +02:00
Linus Groh
543c6e00db LibJS: Implement Infinity 2020-04-02 21:52:15 +02:00
Andreas Kling
99aab4470a LibJS: Object::put() shouldn't create own properties on prototype chain
Unless there is a setter present on the prototype chain, put() should
only set own properties on the object itself.

Fixes #1588.
2020-04-02 21:36:14 +02:00
Linus Groh
a62230770b LibJS: Implement unary plus / minus 2020-04-02 19:55:45 +02:00
Jack Karamanian
bb15b37228 LibJS: Evaluate CallExpression arguments before pushing a CallFrame 2020-04-02 08:50:28 +02:00
Linus Groh
a0da97cb5a LibJS: Add NaN to global object 2020-04-01 22:09:37 +02:00
Linus Groh
ee6472fef2 LibJS: Implement Error function/constructor 2020-04-01 20:47:37 +02:00
Linus Groh
849e2c77e4 LibJS: Implement constructor/non-constructor function calls
This adds Function::construct() for constructor function calls via `new`
keyword. NativeFunction doesn't have constructor behaviour by default,
ScriptFunction simply calls call() in construct()
2020-04-01 20:18:36 +02:00
Jack Karamanian
098f1cd0ca LibJS: Add support for arrow functions 2020-03-30 15:41:36 +02:00
Linus Groh
fb0401871c LibJS: Throw TypeError when calling non-function object
We now have "undefined is not a function" :^)
2020-03-30 14:43:58 +02:00
Linus Groh
d4e3688f4f LibJS: Start implementing Date :^)
This adds:

- A global Date object (with `length` property and `now` function)
- The Date constructor (no arguments yet)
- The Date prototype (with `get*` functions)
2020-03-30 14:11:54 +02:00
Linus Groh
0a94661c14 LibJS: Implement String.prototype.startsWith() 2020-03-29 19:37:16 +02:00
Linus Groh
402fd5a3a3 LibJS: Add tests for Math constants 2020-03-29 17:35:08 +02:00