Changeset 10084 in webkit for trunk/JavaScriptCore/kjs/array_object.cpp
- Timestamp:
- Aug 7, 2005, 9:07:46 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/array_object.cpp
r10076 r10084 21 21 */ 22 22 23 #include "array_object.h" 24 25 #include "error_object.h" 26 #include "internal.h" 27 #include "interpreter.h" 28 #include "object.h" 29 #include "operations.h" 30 #include "reference_list.h" 31 #include "types.h" 23 32 #include "value.h" 24 #include "object.h"25 #include "types.h"26 #include "interpreter.h"27 #include "operations.h"28 #include "array_object.h"29 #include "internal.h"30 #include "error_object.h"31 33 32 34 #include "array_object.lut.h" … … 62 64 unsigned l = length; 63 65 for (unsigned i = 0; i < l; ++i) { 64 storage[i] = (it++).imp();66 storage[i] = it++; 65 67 } 66 68 } … … 71 73 } 72 74 73 Value 75 ValueImp *ArrayInstanceImp::lengthGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) 74 76 { 75 77 return Number(static_cast<ArrayInstanceImp *>(slot.slotBase())->length); … … 90 92 if (index < storageLength) { 91 93 ValueImp *v = storage[index]; 92 if (!v || v == UndefinedImp::staticUndefined) 93 return false; 94 94 if (!v || v->isUndefined()) 95 return false; 95 96 slot.setValueSlot(this, &storage[index]); 96 97 return true; … … 107 108 if (index < storageLength) { 108 109 ValueImp *v = storage[index]; 109 if (!v || v == UndefinedImp::staticUndefined)110 if (!v || v->isUndefined()) 110 111 return false; 111 112 112 slot.setValueSlot(this, &storage[index]); 113 113 return true; … … 118 118 119 119 // Special implementation of [[Put]] - see ECMA 15.4.5.1 120 void ArrayInstanceImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)120 void ArrayInstanceImp::put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr) 121 121 { 122 122 if (propertyName == lengthPropertyName) { 123 setLength(value .toUInt32(exec), exec);123 setLength(value->toUInt32(exec), exec); 124 124 return; 125 125 } … … 135 135 } 136 136 137 void ArrayInstanceImp::put(ExecState *exec, unsigned index, const Value &value, int attr)137 void ArrayInstanceImp::put(ExecState *exec, unsigned index, ValueImp *value, int attr) 138 138 { 139 139 if (index < sparseArrayCutoff && index >= storageLength) { … … 146 146 147 147 if (index < storageLength) { 148 storage[index] = value .imp();148 storage[index] = value; 149 149 return; 150 150 } … … 190 190 191 191 // avoid fetching this every time through the loop 192 ValueImp *undefined = UndefinedImp::staticUndefined;192 ValueImp *undefined = jsUndefined(); 193 193 194 194 for (unsigned i = 0; i < storageLength; ++i) { … … 232 232 ReferenceList sparseProperties; 233 233 234 _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, Object(this));234 _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, this); 235 235 236 236 ReferenceListIterator it = sparseProperties.begin(); … … 266 266 ValueImp *va = *(ValueImp **)a; 267 267 ValueImp *vb = *(ValueImp **)b; 268 if (va-> dispatchType() == UndefinedType) {269 return vb-> dispatchType() == UndefinedType? 0 : 1;270 } 271 if (vb-> dispatchType() == UndefinedType) {268 if (va->isUndefined()) { 269 return vb->isUndefined() ? 0 : 1; 270 } 271 if (vb->isUndefined()) { 272 272 return -1; 273 273 } 274 return compare(va-> dispatchToString(exec), vb->dispatchToString(exec));274 return compare(va->toString(exec), vb->toString(exec)); 275 275 } 276 276 … … 297 297 ObjectImp *compareFunction; 298 298 List arguments; 299 Object 299 ObjectImp *globalObject; 300 300 }; 301 301 … … 308 308 ValueImp *va = *(ValueImp **)a; 309 309 ValueImp *vb = *(ValueImp **)b; 310 if (va-> dispatchType() == UndefinedType) {311 return vb-> dispatchType() == UndefinedType? 0 : 1;312 } 313 if (vb-> dispatchType() == UndefinedType) {310 if (va->isUndefined()) { 311 return vb->isUndefined() ? 0 : 1; 312 } 313 if (vb->isUndefined()) { 314 314 return -1; 315 315 } … … 319 319 args->arguments.append(vb); 320 320 double compareResult = args->compareFunction->call 321 (args->exec, args->globalObject, args->arguments) .toNumber(args->exec);321 (args->exec, args->globalObject, args->arguments)->toNumber(args->exec); 322 322 return compareResult < 0 ? -1 : compareResult > 0 ? 1 : 0; 323 323 } 324 324 325 void ArrayInstanceImp::sort(ExecState *exec, Object &compareFunction)325 void ArrayInstanceImp::sort(ExecState *exec, ObjectImp *compareFunction) 326 326 { 327 327 int lengthNotIncludingUndefined = pushUndefinedObjectsToEnd(exec); 328 328 329 CompareWithCompareFunctionArguments args(exec, compareFunction .imp());329 CompareWithCompareFunctionArguments args(exec, compareFunction); 330 330 compareWithCompareFunctionArguments = &args; 331 331 qsort(storage, lengthNotIncludingUndefined, sizeof(ValueImp *), compareWithCompareFunctionForQSort); … … 335 335 unsigned ArrayInstanceImp::pushUndefinedObjectsToEnd(ExecState *exec) 336 336 { 337 ValueImp *undefined = UndefinedImp::staticUndefined;337 ValueImp *undefined = jsUndefined(); 338 338 339 339 unsigned o = 0; … … 349 349 350 350 ReferenceList sparseProperties; 351 _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, Object(this));351 _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, this); 352 352 unsigned newLength = o + sparseProperties.length(); 353 353 … … 359 359 while (it != sparseProperties.end()) { 360 360 Reference ref = it++; 361 storage[o] = ref.getValue(exec) .imp();361 storage[o] = ref.getValue(exec); 362 362 ObjectImp::deleteProperty(exec, ref.getPropertyName(exec)); 363 363 o++; … … 399 399 : ArrayInstanceImp(objProto, 0) 400 400 { 401 Value protect(this);402 401 setInternalValue(Null()); 403 402 } … … 412 411 ArrayProtoFuncImp::ArrayProtoFuncImp(ExecState *exec, int i, int len) 413 412 : InternalFunctionImp( 414 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype() .imp())413 static_cast<FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype()) 415 414 ), id(i) 416 415 { 417 Value protect(this);418 416 put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); 419 417 } … … 425 423 426 424 // ECMA 15.4.4 427 Value ArrayProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args) 428 { 429 unsigned int length = thisObj.get(exec,lengthPropertyName).toUInt32(exec); 430 ObjectImp *thisImp = thisObj.imp(); 431 432 Value result; 425 ValueImp *ArrayProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 426 { 427 unsigned length = thisObj->get(exec,lengthPropertyName)->toUInt32(exec); 428 429 ValueImp *result; 433 430 434 431 switch (id) { … … 436 433 case ToString: 437 434 438 if (!thisObj .inherits(&ArrayInstanceImp::info)) {439 Object 435 if (!thisObj->inherits(&ArrayInstanceImp::info)) { 436 ObjectImp *err = Error::create(exec,TypeError); 440 437 exec->setException(err); 441 438 return err; … … 447 444 UString str = ""; 448 445 449 if ( args[0].type() != UndefinedType)450 separator = args[0] .toString(exec);446 if (!args[0]->isUndefined()) 447 separator = args[0]->toString(exec); 451 448 for (unsigned int k = 0; k < length; k++) { 452 449 if (k >= 1) 453 450 str += separator; 454 451 455 Value element = thisObj.get(exec, k);456 if (element .type() == UndefinedType || element.type() == NullType)452 ValueImp *element = thisObj->get(exec, k); 453 if (element->isUndefinedOrNull()) 457 454 continue; 458 455 459 456 bool fallback = false; 460 457 if (id == ToLocaleString) { 461 Object o = element.toObject(exec); 462 Object conversionFunction = 463 Object::dynamicCast(o.get(exec, toLocaleStringPropertyName)); 464 if (conversionFunction.isValid() && 465 conversionFunction.implementsCall()) { 466 str += conversionFunction.call(exec, o, List()).toString(exec); 458 ObjectImp *o = element->toObject(exec); 459 ValueImp *conversionFunction = o->get(exec, toLocaleStringPropertyName); 460 if (conversionFunction->isObject() && static_cast<ObjectImp *>(conversionFunction)->implementsCall()) { 461 str += static_cast<ObjectImp *>(conversionFunction)->call(exec, o, List())->toString(exec); 467 462 } else { 468 463 // try toString() fallback … … 472 467 473 468 if (id == ToString || id == Join || fallback) { 474 if (element.type() == ObjectType) { 475 Object o = Object::dynamicCast(element); 476 Object conversionFunction = 477 Object::dynamicCast(o.get(exec, toStringPropertyName)); 478 if (conversionFunction.isValid() && 479 conversionFunction.implementsCall()) { 480 str += conversionFunction.call(exec, o, List()).toString(exec); 469 if (element->isObject()) { 470 ObjectImp *o = static_cast<ObjectImp *>(element); 471 ValueImp *conversionFunction = o->get(exec, toStringPropertyName); 472 if (conversionFunction->isObject() && static_cast<ObjectImp *>(conversionFunction)->implementsCall()) { 473 str += static_cast<ObjectImp *>(conversionFunction)->call(exec, o, List())->toString(exec); 481 474 } else { 482 UString msg = "Can't convert " + o.className() + 483 " object to string"; 484 Object error = Error::create(exec, RangeError, 485 msg.cstring().c_str()); 475 UString msg = "Can't convert " + o->className() + " object to string"; 476 ObjectImp *error = Error::create(exec, RangeError, msg.cstring().c_str()); 486 477 exec->setException(error); 487 478 return error; 488 479 } 489 480 } else { 490 str += element .toString(exec);481 str += element->toString(exec); 491 482 } 492 483 } … … 499 490 } 500 491 case Concat: { 501 Object arr = Object::dynamicCast(exec->lexicalInterpreter()->builtinArray().construct(exec,List::empty()));492 ObjectImp *arr = static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty())); 502 493 int n = 0; 503 Value 504 Object curObj = Object::dynamicCast(thisObj);494 ValueImp *curArg = thisObj; 495 ObjectImp *curObj = static_cast<ObjectImp *>(thisObj); 505 496 ListIterator it = args.begin(); 506 497 for (;;) { 507 if (curArg .type() == ObjectType&&508 curObj .inherits(&ArrayInstanceImp::info)) {498 if (curArg->isObject() && 499 curObj->inherits(&ArrayInstanceImp::info)) { 509 500 unsigned int k = 0; 510 501 // Older versions tried to optimize out getting the length of thisObj 511 502 // by checking for n != 0, but that doesn't work if thisObj is an empty array. 512 length = curObj .get(exec,lengthPropertyName).toUInt32(exec);503 length = curObj->get(exec,lengthPropertyName)->toUInt32(exec); 513 504 while (k < length) { 514 Value 515 if (curObj .imp()->getProperty(exec, k, v))516 arr .put(exec, n, v);505 ValueImp *v; 506 if (curObj->getProperty(exec, k, v)) 507 arr->put(exec, n, v); 517 508 n++; 518 509 k++; 519 510 } 520 511 } else { 521 arr .put(exec, n, curArg);512 arr->put(exec, n, curArg); 522 513 n++; 523 514 } … … 525 516 break; 526 517 curArg = *it; 527 curObj = Object::dynamicCast(it++); // may be 0528 } 529 arr .put(exec,lengthPropertyName, Number(n), DontEnum | DontDelete);518 curObj = static_cast<ObjectImp *>(it++); // may be 0 519 } 520 arr->put(exec,lengthPropertyName, Number(n), DontEnum | DontDelete); 530 521 531 522 result = arr; … … 534 525 case Pop:{ 535 526 if (length == 0) { 536 thisObj .put(exec, lengthPropertyName, Number(length), DontEnum | DontDelete);527 thisObj->put(exec, lengthPropertyName, Number(length), DontEnum | DontDelete); 537 528 result = Undefined(); 538 529 } else { 539 result = thisObj .get(exec, length - 1);540 thisObj .put(exec, lengthPropertyName, Number(length - 1), DontEnum | DontDelete);530 result = thisObj->get(exec, length - 1); 531 thisObj->put(exec, lengthPropertyName, Number(length - 1), DontEnum | DontDelete); 541 532 } 542 533 break; … … 544 535 case Push: { 545 536 for (int n = 0; n < args.size(); n++) 546 thisObj .put(exec, length + n, args[n]);537 thisObj->put(exec, length + n, args[n]); 547 538 length += args.size(); 548 thisObj .put(exec,lengthPropertyName, Number(length), DontEnum | DontDelete);539 thisObj->put(exec,lengthPropertyName, Number(length), DontEnum | DontDelete); 549 540 result = Number(length); 550 541 break; … … 556 547 for (unsigned int k = 0; k < middle; k++) { 557 548 unsigned lk1 = length - k - 1; 558 Value 559 Value 560 bool has2 = this Imp->getProperty(exec, lk1, obj2);561 bool has1 = this Imp->getProperty(exec, k, obj);549 ValueImp *obj; 550 ValueImp *obj2; 551 bool has2 = thisObj->getProperty(exec, lk1, obj2); 552 bool has1 = thisObj->getProperty(exec, k, obj); 562 553 563 554 if (has2) 564 thisObj .put(exec, k, obj2);555 thisObj->put(exec, k, obj2); 565 556 else 566 thisObj .deleteProperty(exec, k);557 thisObj->deleteProperty(exec, k); 567 558 568 559 if (has1) 569 thisObj .put(exec, lk1, obj);560 thisObj->put(exec, lk1, obj); 570 561 else 571 thisObj .deleteProperty(exec, lk1);562 thisObj->deleteProperty(exec, lk1); 572 563 } 573 564 result = thisObj; … … 576 567 case Shift: { 577 568 if (length == 0) { 578 thisObj .put(exec, lengthPropertyName, Number(length), DontEnum | DontDelete);569 thisObj->put(exec, lengthPropertyName, Number(length), DontEnum | DontDelete); 579 570 result = Undefined(); 580 571 } else { 581 result = thisObj .get(exec, 0);572 result = thisObj->get(exec, 0); 582 573 for(unsigned int k = 1; k < length; k++) { 583 Value 584 if (this Imp->getProperty(exec, k, obj))585 thisObj .put(exec, k-1, obj);574 ValueImp *obj; 575 if (thisObj->getProperty(exec, k, obj)) 576 thisObj->put(exec, k-1, obj); 586 577 else 587 thisObj .deleteProperty(exec, k-1);588 } 589 thisObj .deleteProperty(exec, length - 1);590 thisObj .put(exec, lengthPropertyName, Number(length - 1), DontEnum | DontDelete);578 thisObj->deleteProperty(exec, k-1); 579 } 580 thisObj->deleteProperty(exec, length - 1); 581 thisObj->put(exec, lengthPropertyName, Number(length - 1), DontEnum | DontDelete); 591 582 } 592 583 break; … … 596 587 597 588 // We return a new array 598 Object resObj = Object::dynamicCast(exec->lexicalInterpreter()->builtinArray().construct(exec,List::empty()));589 ObjectImp *resObj = static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty())); 599 590 result = resObj; 600 591 double begin = 0; 601 if ( args[0].type() != UndefinedType) {602 begin = args[0] .toInteger(exec);592 if (!args[0]->isUndefined()) { 593 begin = args[0]->toInteger(exec); 603 594 if (begin >= 0) { // false for NaN 604 595 if (begin > length) … … 611 602 } 612 603 double end = length; 613 if ( args[1].type() != UndefinedType) {614 end = args[1] .toInteger(exec);604 if (!args[1]->isUndefined()) { 605 end = args[1]->toInteger(exec); 615 606 if (end < 0) { // false for NaN 616 607 end += length; … … 628 619 int e = static_cast<int>(end); 629 620 for(int k = b; k < e; k++, n++) { 630 Value 631 if (this Imp->getProperty(exec, k, obj))632 resObj .put(exec, n, obj);633 } 634 resObj .put(exec, lengthPropertyName, Number(n), DontEnum | DontDelete);621 ValueImp *obj; 622 if (thisObj->getProperty(exec, k, obj)) 623 resObj->put(exec, n, obj); 624 } 625 resObj->put(exec, lengthPropertyName, Number(n), DontEnum | DontDelete); 635 626 break; 636 627 } … … 639 630 printf("KJS Array::Sort length=%d\n", length); 640 631 for ( unsigned int i = 0 ; i<length ; ++i ) 641 printf("KJS Array::Sort: %d: %s\n", i, thisObj .get(exec, i).toString(exec).ascii() );632 printf("KJS Array::Sort: %d: %s\n", i, thisObj->get(exec, i)->toString(exec).ascii() ); 642 633 #endif 643 Object sortFunction; 644 bool useSortFunction = (args[0].type() != UndefinedType); 645 if (useSortFunction) 634 ObjectImp *sortFunction = NULL; 635 if (!args[0]->isUndefined()) 646 636 { 647 sortFunction = args[0] .toObject(exec);648 if (!sortFunction .implementsCall())649 useSortFunction = false;650 } 651 652 if (this Imp->classInfo() == &ArrayInstanceImp::info) {653 if ( useSortFunction)654 ((ArrayInstanceImp *)this Imp)->sort(exec, sortFunction);637 sortFunction = args[0]->toObject(exec); 638 if (!sortFunction->implementsCall()) 639 sortFunction = NULL; 640 } 641 642 if (thisObj->classInfo() == &ArrayInstanceImp::info) { 643 if (sortFunction) 644 ((ArrayInstanceImp *)thisObj)->sort(exec, sortFunction); 655 645 else 656 ((ArrayInstanceImp *)this Imp)->sort(exec);646 ((ArrayInstanceImp *)thisObj)->sort(exec); 657 647 result = thisObj; 658 648 break; … … 660 650 661 651 if (length == 0) { 662 thisObj .put(exec, lengthPropertyName, Number(0), DontEnum | DontDelete);652 thisObj->put(exec, lengthPropertyName, Number(0), DontEnum | DontDelete); 663 653 result = thisObj; 664 654 break; … … 669 659 for ( unsigned int i = 0 ; i<length-1 ; ++i ) 670 660 { 671 Value iObj = thisObj.get(exec,i);661 ValueImp *iObj = thisObj->get(exec,i); 672 662 unsigned int themin = i; 673 Value 663 ValueImp *minObj = iObj; 674 664 for ( unsigned int j = i+1 ; j<length ; ++j ) 675 665 { 676 Value jObj = thisObj.get(exec,j);666 ValueImp *jObj = thisObj->get(exec,j); 677 667 double cmp; 678 if (jObj .type() == UndefinedType) {668 if (jObj->isUndefined()) { 679 669 cmp = 1; // don't check minObj because there's no need to differentiate == (0) from > (1) 680 } else if (minObj .type() == UndefinedType) {670 } else if (minObj->isUndefined()) { 681 671 cmp = -1; 682 } else if ( useSortFunction) {672 } else if (sortFunction) { 683 673 List l; 684 674 l.append(jObj); 685 675 l.append(minObj); 686 cmp = sortFunction .call(exec, exec->dynamicInterpreter()->globalObject(), l).toNumber(exec);676 cmp = sortFunction->call(exec, exec->dynamicInterpreter()->globalObject(), l)->toNumber(exec); 687 677 } else { 688 cmp = (jObj .toString(exec) < minObj.toString(exec)) ? -1 : 1;678 cmp = (jObj->toString(exec) < minObj->toString(exec)) ? -1 : 1; 689 679 } 690 680 if ( cmp < 0 ) … … 698 688 { 699 689 //printf("KJS Array::Sort: swapping %d and %d\n", i, themin ); 700 thisObj .put( exec, i, minObj );701 thisObj .put( exec, themin, iObj );690 thisObj->put( exec, i, minObj ); 691 thisObj->put( exec, themin, iObj ); 702 692 } 703 693 } … … 705 695 printf("KJS Array::Sort -- Resulting array:\n"); 706 696 for ( unsigned int i = 0 ; i<length ; ++i ) 707 printf("KJS Array::Sort: %d: %s\n", i, thisObj .get(exec, i).toString(exec).ascii() );697 printf("KJS Array::Sort: %d: %s\n", i, thisObj->get(exec, i)->toString(exec).ascii() ); 708 698 #endif 709 699 result = thisObj; … … 712 702 case Splice: { 713 703 // 15.4.4.12 - oh boy this is huge 714 Object resObj = Object::dynamicCast(exec->lexicalInterpreter()->builtinArray().construct(exec,List::empty()));704 ObjectImp *resObj = static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty())); 715 705 result = resObj; 716 int begin = args[0] .toUInt32(exec);706 int begin = args[0]->toUInt32(exec); 717 707 if ( begin < 0 ) 718 708 begin = maxInt( begin + length, 0 ); 719 709 else 720 710 begin = minInt( begin, length ); 721 unsigned int deleteCount = minInt( maxInt( args[1] .toUInt32(exec), 0 ), length - begin );711 unsigned int deleteCount = minInt( maxInt( args[1]->toUInt32(exec), 0 ), length - begin ); 722 712 723 713 //printf( "Splicing from %d, deleteCount=%d \n", begin, deleteCount ); 724 714 for(unsigned int k = 0; k < deleteCount; k++) { 725 Value 726 if (this Imp->getProperty(exec, k+begin, obj))727 resObj .put(exec, k, obj);728 } 729 resObj .put(exec, lengthPropertyName, Number(deleteCount), DontEnum | DontDelete);715 ValueImp *obj; 716 if (thisObj->getProperty(exec, k+begin, obj)) 717 resObj->put(exec, k, obj); 718 } 719 resObj->put(exec, lengthPropertyName, Number(deleteCount), DontEnum | DontDelete); 730 720 731 721 unsigned int additionalArgs = maxInt( args.size() - 2, 0 ); … … 736 726 for ( unsigned int k = begin; k < length - deleteCount; ++k ) 737 727 { 738 Value 739 if (this Imp->getProperty(exec, k+deleteCount, obj))740 thisObj .put(exec, k+additionalArgs, obj);728 ValueImp *obj; 729 if (thisObj->getProperty(exec, k+deleteCount, obj)) 730 thisObj->put(exec, k+additionalArgs, obj); 741 731 else 742 thisObj .deleteProperty(exec, k+additionalArgs);732 thisObj->deleteProperty(exec, k+additionalArgs); 743 733 } 744 734 for ( unsigned int k = length ; k > length - deleteCount + additionalArgs; --k ) 745 thisObj .deleteProperty(exec, k-1);735 thisObj->deleteProperty(exec, k-1); 746 736 } 747 737 else … … 749 739 for ( unsigned int k = length - deleteCount; (int)k > begin; --k ) 750 740 { 751 Value 752 if (this Imp->getProperty(exec, k + deleteCount - 1, obj))753 thisObj .put(exec, k + additionalArgs - 1, obj);741 ValueImp *obj; 742 if (thisObj->getProperty(exec, k + deleteCount - 1, obj)) 743 thisObj->put(exec, k + additionalArgs - 1, obj); 754 744 else 755 thisObj .deleteProperty(exec, k+additionalArgs-1);745 thisObj->deleteProperty(exec, k+additionalArgs-1); 756 746 } 757 747 } … … 759 749 for ( unsigned int k = 0; k < additionalArgs; ++k ) 760 750 { 761 thisObj .put(exec, k+begin, args[k+2]);762 } 763 thisObj .put(exec, lengthPropertyName, Number(length - deleteCount + additionalArgs), DontEnum | DontDelete);751 thisObj->put(exec, k+begin, args[k+2]); 752 } 753 thisObj->put(exec, lengthPropertyName, Number(length - deleteCount + additionalArgs), DontEnum | DontDelete); 764 754 break; 765 755 } … … 768 758 for ( unsigned int k = length; k > 0; --k ) 769 759 { 770 Value 771 if (this Imp->getProperty(exec, k - 1, obj))772 thisObj .put(exec, k+nrArgs-1, obj);760 ValueImp *obj; 761 if (thisObj->getProperty(exec, k - 1, obj)) 762 thisObj->put(exec, k+nrArgs-1, obj); 773 763 else 774 thisObj .deleteProperty(exec, k+nrArgs-1);764 thisObj->deleteProperty(exec, k+nrArgs-1); 775 765 } 776 766 for ( unsigned int k = 0; k < nrArgs; ++k ) 777 thisObj .put(exec, k, args[k]);767 thisObj->put(exec, k, args[k]); 778 768 result = Number(length + nrArgs); 779 thisObj .put(exec, lengthPropertyName, result, DontEnum | DontDelete);769 thisObj->put(exec, lengthPropertyName, result, DontEnum | DontDelete); 780 770 break; 781 771 } … … 788 778 //http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:some 789 779 790 Object eachFunction = args[0].toObject(exec);791 792 if (!eachFunction .implementsCall()) {793 Object 780 ObjectImp *eachFunction = args[0]->toObject(exec); 781 782 if (!eachFunction->implementsCall()) { 783 ObjectImp *err = Error::create(exec,TypeError); 794 784 exec->setException(err); 795 785 return err; 796 786 } 797 787 798 Object applyThis = args[1].imp()->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() : args[1].toObject(exec);788 ObjectImp *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() : args[1]->toObject(exec); 799 789 800 790 if (id == Some || id == Every) … … 807 797 List eachArguments; 808 798 809 eachArguments.append(thisObj .get(exec, k));799 eachArguments.append(thisObj->get(exec, k)); 810 800 eachArguments.append(Number(k)); 811 801 eachArguments.append(thisObj); 812 802 813 bool predicateResult = eachFunction .call(exec, applyThis, eachArguments).toBoolean(exec);803 bool predicateResult = eachFunction->call(exec, applyThis, eachArguments)->toBoolean(exec); 814 804 815 805 if (id == Every && !predicateResult) { … … 827 817 default: 828 818 assert(0); 819 result = 0; 829 820 break; 830 821 } … … 839 830 : InternalFunctionImp(funcProto) 840 831 { 841 Value protect(this);842 832 // ECMA 15.4.3.1 Array.prototype 843 put(exec,prototypePropertyName, Object(arrayProto), DontEnum|DontDelete|ReadOnly);833 put(exec,prototypePropertyName, arrayProto, DontEnum|DontDelete|ReadOnly); 844 834 845 835 // no. of arguments for constructor … … 853 843 854 844 // ECMA 15.4.2 855 Object 845 ObjectImp *ArrayObjectImp::construct(ExecState *exec, const List &args) 856 846 { 857 847 // a single numeric argument denotes the array size (!) 858 if (args.size() == 1 && args[0] .type() == NumberType) {859 uint32_t n = args[0] .toUInt32(exec);860 if (n != args[0] .toNumber(exec)) {861 Object 848 if (args.size() == 1 && args[0]->isNumber()) { 849 uint32_t n = args[0]->toUInt32(exec); 850 if (n != args[0]->toNumber(exec)) { 851 ObjectImp *error = Error::create(exec, RangeError, "Array size is not a small enough positive integer."); 862 852 exec->setException(error); 863 853 return error; 864 854 } 865 return Object(new ArrayInstanceImp(exec->lexicalInterpreter()->builtinArrayPrototype().imp(), n));855 return new ArrayInstanceImp(exec->lexicalInterpreter()->builtinArrayPrototype(), n); 866 856 } 867 857 868 858 // otherwise the array is constructed with the arguments in it 869 return Object(new ArrayInstanceImp(exec->lexicalInterpreter()->builtinArrayPrototype().imp(), args));859 return new ArrayInstanceImp(exec->lexicalInterpreter()->builtinArrayPrototype(), args); 870 860 } 871 861 … … 876 866 877 867 // ECMA 15.6.1 878 Value ArrayObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)868 ValueImp *ArrayObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 879 869 { 880 870 // equivalent to 'new Array(....)'
Note:
See TracChangeset
for help on using the changeset viewer.