Commit graph

518 commits

Author SHA1 Message Date
Linus Groh
8d1e6e9175 LibJS: Don't repeat attributes in {Date,Symbol}Constructor 2021-06-13 00:58:25 +01:00
Linus Groh
7327a28ccc LibJS: Add ECMA-262 section/title/URL comments almost everywhere
As mentioned on Discord earlier, we'll add these to all new functions
going forward - this is the backfill. Reasons:

- It makes you look at the spec, implementing based on MDN or V8
  behavior is a no-go
- It makes finding the various functions that are non-compliant easier,
  in the future everything should either have such a comment or, if it's
  not from the spec at all, a comment explaining why that is the case
- It makes it easier to check whether a certain abstract operation is
  implemented in LibJS, not all of them use the same name as the spec.
  E.g. RejectPromise() is Promise::reject()
- It makes it easier to reason about vm.arguments(), e.g. when the
  function has a rest parameter
- It makes it easier to see whether a certain function is from a
  proposal or Annex B

Also:

- Add arguments to all functions and abstract operations that already
  had a comment
- Fix some outdated section numbers
- Replace some ecma-international.org URLs with tc39.es
2021-06-13 00:33:28 +01:00
Idan Horowitz
322c8a3995 LibJS: Add the MapIterator built-in and the key/values/entries methods
While this implementation should be complete it is based on HashMap's
iterator, which currently follows bucket-order instead of the required
insertion order. This can be simply fixed by replacing the underlying
HashMap member in Map with an enhanced one that maintains a linked
list in insertion order.
2021-06-13 00:33:18 +01:00
Idan Horowitz
6c0d5163a1 LibJS: Add most of the Map.prototype methods
Specifically all aside from "keys", "values" and "entries" which
require an implementation of the MapIterator object.
2021-06-13 00:33:18 +01:00
Idan Horowitz
a96ac8bd56 LibJS: Add the Map built-in object 2021-06-13 00:33:18 +01:00
Idan Horowitz
f9d58ec0b4 LibJS: Move ValueTraits to Value.h and add special case for -0.0
This will allow us to use these traits for other hash-based containers
(like Map). This commit also adds a special case for negative zero
values, because while the equality check used same_value_zero which is
negative/positive zero insensitive, the hash was not.
2021-06-13 00:33:18 +01:00
Idan Horowitz
3c83298a26 LibJS: Use undefined as the fallback value for iterable entry key/value
As defined in OdinaryGet in the specification.
2021-06-12 22:34:28 +01:00
Idan Horowitz
bd9e20ef79 LibJS: Add the Object.getOwnPropertySymbols method 2021-06-12 18:39:23 +01:00
Idan Horowitz
a2da3f97ef LibJS: Remove argument count checks in Object.* methods
These are inconsistent with the specification.
2021-06-12 18:39:23 +01:00
Idan Horowitz
b9d4dd6850 LibJS: Add the WeakRef.prototype.deref method
This is the only exposed method of the WeakRef built-in.
2021-06-12 18:39:23 +01:00
Idan Horowitz
7eba63a8a3 LibJS: Add the WeakRef built-in object 2021-06-12 18:39:23 +01:00
Idan Horowitz
6913f06b6f LibJS: Store and maintain an "execution generation" counter
This counter is increased each time a synchronous execution sequence
completes, and will allow us to emulate the abstract operations
AddToKeptObjects & ClearKeptObjects efficiently.
2021-06-12 18:39:23 +01:00
davidot
e044a3e428 LibJS: Add Array.prototype.keys() 2021-06-12 14:40:34 +01:00
Andreas Kling
dc65f54c06 AK: Rename Vector::append(Vector) => Vector::extend(Vector)
Let's make it a bit more clear when we're appending the elements from
one vector to the end of another vector.
2021-06-12 13:24:45 +02:00
Linus Groh
7e1bffdeb8 LibJS: Implement Object.assign() 2021-06-12 11:36:17 +01:00
Idan Horowitz
77c2db4183 LibJS: Add all of the WeakMap.prototype methods (delete, get, has, set) 2021-06-12 10:44:28 +01:00
Idan Horowitz
39554f3787 LibJS: Add the WeakMap built-in object 2021-06-12 10:44:28 +01:00
Idan Horowitz
1a8ee5d8d7 LibJS: Generify the garbage collector's weak container notifications
This will allow us to use the same interface for other JS weak
containers like the WeakMap & WeakRef.
2021-06-12 10:44:28 +01:00
Andreas Kling
06fdc26656 LibJS: Fix all clang-tidy warnings in Bytecode/Op.h
- Add missing explicit to constructors
- Use move() where appropriate
2021-06-12 11:22:46 +02:00
Gunnar Beutner
6a78b44c22 LibJS: Add missing length() method for NewArray 2021-06-12 11:14:55 +02:00
Linus Groh
633f604c47 LibJS: Fix attributes of Promise.prototype
This was missing a 0 at the end to make it non-writable, non-enumerable,
non-configurable.
2021-06-12 01:19:07 +01:00
Linus Groh
1d7514d51e LibJS: Hide gc() dbgln() behind #ifdef __serenity__
This spams to stdout when using Lagom, and is therefore included in
test-js output. Don't need that.
2021-06-12 01:09:45 +01:00
Idan Horowitz
a1f5357ad3 LibJS: Expose Symbol.species properties as getters
As required by the specification.
2021-06-12 00:44:15 +01:00
Idan Horowitz
7f6d3818a2 LibJS: Add the Object::define_native_accessor method
This is very similar to Object::define_native_property, but here the
native functions are exported as standalone JS getter and setter
functions, instead of being transparently called by interactions with
the property.
2021-06-12 00:44:15 +01:00
Gal Horowitz
b47d117bd2 LibJS: Add bytecode generation for simple ObjectExpressions
Bytecode is now generated for object literals which only contain simple
key-value pairs (i.e. no spread, getters or setters)
2021-06-11 22:44:17 +02:00
Linus Groh
862ba64037 LibJS: Implement the Error Cause proposal
Currently stage 3. https://github.com/tc39/proposal-error-cause
2021-06-11 21:34:05 +01:00
Linus Groh
8d77a3297a LibJS: Improve Error/NativeError tests
Some of this stuff is already tested properly in the name and message
prototype tests, so let's focus on covering all error types here as well
instead.
2021-06-11 21:34:05 +01:00
Linus Groh
cbd7437d40 LibJS: Implement AggregateError 2021-06-11 18:49:50 +01:00
Linus Groh
2f03eb8628 LibJS: Only initialize in add_constructor() if not already done 2021-06-11 18:49:50 +01:00
Linus Groh
ad3242bab7 LibJS: Rename JS_ENUMERATE_{ERROR_SUBCLASSES => NATIVE_ERRORS}
The fact that they *are* subclasses is an implementation detail and
should not be highlighted. The spec calls these NativeErrors, so let's
use that.
Also added a comment explaining *why* they inherit from Error - I was
about to change that :^)
2021-06-11 18:49:50 +01:00
Gal Horowitz
0e10dec324 LibJS: Parse only AssignmentExpressions in ComputedPropertyNames
The property name in an object literal can either be a literal or a
computed name, in which case any AssignmentExpression can be used, we
now only parse AssignmentExpression instead of the previous incorrect
behaviour which allowed any Expression (Specifically, comma
expressions).
2021-06-11 17:25:14 +01:00
Ali Mohammad Pur
8b3f8879c1 LibJS: Use an enum class instead of 'bool is_generator'
This avoid confusion in the order of the multiple boolean parameters
that exist.
2021-06-11 19:42:58 +04:30
Idan Horowitz
f5a978c1aa LibWeb: Set a detach key for ArrayBuffers returned from WASM
As required by the specification:
`Set buffer.[[ArrayBufferDetachKey]] to "WebAssembly.Memory".`
2021-06-11 13:38:25 +01:00
Marcin Gasperowicz
a64089092f LibJS: Implement bytecode generation for switch 2021-06-11 13:12:26 +02:00
Andreas Kling
af48a066c6 LibJS: Add bytecode generation for FunctionExpression :^) 2021-06-11 10:46:46 +02:00
Andreas Kling
749a3b9245 LibJS: Move is_arrow_function() from FunctionExpression to FunctionNode
This will make it easier to write bytecode generation for function
expressions in just a moment.
2021-06-11 10:45:49 +02:00
Linus Groh
17da54d49c LibJS: Fix two accidentally incorrect ScriptFunction constructions
The addition of an is_generator parameter broke this, as is_strict was
being passed in, causing an assertion.
This is being addressed by changing it to an enum in #7981, but in the
meantime let's just fix these two cases.
2021-06-11 01:21:46 +01:00
Linus Groh
f218a4b548 LibJS: Set Error message attributes to writable and configurable only
20.5.1.1 Error ( message )

    When the Error function is called with argument message, the
    following steps are taken:

    [...]
    3b. Let msgDesc be the PropertyDescriptor {
        [[Value]]: msg,
        [[Writable]]: true,
        [[Enumerable]]: false,
        [[Configurable]]: true
    }.
    3c. Perform ! DefinePropertyOrThrow(O, "message", msgDesc).
