source: webkit/trunk/JavaScriptCore/runtime/JSValue.h@ 38247

Last change on this file since 38247 was 38137, checked in by [email protected], 17 years ago

2008-11-05 Cameron Zwarich <[email protected]>

Rubber-stamped by Sam Weinig.

Move more files to the runtime subdirectory of JavaScriptCore.

JavaScriptCore:

  • API/APICast.h:
  • API/JSBase.cpp:
  • API/JSCallbackObject.cpp:
  • API/JSClassRef.cpp:
  • API/JSClassRef.h:
  • API/JSStringRefCF.cpp:
  • API/JSValueRef.cpp:
  • API/OpaqueJSString.cpp:
  • API/OpaqueJSString.h:
  • AllInOneFile.cpp:
  • GNUmakefile.am:
  • JavaScriptCore.pri:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • JavaScriptCoreSources.bkl:
  • VM/CodeBlock.h:
  • VM/CodeGenerator.cpp:
  • VM/Machine.cpp:
  • VM/RegisterFile.h:
  • debugger/Debugger.h:
  • kjs/SourceProvider.h:
  • kjs/TypeInfo.h: Removed.
  • kjs/collector.cpp: Removed.
  • kjs/collector.h: Removed.
  • kjs/completion.h: Removed.
  • kjs/create_hash_table:
  • kjs/identifier.cpp: Removed.
  • kjs/identifier.h: Removed.
  • kjs/interpreter.cpp: Removed.
  • kjs/interpreter.h: Removed.
  • kjs/lexer.cpp:
  • kjs/lexer.h:
  • kjs/lookup.cpp: Removed.
  • kjs/lookup.h: Removed.
  • kjs/nodes.cpp:
  • kjs/nodes.h:
  • kjs/operations.cpp: Removed.
  • kjs/operations.h: Removed.
  • kjs/protect.h: Removed.
  • kjs/regexp.cpp: Removed.
  • kjs/regexp.h: Removed.
  • kjs/ustring.cpp: Removed.
  • kjs/ustring.h: Removed.
  • pcre/pcre_exec.cpp:
  • profiler/CallIdentifier.h:
  • profiler/Profile.h:
  • runtime/ArrayConstructor.cpp:
  • runtime/ArrayPrototype.cpp:
  • runtime/ArrayPrototype.h:
  • runtime/Collector.cpp: Copied from kjs/collector.cpp.
  • runtime/Collector.h: Copied from kjs/collector.h.
  • runtime/CollectorHeapIterator.h:
  • runtime/Completion.h: Copied from kjs/completion.h.
  • runtime/ErrorPrototype.cpp:
  • runtime/Identifier.cpp: Copied from kjs/identifier.cpp.
  • runtime/Identifier.h: Copied from kjs/identifier.h.
  • runtime/InitializeThreading.cpp:
  • runtime/Interpreter.cpp: Copied from kjs/interpreter.cpp.
  • runtime/Interpreter.h: Copied from kjs/interpreter.h.
  • runtime/JSCell.h:
  • runtime/JSGlobalData.cpp:
  • runtime/JSGlobalData.h:
  • runtime/JSLock.cpp:
  • runtime/JSNumberCell.cpp:
  • runtime/JSNumberCell.h:
  • runtime/JSObject.cpp:
  • runtime/JSValue.h:
  • runtime/Lookup.cpp: Copied from kjs/lookup.cpp.
  • runtime/Lookup.h: Copied from kjs/lookup.h.
  • runtime/MathObject.cpp:
  • runtime/NativeErrorPrototype.cpp:
  • runtime/NumberPrototype.cpp:
  • runtime/Operations.cpp: Copied from kjs/operations.cpp.
  • runtime/Operations.h: Copied from kjs/operations.h.
  • runtime/PropertyMapHashTable.h:
  • runtime/Protect.h: Copied from kjs/protect.h.
  • runtime/RegExp.cpp: Copied from kjs/regexp.cpp.
  • runtime/RegExp.h: Copied from kjs/regexp.h.
  • runtime/RegExpConstructor.cpp:
  • runtime/RegExpObject.h:
  • runtime/RegExpPrototype.cpp:
  • runtime/SmallStrings.h:
  • runtime/StringObjectThatMasqueradesAsUndefined.h:
  • runtime/StructureID.cpp:
  • runtime/StructureID.h:
  • runtime/StructureIDTransitionTable.h:
  • runtime/SymbolTable.h:
  • runtime/TypeInfo.h: Copied from kjs/TypeInfo.h.
  • runtime/UString.cpp: Copied from kjs/ustring.cpp.
  • runtime/UString.h: Copied from kjs/ustring.h.
  • wrec/CharacterClassConstructor.h:
  • wrec/WREC.h:

