summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Object.h
AgeCommit message (Collapse)Author
2021-12-10LibJS: Remove Object::value_of()Linus Groh
Being really close to Object.prototype.valueOf() name wise makes this unnecessarily confusing - while it sometimes serves as the implementation of a valueOf() function, it's an abstraction which the spec doesn't have. Use the appropriate getters to retrieve specific internal slots instead, most commonly [[FooData]] from the primitive wrapper objects. For the Object class specifically, use the Value(Object*) ctor instead.
2021-12-08LibJS: Only allocate space for Object private elements if neededAndreas Kling
Most JavaScript objects don't have private elements, so this reduces the size of typical JS::Object instances by two pointers.
2021-10-31LibJS: Remove old Native FunctionsIdan Horowitz
Now that all the usages were updated to the new ThrowCompletionOr based version we can remove the legacy version.
2021-10-24LibJS: Provide default hash traits for JS::PropertyKeyAndreas Kling
Let's not require people to use PropertyNameTraits everywhere when we can just specialize AK::Traits<JS::PropertyKey> instead. :^)
2021-10-24LibJS: Rename PropertyName to PropertyKeyAndreas Kling
Let's use the same name as the spec. :^)
2021-10-20LibJS: Add slot [[PrivateElements]] and related methods to Objectdavidot
2021-10-20LibJS: Rename define_native_function => define_old_native_functionIdan Horowitz
This method will eventually be removed once all native functions are converted to ThrowCompletionOr
2021-10-20LibJS: Convert NativeFunction callback to ThrowCompletionOrIdan Horowitz
2021-10-04LibJS: Convert ordinary_set_with_own_descriptor() to ThrowCompletionOrLinus Groh
2021-10-04LibJS: Convert define_properties() to ThrowCompletionOrLinus Groh
2021-10-04LibJS: Convert set_immutable_prototype() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert enumerable_own_property_names() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert test_integrity_level() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert set_integrity_level() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert has_own_property() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert has_property() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert delete_property_or_throw() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert define_property_or_throw() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert create_non_enum_data_p_or_throw() to ThrowCompletionOrLinus Groh
The actual name is a bit longer, but you know what I mean :^)
2021-10-03LibJS: Convert create_data_property_or_throw() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert create_method_property() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert create_data_property() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert Object::set() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert Object::get() to ThrowCompletionOrLinus Groh
To no one's surprise, this patch is pretty big - this is possibly the most used AO of all of them. Definitely worth it though.
2021-10-03LibJS: Convert is_extensible() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert ordinary_to_primitive() to ThrowCompletionOrLinus Groh
Also add spec step comments to it while we're here.
2021-10-02LibJS: Add Object::set_prototype()Linus Groh
This is just factoring out step "9. Set O.[[Prototype]] to V." of 10.1.2 [[SetPrototypeOf]] into its own method so that we don't have to use internal_set_prototype_of() for setting an object prototype in all cases.
2021-10-01LibJS: Remove transition avoidance & start caching prototype transitionsAndreas Kling
The way that transition avoidance (foo_without_transition) was implemented led to shapes being unshareable and caused shape explosion instead, precisely what we were trying to avoid. This patch removes all the attempts to avoid transitioning shapes, and instead *adds* transitions when changing an object's prototype. This makes transitions flow naturally, and as a result we end up with way fewer shape objects in real-world situations. When we run out of big problems, we can get back to avoiding transitions as an optimization, but for now, let's avoid ballooning our processes with a unique shape for every object.
2021-09-30LibJS: Make scoping follow the specdavidot
Before this we used an ad-hoc combination of references and 'variables' stored in a hashmap. This worked in most cases but is not spec like. Additionally hoisting, dynamically naming functions and scope analysis was not done properly. This patch fixes all of that by: - Implement BindingInitialization for destructuring assignment. - Implementing a new ScopePusher which tracks the lexical and var scoped declarations. This hoists functions to the top level if no lexical declaration name overlaps. Furthermore we do checking of redeclarations in the ScopePusher now requiring less checks all over the place. - Add methods for parsing the directives and statement lists instead of having that code duplicated in multiple places. This allows declarations to pushed to the appropriate scope more easily. - Remove the non spec way of storing 'variables' in DeclarativeEnvironment and make Reference follow the spec instead of checking both the bindings and 'variables'. - Remove all scoping related things from the Interpreter. And instead use environments as specified by the spec. This also includes fixing that NativeFunctions did not produce a valid FunctionEnvironment which could cause issues with callbacks and eval. All FunctionObjects now have a valid NewFunctionEnvironment implementation. - Remove execute_statements from Interpreter and instead use ASTNode::execute everywhere this simplifies AST.cpp as you no longer need to worry about which method to call. - Make ScopeNodes setup their own environment. This uses four different methods specified by the spec {Block, Function, Eval, Global}DeclarationInstantiation with the annexB extensions. - Implement and use NamedEvaluation where specified. Additionally there are fixes to things exposed by these changes to eval, {for, for-in, for-of} loops and assignment. Finally it also fixes some tests in test-js which where passing before but not now that we have correct behavior :^).
2021-09-29LibJS: Convert internal_own_property_keys() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Convert internal_delete() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Convert internal_set() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Convert internal_get() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Convert internal_has_property() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Convert internal_define_own_property() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Convert internal_get_own_property() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Convert internal_prevent_extensions() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Convert internal_is_extensible() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Convert internal_set_prototype_of() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Convert internal_get_prototype_of() to ThrowCompletionOrLinus Groh
2021-09-29LibJS: Fix a typo in a comment in Object.hLinus Groh
2021-09-26LibJS: Make Object::ordinary_set_with_own_descriptor non-staticLuke Wilde
This needs to be accessible for implementing IDL legacy platform objects.
2021-09-25LibJS: Rename OrdinaryFunctionObject to ECMAScriptFunctionObjectLinus Groh
The old name is the result of the perhaps somewhat confusingly named abstract operation OrdinaryFunctionCreate(), which creates an "ordinary object" (https://tc39.es/ecma262/#ordinary-object) in contrast to an "exotic object" (https://tc39.es/ecma262/#exotic-object). However, the term "Ordinary Function" is not used anywhere in the spec, instead the created object is referred to as an "ECMAScript Function Object" (https://tc39.es/ecma262/#sec-ecmascript-function-objects), so let's call it that. The "ordinary" vs. "exotic" distinction is important because there are also "Built-in Function Objects", which can be either implemented as ordinary ECMAScript function objects, or as exotic objects (our NativeFunction). More work needs to be done to move a lot of infrastructure to ECMAScriptFunctionObject in order to make FunctionObject nothing more than an interface for objects that implement [[Call]] and optionally [[Construct]].
2021-08-28LibJS: Add define_direct_{property,accessor}_without_transition()Linus Groh
2021-08-28LibJS: Avoid pointless transitions and metadata lookups in storage_set()Linus Groh
- Replace the misleading abuse of the m_transitions_enabled flag for the fast path without lookup with a new m_initialized boolean that's set either by Heap::allocate() after calling the Object's initialize(), or by the GlobalObject in its special initialize_global_object(). This makes it work regardless of the shape's uniqueness. - When we're adding a new property past the initialization phase, there's no need to do a second metadata lookup to retrieve the storage value offset - it's known to always be the shape's property count minus one. Also, instead of doing manual storage resizing and assignment via indexing, just use Vector::append(). - When we didn't add a new property but are overwriting an existing one, the property count and therefore storage value offset doesn't change, so we don't have to retrieve it either. As a result, Object::set_shape() is now solely responsible for updating the m_shape pointer and is not resizing storage anymore, so I moved it into the header.
2021-08-09LibJS: Move Object::invoke to Value::invoke and fix it for primitivesdavidot
This is a tiny difference and only changes anything for primitives in strict mode. However this is tested in test262 and can be noticed by overriding toString of primitive values. This does now require one to wrap an object in a Value to call invoke but all code using invoke has been migrated.
2021-07-16LibJS: Replace the boolean argument of Object::set with an enum classIdan Horowitz
This is more serenity-esque and also makes pointing out missing exception checks during reviews much easier.
2021-07-16LibJS: Remove unused Object::PutOwnPropertyMode enum classIdan Horowitz
All usages of this enum class were removed in the Object rewrite, but this enum was left behind.
2021-07-09LibJS: Use PropertyName instead of StringOrSymbol in Object::invoke()Idan Horowitz
This prevents the unnecessary PropertyName -> StringOrSymbol -> PropertyName conversion.
2021-07-07LibJS: Remove the NativeProperty mechanism from LibJSIdan Horowitz
These were an ad-hoc way to implement special behaviour when reading or writing to specific object properties. Because these were effectively replaced by the abillity to override the internal methods of Object, they are no longer needed.