2021-06-11 00:23:13 +01:00
Linus Groh
0e38c9b2f7 LibJS: Set NativeError constructors' prototype to Error constructor
The FunctionPrototype is correct for ErrorConstructor itself:

    20.5.2 Properties of the Error Constructor

    The Error constructor:
    - has a [[Prototype]] internal slot whose value is
      %Function.prototype%.

However, not for all the other "NativeError" constructors:

    20.5.6.2 Properties of the NativeError Constructors

    Each NativeError constructor:
    - has a [[Prototype]] internal slot whose value is %Error%.
2021-06-11 00:23:13 +01:00
Andreas Kling
9ee5029bc5 LibJS: Basic bytecode support for computed member expressions
Expressions like foo[1 + 2] now work, and you can assign to them
as well! :^)
2021-06-11 00:36:18 +02:00
Ali Mohammad Pur
b47246ec70 LibJS: Switch AST.{h,cpp} to east const 2021-06-11 00:30:09 +02:00
Ali Mohammad Pur
3234697eca LibJS: Implement generator functions (only in bytecode mode) 2021-06-11 00:30:09 +02:00
Ali Mohammad Pur
c53a86a3fe LibJS: Resolve the `this' value in call expression bytecode 2021-06-11 00:30:09 +02:00
Ali Mohammad Pur
4cfdfb6a88 LibJS: Automatically split linear bytecode into multiple blocks
...instead of crashing :^)
2021-06-11 00:30:09 +02:00
Idan Horowitz
8527f00065 LibJS: Allow and check for detached ArrayBuffers
This is required by the specification and will be used for the
$262.detachArrayBuffer method in test262.
2021-06-10 22:44:26 +01:00
Idan Horowitz
7d6db3f09b LibJS: Throw TypeError on non-object this value in ArrayBuffer methods
`1. If Type(O) is not Object, throw a TypeError exception.`
2021-06-10 22:44:26 +01:00
Idan Horowitz
bc95201aaf LibJS: Dont mask non-RangeError exceptions in ArrayBuffer construction
Non-RangeError exceptions can be thrown by user implementations of
valueOf (which are called by to_index), and the specification disallows
changing the type of the thrown error.
2021-06-10 22:44:26 +01:00
Idan Horowitz
8dc86c6aad LibJS: Bring ArrayBuffer.prototype.slice closer to spec
The exception order was incorrect in the old implementation, and it
did not use the Symbol.species constructor as required by the spec.
2021-06-10 22:44:26 +01:00
Idan Horowitz
b041108a1e LibJS: Explicitly return and accept a Function* in species_constructor
The second argument (the default constructor) and the return value have
to be constructors (as a result functions), so we can require that
explicitly by using appropriate types.
2021-06-10 22:44:26 +01:00
Andreas Kling
93a07ba962 LibJS: Remove GlobalObject& argument from VM::construct()
We can just get the global object from the constructor function.
2021-06-10 23:17:29 +02:00