Changeset 46598 in webkit for trunk/JavaScriptCore/runtime/JSCell.h
- Timestamp:
- Jul 30, 2009, 1:57:44 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSCell.h
r46528 r46598 41 41 friend class JSString; 42 42 friend class JSValue; 43 friend class JSAPIValueWrapper; 43 44 friend struct VPtrSet; 44 45 … … 49 50 public: 50 51 // Querying the type. 52 #if USE(JSVALUE32) 51 53 bool isNumber() const; 54 #endif 52 55 bool isString() const; 53 56 bool isObject() const; 54 57 virtual bool isGetterSetter() const; 55 58 virtual bool isObject(const ClassInfo*) const; 59 virtual bool isAPIValueWrapper() const { return false; } 56 60 57 61 Structure* structure() const; … … 69 73 // FIXME: remove these methods, can check isNumberCell in JSValue && then call asNumberCell::*. 70 74 virtual bool getUInt32(uint32_t&) const; 71 virtual bool getTruncatedInt32(int32_t&) const;72 virtual bool getTruncatedUInt32(uint32_t&) const;73 75 74 76 // Basic conversions. … … 125 127 } 126 128 129 #if USE(JSVALUE32) 127 130 inline bool JSCell::isNumber() const 128 131 { 129 132 return Heap::isNumber(const_cast<JSCell*>(this)); 130 133 } 134 #endif 131 135 132 136 inline bool JSCell::isObject() const … … 153 157 { 154 158 return Heap::markCell(this); 155 }156 157 ALWAYS_INLINE JSCell* JSValue::asCell() const158 {159 ASSERT(isCell());160 return m_ptr;161 159 } 162 160 … … 174 172 inline bool JSValue::isString() const 175 173 { 176 return !JSImmediate::isImmediate(asValue()) && asCell()->isString();174 return isCell() && asCell()->isString(); 177 175 } 178 176 179 177 inline bool JSValue::isGetterSetter() const 180 178 { 181 return !JSImmediate::isImmediate(asValue()) && asCell()->isGetterSetter();179 return isCell() && asCell()->isGetterSetter(); 182 180 } 183 181 184 182 inline bool JSValue::isObject() const 185 183 { 186 return !JSImmediate::isImmediate(asValue()) && asCell()->isObject();184 return isCell() && asCell()->isObject(); 187 185 } 188 186 189 187 inline bool JSValue::getString(UString& s) const 190 188 { 191 return !JSImmediate::isImmediate(asValue()) && asCell()->getString(s);189 return isCell() && asCell()->getString(s); 192 190 } 193 191 194 192 inline UString JSValue::getString() const 195 193 { 196 return JSImmediate::isImmediate(asValue()) ? UString() : asCell()->getString();194 return isCell() ? asCell()->getString() : UString(); 197 195 } 198 196 199 197 inline JSObject* JSValue::getObject() const 200 198 { 201 return JSImmediate::isImmediate(asValue()) ? 0 : asCell()->getObject();199 return isCell() ? asCell()->getObject() : 0; 202 200 } 203 201 204 202 inline CallType JSValue::getCallData(CallData& callData) 205 203 { 206 return JSImmediate::isImmediate(asValue()) ? CallTypeNone : asCell()->getCallData(callData);204 return isCell() ? asCell()->getCallData(callData) : CallTypeNone; 207 205 } 208 206 209 207 inline ConstructType JSValue::getConstructData(ConstructData& constructData) 210 208 { 211 return JSImmediate::isImmediate(asValue()) ? ConstructTypeNone : asCell()->getConstructData(constructData);209 return isCell() ? asCell()->getConstructData(constructData) : ConstructTypeNone; 212 210 } 213 211 214 212 ALWAYS_INLINE bool JSValue::getUInt32(uint32_t& v) const 215 213 { 216 return JSImmediate::isImmediate(asValue()) ? JSImmediate::getUInt32(asValue(), v) : asCell()->getUInt32(v);217 }218 219 ALWAYS_INLINE bool JSValue::getTruncatedInt32(int32_t& v) const220 {221 return JSImmediate::isImmediate(asValue()) ? JSImmediate::getTruncatedInt32(asValue(), v) : asCell()->getTruncatedInt32(v);222 }223 224 inline bool JSValue::getTruncatedUInt32(uint32_t& v) const225 {226 return JSImmediate::isImmediate(asValue()) ? JSImmediate::getTruncatedUInt32(asValue(), v) : asCell()->getTruncatedUInt32(v);214 if (isInt32()) { 215 int32_t i = asInt32(); 216 v = static_cast<uint32_t>(i); 217 return i >= 0; 218 } 219 if (isDouble()) { 220 double d = asDouble(); 221 v = static_cast<uint32_t>(d); 222 return v == d; 223 } 224 return false; 227 225 } 228 226 … … 234 232 inline bool JSValue::marked() const 235 233 { 236 return JSImmediate::isImmediate(asValue()) || asCell()->marked(); 237 } 234 return !isCell() || asCell()->marked(); 235 } 236 237 #if !USE(JSVALUE32_64) 238 ALWAYS_INLINE JSCell* JSValue::asCell() const 239 { 240 ASSERT(isCell()); 241 return m_ptr; 242 } 243 #endif // !USE(JSVALUE32_64) 238 244 239 245 inline JSValue JSValue::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const 240 246 { 241 return JSImmediate::isImmediate(asValue()) ? asValue() : asCell()->toPrimitive(exec, preferredType);247 return isCell() ? asCell()->toPrimitive(exec, preferredType) : asValue(); 242 248 } 243 249 244 250 inline bool JSValue::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) 245 251 { 246 if (JSImmediate::isImmediate(asValue())) { 247 number = JSImmediate::toDouble(asValue()); 248 value = asValue(); 249 return true; 250 } 251 return asCell()->getPrimitiveNumber(exec, number, value); 252 if (isInt32()) { 253 number = asInt32(); 254 value = *this; 255 return true; 256 } 257 if (isDouble()) { 258 number = asDouble(); 259 value = *this; 260 return true; 261 } 262 if (isCell()) 263 return asCell()->getPrimitiveNumber(exec, number, value); 264 if (isTrue()) { 265 number = 1.0; 266 value = *this; 267 return true; 268 } 269 if (isFalse() || isNull()) { 270 number = 0.0; 271 value = *this; 272 return true; 273 } 274 ASSERT(isUndefined()); 275 number = nonInlineNaN(); 276 value = *this; 277 return true; 252 278 } 253 279 254 280 inline bool JSValue::toBoolean(ExecState* exec) const 255 281 { 256 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toBoolean(asValue()) : asCell()->toBoolean(exec); 282 if (isInt32()) 283 return asInt32() != 0; 284 if (isDouble()) 285 return asDouble() > 0.0 || asDouble() < 0.0; // false for NaN 286 if (isCell()) 287 return asCell()->toBoolean(exec); 288 return isTrue(); // false, null, and undefined all convert to false. 257 289 } 258 290 259 291 ALWAYS_INLINE double JSValue::toNumber(ExecState* exec) const 260 292 { 261 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asCell()->toNumber(exec); 293 if (isInt32()) 294 return asInt32(); 295 if (isDouble()) 296 return asDouble(); 297 if (isCell()) 298 return asCell()->toNumber(exec); 299 if (isTrue()) 300 return 1.0; 301 return isUndefined() ? nonInlineNaN() : 0; // null and false both convert to 0. 262 302 } 263 303 264 304 inline UString JSValue::toString(ExecState* exec) const 265 305 { 266 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toString(asValue()) : asCell()->toString(exec); 306 if (isCell()) 307 return asCell()->toString(exec); 308 if (isInt32()) 309 return UString::from(asInt32()); 310 if (isDouble()) 311 return asDouble() == 0.0 ? "0" : UString::from(asDouble()); 312 if (isTrue()) 313 return "true"; 314 if (isFalse()) 315 return "false"; 316 if (isNull()) 317 return "null"; 318 ASSERT(isUndefined()); 319 return "undefined"; 320 } 321 322 inline bool JSValue::needsThisConversion() const 323 { 324 if (UNLIKELY(!isCell())) 325 return true; 326 return asCell()->structure()->typeInfo().needsThisConversion(); 327 } 328 329 inline UString JSValue::toThisString(ExecState* exec) const 330 { 331 return isCell() ? asCell()->toThisString(exec) : toString(exec); 332 } 333 334 inline JSValue JSValue::getJSNumber() 335 { 336 if (isInt32() || isDouble()) 337 return *this; 338 if (isCell()) 339 return asCell()->getJSNumber(); 340 return JSValue(); 267 341 } 268 342 269 343 inline JSObject* JSValue::toObject(ExecState* exec) const 270 344 { 271 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toObject(asValue(), exec) : asCell()->toObject(exec);345 return isCell() ? asCell()->toObject(exec) : toObjectSlowCase(exec); 272 346 } 273 347 274 348 inline JSObject* JSValue::toThisObject(ExecState* exec) const 275 349 { 276 if (UNLIKELY(JSImmediate::isImmediate(asValue()))) 277 return JSImmediate::toThisObject(asValue(), exec); 278 return asCell()->toThisObject(exec); 279 } 280 281 inline bool JSValue::needsThisConversion() const 282 { 283 if (UNLIKELY(JSImmediate::isImmediate(asValue()))) 284 return true; 285 return asCell()->structure()->typeInfo().needsThisConversion(); 286 } 287 288 inline UString JSValue::toThisString(ExecState* exec) const 289 { 290 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toString(asValue()) : asCell()->toThisString(exec); 291 } 292 293 inline JSValue JSValue::getJSNumber() 294 { 295 return JSImmediate::isNumber(asValue()) ? asValue() : JSImmediate::isImmediate(asValue()) ? JSValue() : asCell()->getJSNumber(); 350 return isCell() ? asCell()->toThisObject(exec) : toThisObjectSlowCase(exec); 296 351 } 297 352
Note:
See TracChangeset
for help on using the changeset viewer.