summaryrefslogtreecommitdiff
path: root/Libraries/LibJS
AgeCommit message (Collapse)Author
2020-12-27Base+LibJS+LibWeb: Make prettier cleanLinus Groh
Also use "// prettier-ignore" comments where necessary rather than excluding whole files (via .prettierignore).
2020-12-26LibJS: Implement String.prototype.endsWith()Xavier Cooney
2020-12-26LibJS: Implement IsRegExp abstract operationXavier Cooney
This is needed by various String.prototype operations, as well as the RegExp constructor.
2020-12-24LibJS: Implement Object.prototype.propertyIsEnumerableLuke
Spec: https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable This is used by core-js, which is used by frameworks such as Vue.
2020-12-22Spreadsheet: Override `visit_edges()` and visit stored JS objectsAnotherTest
...and don't let them leak out of their evaluation contexts. Also keep the exceptions separate from the actual values. This greatly reduces the number of assertions hit while entering random data into a sheet.
2020-12-21Everywhere: Switch from (void) to [[maybe_unused]] (#4473)Lenny Maiorani
Problem: - `(void)` simply casts the expression to void. This is understood to indicate that it is ignored, but this is really a compiler trick to get the compiler to not generate a warning. Solution: - Use the `[[maybe_unused]]` attribute to indicate the value is unused. Note: - Functions taking a `(void)` argument list have also been changed to `()` because this is not needed and shows up in the same grep command.
2020-12-14LibJS: Don't treat '?.' followed by decimal digit as QuestionMarkPeriodLinus Groh
From the spec: https://tc39.es/ecma262/#sec-punctuators OptionalChainingPunctuator :: ?. [lookahead ∉ DecimalDigit] We were missing the lookahead and therefore incorrectly treating any '?.' as TokenType::QuestionMarkPeriod. Fixes #4409.
2020-12-09LibWeb: Apply suggested fixes.asynts
2020-12-08LibJS: Add test for Math.asin()Andreas Kling
2020-12-08LibJS: Get rid of Argument and ArgumentVectorAndreas Kling
This was used for a feature where you could pass a vector of arguments to enter_scope(). Since that way of passing arguments was not GC-aware (as vectors use C++ heap storage), let's avoid using it and make sure everything that needs to stay alive is either on the stack or in traced storage instead.
2020-12-08LibJS: Create lexical scope for "catch" on the spot when throwingAndreas Kling
2020-12-08LibJS: Stop creating a redundant lexical scope on function callAndreas Kling
We were scoping the arguments twice, first in execute_function_body(), and then again in enter_scope().
2020-12-08LibJS: Add Math.acos() and Math.asin()Andreas Kling
2020-12-08LibJS: Remove some unnecessary null checksAndreas Kling
It's okay to add nullptr to the conservative roots set. We'll just ignore it later on anyway.
2020-12-08LibJS: Use IndexedProperties::for_each_value() in update_function_name()Andreas Kling
This allows us to get rid of IndexedProperties::values_unordered().
2020-12-08LibJS: Make marking object indexed properties less allocation-heavyAndreas Kling
We were building up a vector with all the values in an object's indexed property storage, and then iterating over the vector to mark values. Instead of this, simply iterate over the property storage directly. :^)
2020-12-08LibJS: Make sure GlobalObject marks the Proxy constructorAndreas Kling
2020-12-08LibJS: Add Math.atan()Andreas Kling
2020-12-06LibJS: Use new format functions everywhereLinus Groh
This changes the remaining uses of the following functions across LibJS: - String::format() => String::formatted() - dbg() => dbgln() - printf() => out(), outln() - fprintf() => warnln() I also removed the relevant 'LogStream& operator<<' overloads as they're not needed anymore.
2020-12-06LibJS: Include source location hint in Parser::print_errors()Linus Groh
2020-12-06LibJS: Remove unused {INTERPRETER,VM}_DEBUGLinus Groh
2020-12-05LibJS: Add Float{32,64}ArrayLinus Groh
2020-12-05LibJS: Implement a very hackish "arguments" objectAndreas Kling
We now lazily create an "arguments" array inside functions when code tries to access it. This doesn't follow the spec at all but still covers a lot of the basic uses of arguments, i.e "arguments.length" and "arguments[n]"
2020-12-05LibJS: Implement parseInt()Andreas Kling
Here's a reasonably faithful implementation of ECMAScript 2021 18.2.5. Some corner cases are not covered, I've left them as FIXME's in the included unit test. Also I had to tweak JS::Value::to_i32() to always convert infinity to zero, which is in accordance with ToInt32 AFAICT.
2020-12-05LibJS: Move is_script_function() to ObjectLinus Groh
Every Object should be able to tell us if it is a ScriptFunction, not only Function objects!
2020-12-02LibJS: Use ArrayBuffer for typed array dataLinus Groh
This is how the spec describes it, and it allows sharing data between multiple typed arrays. Typed arrays now support constructing from an existing ArrayBuffer, and has been prepared for constructing from another typed array or iterator as well.
2020-12-02LibJS: Add ArrayBufferLinus Groh
2020-12-02LibJS: Use Value::to_index() in typed array constructorsLinus Groh
2020-12-02LibJS: Add Value::to_{index,length,integer_or_infinity} abstract operationsLinus Groh
We should pay more attention to using the well-defined abstract operations from the spec rather than making up our own, often slightly different rules. This is another step in that direction.
2020-12-02LibJS: Add generic InvalidLength error typeLinus Groh
We have multiple array types now, so ArrayInvalidLength has been replaced with a generic InvalidLength. Also fixes a small issue in the Array constructor, it should throw RangeError for invalid lengths, not TypeError.
2020-12-02LibJS: Move TypedArray length getter to prototypeLinus Groh
2020-12-02LibJS: Add TypedArray.BYTES_PER_ELEMENTLinus Groh
2020-12-02LibJS: Add more tests for TypedArrayLinus Groh
2020-12-02LibJS: Make TypedArray constructor (somewhat) spec-compliantLinus Groh
- Calling without 'new' is an error - If the first argument is an object, we need a separate code path to initialize from TypedArray, ArrayBuffer, Iterable or Array-like object (marked TODO for now) - Don't insert values into array if more than one argument is present (that's not part of the spec)
2020-12-02LibJS: Add ErrorType::ConstructorWithoutNewLinus Groh
...and use it in Proxy::call(), rather than having a specific error type just for that.
2020-12-02LibJS: Clean up TypedArray constructors and prototypesLinus Groh
The current implementation is not entirely correct yet. Two classes have been added: - TypedArrayConstructor, which the various typed array constructors now inherit from. Calling or constructing this class (from JS, that is) directly is not possible, we might want to move this abstract class functionality to NativeFunction at a later point. - TypedArrayPrototype, which the various typed array prototypes now have as their own prototype. This will be the place where most of the functionality is being shared. Relevant parts from the spec: 22.2.1 The %TypedArray% Intrinsic Object The %TypedArray% intrinsic object: - is a constructor function object that all of the TypedArray constructor objects inherit from. - along with its corresponding prototype object, provides common properties that are inherited by all TypedArray constructors and their instances. 22.2.2 Properties of the %TypedArray% Intrinsic Object The %TypedArray% intrinsic object: - has a [[Prototype]] internal slot whose value is %Function.prototype%. 22.2.2.3 %TypedArray%.prototype The initial value of %TypedArray%.prototype is the %TypedArray% prototype object. 22.2.6 Properties of the TypedArray Constructors Each TypedArray constructor: - has a [[Prototype]] internal slot whose value is %TypedArray%. 22.2.6.2 TypedArray.prototype The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (22.2.7). 22.2.7 Properties of the TypedArray Prototype Objects Each TypedArray prototype object: - has a [[Prototype]] internal slot whose value is %TypedArray.prototype%. 22.2.7.2 TypedArray.prototype.constructor The initial value of a TypedArray.prototype.constructor is the corresponding %TypedArray% intrinsic object.
2020-12-01LibJS: Add six typed arrays (signed and unsigned 8/16/32-bit)Andreas Kling
This patch adds six of the standard type arrays and tries to share as much code as possible: - Uint8Array - Uint16Array - Uint32Array - Int8Array - Int16Array - Int32Array
2020-12-01LibJS: Have Uint8ClampedArray delegate OOB accesses to JS::ObjectAndreas Kling
Uint8ClampedArray itself only cares about legitimate in-bounds accesses since that's what where the specialization happens.
2020-12-01LibJS: Zero out memory in newly allocated Uint8ClampedArray objectsAndreas Kling
2020-12-01LibJS: Remove ProxyPrototypeLinus Groh
Proxy is an "exotic object" and doesn't have its own prototype. Use the regular object prototype instead, but most stuff is happening on the target object anyway. :^)
2020-11-30LibJS: Fix crash in Lexer on EOF in unterminated template literalLinus Groh
Fixes #4252.
2020-11-29LibJS: Add a basic implementation of String.prototype.substr()Andreas Kling
2020-11-29LibJS: Constructor function's "prototype" property should be writableAndreas Kling
This matches other engines.
2020-11-29LibJS+LibWeb: Log JavaScript exceptions raised by web contentAndreas Kling
Instead of hiding JS exceptions raised on the web, we now print them to the debug log. This will make it a bit easier to work out why some web pages aren't working right. :^)
2020-11-28LibJS: Disallow 'with' statement in strict modeLinus Groh
2020-11-28LibJS: Run clang-format on WithScope.hAndreas Kling
2020-11-28LibJS: Add a basic unit test for the "with" statementAndreas Kling
2020-11-28LibJS: Add basic support for "with" statementsAndreas Kling
with statements evaluate an expression and put the result of it at the "front" of the scope chain. This is implemented by creating a WithScope object and placing it in front of the VM's current call frame's scope.
2020-11-28LibJS: Add a scope object abstractionAndreas Kling
Both GlobalObject and LexicalEnvironment now inherit from ScopeObject, and the VM's call frames point to a ScopeObject chain rather than just a LexicalEnvironment chain. This gives us much more flexibility to implement things like "with", and also unifies some of the code paths that previously required special handling of the global object. There's a bunch of more cleanup that can be done in the wake of this change, and there might be some oversights in the handling of the "super" keyword, but this generally seems like a good architectural improvement. :^)
2020-11-28LibJS: Make JS::Value constructors take const cell pointersAndreas Kling
Taking non-const cell pointers is asking for trouble, since passing e.g a "const Object*" to Value(Object*) will actually call Value(bool), which is most likely not what you want.