1 | // -*- mode: c++; c-basic-offset: 4 -*-
|
---|
2 | /*
|
---|
3 | * Copyright (C) 2008 Apple Inc. All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | * 1. Redistributions of source code must retain the above copyright
|
---|
9 | * notice, this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer in the
|
---|
12 | * documentation and/or other materials provided with the distribution.
|
---|
13 | *
|
---|
14 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
---|
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
---|
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
---|
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef StructureID_h
|
---|
28 | #define StructureID_h
|
---|
29 |
|
---|
30 | #include <wtf/OwnArrayPtr.h>
|
---|
31 | #include <wtf/PassRefPtr.h>
|
---|
32 | #include <wtf/RefCounted.h>
|
---|
33 | #include "JSValue.h"
|
---|
34 | #include "ustring.h"
|
---|
35 |
|
---|
36 | namespace JSC {
|
---|
37 |
|
---|
38 | class JSValue;
|
---|
39 | class StructureIDChain;
|
---|
40 |
|
---|
41 | class StructureID : public RefCounted<StructureID> {
|
---|
42 | public:
|
---|
43 | static PassRefPtr<StructureID> create(JSValue* prototype)
|
---|
44 | {
|
---|
45 | return adoptRef(new StructureID(prototype));
|
---|
46 | }
|
---|
47 |
|
---|
48 | static PassRefPtr<StructureID> changePrototypeTransition(StructureID*, JSValue* prototype);
|
---|
49 | static PassRefPtr<StructureID> addPropertyTransition(StructureID*, const Identifier& name);
|
---|
50 | static PassRefPtr<StructureID> getterSetterTransition(StructureID*);
|
---|
51 | static PassRefPtr<StructureID> toDictionaryTransition(StructureID*);
|
---|
52 | static PassRefPtr<StructureID> fromDictionaryTransition(StructureID*);
|
---|
53 |
|
---|
54 | ~StructureID();
|
---|
55 |
|
---|
56 | void mark()
|
---|
57 | {
|
---|
58 | if (!m_prototype->marked())
|
---|
59 | m_prototype->mark();
|
---|
60 | }
|
---|
61 |
|
---|
62 | bool isDictionary() const { return m_isDictionary; }
|
---|
63 |
|
---|
64 | JSValue* prototype() const { return m_prototype; }
|
---|
65 |
|
---|
66 | void setCachedPrototypeChain(PassRefPtr<StructureIDChain> cachedPrototypeChain) { m_cachedPrototypeChain = cachedPrototypeChain; }
|
---|
67 | StructureIDChain* cachedPrototypeChain() const { return m_cachedPrototypeChain.get(); }
|
---|
68 |
|
---|
69 | private:
|
---|
70 | typedef HashMap<RefPtr<UString::Rep>, StructureID*, IdentifierRepHash, HashTraits<RefPtr<UString::Rep> > > TransitionTable;
|
---|
71 |
|
---|
72 | StructureID(JSValue* prototype);
|
---|
73 |
|
---|
74 | static const size_t s_maxTransitionLength = 64;
|
---|
75 |
|
---|
76 | bool m_isDictionary;
|
---|
77 |
|
---|
78 | JSValue* m_prototype;
|
---|
79 | RefPtr<StructureIDChain> m_cachedPrototypeChain;
|
---|
80 |
|
---|
81 | RefPtr<StructureID> m_previous;
|
---|
82 | UString::Rep* m_nameInPrevious;
|
---|
83 |
|
---|
84 | size_t m_transitionCount;
|
---|
85 | TransitionTable m_transitionTable;
|
---|
86 | };
|
---|
87 |
|
---|
88 | class StructureIDChain : public RefCounted<StructureIDChain> {
|
---|
89 | public:
|
---|
90 | static PassRefPtr<StructureIDChain> create(StructureID* structureID) { return adoptRef(new StructureIDChain(structureID)); }
|
---|
91 |
|
---|
92 | RefPtr<StructureID>* head() { return m_vector.get(); }
|
---|
93 |
|
---|
94 | private:
|
---|
95 | StructureIDChain(StructureID* structureID);
|
---|
96 |
|
---|
97 | OwnArrayPtr<RefPtr<StructureID> > m_vector;
|
---|
98 | };
|
---|
99 |
|
---|
100 | } // namespace JSC
|
---|
101 |
|
---|
102 | #endif // StructureID_h
|
---|