mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 09:45:06 +02:00
We already had IC support in PutById for the following cases:
- Changing an existing own property
- Calling a setter located in the prototype chain
This was enough to speed up code where structurally identical objects
(same shape) are processed in a loop:
```js
const arr = [{ a: 1 }, { a: 2 }, { a: 3 }];
for (let obj of arr) {
obj.a += 1;
}
```
However, creating structurally identical objects in a loop was still
slow:
```js
for (let i = 0; i < 10_000_000; i++) {
const o = {};
o.a = 1;
o.b = 2;
o.c = 3;
}
```
This change addresses that by adding a new IC type that caches both the
source and target shapes, allowing property additions to be fast-pathed
by directly jumping to the shape that already includes the new property.
45 lines
2.0 KiB
C++
45 lines
2.0 KiB
C++
/*
|
|
* Copyright (c) 2022, David Tuin <davidot@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibJS/Module.h>
|
|
#include <LibJS/Runtime/Completion.h>
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
namespace JS {
|
|
|
|
class ModuleNamespaceObject final : public Object {
|
|
JS_OBJECT(ModuleNamespaceObject, Object);
|
|
GC_DECLARE_ALLOCATOR(ModuleNamespaceObject);
|
|
|
|
public:
|
|
// 10.4.6 Module Namespace Exotic Objects, https://tc39.es/ecma262/#sec-module-namespace-exotic-objects
|
|
|
|
virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
|
|
virtual ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
|
|
virtual ThrowCompletionOr<bool> internal_is_extensible() const override;
|
|
virtual ThrowCompletionOr<bool> internal_prevent_extensions() override;
|
|
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyKey const&) const override;
|
|
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyKey const&, PropertyDescriptor&, Optional<PropertyDescriptor>* precomputed_get_own_property = nullptr) override;
|
|
virtual ThrowCompletionOr<bool> internal_has_property(PropertyKey const&) const override;
|
|
virtual ThrowCompletionOr<Value> internal_get(PropertyKey const&, Value receiver, CacheableGetPropertyMetadata* = nullptr, PropertyLookupPhase = PropertyLookupPhase::OwnProperty) const override;
|
|
virtual ThrowCompletionOr<bool> internal_set(PropertyKey const&, Value value, Value receiver, CacheableSetPropertyMetadata*, PropertyLookupPhase) override;
|
|
virtual ThrowCompletionOr<bool> internal_delete(PropertyKey const&) override;
|
|
virtual ThrowCompletionOr<GC::RootVector<Value>> internal_own_property_keys() const override;
|
|
virtual void initialize(Realm&) override;
|
|
|
|
private:
|
|
ModuleNamespaceObject(Realm&, Module* module, Vector<Utf16FlyString> exports);
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
GC::Ptr<Module> m_module; // [[Module]]
|
|
Vector<Utf16FlyString> m_exports; // [[Exports]]
|
|
};
|
|
|
|
}
|