summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/Object.h
AgeCommit message (Collapse)Author
2020-05-17LibJS: Add symbol objectsmattco98
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-01LibJS: Implement most of the Reflect objectLinus Groh
2020-05-01LibJS: Add Object::has_property()Linus Groh
Like Object::has_own_property() but going down the prototype chain.
2020-05-01LibJS: Return a bool from Object::put* to indicate successLinus Groh
2020-04-30LibJS: Add Object.{keys,values,entries}()mattco98
2020-04-28LibJS: Implement correct attributes for (almost) all propertiesmattco98
Added the ability to include a u8 attributes parameter with all of the various put methods in the Object class. They can be omitted, in which case it defaults to "Writable | Enumerable | Configurable", just like before this commit. All of the attribute values for each property were gathered from SpiderMonkey in the Firefox console. Some properties (e.g. all of the canvas element properties) have undefined property descriptors... not quite sure what that means. Those were left as the default specified above.
2020-04-26LibJS: Implement basic support for the "delete" operatorAndreas Kling
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-25LibJS: Stop using Optional<Value> in favor of Value's empty stateAndreas Kling
JS::Value already has the empty state ({} or Value() gives you one.) Use this instead of wrapping Value in Optional in some places. I've also added Value::value_or(Value) so you can easily provide a fallback value when one is not present.
2020-04-21LibJS: Add Uint8ClampedArray :^)Andreas Kling
This is a special kind of byte array that clamps its values to 0...255 It will be used for HTML ImageData objects. I made Object::put_by_index() and get_by_index() virtual for this. We'll probably need to make non-numeric property name lookups virtual as well, but this solves my current problem well enough.
2020-04-21LibJS: Implement Function.prototype.bind()Jack Karamanian
2020-04-18LibJS+LibWeb: Pass prototype to Object constructorAndreas Kling
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-10LibJS: Add Object.defineProperty() and start caring about attributesAndreas Kling
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-07LibJS: Add Boolean constructor objectJack Karamanian
2020-04-06LibJS: Add a PropertyName class that represents a string or a numberAndreas Kling
Now that we have two separate storages for Object properties depending on what kind of index they have, it's nice to have an abstraction that still allows us to say "here's a property name". We use PropertyName to always choose the optimal storage path directly while interpreting the AST. :^)
2020-04-06LibJS: Add a number-indexed property storage to all ObjectsAndreas Kling
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-04LibJS: Set length property in Object::put_native_function()Linus Groh
2020-04-02LibJS: Start implementing object shapesAndreas Kling
This patch adds JS::Shape, which implements a transition tree for our Object class. Object property keys, prototypes and attributes are now stored in a Shape, and each Object has a Shape. When adding a property to an Object, we make a transition from the old Shape to a new Shape. If we've made the same exact transition in the past (with another Object), we reuse the same transition and both objects may now share a Shape. This will become the foundation of inline caching and other engine optimizations in the future. :^)
2020-03-30LibJS: Start implementing Date :^)Linus Groh
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-29LibJS+LibWeb: Move native properties to separate getters/settersAndreas Kling
This was a bit cumbersome now, but it gets us closer to a format suited for code generation.
2020-03-28LibJS: Rework how native functions are called to improve |this| valueAndreas Kling
Native functions now only get the Interpreter& as an argument. They can then extract |this| along with any indexed arguments it wants from it. This forces functions that want |this| to actually deal with calling interpreter.this_value().to_object(), and dealing with the possibility of a non-object |this|. This is still not great but let's keep massaging it forward.
2020-03-28LibJS: Oops, "instanceof" was backwards!Andreas Kling
Fix the "instanceof" operator to check if the constructor's prototype property occurs anywhere in the prototype chain of the instance object. This patch also adds Object.setPrototypeOf() to make it possible to create a test for this bug. Thanks to DexesTTP for pointing this out! :^)
2020-03-27LibJS: Allow function calls with missing argumentsAndreas Kling
We were interpreting "undefined" as a variable lookup failure in some cases and throwing a ReferenceError exception instead of treating it as the valid value "undefined". This patch wraps the result of variable lookup in Optional<>, which allows us to only throw ReferenceError when lookup actually fails.
2020-03-26LibJS: Add Object::own_properties() convenience accessorAndreas Kling
2020-03-24LibJS: Use correct |this| value when getting/setting native propertiesAndreas Kling
2020-03-24LibJS: Implement basic exception throwingAndreas Kling
You can now throw exceptions by calling Interpreter::throw_exception(). Anyone who calls ASTNode::execute() needs to check afterwards if the Interpreter now has an exception(), and if so, stop what they're doing and simply return. When catching an exception, we'll first execute the CatchClause node if present. After that, we'll execute the finalizer block if present. This is unlikely to be completely correct, but it's a start! :^)
2020-03-22LibJS: Use FlyString for identifiersAndreas Kling
This makes variable and property lookups a lot faster since comparing two FlyStrings is O(1).
2020-03-21LibJS: Virtualize access to an Object's own propertiesAndreas Kling
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-20LibJS: Parse ArrayExpression and start implementing Array objectsAndreas Kling
Note that property lookup is not functional yet.
2020-03-16LibJS: Add "Heap" and "Runtime" subdirectoriesAndreas Kling
Let's try to keep LibJS tidy as it expands. :^)