2 * Copyright (C) 2012 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
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 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef JSSymbolTableObject_h
30 #define JSSymbolTableObject_h
33 #include "PropertyDescriptor.h"
34 #include "SymbolTable.h"
38 class JSSymbolTableObject
: public JSScope
{
42 SharedSymbolTable
* symbolTable() const { return m_symbolTable
.get(); }
44 static NO_RETURN_DUE_TO_CRASH
void putDirectVirtual(JSObject
*, ExecState
*, PropertyName
, JSValue
, unsigned attributes
);
46 JS_EXPORT_PRIVATE
static bool deleteProperty(JSCell
*, ExecState
*, PropertyName
);
47 JS_EXPORT_PRIVATE
static void getOwnNonIndexPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
);
50 static const unsigned StructureFlags
= IsEnvironmentRecord
| OverridesVisitChildren
| OverridesGetPropertyNames
| Base::StructureFlags
;
52 JSSymbolTableObject(VM
& vm
, Structure
* structure
, JSScope
* scope
, SharedSymbolTable
* symbolTable
= 0)
53 : Base(vm
, structure
, scope
)
56 m_symbolTable
.set(vm
, this, symbolTable
);
59 void finishCreation(VM
& vm
)
61 Base::finishCreation(vm
);
63 m_symbolTable
.set(vm
, this, SharedSymbolTable::create(vm
));
66 static void visitChildren(JSCell
*, SlotVisitor
&);
68 WriteBarrier
<SharedSymbolTable
> m_symbolTable
;
71 template<typename SymbolTableObjectType
>
72 inline bool symbolTableGet(
73 SymbolTableObjectType
* object
, PropertyName propertyName
, PropertySlot
& slot
)
75 SymbolTable
& symbolTable
= *object
->symbolTable();
76 SymbolTable::iterator iter
= symbolTable
.find(propertyName
.publicName());
77 if (iter
== symbolTable
.end())
79 SymbolTableEntry::Fast entry
= iter
->value
;
80 ASSERT(!entry
.isNull());
81 slot
.setValue(object
->registerAt(entry
.getIndex()).get());
85 template<typename SymbolTableObjectType
>
86 inline bool symbolTableGet(
87 SymbolTableObjectType
* object
, PropertyName propertyName
, PropertyDescriptor
& descriptor
)
89 SymbolTable
& symbolTable
= *object
->symbolTable();
90 SymbolTable::iterator iter
= symbolTable
.find(propertyName
.publicName());
91 if (iter
== symbolTable
.end())
93 SymbolTableEntry::Fast entry
= iter
->value
;
94 ASSERT(!entry
.isNull());
95 descriptor
.setDescriptor(
96 object
->registerAt(entry
.getIndex()).get(), entry
.getAttributes() | DontDelete
);
100 template<typename SymbolTableObjectType
>
101 inline bool symbolTableGet(
102 SymbolTableObjectType
* object
, PropertyName propertyName
, PropertySlot
& slot
,
103 bool& slotIsWriteable
)
105 SymbolTable
& symbolTable
= *object
->symbolTable();
106 SymbolTable::iterator iter
= symbolTable
.find(propertyName
.publicName());
107 if (iter
== symbolTable
.end())
109 SymbolTableEntry::Fast entry
= iter
->value
;
110 ASSERT(!entry
.isNull());
111 slot
.setValue(object
->registerAt(entry
.getIndex()).get());
112 slotIsWriteable
= !entry
.isReadOnly();
116 template<typename SymbolTableObjectType
>
117 inline bool symbolTablePut(
118 SymbolTableObjectType
* object
, ExecState
* exec
, PropertyName propertyName
, JSValue value
,
122 ASSERT(!Heap::heap(value
) || Heap::heap(value
) == Heap::heap(object
));
124 SymbolTable
& symbolTable
= *object
->symbolTable();
125 SymbolTable::iterator iter
= symbolTable
.find(propertyName
.publicName());
126 if (iter
== symbolTable
.end())
129 SymbolTableEntry::Fast fastEntry
= iter
->value
.getFast(wasFat
);
130 ASSERT(!fastEntry
.isNull());
131 if (fastEntry
.isReadOnly()) {
133 throwTypeError(exec
, StrictModeReadonlyPropertyWriteError
);
136 if (UNLIKELY(wasFat
))
137 iter
->value
.notifyWrite();
138 object
->registerAt(fastEntry
.getIndex()).set(vm
, object
, value
);
142 template<typename SymbolTableObjectType
>
143 inline bool symbolTablePutWithAttributes(
144 SymbolTableObjectType
* object
, VM
& vm
, PropertyName propertyName
,
145 JSValue value
, unsigned attributes
)
147 ASSERT(!Heap::heap(value
) || Heap::heap(value
) == Heap::heap(object
));
149 SymbolTable::iterator iter
= object
->symbolTable()->find(propertyName
.publicName());
150 if (iter
== object
->symbolTable()->end())
152 SymbolTableEntry
& entry
= iter
->value
;
153 ASSERT(!entry
.isNull());
155 entry
.setAttributes(attributes
);
156 object
->registerAt(entry
.getIndex()).set(vm
, object
, value
);
162 #endif // JSSymbolTableObject_h