Changeset 39769 in webkit for trunk/JavaScriptCore/runtime
- Timestamp:
- Jan 9, 2009, 4:14:25 PM (16 years ago)
- Location:
- trunk/JavaScriptCore/runtime
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSCell.h
r39670 r39769 24 24 #define JSCell_h 25 25 26 #include <wtf/Noncopyable.h> 26 27 #include "Structure.h" 27 28 #include "JSValue.h" … … 31 32 namespace JSC { 32 33 33 class JSCell : public JSValue {34 class JSCell : Noncopyable { 34 35 friend class JIT; 35 36 friend class GetterSetter; … … 39 40 friend class JSPropertyNameIterator; 40 41 friend class JSString; 41 friend class JSValue ;42 friend class JSValuePtr; 42 43 friend class Interpreter; 43 44 … … 113 114 inline JSCell* asCell(JSValuePtr value) 114 115 { 115 ASSERT(!JSImmediate::isImmediate(value));116 116 return value->asCell(); 117 117 } … … 156 156 } 157 157 158 ALWAYS_INLINE JSCell* JSValue ::asCell() const158 ALWAYS_INLINE JSCell* JSValuePtr::asCell() const 159 159 { 160 160 ASSERT(!JSImmediate::isImmediate(asValue())); 161 return const_cast<JSCell*>(reinterpret_cast<const JSCell*>(this));161 return m_ptr; 162 162 } 163 163 … … 173 173 // --- JSValue inlines ---------------------------- 174 174 175 inline bool JSValue ::isNumber() const175 inline bool JSValuePtr::isNumber() const 176 176 { 177 177 return JSImmediate::isNumber(asValue()) || (!JSImmediate::isImmediate(asValue()) && asCell()->isNumber()); 178 178 } 179 179 180 inline bool JSValue ::isString() const180 inline bool JSValuePtr::isString() const 181 181 { 182 182 return !JSImmediate::isImmediate(asValue()) && asCell()->isString(); 183 183 } 184 184 185 inline bool JSValue ::isGetterSetter() const185 inline bool JSValuePtr::isGetterSetter() const 186 186 { 187 187 return !JSImmediate::isImmediate(asValue()) && asCell()->isGetterSetter(); 188 188 } 189 189 190 inline bool JSValue ::isObject() const190 inline bool JSValuePtr::isObject() const 191 191 { 192 192 return !JSImmediate::isImmediate(asValue()) && asCell()->isObject(); 193 193 } 194 194 195 inline double JSValue ::getNumber() const195 inline double JSValuePtr::getNumber() const 196 196 { 197 197 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asCell()->getNumber(); 198 198 } 199 199 200 inline bool JSValue ::getString(UString& s) const200 inline bool JSValuePtr::getString(UString& s) const 201 201 { 202 202 return !JSImmediate::isImmediate(asValue()) && asCell()->getString(s); 203 203 } 204 204 205 inline UString JSValue ::getString() const205 inline UString JSValuePtr::getString() const 206 206 { 207 207 return JSImmediate::isImmediate(asValue()) ? UString() : asCell()->getString(); 208 208 } 209 209 210 inline JSObject* JSValue ::getObject() const210 inline JSObject* JSValuePtr::getObject() const 211 211 { 212 212 return JSImmediate::isImmediate(asValue()) ? 0 : asCell()->getObject(); 213 213 } 214 214 215 inline CallType JSValue ::getCallData(CallData& callData)215 inline CallType JSValuePtr::getCallData(CallData& callData) 216 216 { 217 217 return JSImmediate::isImmediate(asValue()) ? CallTypeNone : asCell()->getCallData(callData); 218 218 } 219 219 220 inline ConstructType JSValue ::getConstructData(ConstructData& constructData)220 inline ConstructType JSValuePtr::getConstructData(ConstructData& constructData) 221 221 { 222 222 return JSImmediate::isImmediate(asValue()) ? ConstructTypeNone : asCell()->getConstructData(constructData); 223 223 } 224 224 225 ALWAYS_INLINE bool JSValue ::getUInt32(uint32_t& v) const225 ALWAYS_INLINE bool JSValuePtr::getUInt32(uint32_t& v) const 226 226 { 227 227 return JSImmediate::isImmediate(asValue()) ? JSImmediate::getUInt32(asValue(), v) : asCell()->getUInt32(v); 228 228 } 229 229 230 ALWAYS_INLINE bool JSValue ::getTruncatedInt32(int32_t& v) const230 ALWAYS_INLINE bool JSValuePtr::getTruncatedInt32(int32_t& v) const 231 231 { 232 232 return JSImmediate::isImmediate(asValue()) ? JSImmediate::getTruncatedInt32(asValue(), v) : asCell()->getTruncatedInt32(v); 233 233 } 234 234 235 inline bool JSValue ::getTruncatedUInt32(uint32_t& v) const235 inline bool JSValuePtr::getTruncatedUInt32(uint32_t& v) const 236 236 { 237 237 return JSImmediate::isImmediate(asValue()) ? JSImmediate::getTruncatedUInt32(asValue(), v) : asCell()->getTruncatedUInt32(v); 238 238 } 239 239 240 inline void JSValue ::mark()240 inline void JSValuePtr::mark() 241 241 { 242 242 asCell()->mark(); // callers should check !marked() before calling mark(), so this should only be called with cells 243 243 } 244 244 245 inline bool JSValue ::marked() const245 inline bool JSValuePtr::marked() const 246 246 { 247 247 return JSImmediate::isImmediate(asValue()) || asCell()->marked(); 248 248 } 249 249 250 inline JSValuePtr JSValue ::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const250 inline JSValuePtr JSValuePtr::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const 251 251 { 252 252 return JSImmediate::isImmediate(asValue()) ? asValue() : asCell()->toPrimitive(exec, preferredType); 253 253 } 254 254 255 inline bool JSValue ::getPrimitiveNumber(ExecState* exec, double& number, JSValuePtr& value)255 inline bool JSValuePtr::getPrimitiveNumber(ExecState* exec, double& number, JSValuePtr& value) 256 256 { 257 257 if (JSImmediate::isImmediate(asValue())) { … … 263 263 } 264 264 265 inline bool JSValue ::toBoolean(ExecState* exec) const265 inline bool JSValuePtr::toBoolean(ExecState* exec) const 266 266 { 267 267 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toBoolean(asValue()) : asCell()->toBoolean(exec); 268 268 } 269 269 270 ALWAYS_INLINE double JSValue ::toNumber(ExecState* exec) const270 ALWAYS_INLINE double JSValuePtr::toNumber(ExecState* exec) const 271 271 { 272 272 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toDouble(asValue()) : asCell()->toNumber(exec); 273 273 } 274 274 275 inline UString JSValue ::toString(ExecState* exec) const275 inline UString JSValuePtr::toString(ExecState* exec) const 276 276 { 277 277 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toString(asValue()) : asCell()->toString(exec); 278 278 } 279 279 280 inline JSObject* JSValue ::toObject(ExecState* exec) const280 inline JSObject* JSValuePtr::toObject(ExecState* exec) const 281 281 { 282 282 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toObject(asValue(), exec) : asCell()->toObject(exec); 283 283 } 284 284 285 inline JSObject* JSValue ::toThisObject(ExecState* exec) const285 inline JSObject* JSValuePtr::toThisObject(ExecState* exec) const 286 286 { 287 287 if (UNLIKELY(JSImmediate::isImmediate(asValue()))) … … 290 290 } 291 291 292 inline bool JSValue ::needsThisConversion() const292 inline bool JSValuePtr::needsThisConversion() const 293 293 { 294 294 if (UNLIKELY(JSImmediate::isImmediate(asValue()))) … … 297 297 } 298 298 299 inline UString JSValue ::toThisString(ExecState* exec) const299 inline UString JSValuePtr::toThisString(ExecState* exec) const 300 300 { 301 301 return JSImmediate::isImmediate(asValue()) ? JSImmediate::toString(asValue()) : asCell()->toThisString(exec); 302 302 } 303 303 304 inline JSValuePtr JSValue ::getJSNumber()304 inline JSValuePtr JSValuePtr::getJSNumber() 305 305 { 306 306 return JSImmediate::isNumber(asValue()) ? asValue() : JSImmediate::isImmediate(asValue()) ? noValue() : asCell()->getJSNumber(); -
trunk/JavaScriptCore/runtime/JSImmediate.h
r39738 r39769 38 38 class JSCell; 39 39 class JSObject; 40 class JSValue;41 40 class UString; 42 41 … … 506 505 uint32_t toUInt32SlowCase(double, bool& ok); 507 506 508 inline bool JSValue ::isUndefined() const507 inline bool JSValuePtr::isUndefined() const 509 508 { 510 509 return asValue() == jsUndefined(); 511 510 } 512 511 513 inline bool JSValue ::isNull() const512 inline bool JSValuePtr::isNull() const 514 513 { 515 514 return asValue() == jsNull(); 516 515 } 517 516 518 inline bool JSValue ::isUndefinedOrNull() const517 inline bool JSValuePtr::isUndefinedOrNull() const 519 518 { 520 519 return JSImmediate::isUndefinedOrNull(asValue()); 521 520 } 522 521 523 inline bool JSValue ::isBoolean() const522 inline bool JSValuePtr::isBoolean() const 524 523 { 525 524 return JSImmediate::isBoolean(asValue()); 526 525 } 527 526 528 inline bool JSValue ::getBoolean(bool& v) const527 inline bool JSValuePtr::getBoolean(bool& v) const 529 528 { 530 529 if (JSImmediate::isBoolean(asValue())) { … … 536 535 } 537 536 538 inline bool JSValue ::getBoolean() const537 inline bool JSValuePtr::getBoolean() const 539 538 { 540 539 return asValue() == jsBoolean(true); 541 540 } 542 541 543 ALWAYS_INLINE int32_t JSValue ::toInt32(ExecState* exec) const542 ALWAYS_INLINE int32_t JSValuePtr::toInt32(ExecState* exec) const 544 543 { 545 544 int32_t i; … … 550 549 } 551 550 552 inline uint32_t JSValue ::toUInt32(ExecState* exec) const551 inline uint32_t JSValuePtr::toUInt32(ExecState* exec) const 553 552 { 554 553 uint32_t i; … … 577 576 } 578 577 579 inline int32_t JSValue ::toInt32(ExecState* exec, bool& ok) const578 inline int32_t JSValuePtr::toInt32(ExecState* exec, bool& ok) const 580 579 { 581 580 int32_t i; … … 587 586 } 588 587 589 inline uint32_t JSValue ::toUInt32(ExecState* exec, bool& ok) const588 inline uint32_t JSValuePtr::toUInt32(ExecState* exec, bool& ok) const 590 589 { 591 590 uint32_t i; -
trunk/JavaScriptCore/runtime/JSNumberCell.h
r39670 r39769 231 231 // --- JSValue inlines ---------------------------- 232 232 233 inline double JSValue ::uncheckedGetNumber() const233 inline double JSValuePtr::uncheckedGetNumber() const 234 234 { 235 235 ASSERT(JSImmediate::isImmediate(asValue()) || asCell()->isNumber()); … … 253 253 } 254 254 255 ALWAYS_INLINE JSValuePtr JSValue ::toJSNumber(ExecState* exec) const255 ALWAYS_INLINE JSValuePtr JSValuePtr::toJSNumber(ExecState* exec) const 256 256 { 257 257 return JSImmediate::isNumber(asValue()) ? asValue() : jsNumber(exec, this->toNumber(exec)); -
trunk/JavaScriptCore/runtime/JSObject.h
r39670 r39769 269 269 270 270 // this method is here to be after the inline declaration of JSCell::isObject 271 inline bool JSValue ::isObject(const ClassInfo* classInfo) const271 inline bool JSValuePtr::isObject(const ClassInfo* classInfo) const 272 272 { 273 273 return !JSImmediate::isImmediate(asValue()) && asCell()->isObject(classInfo); … … 466 466 } 467 467 468 inline JSValuePtr JSValue ::get(ExecState* exec, const Identifier& propertyName) const469 { 470 PropertySlot slot( this);468 inline JSValuePtr JSValuePtr::get(ExecState* exec, const Identifier& propertyName) const 469 { 470 PropertySlot slot(asValue()); 471 471 return get(exec, propertyName, slot); 472 472 } 473 473 474 inline JSValuePtr JSValue ::get(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) const474 inline JSValuePtr JSValuePtr::get(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) const 475 475 { 476 476 if (UNLIKELY(JSImmediate::isImmediate(asValue()))) { … … 492 492 } 493 493 494 inline JSValuePtr JSValue ::get(ExecState* exec, unsigned propertyName) const495 { 496 PropertySlot slot( this);494 inline JSValuePtr JSValuePtr::get(ExecState* exec, unsigned propertyName) const 495 { 496 PropertySlot slot(asValue()); 497 497 return get(exec, propertyName, slot); 498 498 } 499 499 500 inline JSValuePtr JSValue ::get(ExecState* exec, unsigned propertyName, PropertySlot& slot) const500 inline JSValuePtr JSValuePtr::get(ExecState* exec, unsigned propertyName, PropertySlot& slot) const 501 501 { 502 502 if (UNLIKELY(JSImmediate::isImmediate(asValue()))) { … … 518 518 } 519 519 520 inline void JSValue ::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot)520 inline void JSValuePtr::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot) 521 521 { 522 522 if (UNLIKELY(JSImmediate::isImmediate(asValue()))) { … … 527 527 } 528 528 529 inline void JSValue ::put(ExecState* exec, unsigned propertyName, JSValuePtr value)529 inline void JSValuePtr::put(ExecState* exec, unsigned propertyName, JSValuePtr value) 530 530 { 531 531 if (UNLIKELY(JSImmediate::isImmediate(asValue()))) { -
trunk/JavaScriptCore/runtime/JSString.h
r39670 r39769 205 205 // --- JSValue inlines ---------------------------- 206 206 207 inline JSString* JSValue ::toThisJSString(ExecState* exec)207 inline JSString* JSValuePtr::toThisJSString(ExecState* exec) 208 208 { 209 209 return JSImmediate::isImmediate(asValue()) ? jsString(exec, JSImmediate::toString(asValue())) : asCell()->toThisJSString(exec); -
trunk/JavaScriptCore/runtime/JSValue.cpp
r37938 r39769 32 32 33 33 // ECMA 9.4 34 double JSValue ::toInteger(ExecState* exec) const34 double JSValuePtr::toInteger(ExecState* exec) const 35 35 { 36 36 int32_t i; … … 41 41 } 42 42 43 double JSValue ::toIntegerPreserveNaN(ExecState* exec) const43 double JSValuePtr::toIntegerPreserveNaN(ExecState* exec) const 44 44 { 45 45 int32_t i; … … 69 69 } 70 70 71 int32_t JSValue ::toInt32SlowCase(ExecState* exec, bool& ok) const71 int32_t JSValuePtr::toInt32SlowCase(ExecState* exec, bool& ok) const 72 72 { 73 73 return JSC::toInt32SlowCase(toNumber(exec), ok); … … 92 92 } 93 93 94 uint32_t JSValue ::toUInt32SlowCase(ExecState* exec, bool& ok) const94 uint32_t JSValuePtr::toUInt32SlowCase(ExecState* exec, bool& ok) const 95 95 { 96 96 return JSC::toUInt32SlowCase(toNumber(exec), ok); 97 97 } 98 98 99 float JSValue::toFloat(ExecState* exec) const100 {101 return static_cast<float>(toNumber(exec));102 }103 104 99 } // namespace JSC -
trunk/JavaScriptCore/runtime/JSValue.h
r39670 r39769 29 29 #include "CallData.h" 30 30 #include "ConstructData.h" 31 #include <wtf/Noncopyable.h>32 31 33 32 namespace JSC { … … 46 45 enum PreferredPrimitiveType { NoPreference, PreferNumber, PreferString }; 47 46 48 class JSValue : Noncopyable { 49 protected: 50 JSValue() { } 51 virtual ~JSValue() { } 52 47 class JSImmediate; 48 class JSValueEncodedAsPointer; 49 50 class JSValuePtr { 51 friend class JSImmediate; 52 53 static JSValuePtr makeImmediate(intptr_t value) 54 { 55 return JSValuePtr(reinterpret_cast<JSCell*>(value)); 56 } 57 58 intptr_t immediateValue() 59 { 60 return reinterpret_cast<intptr_t>(m_ptr); 61 } 62 53 63 public: 64 JSValuePtr() 65 : m_ptr(0) 66 { 67 } 68 69 JSValuePtr(JSCell* ptr) 70 : m_ptr(ptr) 71 { 72 } 73 74 JSValuePtr(const JSCell* ptr) 75 : m_ptr(const_cast<JSCell*>(ptr)) 76 { 77 } 78 79 JSValuePtr* operator->() const 80 { 81 return const_cast<JSValuePtr*>(this); 82 } 83 84 operator bool() const 85 { 86 return m_ptr; 87 } 88 89 bool operator==(const JSValuePtr other) const 90 { 91 return m_ptr == other.m_ptr; 92 } 93 94 bool operator!=(const JSValuePtr other) const 95 { 96 return m_ptr != other.m_ptr; 97 } 98 99 static JSValueEncodedAsPointer* encode(JSValuePtr value) 100 { 101 return reinterpret_cast<JSValueEncodedAsPointer*>(value.m_ptr); 102 } 103 104 static JSValuePtr decode(JSValueEncodedAsPointer* ptr) 105 { 106 return JSValuePtr(reinterpret_cast<JSCell*>(ptr)); 107 } 108 54 109 // Querying the type. 55 110 bool isUndefined() const; … … 90 145 double toNumber(ExecState*) const; 91 146 JSValuePtr toJSNumber(ExecState*) const; // Fast path for when you expect that the value is an immediate number. 92 93 147 UString toString(ExecState*) const; 94 148 JSObject* toObject(ExecState*) const; … … 103 157 104 158 // Floating point conversions. 105 float toFloat(ExecState* ) const;159 float toFloat(ExecState* exec) const { return static_cast<float>(toNumber(exec)); } 106 160 107 161 // Garbage collection. … … 116 170 void put(ExecState*, const Identifier& propertyName, JSValuePtr, PutPropertySlot&); 117 171 void put(ExecState*, unsigned propertyName, JSValuePtr); 118 bool deleteProperty(ExecState*, const Identifier& propertyName);119 bool deleteProperty(ExecState*, unsigned propertyName);120 172 121 173 bool needsThisConversion() const; … … 126 178 JSValuePtr getJSNumber(); // 0 if this is not a JSNumber or number object 127 179 128 JSValuePtr asValue() const;129 130 180 JSCell* asCell() const; 131 181 132 182 private: 133 bool getPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);134 bool getPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); 183 inline const JSValuePtr asValue() const { return *this; } 184 135 185 int32_t toInt32SlowCase(ExecState*, bool& ok) const; 136 186 uint32_t toUInt32SlowCase(ExecState*, bool& ok) const; 187 188 JSCell* m_ptr; 137 189 }; 138 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->() const172 {173 return m_ptr;174 }175 176 operator bool() const177 {178 return m_ptr;179 }180 181 bool operator==(const JSValuePtr other) const182 {183 return m_ptr == other.m_ptr;184 }185 186 bool operator!=(const JSValuePtr other) const187 {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() const206 {207 return JSValuePtr(this);208 }209 190 210 191 inline JSValuePtr noValue() … … 213 194 } 214 195 215 inline bool operator==(const JSValuePtr a, const JS Value* b) { return a == JSValuePtr(b); }216 inline bool operator==(const JS Value* a, const JSValuePtr b) { return JSValuePtr(a) == b; }217 218 inline bool operator!=(const JSValuePtr a, const JS Value* b) { return a != JSValuePtr(b); }219 inline bool operator!=(const JS Value* a, const JSValuePtr b) { return JSValuePtr(a) != b; }196 inline bool operator==(const JSValuePtr a, const JSCell* b) { return a == JSValuePtr(b); } 197 inline bool operator==(const JSCell* a, const JSValuePtr b) { return JSValuePtr(a) == b; } 198 199 inline bool operator!=(const JSValuePtr a, const JSCell* b) { return a != JSValuePtr(b); } 200 inline bool operator!=(const JSCell* a, const JSValuePtr b) { return JSValuePtr(a) != b; } 220 201 221 202 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.