Changeset 11527 in webkit for trunk/JavaScriptCore/kjs/value.h
- Timestamp:
- Dec 10, 2005, 6:06:17 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/value.h
r11525 r11527 43 43 class ClassInfo; 44 44 class ExecState; 45 class ObjectImp;45 class JSObject; 46 46 47 47 /** … … 59 59 60 60 /** 61 * ValueImpis the base type for all primitives (Undefined, Null, Boolean,61 * JSValue is the base type for all primitives (Undefined, Null, Boolean, 62 62 * String, Number) and objects in ECMAScript. 63 63 * 64 * Note: you should never inherit from ValueImpas it is for primitive types64 * Note: you should never inherit from JSValue as it is for primitive types 65 65 * only (all of which are provided internally by KJS). Instead, inherit from 66 * ObjectImp.66 * JSObject. 67 67 */ 68 class ValueImp{69 friend class AllocatedValueImp; // so it can derive from this class68 class JSValue { 69 friend class JSCell; // so it can derive from this class 70 70 friend class ProtectedValues; // so it can call downcast() 71 71 72 72 private: 73 ValueImp();74 virtual ~ ValueImp();73 JSValue(); 74 virtual ~JSValue(); 75 75 76 76 public: … … 92 92 bool getString(UString&) const; 93 93 UString getString() const; // null string if not a string 94 ObjectImp*getObject(); // NULL if not an object95 const ObjectImp*getObject() const; // NULL if not an object94 JSObject *getObject(); // NULL if not an object 95 const JSObject *getObject() const; // NULL if not an object 96 96 97 97 // Extracting integer values. … … 99 99 100 100 // Basic conversions. 101 ValueImp*toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const;101 JSValue *toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const; 102 102 bool toBoolean(ExecState *exec) const; 103 103 double toNumber(ExecState *exec) const; 104 104 UString toString(ExecState *exec) const; 105 ObjectImp*toObject(ExecState *exec) const;105 JSObject *toObject(ExecState *exec) const; 106 106 107 107 // Integer conversions. … … 117 117 private: 118 118 // Implementation details. 119 AllocatedValueImp*downcast();120 const AllocatedValueImp*downcast() const;119 JSCell *downcast(); 120 const JSCell *downcast() const; 121 121 122 122 // Give a compile time error if we try to copy one of these. 123 ValueImp(const ValueImp&);124 ValueImp& operator=(const ValueImp&);123 JSValue(const JSValue&); 124 JSValue& operator=(const JSValue&); 125 125 }; 126 126 127 class AllocatedValueImp : public ValueImp{127 class JSCell : public JSValue { 128 128 friend class Collector; 129 129 friend class UndefinedImp; … … 132 132 friend class NumberImp; 133 133 friend class StringImp; 134 friend class ObjectImp;134 friend class JSObject; 135 135 private: 136 AllocatedValueImp();137 virtual ~ AllocatedValueImp();136 JSCell(); 137 virtual ~JSCell(); 138 138 public: 139 139 // Querying the type. … … 151 151 bool getString(UString&) const; 152 152 UString getString() const; // null string if not a string 153 ObjectImp*getObject(); // NULL if not an object154 const ObjectImp*getObject() const; // NULL if not an object153 JSObject *getObject(); // NULL if not an object 154 const JSObject *getObject() const; // NULL if not an object 155 155 156 156 // Extracting integer values. … … 158 158 159 159 // Basic conversions. 160 virtual ValueImp*toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const = 0;160 virtual JSValue *toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const = 0; 161 161 virtual bool toBoolean(ExecState *exec) const = 0; 162 162 virtual double toNumber(ExecState *exec) const = 0; 163 163 virtual UString toString(ExecState *exec) const = 0; 164 virtual ObjectImp*toObject(ExecState *exec) const = 0;164 virtual JSObject *toObject(ExecState *exec) const = 0; 165 165 166 166 // Garbage collection. … … 173 173 }; 174 174 175 AllocatedValueImp*jsUndefined();176 AllocatedValueImp*jsNull();177 178 AllocatedValueImp*jsBoolean(bool);179 180 ValueImp*jsNumber(double);181 ValueImp*jsNaN();182 183 AllocatedValueImp*jsString(const UString &); // returns empty string if passed null string184 AllocatedValueImp*jsString(const char * = ""); // returns empty string if passed 0175 JSCell *jsUndefined(); 176 JSCell *jsNull(); 177 178 JSCell *jsBoolean(bool); 179 180 JSValue *jsNumber(double); 181 JSValue *jsNaN(); 182 183 JSCell *jsString(const UString &); // returns empty string if passed null string 184 JSCell *jsString(const char * = ""); // returns empty string if passed 0 185 185 186 186 extern const double NaN; … … 189 189 class ConstantValues { 190 190 public: 191 static AllocatedValueImp*undefined;192 static AllocatedValueImp*null;193 static AllocatedValueImp*jsFalse;194 static AllocatedValueImp*jsTrue;191 static JSCell *undefined; 192 static JSCell *null; 193 static JSCell *jsFalse; 194 static JSCell *jsTrue; 195 195 196 196 static void initIfNeeded(); … … 198 198 }; 199 199 200 inline AllocatedValueImp*jsUndefined()200 inline JSCell *jsUndefined() 201 201 { 202 202 return ConstantValues::undefined; 203 203 } 204 204 205 inline AllocatedValueImp*jsNull()205 inline JSCell *jsNull() 206 206 { 207 207 return ConstantValues::null; 208 208 } 209 209 210 inline AllocatedValueImp*jsBoolean(bool b)210 inline JSCell *jsBoolean(bool b) 211 211 { 212 212 return b ? ConstantValues::jsTrue : ConstantValues::jsFalse; 213 213 } 214 214 215 inline ValueImp*jsNaN()215 inline JSValue *jsNaN() 216 216 { 217 217 return SimpleNumber::make(NaN); 218 218 } 219 219 220 inline ValueImp::ValueImp()221 { 222 } 223 224 inline ValueImp::~ValueImp()225 { 226 } 227 228 inline AllocatedValueImp::AllocatedValueImp()220 inline JSValue::JSValue() 221 { 222 } 223 224 inline JSValue::~JSValue() 225 { 226 } 227 228 inline JSCell::JSCell() 229 229 : m_marked(false) 230 230 { 231 231 } 232 232 233 inline AllocatedValueImp::~AllocatedValueImp()234 { 235 } 236 237 inline bool AllocatedValueImp::isBoolean() const233 inline JSCell::~JSCell() 234 { 235 } 236 237 inline bool JSCell::isBoolean() const 238 238 { 239 239 return type() == BooleanType; 240 240 } 241 241 242 inline bool AllocatedValueImp::isNumber() const242 inline bool JSCell::isNumber() const 243 243 { 244 244 return type() == NumberType; 245 245 } 246 246 247 inline bool AllocatedValueImp::isString() const247 inline bool JSCell::isString() const 248 248 { 249 249 return type() == StringType; 250 250 } 251 251 252 inline bool AllocatedValueImp::isObject() const252 inline bool JSCell::isObject() const 253 253 { 254 254 return type() == ObjectType; 255 255 } 256 256 257 inline bool AllocatedValueImp::marked() const257 inline bool JSCell::marked() const 258 258 { 259 259 return m_marked; 260 260 } 261 261 262 inline void AllocatedValueImp::mark()262 inline void JSCell::mark() 263 263 { 264 264 m_marked = true; 265 265 } 266 266 267 inline AllocatedValueImp *ValueImp::downcast()267 inline JSCell *JSValue::downcast() 268 268 { 269 269 assert(!SimpleNumber::is(this)); 270 return static_cast< AllocatedValueImp*>(this);271 } 272 273 inline const AllocatedValueImp *ValueImp::downcast() const270 return static_cast<JSCell *>(this); 271 } 272 273 inline const JSCell *JSValue::downcast() const 274 274 { 275 275 assert(!SimpleNumber::is(this)); 276 return static_cast<const AllocatedValueImp*>(this);277 } 278 279 inline bool ValueImp::isUndefined() const276 return static_cast<const JSCell *>(this); 277 } 278 279 inline bool JSValue::isUndefined() const 280 280 { 281 281 return this == jsUndefined(); 282 282 } 283 283 284 inline bool ValueImp::isNull() const284 inline bool JSValue::isNull() const 285 285 { 286 286 return this == jsNull(); 287 287 } 288 288 289 inline bool ValueImp::isUndefinedOrNull() const289 inline bool JSValue::isUndefinedOrNull() const 290 290 { 291 291 return this == jsUndefined() || this == jsNull(); 292 292 } 293 293 294 inline bool ValueImp::isBoolean() const294 inline bool JSValue::isBoolean() const 295 295 { 296 296 return !SimpleNumber::is(this) && downcast()->isBoolean(); 297 297 } 298 298 299 inline bool ValueImp::isNumber() const299 inline bool JSValue::isNumber() const 300 300 { 301 301 return SimpleNumber::is(this) || downcast()->isNumber(); 302 302 } 303 303 304 inline bool ValueImp::isString() const304 inline bool JSValue::isString() const 305 305 { 306 306 return !SimpleNumber::is(this) && downcast()->isString(); 307 307 } 308 308 309 inline bool ValueImp::isObject() const309 inline bool JSValue::isObject() const 310 310 { 311 311 return !SimpleNumber::is(this) && downcast()->isObject(); 312 312 } 313 313 314 inline bool ValueImp::isObject(const ClassInfo *c) const314 inline bool JSValue::isObject(const ClassInfo *c) const 315 315 { 316 316 return !SimpleNumber::is(this) && downcast()->isObject(c); 317 317 } 318 318 319 inline bool ValueImp::getBoolean(bool& v) const319 inline bool JSValue::getBoolean(bool& v) const 320 320 { 321 321 return !SimpleNumber::is(this) && downcast()->getBoolean(v); 322 322 } 323 323 324 inline bool ValueImp::getNumber(double& v) const324 inline bool JSValue::getNumber(double& v) const 325 325 { 326 326 if (SimpleNumber::is(this)) { … … 331 331 } 332 332 333 inline double ValueImp::getNumber() const333 inline double JSValue::getNumber() const 334 334 { 335 335 return SimpleNumber::is(this) ? SimpleNumber::value(this) : downcast()->getNumber(); 336 336 } 337 337 338 inline bool ValueImp::getString(UString& s) const338 inline bool JSValue::getString(UString& s) const 339 339 { 340 340 return !SimpleNumber::is(this) && downcast()->getString(s); 341 341 } 342 342 343 inline UString ValueImp::getString() const343 inline UString JSValue::getString() const 344 344 { 345 345 return SimpleNumber::is(this) ? UString() : downcast()->getString(); 346 346 } 347 347 348 inline ObjectImp *ValueImp::getObject()348 inline JSObject *JSValue::getObject() 349 349 { 350 350 return SimpleNumber::is(this) ? 0 : downcast()->getObject(); 351 351 } 352 352 353 inline const ObjectImp *ValueImp::getObject() const353 inline const JSObject *JSValue::getObject() const 354 354 { 355 355 return SimpleNumber::is(this) ? 0 : downcast()->getObject(); 356 356 } 357 357 358 inline bool ValueImp::getUInt32(uint32_t& v) const358 inline bool JSValue::getUInt32(uint32_t& v) const 359 359 { 360 360 if (SimpleNumber::is(this)) { … … 368 368 } 369 369 370 inline void ValueImp::mark()370 inline void JSValue::mark() 371 371 { 372 372 if (!SimpleNumber::is(this)) … … 374 374 } 375 375 376 inline bool ValueImp::marked() const376 inline bool JSValue::marked() const 377 377 { 378 378 return SimpleNumber::is(this) || downcast()->marked(); 379 379 } 380 380 381 inline Type ValueImp::type() const381 inline Type JSValue::type() const 382 382 { 383 383 return SimpleNumber::is(this) ? NumberType : downcast()->type(); 384 384 } 385 385 386 inline ValueImp *ValueImp::toPrimitive(ExecState *exec, Type preferredType) const387 { 388 return SimpleNumber::is(this) ? const_cast< ValueImp*>(this) : downcast()->toPrimitive(exec, preferredType);389 } 390 391 inline bool ValueImp::toBoolean(ExecState *exec) const386 inline JSValue *JSValue::toPrimitive(ExecState *exec, Type preferredType) const 387 { 388 return SimpleNumber::is(this) ? const_cast<JSValue *>(this) : downcast()->toPrimitive(exec, preferredType); 389 } 390 391 inline bool JSValue::toBoolean(ExecState *exec) const 392 392 { 393 393 if (SimpleNumber::is(this)) { … … 399 399 } 400 400 401 inline double ValueImp::toNumber(ExecState *exec) const401 inline double JSValue::toNumber(ExecState *exec) const 402 402 { 403 403 return SimpleNumber::is(this) ? SimpleNumber::value(this) : downcast()->toNumber(exec); 404 404 } 405 405 406 inline UString ValueImp::toString(ExecState *exec) const406 inline UString JSValue::toString(ExecState *exec) const 407 407 { 408 408 if (SimpleNumber::is(this)) {
Note:
See TracChangeset
for help on using the changeset viewer.