WebCore:

  • ForwardingHeaders/kjs/collector.h: Removed.
  • ForwardingHeaders/kjs/completion.h: Removed.
  • ForwardingHeaders/kjs/identifier.h: Removed.
  • ForwardingHeaders/kjs/interpreter.h: Removed.
  • ForwardingHeaders/kjs/lookup.h: Removed.
  • ForwardingHeaders/kjs/operations.h: Removed.
  • ForwardingHeaders/kjs/protect.h: Removed.
  • ForwardingHeaders/kjs/ustring.h: Removed.
  • ForwardingHeaders/runtime/Collector.h: Copied from ForwardingHeaders/kjs/collector.h.
  • ForwardingHeaders/runtime/Completion.h: Copied from ForwardingHeaders/kjs/completion.h.
  • ForwardingHeaders/runtime/Identifier.h: Copied from ForwardingHeaders/kjs/identifier.h.
  • ForwardingHeaders/runtime/Interpreter.h: Copied from ForwardingHeaders/kjs/interpreter.h.
  • ForwardingHeaders/runtime/Lookup.h: Copied from ForwardingHeaders/kjs/lookup.h.
  • ForwardingHeaders/runtime/Operations.h: Copied from ForwardingHeaders/kjs/operations.h.
  • ForwardingHeaders/runtime/Protect.h: Copied from ForwardingHeaders/kjs/protect.h.
  • ForwardingHeaders/runtime/UString.h: Copied from ForwardingHeaders/kjs/ustring.h.
  • bindings/js/GCController.cpp:
  • bindings/js/JSCustomPositionCallback.h:
  • bindings/js/JSCustomPositionErrorCallback.h:
  • bindings/js/JSCustomSQLStatementCallback.h:
  • bindings/js/JSCustomSQLStatementErrorCallback.h:
  • bindings/js/JSCustomSQLTransactionErrorCallback.h:
  • bindings/js/JSCustomVoidCallback.h:
  • bindings/js/JSDOMBinding.h:
  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSEventListener.h:
  • bindings/js/ScheduledAction.h:
  • bindings/js/ScriptController.cpp:
  • bindings/js/ScriptController.h:
  • bindings/objc/WebScriptObject.mm:
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/NP_jsobject.cpp:
  • bridge/c/c_class.cpp:
  • bridge/jni/jni_class.cpp:
  • bridge/jni/jni_jsobject.mm:
  • bridge/npruntime.cpp:
  • bridge/runtime_root.h:
  • history/CachedPage.h:
  • html/CanvasRenderingContext2D.cpp:
  • html/HTMLCanvasElement.cpp:
  • inspector/InspectorController.cpp:
  • inspector/JavaScriptCallFrame.cpp:
  • page/Console.cpp:
  • page/Page.cpp:
  • platform/text/AtomicString.cpp:
  • platform/text/PlatformString.h:

