Changeset 1825 in webkit for trunk/JavaScriptCore/kjs/value.cpp
- Timestamp:
- Aug 15, 2002, 5:02:07 AM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/value.cpp
r1824 r1825 37 37 #include "error_object.h" 38 38 #include "nodes.h" 39 #include "simple_number.h" 39 40 40 41 using namespace KJS; … … 64 65 bool ValueImp::marked() const 65 66 { 66 // FIXNUM: need special case for fixnum, they should act as if 67 // always marked. 68 return (_flags & VI_MARKED); 67 // simple numbers are always considered marked 68 return SimpleNumber::isSimpleNumber(this) || (_flags & VI_MARKED); 69 69 } 70 70 71 71 void ValueImp::setGcAllowed() 72 72 { 73 // FIXNUM: need special case for fixnum, should be a no-op 74 //fprintf(stderr,"ValueImp::setGcAllowed %p\n",(void*)this); 75 _flags |= VI_GCALLOWED; 73 // simple numbers are never seen by the collector so setting this 74 // flag is irrelevant 75 if (!SimpleNumber::isSimpleNumber(this)) { 76 //fprintf(stderr,"ValueImp::setGcAllowed %p\n",(void*)this); 77 _flags |= VI_GCALLOWED; 78 } 76 79 } 77 80 … … 95 98 { 96 99 unsigned i; 97 if ( toUInt32(i))100 if (dispatchToUInt32(i)) 98 101 return (int)i; 99 102 return int(roundValue(exec, Value(const_cast<ValueImp*>(this)))); … … 103 106 { 104 107 unsigned i; 105 if ( toUInt32(i))108 if (dispatchToUInt32(i)) 106 109 return (int)i; 107 110 … … 118 121 { 119 122 unsigned i; 120 if ( toUInt32(i))123 if (dispatchToUInt32(i)) 121 124 return i; 122 125 … … 130 133 { 131 134 unsigned i; 132 if ( toUInt32(i))135 if (dispatchToUInt32(i)) 133 136 return (unsigned short)i; 134 137 … … 181 184 Type ValueImp::dispatchType() const 182 185 { 183 // FIXNUM: need special case for fixnums here 184 return this->type(); 186 if (SimpleNumber::isSimpleNumber(this)) { 187 return NumberType; 188 } else { 189 return this->type(); 190 } 185 191 } 186 192 187 193 Value ValueImp::dispatchToPrimitive(ExecState *exec, Type preferredType) const 188 194 { 189 // FIXNUM: need special case for fixnums here 190 return this->toPrimitive(exec, preferredType); 195 if (SimpleNumber::isSimpleNumber(this)) { 196 return Number((NumberImp*)this); 197 } else { 198 return this->toPrimitive(exec, preferredType); 199 } 191 200 } 192 201 193 202 bool ValueImp::dispatchToBoolean(ExecState *exec) const 194 203 { 195 // FIXNUM: need special case for fixnums here 196 return this->toBoolean(exec); 204 if (SimpleNumber::isSimpleNumber(this)) { 205 return SimpleNumber::longValue(this); 206 } else { 207 return this->toBoolean(exec); 208 } 197 209 } 198 210 199 211 double ValueImp::dispatchToNumber(ExecState *exec) const 200 212 { 201 // FIXNUM: need special case for fixnums here 202 return this->toNumber(exec); 213 if (SimpleNumber::isSimpleNumber(this)) { 214 return SimpleNumber::longValue(this); 215 } else { 216 return this->toNumber(exec); 217 } 203 218 } 204 219 205 220 UString ValueImp::dispatchToString(ExecState *exec) const 206 221 { 207 // FIXNUM: need special case for fixnums here 208 return this->toString(exec); 222 if (SimpleNumber::isSimpleNumber(this)) { 223 return UString::from(SimpleNumber::longValue(this)); 224 } else { 225 return this->toString(exec); 226 } 209 227 } 210 228 211 229 Object ValueImp::dispatchToObject(ExecState *exec) const 212 230 { 213 // FIXNUM: need special case for fixnums here 214 return this->toObject(exec); 231 if (SimpleNumber::isSimpleNumber(this)) { 232 List args; 233 args.append(Number(static_cast<NumberImp*>(const_cast<ValueImp *>(this)))); 234 return Object::dynamicCast(exec->interpreter()->builtinNumber().construct(exec,args)); 235 } else { 236 return this->toObject(exec); 237 } 215 238 } 216 239 217 240 bool ValueImp::dispatchToUInt32(unsigned& result) const 218 241 { 219 // FIXNUM: need special case for fixnums here 220 return this->toUInt32(result); 242 if (SimpleNumber::isSimpleNumber(this)) { 243 result = SimpleNumber::longValue(this); 244 return true; 245 } else { 246 return this->toUInt32(result); 247 } 221 248 } 222 249 223 250 Value ValueImp::dispatchGetBase(ExecState *exec) const 224 251 { 225 // FIXNUM: need special case for fixnums here 226 return this->getBase(exec); 252 if (SimpleNumber::isSimpleNumber(this)) { 253 Object err = Error::create(exec, ReferenceError, I18N_NOOP("Invalid reference base")); 254 exec->setException(err); 255 return err; 256 } else { 257 return this->getBase(exec); 258 } 227 259 } 228 260 229 261 UString ValueImp::dispatchGetPropertyName(ExecState *exec) const 230 262 { 231 // FIXNUM: need special case for fixnums here 232 return this->getPropertyName(exec); 233 } 234 235 #if 0 236 Value ValueImp::dispatchGetValue(ExecState *exec) const 237 { 238 // FIXNUM: need special case for fixnums here 239 return this->getValue(exec); 240 } 241 #endif 263 if (SimpleNumber::isSimpleNumber(this)) { 264 return UString(); 265 } else { 266 return this->getPropertyName(exec); 267 } 268 } 242 269 243 270 void ValueImp::dispatchPutValue(ExecState *exec, const Value& w) 244 271 { 245 // FIXNUM: need special case for fixnums here 246 return this->putValue(exec, w); 272 if (SimpleNumber::isSimpleNumber(this)) { 273 Object err = Error::create(exec,ReferenceError); 274 exec->setException(err); 275 } else { 276 return this->putValue(exec, w); 277 } 247 278 } 248 279 249 280 bool ValueImp::dispatchDeleteValue(ExecState *exec) 250 281 { 251 // FIXNUM: need special case for fixnums here 252 return this->deleteValue(exec); 282 if (SimpleNumber::isSimpleNumber(this)) { 283 Object err = Error::create(exec,ReferenceError); 284 exec->setException(err); 285 return false; 286 } else { 287 return this->deleteValue(exec); 288 } 253 289 } 254 290 … … 372 408 // ------------------------------ Number --------------------------------------- 373 409 374 // FIXNUM: need fixnum special case in below constructor375 410 Number::Number(int i) 376 : Value(new NumberImp(static_cast<double>(i))) { } 377 378 // FIXNUM: need fixnum special case in below constructor 411 : Value(SimpleNumber::fitsInSimpleNumber(i) ? SimpleNumber::makeSimpleNumber(i) : new NumberImp(static_cast<double>(i))) { } 412 379 413 Number::Number(unsigned int u) 380 : Value(new NumberImp(static_cast<double>(u))) { } 381 382 // FIXNUM: need fixnum special case in below constructor 414 : Value(SimpleNumber::fitsInSimpleNumber(u) ? SimpleNumber::makeSimpleNumber(u) : new NumberImp(static_cast<double>(u))) { } 415 383 416 Number::Number(double d) 384 : Value(new NumberImp(d)) { } 385 386 // FIXNUM: need fixnum special case in below constructor 417 : Value(SimpleNumber::fitsInSimpleNumber((long)d) ? SimpleNumber::makeSimpleNumber((long)d) : new NumberImp(d)) { } 418 387 419 Number::Number(long int l) 388 : Value(new NumberImp(static_cast<double>(l))) { } 389 390 // FIXNUM: need fixnum special case in below constructor 420 : Value(SimpleNumber::fitsInSimpleNumber(l) ? SimpleNumber::makeSimpleNumber(l) : new NumberImp(static_cast<double>(l))) { } 421 391 422 Number::Number(long unsigned int l) 392 : Value( new NumberImp(static_cast<double>(l))) { }423 : Value(SimpleNumber::fitsInSimpleNumber(l) ? SimpleNumber::makeSimpleNumber(l) : new NumberImp(static_cast<double>(l))) { } 393 424 394 425 Number Number::dynamicCast(const Value &v) … … 402 433 double Number::value() const 403 434 { 404 assert(rep); 405 return ((NumberImp*)rep)->value(); 435 if (SimpleNumber::isSimpleNumber(rep)) { 436 return (double)SimpleNumber::longValue(rep); 437 } else { 438 assert(rep); 439 return ((NumberImp*)rep)->value(); 440 } 406 441 } 407 442
Note:
See TracChangeset
for help on using the changeset viewer.