initial import
[vuplus_webkit] / Source / JavaScriptCore / runtime / JSCell.cpp
1 /*
2  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
4  *  Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Library General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Library General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Library General Public License
17  *  along with this library; see the file COPYING.LIB.  If not, write to
18  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301, USA.
20  *
21  */
22
23 #include "config.h"
24 #include "JSCell.h"
25
26 #include "JSFunction.h"
27 #include "JSString.h"
28 #include "JSObject.h"
29 #include <wtf/MathExtras.h>
30
31 namespace JSC {
32
33 bool JSCell::getString(ExecState* exec, UString&stringValue) const
34 {
35     if (!isString())
36         return false;
37     stringValue = static_cast<const JSString*>(this)->value(exec);
38     return true;
39 }
40
41 UString JSCell::getString(ExecState* exec) const
42 {
43     return isString() ? static_cast<const JSString*>(this)->value(exec) : UString();
44 }
45
46 JSObject* JSCell::getObject()
47 {
48     return isObject() ? asObject(this) : 0;
49 }
50
51 const JSObject* JSCell::getObject() const
52 {
53     return isObject() ? static_cast<const JSObject*>(this) : 0;
54 }
55
56 CallType JSCell::getCallData(CallData&)
57 {
58     return CallTypeNone;
59 }
60
61 ConstructType JSCell::getConstructData(ConstructData&)
62 {
63     return ConstructTypeNone;
64 }
65
66 bool JSCell::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot)
67 {
68     // This is not a general purpose implementation of getOwnPropertySlot.
69     // It should only be called by JSValue::get.
70     // It calls getPropertySlot, not getOwnPropertySlot.
71     JSObject* object = toObject(exec, exec->lexicalGlobalObject());
72     slot.setBase(object);
73     if (!object->getPropertySlot(exec, identifier, slot))
74         slot.setUndefined();
75     return true;
76 }
77
78 bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot)
79 {
80     // This is not a general purpose implementation of getOwnPropertySlot.
81     // It should only be called by JSValue::get.
82     // It calls getPropertySlot, not getOwnPropertySlot.
83     JSObject* object = toObject(exec, exec->lexicalGlobalObject());
84     slot.setBase(object);
85     if (!object->getPropertySlot(exec, identifier, slot))
86         slot.setUndefined();
87     return true;
88 }
89
90 void JSCell::put(ExecState* exec, const Identifier& identifier, JSValue value, PutPropertySlot& slot)
91 {
92     toObject(exec, exec->lexicalGlobalObject())->put(exec, identifier, value, slot);
93 }
94
95 void JSCell::put(ExecState* exec, unsigned identifier, JSValue value)
96 {
97     toObject(exec, exec->lexicalGlobalObject())->put(exec, identifier, value);
98 }
99
100 bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier)
101 {
102     return toObject(exec, exec->lexicalGlobalObject())->deleteProperty(exec, identifier);
103 }
104
105 bool JSCell::deleteProperty(ExecState* exec, unsigned identifier)
106 {
107     return toObject(exec, exec->lexicalGlobalObject())->deleteProperty(exec, identifier);
108 }
109
110 JSObject* JSCell::toThisObject(ExecState* exec) const
111 {
112     return toObject(exec, exec->lexicalGlobalObject());
113 }
114
115 JSValue JSCell::getJSNumber()
116 {
117     return JSValue();
118 }
119
120 JSValue JSCell::toPrimitive(ExecState*, PreferredPrimitiveType) const
121 {
122     ASSERT_NOT_REACHED();
123     return JSValue();
124 }
125
126 bool JSCell::getPrimitiveNumber(ExecState*, double&, JSValue&)
127 {
128     ASSERT_NOT_REACHED();
129     return false;
130 }
131
132 double JSCell::toNumber(ExecState*) const
133 {
134     ASSERT_NOT_REACHED();
135     return 0;
136 }
137
138 UString JSCell::toString(ExecState*) const
139 {
140     ASSERT_NOT_REACHED();
141     return UString();
142 }
143
144 JSObject* JSCell::toObject(ExecState*, JSGlobalObject*) const
145 {
146     ASSERT_NOT_REACHED();
147     return 0;
148 }
149
150 void slowValidateCell(JSCell* cell)
151 {
152     ASSERT_GC_OBJECT_LOOKS_VALID(cell);
153 }
154
155 } // namespace JSC