]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/PropertyTable.cpp
   2  * Copyright (C) 2013 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, 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
) { 
  87         vm
.heap
.writeBarrier(this, iter
->specificValue
.get()); 
  90     // Copy the m_deletedOffsets vector. 
  91     Vector
<PropertyOffset
>* otherDeletedOffsets 
= other
.m_deletedOffsets
.get(); 
  92     if (otherDeletedOffsets
) 
  93         m_deletedOffsets 
= adoptPtr(new Vector
<PropertyOffset
>(*otherDeletedOffsets
)); 
  96 PropertyTable::PropertyTable(VM
& vm
, unsigned initialCapacity
, const PropertyTable
& other
) 
  97     : JSCell(vm
, vm
.propertyTableStructure
.get()) 
  98     , m_indexSize(sizeForCapacity(initialCapacity
)) 
  99     , m_indexMask(m_indexSize 
- 1) 
 100     , m_index(static_cast<unsigned*>(fastZeroedMalloc(dataSize()))) 
 104     ASSERT(isPowerOf2(m_indexSize
)); 
 105     ASSERT(initialCapacity 
>= other
.m_keyCount
); 
 107     const_iterator end 
= other
.end(); 
 108     for (const_iterator iter 
= other
.begin(); iter 
!= end
; ++iter
) { 
 112         vm
.heap
.writeBarrier(this, iter
->specificValue
.get()); 
 115     // Copy the m_deletedOffsets vector. 
 116     Vector
<PropertyOffset
>* otherDeletedOffsets 
= other
.m_deletedOffsets
.get(); 
 117     if (otherDeletedOffsets
) 
 118         m_deletedOffsets 
= adoptPtr(new Vector
<PropertyOffset
>(*otherDeletedOffsets
)); 
 121 void PropertyTable::destroy(JSCell
* cell
) 
 123     static_cast<PropertyTable
*>(cell
)->PropertyTable::~PropertyTable(); 
 126 PropertyTable::~PropertyTable() 
 128     iterator end 
= this->end(); 
 129     for (iterator iter 
= begin(); iter 
!= end
; ++iter
) 
 135 void PropertyTable::visitChildren(JSCell
* cell
, SlotVisitor
& visitor
) 
 137     PropertyTable
* thisObject 
= jsCast
<PropertyTable
*>(cell
); 
 138     ASSERT_GC_OBJECT_INHERITS(thisObject
, info()); 
 139     ASSERT(thisObject
->structure()->typeInfo().overridesVisitChildren()); 
 141     JSCell::visitChildren(thisObject
, visitor
); 
 143     PropertyTable::iterator end 
= thisObject
->end(); 
 144     for (PropertyTable::iterator ptr 
= thisObject
->begin(); ptr 
!= end
; ++ptr
) 
 145         visitor
.append(&ptr
->specificValue
);