1/*
2 * Copyright (C) 2013, 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#ifndef StructureRareData_h
27#define StructureRareData_h
28
29#include "ClassInfo.h"
30#include "JSCell.h"
31#include "JSTypeInfo.h"
32#include "PropertyOffset.h"
33#include "PropertySlot.h"
34
35namespace JSC {
36
37class JSPropertyNameEnumerator;
38class Structure;
39class ObjectToStringAdaptiveStructureWatchpoint;
40class ObjectToStringAdaptiveInferredPropertyValueWatchpoint;
41
42class StructureRareData final : public JSCell {
43public:
44 typedef JSCell Base;
45 static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
46
47 static StructureRareData* create(VM&, Structure*);
48
49 static const bool needsDestruction = true;
50 static void destroy(JSCell*);
51
52 static void visitChildren(JSCell*, SlotVisitor&);
53
54 static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
55
56 Structure* previousID() const;
57 void setPreviousID(VM&, Structure*);
58 void clearPreviousID();
59
60 JSString* objectToStringValue() const;
61 void setObjectToStringValue(ExecState*, VM&, Structure* baseStructure, JSString* value, PropertySlot toStringTagSymbolSlot);
62
63 JSPropertyNameEnumerator* cachedPropertyNameEnumerator() const;
64 void setCachedPropertyNameEnumerator(VM&, JSPropertyNameEnumerator*);
65
66 DECLARE_EXPORT_INFO;
67
68private:
69 friend class Structure;
70 friend class ObjectToStringAdaptiveStructureWatchpoint;
71 friend class ObjectToStringAdaptiveInferredPropertyValueWatchpoint;
72
73 void clearObjectToStringValue();
74
75 StructureRareData(VM&, Structure*);
76
77 WriteBarrier<Structure> m_previous;
78 WriteBarrier<JSString> m_objectToStringValue;
79 WriteBarrier<JSPropertyNameEnumerator> m_cachedPropertyNameEnumerator;
80
81 typedef HashMap<PropertyOffset, RefPtr<WatchpointSet>, WTF::IntHash<PropertyOffset>, WTF::UnsignedWithZeroKeyHashTraits<PropertyOffset>> PropertyWatchpointMap;
82 std::unique_ptr<PropertyWatchpointMap> m_replacementWatchpointSets;
83 Bag<ObjectToStringAdaptiveStructureWatchpoint> m_objectToStringAdaptiveWatchpointSet;
84 std::unique_ptr<ObjectToStringAdaptiveInferredPropertyValueWatchpoint> m_objectToStringAdaptiveInferredValueWatchpoint;
85 bool m_giveUpOnObjectToStringValueCache;
86};
87
88} // namespace JSC
89
90#endif // StructureRareData_h
91