/src/hermes/lib/VM/DecoratedObject.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | #include "hermes/VM/DecoratedObject.h" |
9 | | |
10 | | #include "hermes/VM/Runtime-inline.h" |
11 | | #pragma GCC diagnostic push |
12 | | |
13 | | #ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32 |
14 | | #pragma GCC diagnostic ignored "-Wshorten-64-to-32" |
15 | | #endif |
16 | | namespace hermes { |
17 | | namespace vm { |
18 | | //===----------------------------------------------------------------------===// |
19 | | // class DecoratedObject |
20 | | |
21 | 0 | size_t DecoratedObject::Decoration::getMallocSize() const { |
22 | 0 | return sizeof *this; |
23 | 0 | } |
24 | | |
25 | | const ObjectVTable DecoratedObject::vt{ |
26 | | VTable( |
27 | | CellKind::DecoratedObjectKind, |
28 | | cellSize<DecoratedObject>(), |
29 | | DecoratedObject::_finalizeImpl, |
30 | | DecoratedObject::_mallocSizeImpl), |
31 | | DecoratedObject::_getOwnIndexedRangeImpl, |
32 | | DecoratedObject::_haveOwnIndexedImpl, |
33 | | DecoratedObject::_getOwnIndexedPropertyFlagsImpl, |
34 | | DecoratedObject::_getOwnIndexedImpl, |
35 | | DecoratedObject::_setOwnIndexedImpl, |
36 | | DecoratedObject::_deleteOwnIndexedImpl, |
37 | | DecoratedObject::_checkAllOwnIndexedImpl, |
38 | | }; |
39 | | |
40 | 1 | void DecoratedObjectBuildMeta(const GCCell *cell, Metadata::Builder &mb) { |
41 | 1 | mb.addJSObjectOverlapSlots(JSObject::numOverlapSlots<DecoratedObject>()); |
42 | 1 | JSObjectBuildMeta(cell, mb); |
43 | 1 | mb.setVTable(&DecoratedObject::vt); |
44 | 1 | } |
45 | | |
46 | | // static |
47 | | PseudoHandle<DecoratedObject> DecoratedObject::create( |
48 | | Runtime &runtime, |
49 | | Handle<JSObject> parentHandle, |
50 | | std::unique_ptr<Decoration> decoration, |
51 | 0 | unsigned int additionalSlotCount) { |
52 | 0 | const size_t reservedSlots = |
53 | 0 | numOverlapSlots<DecoratedObject>() + additionalSlotCount; |
54 | 0 | auto *cell = runtime.makeAFixed<DecoratedObject, HasFinalizer::Yes>( |
55 | 0 | runtime, |
56 | 0 | parentHandle, |
57 | 0 | runtime.getHiddenClassForPrototype(*parentHandle, reservedSlots), |
58 | 0 | std::move(decoration)); |
59 | 0 | auto self = JSObjectInit::initToPseudoHandle(runtime, cell); |
60 | | // Allocate a propStorage if the number of additional slots requires it. |
61 | 0 | auto selfWithSlots = runtime.ignoreAllocationFailure( |
62 | 0 | JSObject::allocatePropStorage(std::move(self), runtime, reservedSlots)); |
63 | 0 | return PseudoHandle<DecoratedObject>::vmcast(std::move(selfWithSlots)); |
64 | 0 | } |
65 | | |
66 | | // static |
67 | 93 | void DecoratedObject::_finalizeImpl(GCCell *cell, GC &) { |
68 | 93 | auto *self = vmcast<DecoratedObject>(cell); |
69 | 93 | self->~DecoratedObject(); |
70 | 93 | } |
71 | | |
72 | | // static |
73 | 0 | size_t DecoratedObject::_mallocSizeImpl(GCCell *cell) { |
74 | 0 | DecoratedObject *self = vmcast<DecoratedObject>(cell); |
75 | 0 | if (const Decoration *deco = self->getDecoration()) { |
76 | 0 | return deco->getMallocSize(); |
77 | 0 | } |
78 | 0 | return 0; |
79 | 0 | } |
80 | | |
81 | | } // namespace vm |
82 | | } // namespace hermes |