Changeset 1799 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Aug 12, 2002, 1:14:02 PM (23 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/array_object.cpp
r1623 r1799 40 40 const ClassInfo ArrayInstanceImp::info = {"Array", 0, 0, 0}; 41 41 42 ArrayInstanceImp::ArrayInstanceImp(const Object &proto )42 ArrayInstanceImp::ArrayInstanceImp(const Object &proto, unsigned initialLength) 43 43 : ObjectImp(proto) 44 { 44 , length(initialLength) 45 , capacity(length) 46 , storage(length ? new Undefined[length] : 0) 47 { 48 } 49 50 ArrayInstanceImp::ArrayInstanceImp(const Object &proto, const List &list) 51 : ObjectImp(proto) 52 , length(list.size()) 53 , capacity(length) 54 , storage(length ? new Undefined[length] : 0) 55 { 56 ListIterator it = list.begin(); 57 const unsigned l = length; 58 for (unsigned i = 0; i < l; ++i) { 59 storage[i] = it++; 60 } 61 } 62 63 ArrayInstanceImp::~ArrayInstanceImp() 64 { 65 delete [] storage; 66 } 67 68 Value ArrayInstanceImp::get(ExecState *exec, const UString &propertyName) const 69 { 70 if (propertyName == lengthPropertyName) 71 return Number(length); 72 73 bool ok; 74 unsigned index = propertyName.toULong(&ok); 75 if (ok) { 76 if (index >= length) 77 return Undefined(); 78 return storage[index]; 79 } 80 81 return ObjectImp::get(exec, propertyName); 82 } 83 84 Value ArrayInstanceImp::get(ExecState *exec, unsigned index) const 85 { 86 if (index >= length) 87 return Undefined(); 88 return storage[index]; 45 89 } 46 90 … … 48 92 void ArrayInstanceImp::put(ExecState *exec, const UString &propertyName, const Value &value, int attr) 49 93 { 50 if ((attr == None || attr == DontDelete) && !canPut(exec,propertyName)) 94 if (propertyName == lengthPropertyName) { 95 setLength(value.toUInt32(exec)); 51 96 return; 52 53 if (hasProperty(exec,propertyName)) { 54 if (propertyName == "length") { 55 Value len = get(exec,"length"); 56 unsigned int oldLen = len.toUInt32(exec); 57 unsigned int newLen = value.toUInt32(exec); 58 // shrink array 59 for (unsigned int u = newLen; u < oldLen; u++) { 60 UString p = UString::from(u); 61 if (hasOwnProperty(exec, p)) 62 deleteProperty(exec, p); 63 } 64 ObjectImp::put(exec, "length", Number(newLen), DontEnum | DontDelete); 65 return; 66 } 67 // put(p, v); 68 } // } else 69 ObjectImp::put(exec, propertyName, value, attr); 70 71 // array index ? 72 unsigned int idx; 73 if (!sscanf(propertyName.cstring().c_str(), "%u", &idx)) /* TODO */ 97 } 98 99 bool ok; 100 unsigned index = propertyName.toULong(&ok); 101 if (ok) { 102 setLength(index + 1); 103 storage[index] = value; 74 104 return; 75 76 // do we need to update/create the length property ? 77 if (hasOwnProperty(exec, "length")) { 78 Value len = get(exec, "length"); 79 if (idx < len.toUInt32(exec)) 80 return; 81 } 82 83 ObjectImp::put(exec, "length", Number(idx+1), DontDelete | DontEnum); 84 } 85 86 void ArrayInstanceImp::putDirect(ExecState *exec, const UString &propertyName, const Value &value, int attr) 87 { 88 ObjectImp::put(exec,propertyName,value,attr); 89 } 90 91 bool ArrayInstanceImp::hasOwnProperty(ExecState *exec, 92 const UString &propertyName) 93 { 94 // disable this object's prototype temporarily for the hasProperty() call 95 Value protoBackup = prototype(); 96 setPrototype(Undefined()); 97 bool b = hasProperty(exec, propertyName); 98 setPrototype(protoBackup); 99 return b; 105 } 106 107 ObjectImp::put(exec, propertyName, value, attr); 108 } 109 110 void ArrayInstanceImp::put(ExecState *exec, unsigned index, const Value &value, int attr) 111 { 112 setLength(index + 1); 113 storage[index] = value; 114 } 115 116 bool ArrayInstanceImp::hasProperty(ExecState *exec, const UString &propertyName) const 117 { 118 if (propertyName == lengthPropertyName) 119 return true; 120 121 bool ok; 122 unsigned index = propertyName.toULong(&ok); 123 if (ok) { 124 if (index >= length) 125 return false; 126 return !storage[index].isA(UndefinedType); 127 } 128 129 return ObjectImp::hasProperty(exec, propertyName); 130 } 131 132 bool ArrayInstanceImp::hasProperty(ExecState *exec, unsigned index) const 133 { 134 if (index >= length) 135 return false; 136 return !storage[index].isA(UndefinedType); 137 } 138 139 bool ArrayInstanceImp::deleteProperty(ExecState *exec, const UString &propertyName) 140 { 141 if (propertyName == lengthPropertyName) 142 return false; 143 144 bool ok; 145 unsigned index = propertyName.toULong(&ok); 146 if (ok) { 147 if (index >= length) 148 return true; 149 storage[index] = Undefined(); 150 return true; 151 } 152 153 return ObjectImp::deleteProperty(exec, propertyName); 154 } 155 156 bool ArrayInstanceImp::deleteProperty(ExecState *exec, unsigned index) 157 { 158 if (index >= length) 159 return true; 160 storage[index] = Undefined(); 161 return true; 162 } 163 164 void ArrayInstanceImp::setLength(unsigned newLength) 165 { 166 if (newLength < length) { 167 const unsigned l = length; 168 for (unsigned i = newLength; i < l; ++i) 169 storage[i] = Undefined(); 170 } 171 if (newLength > capacity) { 172 unsigned newCapacity = (newLength * 3 + 1) / 2; 173 Value *newStorage = new Undefined [newCapacity]; 174 const unsigned l = length; 175 for (unsigned i = 0; i < l; ++i) 176 newStorage[i] = storage[i]; 177 delete [] storage; 178 storage = newStorage; 179 capacity = newCapacity; 180 } 181 length = newLength; 182 } 183 184 void ArrayInstanceImp::mark() 185 { 186 ObjectImp::mark(); 187 const unsigned l = length; 188 for (unsigned i = 0; i < l; ++i) { 189 ValueImp *imp = storage[i].imp(); 190 if (!imp->marked()) 191 imp->mark(); 192 } 100 193 } 101 194 … … 124 217 ArrayPrototypeImp::ArrayPrototypeImp(ExecState *exec, 125 218 ObjectPrototypeImp *objProto) 126 : ArrayInstanceImp(Object(objProto) )219 : ArrayInstanceImp(Object(objProto), 0) 127 220 { 128 221 Value protect(this); 129 222 setInternalValue(Null()); 130 131 // The constructor will be added later, by InterpreterImp, once ArrayObjectImp has been constructed.132 put(exec,"length", Number(0), DontEnum | DontDelete);133 223 } 134 224 … … 147 237 { 148 238 Value protect(this); 149 put(exec, "length",Number(len),DontDelete|ReadOnly|DontEnum);239 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 150 240 } 151 241 … … 158 248 Value ArrayProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args) 159 249 { 160 unsigned int length = thisObj.get(exec, "length").toUInt32(exec);250 unsigned int length = thisObj.get(exec,lengthPropertyName).toUInt32(exec); 161 251 162 252 Value result; … … 184 274 if (k >= 1) 185 275 str += separator; 186 Value element = thisObj.get(exec, UString::from(k));276 Value element = thisObj.get(exec,k); 187 277 if (element.type() != UndefinedType && element.type() != NullType) 188 278 str += element.toString(exec); … … 202 292 unsigned int k = 0; 203 293 if (n > 0) 204 length = curObj.get(exec, "length").toUInt32(exec);294 length = curObj.get(exec,lengthPropertyName).toUInt32(exec); 205 295 while (k < length) { 206 UString p = UString::from(k); 207 if (curObj.hasProperty(exec,p)) 208 arr.put(exec,UString::from(n), curObj.get(exec,p)); 296 if (curObj.hasProperty(exec,k)) 297 arr.put(exec, n, curObj.get(exec, k)); 209 298 n++; 210 299 k++; 211 300 } 212 301 } else { 213 arr.put(exec, UString::from(n), curArg);302 arr.put(exec, n, curArg); 214 303 n++; 215 304 } … … 219 308 curObj = Object::dynamicCast(it++); // may be 0 220 309 } 221 arr.put(exec, "length", Number(n), DontEnum | DontDelete);310 arr.put(exec,lengthPropertyName, Number(n), DontEnum | DontDelete); 222 311 223 312 result = arr; … … 225 314 } 226 315 case Pop:{ 227 228 316 if (length == 0) { 229 thisObj.put(exec, "length", Number(length), DontEnum | DontDelete);317 thisObj.put(exec, lengthPropertyName, Number(length), DontEnum | DontDelete); 230 318 result = Undefined(); 231 319 } else { 232 UString str = UString::from(length - 1); 233 result = thisObj.get(exec,str); 234 thisObj.deleteProperty(exec, str); 235 thisObj.put(exec, "length", Number(length - 1), DontEnum | DontDelete); 320 result = thisObj.get(exec, length - 1); 321 thisObj.put(exec, lengthPropertyName, Number(length - 1), DontEnum | DontDelete); 236 322 } 237 323 break; … … 239 325 case Push: { 240 326 for (int n = 0; n < args.size(); n++) 241 thisObj.put(exec, UString::from(length + n), args[n]);327 thisObj.put(exec, length + n, args[n]); 242 328 length += args.size(); 243 thisObj.put(exec, "length", Number(length), DontEnum | DontDelete);329 thisObj.put(exec,lengthPropertyName, Number(length), DontEnum | DontDelete); 244 330 result = Number(length); 245 331 break; … … 250 336 251 337 for (unsigned int k = 0; k < middle; k++) { 252 UString str = UString::from(k); 253 UString str2 = UString::from(length - k - 1); 254 Value obj = thisObj.get(exec,str); 255 Value obj2 = thisObj.get(exec,str2); 256 if (thisObj.hasProperty(exec,str2)) { 257 if (thisObj.hasProperty(exec,str)) { 258 thisObj.put(exec, str, obj2); 259 thisObj.put(exec, str2, obj); 338 unsigned lk1 = length - k - 1; 339 Value obj = thisObj.get(exec,k); 340 Value obj2 = thisObj.get(exec,lk1); 341 if (thisObj.hasProperty(exec,lk1)) { 342 if (thisObj.hasProperty(exec,k)) { 343 thisObj.put(exec, k, obj2); 344 thisObj.put(exec, lk1, obj); 260 345 } else { 261 thisObj.put(exec, str, obj2);262 thisObj.deleteProperty(exec, str2);346 thisObj.put(exec, k, obj2); 347 thisObj.deleteProperty(exec, lk1); 263 348 } 264 349 } else { 265 if (thisObj.hasProperty(exec, str)) {266 thisObj.deleteProperty(exec, str);267 thisObj.put(exec, str2, obj);350 if (thisObj.hasProperty(exec, k)) { 351 thisObj.deleteProperty(exec, k); 352 thisObj.put(exec, lk1, obj); 268 353 } else { 269 354 // why delete something that's not there ? Strange. 270 thisObj.deleteProperty(exec, str);271 thisObj.deleteProperty(exec, str2);355 thisObj.deleteProperty(exec, k); 356 thisObj.deleteProperty(exec, lk1); 272 357 } 273 358 } … … 278 363 case Shift: { 279 364 if (length == 0) { 280 thisObj.put(exec, "length", Number(length), DontEnum | DontDelete);365 thisObj.put(exec, lengthPropertyName, Number(length), DontEnum | DontDelete); 281 366 result = Undefined(); 282 367 } else { 283 result = thisObj.get(exec, "0");368 result = thisObj.get(exec, 0); 284 369 for(unsigned int k = 1; k < length; k++) { 285 UString str = UString::from(k); 286 UString str2 = UString::from(k-1); 287 if (thisObj.hasProperty(exec, str)) { 288 Value obj = thisObj.get(exec, str); 289 thisObj.put(exec, str2, obj); 370 if (thisObj.hasProperty(exec, k)) { 371 Value obj = thisObj.get(exec, k); 372 thisObj.put(exec, k-1, obj); 290 373 } else 291 thisObj.deleteProperty(exec, str2);292 } 293 thisObj.deleteProperty(exec, UString::from(length - 1));294 thisObj.put(exec, "length", Number(length - 1), DontEnum | DontDelete);374 thisObj.deleteProperty(exec, k-1); 375 } 376 thisObj.deleteProperty(exec, length - 1); 377 thisObj.put(exec, lengthPropertyName, Number(length - 1), DontEnum | DontDelete); 295 378 } 296 379 break; … … 319 402 //printf( "Slicing from %d to %d \n", begin, end ); 320 403 for(unsigned int k = 0; k < (unsigned int) end-begin; k++) { 321 UString str = UString::from(k+begin); 322 if (thisObj.hasProperty(exec,str)) { 323 UString str2 = UString::from(k); 324 Value obj = thisObj.get(exec, str); 325 resObj.put(exec, str2, obj); 326 } 327 } 328 resObj.put(exec, "length", Number(end - begin), DontEnum | DontDelete); 404 if (thisObj.hasProperty(exec,k+begin)) { 405 Value obj = thisObj.get(exec, k+begin); 406 resObj.put(exec, k, obj); 407 } 408 } 409 resObj.put(exec, lengthPropertyName, Number(end - begin), DontEnum | DontDelete); 329 410 break; 330 411 } … … 333 414 printf("KJS Array::Sort length=%d\n", length); 334 415 for ( unsigned int i = 0 ; i<length ; ++i ) 335 printf("KJS Array::Sort: %d: %s\n", i, thisObj.get( UString::from(i)).toString().value().ascii() );416 printf("KJS Array::Sort: %d: %s\n", i, thisObj.get(i).toString().value().ascii() ); 336 417 #endif 337 418 Object sortFunction; … … 345 426 346 427 if (length == 0) { 347 thisObj.put(exec, "length", Number(0), DontEnum | DontDelete);428 thisObj.put(exec, lengthPropertyName, Number(0), DontEnum | DontDelete); 348 429 result = Undefined(); 349 430 break; … … 354 435 for ( unsigned int i = 0 ; i<length-1 ; ++i ) 355 436 { 356 Value iObj = thisObj.get(exec, UString::from(i));437 Value iObj = thisObj.get(exec,i); 357 438 unsigned int themin = i; 358 439 Value minObj = iObj; 359 440 for ( unsigned int j = i+1 ; j<length ; ++j ) 360 441 { 361 Value jObj = thisObj.get(exec, UString::from(j));442 Value jObj = thisObj.get(exec,j); 362 443 int cmp; 363 444 if (jObj.type() == UndefinedType) { … … 384 465 { 385 466 //printf("KJS Array::Sort: swapping %d and %d\n", i, themin ); 386 thisObj.put( exec, UString::from(i), minObj );387 thisObj.put( exec, UString::from(themin), iObj );467 thisObj.put( exec, i, minObj ); 468 thisObj.put( exec, themin, iObj ); 388 469 } 389 470 } … … 391 472 printf("KJS Array::Sort -- Resulting array:\n"); 392 473 for ( unsigned int i = 0 ; i<length ; ++i ) 393 printf("KJS Array::Sort: %d: %s\n", i, thisObj.get( UString::from(i)).toString().value().ascii() );474 printf("KJS Array::Sort: %d: %s\n", i, thisObj.get(i).toString().value().ascii() ); 394 475 #endif 395 476 result = thisObj; … … 409 490 //printf( "Splicing from %d, deleteCount=%d \n", begin, deleteCount ); 410 491 for(unsigned int k = 0; k < deleteCount; k++) { 411 UString str = UString::from(k+begin); 412 if (thisObj.hasProperty(exec,str)) { 413 UString str2 = UString::from(k); 414 Value obj = thisObj.get(exec, str); 415 resObj.put(exec, str2, obj); 416 } 417 } 418 resObj.put(exec, "length", Number(deleteCount), DontEnum | DontDelete); 492 if (thisObj.hasProperty(exec,k+begin)) { 493 Value obj = thisObj.get(exec, k+begin); 494 resObj.put(exec, k, obj); 495 } 496 } 497 resObj.put(exec, lengthPropertyName, Number(deleteCount), DontEnum | DontDelete); 419 498 420 499 unsigned int additionalArgs = maxInt( args.size() - 2, 0 ); … … 425 504 for ( unsigned int k = begin; k < length - deleteCount; ++k ) 426 505 { 427 UString str = UString::from(k+deleteCount); 428 UString str2 = UString::from(k+additionalArgs); 429 if (thisObj.hasProperty(exec,str)) { 430 Value obj = thisObj.get(exec, str); 431 thisObj.put(exec, str2, obj); 506 if (thisObj.hasProperty(exec,k+deleteCount)) { 507 Value obj = thisObj.get(exec, k+deleteCount); 508 thisObj.put(exec, k+additionalArgs, obj); 432 509 } 433 510 else 434 thisObj.deleteProperty(exec, str2);511 thisObj.deleteProperty(exec, k+additionalArgs); 435 512 } 436 513 for ( unsigned int k = length ; k > length - deleteCount + additionalArgs; --k ) 437 thisObj.deleteProperty(exec, UString::from(k-1));514 thisObj.deleteProperty(exec, k-1); 438 515 } 439 516 else … … 441 518 for ( unsigned int k = length - deleteCount; (int)k > begin; --k ) 442 519 { 443 UString str = UString::from(k+deleteCount-1); 444 UString str2 = UString::from(k+additionalArgs-1); 445 if (thisObj.hasProperty(exec,str)) { 446 Value obj = thisObj.get(exec, str); 447 thisObj.put(exec, str2, obj); 520 if (thisObj.hasProperty(exec,k+deleteCount-1)) { 521 Value obj = thisObj.get(exec, k+deleteCount-1); 522 thisObj.put(exec, k+additionalArgs-1, obj); 448 523 } 449 524 else 450 thisObj.deleteProperty(exec, str2);525 thisObj.deleteProperty(exec, k+additionalArgs-1); 451 526 } 452 527 } … … 454 529 for ( unsigned int k = 0; k < additionalArgs; ++k ) 455 530 { 456 thisObj.put(exec, UString::from(k+begin), args[k+2]);457 } 458 thisObj.put(exec, "length", Number(length - deleteCount + additionalArgs), DontEnum | DontDelete);531 thisObj.put(exec, k+begin, args[k+2]); 532 } 533 thisObj.put(exec, lengthPropertyName, Number(length - deleteCount + additionalArgs), DontEnum | DontDelete); 459 534 break; 460 535 } … … 463 538 for ( unsigned int k = length; k > 0; --k ) 464 539 { 465 UString str = UString::from(k-1); 466 UString str2 = UString::from(k+nrArgs-1); 467 if (thisObj.hasProperty(exec,str)) { 468 Value obj = thisObj.get(exec, str); 469 thisObj.put(exec, str2, obj); 540 if (thisObj.hasProperty(exec,k-1)) { 541 Value obj = thisObj.get(exec, k-1); 542 thisObj.put(exec, k+nrArgs-1, obj); 470 543 } else { 471 thisObj.deleteProperty(exec, str2);544 thisObj.deleteProperty(exec, k+nrArgs-1); 472 545 } 473 546 } 474 547 for ( unsigned int k = 0; k < nrArgs; ++k ) 475 thisObj.put(exec, UString::from(k), args[k]);548 thisObj.put(exec, k, args[k]); 476 549 result = Number(length + nrArgs); 477 thisObj.put(exec, "length", result, DontEnum | DontDelete);550 thisObj.put(exec, lengthPropertyName, result, DontEnum | DontDelete); 478 551 break; 479 552 } … … 494 567 Value protect(this); 495 568 // ECMA 15.4.3.1 Array.prototype 496 put(exec, "prototype", Object(arrayProto), DontEnum|DontDelete|ReadOnly);569 put(exec,prototypePropertyName, Object(arrayProto), DontEnum|DontDelete|ReadOnly); 497 570 498 571 // no. of arguments for constructor 499 put(exec, "length", Number(1), ReadOnly|DontDelete|DontEnum);572 put(exec,lengthPropertyName, Number(1), ReadOnly|DontDelete|DontEnum); 500 573 } 501 574 … … 508 581 Object ArrayObjectImp::construct(ExecState *exec, const List &args) 509 582 { 510 Object result(new ArrayInstanceImp(exec->interpreter()->builtinArrayPrototype())); 511 512 unsigned int len; 513 ListIterator it = args.begin(); 514 // a single argument might denote the array size 515 if (args.size() == 1 && it->type() == NumberType) 516 len = it->toUInt32(exec); 517 else { 518 // initialize array 519 len = args.size(); 520 for (unsigned int u = 0; it != args.end(); it++, u++) 521 result.put(exec, UString::from(u), *it); 522 } 523 524 // array size 525 result.put(exec, "length", Number(len), DontEnum | DontDelete); 526 static_cast<ArrayInstanceImp*>(result.imp())->putDirect(exec, "length", Number(len), DontEnum | DontDelete); 527 528 return result; 583 // a single numeric argument denotes the array size (!) 584 if (args.size() == 1 && args[0].type() == NumberType) 585 return Object(new ArrayInstanceImp(exec->interpreter()->builtinArrayPrototype(), args[0].toUInt32(exec))); 586 587 // otherwise the array is constructed with the arguments in it 588 return Object(new ArrayInstanceImp(exec->interpreter()->builtinArrayPrototype(), args)); 529 589 } 530 590 -
trunk/JavaScriptCore/kjs/array_object.h
r1024 r1799 30 30 class ArrayInstanceImp : public ObjectImp { 31 31 public: 32 ArrayInstanceImp(const Object &proto); 32 ArrayInstanceImp(const Object &proto, unsigned initialLength); 33 ArrayInstanceImp(const Object &proto, const List &initialValues); 34 ~ArrayInstanceImp(); 33 35 36 virtual Value get(ExecState *exec, const UString &propertyName) const; 37 virtual Value get(ExecState *exec, unsigned propertyName) const; 34 38 virtual void put(ExecState *exec, const UString &propertyName, const Value &value, int attr = None); 35 virtual void putDirect(ExecState *exec, const UString &propertyName, const Value &value, int attr = None); 36 /** 37 * A shallow hasProperty() variant that doesn't look at the prototype's 38 * properties. 39 */ 40 virtual bool hasOwnProperty(ExecState *exec, const UString &propertyName); 39 virtual void put(ExecState *exec, unsigned propertyName, const Value &value, int attr = None); 40 virtual bool hasProperty(ExecState *exec, const UString &propertyName) const; 41 virtual bool hasProperty(ExecState *exec, unsigned propertyName) const; 42 virtual bool deleteProperty(ExecState *exec, const UString &propertyName); 43 virtual bool deleteProperty(ExecState *exec, unsigned propertyName); 44 45 virtual void mark(); 41 46 42 47 virtual const ClassInfo *classInfo() const { return &info; } 43 48 static const ClassInfo info; 49 50 unsigned getLength() const { return length; } 51 52 private: 53 void setLength(unsigned newLength); 54 55 unsigned length; 56 unsigned capacity; 57 Value *storage; 44 58 }; 45 59 -
trunk/JavaScriptCore/kjs/bool_object.cpp
r798 r1799 53 53 // The constructor will be added later by InterpreterImp::InterpreterImp() 54 54 55 put(exec, "toString", Object(new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ToString,0)), DontEnum);56 put(exec, "valueOf", Object(new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ValueOf,0)), DontEnum);55 put(exec,toStringPropertyName, Object(new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ToString,0)), DontEnum); 56 put(exec,valueOfPropertyName, Object(new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ValueOf,0)), DontEnum); 57 57 setInternalValue(Boolean(false)); 58 58 } … … 66 66 { 67 67 Value protect(this); 68 put(exec, "length",Number(len),DontDelete|ReadOnly|DontEnum);68 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 69 69 } 70 70 … … 105 105 { 106 106 Value protect(this); 107 put(exec, "prototype", Object(booleanProto),DontEnum|DontDelete|ReadOnly);107 put(exec,prototypePropertyName, Object(booleanProto),DontEnum|DontDelete|ReadOnly); 108 108 109 109 // no. of arguments for constructor 110 put(exec, "length", Number(1), ReadOnly|DontDelete|DontEnum);110 put(exec,lengthPropertyName, Number(1), ReadOnly|DontDelete|DontEnum); 111 111 } 112 112 -
trunk/JavaScriptCore/kjs/date_object.cpp
r1326 r1799 148 148 { 149 149 Value protect(this); 150 put(exec, "length",Number(len),DontDelete|ReadOnly|DontEnum);150 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 151 151 } 152 152 … … 322 322 Value protect(this); 323 323 // ECMA 15.9.4.1 Date.prototype 324 put(exec, "prototype", Object(dateProto), DontEnum|DontDelete|ReadOnly);324 put(exec,prototypePropertyName, Object(dateProto), DontEnum|DontDelete|ReadOnly); 325 325 326 326 put(exec,"parse", Object(new DateObjectFuncImp(exec,funcProto,DateObjectFuncImp::Parse, 1)), DontEnum); … … 328 328 329 329 // no. of arguments for constructor 330 put(exec, "length", Number(7), ReadOnly|DontDelete|DontEnum);330 put(exec,lengthPropertyName, Number(7), ReadOnly|DontDelete|DontEnum); 331 331 } 332 332 … … 417 417 { 418 418 Value protect(this); 419 put(exec, "length",Number(len),DontDelete|ReadOnly|DontEnum);419 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 420 420 } 421 421 -
trunk/JavaScriptCore/kjs/error_object.cpp
r798 r1799 44 44 put(exec, "name", String("Error"), DontEnum); 45 45 put(exec, "message", String("Unknown error"), DontEnum); 46 put(exec, "toString", Object(new ErrorProtoFuncImp(exec,funcProto)), DontEnum);46 put(exec, toStringPropertyName, Object(new ErrorProtoFuncImp(exec,funcProto)), DontEnum); 47 47 } 48 48 … … 53 53 { 54 54 Value protect(this); 55 put(exec, "length",Number(0),DontDelete|ReadOnly|DontEnum);55 put(exec,lengthPropertyName,Number(0),DontDelete|ReadOnly|DontEnum); 56 56 } 57 57 … … 87 87 Value protect(this); 88 88 // ECMA 15.11.3.1 Error.prototype 89 put(exec, "prototype", Object(errorProto), DontEnum|DontDelete|ReadOnly);89 put(exec, prototypePropertyName, Object(errorProto), DontEnum|DontDelete|ReadOnly); 90 90 //put(exec, "name", String(n)); 91 91 } … … 144 144 proto = static_cast<ObjectImp*>(prot.imp()); 145 145 146 put(exec, "length",Number(1),DontDelete|ReadOnly|DontEnum); // ECMA 15.11.7.5147 put(exec, "prototype",prot);146 put(exec,lengthPropertyName,Number(1),DontDelete|ReadOnly|DontEnum); // ECMA 15.11.7.5 147 put(exec,prototypePropertyName,prot); 148 148 } 149 149 -
trunk/JavaScriptCore/kjs/function.cpp
r1623 r1799 275 275 { 276 276 Object proto; 277 Value p = get(exec, "prototype");277 Value p = get(exec,prototypePropertyName); 278 278 if (p.type() == ObjectType) 279 279 proto = Object(static_cast<ObjectImp*>(p.imp())); … … 315 315 Value protect(this); 316 316 put(exec,"callee", Object(func), DontEnum); 317 put(exec, "length", Number(args.size()), DontEnum);317 put(exec,lengthPropertyName, Number(args.size()), DontEnum); 318 318 if (!args.isEmpty()) { 319 319 ListIterator arg = args.begin(); 320 320 for (int i = 0; arg != args.end(); arg++, i++) { 321 put(exec, UString::from(i), *arg, DontEnum);321 put(exec,i, *arg, DontEnum); 322 322 } 323 323 } … … 349 349 { 350 350 Value protect(this); 351 put(exec, "length",Number(len),DontDelete|ReadOnly|DontEnum);351 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 352 352 } 353 353 -
trunk/JavaScriptCore/kjs/function_object.cpp
r1024 r1799 41 41 { 42 42 Value protect(this); 43 put(exec, "toString", Object(new FunctionProtoFuncImp(exec, this, FunctionProtoFuncImp::ToString, 0)), DontEnum);43 put(exec, toStringPropertyName, Object(new FunctionProtoFuncImp(exec, this, FunctionProtoFuncImp::ToString, 0)), DontEnum); 44 44 put(exec, "apply", Object(new FunctionProtoFuncImp(exec, this, FunctionProtoFuncImp::Apply, 2)), DontEnum); 45 45 put(exec, "call", Object(new FunctionProtoFuncImp(exec, this, FunctionProtoFuncImp::Call, 1)), DontEnum); … … 68 68 { 69 69 Value protect(this); 70 put(exec, "length",Number(len),DontDelete|ReadOnly|DontEnum);70 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 71 71 } 72 72 … … 130 130 131 131 Object argArrayObj = Object::dynamicCast(argArray); 132 unsigned int length = argArrayObj.get(exec, "length").toUInt32(exec);132 unsigned int length = argArrayObj.get(exec,lengthPropertyName).toUInt32(exec); 133 133 for (unsigned int i = 0; i < length; i++) 134 applyArgs.append(argArrayObj.get(exec, UString::from(i)));134 applyArgs.append(argArrayObj.get(exec,i)); 135 135 } 136 136 else { … … 175 175 { 176 176 Value protect(this); 177 put(exec, "prototype", Object(funcProto), DontEnum|DontDelete|ReadOnly);177 put(exec,prototypePropertyName, Object(funcProto), DontEnum|DontDelete|ReadOnly); 178 178 179 179 // no. of arguments for constructor 180 put(exec, "length", Number(1), ReadOnly|DontDelete|DontEnum);180 put(exec,lengthPropertyName, Number(1), ReadOnly|DontDelete|DontEnum); 181 181 } 182 182 … … 276 276 } 277 277 278 fimp->put(exec, "length", Number(params),ReadOnly|DontDelete|DontEnum);278 fimp->put(exec,lengthPropertyName, Number(params),ReadOnly|DontDelete|DontEnum); 279 279 List consArgs; 280 280 … … 283 283 prototype.put(exec, "constructor", 284 284 Object(fimp), DontEnum|DontDelete|ReadOnly); 285 fimp->put(exec, "prototype",prototype,DontEnum|DontDelete|ReadOnly);285 fimp->put(exec,prototypePropertyName,prototype,DontEnum|DontDelete|ReadOnly); 286 286 fimp->put(exec,"arguments",Null(),DontEnum|DontDelete|ReadOnly); 287 287 return ret; -
trunk/JavaScriptCore/kjs/internal.cpp
r1790 r1799 193 193 // ------------------------------ StringImp ------------------------------------ 194 194 195 StringImp::StringImp(const UString& v)196 : val(v)197 {198 }199 200 195 Value StringImp::toPrimitive(ExecState */*exec*/, Type) const 201 196 { … … 221 216 { 222 217 List args; 223 args.append( String(const_cast<StringImp*>(this)));218 args.append(Value(const_cast<StringImp*>(this))); 224 219 return Object::dynamicCast(exec->interpreter()->builtinString().construct(exec,args)); 225 220 } 226 221 227 222 // ------------------------------ NumberImp ------------------------------------ 228 229 NumberImp::NumberImp(double v)230 : val(v)231 {232 }233 223 234 224 Value NumberImp::toPrimitive(ExecState *, Type) const … … 259 249 } 260 250 251 bool NumberImp::toUInt32(unsigned& uint32) const 252 { 253 uint32 = (unsigned)val; 254 return (double)uint32 == val; 255 } 256 261 257 // ------------------------------ ReferenceImp --------------------------------- 262 258 259 ReferenceImp::ReferenceImp(const Value& v, unsigned p) 260 : base(v.imp()), propertyNameIsNumber(true), propertyNameAsNumber(p) 261 { 262 } 263 263 264 ReferenceImp::ReferenceImp(const Value& v, const UString& p) 264 : base(v.imp()), prop (p)265 : base(v.imp()), propertyNameIsNumber(false), prop(p) 265 266 { 266 267 } … … 306 307 assert(false); 307 308 return Object(); 309 } 310 311 UString ReferenceImp::getPropertyName(ExecState *) const 312 { 313 if (propertyNameIsNumber && prop.isNull()) 314 prop = UString::from(propertyNameAsNumber); 315 return prop; 316 } 317 318 Value ReferenceImp::getValue(ExecState *exec) const 319 { 320 Value o = getBase(exec); 321 322 if (o.isNull() || o.type() == NullType) { 323 UString m = I18N_NOOP("Can't find variable: ") + getPropertyName(exec); 324 Object err = Error::create(exec, ReferenceError, m.ascii()); 325 exec->setException(err); 326 return err; 327 } 328 329 if (o.type() != ObjectType) { 330 UString m = I18N_NOOP("Base is not an object"); 331 Object err = Error::create(exec, ReferenceError, m.ascii()); 332 exec->setException(err); 333 return err; 334 } 335 336 if (propertyNameIsNumber) 337 return static_cast<ObjectImp*>(o.imp())->get(exec,propertyNameAsNumber); 338 return static_cast<ObjectImp*>(o.imp())->get(exec,prop); 339 } 340 341 void ReferenceImp::putValue(ExecState *exec, const Value& w) 342 { 343 #ifdef KJS_VERBOSE 344 printInfo(exec,(UString("setting property ")+getPropertyName(exec)).cstring().c_str(),w); 345 #endif 346 Value o = getBase(exec); 347 if (o.type() == NullType) 348 o = exec->interpreter()->globalObject(); 349 350 if (propertyNameIsNumber) 351 return static_cast<ObjectImp*>(o.imp())->put(exec,propertyNameAsNumber, w); 352 return static_cast<ObjectImp*>(o.imp())->put(exec,prop, w); 353 } 354 355 bool ReferenceImp::deleteValue(ExecState *exec) 356 { 357 Value b = getBase(exec); 358 359 // The spec doesn't mention what to do if the base is null... just return true 360 if (b.type() != ObjectType) { 361 assert(b.type() == NullType); 362 return true; 363 } 364 365 if (propertyNameIsNumber) 366 return static_cast<ObjectImp*>(b.imp())->deleteProperty(exec,propertyNameAsNumber); 367 return static_cast<ObjectImp*>(b.imp())->deleteProperty(exec,prop); 308 368 } 309 369 … … 1120 1180 return Boolean(false); 1121 1181 1122 Value prot = get(exec, "prototype");1182 Value prot = get(exec,prototypePropertyName); 1123 1183 if (prot.type() != ObjectType && prot.type() != NullType) { 1124 1184 Object err = Error::create(exec, TypeError, "Invalid prototype encountered " -
trunk/JavaScriptCore/kjs/internal.h
r1024 r1799 50 50 class UndefinedImp : public ValueImp { 51 51 public: 52 UndefinedImp() {}53 virtual ~UndefinedImp() { }54 55 52 Type type() const { return UndefinedType; } 56 53 … … 64 61 }; 65 62 63 inline Undefined::Undefined(UndefinedImp *imp) : Value(imp) { } 64 66 65 class NullImp : public ValueImp { 67 66 public: 68 NullImp() {}69 virtual ~NullImp() { }70 71 67 Type type() const { return NullType; } 72 68 … … 80 76 }; 81 77 78 inline Null::Null(NullImp *imp) : Value(imp) { } 79 82 80 class BooleanImp : public ValueImp { 83 81 public: 84 virtual ~BooleanImp() { }85 82 BooleanImp(bool v = false) : val(v) { } 86 83 bool value() const { return val; } … … 99 96 bool val; 100 97 }; 98 99 inline Boolean::Boolean(BooleanImp *imp) : Value(imp) { } 101 100 102 101 class StringImp : public ValueImp { 103 102 public: 104 StringImp(const UString& v); 105 virtual ~StringImp() { } 103 StringImp(const UString& v) : val(v) { } 106 104 UString value() const { return val; } 107 105 … … 118 116 }; 119 117 118 inline String::String(StringImp *imp) : Value(imp) { } 119 120 120 class NumberImp : public ValueImp { 121 121 public: 122 NumberImp(double v); 123 virtual ~NumberImp() { } 122 NumberImp(double v) : val(v) { } 124 123 double value() const { return val; } 125 124 … … 132 131 Object toObject(ExecState *exec) const; 133 132 133 virtual bool toUInt32(unsigned&) const; 134 134 135 private: 135 136 double val; 136 137 }; 138 139 inline Number::Number(NumberImp *imp) : Value(imp) { } 137 140 138 141 // --------------------------------------------------------------------------- … … 142 145 class ReferenceImp : public ValueImp { 143 146 public: 144 145 147 ReferenceImp(const Value& v, const UString& p); 146 virtual ~ReferenceImp() { }148 ReferenceImp(const Value& v, unsigned p); 147 149 virtual void mark(); 148 150 … … 153 155 Object toObject(ExecState *exec) const; 154 156 155 Value getBase() const { return Value(base); } 156 UString getPropertyName() const { return prop; } 157 Value getBase(ExecState *) const { return Value(base); } 158 UString getPropertyName(ExecState *) const; 159 Value getValue(ExecState *exec) const; 160 void putValue(ExecState *exec, const Value& w); 161 bool deleteValue(ExecState *exec); 157 162 158 163 Type type() const { return ReferenceType; } … … 160 165 private: 161 166 ValueImp *base; 162 UString prop; 163 }; 167 bool propertyNameIsNumber; 168 unsigned propertyNameAsNumber; 169 mutable UString prop; 170 }; 171 172 inline Reference::Reference(ReferenceImp *imp) : Value(imp) { } 164 173 165 174 class CompletionImp : public ValueImp { … … 186 195 UString tar; 187 196 }; 197 198 inline Completion::Completion(CompletionImp *imp) : Value(imp) { } 188 199 189 200 /** … … 244 255 static ListImp *emptyList; 245 256 }; 257 258 inline List::List(ListImp *imp) : Value(imp) { } 246 259 247 260 /** -
trunk/JavaScriptCore/kjs/math_object.cpp
r1623 r1799 131 131 { 132 132 Value protect(this); 133 put(exec, "length",Number(l),DontDelete|ReadOnly|DontEnum);133 put(exec,lengthPropertyName,Number(l),DontDelete|ReadOnly|DontEnum); 134 134 } 135 135 -
trunk/JavaScriptCore/kjs/nodes.cpp
r1623 r1799 118 118 } 119 119 120 StatementNode::~StatementNode()121 {122 }123 124 120 void StatementNode::setLoc(int line0, int line1, int sourceId) 125 121 { … … 227 223 // ------------------------------ GroupNode ------------------------------------ 228 224 229 GroupNode::~GroupNode()230 {231 }232 233 225 void GroupNode::ref() 234 226 { … … 252 244 253 245 // ------------------------------ ElisionNode ---------------------------------- 254 255 ElisionNode::~ElisionNode()256 {257 }258 246 259 247 void ElisionNode::ref() … … 281 269 282 270 // ------------------------------ ElementNode ---------------------------------- 283 284 ElementNode::~ElementNode()285 {286 }287 271 288 272 void ElementNode::ref() … … 321 305 KJS_CHECKEXCEPTIONVALUE 322 306 val = node->evaluate(exec).getValue(exec); 323 length = array.get(exec, "length").toInt32(exec);307 length = array.get(exec,lengthPropertyName).toInt32(exec); 324 308 } else { 325 309 Value newArr = exec->interpreter()->builtinArray().construct(exec,List::empty()); … … 329 313 } 330 314 331 array.put(exec, UString::from(elisionLen + length), val);315 array.put(exec, elisionLen + length, val); 332 316 333 317 return array; … … 335 319 336 320 // ------------------------------ ArrayNode ------------------------------------ 337 338 ArrayNode::~ArrayNode()339 {340 }341 321 342 322 void ArrayNode::ref() … … 369 349 array = Object(static_cast<ObjectImp*>(element->evaluate(exec).imp())); 370 350 KJS_CHECKEXCEPTIONVALUE 371 length = opt ? array.get(exec, "length").toInt32(exec) : 0;351 length = opt ? array.get(exec,lengthPropertyName).toInt32(exec) : 0; 372 352 } else { 373 353 Value newArr = exec->interpreter()->builtinArray().construct(exec,List::empty()); … … 377 357 378 358 if (opt) 379 array.put(exec, "length", Number(elisionLen + length), DontEnum | DontDelete);359 array.put(exec,lengthPropertyName, Number(elisionLen + length), DontEnum | DontDelete); 380 360 381 361 return array; … … 383 363 384 364 // ------------------------------ ObjectLiteralNode ---------------------------- 385 386 ObjectLiteralNode::~ObjectLiteralNode()387 {388 }389 365 390 366 void ObjectLiteralNode::ref() … … 412 388 413 389 // ------------------------------ PropertyValueNode ---------------------------- 414 415 PropertyValueNode::~PropertyValueNode()416 {417 }418 390 419 391 void PropertyValueNode::ref() … … 479 451 // ------------------------------ AccessorNode1 -------------------------------- 480 452 481 AccessorNode1::~AccessorNode1()482 {483 }484 485 453 void AccessorNode1::ref() 486 454 { … … 511 479 Value v2 = e2.getValue(exec); 512 480 Object o = v1.toObject(exec); 481 unsigned i; 482 if (v2.toUInt32(i)) 483 return Reference(o, i); 513 484 String s = v2.toString(exec); 514 485 return Reference(o, s.value()); … … 516 487 517 488 // ------------------------------ AccessorNode2 -------------------------------- 518 519 AccessorNode2::~AccessorNode2()520 {521 }522 489 523 490 void AccessorNode2::ref() … … 553 520 ArgumentListNode::ArgumentListNode(ArgumentListNode *l, Node *e) 554 521 : list(l), expr(e) 555 {556 }557 558 ArgumentListNode::~ArgumentListNode()559 522 { 560 523 } … … 608 571 } 609 572 610 ArgumentsNode::~ArgumentsNode()611 {612 }613 614 573 void ArgumentsNode::ref() 615 574 { … … 644 603 645 604 // ECMA 11.2.2 646 647 NewExprNode::~NewExprNode()648 {649 }650 605 651 606 void NewExprNode::ref() … … 694 649 695 650 // ------------------------------ FunctionCallNode ----------------------------- 696 697 FunctionCallNode::~FunctionCallNode()698 {699 }700 651 701 652 void FunctionCallNode::ref() … … 788 739 // ------------------------------ PostfixNode ---------------------------------- 789 740 790 PostfixNode::~PostfixNode()791 {792 }793 794 741 void PostfixNode::ref() 795 742 { … … 824 771 // ------------------------------ DeleteNode ----------------------------------- 825 772 826 DeleteNode::~DeleteNode()827 {828 }829 830 773 void DeleteNode::ref() 831 774 { … … 847 790 Value e = expr->evaluate(exec); 848 791 KJS_CHECKEXCEPTIONVALUE 849 if (e.type() != ReferenceType) 850 return Boolean(true); 851 Value b = e.getBase(exec); 852 UString n = e.getPropertyName(exec); 853 854 // The spec doesn't mention what to do if the base is null... just return true 855 if (b.type() != ObjectType) { 856 assert(b.type() == NullType); 857 return Boolean(true); 858 } 859 860 Object o = Object(static_cast<ObjectImp*>(b.imp())); 861 862 bool ret = o.deleteProperty(exec,n); 863 864 return Boolean(ret); 792 return Boolean(e.deleteValue(exec)); 865 793 } 866 794 867 795 // ------------------------------ VoidNode ------------------------------------- 868 869 VoidNode::~VoidNode()870 {871 }872 796 873 797 void VoidNode::ref() … … 896 820 897 821 // ------------------------------ TypeOfNode ----------------------------------- 898 899 TypeOfNode::~TypeOfNode()900 {901 }902 822 903 823 void TypeOfNode::ref() … … 957 877 // ------------------------------ PrefixNode ----------------------------------- 958 878 959 PrefixNode::~PrefixNode()960 {961 }962 963 879 void PrefixNode::ref() 964 880 { … … 993 909 // ------------------------------ UnaryPlusNode -------------------------------- 994 910 995 UnaryPlusNode::~UnaryPlusNode()996 {997 }998 999 911 void UnaryPlusNode::ref() 1000 912 { … … 1023 935 // ------------------------------ NegateNode ----------------------------------- 1024 936 1025 NegateNode::~NegateNode()1026 {1027 }1028 1029 937 void NegateNode::ref() 1030 938 { … … 1056 964 // ------------------------------ BitwiseNotNode ------------------------------- 1057 965 1058 BitwiseNotNode::~BitwiseNotNode()1059 {1060 }1061 1062 966 void BitwiseNotNode::ref() 1063 967 { … … 1087 991 // ------------------------------ LogicalNotNode ------------------------------- 1088 992 1089 LogicalNotNode::~LogicalNotNode()1090 {1091 }1092 1093 993 void LogicalNotNode::ref() 1094 994 { … … 1117 1017 1118 1018 // ------------------------------ MultNode ------------------------------------- 1119 1120 MultNode::~MultNode()1121 {1122 }1123 1019 1124 1020 void MultNode::ref() … … 1156 1052 // ------------------------------ AddNode -------------------------------------- 1157 1053 1158 AddNode::~AddNode()1159 {1160 }1161 1162 1054 void AddNode::ref() 1163 1055 { … … 1193 1085 1194 1086 // ------------------------------ ShiftNode ------------------------------------ 1195 1196 ShiftNode::~ShiftNode()1197 {1198 }1199 1087 1200 1088 void ShiftNode::ref() … … 1248 1136 1249 1137 // ------------------------------ RelationalNode ------------------------------- 1250 1251 RelationalNode::~RelationalNode()1252 {1253 }1254 1138 1255 1139 void RelationalNode::ref() … … 1324 1208 // ------------------------------ EqualNode ------------------------------------ 1325 1209 1326 EqualNode::~EqualNode()1327 {1328 }1329 1330 1210 void EqualNode::ref() 1331 1211 { … … 1370 1250 1371 1251 // ------------------------------ BitOperNode ---------------------------------- 1372 1373 BitOperNode::~BitOperNode()1374 {1375 }1376 1252 1377 1253 void BitOperNode::ref() … … 1417 1293 // ------------------------------ BinaryLogicalNode ---------------------------- 1418 1294 1419 BinaryLogicalNode::~BinaryLogicalNode()1420 {1421 }1422 1423 1295 void BinaryLogicalNode::ref() 1424 1296 { … … 1457 1329 1458 1330 // ------------------------------ ConditionalNode ------------------------------ 1459 1460 ConditionalNode::~ConditionalNode()1461 {1462 }1463 1331 1464 1332 void ConditionalNode::ref() … … 1502 1370 1503 1371 // ------------------------------ AssignNode ----------------------------------- 1504 1505 AssignNode::~AssignNode()1506 {1507 }1508 1372 1509 1373 void AssignNode::ref() … … 1597 1461 // ------------------------------ CommaNode ------------------------------------ 1598 1462 1599 CommaNode::~CommaNode()1600 {1601 }1602 1603 1463 void CommaNode::ref() 1604 1464 { … … 1632 1492 1633 1493 // ------------------------------ StatListNode --------------------------------- 1634 1635 StatListNode::~StatListNode()1636 {1637 }1638 1494 1639 1495 void StatListNode::ref() … … 1698 1554 // ------------------------------ AssignExprNode ------------------------------- 1699 1555 1700 AssignExprNode::~AssignExprNode()1701 {1702 }1703 1704 1556 void AssignExprNode::ref() 1705 1557 { … … 1726 1578 VarDeclNode::VarDeclNode(const UString *id, AssignExprNode *in) 1727 1579 : ident(*id), init(in) 1728 {1729 }1730 1731 VarDeclNode::~VarDeclNode()1732 1580 { 1733 1581 } … … 1781 1629 // ------------------------------ VarDeclListNode ------------------------------ 1782 1630 1783 VarDeclListNode::~VarDeclListNode()1784 {1785 }1786 1787 1631 void VarDeclListNode::ref() 1788 1632 { … … 1827 1671 // ------------------------------ VarStatementNode ----------------------------- 1828 1672 1829 VarStatementNode::~VarStatementNode()1830 {1831 }1832 1833 1673 void VarStatementNode::ref() 1834 1674 { … … 1863 1703 // ------------------------------ BlockNode ------------------------------------ 1864 1704 1865 BlockNode::~BlockNode()1866 {1867 }1868 1869 1705 void BlockNode::ref() 1870 1706 { … … 1907 1743 1908 1744 // ------------------------------ ExprStatementNode ---------------------------- 1909 1910 ExprStatementNode::~ExprStatementNode()1911 {1912 }1913 1745 1914 1746 void ExprStatementNode::ref() … … 1939 1771 1940 1772 // ------------------------------ IfNode --------------------------------------- 1941 1942 IfNode::~IfNode()1943 {1944 }1945 1773 1946 1774 void IfNode::ref() … … 1997 1825 1998 1826 // ------------------------------ DoWhileNode ---------------------------------- 1999 2000 DoWhileNode::~DoWhileNode()2001 {2002 }2003 1827 2004 1828 void DoWhileNode::ref() … … 2055 1879 // ------------------------------ WhileNode ------------------------------------ 2056 1880 2057 WhileNode::~WhileNode()2058 {2059 }2060 2061 1881 void WhileNode::ref() 2062 1882 { … … 2118 1938 2119 1939 // ------------------------------ ForNode -------------------------------------- 2120 2121 ForNode::~ForNode()2122 {2123 }2124 1940 2125 1941 void ForNode::ref() … … 2212 2028 } 2213 2029 2214 ForInNode::~ForInNode()2215 {2216 }2217 2218 2030 void ForInNode::ref() 2219 2031 { … … 2333 2145 // ------------------------------ ReturnNode ----------------------------------- 2334 2146 2335 ReturnNode::~ReturnNode()2336 {2337 }2338 2339 2147 void ReturnNode::ref() 2340 2148 { … … 2367 2175 2368 2176 // ------------------------------ WithNode ------------------------------------- 2369 2370 WithNode::~WithNode()2371 {2372 }2373 2177 2374 2178 void WithNode::ref() … … 2414 2218 // ------------------------------ CaseClauseNode ------------------------------- 2415 2219 2416 CaseClauseNode::~CaseClauseNode()2417 {2418 }2419 2420 2220 void CaseClauseNode::ref() 2421 2221 { … … 2463 2263 // ------------------------------ ClauseListNode ------------------------------- 2464 2264 2465 ClauseListNode::~ClauseListNode()2466 {2467 }2468 2469 2265 void ClauseListNode::ref() 2470 2266 { … … 2512 2308 2513 2309 // ------------------------------ CaseBlockNode -------------------------------- 2514 2515 CaseBlockNode::~CaseBlockNode()2516 {2517 }2518 2310 2519 2311 void CaseBlockNode::ref() … … 2620 2412 // ------------------------------ SwitchNode ----------------------------------- 2621 2413 2622 SwitchNode::~SwitchNode()2623 {2624 }2625 2626 2414 void SwitchNode::ref() 2627 2415 { … … 2664 2452 2665 2453 // ------------------------------ LabelNode ------------------------------------ 2666 2667 LabelNode::~LabelNode()2668 {2669 }2670 2454 2671 2455 void LabelNode::ref() … … 2708 2492 // ------------------------------ ThrowNode ------------------------------------ 2709 2493 2710 ThrowNode::~ThrowNode()2711 {2712 }2713 2714 2494 void ThrowNode::ref() 2715 2495 { … … 2742 2522 2743 2523 // ------------------------------ CatchNode ------------------------------------ 2744 2745 CatchNode::~CatchNode()2746 {2747 }2748 2524 2749 2525 void CatchNode::ref() … … 2791 2567 // ------------------------------ FinallyNode ---------------------------------- 2792 2568 2793 FinallyNode::~FinallyNode()2794 {2795 }2796 2797 2569 void FinallyNode::ref() 2798 2570 { … … 2821 2593 2822 2594 // ------------------------------ TryNode -------------------------------------- 2823 2824 TryNode::~TryNode()2825 {2826 }2827 2595 2828 2596 void TryNode::ref() … … 2886 2654 // ------------------------------ ParameterNode -------------------------------- 2887 2655 2888 ParameterNode::~ParameterNode()2889 {2890 }2891 2892 2656 void ParameterNode::ref() 2893 2657 { … … 2931 2695 } 2932 2696 2933 FunctionBodyNode::~FunctionBodyNode()2934 {2935 //fprintf(stderr,"FunctionBodyNode::~FunctionBodyNode %p\n",this);2936 }2937 2938 2697 void FunctionBodyNode::ref() 2939 2698 { … … 2977 2736 2978 2737 // ------------------------------ FuncDeclNode --------------------------------- 2979 2980 FuncDeclNode::~FuncDeclNode()2981 {2982 }2983 2738 2984 2739 void FuncDeclNode::ref() … … 3012 2767 List empty; 3013 2768 Value proto = exec->interpreter()->builtinObject().construct(exec,empty); 3014 func.put(exec, "prototype", proto, Internal|DontDelete);2769 func.put(exec, prototypePropertyName, proto, Internal|DontDelete); 3015 2770 3016 2771 int plen = 0; … … 3018 2773 fimp->addParameter(p->ident()); 3019 2774 3020 func.put(exec, "length", Number(plen), ReadOnly|DontDelete|DontEnum);2775 func.put(exec, lengthPropertyName, Number(plen), ReadOnly|DontDelete|DontEnum); 3021 2776 3022 2777 exec->context().imp()->variableObject().put(exec,ident,func); … … 3036 2791 // ------------------------------ FuncExprNode --------------------------------- 3037 2792 3038 FuncExprNode::~FuncExprNode()3039 {3040 }3041 3042 2793 void FuncExprNode::ref() 3043 2794 { … … 3067 2818 List empty; 3068 2819 Value proto = exec->interpreter()->builtinObject().construct(exec,empty); 3069 fimp->put(exec, "prototype", proto, Internal|DontDelete);2820 fimp->put(exec, prototypePropertyName, proto, Internal|DontDelete); 3070 2821 3071 2822 int plen = 0; 3072 2823 for(ParameterNode *p = param; p != 0L; p = p->nextParam(), plen++) 3073 2824 fimp->addParameter(p->ident()); 3074 fimp->put(exec, "length", Number(plen), ReadOnly|DontDelete|DontEnum);2825 fimp->put(exec,lengthPropertyName, Number(plen), ReadOnly|DontDelete|DontEnum); 3075 2826 3076 2827 return ret; … … 3078 2829 3079 2830 // ------------------------------ SourceElementNode ---------------------------- 3080 3081 SourceElementNode::~SourceElementNode()3082 {3083 }3084 2831 3085 2832 void SourceElementNode::ref() … … 3124 2871 3125 2872 // ------------------------------ SourceElementsNode --------------------------- 3126 3127 SourceElementsNode::~SourceElementsNode()3128 {3129 }3130 2873 3131 2874 void SourceElementsNode::ref() … … 3188 2931 //fprintf(stderr,"ProgramNode::ProgramNode %p\n",this); 3189 2932 } 3190 3191 ProgramNode::~ProgramNode() {3192 //fprintf(stderr,"ProgramNode::~ProgramNode %p\n",this);3193 } -
trunk/JavaScriptCore/kjs/nodes.h
r1623 r1799 112 112 public: 113 113 StatementNode(); 114 ~StatementNode();115 114 void setLoc(int line0, int line1, int sourceId); 116 115 int firstLine() const { return l0; } … … 197 196 virtual void ref(); 198 197 virtual bool deref(); 199 virtual ~GroupNode();200 198 Value evaluate(ExecState *exec); 201 199 virtual void streamTo(SourceStream &s) const { group->streamTo(s); } … … 209 207 virtual void ref(); 210 208 virtual bool deref(); 211 virtual ~ElisionNode();212 209 Value evaluate(ExecState *exec); 213 210 virtual void streamTo(SourceStream &s) const; … … 223 220 virtual void ref(); 224 221 virtual bool deref(); 225 virtual ~ElementNode();226 222 Value evaluate(ExecState *exec); 227 223 virtual void streamTo(SourceStream &s) const; … … 241 237 virtual void ref(); 242 238 virtual bool deref(); 243 virtual ~ArrayNode();244 239 Value evaluate(ExecState *exec); 245 240 virtual void streamTo(SourceStream &s) const; … … 255 250 virtual void ref(); 256 251 virtual bool deref(); 257 virtual ~ObjectLiteralNode();258 252 Value evaluate(ExecState *exec); 259 253 virtual void streamTo(SourceStream &s) const; … … 268 262 virtual void ref(); 269 263 virtual bool deref(); 270 virtual ~PropertyValueNode();271 264 Value evaluate(ExecState *exec); 272 265 virtual void streamTo(SourceStream &s) const; … … 291 284 virtual void ref(); 292 285 virtual bool deref(); 293 virtual ~AccessorNode1();294 286 Value evaluate(ExecState *exec); 295 287 virtual void streamTo(SourceStream &s) const; … … 304 296 virtual void ref(); 305 297 virtual bool deref(); 306 virtual ~AccessorNode2();307 298 Value evaluate(ExecState *exec); 308 299 virtual void streamTo(SourceStream &s) const; … … 318 309 virtual void ref(); 319 310 virtual bool deref(); 320 virtual ~ArgumentListNode();321 311 Value evaluate(ExecState *exec); 322 312 List evaluateList(ExecState *exec); … … 332 322 virtual void ref(); 333 323 virtual bool deref(); 334 virtual ~ArgumentsNode();335 324 Value evaluate(ExecState *exec); 336 325 List evaluateList(ExecState *exec); … … 346 335 virtual void ref(); 347 336 virtual bool deref(); 348 virtual ~NewExprNode();349 337 Value evaluate(ExecState *exec); 350 338 virtual void streamTo(SourceStream &s) const; … … 359 347 virtual void ref(); 360 348 virtual bool deref(); 361 virtual ~FunctionCallNode();362 349 Value evaluate(ExecState *exec); 363 350 virtual void streamTo(SourceStream &s) const; … … 372 359 virtual void ref(); 373 360 virtual bool deref(); 374 virtual ~PostfixNode();375 361 Value evaluate(ExecState *exec); 376 362 virtual void streamTo(SourceStream &s) const; … … 385 371 virtual void ref(); 386 372 virtual bool deref(); 387 virtual ~DeleteNode();388 373 Value evaluate(ExecState *exec); 389 374 virtual void streamTo(SourceStream &s) const; … … 397 382 virtual void ref(); 398 383 virtual bool deref(); 399 virtual ~VoidNode();400 384 Value evaluate(ExecState *exec); 401 385 virtual void streamTo(SourceStream &s) const; … … 409 393 virtual void ref(); 410 394 virtual bool deref(); 411 virtual ~TypeOfNode();412 395 Value evaluate(ExecState *exec); 413 396 virtual void streamTo(SourceStream &s) const; … … 421 404 virtual void ref(); 422 405 virtual bool deref(); 423 virtual ~PrefixNode();424 406 Value evaluate(ExecState *exec); 425 407 virtual void streamTo(SourceStream &s) const; … … 434 416 virtual void ref(); 435 417 virtual bool deref(); 436 virtual ~UnaryPlusNode();437 418 Value evaluate(ExecState *exec); 438 419 virtual void streamTo(SourceStream &s) const; … … 446 427 virtual void ref(); 447 428 virtual bool deref(); 448 virtual ~NegateNode();449 429 Value evaluate(ExecState *exec); 450 430 virtual void streamTo(SourceStream &s) const; … … 458 438 virtual void ref(); 459 439 virtual bool deref(); 460 virtual ~BitwiseNotNode();461 440 Value evaluate(ExecState *exec); 462 441 virtual void streamTo(SourceStream &s) const; … … 470 449 virtual void ref(); 471 450 virtual bool deref(); 472 virtual ~LogicalNotNode();473 451 Value evaluate(ExecState *exec); 474 452 virtual void streamTo(SourceStream &s) const; … … 482 460 virtual void ref(); 483 461 virtual bool deref(); 484 virtual ~MultNode();485 462 Value evaluate(ExecState *exec); 486 463 virtual void streamTo(SourceStream &s) const; … … 495 472 virtual void ref(); 496 473 virtual bool deref(); 497 virtual ~AddNode();498 474 Value evaluate(ExecState *exec); 499 475 virtual void streamTo(SourceStream &s) const; … … 509 485 virtual void ref(); 510 486 virtual bool deref(); 511 virtual ~ShiftNode();512 487 Value evaluate(ExecState *exec); 513 488 virtual void streamTo(SourceStream &s) const; … … 523 498 virtual void ref(); 524 499 virtual bool deref(); 525 virtual ~RelationalNode();526 500 Value evaluate(ExecState *exec); 527 501 virtual void streamTo(SourceStream &s) const; … … 537 511 virtual void ref(); 538 512 virtual bool deref(); 539 virtual ~EqualNode();540 513 Value evaluate(ExecState *exec); 541 514 virtual void streamTo(SourceStream &s) const; … … 551 524 virtual void ref(); 552 525 virtual bool deref(); 553 virtual ~BitOperNode();554 526 Value evaluate(ExecState *exec); 555 527 virtual void streamTo(SourceStream &s) const; … … 568 540 virtual void ref(); 569 541 virtual bool deref(); 570 virtual ~BinaryLogicalNode();571 542 Value evaluate(ExecState *exec); 572 543 virtual void streamTo(SourceStream &s) const; … … 585 556 virtual void ref(); 586 557 virtual bool deref(); 587 virtual ~ConditionalNode();588 558 Value evaluate(ExecState *exec); 589 559 virtual void streamTo(SourceStream &s) const; … … 597 567 virtual void ref(); 598 568 virtual bool deref(); 599 virtual ~AssignNode();600 569 Value evaluate(ExecState *exec); 601 570 virtual void streamTo(SourceStream &s) const; … … 611 580 virtual void ref(); 612 581 virtual bool deref(); 613 virtual ~CommaNode();614 582 Value evaluate(ExecState *exec); 615 583 virtual void streamTo(SourceStream &s) const; … … 624 592 virtual void ref(); 625 593 virtual bool deref(); 626 virtual ~StatListNode();627 594 virtual Completion execute(ExecState *exec); 628 595 virtual void processVarDecls(ExecState *exec); … … 638 605 virtual void ref(); 639 606 virtual bool deref(); 640 virtual ~AssignExprNode();641 607 Value evaluate(ExecState *exec); 642 608 virtual void streamTo(SourceStream &s) const; … … 650 616 virtual void ref(); 651 617 virtual bool deref(); 652 virtual ~VarDeclNode();653 618 Value evaluate(ExecState *exec); 654 619 virtual void processVarDecls(ExecState *exec); … … 665 630 virtual void ref(); 666 631 virtual bool deref(); 667 virtual ~VarDeclListNode();668 632 Value evaluate(ExecState *exec); 669 633 virtual void processVarDecls(ExecState *exec); … … 679 643 virtual void ref(); 680 644 virtual bool deref(); 681 virtual ~VarStatementNode();682 645 virtual Completion execute(ExecState *exec); 683 646 virtual void processVarDecls(ExecState *exec); … … 692 655 virtual void ref(); 693 656 virtual bool deref(); 694 virtual ~BlockNode();695 657 virtual Completion execute(ExecState *exec); 696 658 virtual void processVarDecls(ExecState *exec); … … 712 674 virtual void ref(); 713 675 virtual bool deref(); 714 virtual ~ExprStatementNode();715 676 virtual Completion execute(ExecState *exec); 716 677 virtual void streamTo(SourceStream &s) const; … … 725 686 virtual void ref(); 726 687 virtual bool deref(); 727 virtual ~IfNode();728 688 virtual Completion execute(ExecState *exec); 729 689 virtual void processVarDecls(ExecState *exec); … … 739 699 virtual void ref(); 740 700 virtual bool deref(); 741 virtual ~DoWhileNode();742 701 virtual Completion execute(ExecState *exec); 743 702 virtual void processVarDecls(ExecState *exec); … … 753 712 virtual void ref(); 754 713 virtual bool deref(); 755 virtual ~WhileNode();756 714 virtual Completion execute(ExecState *exec); 757 715 virtual void processVarDecls(ExecState *exec); … … 768 726 virtual void ref(); 769 727 virtual bool deref(); 770 virtual ~ForNode();771 728 virtual Completion execute(ExecState *exec); 772 729 virtual void processVarDecls(ExecState *exec); … … 783 740 virtual void ref(); 784 741 virtual bool deref(); 785 virtual ~ForInNode();786 742 virtual Completion execute(ExecState *exec); 787 743 virtual void processVarDecls(ExecState *exec); … … 820 776 virtual void ref(); 821 777 virtual bool deref(); 822 virtual ~ReturnNode();823 778 virtual Completion execute(ExecState *exec); 824 779 virtual void streamTo(SourceStream &s) const; … … 832 787 virtual void ref(); 833 788 virtual bool deref(); 834 virtual ~WithNode();835 789 virtual Completion execute(ExecState *exec); 836 790 virtual void processVarDecls(ExecState *exec); … … 846 800 virtual void ref(); 847 801 virtual bool deref(); 848 virtual ~CaseClauseNode();849 802 Value evaluate(ExecState *exec); 850 803 Completion evalStatements(ExecState *exec); … … 861 814 virtual void ref(); 862 815 virtual bool deref(); 863 virtual ~ClauseListNode();864 816 ClauseListNode* append(CaseClauseNode *c); 865 817 Value evaluate(ExecState *exec); … … 879 831 virtual void ref(); 880 832 virtual bool deref(); 881 virtual ~CaseBlockNode();882 833 Value evaluate(ExecState *exec); 883 834 Completion evalBlock(ExecState *exec, const Value& input); … … 895 846 virtual void ref(); 896 847 virtual bool deref(); 897 virtual ~SwitchNode();898 848 virtual Completion execute(ExecState *exec); 899 849 virtual void processVarDecls(ExecState *exec); … … 909 859 virtual void ref(); 910 860 virtual bool deref(); 911 virtual ~LabelNode();912 861 virtual Completion execute(ExecState *exec); 913 862 virtual void processVarDecls(ExecState *exec); … … 923 872 virtual void ref(); 924 873 virtual bool deref(); 925 virtual ~ThrowNode();926 874 virtual Completion execute(ExecState *exec); 927 875 virtual void streamTo(SourceStream &s) const; … … 935 883 virtual void ref(); 936 884 virtual bool deref(); 937 virtual ~CatchNode();938 885 virtual Completion execute(ExecState *exec); 939 886 Completion execute(ExecState *exec, const Value &arg); … … 950 897 virtual void ref(); 951 898 virtual bool deref(); 952 virtual ~FinallyNode();953 899 virtual Completion execute(ExecState *exec); 954 900 virtual void processVarDecls(ExecState *exec); … … 964 910 virtual void ref(); 965 911 virtual bool deref(); 966 virtual ~TryNode();967 912 virtual Completion execute(ExecState *exec); 968 913 virtual void processVarDecls(ExecState *exec); … … 980 925 virtual void ref(); 981 926 virtual bool deref(); 982 virtual ~ParameterNode();983 927 Value evaluate(ExecState *exec); 984 928 UString ident() { return id; } … … 996 940 virtual void ref(); 997 941 virtual bool deref(); 998 virtual ~FunctionBodyNode();999 942 Completion execute(ExecState *exec); 1000 943 virtual void processFuncDecl(ExecState *exec); … … 1011 954 virtual void ref(); 1012 955 virtual bool deref(); 1013 virtual ~FuncDeclNode();1014 956 Completion execute(ExecState */*exec*/) 1015 957 { /* empty */ return Completion(); } … … 1028 970 virtual void ref(); 1029 971 virtual bool deref(); 1030 virtual ~FuncExprNode();1031 972 Value evaluate(ExecState *exec); 1032 973 virtual void streamTo(SourceStream &s) const; … … 1042 983 virtual void ref(); 1043 984 virtual bool deref(); 1044 virtual ~SourceElementNode();1045 985 Completion execute(ExecState *exec); 1046 986 virtual void processFuncDecl(ExecState *exec); … … 1060 1000 virtual void ref(); 1061 1001 virtual bool deref(); 1062 virtual ~SourceElementsNode();1063 1002 Completion execute(ExecState *exec); 1064 1003 virtual void processFuncDecl(ExecState *exec); … … 1073 1012 public: 1074 1013 ProgramNode(SourceElementsNode *s); 1075 ~ProgramNode();1076 private:1077 // Disallow copy1078 ProgramNode(const ProgramNode &other);1079 1014 }; 1080 1015 -
trunk/JavaScriptCore/kjs/nodes2string.cpp
r830 r1799 35 35 UString toString() const { return str; } 36 36 SourceStream& operator<<(const KJS::UString &); 37 SourceStream& operator<<(char); 37 38 SourceStream& operator<<(Format f); 38 39 SourceStream& operator<<(const Node *); … … 44 45 45 46 using namespace KJS; 47 48 SourceStream& SourceStream::operator<<(char c) 49 { 50 str += UString(c); 51 return *this; 52 } 46 53 47 54 SourceStream& SourceStream::operator<<(const KJS::UString &s) -
trunk/JavaScriptCore/kjs/number_object.cpp
r1024 r1799 55 55 // The constructor will be added later, after NumberObjectImp has been constructed 56 56 57 put(exec, "toString", Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ToString, 1)), DontEnum);57 put(exec,toStringPropertyName, Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ToString, 1)), DontEnum); 58 58 put(exec,"toLocaleString", Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ToLocaleString, 0)), DontEnum); 59 put(exec, "valueOf", Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ValueOf, 0)), DontEnum);59 put(exec,valueOfPropertyName, Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ValueOf, 0)), DontEnum); 60 60 } 61 61 … … 68 68 { 69 69 Value protect(this); 70 put(exec, "length",Number(len),DontDelete|ReadOnly|DontEnum);70 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 71 71 } 72 72 … … 125 125 Value protect(this); 126 126 // Number.Prototype 127 put(exec, "prototype", Value(numberProto),DontEnum|DontDelete|ReadOnly);127 put(exec,prototypePropertyName, Value(numberProto),DontEnum|DontDelete|ReadOnly); 128 128 129 129 // no. of arguments for constructor 130 put(exec, "length", Number(1), ReadOnly|DontDelete|DontEnum);130 put(exec,lengthPropertyName, Number(1), ReadOnly|DontDelete|DontEnum); 131 131 } 132 132 -
trunk/JavaScriptCore/kjs/object.cpp
r1326 r1799 39 39 #include "property_map.h" 40 40 41 using namespace KJS; 41 namespace KJS { 42 43 extern const UString lengthPropertyName("length"); 44 extern const UString prototypePropertyName("prototype"); 45 extern const UString toStringPropertyName("toString"); 46 extern const UString valueOfPropertyName("valueOf"); 42 47 43 48 // ------------------------------ Object --------------------------------------- 44 45 Object::Object() : Value()46 {47 }48 49 Object::Object(ObjectImp *v) : Value(v)50 {51 }52 53 Object::Object(const Object &v) : Value(v)54 {55 }56 57 Object::~Object()58 {59 }60 61 Object& Object::operator=(const Object &v)62 {63 Value::operator=(v);64 return *this;65 }66 67 const ClassInfo *Object::classInfo() const68 {69 return static_cast<ObjectImp*>(rep)->classInfo();70 }71 72 bool Object::inherits(const ClassInfo *cinfo) const73 {74 return static_cast<ObjectImp*>(rep)->inherits(cinfo);75 }76 49 77 50 Object Object::dynamicCast(const Value &v) … … 81 54 82 55 return Object(static_cast<ObjectImp*>(v.imp())); 83 }84 85 Value Object::prototype() const86 {87 return Value(static_cast<ObjectImp*>(rep)->prototype());88 }89 90 UString Object::className() const91 {92 return static_cast<ObjectImp*>(rep)->className();93 }94 95 Value Object::get(ExecState *exec, const UString &propertyName) const96 {97 return static_cast<ObjectImp*>(rep)->get(exec,propertyName);98 }99 100 void Object::put(ExecState *exec, const UString &propertyName, const Value &value, int attr)101 {102 static_cast<ObjectImp*>(rep)->put(exec,propertyName,value,attr);103 }104 105 bool Object::canPut(ExecState *exec, const UString &propertyName) const106 {107 return static_cast<ObjectImp*>(rep)->canPut(exec,propertyName);108 }109 110 bool Object::hasProperty(ExecState *exec, const UString &propertyName) const111 {112 return static_cast<ObjectImp*>(rep)->hasProperty(exec, propertyName);113 }114 115 bool Object::deleteProperty(ExecState *exec, const UString &propertyName)116 {117 return static_cast<ObjectImp*>(rep)->deleteProperty(exec,propertyName);118 }119 120 Value Object::defaultValue(ExecState *exec, Type hint) const121 {122 return static_cast<ObjectImp*>(rep)->defaultValue(exec,hint);123 }124 125 bool Object::implementsConstruct() const126 {127 return static_cast<ObjectImp*>(rep)->implementsConstruct();128 }129 130 Object Object::construct(ExecState *exec, const List &args)131 {132 return static_cast<ObjectImp*>(rep)->construct(exec,args);133 }134 135 bool Object::implementsCall() const136 {137 return static_cast<ObjectImp*>(rep)->implementsCall();138 }139 140 Value Object::call(ExecState *exec, Object &thisObj, const List &args)141 {142 return static_cast<ObjectImp*>(rep)->call(exec,thisObj,args);143 }144 145 bool Object::implementsHasInstance() const146 {147 return static_cast<ObjectImp*>(rep)->implementsHasInstance();148 }149 150 Boolean Object::hasInstance(ExecState *exec, const Value &value)151 {152 return static_cast<ObjectImp*>(rep)->hasInstance(exec,value);153 }154 155 const List Object::scope() const156 {157 return static_cast<ObjectImp*>(rep)->scope();158 }159 160 void Object::setScope(const List &s)161 {162 static_cast<ObjectImp*>(rep)->setScope(s);163 }164 165 List Object::propList(ExecState *exec, bool recursive)166 {167 return static_cast<ObjectImp*>(rep)->propList(exec,recursive);168 }169 170 Value Object::internalValue() const171 {172 return static_cast<ObjectImp*>(rep)->internalValue();173 }174 175 void Object::setInternalValue(const Value &v)176 {177 static_cast<ObjectImp*>(rep)->setInternalValue(v);178 56 } 179 57 … … 294 172 295 173 return proto.get(exec,propertyName); 174 } 175 176 Value ObjectImp::get(ExecState *exec, unsigned propertyName) const 177 { 178 return get(exec, UString::from(propertyName)); 296 179 } 297 180 … … 335 218 } 336 219 220 void ObjectImp::put(ExecState *exec, unsigned propertyName, 221 const Value &value, int attr) 222 { 223 put(exec, UString::from(propertyName), value, attr); 224 } 225 337 226 // ECMA 8.6.2.3 338 227 bool ObjectImp::canPut(ExecState *, const UString &propertyName) const … … 367 256 Object proto = Object::dynamicCast(prototype()); 368 257 return !proto.isNull() && proto.hasProperty(exec,propertyName); 258 } 259 260 bool ObjectImp::hasProperty(ExecState *exec, unsigned propertyName) const 261 { 262 return hasProperty(exec, UString::from(propertyName)); 369 263 } 370 264 … … 387 281 } 388 282 283 bool ObjectImp::deleteProperty(ExecState *exec, unsigned propertyName) 284 { 285 return deleteProperty(exec, UString::from(propertyName)); 286 } 287 389 288 void ObjectImp::deleteAllProperties( ExecState * ) 390 289 { … … 405 304 Value v; 406 305 if (hint == StringType) 407 v = get(exec, "toString");306 v = get(exec,toStringPropertyName); 408 307 else 409 v = get(exec, "valueOf");308 v = get(exec,valueOfPropertyName); 410 309 411 310 if (v.type() == ObjectType) { … … 424 323 425 324 if (hint == StringType) 426 v = get(exec, "valueOf");325 v = get(exec,valueOfPropertyName); 427 326 else 428 v = get(exec, "toString");327 v = get(exec,toStringPropertyName); 429 328 430 329 if (v.type() == ObjectType) { … … 546 445 } 547 446 548 // The following functions simply call the corresponding functions in ValueImp549 // but are overridden in case of future needs550 551 447 Value ObjectImp::toPrimitive(ExecState *exec, Type preferredType) const 552 448 { … … 565 461 return 0.0; 566 462 return prim.toNumber(exec); 567 }568 569 int ObjectImp::toInteger(ExecState *exec) const570 {571 return ValueImp::toInteger(exec);572 }573 574 int ObjectImp::toInt32(ExecState *exec) const575 {576 return ValueImp::toInt32(exec);577 }578 579 unsigned int ObjectImp::toUInt32(ExecState *exec) const580 {581 return ValueImp::toUInt32(exec);582 }583 584 unsigned short ObjectImp::toUInt16(ExecState *exec) const585 {586 return ValueImp::toUInt16(exec);587 463 } 588 464 … … 670 546 } 671 547 548 } // namespace KJS -
trunk/JavaScriptCore/kjs/object.h
r1623 r1799 80 80 class Object : public Value { 81 81 public: 82 Object() ;82 Object() { } 83 83 explicit Object(ObjectImp *v); 84 Object(const Object &v); 85 virtual ~Object(); 86 87 Object& operator=(const Object &v); 88 89 virtual const ClassInfo *classInfo() const; 84 85 ObjectImp *imp() const; 86 87 const ClassInfo *classInfo() const; 90 88 bool inherits(const ClassInfo *cinfo) const; 91 89 … … 133 131 */ 134 132 Value get(ExecState *exec, const UString &propertyName) const; 133 Value get(ExecState *exec, unsigned propertyName) const; 135 134 136 135 /** … … 145 144 void put(ExecState *exec, const UString &propertyName, 146 145 const Value &value, int attr = None); 146 void put(ExecState *exec, unsigned propertyName, 147 const Value &value, int attr = None); 147 148 148 149 /** … … 169 170 */ 170 171 bool hasProperty(ExecState *exec, const UString &propertyName) const; 172 bool hasProperty(ExecState *exec, unsigned propertyName) const; 171 173 172 174 /** … … 182 184 */ 183 185 bool deleteProperty(ExecState *exec, const UString &propertyName); 186 bool deleteProperty(ExecState *exec, unsigned propertyName); 184 187 185 188 /** … … 350 353 }; 351 354 355 inline Object Value::toObject(ExecState *exec) const { return rep->toObject(exec); } 356 352 357 class ObjectImp : public ValueImp { 353 358 public: … … 467 472 // [[Get]] - must be implemented by all Objects 468 473 virtual Value get(ExecState *exec, const UString &propertyName) const; 474 virtual Value get(ExecState *exec, unsigned propertyName) const; 469 475 470 476 /** … … 476 482 virtual void put(ExecState *exec, const UString &propertyName, 477 483 const Value &value, int attr = None); 484 virtual void put(ExecState *exec, unsigned propertyName, 485 const Value &value, int attr = None); 478 486 479 487 /** … … 493 501 virtual bool hasProperty(ExecState *exec, 494 502 const UString &propertyName) const; 503 virtual bool hasProperty(ExecState *exec, unsigned propertyName) const; 495 504 496 505 /** … … 502 511 virtual bool deleteProperty(ExecState *exec, 503 512 const UString &propertyName); 513 virtual bool deleteProperty(ExecState *exec, unsigned propertyName); 504 514 505 515 /** … … 560 570 bool toBoolean(ExecState *exec) const; 561 571 double toNumber(ExecState *exec) const; 562 int toInteger(ExecState *exec) const;563 int toInt32(ExecState *exec) const;564 unsigned int toUInt32(ExecState *exec) const;565 unsigned short toUInt16(ExecState *exec) const;566 572 UString toString(ExecState *exec) const; 567 573 Object toObject(ExecState *exec) const; … … 613 619 }; 614 620 621 inline Object::Object(ObjectImp *v) : Value(v) { } 622 623 inline ObjectImp *Object::imp() const { return static_cast<ObjectImp*>(rep); } 624 625 inline const ClassInfo *Object::classInfo() const 626 { return imp()->classInfo(); } 627 628 inline bool Object::inherits(const ClassInfo *cinfo) const 629 { return imp()->inherits(cinfo); } 630 631 inline Value Object::prototype() const 632 { return Value(imp()->prototype()); } 633 634 inline UString Object::className() const 635 { return imp()->className(); } 636 637 inline Value Object::get(ExecState *exec, const UString &propertyName) const 638 { return imp()->get(exec,propertyName); } 639 640 inline Value Object::get(ExecState *exec, unsigned propertyName) const 641 { return imp()->get(exec,propertyName); } 642 643 inline void Object::put(ExecState *exec, const UString &propertyName, const Value &value, int attr) 644 { imp()->put(exec,propertyName,value,attr); } 645 646 inline void Object::put(ExecState *exec, unsigned propertyName, const Value &value, int attr) 647 { imp()->put(exec,propertyName,value,attr); } 648 649 inline bool Object::canPut(ExecState *exec, const UString &propertyName) const 650 { return imp()->canPut(exec,propertyName); } 651 652 inline bool Object::hasProperty(ExecState *exec, const UString &propertyName) const 653 { return imp()->hasProperty(exec, propertyName); } 654 655 inline bool Object::hasProperty(ExecState *exec, unsigned propertyName) const 656 { return imp()->hasProperty(exec, propertyName); } 657 658 inline bool Object::deleteProperty(ExecState *exec, const UString &propertyName) 659 { return imp()->deleteProperty(exec,propertyName); } 660 661 inline bool Object::deleteProperty(ExecState *exec, unsigned propertyName) 662 { return imp()->deleteProperty(exec,propertyName); } 663 664 inline Value Object::defaultValue(ExecState *exec, Type hint) const 665 { return imp()->defaultValue(exec,hint); } 666 667 inline bool Object::implementsConstruct() const 668 { return imp()->implementsConstruct(); } 669 670 inline Object Object::construct(ExecState *exec, const List &args) 671 { return imp()->construct(exec,args); } 672 673 inline bool Object::implementsCall() const 674 { return imp()->implementsCall(); } 675 676 inline Value Object::call(ExecState *exec, Object &thisObj, const List &args) 677 { return imp()->call(exec,thisObj,args); } 678 679 inline bool Object::implementsHasInstance() const 680 { return imp()->implementsHasInstance(); } 681 682 inline Boolean Object::hasInstance(ExecState *exec, const Value &value) 683 { return imp()->hasInstance(exec,value); } 684 685 inline const List Object::scope() const 686 { return imp()->scope(); } 687 688 inline void Object::setScope(const List &s) 689 { imp()->setScope(s); } 690 691 inline List Object::propList(ExecState *exec, bool recursive) 692 { return imp()->propList(exec,recursive); } 693 694 inline Value Object::internalValue() const 695 { return imp()->internalValue(); } 696 697 inline void Object::setInternalValue(const Value &v) 698 { imp()->setInternalValue(v); } 699 700 extern const UString lengthPropertyName; 701 extern const UString prototypePropertyName; 702 extern const UString toStringPropertyName; 703 extern const UString valueOfPropertyName; 704 615 705 }; // namespace 616 706 -
trunk/JavaScriptCore/kjs/object_object.cpp
r1024 r1799 39 39 { 40 40 Value protect(this); 41 put(exec, "toString", Object(new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToString, 0)), DontEnum);42 put(exec, "valueOf", Object(new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ValueOf, 0)), DontEnum);41 put(exec,toStringPropertyName, Object(new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToString, 0)), DontEnum); 42 put(exec,valueOfPropertyName, Object(new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ValueOf, 0)), DontEnum); 43 43 } 44 44 … … 52 52 { 53 53 Value protect(this); 54 put(exec, "length",Number(len),DontDelete|ReadOnly|DontEnum);54 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 55 55 } 56 56 … … 80 80 Value protect(this); 81 81 // ECMA 15.2.3.1 82 put(exec, "prototype", Object(objProto), DontEnum|DontDelete|ReadOnly);82 put(exec,prototypePropertyName, Object(objProto), DontEnum|DontDelete|ReadOnly); 83 83 84 84 // no. of arguments for constructor 85 put(exec, "length", Number(1), ReadOnly|DontDelete|DontEnum);85 put(exec,lengthPropertyName, Number(1), ReadOnly|DontDelete|DontEnum); 86 86 } 87 87 -
trunk/JavaScriptCore/kjs/regexp_object.cpp
r1623 r1799 50 50 put(exec, "exec", Object(new RegExpProtoFuncImp(exec,funcProto,RegExpProtoFuncImp::Exec, 0)), DontEnum); 51 51 put(exec, "test", Object(new RegExpProtoFuncImp(exec,funcProto,RegExpProtoFuncImp::Test, 0)), DontEnum); 52 put(exec, "toString", Object(new RegExpProtoFuncImp(exec,funcProto,RegExpProtoFuncImp::ToString, 0)), DontEnum);52 put(exec, toStringPropertyName, Object(new RegExpProtoFuncImp(exec,funcProto,RegExpProtoFuncImp::ToString, 0)), DontEnum); 53 53 } 54 54 … … 60 60 { 61 61 Value protect(this); 62 put(exec, "length",Number(len),DontDelete|ReadOnly|DontEnum);62 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 63 63 } 64 64 … … 157 157 Value protect(this); 158 158 // ECMA 15.10.5.1 RegExp.prototype 159 put(exec, "prototype", Object(regProto), DontEnum|DontDelete|ReadOnly);159 put(exec,prototypePropertyName, Object(regProto), DontEnum|DontDelete|ReadOnly); 160 160 161 161 // no. of arguments for constructor 162 put(exec, "length", Number(2), ReadOnly|DontDelete|DontEnum);162 put(exec,lengthPropertyName, Number(2), ReadOnly|DontDelete|DontEnum); 163 163 } 164 164 -
trunk/JavaScriptCore/kjs/string_object.cpp
r1623 r1799 90 90 Value protect(this); 91 91 // The constructor will be added later, after StringObjectImp has been built 92 put(exec, "length",Number(0),DontDelete|ReadOnly|DontEnum);92 put(exec,lengthPropertyName,Number(0),DontDelete|ReadOnly|DontEnum); 93 93 94 94 } … … 107 107 { 108 108 Value protect(this); 109 put(exec, "length",Number(len),DontDelete|ReadOnly|DontEnum);109 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 110 110 } 111 111 … … 343 343 if (u.isEmpty() && !reg.match(u, 0).isNull()) { 344 344 // empty string matched by regexp -> empty array 345 res.put(exec, "length", Number(0));345 res.put(exec,lengthPropertyName, Number(0)); 346 346 break; 347 347 } … … 357 357 pos = mpos + (mstr.isEmpty() ? 1 : mstr.size()); 358 358 if (mpos != p0 || !mstr.isEmpty()) { 359 res.put(exec, UString::from(i), String(u.substr(p0, mpos-p0)));359 res.put(exec,i, String(u.substr(p0, mpos-p0))); 360 360 p0 = mpos + mstr.size(); 361 361 i++; … … 367 367 if (u.isEmpty()) { 368 368 // empty separator matches empty string -> empty array 369 put(exec, "length", Number(0));369 put(exec,lengthPropertyName, Number(0)); 370 370 break; 371 371 } else { 372 372 while (i != d && i < u.size()-1) 373 res.put(exec, UString::from(i++), String(u.substr(p0++, 1)));373 res.put(exec, i++, String(u.substr(p0++, 1))); 374 374 } 375 375 } else { 376 376 while (i != d && (pos = u.find(u2, p0)) >= 0) { 377 res.put(exec, UString::from(i), String(u.substr(p0, pos-p0)));377 res.put(exec, i, String(u.substr(p0, pos-p0))); 378 378 p0 = pos + u2.size(); 379 379 i++; … … 383 383 // add remaining string, if any 384 384 if (i != d) 385 res.put(exec, UString::from(i++), String(u.substr(p0)));386 res.put(exec, "length", Number(i));385 res.put(exec, i++, String(u.substr(p0))); 386 res.put(exec,lengthPropertyName, Number(i)); 387 387 } 388 388 break; … … 498 498 Value protect(this); 499 499 // ECMA 15.5.3.1 String.prototype 500 put(exec,"prototype", Object(stringProto), DontEnum|DontDelete|ReadOnly); 501 502 put(exec,"fromCharCode", Object(new StringObjectFuncImp(exec,funcProto)), DontEnum); 500 put(exec,prototypePropertyName, Object(stringProto), DontEnum|DontDelete|ReadOnly); 501 502 static UString fromCharCode("fromCharCode"); 503 put(exec,fromCharCode, Object(new StringObjectFuncImp(exec,funcProto)), DontEnum); 503 504 504 505 // no. of arguments for constructor 505 put(exec, "length", Number(1), ReadOnly|DontDelete|DontEnum);506 put(exec,lengthPropertyName, Number(1), ReadOnly|DontDelete|DontEnum); 506 507 } 507 508 … … 525 526 526 527 obj.setInternalValue(String(s)); 527 obj.put(exec, "length", Number(s.size()), ReadOnly|DontEnum|DontDelete);528 obj.put(exec, lengthPropertyName, Number(s.size()), ReadOnly|DontEnum|DontDelete); 528 529 529 530 return obj; … … 553 554 { 554 555 Value protect(this); 555 put(exec, "length",Number(1),DontDelete|ReadOnly|DontEnum);556 put(exec,lengthPropertyName,Number(1),DontDelete|ReadOnly|DontEnum); 556 557 } 557 558 -
trunk/JavaScriptCore/kjs/types.cpp
r1623 r1799 46 46 } 47 47 48 Reference::Reference(const Object& b, unsigned p) 49 : Value(new ReferenceImp(b,p)) 50 { 51 } 52 48 53 Reference::Reference(const Null& b, const UString& p) 49 54 : Value(new ReferenceImp(b,p)) … … 51 56 } 52 57 53 Reference::Reference(ReferenceImp *v) : Value(v) 54 { 55 } 56 57 Reference::Reference(const Reference &v) : Value(v) 58 { 59 } 60 61 Reference::~Reference() 62 { 63 } 64 65 Reference& Reference::operator=(const Reference &v) 66 { 67 Value::operator=(v); 68 return *this; 58 Reference::Reference(const Null& b, unsigned p) 59 : Value(new ReferenceImp(b,p)) 60 { 69 61 } 70 62 … … 87 79 ListIterator::ListIterator(const List &l) 88 80 : node(static_cast<ListImp*>(l.imp())->hook->next) 89 {90 }91 92 ListIterator& ListIterator::operator=(const ListIterator &iterator)93 {94 node=iterator.node;95 return *this;96 }97 98 ListIterator::ListIterator(const ListIterator &i) : node(i.node)99 {100 }101 102 ListIterator::~ListIterator()103 81 { 104 82 } … … 160 138 } 161 139 162 List::List(ListImp *v) : Value(v)163 {164 //fprintf(stderr,"List::List(imp) this=%p imp=%p refcount=%d\n",this,v,v?v->refcount:0);165 }166 167 List::List(const List &v) : Value(v)168 {169 //fprintf(stderr,"List::List(List) this=%p imp=%p refcount=%d\n",this,rep,rep?rep->refcount:0);170 }171 172 List::~List()173 {174 //fprintf(stderr,"List::~List() this=%p imp=%p refcount=%d\n",this,rep,rep->refcount-1);175 }176 177 List& List::operator=(const List &v)178 {179 //fprintf(stderr,"List::operator=() this=%p\n",this);180 Value::operator=(v);181 return *this;182 }183 184 140 List List::dynamicCast(const Value &v) 185 141 { … … 286 242 } 287 243 288 Completion::Completion(CompletionImp *v) : Value(v)289 {290 }291 292 Completion::Completion(const Completion &v) : Value(v)293 {294 }295 296 Completion::~Completion()297 {298 }299 300 Completion& Completion::operator=(const Completion &v)301 {302 Value::operator=(v);303 return *this;304 }305 306 244 Completion Completion::dynamicCast(const Value &v) 307 245 { -
trunk/JavaScriptCore/kjs/types.h
r1623 r1799 34 34 public: 35 35 Reference(const Object& b, const UString& p); 36 Reference(const Object& b, unsigned p); 36 37 Reference(const Null& b, const UString& p); 38 Reference(const Null& b, unsigned p); 37 39 Reference(ReferenceImp *v); 38 Reference(const Reference &v);39 virtual ~Reference();40 41 Reference& operator=(const Reference &v);42 40 43 41 /** … … 72 70 ListIterator(const List &l); 73 71 /** 74 * Assignment constructor.75 */76 ListIterator& operator=(const ListIterator &iterator);77 /**78 * Copy constructor.79 */80 ListIterator(const ListIterator &i);81 ~ListIterator();82 /**83 72 * Dereference the iterator. 84 73 * @return A pointer to the element the iterator operates on. … … 139 128 List(); 140 129 List(ListImp *v); 141 List(const List &v);142 virtual ~List();143 144 List& operator=(const List &v);145 130 146 131 /** … … 255 240 const UString &t = UString::null); 256 241 Completion(CompletionImp *v); 257 Completion(const Completion &v);258 virtual ~Completion();259 260 Completion& operator=(const Completion &v);261 242 262 243 /** -
trunk/JavaScriptCore/kjs/ustring.cpp
r1791 r1799 116 116 UChar UChar::null; 117 117 UString::Rep UString::Rep::null = { 0, 0, 0, 1 }; 118 UString::Rep UString::Rep::empty = { 0, 0, 0, 1 }; 118 119 UString UString::null; 119 120 const int normalStatBufferSize = 4096; … … 191 192 } 192 193 int length = strlen(c); 194 if (length == 0) { 195 attach(&Rep::empty); 196 return; 197 } 193 198 UChar *d = new UChar[length]; 194 199 for (int i = 0; i < length; i++) … … 199 204 UString::UString(const UChar *c, int length) 200 205 { 206 if (length == 0) { 207 attach(&Rep::empty); 208 return; 209 } 201 210 UChar *d = new UChar[length]; 202 211 memcpy(d, c, length * sizeof(UChar)); … … 206 215 UString::UString(UChar *c, int length, bool copy) 207 216 { 217 if (length == 0) { 218 attach(&Rep::empty); 219 return; 220 } 208 221 UChar *d; 209 222 if (copy) { … … 224 237 int aSize = a.size(); 225 238 int bSize = b.size(); 226 UChar *d = new UChar[aSize + bSize]; 239 int length = aSize + bSize; 240 if (length == 0) { 241 attach(&Rep::empty); 242 return; 243 } 244 UChar *d = new UChar[length]; 227 245 memcpy(d, a.data(), aSize * sizeof(UChar)); 228 246 memcpy(d + aSize, b.data(), bSize * sizeof(UChar)); 229 rep = Rep::create(d, aSize + bSize);247 rep = Rep::create(d, length); 230 248 } 231 249 … … 467 485 int UString::find(const UString &f, int pos) const 468 486 { 469 if ( isNull())487 if (size() < f.size()) 470 488 return -1; 471 long fsize = f.size() * sizeof(UChar);472 489 if (pos < 0) 473 490 pos = 0; 474 491 const UChar *end = data() + size() - f.size(); 492 long fsize = f.size() * sizeof(UChar); 493 const void *fdata = f.data(); 475 494 for (const UChar *c = data() + pos; c <= end; c++) 476 if (!memcmp( (void*)c, (void*)f.data(), fsize))495 if (!memcmp(c, fdata, fsize)) 477 496 return (c-data()); 478 497 … … 480 499 } 481 500 501 int UString::find(UChar ch, int pos) const 502 { 503 if (pos < 0) 504 pos = 0; 505 const UChar *end = data() + size(); 506 for (const UChar *c = data() + pos; c < end; c++) 507 if (*c == ch) 508 return (c-data()); 509 510 return -1; 511 } 512 482 513 int UString::rfind(const UString &f, int pos) const 483 514 { 484 if ( isNull())515 if (size() < f.size()) 485 516 return -1; 486 517 if (pos + f.size() >= size()) 487 518 pos = size() - f.size(); 488 519 long fsize = f.size() * sizeof(UChar); 520 const void *fdata = f.data(); 489 521 for (const UChar *c = data() + pos; c >= data(); c--) { 490 if (!memcmp( (void*)c, (void*)f.data(), fsize))522 if (!memcmp(c, fdata, fsize)) 491 523 return (c-data()); 492 524 } … … 495 527 } 496 528 529 int UString::rfind(UChar ch, int pos) const 530 { 531 if (isEmpty()) 532 return -1; 533 if (pos + 1 >= size()) 534 pos = size() - 1; 535 for (const UChar *c = data() + pos; c >= data(); c--) { 536 if (*c == ch) 537 return (c-data()); 538 } 539 540 return -1; 541 } 542 497 543 UString UString::substr(int pos, int len) const 498 544 { 499 if (isNull())500 return UString();501 545 if (pos < 0) 502 546 pos = 0; … … 552 596 bool KJS::operator==(const UString& s1, const char *s2) 553 597 { 554 if (s2 == 0L && s1.isNull()) 555 return true; 556 557 if (s1.size() != (int) strlen(s2)) 598 if (s2 == 0) { 599 return s1.isEmpty(); 600 } 601 602 if (s1.size() != (int)strlen(s2)) 558 603 return false; 559 604 560 605 const UChar *u = s1.data(); 561 606 while (*s2) { 562 if (u->uc != *s2)607 if (u->uc != (unsigned char)*s2) 563 608 return false; 564 609 s2++; … … 583 628 } 584 629 if (l < lmin) 585 return (c1->u nicode() < c2->unicode());630 return (c1->uc < c2->uc); 586 631 587 632 return (l1 < l2); -
trunk/JavaScriptCore/kjs/ustring.h
r1791 r1799 216 216 int rc; 217 217 static Rep null; 218 static Rep empty; 218 219 }; 219 220 … … 226 227 * Constructs a string from the single character c. 227 228 */ 228 UString(char c);229 explicit UString(char c); 229 230 /** 230 231 * Constructs a string from a classical zero determined char string. … … 316 317 */ 317 318 UString &operator=(const char *c); 318 /**319 * Assignment operator.320 */321 319 UString &operator=(const UString &); 322 320 /** … … 376 374 */ 377 375 int find(const UString &f, int pos = 0) const; 376 int find(UChar, int pos = 0) const; 378 377 /** 379 378 * @return Position of first occurence of f searching backwards from … … 382 381 */ 383 382 int rfind(const UString &f, int pos) const; 383 int rfind(UChar, int pos) const; 384 384 /** 385 385 * @return The sub string starting at position pos and length len. -
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 -
trunk/JavaScriptCore/kjs/value.h
r1791 r1799 115 115 // The conversion operations 116 116 117 virtual Value toPrimitive(ExecState *exec, 118 Type preferredType = UnspecifiedType) const = 0; 117 virtual Value toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const = 0; 119 118 virtual bool toBoolean(ExecState *exec) const = 0; 120 119 virtual double toNumber(ExecState *exec) const = 0; 121 virtual int toInteger(ExecState *exec) const;122 virtual int toInt32(ExecState *exec) const;123 virtual unsigned int toUInt32(ExecState *exec) const;124 virtual unsigned short toUInt16(ExecState *exec) const;125 120 virtual UString toString(ExecState *exec) const = 0; 126 121 virtual Object toObject(ExecState *exec) const = 0; 122 123 virtual bool toUInt32(unsigned&) const; 124 125 int toInteger(ExecState *exec) const; 126 int toInt32(ExecState *exec) const; 127 unsigned int toUInt32(ExecState *exec) const; 128 unsigned short toUInt16(ExecState *exec) const; 127 129 128 130 // Reference operations … … 131 133 virtual UString getPropertyName(ExecState *exec) const; 132 134 virtual Value getValue(ExecState *exec) const; 133 virtual void putValue(ExecState *exec, const Value w); 135 virtual void putValue(ExecState *exec, const Value& w); 136 virtual bool deleteValue(ExecState *exec); 134 137 135 138 private: … … 143 146 ValueImpPrivate *_vd; 144 147 unsigned int _flags; 148 149 // Give a compile time error if we try to copy one of these. 150 ValueImp(const ValueImp&); 151 ValueImp& operator=(const ValueImp&); 145 152 }; 146 153 … … 162 169 class Value { 163 170 public: 164 Value() ;171 Value() : rep(0) { } 165 172 explicit Value(ValueImp *v); 166 173 Value(const Value &v); 167 virtual~Value();174 ~Value(); 168 175 169 176 Value& operator=(const Value &v); 170 bool isNull() const ;171 ValueImp *imp() const ;177 bool isNull() const { return rep == 0; } 178 ValueImp *imp() const { return rep; } 172 179 173 180 /** … … 178 185 * @return The type of value 179 186 */ 180 Type type() const ;187 Type type() const { return rep->type(); } 181 188 182 189 /** … … 186 193 * @return true if the value is of the specified type, otherwise false 187 194 */ 188 bool isA(Type t) const ;195 bool isA(Type t) const { return rep->type() == t; } 189 196 190 197 /** … … 193 200 */ 194 201 Value toPrimitive(ExecState *exec, 195 Type preferredType = UnspecifiedType) const; 202 Type preferredType = UnspecifiedType) const 203 { return rep->toPrimitive(exec, preferredType); } 196 204 197 205 /** 198 206 * Performs the ToBoolean type conversion operation on this value (ECMA 9.2) 199 207 */ 200 bool toBoolean(ExecState *exec) const ;208 bool toBoolean(ExecState *exec) const { return rep->toBoolean(exec); } 201 209 202 210 /** 203 211 * Performs the ToNumber type conversion operation on this value (ECMA 9.3) 204 212 */ 205 double toNumber(ExecState *exec) const ;213 double toNumber(ExecState *exec) const { return rep->toNumber(exec); } 206 214 207 215 /** 208 216 * Performs the ToInteger type conversion operation on this value (ECMA 9.4) 209 217 */ 210 int toInteger(ExecState *exec) const ;218 int toInteger(ExecState *exec) const { return rep->toInteger(exec); } 211 219 212 220 /** 213 221 * Performs the ToInt32 type conversion operation on this value (ECMA 9.5) 214 222 */ 215 int toInt32(ExecState *exec) const ;223 int toInt32(ExecState *exec) const { return rep->toInt32(exec); } 216 224 217 225 /** 218 226 * Performs the ToUint32 type conversion operation on this value (ECMA 9.6) 219 227 */ 220 unsigned int toUInt32(ExecState *exec) const ;228 unsigned int toUInt32(ExecState *exec) const { return rep->toUInt32(exec); } 221 229 222 230 /** 223 231 * Performs the ToUint16 type conversion operation on this value (ECMA 9.7) 224 232 */ 225 unsigned short toUInt16(ExecState *exec) const ;233 unsigned short toUInt16(ExecState *exec) const { return rep->toUInt16(exec); } 226 234 227 235 /** 228 236 * Performs the ToString type conversion operation on this value (ECMA 9.8) 229 237 */ 230 UString toString(ExecState *exec) const ;238 UString toString(ExecState *exec) const { return rep->toString(exec); } 231 239 232 240 /** … … 241 249 * this method is guaranteed to return either Null() or an Object value. 242 250 */ 243 Value getBase(ExecState *exec) const ;251 Value getBase(ExecState *exec) const { return rep->getBase(exec); } 244 252 245 253 /** … … 247 255 * (ECMA 8.7) 248 256 */ 249 UString getPropertyName(ExecState *exec) const ;257 UString getPropertyName(ExecState *exec) const { return rep->getPropertyName(exec); } 250 258 251 259 /** … … 253 261 * (ECMA 8.7.1) 254 262 */ 255 Value getValue(ExecState *exec) const ;263 Value getValue(ExecState *exec) const { return rep->getValue(exec); } 256 264 257 265 /** … … 259 267 * (ECMA 8.7.1) 260 268 */ 261 void putValue(ExecState *exec, const Value w); 269 void putValue(ExecState *exec, const Value &w) { rep->putValue(exec, w); } 270 bool deleteValue(ExecState *exec) { return rep->deleteValue(exec); } 271 272 /** 273 * Checks if we can do a lossless conversion to UInt32. 274 */ 275 bool toUInt32(unsigned& i) const { return rep->toUInt32(i); } 262 276 263 277 protected: 264 278 ValueImp *rep; 265 279 }; 266 267 bool operator==(const Value &v1, const Value &v2);268 bool operator!=(const Value &v1, const Value &v2);269 280 270 281 // Primitive types … … 278 289 public: 279 290 Undefined(); 280 Undefined(const Undefined &v);281 virtual ~Undefined();282 283 Undefined& operator=(const Undefined &v);284 291 285 292 /** … … 307 314 public: 308 315 Null(); 309 Null(const Null &v);310 virtual ~Null();311 312 Null& operator=(const Null &v);313 316 314 317 /** … … 333 336 public: 334 337 Boolean(bool b = false); 335 Boolean(const Boolean &v);336 virtual ~Boolean();337 338 Boolean& operator=(const Boolean &v);339 338 340 339 /** … … 361 360 public: 362 361 String(const UString &s = ""); 363 String(const String &v);364 virtual ~String();365 366 String& operator=(const String &v);367 362 368 363 /** … … 396 391 Number(long int l); 397 392 Number(long unsigned int l); 398 Number(const Number &v);399 virtual ~Number();400 401 Number& operator=(const Number &v);402 393 403 394 double value() const;
Note:
See TracChangeset
for help on using the changeset viewer.