Commit graph

21 commits

Author SHA1 Message Date
Shannon Booth
f87041bf3a LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
2024-11-15 14:49:20 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Andreas Kling
340a115dfe LibJS: Make native function/property callbacks take VM, not Interpreter
More work on decoupling the general runtime from Interpreter. The goal
is becoming clearer. Interpreter should be one possible way to execute
code inside a VM. In the future we might have other ways :^)
2020-09-27 20:26:58 +02:00
Andreas Kling
af51dc105a LibJS+LibWeb: Add JS::Object::inherits(class_name)
To allow implementing the DOM class hierarchy in JS bindings, this
patch adds an inherits() function that can be used to ask an Object
if it inherits from a specific C++ class (by name).

The necessary overrides are baked into each Object subclass by the
new JS_OBJECT macro, which works similarly to C_OBJECT in LibCore.

Thanks to @Dexesttp for suggesting this approach. :^)
2020-06-21 15:15:52 +02:00
Andreas Kling
cd14ebb11f LibJS: More Interpreter::global_object() removal
Also let's settle on calling the operation of fetching the "this" value
from the Interpreter and converting it to a specific Object pointer
typed_this() since consistency is nice.
2020-06-20 17:50:48 +02:00
Andreas Kling
e4add19915 LibJS: Pass GlobalObject& to native functions and property accessors
More work towards supporting multiple global objects. Native C++ code
now get a GlobalObject& and don't have to ask the Interpreter for it.

I've added macros for declaring and defining native callbacks since
this was pretty tedious and this makes it easier next time we want to
change any of these signatures.
2020-06-20 15:45:07 +02:00
Andreas Kling
053863f35e LibJS: Interpreter::this_value() => this_value(GlobalObject&)
Once the Interpreter has no global object attached to it, we have to
provide it everywhere.
2020-06-08 21:12:20 +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
Linus Groh
418092a71a LibJS: Implement Array length setter 2020-04-23 09:47:23 +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
Linus Groh
9fab52a390 LibJS: Remove shift, pop, push functions from Array object
This abstraction isn't really that useful, as we can access the
underlying Vector<Value> using elements() and operate on it directly.
2020-04-14 13:40:04 +02:00
Andreas Kling
90ba0145f6 LibJS: Add a number-indexed property storage to all Objects
Objects can have both named and indexed properties. Previously we kept
all property names as strings. This patch separates named and indexed
properties and splits them between Object::m_storage and m_elements.

This allows us to do much faster array-style access using numeric
indices. It also makes the Array class much less special, since all
Objects now have number-indexed storage. :^)
2020-04-06 18:09:26 +02:00
Andreas Kling
30440134cb LibJS+LibWeb: Move native properties to separate getters/setters
This was a bit cumbersome now, but it gets us closer to a format suited
for code generation.
2020-03-29 00:37:33 +01:00
Linus Groh
c209ea1985 LibJS: Implement Array.prototype.{shift,pop} 2020-03-28 22:18:11 +01:00
Andreas Kling
7dc78b5e38 LibJS: Use correct |this| value when getting/setting native properties 2020-03-24 16:14:10 +01:00
Andreas Kling
cccbe43056 LibJS: Use FlyString for identifiers
This makes variable and property lookups a lot faster since comparing
two FlyStrings is O(1).
2020-03-22 13:03:43 +01:00
Andreas Kling
324b92fd06 LibJS: Virtualize access to an Object's own properties
Object now has virtual get_own_property() and put_own_property() member
functions that can be overridden to provide custom behavior.

We use these virtuals to move Array-specific access behavior to Array.
2020-03-21 14:37:34 +01:00
Andreas Kling
bceabd7c4b LibJS: Add ArrayPrototype and implement Array.prototype.push()
This function is ultimately supposed to be generic and allow any |this|
that has a length property, but for now it only works on our own Array
object type.
2020-03-20 21:56:40 +01:00
Andreas Kling
8f7d4f67a4 LibJS: Support reading/writing elements in an Array via Object get/put
I'm not completely thrilled about Object::get() and Object::put() doing
special-case stuff for arrays, and we should probably come up with a
better abstraction for it.

But at least it works for now, which is really nice. :^)
2020-03-20 21:56:40 +01:00
Andreas Kling
a82f64d3d6 LibJS: Parse ArrayExpression and start implementing Array objects
Note that property lookup is not functional yet.
2020-03-20 21:56:40 +01:00