]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/PropertyTable.cpp
2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "PropertyMapHashTable.h"
29 #include "JSCJSValueInlines.h"
30 #include "JSCellInlines.h"
31 #include "SlotVisitorInlines.h"
32 #include "StructureInlines.h"
34 #include <wtf/CryptographicallyRandomNumber.h>
38 const ClassInfo
PropertyTable::s_info
= { "PropertyTable", 0, 0, CREATE_METHOD_TABLE(PropertyTable
) };
40 PropertyTable
* PropertyTable::create(VM
& vm
, unsigned initialCapacity
)
42 PropertyTable
* table
= new (NotNull
, allocateCell
<PropertyTable
>(vm
.heap
)) PropertyTable(vm
, initialCapacity
);
43 table
->finishCreation(vm
);
47 PropertyTable
* PropertyTable::clone(VM
& vm
, const PropertyTable
& other
)
49 PropertyTable
* table
= new (NotNull
, allocateCell
<PropertyTable
>(vm
.heap
)) PropertyTable(vm
, other
);
50 table
->finishCreation(vm
);
54 PropertyTable
* PropertyTable::clone(VM
& vm
, unsigned initialCapacity
, const PropertyTable
& other
)
56 PropertyTable
* table
= new (NotNull
, allocateCell
<PropertyTable
>(vm
.heap
)) PropertyTable(vm
, initialCapacity
, other
);
57 table
->finishCreation(vm
);
61 PropertyTable::PropertyTable(VM
& vm
, unsigned initialCapacity
)
62 : JSCell(vm
, vm
.propertyTableStructure
.get())
63 , m_indexSize(sizeForCapacity(initialCapacity
))
64 , m_indexMask(m_indexSize
- 1)
65 , m_index(static_cast<unsigned*>(fastZeroedMalloc(dataSize())))
69 ASSERT(isPowerOf2(m_indexSize
));
72 PropertyTable::PropertyTable(VM
& vm
, const PropertyTable
& other
)
73 : JSCell(vm
, vm
.propertyTableStructure
.get())
74 , m_indexSize(other
.m_indexSize
)
75 , m_indexMask(other
.m_indexMask
)
76 , m_index(static_cast<unsigned*>(fastMalloc(dataSize())))
77 , m_keyCount(other
.m_keyCount
)
78 , m_deletedCount(other
.m_deletedCount
)
80 ASSERT(isPowerOf2(m_indexSize
));
82 memcpy(m_index
, other
.m_index
, dataSize());
84 iterator end
= this->end();
85 for (iterator iter
= begin(); iter
!= end
; ++iter
)
88 // Copy the m_deletedOffsets vector.
89 Vector
<PropertyOffset
>* otherDeletedOffsets
= other
.m_deletedOffsets
.get();
90 if (otherDeletedOffsets
)
91 m_deletedOffsets
= std::make_unique
<Vector
<PropertyOffset
>>(*otherDeletedOffsets
);
94 PropertyTable::PropertyTable(VM
& vm
, unsigned initialCapacity
, const PropertyTable
& other
)
95 : JSCell(vm
, vm
.propertyTableStructure
.get())
96 , m_indexSize(sizeForCapacity(initialCapacity
))
97 , m_indexMask(m_indexSize
- 1)
98 , m_index(static_cast<unsigned*>(fastZeroedMalloc(dataSize())))
102 ASSERT(isPowerOf2(m_indexSize
));
103 ASSERT(initialCapacity
>= other
.m_keyCount
);
105 const_iterator end
= other
.end();
106 for (const_iterator iter
= other
.begin(); iter
!= end
; ++iter
) {
112 // Copy the m_deletedOffsets vector.
113 Vector
<PropertyOffset
>* otherDeletedOffsets
= other
.m_deletedOffsets
.get();
114 if (otherDeletedOffsets
)
115 m_deletedOffsets
= std::make_unique
<Vector
<PropertyOffset
>>(*otherDeletedOffsets
);
118 void PropertyTable::destroy(JSCell
* cell
)
120 static_cast<PropertyTable
*>(cell
)->PropertyTable::~PropertyTable();
123 PropertyTable::~PropertyTable()
125 iterator end
= this->end();
126 for (iterator iter
= begin(); iter
!= end
; ++iter
)