WebKit/mac:

  • ForwardingHeaders/kjs/collector.h: Removed.
  • ForwardingHeaders/kjs/identifier.h: Removed.
  • ForwardingHeaders/kjs/interpreter.h: Removed.
  • ForwardingHeaders/kjs/lookup.h: Removed.
  • ForwardingHeaders/kjs/operations.h: Removed.
  • ForwardingHeaders/kjs/protect.h: Removed.
  • ForwardingHeaders/runtime/Interpreter.h: Copied from ForwardingHeaders/kjs/interpreter.h.
  • WebView/WebScriptDebugDelegate.mm:

WebKit/wx:

  • WebFrame.cpp:
  • WebView.cpp:
  • Property svn:eol-style set to native
File size: 7.6 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 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#ifndef JSValue_h
24#define JSValue_h
25
26#include "CallData.h"
27#include "ConstructData.h"
28#include "JSImmediate.h"
29#include "UString.h"
30#include <stddef.h> // for size_t
31
32// The magic number 0x4000 is not important here, it is being subtracted back out (avoiding using zero since this
33// can have unexpected effects in this type of macro, particularly where multiple-inheritance is involved).
34#define OBJECT_OFFSET(class, member) (reinterpret_cast<ptrdiff_t>(&(reinterpret_cast<class*>(0x4000)->member)) - 0x4000)
35
36namespace JSC {
37
38 class Identifier;
39 class JSString;
40 class PropertySlot;
41 class PutPropertySlot;
42
43 struct ClassInfo;
44 struct Instruction;
45
46 enum PreferredPrimitiveType { NoPreference, PreferNumber, PreferString };
47
48 class JSValue : Noncopyable {
49 protected:
50 JSValue() { }
51 virtual ~JSValue() { }
52
53 public:
54 // Querying the type.
55 bool isUndefined() const;
56 bool isNull() const;
57 bool isUndefinedOrNull() const;
58 bool isBoolean() const;
59 bool isNumber() const;
60 bool isString() const;
61 bool isGetterSetter() const;
62 bool isObject() const;
63 bool isObject(const ClassInfo*) const;
64
65 // Extracting the value.
66 bool getBoolean(bool&) const;
67 bool getBoolean() const; // false if not a boolean
68 double getNumber() const; // NaN if not a number
69 double uncheckedGetNumber() const;
70 bool getString(UString&) const;
71 UString getString() const; // null string if not a string
72 JSObject* getObject() const; // 0 if not an object
73
74 CallType getCallData(CallData&);
75 ConstructType getConstructData(ConstructData&);
76
77 // Extracting integer values.
78 bool getUInt32(uint32_t&) const;
79 bool getTruncatedInt32(int32_t&) const;
80 bool getTruncatedUInt32(uint32_t&) const;
81
82 // Basic conversions.
83 JSValue* toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
84 bool getPrimitiveNumber(ExecState*, double& number, JSValue*&);
85
86 bool toBoolean(ExecState*) const;
87
88 // toNumber conversion is expected to be side effect free if an exception has
89 // been set in the ExecState already.
90 double toNumber(ExecState*) const;
91 JSValue* toJSNumber(ExecState*) const; // Fast path for when you expect that the value is an immediate number.
92
93 UString toString(ExecState*) const;
94 JSObject* toObject(ExecState*) const;
95
96 // Integer conversions.
97 double toInteger(ExecState*) const;
98 double toIntegerPreserveNaN(ExecState*) const;
99 int32_t toInt32(ExecState*) const;
100 int32_t toInt32(ExecState*, bool& ok) const;
101 uint32_t toUInt32(ExecState*) const;
102 uint32_t toUInt32(ExecState*, bool& ok) const;
103
104 // Floating point conversions.
105 float toFloat(ExecState*) const;
106
107 // Garbage collection.
108 void mark();
109 bool marked() const;
110
111 // Object operations, with the toObject operation included.
112 JSValue* get(ExecState*, const Identifier& propertyName) const;
113 JSValue* get(ExecState*, const Identifier& propertyName, PropertySlot&) const;
114 JSValue* get(ExecState*, unsigned propertyName) const;
115 JSValue* get(ExecState*, unsigned propertyName, PropertySlot&) const;
116 void put(ExecState*, const Identifier& propertyName, JSValue*, PutPropertySlot&);
117 void put(ExecState*, unsigned propertyName, JSValue*);
118 bool deleteProperty(ExecState*, const Identifier& propertyName);
119 bool deleteProperty(ExecState*, unsigned propertyName);
120
121 bool needsThisConversion() const;
122 JSObject* toThisObject(ExecState*) const;
123 UString toThisString(ExecState*) const;
124 JSString* toThisJSString(ExecState*);
125
126 JSValue* getJSNumber(); // 0 if this is not a JSNumber or number object
127
128 JSValue* asValue() const;
129
130 JSCell* asCell() const;
131
132 private:
133 bool getPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
134 bool getPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
135 int32_t toInt32SlowCase(ExecState*, bool& ok) const;
136 uint32_t toUInt32SlowCase(ExecState*, bool& ok) const;
137 };
138
139 // These are identical logic to the JSValue functions above, and faster than jsNumber(number)->toInt32().
140 int32_t toInt32(double);
141 uint32_t toUInt32(double);
142 int32_t toInt32SlowCase(double, bool& ok);
143 uint32_t toUInt32SlowCase(double, bool& ok);
144
145 inline JSValue* JSValue::asValue() const
146 {
147 return const_cast<JSValue*>(this);
148 }
149
150 inline bool JSValue::isUndefined() const
151 {
152 return asValue() == jsUndefined();
153 }
154
155 inline bool JSValue::isNull() const
156 {
157 return asValue() == jsNull();
158 }
159
160 inline bool JSValue::isUndefinedOrNull() const
161 {
162 return JSImmediate::isUndefinedOrNull(asValue());
163 }
164
165 inline bool JSValue::isBoolean() const
166 {
167 return JSImmediate::isBoolean(asValue());
168 }
169
170 inline bool JSValue::getBoolean(bool& v) const
171 {
172 if (JSImmediate::isBoolean(asValue())) {
173 v = JSImmediate::toBoolean(asValue());
174 return true;
175 }
176
177 return false;
178 }
179
180 inline bool JSValue::getBoolean() const
181 {
182 return asValue() == jsBoolean(true);
183 }
184
185 ALWAYS_INLINE int32_t JSValue::toInt32(ExecState* exec) const
186 {
187 int32_t i;
188 if (getTruncatedInt32(i))
189 return i;
190 bool ok;
191 return toInt32SlowCase(exec, ok);
192 }
193
194 inline uint32_t JSValue::toUInt32(ExecState* exec) const
195 {
196 uint32_t i;
197 if (getTruncatedUInt32(i))
198 return i;
199 bool ok;
200 return toUInt32SlowCase(exec, ok);
201 }
202
203 inline int32_t toInt32(double val)
204 {
205 if (!(val >= -2147483648.0 && val < 2147483648.0)) {
206 bool ignored;
207 return toInt32SlowCase(val, ignored);
208 }
209 return static_cast<int32_t>(val);
210 }
211
212 inline uint32_t toUInt32(double val)
213 {
214 if (!(val >= 0.0 && val < 4294967296.0)) {
215 bool ignored;
216 return toUInt32SlowCase(val, ignored);
217 }
218 return static_cast<uint32_t>(val);
219 }
220
221 inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const
222 {
223 int32_t i;
224 if (getTruncatedInt32(i)) {
225 ok = true;
226 return i;
227 }
228 return toInt32SlowCase(exec, ok);
229 }
230
231 inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const
232 {
233 uint32_t i;
234 if (getTruncatedUInt32(i)) {
235 ok = true;
236 return i;
237 }
238 return toUInt32SlowCase(exec, ok);
239 }
240
241} // namespace JSC
242
243#endif // JSValue_h
Note: See TracBrowser for help on using the repository browser.