Changeset 1799 in webkit for trunk/JavaScriptCore/kjs/value.cpp
- Timestamp:
- Aug 12, 2002, 1:14:02 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/value.cpp
r1789 r1799 83 83 } 84 84 85 bool ValueImp::toUInt32(unsigned&) const 86 { 87 return false; 88 } 89 85 90 // ECMA 9.4 86 91 int ValueImp::toInteger(ExecState *exec) const 87 92 { 93 unsigned i; 94 if (toUInt32(i)) 95 return (int)i; 88 96 return int(roundValue(exec, Value(const_cast<ValueImp*>(this)))); 89 97 } … … 91 99 int ValueImp::toInt32(ExecState *exec) const 92 100 { 101 unsigned i; 102 if (toUInt32(i)) 103 return (int)i; 104 93 105 double d = roundValue(exec, Value(const_cast<ValueImp*>(this))); 94 106 double d32 = fmod(d, D32); … … 102 114 unsigned int ValueImp::toUInt32(ExecState *exec) const 103 115 { 116 unsigned i; 117 if (toUInt32(i)) 118 return i; 119 104 120 double d = roundValue(exec, Value(const_cast<ValueImp*>(this))); 105 121 double d32 = fmod(d, D32); … … 110 126 unsigned short ValueImp::toUInt16(ExecState *exec) const 111 127 { 128 unsigned i; 129 if (toUInt32(i)) 130 return (unsigned short)i; 131 112 132 double d = roundValue(exec, Value(const_cast<ValueImp*>(this))); 113 133 double d16 = fmod(d, D16); … … 119 139 Value ValueImp::getBase(ExecState *exec) const 120 140 { 121 if (type() != ReferenceType) { 122 Object err = Error::create(exec, ReferenceError, I18N_NOOP("Invalid reference base")); 123 exec->setException(err); 124 return err; 125 } 126 127 return (static_cast<const ReferenceImp*>(this))->getBase(); 141 Object err = Error::create(exec, ReferenceError, I18N_NOOP("Invalid reference base")); 142 exec->setException(err); 143 return err; 128 144 } 129 145 … … 131 147 UString ValueImp::getPropertyName(ExecState * /*exec*/) const 132 148 { 133 if (type() != ReferenceType) 134 // the spec wants a runtime error here. But getValue() and putValue() 135 // will catch this case on their own earlier. When returning a Null 136 // string we should be on the safe side. 137 return UString(); 138 139 return (static_cast<const ReferenceImp*>(this))->getPropertyName(); 149 // the spec wants a runtime error here. But getValue() and putValue() 150 // will catch this case on their own earlier. When returning a Null 151 // string we should be on the safe side. 152 return UString(); 140 153 } 141 154 … … 143 156 Value ValueImp::getValue(ExecState *exec) const 144 157 { 145 if (type() != ReferenceType) 146 return Value(const_cast<ValueImp*>(this)); 147 148 Value o = getBase(exec); 149 150 if (o.isNull() || o.type() == NullType) { 151 UString m = I18N_NOOP("Can't find variable: ") + getPropertyName(exec); 152 Object err = Error::create(exec, ReferenceError, m.ascii()); 153 exec->setException(err); 154 return err; 155 } 156 157 if (o.type() != ObjectType) { 158 UString m = I18N_NOOP("Base is not an object"); 159 Object err = Error::create(exec, ReferenceError, m.ascii()); 160 exec->setException(err); 161 return err; 162 } 163 164 return static_cast<ObjectImp*>(o.imp())->get(exec,getPropertyName(exec)); 165 } 166 167 void ValueImp::putValue(ExecState *exec, const Value w) 168 { 169 if (type() != ReferenceType) { 170 Object err = Error::create(exec,ReferenceError); 171 exec->setException(err); 172 return; 173 } 174 175 #ifdef KJS_VERBOSE 176 printInfo(exec,(UString("setting property ")+getPropertyName(exec)).cstring().c_str(),w); 177 #endif 178 Value o = getBase(exec); 179 if (o.type() == NullType) 180 exec->interpreter()->globalObject().put(exec,getPropertyName(exec), w); 181 else { 182 static_cast<ObjectImp*>(o.imp())->put(exec,getPropertyName(exec), w); 183 } 184 185 return; 186 } 187 188 bool KJS::operator==(const Value &v1, const Value &v2) 189 { 190 return (v1.imp() == v2.imp()); 191 } 192 193 bool KJS::operator!=(const Value &v1, const Value &v2) 194 { 195 return (v1.imp() != v2.imp()); 196 } 197 198 199 158 return Value(const_cast<ValueImp*>(this)); 159 } 160 161 void ValueImp::putValue(ExecState *exec, const Value& w) 162 { 163 Object err = Error::create(exec,ReferenceError); 164 exec->setException(err); 165 } 166 167 bool ValueImp::deleteValue(ExecState *exec) 168 { 169 Object err = Error::create(exec,ReferenceError); 170 exec->setException(err); 171 return false; 172 } 200 173 201 174 // ------------------------------ Value ---------------------------------------- 202 203 Value::Value()204 {205 rep = 0;206 }207 175 208 176 Value::Value(ValueImp *v) … … 251 219 } 252 220 253 bool Value::isNull() const254 {255 return (rep == 0);256 }257 258 ValueImp *Value::imp() const259 {260 return rep;261 }262 263 Type Value::type() const264 {265 return rep->type();266 }267 268 bool Value::isA(Type t) const269 {270 return (type() == t);271 }272 273 Value Value::toPrimitive(ExecState *exec, Type preferredType) const274 {275 return rep->toPrimitive(exec,preferredType);276 }277 278 bool Value::toBoolean(ExecState *exec) const279 {280 return rep->toBoolean(exec);281 }282 283 double Value::toNumber(ExecState *exec) const284 {285 return rep->toNumber(exec);286 }287 288 int Value::toInteger(ExecState *exec) const289 {290 return rep->toInteger(exec);291 }292 293 int Value::toInt32(ExecState *exec) const294 {295 return rep->toInt32(exec);296 }297 298 unsigned int Value::toUInt32(ExecState *exec) const299 {300 return rep->toUInt32(exec);301 }302 303 unsigned short Value::toUInt16(ExecState *exec) const304 {305 return rep->toUInt16(exec);306 }307 308 UString Value::toString(ExecState *exec) const309 {310 return rep->toString(exec);311 }312 313 Object Value::toObject(ExecState *exec) const314 {315 return rep->toObject(exec);316 }317 318 Value Value::getBase(ExecState *exec) const319 {320 return rep->getBase(exec);321 }322 323 UString Value::getPropertyName(ExecState *exec) const324 {325 return rep->getPropertyName(exec);326 }327 328 Value Value::getValue(ExecState *exec) const329 {330 return rep->getValue(exec);331 }332 333 void Value::putValue(ExecState *exec, const Value w)334 {335 rep->putValue(exec,w);336 }337 338 221 // ------------------------------ Undefined ------------------------------------ 339 222 340 223 Undefined::Undefined() : Value(UndefinedImp::staticUndefined) 341 224 { 342 }343 344 Undefined::~Undefined() {345 }346 347 Undefined::Undefined(UndefinedImp *v) : Value(v)348 {349 }350 351 Undefined::Undefined(const Undefined &v) : Value(v)352 {353 }354 355 Undefined& Undefined::operator=(const Undefined &v)356 {357 Value::operator=(v);358 return *this;359 225 } 360 226 … … 373 239 } 374 240 375 Null::~Null() {376 }377 378 379 Null::Null(NullImp *v) : Value(v)380 {381 }382 383 Null::Null(const Null &v) : Value(v)384 {385 }386 387 Null& Null::operator=(const Null &v)388 {389 Value::operator=(v);390 return *this;391 }392 393 241 Null Null::dynamicCast(const Value &v) 394 242 { … … 406 254 } 407 255 408 Boolean::~Boolean() { }409 410 411 412 Boolean::Boolean(BooleanImp *v) : Value(v)413 {414 }415 416 Boolean::Boolean(const Boolean &v) : Value(v)417 {418 }419 420 Boolean& Boolean::operator=(const Boolean &v)421 {422 Value::operator=(v);423 return *this;424 }425 426 427 256 bool Boolean::value() const 428 257 { … … 445 274 } 446 275 447 String::~String() { }448 449 String::String(StringImp *v) : Value(v)450 {451 }452 453 String::String(const String &v) : Value(v)454 {455 }456 457 String& String::operator=(const String &v)458 {459 Value::operator=(v);460 return *this;461 }462 463 276 UString String::value() const 464 277 { … … 492 305 : Value(new NumberImp(static_cast<double>(l))) { } 493 306 494 Number::~Number() { }495 496 Number::Number(NumberImp *v) : Value(v)497 {498 }499 500 Number::Number(const Number &v) : Value(v)501 {502 }503 504 Number& Number::operator=(const Number &v)505 {506 Value::operator=(v);507 return *this;508 }509 510 307 Number Number::dynamicCast(const Value &v) 511 308 { … … 536 333 return KJS::isInf(value()); 537 334 } 538
Note:
See TracChangeset
for help on using the changeset viewer.