Changeset 39670 in webkit for trunk/JavaScriptCore/runtime/JSValue.h
- Timestamp:
- Jan 6, 2009, 9:11:57 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSValue.h
r38467 r39670 21 21 */ 22 22 23 #include <stddef.h> // for size_t 24 #include <stdint.h> 25 23 26 #ifndef JSValue_h 24 27 #define JSValue_h … … 26 29 #include "CallData.h" 27 30 #include "ConstructData.h" 28 #include "JSImmediate.h" 29 #include "UString.h" 30 #include <stddef.h> // for size_t 31 #include <wtf/Noncopyable.h> 31 32 32 33 namespace JSC { 33 34 34 35 class Identifier; 36 class JSCell; 37 class JSObject; 35 38 class JSString; 36 39 class PropertySlot; 37 40 class PutPropertySlot; 41 class UString; 38 42 39 43 struct ClassInfo; … … 77 81 78 82 // Basic conversions. 79 JSValue *toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;80 bool getPrimitiveNumber(ExecState*, double& number, JSValue *&);83 JSValuePtr toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const; 84 bool getPrimitiveNumber(ExecState*, double& number, JSValuePtr&); 81 85 82 86 bool toBoolean(ExecState*) const; … … 85 89 // been set in the ExecState already. 86 90 double toNumber(ExecState*) const; 87 JSValue *toJSNumber(ExecState*) const; // Fast path for when you expect that the value is an immediate number.91 JSValuePtr toJSNumber(ExecState*) const; // Fast path for when you expect that the value is an immediate number. 88 92 89 93 UString toString(ExecState*) const; … … 106 110 107 111 // Object operations, with the toObject operation included. 108 JSValue *get(ExecState*, const Identifier& propertyName) const;109 JSValue *get(ExecState*, const Identifier& propertyName, PropertySlot&) const;110 JSValue *get(ExecState*, unsigned propertyName) const;111 JSValue *get(ExecState*, unsigned propertyName, PropertySlot&) const;112 void put(ExecState*, const Identifier& propertyName, JSValue *, PutPropertySlot&);113 void put(ExecState*, unsigned propertyName, JSValue *);112 JSValuePtr get(ExecState*, const Identifier& propertyName) const; 113 JSValuePtr get(ExecState*, const Identifier& propertyName, PropertySlot&) const; 114 JSValuePtr get(ExecState*, unsigned propertyName) const; 115 JSValuePtr get(ExecState*, unsigned propertyName, PropertySlot&) const; 116 void put(ExecState*, const Identifier& propertyName, JSValuePtr, PutPropertySlot&); 117 void put(ExecState*, unsigned propertyName, JSValuePtr); 114 118 bool deleteProperty(ExecState*, const Identifier& propertyName); 115 119 bool deleteProperty(ExecState*, unsigned propertyName); … … 120 124 JSString* toThisJSString(ExecState*); 121 125 122 JSValue *getJSNumber(); // 0 if this is not a JSNumber or number object123 124 JSValue *asValue() const;126 JSValuePtr getJSNumber(); // 0 if this is not a JSNumber or number object 127 128 JSValuePtr asValue() const; 125 129 126 130 JSCell* asCell() const; … … 133 137 }; 134 138 135 // These are identical logic to the JSValue functions above, and faster than jsNumber(number)->toInt32(). 136 int32_t toInt32(double); 137 uint32_t toUInt32(double); 138 int32_t toInt32SlowCase(double, bool& ok); 139 uint32_t toUInt32SlowCase(double, bool& ok); 140 141 inline JSValue* JSValue::asValue() const 139 class JSImmediate; 140 class JSValueEncodedAsPointer; 141 142 class JSValuePtr { 143 friend class JSImmediate; 144 145 static JSValuePtr makeImmediate(intptr_t value) 146 { 147 return JSValuePtr(reinterpret_cast<JSValue*>(value)); 148 } 149 150 intptr_t immediateValue() 151 { 152 return reinterpret_cast<intptr_t>(m_ptr); 153 } 154 155 public: 156 JSValuePtr() 157 : m_ptr(0) 158 { 159 } 160 161 JSValuePtr(JSValue* ptr) 162 : m_ptr(ptr) 163 { 164 } 165 166 JSValuePtr(const JSValue* ptr) 167 : m_ptr(const_cast<JSValue*>(ptr)) 168 { 169 } 170 171 JSValue* operator->() const 172 { 173 return m_ptr; 174 } 175 176 operator bool() const 177 { 178 return m_ptr; 179 } 180 181 bool operator==(const JSValuePtr other) const 182 { 183 return m_ptr == other.m_ptr; 184 } 185 186 bool operator!=(const JSValuePtr other) const 187 { 188 return m_ptr != other.m_ptr; 189 } 190 191 static JSValueEncodedAsPointer* encode(JSValuePtr value) 192 { 193 return reinterpret_cast<JSValueEncodedAsPointer*>(value.m_ptr); 194 } 195 196 static JSValuePtr decode(JSValueEncodedAsPointer* ptr) 197 { 198 return JSValuePtr(reinterpret_cast<JSValue*>(ptr)); 199 } 200 201 private: 202 JSValue* m_ptr; 203 }; 204 205 inline JSValuePtr JSValue::asValue() const 142 206 { 143 return const_cast<JSValue*>(this);207 return JSValuePtr(this); 144 208 } 145 209 146 inline bool JSValue::isUndefined() const210 inline JSValuePtr noValue() 147 211 { 148 return asValue() == jsUndefined();212 return JSValuePtr(); 149 213 } 150 214 151 inline bool JSValue::isNull() const 152 { 153 return asValue() == jsNull(); 154 } 155 156 inline bool JSValue::isUndefinedOrNull() const 157 { 158 return JSImmediate::isUndefinedOrNull(asValue()); 159 } 160 161 inline bool JSValue::isBoolean() const 162 { 163 return JSImmediate::isBoolean(asValue()); 164 } 165 166 inline bool JSValue::getBoolean(bool& v) const 167 { 168 if (JSImmediate::isBoolean(asValue())) { 169 v = JSImmediate::toBoolean(asValue()); 170 return true; 171 } 172 173 return false; 174 } 175 176 inline bool JSValue::getBoolean() const 177 { 178 return asValue() == jsBoolean(true); 179 } 180 181 ALWAYS_INLINE int32_t JSValue::toInt32(ExecState* exec) const 182 { 183 int32_t i; 184 if (getTruncatedInt32(i)) 185 return i; 186 bool ok; 187 return toInt32SlowCase(exec, ok); 188 } 189 190 inline uint32_t JSValue::toUInt32(ExecState* exec) const 191 { 192 uint32_t i; 193 if (getTruncatedUInt32(i)) 194 return i; 195 bool ok; 196 return toUInt32SlowCase(exec, ok); 197 } 198 199 inline int32_t toInt32(double val) 200 { 201 if (!(val >= -2147483648.0 && val < 2147483648.0)) { 202 bool ignored; 203 return toInt32SlowCase(val, ignored); 204 } 205 return static_cast<int32_t>(val); 206 } 207 208 inline uint32_t toUInt32(double val) 209 { 210 if (!(val >= 0.0 && val < 4294967296.0)) { 211 bool ignored; 212 return toUInt32SlowCase(val, ignored); 213 } 214 return static_cast<uint32_t>(val); 215 } 216 217 inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const 218 { 219 int32_t i; 220 if (getTruncatedInt32(i)) { 221 ok = true; 222 return i; 223 } 224 return toInt32SlowCase(exec, ok); 225 } 226 227 inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const 228 { 229 uint32_t i; 230 if (getTruncatedUInt32(i)) { 231 ok = true; 232 return i; 233 } 234 return toUInt32SlowCase(exec, ok); 235 } 215 inline bool operator==(const JSValuePtr a, const JSValue* b) { return a == JSValuePtr(b); } 216 inline bool operator==(const JSValue* a, const JSValuePtr b) { return JSValuePtr(a) == b; } 217 218 inline bool operator!=(const JSValuePtr a, const JSValue* b) { return a != JSValuePtr(b); } 219 inline bool operator!=(const JSValue* a, const JSValuePtr b) { return JSValuePtr(a) != b; } 236 220 237 221 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.