]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 2006 Maks Orlovich | |
3 | * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | |
4 | * | |
5 | * This library is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU Library General Public | |
7 | * License as published by the Free Software Foundation; either | |
8 | * version 2 of the License, or (at your option) any later version. | |
9 | * | |
10 | * This library is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Library General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Library General Public License | |
16 | * along with this library; see the file COPYING.LIB. If not, write to | |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
18 | * Boston, MA 02110-1301, USA. | |
19 | * | |
20 | */ | |
21 | ||
22 | #ifndef JSWrapperObject_h | |
23 | #define JSWrapperObject_h | |
24 | ||
93a37866 | 25 | #include "JSDestructibleObject.h" |
9dae56ea A |
26 | |
27 | namespace JSC { | |
f9bf01c6 | 28 | |
9dae56ea A |
29 | // This class is used as a base for classes such as String, |
30 | // Number, Boolean and Date which are wrappers for primitive types. | |
93a37866 | 31 | class JSWrapperObject : public JSDestructibleObject { |
9dae56ea | 32 | public: |
93a37866 A |
33 | typedef JSDestructibleObject Base; |
34 | ||
35 | static size_t allocationSize(size_t inlineCapacity) | |
36 | { | |
37 | ASSERT_UNUSED(inlineCapacity, !inlineCapacity); | |
38 | return sizeof(JSWrapperObject); | |
39 | } | |
6fe7ccc8 | 40 | |
14957cd0 | 41 | JSValue internalValue() const; |
93a37866 | 42 | void setInternalValue(VM&, JSValue); |
f9bf01c6 | 43 | |
93a37866 | 44 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) |
f9bf01c6 | 45 | { |
81345200 | 46 | return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); |
93a37866 A |
47 | } |
48 | ||
49 | static ptrdiff_t internalValueOffset() { return OBJECT_OFFSETOF(JSWrapperObject, m_internalValue); } | |
50 | static ptrdiff_t internalValueCellOffset() | |
51 | { | |
52 | #if USE(JSVALUE64) | |
53 | return internalValueOffset(); | |
54 | #else | |
55 | return internalValueOffset() + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload); | |
56 | #endif | |
f9bf01c6 A |
57 | } |
58 | ||
59 | protected: | |
93a37866 A |
60 | explicit JSWrapperObject(VM&, Structure*); |
61 | static const unsigned StructureFlags = OverridesVisitChildren | Base::StructureFlags; | |
f9bf01c6 | 62 | |
6fe7ccc8 A |
63 | static void visitChildren(JSCell*, SlotVisitor&); |
64 | ||
9dae56ea | 65 | private: |
14957cd0 | 66 | WriteBarrier<Unknown> m_internalValue; |
9dae56ea | 67 | }; |
f9bf01c6 | 68 | |
93a37866 A |
69 | inline JSWrapperObject::JSWrapperObject(VM& vm, Structure* structure) |
70 | : JSDestructibleObject(vm, structure) | |
9dae56ea A |
71 | { |
72 | } | |
f9bf01c6 | 73 | |
14957cd0 A |
74 | inline JSValue JSWrapperObject::internalValue() const |
75 | { | |
76 | return m_internalValue.get(); | |
77 | } | |
78 | ||
93a37866 | 79 | inline void JSWrapperObject::setInternalValue(VM& vm, JSValue value) |
9dae56ea A |
80 | { |
81 | ASSERT(value); | |
82 | ASSERT(!value.isObject()); | |
93a37866 | 83 | m_internalValue.set(vm, this, value); |
9dae56ea A |
84 | } |
85 | ||
86 | } // namespace JSC | |
87 | ||
88 | #endif // JSWrapperObject_h |