]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/JSPropertyNameEnumerator.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / JSPropertyNameEnumerator.cpp
1 /*
2 * Copyright (C) 2014 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26 #include "config.h"
27 #include "JSPropertyNameEnumerator.h"
28
29 #include "JSCInlines.h"
30 #include "StrongInlines.h"
31
32 namespace JSC {
33
34 const ClassInfo JSPropertyNameEnumerator::s_info = { "JSPropertyNameEnumerator", 0, 0, CREATE_METHOD_TABLE(JSPropertyNameEnumerator) };
35
36 JSPropertyNameEnumerator* JSPropertyNameEnumerator::create(VM& vm)
37 {
38 if (!vm.emptyPropertyNameEnumerator.get()) {
39 PropertyNameArray propertyNames(&vm);
40 vm.emptyPropertyNameEnumerator = Strong<JSCell>(vm, create(vm, 0, 0, 0, propertyNames));
41 }
42 return jsCast<JSPropertyNameEnumerator*>(vm.emptyPropertyNameEnumerator.get());
43 }
44
45 JSPropertyNameEnumerator* JSPropertyNameEnumerator::create(VM& vm, Structure* structure, uint32_t indexedLength, uint32_t numberStructureProperties, PropertyNameArray& propertyNames)
46 {
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());
52 return enumerator;
53 }
54
55 JSPropertyNameEnumerator::JSPropertyNameEnumerator(VM& vm, StructureID structureID, uint32_t inlineCapacity)
56 : JSCell(vm, vm.propertyNameEnumeratorStructure.get())
57 , m_cachedStructureID(structureID)
58 , m_cachedInlineCapacity(inlineCapacity)
59 {
60 }
61
62 void JSPropertyNameEnumerator::finishCreation(VM& vm, uint32_t indexedLength, uint32_t endStructurePropertyIndex, PassRefPtr<PropertyNameArrayData> idents)
63 {
64 Base::finishCreation(vm);
65
66 RefPtr<PropertyNameArrayData> identifiers = idents;
67 PropertyNameArrayData::PropertyNameVector& vector = identifiers->propertyNameVector();
68
69 m_indexedLength = indexedLength;
70 m_endStructurePropertyIndex = endStructurePropertyIndex;
71 m_endGenericPropertyIndex = vector.size();
72
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()));
77 }
78 }
79
80 void JSPropertyNameEnumerator::destroy(JSCell* cell)
81 {
82 jsCast<JSPropertyNameEnumerator*>(cell)->JSPropertyNameEnumerator::~JSPropertyNameEnumerator();
83 }
84
85 void JSPropertyNameEnumerator::visitChildren(JSCell* cell, SlotVisitor& visitor)
86 {
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);
92 }
93
94 } // namespace JSC