2 * Copyright (C) 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. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "JSPropertyNameEnumerator.h"
29 #include "JSCInlines.h"
30 #include "StrongInlines.h"
34 const ClassInfo
JSPropertyNameEnumerator::s_info
= { "JSPropertyNameEnumerator", 0, 0, CREATE_METHOD_TABLE(JSPropertyNameEnumerator
) };
36 JSPropertyNameEnumerator
* JSPropertyNameEnumerator::create(VM
& vm
)
38 if (!vm
.emptyPropertyNameEnumerator
.get()) {
39 PropertyNameArray
propertyNames(&vm
);
40 vm
.emptyPropertyNameEnumerator
= Strong
<JSCell
>(vm
, create(vm
, 0, 0, 0, propertyNames
));
42 return jsCast
<JSPropertyNameEnumerator
*>(vm
.emptyPropertyNameEnumerator
.get());
45 JSPropertyNameEnumerator
* JSPropertyNameEnumerator::create(VM
& vm
, Structure
* structure
, uint32_t indexedLength
, uint32_t numberStructureProperties
, PropertyNameArray
& propertyNames
)
47 StructureID structureID
= structure
? structure
->id() : 0;
48 uint32_t inlineCapacity
= structure
? structure
->inlineCapacity() : 0;
49 JSPropertyNameEnumerator
* enumerator
= new (NotNull
,
50 allocateCell
<JSPropertyNameEnumerator
>(vm
.heap
)) JSPropertyNameEnumerator(vm
, structureID
, inlineCapacity
);
51 enumerator
->finishCreation(vm
, indexedLength
, numberStructureProperties
, propertyNames
.data());
55 JSPropertyNameEnumerator::JSPropertyNameEnumerator(VM
& vm
, StructureID structureID
, uint32_t inlineCapacity
)
56 : JSCell(vm
, vm
.propertyNameEnumeratorStructure
.get())
57 , m_cachedStructureID(structureID
)
58 , m_cachedInlineCapacity(inlineCapacity
)
62 void JSPropertyNameEnumerator::finishCreation(VM
& vm
, uint32_t indexedLength
, uint32_t endStructurePropertyIndex
, PassRefPtr
<PropertyNameArrayData
> idents
)
64 Base::finishCreation(vm
);
66 RefPtr
<PropertyNameArrayData
> identifiers
= idents
;
67 PropertyNameArrayData::PropertyNameVector
& vector
= identifiers
->propertyNameVector();
69 m_indexedLength
= indexedLength
;
70 m_endStructurePropertyIndex
= endStructurePropertyIndex
;
71 m_endGenericPropertyIndex
= vector
.size();
73 m_propertyNames
.resizeToFit(vector
.size());
74 for (unsigned i
= 0; i
< vector
.size(); ++i
) {
75 const Identifier
& identifier
= vector
[i
];
76 m_propertyNames
[i
].set(vm
, this, jsString(&vm
, identifier
.string()));
80 void JSPropertyNameEnumerator::destroy(JSCell
* cell
)
82 jsCast
<JSPropertyNameEnumerator
*>(cell
)->JSPropertyNameEnumerator::~JSPropertyNameEnumerator();
85 void JSPropertyNameEnumerator::visitChildren(JSCell
* cell
, SlotVisitor
& visitor
)
87 Base::visitChildren(cell
, visitor
);
88 JSPropertyNameEnumerator
* thisObject
= jsCast
<JSPropertyNameEnumerator
*>(cell
);
89 for (unsigned i
= 0; i
< thisObject
->m_propertyNames
.size(); ++i
)
90 visitor
.append(&thisObject
->m_propertyNames
[i
]);
91 visitor
.append(&thisObject
->m_prototypeChain
);