Changeset 39769 in webkit for trunk/JavaScriptCore/runtime/JSValue.h
- Timestamp:
- Jan 9, 2009, 4:14:25 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.