Changeset 9889 in webkit for trunk/JavaScriptCore/kjs/array_object.cpp
- Timestamp:
- Jul 25, 2005, 3:17:20 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/array_object.cpp
r9842 r9889 71 71 } 72 72 73 Value ArrayInstanceImp::get(ExecState *exec, const Identifier &propertyName) const 74 { 75 if (propertyName == lengthPropertyName) 76 return Number(length); 73 bool ArrayInstanceImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 74 { 75 if (propertyName == lengthPropertyName) { 76 result = Number(length); 77 return true; 78 } 77 79 78 80 bool ok; … … 80 82 if (ok) { 81 83 if (index >= length) 82 return Undefined();84 return false; 83 85 if (index < storageLength) { 84 86 ValueImp *v = storage[index]; 85 return v ? Value(v) : Undefined(); 86 } 87 } 88 89 return ObjectImp::get(exec, propertyName); 90 } 91 92 Value ArrayInstanceImp::get(ExecState *exec, unsigned index) const 87 if (!v || v == UndefinedImp::staticUndefined) 88 return false; 89 90 result = Value(v); 91 return true; 92 } 93 } 94 95 return ObjectImp::getOwnProperty(exec, propertyName, result); 96 } 97 98 bool ArrayInstanceImp::getOwnProperty(ExecState *exec, unsigned index, Value& result) const 93 99 { 94 100 if (index >= length) 95 return Undefined();101 return false; 96 102 if (index < storageLength) { 97 103 ValueImp *v = storage[index]; 98 return v ? Value(v) : Undefined(); 99 } 100 101 return ObjectImp::get(exec, Identifier::from(index)); 104 if (!v || v == UndefinedImp::staticUndefined) 105 return false; 106 107 result = Value(v); 108 return true; 109 } 110 111 return ObjectImp::getOwnProperty(exec, Identifier::from(index), result); 102 112 } 103 113 … … 419 429 } 420 430 421 Value ArrayPrototypeImp::get(ExecState *exec, const Identifier &propertyName) const 422 { 423 //fprintf( stderr, "ArrayPrototypeImp::get(%s)\n", propertyName.ascii() ); 424 return lookupGetFunction<ArrayProtoFuncImp, ArrayInstanceImp>( exec, propertyName, &arrayTable, this ); 431 bool ArrayPrototypeImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 432 { 433 return lookupGetOwnFunction<ArrayProtoFuncImp, ArrayInstanceImp>(exec, propertyName, &arrayTable, this, result); 425 434 } 426 435 … … 445 454 { 446 455 unsigned int length = thisObj.get(exec,lengthPropertyName).toUInt32(exec); 456 ObjectImp *thisImp = thisObj.imp(); 447 457 448 458 Value result; … … 502 512 length = curObj.get(exec,lengthPropertyName).toUInt32(exec); 503 513 while (k < length) { 504 if (curObj.hasProperty(exec,k)) 505 arr.put(exec, n, curObj.get(exec, k)); 514 Value v; 515 if (curObj.imp()->getProperty(exec, k, v)) 516 arr.put(exec, n, v); 506 517 n++; 507 518 k++; … … 545 556 for (unsigned int k = 0; k < middle; k++) { 546 557 unsigned lk1 = length - k - 1; 547 Value obj = thisObj.get(exec,k); 548 Value obj2 = thisObj.get(exec,lk1); 549 if (thisObj.hasProperty(exec,lk1)) { 550 if (thisObj.hasProperty(exec,k)) { 551 thisObj.put(exec, k, obj2); 552 thisObj.put(exec, lk1, obj); 553 } else { 554 thisObj.put(exec, k, obj2); 555 thisObj.deleteProperty(exec, lk1); 556 } 557 } else { 558 if (thisObj.hasProperty(exec, k)) { 559 thisObj.deleteProperty(exec, k); 560 thisObj.put(exec, lk1, obj); 561 } else { 562 // why delete something that's not there ? Strange. 563 thisObj.deleteProperty(exec, k); 564 thisObj.deleteProperty(exec, lk1); 565 } 566 } 558 Value obj; 559 Value obj2; 560 bool has2 = thisImp->getProperty(exec, lk1, obj2); 561 bool has1 = thisImp->getProperty(exec, k, obj); 562 563 if (has2) 564 thisObj.put(exec, k, obj2); 565 else 566 thisObj.deleteProperty(exec, k); 567 568 if (has1) 569 thisObj.put(exec, lk1, obj); 570 else 571 thisObj.deleteProperty(exec, lk1); 567 572 } 568 573 result = thisObj; … … 576 581 result = thisObj.get(exec, 0); 577 582 for(unsigned int k = 1; k < length; k++) { 578 if (thisObj.hasProperty(exec, k)) {579 Value obj = thisObj.get(exec, k);583 Value obj; 584 if (thisImp->getProperty(exec, k, obj)) 580 585 thisObj.put(exec, k-1, obj); 581 }else586 else 582 587 thisObj.deleteProperty(exec, k-1); 583 588 } … … 623 628 int e = static_cast<int>(end); 624 629 for(int k = b; k < e; k++, n++) { 625 if (thisObj.hasProperty(exec, k)) {626 Value obj = thisObj.get(exec, k);630 Value obj; 631 if (thisImp->getProperty(exec, k, obj)) 627 632 resObj.put(exec, n, obj); 628 }629 633 } 630 634 resObj.put(exec, lengthPropertyName, Number(n), DontEnum | DontDelete); … … 646 650 } 647 651 648 if (this Obj.imp()->classInfo() == &ArrayInstanceImp::info) {652 if (thisImp->classInfo() == &ArrayInstanceImp::info) { 649 653 if (useSortFunction) 650 ((ArrayInstanceImp *)this Obj.imp())->sort(exec, sortFunction);654 ((ArrayInstanceImp *)thisImp)->sort(exec, sortFunction); 651 655 else 652 ((ArrayInstanceImp *)this Obj.imp())->sort(exec);656 ((ArrayInstanceImp *)thisImp)->sort(exec); 653 657 result = thisObj; 654 658 break; … … 719 723 //printf( "Splicing from %d, deleteCount=%d \n", begin, deleteCount ); 720 724 for(unsigned int k = 0; k < deleteCount; k++) { 721 if (thisObj.hasProperty(exec,k+begin)) {722 Value obj = thisObj.get(exec, k+begin);725 Value obj; 726 if (thisImp->getProperty(exec, k+begin, obj)) 723 727 resObj.put(exec, k, obj); 724 }725 728 } 726 729 resObj.put(exec, lengthPropertyName, Number(deleteCount), DontEnum | DontDelete); … … 733 736 for ( unsigned int k = begin; k < length - deleteCount; ++k ) 734 737 { 735 if (thisObj.hasProperty(exec,k+deleteCount)) {736 Value obj = thisObj.get(exec, k+deleteCount);738 Value obj; 739 if (thisImp->getProperty(exec, k+deleteCount, obj)) 737 740 thisObj.put(exec, k+additionalArgs, obj); 738 }739 741 else 740 742 thisObj.deleteProperty(exec, k+additionalArgs); … … 747 749 for ( unsigned int k = length - deleteCount; (int)k > begin; --k ) 748 750 { 749 if (thisObj.hasProperty(exec,k+deleteCount-1)) { 750 Value obj = thisObj.get(exec, k+deleteCount-1); 751 thisObj.put(exec, k+additionalArgs-1, obj); 752 } 751 Value obj; 752 if (thisImp->getProperty(exec, k + deleteCount - 1, obj)) 753 thisObj.put(exec, k + additionalArgs - 1, obj); 753 754 else 754 755 thisObj.deleteProperty(exec, k+additionalArgs-1); … … 767 768 for ( unsigned int k = length; k > 0; --k ) 768 769 { 769 if (thisObj.hasProperty(exec,k-1)) {770 Value obj = thisObj.get(exec, k-1);770 Value obj; 771 if (thisImp->getProperty(exec, k - 1, obj)) 771 772 thisObj.put(exec, k+nrArgs-1, obj); 772 } else {773 else 773 774 thisObj.deleteProperty(exec, k+nrArgs-1); 774 }775 775 } 776 776 for ( unsigned int k = 0; k < nrArgs; ++k )
Note:
See TracChangeset
for help on using the changeset viewer.