Changeset 34754 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Jun 23, 2008, 10:23:17 PM (17 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 40 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ArrayPrototype.cpp
r34659 r34754 24 24 #include "config.h" 25 25 #include "ArrayPrototype.h" 26 #include "ArrayPrototype.lut.h"27 26 28 27 #include "Machine.h" … … 35 34 36 35 #include <algorithm> // for std::min 36 37 namespace KJS { 38 39 static JSValue* arrayProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&); 40 static JSValue* arrayProtoFuncToLocaleString(ExecState*, JSObject*, JSValue*, const ArgList&); 41 static JSValue* arrayProtoFuncConcat(ExecState*, JSObject*, JSValue*, const ArgList&); 42 static JSValue* arrayProtoFuncJoin(ExecState*, JSObject*, JSValue*, const ArgList&); 43 static JSValue* arrayProtoFuncPop(ExecState*, JSObject*, JSValue*, const ArgList&); 44 static JSValue* arrayProtoFuncPush(ExecState*, JSObject*, JSValue*, const ArgList&); 45 static JSValue* arrayProtoFuncReverse(ExecState*, JSObject*, JSValue*, const ArgList&); 46 static JSValue* arrayProtoFuncShift(ExecState*, JSObject*, JSValue*, const ArgList&); 47 static JSValue* arrayProtoFuncSlice(ExecState*, JSObject*, JSValue*, const ArgList&); 48 static JSValue* arrayProtoFuncSort(ExecState*, JSObject*, JSValue*, const ArgList&); 49 static JSValue* arrayProtoFuncSplice(ExecState*, JSObject*, JSValue*, const ArgList&); 50 static JSValue* arrayProtoFuncUnShift(ExecState*, JSObject*, JSValue*, const ArgList&); 51 static JSValue* arrayProtoFuncEvery(ExecState*, JSObject*, JSValue*, const ArgList&); 52 static JSValue* arrayProtoFuncForEach(ExecState*, JSObject*, JSValue*, const ArgList&); 53 static JSValue* arrayProtoFuncSome(ExecState*, JSObject*, JSValue*, const ArgList&); 54 static JSValue* arrayProtoFuncIndexOf(ExecState*, JSObject*, JSValue*, const ArgList&); 55 static JSValue* arrayProtoFuncFilter(ExecState*, JSObject*, JSValue*, const ArgList&); 56 static JSValue* arrayProtoFuncMap(ExecState*, JSObject*, JSValue*, const ArgList&); 57 static JSValue* arrayProtoFuncLastIndexOf(ExecState*, JSObject*, JSValue*, const ArgList&); 58 59 } 60 61 #include "ArrayPrototype.lut.h" 37 62 38 63 namespace KJS { … … 89 114 } 90 115 91 JSValue* arrayProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList&)92 { 93 if (!this Obj->inherits(&JSArray::info))116 JSValue* arrayProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 117 { 118 if (!thisValue->isObject(&JSArray::info)) 94 119 return throwError(exec, TypeError); 120 JSObject* thisObj = static_cast<JSArray*>(thisValue); 95 121 96 122 HashSet<JSObject*>& arrayVisitedElements = exec->dynamicGlobalObject()->arrayVisitedElements(); … … 132 158 } 133 159 134 JSValue* arrayProtoFuncToLocaleString(ExecState* exec, JSObject* thisObj, const ArgList&)135 { 136 if (!this Obj->inherits(&JSArray::info))160 JSValue* arrayProtoFuncToLocaleString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 161 { 162 if (!thisValue->isObject(&JSArray::info)) 137 163 return throwError(exec, TypeError); 164 JSObject* thisObj = static_cast<JSArray*>(thisValue); 138 165 139 166 HashSet<JSObject*>& arrayVisitedElements = exec->dynamicGlobalObject()->arrayVisitedElements(); … … 163 190 JSValue* conversionFunction = o->get(exec, exec->propertyNames().toLocaleString); 164 191 UString str; 165 if (conversionFunction->isObject() && static_cast<JSObject*>(conversionFunction)->implementsCall()) 166 str = static_cast<JSObject*>(conversionFunction)->callAsFunction(exec, o, exec->emptyList())->toString(exec); 192 CallData callData; 193 CallType callType = conversionFunction->getCallData(callData); 194 if (callType != CallTypeNone) 195 str = call(exec, conversionFunction, callType, callData, element, exec->emptyList())->toString(exec); 167 196 else 168 197 str = element->toString(exec); … … 181 210 } 182 211 183 JSValue* arrayProtoFuncJoin(ExecState* exec, JSObject* thisObj, const ArgList& args) 184 { 212 JSValue* arrayProtoFuncJoin(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 213 { 214 JSObject* thisObj = thisValue->toThisObject(exec); 215 185 216 HashSet<JSObject*>& arrayVisitedElements = exec->dynamicGlobalObject()->arrayVisitedElements(); 186 217 if (arrayVisitedElements.size() > MaxReentryDepth) … … 224 255 } 225 256 226 JSValue* arrayProtoFuncConcat(ExecState* exec, JSObject* thisObj, const ArgList& args)227 { 228 JS Object* arr = static_cast<JSObject*>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, exec->emptyList()));257 JSValue* arrayProtoFuncConcat(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 258 { 259 JSArray* arr = constructEmptyArray(exec); 229 260 int n = 0; 230 JSValue* curArg = thisObj; 231 JSObject* curObj = static_cast<JSObject* >(thisObj); 261 JSValue* curArg = thisValue->toThisObject(exec); 232 262 ArgList::const_iterator it = args.begin(); 233 263 ArgList::const_iterator end = args.end(); 234 264 while (1) { 235 if (curArg->isObject() && curObj->inherits(&JSArray::info)) { 236 unsigned k = 0; 237 // Older versions tried to optimize out getting the length of thisObj 238 // by checking for n != 0, but that doesn't work if thisObj is an empty array. 239 unsigned length = curObj->get(exec, exec->propertyNames().length)->toUInt32(exec); 240 while (k < length) { 241 if (JSValue* v = getProperty(exec, curObj, k)) 265 if (curArg->isObject(&JSArray::info)) { 266 JSArray* curArray = static_cast<JSArray*>(curArg); 267 unsigned length = curArray->getLength(); 268 for (unsigned k = 0; k < length; ++k) { 269 if (JSValue* v = curArray->getItem(k)) 242 270 arr->put(exec, n, v); 243 271 n++; 244 k++;245 272 } 246 273 } else { … … 251 278 break; 252 279 curArg = *it; 253 curObj = static_cast<JSObject*>(curArg); // may be 0254 280 ++it; 255 281 } 256 arr-> put(exec, exec->propertyNames().length, jsNumber(exec, n));282 arr->setLength(n); 257 283 return arr; 258 284 } 259 285 260 JSValue* arrayProtoFuncPop(ExecState* exec, JSObject* thisObj, const ArgList&) 261 { 286 JSValue* arrayProtoFuncPop(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 287 { 288 JSObject* thisObj = thisValue->toThisObject(exec); 262 289 JSValue* result = 0; 263 290 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); … … 273 300 } 274 301 275 JSValue* arrayProtoFuncPush(ExecState* exec, JSObject* thisObj, const ArgList& args) 276 { 302 JSValue* arrayProtoFuncPush(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 303 { 304 JSObject* thisObj = thisValue->toThisObject(exec); 277 305 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); 278 306 for (unsigned n = 0; n < args.size(); n++) … … 283 311 } 284 312 285 JSValue* arrayProtoFuncReverse(ExecState* exec, JSObject* thisObj, const ArgList&) 286 { 313 JSValue* arrayProtoFuncReverse(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 314 { 315 JSObject* thisObj = thisValue->toThisObject(exec); 287 316 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); 288 317 unsigned middle = length / 2; … … 306 335 } 307 336 308 JSValue* arrayProtoFuncShift(ExecState* exec, JSObject* thisObj, const ArgList&) 309 { 337 JSValue* arrayProtoFuncShift(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 338 { 339 JSObject* thisObj = thisValue->toThisObject(exec); 310 340 JSValue* result = 0; 311 341 … … 328 358 } 329 359 330 JSValue* arrayProtoFuncSlice(ExecState* exec, JSObject* thisObj, const ArgList& args)360 JSValue* arrayProtoFuncSlice(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 331 361 { 332 362 // http://developer.netscape.com/docs/manuals/js/client/jsref/array.htm#1193713 or 15.4.4.10 333 363 364 JSObject* thisObj = thisValue->toThisObject(exec); 365 334 366 // We return a new array 335 JS Object* resObj = static_cast<JSObject* >(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, exec->emptyList()));367 JSArray* resObj = constructEmptyArray(exec); 336 368 JSValue* result = resObj; 337 369 double begin = args[0]->toInteger(exec); … … 367 399 resObj->put(exec, n, v); 368 400 } 369 resObj-> put(exec, exec->propertyNames().length, jsNumber(exec, n));401 resObj->setLength(n); 370 402 return result; 371 403 } 372 404 373 JSValue* arrayProtoFuncSort(ExecState* exec, JSObject* thisObj, const ArgList& args) 374 { 375 JSObject* sortFunction = 0; 376 if (!args[0]->isUndefined()) { 377 sortFunction = args[0]->toObject(exec); 378 if (!sortFunction->implementsCall()) 379 sortFunction = 0; 380 } 405 JSValue* arrayProtoFuncSort(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 406 { 407 JSObject* thisObj = thisValue->toThisObject(exec); 408 409 JSValue* function = args[0]; 410 CallData callData; 411 CallType callType = function->getCallData(callData); 381 412 382 413 if (thisObj->classInfo() == &JSArray::info) { 383 if ( sortFunction)384 static_cast<JSArray*>(thisObj)->sort(exec, sortFunction);414 if (callType != CallTypeNone) 415 static_cast<JSArray*>(thisObj)->sort(exec, function, callType, callData); 385 416 else 386 417 static_cast<JSArray*>(thisObj)->sort(exec); … … 406 437 else if (minObj->isUndefined()) 407 438 compareResult = -1; 408 else if ( sortFunction) {439 else if (callType != CallTypeNone) { 409 440 ArgList l; 410 441 l.append(jObj); 411 442 l.append(minObj); 412 compareResult = sortFunction->callAsFunction(exec, exec->globalThisValue(), l)->toNumber(exec);443 compareResult = call(exec, function, callType, callData, exec->globalThisValue(), l)->toNumber(exec); 413 444 } else 414 445 compareResult = (jObj->toString(exec) < minObj->toString(exec)) ? -1 : 1; … … 428 459 } 429 460 430 JSValue* arrayProtoFuncSplice(ExecState* exec, JSObject* thisObj, const ArgList& args) 431 { 461 JSValue* arrayProtoFuncSplice(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 462 { 463 JSObject* thisObj = thisValue->toThisObject(exec); 464 432 465 // 15.4.4.12 433 JS Object* resObj = static_cast<JSObject* >(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, exec->emptyList()));466 JSArray* resObj = constructEmptyArray(exec); 434 467 JSValue* result = resObj; 435 468 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); … … 452 485 resObj->put(exec, k, v); 453 486 } 454 resObj-> put(exec, exec->propertyNames().length, jsNumber(exec, deleteCount));487 resObj->setLength(deleteCount); 455 488 456 489 unsigned additionalArgs = std::max<int>(args.size() - 2, 0); … … 481 514 } 482 515 483 JSValue* arrayProtoFuncUnShift(ExecState* exec, JSObject* thisObj, const ArgList& args) 484 { 516 JSValue* arrayProtoFuncUnShift(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 517 { 518 JSObject* thisObj = thisValue->toThisObject(exec); 519 485 520 // 15.4.4.13 486 521 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); … … 501 536 } 502 537 503 JSValue* arrayProtoFuncFilter(ExecState* exec, JSObject* thisObj, const ArgList& args) 504 { 505 JSObject* eachFunction = args[0]->toObject(exec); 506 507 if (!eachFunction->implementsCall()) 538 JSValue* arrayProtoFuncFilter(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 539 { 540 JSObject* thisObj = thisValue->toThisObject(exec); 541 542 JSValue* function = args[0]; 543 CallData callData; 544 CallType callType = function->getCallData(callData); 545 if (callType == CallTypeNone) 508 546 return throwError(exec, TypeError); 509 547 510 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : 511 JS Object* resultArray = static_cast<JSObject*>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, exec->emptyList()));548 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec); 549 JSArray* resultArray = constructEmptyArray(exec); 512 550 513 551 unsigned filterIndex = 0; … … 527 565 eachArguments.append(thisObj); 528 566 529 JSValue* result = eachFunction->callAsFunction(exec, applyThis, eachArguments);567 JSValue* result = call(exec, function, callType, callData, applyThis, eachArguments); 530 568 531 569 if (result->toBoolean(exec)) … … 535 573 } 536 574 537 JSValue* arrayProtoFuncMap(ExecState* exec, JSObject* thisObj, const ArgList& args) 538 { 539 JSObject* eachFunction = args[0]->toObject(exec); 540 if (!eachFunction->implementsCall()) 575 JSValue* arrayProtoFuncMap(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 576 { 577 JSObject* thisObj = thisValue->toThisObject(exec); 578 579 JSValue* function = args[0]; 580 CallData callData; 581 CallType callType = function->getCallData(callData); 582 if (callType == CallTypeNone) 541 583 return throwError(exec, TypeError); 542 584 543 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec); 544 545 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); 546 547 ArgList mapArgs; 548 mapArgs.append(jsNumber(exec, length)); 549 JSObject* resultArray = static_cast<JSObject*>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, mapArgs)); 585 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec); 586 587 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); 588 589 JSArray* resultArray = constructEmptyArray(exec, length); 550 590 551 591 for (unsigned k = 0; k < length && !exec->hadException(); ++k) { … … 562 602 eachArguments.append(thisObj); 563 603 564 JSValue* result = eachFunction->callAsFunction(exec, applyThis, eachArguments);604 JSValue* result = call(exec, function, callType, callData, applyThis, eachArguments); 565 605 resultArray->put(exec, k, result); 566 606 } … … 574 614 // http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:some 575 615 576 JSValue* arrayProtoFuncEvery(ExecState* exec, JSObject* thisObj, const ArgList& args) 577 { 578 JSObject* eachFunction = args[0]->toObject(exec); 579 580 if (!eachFunction->implementsCall()) 616 JSValue* arrayProtoFuncEvery(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 617 { 618 JSObject* thisObj = thisValue->toThisObject(exec); 619 620 JSValue* function = args[0]; 621 CallData callData; 622 CallType callType = function->getCallData(callData); 623 if (callType == CallTypeNone) 581 624 return throwError(exec, TypeError); 582 625 583 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : 626 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec); 584 627 585 628 JSValue* result = jsBoolean(true); … … 598 641 eachArguments.append(thisObj); 599 642 600 bool predicateResult = eachFunction->callAsFunction(exec, applyThis, eachArguments)->toBoolean(exec);643 bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean(exec); 601 644 602 645 if (!predicateResult) { … … 609 652 } 610 653 611 JSValue* arrayProtoFuncForEach(ExecState* exec, JSObject* thisObj, const ArgList& args) 612 { 613 JSObject* eachFunction = args[0]->toObject(exec); 614 615 if (!eachFunction->implementsCall()) 654 JSValue* arrayProtoFuncForEach(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 655 { 656 JSObject* thisObj = thisValue->toThisObject(exec); 657 658 JSValue* function = args[0]; 659 CallData callData; 660 CallType callType = function->getCallData(callData); 661 if (callType == CallTypeNone) 616 662 return throwError(exec, TypeError); 617 663 618 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : 664 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec); 619 665 620 666 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); … … 629 675 eachArguments.append(thisObj); 630 676 631 eachFunction->callAsFunction(exec, applyThis, eachArguments);677 call(exec, function, callType, callData, applyThis, eachArguments); 632 678 } 633 679 return jsUndefined(); 634 680 } 635 681 636 JSValue* arrayProtoFuncSome(ExecState* exec, JSObject* thisObj, const ArgList& args) 637 { 638 JSObject* eachFunction = args[0]->toObject(exec); 639 640 if (!eachFunction->implementsCall()) 682 JSValue* arrayProtoFuncSome(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 683 { 684 JSObject* thisObj = thisValue->toThisObject(exec); 685 686 JSValue* function = args[0]; 687 CallData callData; 688 CallType callType = function->getCallData(callData); 689 if (callType == CallTypeNone) 641 690 return throwError(exec, TypeError); 642 691 643 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : 692 JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->globalThisValue() : args[1]->toObject(exec); 644 693 645 694 JSValue* result = jsBoolean(false); … … 656 705 eachArguments.append(thisObj); 657 706 658 bool predicateResult = eachFunction->callAsFunction(exec, applyThis, eachArguments)->toBoolean(exec);707 bool predicateResult = call(exec, function, callType, callData, applyThis, eachArguments)->toBoolean(exec); 659 708 660 709 if (predicateResult) { … … 666 715 } 667 716 668 JSValue* arrayProtoFuncIndexOf(ExecState* exec, JSObject* thisObj, const ArgList& args)717 JSValue* arrayProtoFuncIndexOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 669 718 { 670 719 // JavaScript 1.5 Extension by Mozilla 671 720 // Documentation: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:indexOf 721 722 JSObject* thisObj = thisValue->toThisObject(exec); 672 723 673 724 unsigned index = 0; … … 695 746 } 696 747 697 JSValue* arrayProtoFuncLastIndexOf(ExecState* exec, JSObject* thisObj, const ArgList& args)748 JSValue* arrayProtoFuncLastIndexOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 698 749 { 699 750 // JavaScript 1.6 Extension by Mozilla 700 751 // Documentation: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:lastIndexOf 752 753 JSObject* thisObj = thisValue->toThisObject(exec); 701 754 702 755 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); … … 733 786 734 787 // no. of arguments for constructor 735 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum); 736 } 737 738 ConstructType ArrayConstructor::getConstructData(ConstructData&) 739 { 740 return ConstructTypeNative; 741 } 742 743 // ECMA 15.4.2 744 JSObject* ArrayConstructor::construct(ExecState* exec, const ArgList& args) 788 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete); 789 } 790 791 static JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgList& args) 745 792 { 746 793 // a single numeric argument denotes the array size (!) … … 756 803 } 757 804 805 static JSObject* constructWithArrayConstructor(ExecState* exec, JSObject*, const ArgList& args) 806 { 807 return constructArrayWithSizeQuirk(exec, args); 808 } 809 810 // ECMA 15.4.2 811 ConstructType ArrayConstructor::getConstructData(ConstructData& constructData) 812 { 813 constructData.native.function = constructWithArrayConstructor; 814 return ConstructTypeNative; 815 } 816 817 static JSValue* callArrayConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 818 { 819 return constructArrayWithSizeQuirk(exec, args); 820 } 821 758 822 // ECMA 15.6.1 759 JSValue* ArrayConstructor::callAsFunction(ExecState* exec, JSObject*, const ArgList& args)823 CallType ArrayConstructor::getCallData(CallData& callData) 760 824 { 761 825 // equivalent to 'new Array(....)' 762 return construct(exec, args); 763 } 764 765 } 826 callData.native.function = callArrayConstructor; 827 return CallTypeNative; 828 } 829 830 } -
trunk/JavaScriptCore/kjs/ArrayPrototype.h
r34587 r34754 40 40 public: 41 41 ArrayConstructor(ExecState*, FunctionPrototype*, ArrayPrototype*); 42 43 42 virtual ConstructType getConstructData(ConstructData&); 44 virtual JSObject* construct(ExecState*, const ArgList&); 45 46 virtual JSValue* callAsFunction(ExecState*, JSObject*, const ArgList&); 47 43 virtual CallType getCallData(CallData&); 48 44 }; 49 50 JSValue* arrayProtoFuncToString(ExecState*, JSObject*, const ArgList&);51 JSValue* arrayProtoFuncToLocaleString(ExecState*, JSObject*, const ArgList&);52 JSValue* arrayProtoFuncConcat(ExecState*, JSObject*, const ArgList&);53 JSValue* arrayProtoFuncJoin(ExecState*, JSObject*, const ArgList&);54 JSValue* arrayProtoFuncPop(ExecState*, JSObject*, const ArgList&);55 JSValue* arrayProtoFuncPush(ExecState*, JSObject*, const ArgList&);56 JSValue* arrayProtoFuncReverse(ExecState*, JSObject*, const ArgList&);57 JSValue* arrayProtoFuncShift(ExecState*, JSObject*, const ArgList&);58 JSValue* arrayProtoFuncSlice(ExecState*, JSObject*, const ArgList&);59 JSValue* arrayProtoFuncSort(ExecState*, JSObject*, const ArgList&);60 JSValue* arrayProtoFuncSplice(ExecState*, JSObject*, const ArgList&);61 JSValue* arrayProtoFuncUnShift(ExecState*, JSObject*, const ArgList&);62 JSValue* arrayProtoFuncEvery(ExecState*, JSObject*, const ArgList&);63 JSValue* arrayProtoFuncForEach(ExecState*, JSObject*, const ArgList&);64 JSValue* arrayProtoFuncSome(ExecState*, JSObject*, const ArgList&);65 JSValue* arrayProtoFuncIndexOf(ExecState*, JSObject*, const ArgList&);66 JSValue* arrayProtoFuncFilter(ExecState*, JSObject*, const ArgList&);67 JSValue* arrayProtoFuncMap(ExecState*, JSObject*, const ArgList&);68 JSValue* arrayProtoFuncLastIndexOf(ExecState*, JSObject*, const ArgList&);69 45 70 46 } // namespace KJS -
trunk/JavaScriptCore/kjs/BooleanObject.cpp
r34659 r34754 41 41 42 42 // Functions 43 static JSValue* booleanProtoFuncToString(ExecState*, JSObject*, const ArgList&);44 static JSValue* booleanProtoFuncValueOf(ExecState*, JSObject*, const ArgList&);43 static JSValue* booleanProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&); 44 static JSValue* booleanProtoFuncValueOf(ExecState*, JSObject*, JSValue*, const ArgList&); 45 45 46 46 // ECMA 15.6.4 … … 60 60 // ECMA 15.6.4.2 + 15.6.4.3 61 61 62 JSValue* booleanProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList&)62 JSValue* booleanProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 63 63 { 64 if (!thisObj->inherits(&BooleanObject::info)) 64 if (JSImmediate::isBoolean(thisValue)) 65 return jsString(exec, JSImmediate::toString(thisValue)); 66 67 if (!thisValue->isObject(&BooleanObject::info)) 65 68 return throwError(exec, TypeError); 66 69 67 JSValue* v = static_cast<BooleanObject*>(thisObj)->internalValue();68 ASSERT(v); 70 return jsString(exec, JSImmediate::toString(static_cast<BooleanObject*>(thisValue)->internalValue())); 71 } 69 72 70 return jsString(exec, v->toString(exec)); 71 } 72 JSValue* booleanProtoFuncValueOf(ExecState* exec, JSObject* thisObj, const ArgList&) 73 JSValue* booleanProtoFuncValueOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 73 74 { 74 if (!thisObj->inherits(&BooleanObject::info)) 75 if (JSImmediate::isBoolean(thisValue)) 76 return thisValue; 77 78 if (!thisValue->isObject(&BooleanObject::info)) 75 79 return throwError(exec, TypeError); 76 80 77 JSValue* v = static_cast<BooleanObject*>(thisObj)->internalValue(); 78 ASSERT(v); 79 80 // TODO: optimize for bool case 81 return jsBoolean(v->toBoolean(exec)); 81 return static_cast<BooleanObject*>(thisValue)->internalValue(); 82 82 } 83 83 … … 94 94 } 95 95 96 ConstructType BooleanConstructor::getConstructData(ConstructData&) 96 // ECMA 15.6.2 97 JSObject* constructBoolean(ExecState* exec, const ArgList& args) 97 98 { 98 return ConstructTypeNative; 99 } 100 101 // ECMA 15.6.2 102 JSObject* BooleanConstructor::construct(ExecState* exec, const ArgList& args) 103 { 104 BooleanObject* obj(new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanPrototype())); 99 BooleanObject* obj = new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanPrototype()); 105 100 obj->setInternalValue(jsBoolean(args[0]->toBoolean(exec))); 106 101 return obj; 107 102 } 108 103 104 static JSObject* constructWithBooleanConstructor(ExecState* exec, JSObject*, const ArgList& args) 105 { 106 return constructBoolean(exec, args); 107 } 108 109 ConstructType BooleanConstructor::getConstructData(ConstructData& constructData) 110 { 111 constructData.native.function = constructWithBooleanConstructor; 112 return ConstructTypeNative; 113 } 114 109 115 // ECMA 15.6.1 110 JSValue* BooleanConstructor::callAsFunction(ExecState* exec, JSObject*, const ArgList& args)116 static JSValue* callBooleanConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 111 117 { 112 // TODO: optimize for bool case113 118 return jsBoolean(args[0]->toBoolean(exec)); 114 119 } 115 120 121 CallType BooleanConstructor::getCallData(CallData& callData) 122 { 123 callData.native.function = callBooleanConstructor; 124 return CallTypeNative; 125 } 126 127 JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSValue* immediateBooleanValue) 128 { 129 BooleanObject* obj = new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanPrototype()); 130 obj->setInternalValue(immediateBooleanValue); 131 return obj; 132 } 133 116 134 } // namespace KJS -
trunk/JavaScriptCore/kjs/BooleanObject.h
r34587 r34754 54 54 public: 55 55 BooleanConstructor(ExecState*, FunctionPrototype*, BooleanPrototype*); 56 private: 57 virtual ConstructType getConstructData(ConstructData&); 58 virtual CallType getCallData(CallData&); 59 }; 56 60 57 virtual ConstructType getConstructData(ConstructData&); 58 virtual JSObject* construct(ExecState*, const ArgList&); 59 60 virtual JSValue* callAsFunction(ExecState*, JSObject*, const ArgList&); 61 }; 61 JSObject* constructBooleanFromImmediateBoolean(ExecState*, JSValue*); 62 JSObject* constructBoolean(ExecState*, const ArgList&); 62 63 63 64 } // namespace KJS -
trunk/JavaScriptCore/kjs/CallData.h
r34372 r34754 32 32 namespace KJS { 33 33 34 class ArgList; 35 class ExecState; 34 36 class FunctionBodyNode; 37 class JSObject; 38 class JSValue; 35 39 class ScopeChainNode; 36 40 … … 41 45 }; 42 46 47 typedef JSValue* (*NativeFunction)(ExecState*, JSObject*, JSValue* thisValue, const ArgList&); 48 43 49 union CallData { 50 struct { 51 NativeFunction function; 52 } native; 44 53 struct { 45 54 FunctionBodyNode* functionBody; … … 48 57 }; 49 58 59 JSValue* call(ExecState*, JSValue* functionObject, CallType, const CallData&, JSValue* thisValue, const ArgList&); 60 50 61 } // namespace KJS 51 62 -
trunk/JavaScriptCore/kjs/ConstructData.h
r33979 r34754 32 32 namespace KJS { 33 33 34 class ArgList; 35 class ExecState; 34 36 class FunctionBodyNode; 35 class ScopeChain; 37 class JSObject; 38 class JSValue; 39 class ScopeChainNode; 36 40 37 41 enum ConstructType { … … 41 45 }; 42 46 47 typedef JSObject* (*NativeConstructor)(ExecState*, JSObject*, const ArgList&); 48 43 49 union ConstructData { 50 struct { 51 NativeConstructor function; 52 } native; 44 53 struct { 45 54 FunctionBodyNode* functionBody; … … 48 57 }; 49 58 59 JSObject* construct(ExecState*, JSValue* constructor, ConstructType, const ConstructData&, const ArgList&); 60 50 61 } // namespace KJS 51 62 -
trunk/JavaScriptCore/kjs/FunctionPrototype.cpp
r34659 r34754 39 39 // ------------------------------ FunctionPrototype ------------------------- 40 40 41 static JSValue* functionProtoFuncToString(ExecState*, JSObject*, const ArgList&);42 static JSValue* functionProtoFuncApply(ExecState*, JSObject*, const ArgList&);43 static JSValue* functionProtoFuncCall(ExecState*, JSObject*, const ArgList&);41 static JSValue* functionProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&); 42 static JSValue* functionProtoFuncApply(ExecState*, JSObject*, JSValue*, const ArgList&); 43 static JSValue* functionProtoFuncCall(ExecState*, JSObject*, JSValue*, const ArgList&); 44 44 45 45 FunctionPrototype::FunctionPrototype(ExecState* exec) … … 52 52 } 53 53 54 static JSValue* callFunctionPrototype(ExecState*, JSObject*, JSValue*, const ArgList&) 55 { 56 return jsUndefined(); 57 } 58 54 59 // ECMA 15.3.4 55 JSValue* FunctionPrototype::callAsFunction(ExecState*, JSObject*, const ArgList&) 56 { 57 return jsUndefined(); 60 CallType FunctionPrototype::getCallData(CallData& callData) 61 { 62 callData.native.function = callFunctionPrototype; 63 return CallTypeNative; 58 64 } 59 65 60 66 // Functions 61 67 62 JSValue* functionProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList&) 63 { 64 if (!thisObj || !thisObj->inherits(&InternalFunction::info)) { 65 #ifndef NDEBUG 66 fprintf(stderr,"attempted toString() call on null or non-function object\n"); 67 #endif 68 JSValue* functionProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 69 { 70 if (!thisValue->isObject(&InternalFunction::info)) 68 71 return throwError(exec, TypeError); 69 } 70 71 if (thisObj->inherits(&JSFunction::info)) { 72 JSFunction* fi = static_cast<JSFunction*>(thisObj); 72 73 InternalFunction* function = static_cast<InternalFunction*>(thisValue); 74 75 if (function->inherits(&JSFunction::info)) { 76 JSFunction* fi = static_cast<JSFunction*>(thisValue); 73 77 return jsString(exec, "function " + fi->functionName().ustring() + "(" + fi->body->paramString() + ") " + fi->body->toSourceString()); 74 78 } 75 79 76 return jsString(exec, "function " + static_cast<InternalFunction*>(thisObj)->functionName().ustring() + "() {\n [native code]\n}"); 77 } 78 79 JSValue* functionProtoFuncApply(ExecState* exec, JSObject* thisObj, const ArgList& args) 80 { 81 if (!thisObj->implementsCall()) 80 return jsString(exec, "function " + function->functionName().ustring() + "() {\n [native code]\n}"); 81 } 82 83 JSValue* functionProtoFuncApply(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 84 { 85 CallData callData; 86 CallType callType = thisValue->getCallData(callData); 87 if (callType == CallTypeNone) 82 88 return throwError(exec, TypeError); 83 89 … … 85 91 JSValue* argArray = args[1]; 86 92 87 JS Object* applyThis;93 JSValue* applyThis; 88 94 if (thisArg->isUndefinedOrNull()) 89 95 applyThis = exec->globalThisValue(); … … 105 111 } 106 112 107 return thisObj->callAsFunction(exec, applyThis, applyArgs); 108 } 109 110 JSValue* functionProtoFuncCall(ExecState* exec, JSObject* thisObj, const ArgList& args) 111 { 112 if (!thisObj->implementsCall()) 113 return call(exec, thisValue, callType, callData, applyThis, applyArgs); 114 } 115 116 JSValue* functionProtoFuncCall(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 117 { 118 CallData callData; 119 CallType callType = thisValue->getCallData(callData); 120 if (callType == CallTypeNone) 113 121 return throwError(exec, TypeError); 114 122 … … 123 131 ArgList argsTail; 124 132 args.getSlice(1, argsTail); 125 return thisObj->callAsFunction(exec, callThis, argsTail);133 return call(exec, thisValue, callType, callData, callThis, argsTail); 126 134 } 127 135 … … 137 145 } 138 146 139 ConstructType FunctionConstructor::getConstructData(ConstructData&) 140 { 147 static JSObject* constructWithFunctionConstructor(ExecState* exec, JSObject*, const ArgList& args) 148 { 149 return constructFunction(exec, args); 150 } 151 152 ConstructType FunctionConstructor::getConstructData(ConstructData& constructData) 153 { 154 constructData.native.function = constructWithFunctionConstructor; 141 155 return ConstructTypeNative; 142 156 } 143 157 158 static JSValue* callFunctionConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 159 { 160 return constructFunction(exec, args); 161 } 162 163 // ECMA 15.3.1 The Function Constructor Called as a Function 164 CallType FunctionConstructor::getCallData(CallData& callData) 165 { 166 callData.native.function = callFunctionConstructor; 167 return CallTypeNative; 168 } 169 144 170 // ECMA 15.3.2 The Function Constructor 145 JSObject* FunctionConstructor::construct(ExecState* exec, const ArgList& args, const Identifier& functionName, const UString& sourceURL, int lineNumber)171 JSObject* constructFunction(ExecState* exec, const ArgList& args, const Identifier& functionName, const UString& sourceURL, int lineNumber) 146 172 { 147 173 UString p(""); … … 175 201 ScopeChain scopeChain(exec->lexicalGlobalObject(), exec->globalThisValue()); 176 202 177 JSFunction* f imp= new (exec) JSFunction(exec, functionName, functionBody.get(), scopeChain.node());203 JSFunction* function = new (exec) JSFunction(exec, functionName, functionBody.get(), scopeChain.node()); 178 204 179 205 // parse parameter list. throw syntax error on illegal identifiers … … 208 234 } 209 235 210 JSObject* objCons = exec->lexicalGlobalObject()->objectConstructor(); 211 JSObject* prototype = objCons->construct(exec, exec->emptyList()); 212 prototype->putDirect(exec->propertyNames().constructor, fimp, DontEnum); 213 fimp->putDirect(exec->propertyNames().prototype, prototype, DontDelete); 214 return fimp; 236 JSObject* prototype = constructEmptyObject(exec); 237 prototype->putDirect(exec->propertyNames().constructor, function, DontEnum); 238 function->putDirect(exec->propertyNames().prototype, prototype, DontDelete); 239 return function; 215 240 } 216 241 217 242 // ECMA 15.3.2 The Function Constructor 218 JSObject* FunctionConstructor::construct(ExecState* exec, const ArgList& args) 219 { 220 return construct(exec, args, Identifier(exec, "anonymous"), UString(), 1); 221 } 222 223 // ECMA 15.3.1 The Function Constructor Called as a Function 224 JSValue* FunctionConstructor::callAsFunction(ExecState* exec, JSObject*, const ArgList& args) 225 { 226 return construct(exec, args); 243 JSObject* constructFunction(ExecState* exec, const ArgList& args) 244 { 245 return constructFunction(exec, args, Identifier(exec, "anonymous"), UString(), 1); 227 246 } 228 247 -
trunk/JavaScriptCore/kjs/FunctionPrototype.h
r34587 r34754 38 38 public: 39 39 FunctionPrototype(ExecState*); 40 41 virtual JSValue* callAsFunction(ExecState*, JSObject*, const ArgList&);40 private: 41 virtual CallType getCallData(CallData&); 42 42 }; 43 43 … … 50 50 public: 51 51 FunctionConstructor(ExecState*, FunctionPrototype*); 52 private: 53 virtual ConstructType getConstructData(ConstructData&); 54 virtual CallType getCallData(CallData&); 55 }; 52 56 53 virtual ConstructType getConstructData(ConstructData&); 54 virtual JSObject* construct(ExecState*, const ArgList&); 55 virtual JSObject* construct(ExecState*, const ArgList&, const Identifier& functionName, const UString& sourceURL, int lineNumber); 56 57 virtual JSValue* callAsFunction(ExecState*, JSObject*, const ArgList&); 58 }; 57 JSObject* constructFunction(ExecState*, const ArgList&, const Identifier& functionName, const UString& sourceURL, int lineNumber); 58 JSObject* constructFunction(ExecState*, const ArgList&); 59 59 60 60 } // namespace KJS -
trunk/JavaScriptCore/kjs/JSArray.cpp
r34659 r34754 24 24 #include "JSArray.h" 25 25 26 #include "ArrayPrototype.h" 26 27 #include "PropertyNameArray.h" 27 28 #include <wtf/Assertions.h> … … 558 559 Vector<AVLTreeNodeForArrayCompare> m_nodes; 559 560 ExecState* m_exec; 560 JSObject* m_compareFunction; 561 JSObject* m_globalThisValue; 561 JSValue* m_compareFunction; 562 CallType m_compareCallType; 563 const CallData* m_compareCallData; 564 JSValue* m_globalThisValue; 562 565 563 566 handle get_less(handle h) { return m_nodes[h].lt & 0x7FFFFFFF; } … … 596 599 arguments.append(va); 597 600 arguments.append(vb); 598 double compareResult = m_compareFunction->callAsFunction(m_exec, m_globalThisValue, arguments)->toNumber(m_exec);601 double compareResult = call(m_exec, m_compareFunction, m_compareCallType, *m_compareCallData, m_globalThisValue, arguments)->toNumber(m_exec); 599 602 return (compareResult < 0) ? -1 : 1; // Not passing equality through, because we need to store all values, even if equivalent. 600 603 } … … 606 609 }; 607 610 608 void JSArray::sort(ExecState* exec, JS Object* compareFunction)611 void JSArray::sort(ExecState* exec, JSValue* compareFunction, CallType callType, const CallData& callData) 609 612 { 610 613 checkConsistency(); … … 626 629 tree.abstractor().m_exec = exec; 627 630 tree.abstractor().m_compareFunction = compareFunction; 631 tree.abstractor().m_compareCallType = callType; 632 tree.abstractor().m_compareCallData = &callData; 628 633 tree.abstractor().m_globalThisValue = exec->globalThisValue(); 629 634 tree.abstractor().m_nodes.resize(usedVectorLength + (m_storage->m_sparseValueMap ? m_storage->m_sparseValueMap->size() : 0)); … … 811 816 #endif 812 817 813 } 818 JSArray* constructEmptyArray(ExecState* exec) 819 { 820 return new (exec) JSArray(exec->lexicalGlobalObject()->arrayPrototype(), 0); 821 } 822 823 JSArray* constructEmptyArray(ExecState* exec, unsigned initialLength) 824 { 825 return new (exec) JSArray(exec->lexicalGlobalObject()->arrayPrototype(), initialLength); 826 } 827 828 JSArray* constructArray(ExecState* exec, JSValue* singleItemValue) 829 { 830 ArgList values; 831 values.append(singleItemValue); 832 return new (exec) JSArray(exec->lexicalGlobalObject()->arrayPrototype(), values); 833 } 834 835 JSArray* constructArray(ExecState* exec, const ArgList& values) 836 { 837 return new (exec) JSArray(exec->lexicalGlobalObject()->arrayPrototype(), values); 838 } 839 840 } -
trunk/JavaScriptCore/kjs/JSArray.h
r34587 r34754 33 33 JSArray(JSObject* prototype, unsigned initialLength); 34 34 JSArray(JSObject* prototype, const ArgList& initialValues); 35 ~JSArray();35 virtual ~JSArray(); 36 36 37 37 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); 38 38 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); 39 virtual void put(ExecState*, const Identifier& propertyName, JSValue*); 40 virtual void put(ExecState*, unsigned propertyName, JSValue*); 41 virtual bool deleteProperty(ExecState *, const Identifier& propertyName); 42 virtual bool deleteProperty(ExecState *, unsigned propertyName); 43 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 39 virtual void put(ExecState*, unsigned propertyName, JSValue*); // FIXME: Make protected and add setItem. 44 40 45 virtual void mark();46 47 virtual const ClassInfo* classInfo() const { return &info; }48 41 static const ClassInfo info; 49 42 50 43 unsigned getLength() const { return m_length; } 44 void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray. 51 45 JSValue* getItem(unsigned) const; 52 46 53 47 void sort(ExecState*); 54 void sort(ExecState*, JS Object* compareFunction);48 void sort(ExecState*, JSValue* compareFunction, CallType, const CallData&); 55 49 56 50 protected: 51 virtual void put(ExecState*, const Identifier& propertyName, JSValue*); 52 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 53 virtual bool deleteProperty(ExecState*, unsigned propertyName); 54 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 55 virtual void mark(); 56 57 57 void* lazyCreationData(); 58 58 void setLazyCreationData(void*); 59 59 60 60 private: 61 using JSObject::get; 62 63 virtual const ClassInfo* classInfo() const { return &info; } 64 61 65 static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&); 62 66 bool inlineGetOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); 63 67 64 void setLength(unsigned);65 68 bool increaseVectorLength(unsigned newLength); 66 69 … … 75 78 }; 76 79 80 JSArray* constructEmptyArray(ExecState*); 81 JSArray* constructEmptyArray(ExecState*, unsigned initialLength); 82 JSArray* constructArray(ExecState*, JSValue* singleItemValue); 83 JSArray* constructArray(ExecState*, const ArgList& values); 84 77 85 } // namespace KJS 78 86 -
trunk/JavaScriptCore/kjs/JSFunction.cpp
r34684 r34754 81 81 } 82 82 83 JSValue* JSFunction::call AsFunction(ExecState* exec, JSObject* thisObj, const ArgList& args)83 JSValue* JSFunction::call(ExecState* exec, JSValue* thisValue, const ArgList& args) 84 84 { 85 85 JSValue* exception = 0; … … 88 88 if (!current->safeForReentry()) { 89 89 stack->pushFunctionRegisterFile(); 90 JSValue* result = exec->machine()->execute(body.get(), exec, this, this Obj, args, stack, _scope.node(), &exception);90 JSValue* result = exec->machine()->execute(body.get(), exec, this, thisValue->toThisObject(exec), args, stack, _scope.node(), &exception); 91 91 stack->popFunctionRegisterFile(); 92 92 exec->setException(exception); 93 93 return result; 94 94 } else { 95 JSValue* result = exec->machine()->execute(body.get(), exec, this, this Obj, args, stack, _scope.node(), &exception);95 JSValue* result = exec->machine()->execute(body.get(), exec, this, thisValue->toThisObject(exec), args, stack, _scope.node(), &exception); 96 96 current->setSafeForReentry(true); 97 97 exec->setException(exception); … … 159 159 * function f2(x, x): getParameterName(0) --> null 160 160 */ 161 IdentifierJSFunction::getParameterName(int index)161 const Identifier& JSFunction::getParameterName(int index) 162 162 { 163 163 Vector<Identifier>& parameters = body->parameters(); … … 166 166 return JSGlobalData::threadInstance().propertyNames->nullIdentifier; 167 167 168 Identifiername = parameters[index];168 const Identifier& name = parameters[index]; 169 169 170 170 // Are there any subsequent parameters with the same name? … … 556 556 } 557 557 558 JSValue* globalFuncEval(ExecState* exec, PrototypeReflexiveFunction* function, JSObject* thisObj, const ArgList& args)559 { 560 JS GlobalObject* globalObject = thisObj->toGlobalObject(exec);561 558 JSValue* globalFuncEval(ExecState* exec, JSObject* function, JSValue* thisValue, const ArgList& args) 559 { 560 JSObject* thisObject = thisValue->toThisObject(exec); 561 JSGlobalObject* globalObject = thisObject->toGlobalObject(exec); 562 562 if (!globalObject || globalObject->evalFunction() != function) 563 563 return throwError(exec, EvalError, "The \"this\" value passed to eval must be the global object from which eval originated"); … … 579 579 580 580 JSValue* exception = 0; 581 JSValue* value = exec->machine()->execute(evalNode.get(), exec, thisObj , &exec->dynamicGlobalObject()->registerFileStack(), globalObject->globalScopeChain().node(), &exception);581 JSValue* value = exec->machine()->execute(evalNode.get(), exec, thisObject, &exec->dynamicGlobalObject()->registerFileStack(), globalObject->globalScopeChain().node(), &exception); 582 582 583 583 if (exception) { … … 589 589 } 590 590 591 JSValue* globalFuncParseInt(ExecState* exec, JSObject*, const ArgList& args)591 JSValue* globalFuncParseInt(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 592 592 { 593 593 return jsNumber(exec, parseInt(args[0]->toString(exec), args[1]->toInt32(exec))); 594 594 } 595 595 596 JSValue* globalFuncParseFloat(ExecState* exec, JSObject*, const ArgList& args)596 JSValue* globalFuncParseFloat(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 597 597 { 598 598 return jsNumber(exec, parseFloat(args[0]->toString(exec))); 599 599 } 600 600 601 JSValue* globalFuncIsNaN(ExecState* exec, JSObject*, const ArgList& args)601 JSValue* globalFuncIsNaN(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 602 602 { 603 603 return jsBoolean(isnan(args[0]->toNumber(exec))); 604 604 } 605 605 606 JSValue* globalFuncIsFinite(ExecState* exec, JSObject*, const ArgList& args)606 JSValue* globalFuncIsFinite(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 607 607 { 608 608 double n = args[0]->toNumber(exec); … … 610 610 } 611 611 612 JSValue* globalFuncDecodeURI(ExecState* exec, JSObject*, const ArgList& args)612 JSValue* globalFuncDecodeURI(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 613 613 { 614 614 static const char do_not_unescape_when_decoding_URI[] = … … 618 618 } 619 619 620 JSValue* globalFuncDecodeURIComponent(ExecState* exec, JSObject*, const ArgList& args)620 JSValue* globalFuncDecodeURIComponent(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 621 621 { 622 622 return decode(exec, args, "", true); 623 623 } 624 624 625 JSValue* globalFuncEncodeURI(ExecState* exec, JSObject*, const ArgList& args)625 JSValue* globalFuncEncodeURI(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 626 626 { 627 627 static const char do_not_escape_when_encoding_URI[] = … … 634 634 } 635 635 636 JSValue* globalFuncEncodeURIComponent(ExecState* exec, JSObject*, const ArgList& args)636 JSValue* globalFuncEncodeURIComponent(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 637 637 { 638 638 static const char do_not_escape_when_encoding_URI_component[] = … … 645 645 } 646 646 647 JSValue* globalFuncEscape(ExecState* exec, JSObject*, const ArgList& args)647 JSValue* globalFuncEscape(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 648 648 { 649 649 static const char do_not_escape[] = … … 674 674 } 675 675 676 JSValue* globalFuncUnescape(ExecState* exec, JSObject*, const ArgList& args)676 JSValue* globalFuncUnescape(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 677 677 { 678 678 UString s = "", str = args[0]->toString(exec); … … 700 700 701 701 #ifndef NDEBUG 702 JSValue* globalFuncKJSPrint(ExecState* exec, JSObject*, const ArgList& args)702 JSValue* globalFuncKJSPrint(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 703 703 { 704 704 CStringBuffer string; … … 711 711 // ------------------------------ PrototypeFunction ------------------------------- 712 712 713 PrototypeFunction::PrototypeFunction(ExecState* exec, int len, const Identifier& name, JSMemberFunction function)713 PrototypeFunction::PrototypeFunction(ExecState* exec, int len, const Identifier& name, NativeFunction function) 714 714 : InternalFunction(exec->lexicalGlobalObject()->functionPrototype(), name) 715 715 , m_function(function) … … 719 719 } 720 720 721 PrototypeFunction::PrototypeFunction(ExecState* exec, FunctionPrototype* functionPrototype, int len, const Identifier& name, JSMemberFunction function)721 PrototypeFunction::PrototypeFunction(ExecState* exec, FunctionPrototype* functionPrototype, int len, const Identifier& name, NativeFunction function) 722 722 : InternalFunction(functionPrototype, name) 723 723 , m_function(function) … … 727 727 } 728 728 729 JSValue* PrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const ArgList& args) 730 { 731 return m_function(exec, thisObj, args); 729 CallType PrototypeFunction::getCallData(CallData& callData) 730 { 731 callData.native.function = m_function; 732 return CallTypeNative; 732 733 } 733 734 734 735 // ------------------------------ PrototypeReflexiveFunction ------------------------------- 735 736 736 PrototypeReflexiveFunction::PrototypeReflexiveFunction(ExecState* exec, FunctionPrototype* functionPrototype, int len, const Identifier& name, JSMemberFunction function, JSGlobalObject* cachedGlobalObject) 737 : InternalFunction(functionPrototype, name) 738 , m_function(function) 737 GlobalEvalFunction::GlobalEvalFunction(ExecState* exec, FunctionPrototype* functionPrototype, int len, const Identifier& name, NativeFunction function, JSGlobalObject* cachedGlobalObject) 738 : PrototypeFunction(exec, functionPrototype, len, name, function) 739 739 , m_cachedGlobalObject(cachedGlobalObject) 740 740 { 741 ASSERT_ARG(function, function);742 741 ASSERT_ARG(cachedGlobalObject, cachedGlobalObject); 743 putDirect(exec->propertyNames().length, jsNumber(exec, len), DontDelete | ReadOnly | DontEnum); 744 } 745 746 JSValue* PrototypeReflexiveFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const ArgList& args) 747 { 748 return m_function(exec, this, thisObj, args); 749 } 750 751 void PrototypeReflexiveFunction::mark() 752 { 753 InternalFunction::mark(); 742 } 743 744 void GlobalEvalFunction::mark() 745 { 746 PrototypeFunction::mark(); 754 747 if (!m_cachedGlobalObject->marked()) 755 748 m_cachedGlobalObject->mark(); -
trunk/JavaScriptCore/kjs/JSFunction.h
r34587 r34754 40 40 class InternalFunction : public JSObject { 41 41 public: 42 static const ClassInfo info; 43 virtual const ClassInfo* classInfo() const { return &info; } 44 const Identifier& functionName() const { return m_name; } 45 46 protected: 42 47 InternalFunction(); 43 48 InternalFunction(FunctionPrototype*, const Identifier&); 44 49 45 virtual CallType getCallData(CallData&); 46 47 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObjec, const ArgList& args) = 0; 50 private: 51 virtual CallType getCallData(CallData&) = 0; 48 52 virtual bool implementsHasInstance() const; 49 53 50 virtual const ClassInfo* classInfo() const { return &info; }51 static const ClassInfo info;52 const Identifier& functionName() const { return m_name; }53 54 private:55 54 Identifier m_name; 56 55 }; … … 64 63 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 65 64 66 virtual ConstructType getConstructData(ConstructData&);67 virtual JSObject* construct(ExecState*, const ArgList& args);65 JSObject* construct(ExecState*, const ArgList&); 66 JSValue* call(ExecState*, JSValue* thisValue, const ArgList&); 68 67 69 virtual CallType getCallData(CallData&); 70 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const ArgList& args); 68 // Note: Returns a null identifier for any parameters that will never get set 69 // due to a later parameter with the same name. 70 const Identifier& getParameterName(int index); 71 71 72 // Note: unlike body->paramName, this returns Identifier::null for parameters73 // that will never get set, due to later param having the same name74 Identifier getParameterName(int index);75 76 virtual const ClassInfo* classInfo() const { return &info; }77 72 static const ClassInfo info; 78 73 … … 85 80 86 81 private: 82 virtual const ClassInfo* classInfo() const { return &info; } 83 virtual ConstructType getConstructData(ConstructData&); 84 virtual CallType getCallData(CallData&); 85 87 86 ScopeChain _scope; 88 87 … … 94 93 class IndexToNameMap { 95 94 public: 96 IndexToNameMap(JSFunction*, const ArgList& args);95 IndexToNameMap(JSFunction*, const ArgList&); 97 96 ~IndexToNameMap(); 98 97 … … 124 123 class PrototypeFunction : public InternalFunction { 125 124 public: 126 typedef JSValue* (*JSMemberFunction)(ExecState*, JSObject* thisObj, const ArgList&); 127 128 PrototypeFunction(ExecState*, int len, const Identifier&, JSMemberFunction); 129 PrototypeFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, JSMemberFunction); 130 131 virtual JSValue* callAsFunction(ExecState* exec, JSObject* thisObj, const ArgList&); 125 PrototypeFunction(ExecState*, int len, const Identifier&, NativeFunction); 126 PrototypeFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, NativeFunction); 132 127 133 128 private: 134 const JSMemberFunction m_function; 129 virtual CallType getCallData(CallData&); 130 131 const NativeFunction m_function; 135 132 }; 136 133 134 class GlobalEvalFunction : public PrototypeFunction { 135 public: 136 GlobalEvalFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, NativeFunction, JSGlobalObject* expectedThisObject); 137 JSGlobalObject* cachedGlobalObject() const { return m_cachedGlobalObject; } 137 138 138 // Just like PrototypeFunction, but callbacks also get passed the JS function object. 139 class PrototypeReflexiveFunction : public InternalFunction { 140 public: 141 typedef JSValue* (*JSMemberFunction)(ExecState*, PrototypeReflexiveFunction*, JSObject* thisObj, const ArgList&); 139 private: 140 virtual void mark(); 142 141 143 PrototypeReflexiveFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, JSMemberFunction, JSGlobalObject* expectedThisObject); 144 145 virtual void mark(); 146 virtual JSValue* callAsFunction(ExecState* exec, JSObject* thisObj, const ArgList&); 147 148 JSGlobalObject* cachedGlobalObject() const { return m_cachedGlobalObject; } 149 150 private: 151 const JSMemberFunction m_function; 152 JSGlobalObject* m_cachedGlobalObject; 153 }; 142 JSGlobalObject* m_cachedGlobalObject; 143 }; 154 144 155 145 // Global Functions 156 JSValue* globalFuncEval(ExecState*, PrototypeReflexiveFunction*, JSObject*, const ArgList&);157 JSValue* globalFuncParseInt(ExecState*, JSObject*, const ArgList&);158 JSValue* globalFuncParseFloat(ExecState*, JSObject*, const ArgList&);159 JSValue* globalFuncIsNaN(ExecState*, JSObject*, const ArgList&);160 JSValue* globalFuncIsFinite(ExecState*, JSObject*, const ArgList&);161 JSValue* globalFuncDecodeURI(ExecState*, JSObject*, const ArgList&);162 JSValue* globalFuncDecodeURIComponent(ExecState*, JSObject*, const ArgList&);163 JSValue* globalFuncEncodeURI(ExecState*, JSObject*, const ArgList&);164 JSValue* globalFuncEncodeURIComponent(ExecState*, JSObject*, const ArgList&);165 JSValue* globalFuncEscape(ExecState*, JSObject*, const ArgList&);166 JSValue* globalFuncUnescape(ExecState*, JSObject*, const ArgList&);146 JSValue* globalFuncEval(ExecState*, JSObject*, JSValue*, const ArgList&); 147 JSValue* globalFuncParseInt(ExecState*, JSObject*, JSValue*, const ArgList&); 148 JSValue* globalFuncParseFloat(ExecState*, JSObject*, JSValue*, const ArgList&); 149 JSValue* globalFuncIsNaN(ExecState*, JSObject*, JSValue*, const ArgList&); 150 JSValue* globalFuncIsFinite(ExecState*, JSObject*, JSValue*, const ArgList&); 151 JSValue* globalFuncDecodeURI(ExecState*, JSObject*, JSValue*, const ArgList&); 152 JSValue* globalFuncDecodeURIComponent(ExecState*, JSObject*, JSValue*, const ArgList&); 153 JSValue* globalFuncEncodeURI(ExecState*, JSObject*, JSValue*, const ArgList&); 154 JSValue* globalFuncEncodeURIComponent(ExecState*, JSObject*, JSValue*, const ArgList&); 155 JSValue* globalFuncEscape(ExecState*, JSObject*, JSValue*, const ArgList&); 156 JSValue* globalFuncUnescape(ExecState*, JSObject*, JSValue*, const ArgList&); 167 157 #ifndef NDEBUG 168 JSValue* globalFuncKJSPrint(ExecState*, JSObject*, const ArgList&);158 JSValue* globalFuncKJSPrint(ExecState*, JSObject*, JSValue*, const ArgList&); 169 159 #endif 170 160 -
trunk/JavaScriptCore/kjs/JSGlobalObject.cpp
r34673 r34754 213 213 214 214 // Constructors 215 d()->objectConstructor = 0;216 d()->functionConstructor = 0;217 d()->arrayConstructor = 0;218 d()->stringConstructor = 0;219 d()->booleanConstructor = 0;220 d()->numberConstructor = 0;221 d()->dateConstructor = 0;222 215 d()->regExpConstructor = 0; 223 216 d()->errorConstructor = 0; … … 235 228 236 229 // Prototypes 230 237 231 d()->functionPrototype = new (exec) FunctionPrototype(exec); 238 232 d()->objectPrototype = new (exec) ObjectPrototype(exec, d()->functionPrototype); … … 255 249 256 250 // Constructors 257 d()->objectConstructor = new (exec) ObjectConstructor(exec, d()->objectPrototype, d()->functionPrototype); 258 d()->functionConstructor = new (exec) FunctionConstructor(exec, d()->functionPrototype); 259 d()->arrayConstructor = new (exec) ArrayConstructor(exec, d()->functionPrototype, d()->arrayPrototype); 260 d()->stringConstructor = new (exec) StringConstructor(exec, d()->functionPrototype, d()->stringPrototype); 261 d()->booleanConstructor = new (exec) BooleanConstructor(exec, d()->functionPrototype, d()->booleanPrototype); 262 d()->numberConstructor = new (exec) NumberConstructor(exec, d()->functionPrototype, d()->numberPrototype); 263 d()->dateConstructor = new (exec) DateConstructor(exec, d()->functionPrototype, d()->datePrototype); 251 252 JSValue* objectConstructor = new (exec) ObjectConstructor(exec, d()->objectPrototype, d()->functionPrototype); 253 JSValue* functionConstructor = new (exec) FunctionConstructor(exec, d()->functionPrototype); 254 JSValue* arrayConstructor = new (exec) ArrayConstructor(exec, d()->functionPrototype, d()->arrayPrototype); 255 JSValue* stringConstructor = new (exec) StringConstructor(exec, d()->functionPrototype, d()->stringPrototype); 256 JSValue* booleanConstructor = new (exec) BooleanConstructor(exec, d()->functionPrototype, d()->booleanPrototype); 257 JSValue* numberConstructor = new (exec) NumberConstructor(exec, d()->functionPrototype, d()->numberPrototype); 258 JSValue* dateConstructor = new (exec) DateConstructor(exec, d()->functionPrototype, d()->datePrototype); 259 264 260 d()->regExpConstructor = new (exec) RegExpConstructor(exec, d()->functionPrototype, d()->regExpPrototype); 261 265 262 d()->errorConstructor = new (exec) ErrorConstructor(exec, d()->functionPrototype, d()->errorPrototype); 266 263 … … 272 269 d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, d()->functionPrototype, d()->URIErrorPrototype); 273 270 274 d()->functionPrototype->putDirect(exec->propertyNames().constructor, d()->functionConstructor, DontEnum);275 276 d()->objectPrototype->putDirect(exec->propertyNames().constructor, d()->objectConstructor, DontEnum);277 d()->functionPrototype->putDirect(exec->propertyNames().constructor, d()->functionConstructor, DontEnum);278 d()->arrayPrototype->putDirect(exec->propertyNames().constructor, d()->arrayConstructor, DontEnum);279 d()->booleanPrototype->putDirect(exec->propertyNames().constructor, d()->booleanConstructor, DontEnum);280 d()->stringPrototype->putDirect(exec->propertyNames().constructor, d()->stringConstructor, DontEnum);281 d()->numberPrototype->putDirect(exec->propertyNames().constructor, d()->numberConstructor, DontEnum);282 d()->datePrototype->putDirect(exec->propertyNames().constructor, d ()->dateConstructor, DontEnum);271 d()->functionPrototype->putDirect(exec->propertyNames().constructor, functionConstructor, DontEnum); 272 273 d()->objectPrototype->putDirect(exec->propertyNames().constructor, objectConstructor, DontEnum); 274 d()->functionPrototype->putDirect(exec->propertyNames().constructor, functionConstructor, DontEnum); 275 d()->arrayPrototype->putDirect(exec->propertyNames().constructor, arrayConstructor, DontEnum); 276 d()->booleanPrototype->putDirect(exec->propertyNames().constructor, booleanConstructor, DontEnum); 277 d()->stringPrototype->putDirect(exec->propertyNames().constructor, stringConstructor, DontEnum); 278 d()->numberPrototype->putDirect(exec->propertyNames().constructor, numberConstructor, DontEnum); 279 d()->datePrototype->putDirect(exec->propertyNames().constructor, dateConstructor, DontEnum); 283 280 d()->regExpPrototype->putDirect(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum); 284 281 d()->errorPrototype->putDirect(exec->propertyNames().constructor, d()->errorConstructor, DontEnum); … … 294 291 // FIXME: These properties could be handled by a static hash table. 295 292 296 putDirect(Identifier(exec, "Object"), d()->objectConstructor, DontEnum);297 putDirect(Identifier(exec, "Function"), d()->functionConstructor, DontEnum);298 putDirect(Identifier(exec, "Array"), d()->arrayConstructor, DontEnum);299 putDirect(Identifier(exec, "Boolean"), d()->booleanConstructor, DontEnum);300 putDirect(Identifier(exec, "String"), d()->stringConstructor, DontEnum);301 putDirect(Identifier(exec, "Number"), d()->numberConstructor, DontEnum);302 putDirect(Identifier(exec, "Date"), d ()->dateConstructor, DontEnum);293 putDirect(Identifier(exec, "Object"), objectConstructor, DontEnum); 294 putDirect(Identifier(exec, "Function"), functionConstructor, DontEnum); 295 putDirect(Identifier(exec, "Array"), arrayConstructor, DontEnum); 296 putDirect(Identifier(exec, "Boolean"), booleanConstructor, DontEnum); 297 putDirect(Identifier(exec, "String"), stringConstructor, DontEnum); 298 putDirect(Identifier(exec, "Number"), numberConstructor, DontEnum); 299 putDirect(Identifier(exec, "Date"), dateConstructor, DontEnum); 303 300 putDirect(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum); 304 301 putDirect(Identifier(exec, "Error"), d()->errorConstructor, DontEnum); … … 322 319 // Set global functions. 323 320 324 d()->evalFunction = new (exec) PrototypeReflexiveFunction(exec, d()->functionPrototype, 1, exec->propertyNames().eval, globalFuncEval, this);321 d()->evalFunction = new (exec) GlobalEvalFunction(exec, d()->functionPrototype, 1, exec->propertyNames().eval, globalFuncEval, this); 325 322 putDirectFunction(d()->evalFunction, DontEnum); 326 323 putDirectFunction(new (exec) PrototypeFunction(exec, d()->functionPrototype, 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum); … … 416 413 markIfNeeded(d()->globalExec->exception()); 417 414 418 markIfNeeded(d()->objectConstructor);419 markIfNeeded(d()->functionConstructor);420 markIfNeeded(d()->arrayConstructor);421 markIfNeeded(d()->booleanConstructor);422 markIfNeeded(d()->stringConstructor);423 markIfNeeded(d()->numberConstructor);424 markIfNeeded(d()->dateConstructor);425 415 markIfNeeded(d()->regExpConstructor); 426 416 markIfNeeded(d()->errorConstructor); -
trunk/JavaScriptCore/kjs/JSGlobalObject.h
r34659 r34754 33 33 namespace KJS { 34 34 35 class ArrayConstructor;36 35 class ArrayPrototype; 37 class BooleanConstructor;38 36 class BooleanPrototype; 39 class DateConstructor;40 37 class DatePrototype; 41 38 class Debugger; … … 44 41 class EvalError; 45 42 class EvalErrorPrototype; 46 class FunctionConstructor;47 43 class FunctionPrototype; 48 struct HashTable;44 class GlobalEvalFunction; 49 45 class JSGlobalObject; 50 46 class NativeErrorConstructor; 51 47 class NativeErrorPrototype; 52 class NumberConstructor;53 48 class NumberPrototype; 54 class ObjectConstructor;55 49 class ObjectPrototype; 56 50 class ProgramCodeBlock; 57 class PrototypeReflexiveFunction;58 51 class RangeError; 59 52 class RangeErrorPrototype; … … 65 58 class RuntimeMethod; 66 59 class ScopeChain; 67 class StringConstructor;68 60 class StringPrototype; 69 61 class SyntaxErrorPrototype; … … 72 64 class UriError; 73 65 class UriErrorPrototype; 66 74 67 struct ActivationStackNode; 68 struct HashTable; 75 69 76 70 typedef Vector<ExecState*, 16> ExecStateStack; … … 105 99 unsigned ticksUntilNextTimeoutCheck; 106 100 107 ObjectConstructor* objectConstructor;108 FunctionConstructor* functionConstructor;109 ArrayConstructor* arrayConstructor;110 BooleanConstructor* booleanConstructor;111 StringConstructor* stringConstructor;112 NumberConstructor* numberConstructor;113 DateConstructor* dateConstructor;114 101 RegExpConstructor* regExpConstructor; 115 102 ErrorConstructor* errorConstructor; … … 121 108 NativeErrorConstructor* URIErrorConstructor; 122 109 123 PrototypeReflexiveFunction* evalFunction;110 GlobalEvalFunction* evalFunction; 124 111 125 112 ObjectPrototype* objectPrototype; … … 157 144 158 145 protected: 159 JSGlobalObject(JSValue* proto , JSObject* globalThisValue)160 : JSVariableObject(proto , new JSGlobalObjectData(this, globalThisValue))146 JSGlobalObject(JSValue* prototype, JSObject* globalThisValue) 147 : JSVariableObject(prototype, new JSGlobalObjectData(this, globalThisValue)) 161 148 { 162 149 init(globalThisValue); … … 187 174 // replaces the global object's associated property. 188 175 189 ObjectConstructor* objectConstructor() const { return d()->objectConstructor; }190 FunctionConstructor* functionConstructor() const { return d()->functionConstructor; }191 ArrayConstructor* arrayConstructor() const { return d()->arrayConstructor; }192 BooleanConstructor* booleanConstructor() const { return d()->booleanConstructor; }193 StringConstructor* stringConstructor() const{ return d()->stringConstructor; }194 NumberConstructor* numberConstructor() const{ return d()->numberConstructor; }195 DateConstructor* dateConstructor() const{ return d()->dateConstructor; }196 176 RegExpConstructor* regExpConstructor() const { return d()->regExpConstructor; } 177 197 178 ErrorConstructor* errorConstructor() const { return d()->errorConstructor; } 198 179 NativeErrorConstructor* evalErrorConstructor() const { return d()->evalErrorConstructor; } … … 203 184 NativeErrorConstructor* URIErrorConstructor() const { return d()->URIErrorConstructor; } 204 185 205 PrototypeReflexiveFunction* evalFunction() const { return d()->evalFunction; }186 GlobalEvalFunction* evalFunction() const { return d()->evalFunction; } 206 187 207 188 ObjectPrototype* objectPrototype() const { return d()->objectPrototype; } -
trunk/JavaScriptCore/kjs/JSImmediate.cpp
r34659 r34754 30 30 namespace KJS { 31 31 32 JSObject *JSImmediate::toObject(const JSValue *v, ExecState *exec)32 JSObject* JSImmediate::toObject(const JSValue *v, ExecState *exec) 33 33 { 34 34 ASSERT(isImmediate(v)); 35 35 if (v == jsNull()) 36 36 return new (exec) JSNotAnObject(throwError(exec, TypeError, "Null value")); 37 elseif (v == jsUndefined())37 if (v == jsUndefined()) 38 38 return new (exec) JSNotAnObject(throwError(exec, TypeError, "Undefined value")); 39 else if (isBoolean(v)) { 40 ArgList args; 41 args.append(const_cast<JSValue *>(v)); 42 return exec->lexicalGlobalObject()->booleanConstructor()->construct(exec, args); 43 } else { 44 ASSERT(isNumber(v)); 45 ArgList args; 46 args.append(const_cast<JSValue *>(v)); 47 return exec->lexicalGlobalObject()->numberConstructor()->construct(exec, args); 48 } 39 if (isBoolean(v)) 40 return constructBooleanFromImmediateBoolean(exec, const_cast<JSValue*>(v)); 41 ASSERT(isNumber(v)); 42 return constructNumberFromImmediateNumber(exec, const_cast<JSValue*>(v)); 49 43 } 50 44 -
trunk/JavaScriptCore/kjs/JSNotAnObject.cpp
r34587 r34754 127 127 } 128 128 129 JSValue* JSNotAnObject::defaultValue(ExecState* exec, JSType) const130 {131 UNUSED_PARAM(exec);132 ASSERT(exec->hadException() && exec->exception() == m_exception);133 return m_exception;134 }135 136 JSObject* JSNotAnObject::construct(ExecState* exec, const ArgList&)137 {138 UNUSED_PARAM(exec);139 ASSERT(exec->hadException() && exec->exception() == m_exception);140 return m_exception;141 }142 143 JSObject* JSNotAnObject::construct(ExecState* exec, const ArgList&, const Identifier&, const UString&, int)144 {145 UNUSED_PARAM(exec);146 ASSERT(exec->hadException() && exec->exception() == m_exception);147 return m_exception;148 }149 150 JSValue* JSNotAnObject::callAsFunction(ExecState* exec, JSObject*, const ArgList&)151 {152 UNUSED_PARAM(exec);153 ASSERT(exec->hadException() && exec->exception() == m_exception);154 return m_exception;155 }156 157 129 void JSNotAnObject::getPropertyNames(ExecState* exec, PropertyNameArray&) 158 130 { -
trunk/JavaScriptCore/kjs/JSNotAnObject.h
r34587 r34754 44 44 } 45 45 46 // JSValue methods 46 private: 47 // JSValue methods 47 48 virtual JSValue* toPrimitive(ExecState*, JSType preferredType = UnspecifiedType) const; 48 49 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*&); … … 65 66 virtual bool deleteProperty(ExecState*, unsigned propertyName); 66 67 67 virtual JSValue* defaultValue(ExecState*, JSType hint) const;68 69 virtual JSObject* construct(ExecState*, const ArgList&);70 virtual JSObject* construct(ExecState*, const ArgList&, const Identifier& functionName, const UString& sourceURL, int lineNumber);71 72 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const ArgList&);73 74 68 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 75 69 76 private:77 70 JSObject* m_exception; 78 71 }; -
trunk/JavaScriptCore/kjs/JSObject.cpp
r34659 r34754 70 70 } 71 71 72 const ClassInfo *JSObject::classInfo() const73 {74 return 0;75 }76 77 72 UString JSObject::className() const 78 73 { … … 94 89 95 90 // ECMA 8.6.2.2 96 void JSObject::put(ExecState* exec, const Identifier &propertyName, JSValue *value)91 void JSObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value) 97 92 { 98 93 ASSERT(value); … … 102 97 JSObject* proto = value->getObject(); 103 98 104 // Setting __proto__ to a non-object, non-null value is silently ignored to match Mozilla 99 // Setting __proto__ to a non-object, non-null value is silently ignored to match Mozilla. 105 100 if (!proto && value != jsNull()) 106 101 return; … … 113 108 proto = proto->prototype() ? proto->prototype()->getObject() : 0; 114 109 } 115 110 116 111 setPrototype(value); 117 112 return; … … 119 114 120 115 // Check if there are any setters or getters in the prototype chain 121 JSObject *obj = this; 122 bool hasGettersOrSetters = false; 123 while (true) { 124 if (obj->_prop.hasGetterSetterProperties()) { 125 hasGettersOrSetters = true; 116 JSObject* obj; 117 JSValue* prototype; 118 for (obj = this; !obj->_prop.hasGetterSetterProperties(); obj = static_cast<JSObject*>(prototype)) { 119 prototype = obj->_proto; 120 if (prototype == jsNull()) { 121 _prop.put(propertyName, value, 0, true); 122 return; 123 } 124 } 125 126 unsigned attributes; 127 if (_prop.get(propertyName, attributes) && attributes & ReadOnly) 128 return; 129 130 for (; ; obj = static_cast<JSObject*>(prototype)) { 131 if (JSValue* gs = obj->_prop.get(propertyName, attributes)) { 132 if (attributes & IsGetterSetter) { 133 JSObject* setterFunc = static_cast<GetterSetter*>(gs)->setter(); 134 if (!setterFunc) { 135 throwSetterError(exec); 136 return; 137 } 138 139 CallData callData; 140 CallType callType = setterFunc->getCallData(callData); 141 ArgList args; 142 args.append(value); 143 call(exec, setterFunc, callType, callData, this, args); 144 return; 145 } 146 147 // If there's an existing property on the object or one of its 148 // prototypes it should be replaced, so break here. 126 149 break; 127 150 } 128 129 if (obj->_proto == jsNull()) 151 152 prototype = obj->_proto; 153 if (prototype == jsNull()) 130 154 break; 131 132 obj = static_cast<JSObject *>(obj->_proto);133 155 } 134 135 if (hasGettersOrSetters) { 136 unsigned attributes; 137 if (_prop.get(propertyName, attributes) && attributes & ReadOnly) 138 return; 139 140 obj = this; 141 while (true) { 142 if (JSValue *gs = obj->_prop.get(propertyName, attributes)) { 143 if (attributes & IsGetterSetter) { 144 JSObject *setterFunc = static_cast<GetterSetter *>(gs)->getSetter(); 145 146 if (!setterFunc) { 147 throwSetterError(exec); 148 return; 149 } 150 151 ArgList args; 152 args.append(value); 153 154 setterFunc->callAsFunction(exec, this->toThisObject(exec), args); 155 return; 156 } else { 157 // If there's an existing property on the object or one of its 158 // prototype it should be replaced, so we just break here. 159 break; 160 } 161 } 162 163 if (!obj->_proto->isObject()) 164 break; 165 166 obj = static_cast<JSObject *>(obj->_proto); 167 } 168 } 169 156 170 157 _prop.put(propertyName, value, 0, true); 171 158 } … … 231 218 } 232 219 233 static ALWAYS_INLINE JSValue *tryGetAndCallProperty(ExecState *exec, const JSObject *object, const Identifier &propertyName) { 234 JSValue* v = object->get(exec, propertyName); 235 if (v->isObject()) { 236 JSObject* o = static_cast<JSObject*>(v); 237 CallData data; 238 CallType callType = o->getCallData(data); 239 // spec says "not primitive type" but ... 240 if (callType != CallTypeNone) { 241 JSObject* thisObj = const_cast<JSObject*>(object); 242 JSValue* def = o->callAsFunction(exec, thisObj->toThisObject(exec), exec->emptyList()); 243 JSType defType = def->type(); 244 ASSERT(defType != GetterSetterType); 245 if (defType != ObjectType) 246 return def; 247 } 248 } 249 return NULL; 220 static ALWAYS_INLINE JSValue* callDefaultValueFunction(ExecState* exec, const JSObject* object, const Identifier& propertyName) 221 { 222 JSValue* function = object->get(exec, propertyName); 223 CallData callData; 224 CallType callType = function->getCallData(callData); 225 if (callType == CallTypeNone) 226 return 0; 227 JSValue* result = call(exec, function, callType, callData, const_cast<JSObject*>(object), exec->emptyList()); 228 ASSERT(result->type() != GetterSetterType); 229 if (exec->hadException()) 230 return exec->exception(); 231 if (result->isObject()) 232 return 0; 233 return result; 250 234 } 251 235 … … 260 244 JSValue* JSObject::defaultValue(ExecState* exec, JSType hint) const 261 245 { 262 // We need this check to guard against the case where this object is rhs of263 // a binary expression where lhs threw an exception in its conversion to264 // primitive265 if (exec->hadException())266 return exec->exception();267 /* Prefer String for Date objects */ 268 if ((hint == StringType) || (hint != NumberType && _proto == exec->lexicalGlobalObject()->datePrototype())) {269 if ( JSValue* v = tryGetAndCallProperty(exec, this, exec->propertyNames().toString))270 return v;271 if (JSValue* v = tryGetAndCallProperty(exec, this, exec->propertyNames().valueOf))272 return v;273 } else {274 if (JSValue* v = tryGetAndCallProperty(exec, this, exec->propertyNames().valueOf))275 return v;276 if (JSValue* v = tryGetAndCallProperty(exec, this, exec->propertyNames().toString))277 return v;278 }279 280 if (exec->hadException()) 281 return exec->exception();282 283 return throwError(exec, TypeError, "No default value");246 // We need this check to guard against the case where this object is rhs of 247 // a binary expression where lhs threw an exception in its conversion to 248 // primitive. 249 if (exec->hadException()) 250 return exec->exception(); 251 252 // Must call toString first for Date objects. 253 if ((hint == StringType) || (hint != NumberType && _proto == exec->lexicalGlobalObject()->datePrototype())) { 254 if (JSValue* value = callDefaultValueFunction(exec, this, exec->propertyNames().toString)) 255 return value; 256 if (JSValue* value = callDefaultValueFunction(exec, this, exec->propertyNames().valueOf)) 257 return value; 258 } else { 259 if (JSValue* value = callDefaultValueFunction(exec, this, exec->propertyNames().valueOf)) 260 return value; 261 if (JSValue* value = callDefaultValueFunction(exec, this, exec->propertyNames().toString)) 262 return value; 263 } 264 265 ASSERT(!exec->hadException()); 266 267 return throwError(exec, TypeError, "No default value"); 284 268 } 285 269 … … 335 319 if (v->type() != GetterSetterType) 336 320 return jsUndefined(); 337 JSObject* funcObj = static_cast<GetterSetter*>(v)->get Getter();321 JSObject* funcObj = static_cast<GetterSetter*>(v)->getter(); 338 322 if (!funcObj) 339 323 return jsUndefined(); … … 355 339 if (v->type() != GetterSetterType) 356 340 return jsUndefined(); 357 JSObject* funcObj = static_cast<GetterSetter*>(v)-> getSetter();341 JSObject* funcObj = static_cast<GetterSetter*>(v)->setter(); 358 342 if (!funcObj) 359 343 return jsUndefined(); … … 367 351 } 368 352 369 JSObject* JSObject::construct(ExecState*, const ArgList& /*args*/)370 {371 ASSERT(false);372 return NULL;373 }374 375 JSObject* JSObject::construct(ExecState* exec, const ArgList& args, const Identifier& /*functionName*/, const UString& /*sourceURL*/, int /*lineNumber*/)376 {377 return construct(exec, args);378 }379 380 bool JSObject::implementsCall()381 {382 CallData callData;383 return getCallData(callData) != CallTypeNone;384 }385 386 JSValue *JSObject::callAsFunction(ExecState* /*exec*/, JSObject* /*thisObj*/, const ArgList &/*args*/)387 {388 ASSERT(false);389 return NULL;390 }391 392 353 bool JSObject::implementsHasInstance() const 393 354 { … … 399 360 JSValue* proto = get(exec, exec->propertyNames().prototype); 400 361 if (!proto->isObject()) { 401 throwError(exec, TypeError, "in tanceof called on an object with an invalid prototype property.");362 throwError(exec, TypeError, "instanceof called on an object with an invalid prototype property."); 402 363 return false; 403 364 } … … 508 469 } 509 470 510 void JSObject::fillGetterPropertySlot(PropertySlot& slot, JSValue **location) 511 { 512 GetterSetter *gs = static_cast<GetterSetter *>(*location); 513 JSObject *getterFunc = gs->getGetter(); 514 if (getterFunc) 471 void JSObject::fillGetterPropertySlot(PropertySlot& slot, JSValue** location) 472 { 473 if (JSObject* getterFunc = static_cast<GetterSetter*>(*location)->getter()) 515 474 slot.setGetterSlot(getterFunc); 516 475 else … … 561 520 else 562 521 args.append(jsString(exec, message)); 563 JSObject *err = static_cast<JSObject *>(cons->construct(exec,args)); 522 ConstructData constructData; 523 ConstructType constructType = cons->getConstructData(constructData); 524 JSObject* err = construct(exec, cons, constructType, constructData, args); 564 525 565 526 if (lineno != -1) … … 607 568 } 608 569 570 JSObject* constructEmptyObject(ExecState* exec) 571 { 572 return new (exec) JSObject(exec->lexicalGlobalObject()->objectPrototype()); 573 } 574 609 575 } // namespace KJS -
trunk/JavaScriptCore/kjs/JSObject.h
r34664 r34754 85 85 JSType type() const { return GetterSetterType; } 86 86 87 GetterSetter() : getter(0), setter(0) { } 88 89 virtual JSValue* toPrimitive(ExecState*, JSType preferred = UnspecifiedType) const; 90 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value); 91 virtual bool toBoolean(ExecState *exec) const; 92 virtual double toNumber(ExecState *exec) const; 93 virtual UString toString(ExecState *exec) const; 94 virtual JSObject *toObject(ExecState *exec) const; 87 GetterSetter() : m_getter(0), m_setter(0) { } 95 88 96 89 virtual void mark(); 97 90 98 JSObject *getGetter() { returngetter; }99 void setGetter(JSObject *g) { getter = g; }100 JSObject *getSetter() { returnsetter; }101 void setSetter(JSObject *s) { setter = s; }91 JSObject* getter() const { return m_getter; } 92 void setGetter(JSObject* getter) { m_getter = getter; } 93 JSObject* setter() const { return m_setter; } 94 void setSetter(JSObject* setter) { m_setter = setter; } 102 95 103 96 private: 104 // Object operations, with the toObject operation included.105 virtual bool get OwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);106 virtual bool getOwnPropertySlot(ExecState*, unsigned index, PropertySlot&);107 virtual void put(ExecState*, const Identifier& propertyName, JSValue*);108 virtual void put(ExecState*, unsigned propertyName, JSValue*);109 virtual JSObject* to ThisObject(ExecState*) const;110 111 JSObject *getter;112 JSObject *setter;97 virtual JSValue* toPrimitive(ExecState*, JSType preferred) const; 98 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value); 99 virtual bool toBoolean(ExecState*) const; 100 virtual double toNumber(ExecState*) const; 101 virtual UString toString(ExecState*) const; 102 virtual JSObject* toObject(ExecState*) const; 103 104 JSObject* m_getter; 105 JSObject* m_setter; 113 106 }; 114 107 … … 168 161 * @see inherits() 169 162 */ 170 virtual const ClassInfo *classInfo() const;171 163 172 164 /** … … 196 188 * ClassInfo pointer specified in cinfo 197 189 */ 198 bool inherits(const ClassInfo *cinfo) const;190 bool inherits(const ClassInfo* classInfo) const { return isObject(classInfo); } // FIXME: Merge with isObject. 199 191 200 192 // internal properties (ECMA 262-3 8.6.2) … … 231 223 /** 232 224 * Retrieves the specified property from the object. If neither the object 233 * or any other object in it 's prototype chain have the property, this225 * or any other object in its prototype chain have the property, this 234 226 * function will return Undefined. 235 227 * … … 277 269 278 270 /** 279 * Checks to see whether the object (or any object in it 's prototype chain)271 * Checks to see whether the object (or any object in its prototype chain) 280 272 * has a property with the specified name. 281 273 * … … 320 312 * all Objects) 321 313 */ 322 virtual JSValue *defaultValue(ExecState *exec, JSType hint) const; 323 324 /** 325 * Creates a new object based on this object. Typically this means the 326 * following: 327 * 1. A new object is created 328 * 2. The prototype of the new object is set to the value of this object's 329 * "prototype" property 330 * 3. The call() method of this object is called, with the new object 331 * passed as the this value 332 * 4. The new object is returned 333 * 334 * In some cases, Host objects may differ from these semantics, although 335 * this is discouraged. 336 * 337 * If an error occurs during construction, the execution state's exception 338 * will be set. This can be tested for with ExecState::hadException(). 339 * Under some circumstances, the exception object may also be returned. 340 * 341 * Note: This function should not be called if getConstructData() returns 342 * ConstructTypeNone, in which case it will result in an assertion failure. 343 * 344 * @param exec The current execution state 345 * @param args The arguments to be passed to call() once the new object has 346 * been created 347 * @return The newly created & initialized object 348 */ 349 /** 350 * Implementation of the [[Construct]] internal property 351 */ 352 virtual JSObject* construct(ExecState* exec, const ArgList& args); 353 virtual JSObject* construct(ExecState* exec, const ArgList& args, const Identifier& functionName, const UString& sourceURL, int lineNumber); 354 355 /** 356 * Calls this object as if it is a function. 357 * 358 * Note: This function should not be called if implementsCall() returns 359 * false, in which case it will result in an assertion failure. 360 * 361 * See ECMA 8.6.2.3 362 * 363 * @param exec The current execution state 364 * @param thisObj The obj to be used as "this" within function execution. 365 * Note that in most cases this will be different from the C++ "this" 366 * object. For example, if the ECMAScript code "window.location->toString()" 367 * is executed, call() will be invoked on the C++ object which implements 368 * the toString method, with the thisObj being window.location 369 * @param args ArgList of arguments to be passed to the function 370 * @return The return value from the function 371 */ 372 bool implementsCall(); 373 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const ArgList &args); 314 virtual JSValue* defaultValue(ExecState*, JSType hint) const; 374 315 375 316 /** … … 447 388 }; 448 389 390 JSObject* constructEmptyObject(ExecState*); 391 449 392 /** 450 393 * Types of Native Errors available. For custom errors, GeneralError … … 506 449 } 507 450 508 inline bool JS Object::inherits(const ClassInfo *info) const509 { 510 for (const ClassInfo *ci = classInfo(); ci; ci = ci->parentClass)451 inline bool JSCell::isObject(const ClassInfo* info) const 452 { 453 for (const ClassInfo* ci = classInfo(); ci; ci = ci->parentClass) { 511 454 if (ci == info) 512 455 return true; 456 } 513 457 return false; 514 458 } 515 459 516 // this method is here to be after the inline declaration of JSObject::inherits517 inline bool JSCell::isObject(const ClassInfo *info) const518 {519 return isObject() && static_cast<const JSObject *>(this)->inherits(info);520 }521 522 460 // this method is here to be after the inline declaration of JSCell::isObject 523 inline bool JSValue::isObject(const ClassInfo *c) const524 { 525 return !JSImmediate::isImmediate(this) && asCell()->isObject(c );461 inline bool JSValue::isObject(const ClassInfo* classInfo) const 462 { 463 return !JSImmediate::isImmediate(this) && asCell()->isObject(classInfo); 526 464 } 527 465 -
trunk/JavaScriptCore/kjs/JSValue.cpp
r34659 r34754 256 256 } 257 257 258 bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier) 259 { 260 return toObject(exec)->deleteProperty(exec, identifier); 261 } 262 263 bool JSCell::deleteProperty(ExecState* exec, unsigned identifier) 264 { 265 return toObject(exec)->deleteProperty(exec, identifier); 266 } 267 258 268 JSObject* JSCell::toThisObject(ExecState* exec) const 259 269 { … … 261 271 } 262 272 273 const ClassInfo* JSCell::classInfo() const 274 { 275 return 0; 276 } 277 263 278 JSCell* jsString(ExecState* exec, const char* s) 264 279 { … … 276 291 } 277 292 293 JSValue* call(ExecState* exec, JSValue* functionObject, CallType callType, const CallData& callData, JSValue* thisValue, const ArgList& args) 294 { 295 if (callType == CallTypeNative) 296 return callData.native.function(exec, static_cast<JSObject*>(functionObject), thisValue, args); 297 ASSERT(callType == CallTypeJS); 298 // FIXME: This can be done more efficiently using the callData. 299 return static_cast<JSFunction*>(functionObject)->call(exec, thisValue, args); 300 } 301 302 JSObject* construct(ExecState* exec, JSValue* object, ConstructType constructType, const ConstructData& constructData, const ArgList& args) 303 { 304 if (constructType == ConstructTypeNative) 305 return constructData.native.function(exec, static_cast<JSObject*>(object), args); 306 ASSERT(constructType == ConstructTypeJS); 307 // FIXME: This can be done more efficiently using the constructData. 308 return static_cast<JSFunction*>(object)->construct(exec, args); 309 } 310 278 311 } // namespace KJS -
trunk/JavaScriptCore/kjs/JSValue.h
r34659 r34754 68 68 bool isString() const; 69 69 bool isObject() const; 70 bool isObject(const ClassInfo*) const; 70 bool isObject(const ClassInfo*) const; // FIXME: Merge with inherits. 71 71 72 72 // Extracting the value. … … 129 129 void put(ExecState*, const Identifier& propertyName, JSValue*); 130 130 void put(ExecState*, unsigned propertyName, JSValue*); 131 bool deleteProperty(ExecState*, const Identifier& propertyName); 132 bool deleteProperty(ExecState*, unsigned propertyName); 131 133 JSObject* toThisObject(ExecState*) const; 132 134 … … 160 162 bool isString() const; 161 163 bool isObject() const; 162 bool isObject(const ClassInfo*) const; 164 bool isObject(const ClassInfo*) const; // FIXME: Merge with inherits. 163 165 164 166 // Extracting the value. … … 192 194 193 195 // Object operations, with the toObject operation included. 196 virtual const ClassInfo* classInfo() const; 194 197 virtual void put(ExecState*, const Identifier& propertyName, JSValue*); 195 198 virtual void put(ExecState*, unsigned propertyName, JSValue*); 199 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 200 virtual bool deleteProperty(ExecState*, unsigned propertyName); 196 201 virtual JSObject* toThisObject(ExecState*) const; 197 202 -
trunk/JavaScriptCore/kjs/MathObject.cpp
r34659 r34754 21 21 #include "config.h" 22 22 #include "MathObject.h" 23 #include "MathObject.lut.h"24 23 25 24 #include "operations.h" … … 30 29 namespace KJS { 31 30 31 static JSValue* mathProtoFuncAbs(ExecState*, JSObject*, JSValue*, const ArgList&); 32 static JSValue* mathProtoFuncACos(ExecState*, JSObject*, JSValue*, const ArgList&); 33 static JSValue* mathProtoFuncASin(ExecState*, JSObject*, JSValue*, const ArgList&); 34 static JSValue* mathProtoFuncATan(ExecState*, JSObject*, JSValue*, const ArgList&); 35 static JSValue* mathProtoFuncATan2(ExecState*, JSObject*, JSValue*, const ArgList&); 36 static JSValue* mathProtoFuncCeil(ExecState*, JSObject*, JSValue*, const ArgList&); 37 static JSValue* mathProtoFuncCos(ExecState*, JSObject*, JSValue*, const ArgList&); 38 static JSValue* mathProtoFuncExp(ExecState*, JSObject*, JSValue*, const ArgList&); 39 static JSValue* mathProtoFuncFloor(ExecState*, JSObject*, JSValue*, const ArgList&); 40 static JSValue* mathProtoFuncLog(ExecState*, JSObject*, JSValue*, const ArgList&); 41 static JSValue* mathProtoFuncMax(ExecState*, JSObject*, JSValue*, const ArgList&); 42 static JSValue* mathProtoFuncMin(ExecState*, JSObject*, JSValue*, const ArgList&); 43 static JSValue* mathProtoFuncPow(ExecState*, JSObject*, JSValue*, const ArgList&); 44 static JSValue* mathProtoFuncRandom(ExecState*, JSObject*, JSValue*, const ArgList&); 45 static JSValue* mathProtoFuncRound(ExecState*, JSObject*, JSValue*, const ArgList&); 46 static JSValue* mathProtoFuncSin(ExecState*, JSObject*, JSValue*, const ArgList&); 47 static JSValue* mathProtoFuncSqrt(ExecState*, JSObject*, JSValue*, const ArgList&); 48 static JSValue* mathProtoFuncTan(ExecState*, JSObject*, JSValue*, const ArgList&); 49 50 } 51 52 #include "MathObject.lut.h" 53 54 namespace KJS { 55 32 56 // ------------------------------ MathObject -------------------------------- 33 57 … … 35 59 36 60 /* Source for MathObject.lut.h 37 @begin mathTable 2161 @begin mathTable 38 62 E MathObject::Euler DontEnum|DontDelete|ReadOnly 39 63 LN2 MathObject::Ln2 DontEnum|DontDelete|ReadOnly … … 104 128 // ------------------------------ Functions -------------------------------- 105 129 106 JSValue* mathProtoFuncAbs(ExecState* exec, JSObject*, const ArgList& args)130 JSValue* mathProtoFuncAbs(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 107 131 { 108 132 double arg = args[0]->toNumber(exec); … … 110 134 } 111 135 112 JSValue* mathProtoFuncACos(ExecState* exec, JSObject*, const ArgList& args)136 JSValue* mathProtoFuncACos(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 113 137 { 114 138 return jsNumber(exec, acos(args[0]->toNumber(exec))); 115 139 } 116 140 117 JSValue* mathProtoFuncASin(ExecState* exec, JSObject*, const ArgList& args)141 JSValue* mathProtoFuncASin(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 118 142 { 119 143 return jsNumber(exec, asin(args[0]->toNumber(exec))); 120 144 } 121 145 122 JSValue* mathProtoFuncATan(ExecState* exec, JSObject*, const ArgList& args)146 JSValue* mathProtoFuncATan(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 123 147 { 124 148 return jsNumber(exec, atan(args[0]->toNumber(exec))); 125 149 } 126 150 127 JSValue* mathProtoFuncATan2(ExecState* exec, JSObject*, const ArgList& args)151 JSValue* mathProtoFuncATan2(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 128 152 { 129 153 return jsNumber(exec, atan2(args[0]->toNumber(exec), args[1]->toNumber(exec))); 130 154 } 131 155 132 JSValue* mathProtoFuncCeil(ExecState* exec, JSObject*, const ArgList& args)156 JSValue* mathProtoFuncCeil(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 133 157 { 134 158 double arg = args[0]->toNumber(exec); … … 138 162 } 139 163 140 JSValue* mathProtoFuncCos(ExecState* exec, JSObject*, const ArgList& args)164 JSValue* mathProtoFuncCos(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 141 165 { 142 166 return jsNumber(exec, cos(args[0]->toNumber(exec))); 143 167 } 144 168 145 JSValue* mathProtoFuncExp(ExecState* exec, JSObject*, const ArgList& args)169 JSValue* mathProtoFuncExp(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 146 170 { 147 171 return jsNumber(exec, exp(args[0]->toNumber(exec))); 148 172 } 149 173 150 JSValue* mathProtoFuncFloor(ExecState* exec, JSObject*, const ArgList& args)174 JSValue* mathProtoFuncFloor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 151 175 { 152 176 double arg = args[0]->toNumber(exec); … … 156 180 } 157 181 158 JSValue* mathProtoFuncLog(ExecState* exec, JSObject*, const ArgList& args)182 JSValue* mathProtoFuncLog(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 159 183 { 160 184 return jsNumber(exec, log(args[0]->toNumber(exec))); 161 185 } 162 186 163 JSValue* mathProtoFuncMax(ExecState* exec, JSObject*, const ArgList& args)187 JSValue* mathProtoFuncMax(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 164 188 { 165 189 unsigned argsCount = args.size(); … … 177 201 } 178 202 179 JSValue* mathProtoFuncMin(ExecState* exec, JSObject*, const ArgList& args)203 JSValue* mathProtoFuncMin(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 180 204 { 181 205 unsigned argsCount = args.size(); … … 193 217 } 194 218 195 JSValue* mathProtoFuncPow(ExecState* exec, JSObject*, const ArgList& args)219 JSValue* mathProtoFuncPow(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 196 220 { 197 221 // ECMA 15.8.2.1.13 … … 207 231 } 208 232 209 JSValue* mathProtoFuncRandom(ExecState* exec, JSObject*, const ArgList&)233 JSValue* mathProtoFuncRandom(ExecState* exec, JSObject*, JSValue*, const ArgList&) 210 234 { 211 235 #if !USE(MULTIPLE_THREADS) … … 220 244 } 221 245 222 JSValue* mathProtoFuncRound(ExecState* exec, JSObject*, const ArgList& args)246 JSValue* mathProtoFuncRound(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 223 247 { 224 248 double arg = args[0]->toNumber(exec); … … 228 252 } 229 253 230 JSValue* mathProtoFuncSin(ExecState* exec, JSObject*, const ArgList& args)254 JSValue* mathProtoFuncSin(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 231 255 { 232 256 return jsNumber(exec, sin(args[0]->toNumber(exec))); 233 257 } 234 258 235 JSValue* mathProtoFuncSqrt(ExecState* exec, JSObject*, const ArgList& args)259 JSValue* mathProtoFuncSqrt(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 236 260 { 237 261 return jsNumber(exec, sqrt(args[0]->toNumber(exec))); 238 262 } 239 263 240 JSValue* mathProtoFuncTan(ExecState* exec, JSObject*, const ArgList& args)264 JSValue* mathProtoFuncTan(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 241 265 { 242 266 return jsNumber(exec, tan(args[0]->toNumber(exec))); -
trunk/JavaScriptCore/kjs/MathObject.h
r34587 r34754 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 * This file is part of the KDE libraries4 2 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 5 3 * … … 41 39 }; 42 40 43 // Functions44 JSValue* mathProtoFuncAbs(ExecState*, JSObject*, const ArgList&);45 JSValue* mathProtoFuncACos(ExecState*, JSObject*, const ArgList&);46 JSValue* mathProtoFuncASin(ExecState*, JSObject*, const ArgList&);47 JSValue* mathProtoFuncATan(ExecState*, JSObject*, const ArgList&);48 JSValue* mathProtoFuncATan2(ExecState*, JSObject*, const ArgList&);49 JSValue* mathProtoFuncCeil(ExecState*, JSObject*, const ArgList&);50 JSValue* mathProtoFuncCos(ExecState*, JSObject*, const ArgList&);51 JSValue* mathProtoFuncExp(ExecState*, JSObject*, const ArgList&);52 JSValue* mathProtoFuncFloor(ExecState*, JSObject*, const ArgList&);53 JSValue* mathProtoFuncLog(ExecState*, JSObject*, const ArgList&);54 JSValue* mathProtoFuncMax(ExecState*, JSObject*, const ArgList&);55 JSValue* mathProtoFuncMin(ExecState*, JSObject*, const ArgList&);56 JSValue* mathProtoFuncPow(ExecState*, JSObject*, const ArgList&);57 JSValue* mathProtoFuncRandom(ExecState*, JSObject*, const ArgList&);58 JSValue* mathProtoFuncRound(ExecState*, JSObject*, const ArgList&);59 JSValue* mathProtoFuncSin(ExecState*, JSObject*, const ArgList&);60 JSValue* mathProtoFuncSqrt(ExecState*, JSObject*, const ArgList&);61 JSValue* mathProtoFuncTan(ExecState*, JSObject*, const ArgList&);62 63 41 } // namespace KJS 64 42 -
trunk/JavaScriptCore/kjs/NumberObject.cpp
r34659 r34754 44 44 // ------------------------------ NumberPrototype --------------------------- 45 45 46 static JSValue* numberProtoFuncToString(ExecState*, JSObject*, const ArgList&);47 static JSValue* numberProtoFuncToLocaleString(ExecState*, JSObject*, const ArgList&);48 static JSValue* numberProtoFuncValueOf(ExecState*, JSObject*, const ArgList&);49 static JSValue* numberProtoFuncToFixed(ExecState*, JSObject*, const ArgList&);50 static JSValue* numberProtoFuncToExponential(ExecState*, JSObject*, const ArgList&);51 static JSValue* numberProtoFuncToPrecision(ExecState*, JSObject*, const ArgList&);46 static JSValue* numberProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&); 47 static JSValue* numberProtoFuncToLocaleString(ExecState*, JSObject*, JSValue*, const ArgList&); 48 static JSValue* numberProtoFuncValueOf(ExecState*, JSObject*, JSValue*, const ArgList&); 49 static JSValue* numberProtoFuncToFixed(ExecState*, JSObject*, JSValue*, const ArgList&); 50 static JSValue* numberProtoFuncToExponential(ExecState*, JSObject*, JSValue*, const ArgList&); 51 static JSValue* numberProtoFuncToPrecision(ExecState*, JSObject*, JSValue*, const ArgList&); 52 52 53 53 // ECMA 15.7.4 … … 143 143 144 144 145 JSValue* numberProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList& args)146 { 147 if (!this Obj->inherits(&NumberObject::info))145 JSValue* numberProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 146 { 147 if (!thisValue->isObject(&NumberObject::info)) 148 148 return throwError(exec, TypeError); 149 149 150 JSValue* v = static_cast<NumberObject*>(this Obj)->internalValue();150 JSValue* v = static_cast<NumberObject*>(thisValue)->internalValue(); 151 151 152 152 double radixAsDouble = args[0]->toInteger(exec); // nan -> 0 … … 164 164 char s[2048 + 3]; 165 165 const char* lastCharInString = s + sizeof(s) - 1; 166 double x = v-> toNumber(exec);166 double x = v->uncheckedGetNumber(); 167 167 if (isnan(x) || isinf(x)) 168 168 return jsString(exec, UString::from(x)); … … 208 208 } 209 209 210 JSValue* numberProtoFuncToLocaleString(ExecState* exec, JSObject* thisObj, const ArgList&)211 { 212 if (!this Obj->inherits(&NumberObject::info))210 JSValue* numberProtoFuncToLocaleString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 211 { 212 if (!thisValue->isObject(&NumberObject::info)) 213 213 return throwError(exec, TypeError); 214 214 215 215 // TODO 216 return jsString(exec, static_cast<NumberObject*>(this Obj)->internalValue()->toString(exec));217 } 218 219 JSValue* numberProtoFuncValueOf(ExecState* exec, JSObject* thisObj, const ArgList&)220 { 221 if (!this Obj->inherits(&NumberObject::info))216 return jsString(exec, static_cast<NumberObject*>(thisValue)->internalValue()->toString(exec)); 217 } 218 219 JSValue* numberProtoFuncValueOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 220 { 221 if (!thisValue->isObject(&NumberObject::info)) 222 222 return throwError(exec, TypeError); 223 223 224 return static_cast<NumberObject*>(this Obj)->internalValue()->toJSNumber(exec);225 } 226 227 JSValue* numberProtoFuncToFixed(ExecState* exec, JSObject* thisObj, const ArgList& args)228 { 229 if (!this Obj->inherits(&NumberObject::info))224 return static_cast<NumberObject*>(thisValue)->internalValue(); 225 } 226 227 JSValue* numberProtoFuncToFixed(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 228 { 229 if (!thisValue->isObject(&NumberObject::info)) 230 230 return throwError(exec, TypeError); 231 231 232 JSValue* v = static_cast<NumberObject*>(this Obj)->internalValue();232 JSValue* v = static_cast<NumberObject*>(thisValue)->internalValue(); 233 233 234 234 JSValue* fractionDigits = args[0]; … … 238 238 int f = (int)df; 239 239 240 double x = v-> toNumber(exec);240 double x = v->uncheckedGetNumber(); 241 241 if (isnan(x)) 242 242 return jsString(exec, "NaN"); … … 311 311 } 312 312 313 JSValue* numberProtoFuncToExponential(ExecState* exec, JSObject* thisObj, const ArgList& args)314 { 315 if (!this Obj->inherits(&NumberObject::info))313 JSValue* numberProtoFuncToExponential(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 314 { 315 if (!thisValue->isObject(&NumberObject::info)) 316 316 return throwError(exec, TypeError); 317 317 318 JSValue* v = static_cast<NumberObject*>(thisObj)->internalValue(); 319 320 double x = v->toNumber(exec); 318 double x = static_cast<NumberObject*>(thisValue)->internalValue()->uncheckedGetNumber(); 321 319 322 320 if (isnan(x) || isinf(x)) … … 382 380 } 383 381 384 JSValue* numberProtoFuncToPrecision(ExecState* exec, JSObject* thisObj, const ArgList& args)385 { 386 if (!this Obj->inherits(&NumberObject::info))382 JSValue* numberProtoFuncToPrecision(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 383 { 384 if (!thisValue->isObject(&NumberObject::info)) 387 385 return throwError(exec, TypeError); 388 386 389 JSValue* v = static_cast<NumberObject*>(this Obj)->internalValue();387 JSValue* v = static_cast<NumberObject*>(thisValue)->internalValue(); 390 388 391 389 double doublePrecision = args[0]->toIntegerPreserveNaN(exec); 392 double x = v-> toNumber(exec);390 double x = v->uncheckedGetNumber(); 393 391 if (args[0]->isUndefined() || isnan(x) || isinf(x)) 394 392 return jsString(exec, v->toString(exec)); … … 454 452 455 453 /* Source for NumberObject.lut.h 456 @begin numberTable 5454 @begin numberTable 457 455 NaN NumberConstructor::NaNValue DontEnum|DontDelete|ReadOnly 458 456 NEGATIVE_INFINITY NumberConstructor::NegInfinity DontEnum|DontDelete|ReadOnly … … 463 461 */ 464 462 NumberConstructor::NumberConstructor(ExecState* exec, FunctionPrototype* funcProto, NumberPrototype* numberProto) 465 : InternalFunction(funcProto, Identifier(exec, numberProto-> classInfo()->className))463 : InternalFunction(funcProto, Identifier(exec, numberProto->info.className)) 466 464 { 467 465 // Number.Prototype … … 469 467 470 468 // no. of arguments for constructor 471 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly |DontDelete|DontEnum);469 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete); 472 470 } 473 471 … … 496 494 } 497 495 498 ConstructType NumberConstructor::getConstructData(ConstructData&)499 {500 return ConstructTypeNative;501 }502 503 496 // ECMA 15.7.1 504 JSObject* NumberConstructor::construct(ExecState* exec, const ArgList& args) 505 { 506 JSObject* proto = exec->lexicalGlobalObject()->numberPrototype(); 507 NumberObject* obj = new (exec) NumberObject(proto); 508 509 // FIXME: Check args[0]->isUndefined() instead of args.isEmpty()? 497 static JSObject* constructWithNumberConstructor(ExecState* exec, JSObject*, const ArgList& args) 498 { 499 NumberObject* obj = new (exec) NumberObject(exec->lexicalGlobalObject()->numberPrototype()); 510 500 double n = args.isEmpty() ? 0 : args[0]->toNumber(exec); 511 501 obj->setInternalValue(jsNumber(exec, n)); … … 513 503 } 514 504 505 ConstructType NumberConstructor::getConstructData(ConstructData& constructData) 506 { 507 constructData.native.function = constructWithNumberConstructor; 508 return ConstructTypeNative; 509 } 510 515 511 // ECMA 15.7.2 516 JSValue* NumberConstructor::callAsFunction(ExecState* exec, JSObject*, const ArgList& args) 517 { 518 // FIXME: Check args[0]->isUndefined() instead of args.isEmpty()? 512 static JSValue* callNumberConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 513 { 519 514 return jsNumber(exec, args.isEmpty() ? 0 : args[0]->toNumber(exec)); 520 515 } 521 516 517 CallType NumberConstructor::getCallData(CallData& callData) 518 { 519 callData.native.function = callNumberConstructor; 520 return CallTypeNative; 521 } 522 523 NumberObject* constructNumber(ExecState* exec, JSNumberCell* number) 524 { 525 NumberObject* obj = new (exec) NumberObject(exec->lexicalGlobalObject()->numberPrototype()); 526 obj->setInternalValue(number); 527 return obj; 528 } 529 530 NumberObject* constructNumberFromImmediateNumber(ExecState* exec, JSValue* value) 531 { 532 NumberObject* obj = new (exec) NumberObject(exec->lexicalGlobalObject()->numberPrototype()); 533 obj->setInternalValue(value); 534 return obj; 535 } 536 522 537 } // namespace KJS -
trunk/JavaScriptCore/kjs/NumberObject.h
r34587 r34754 28 28 namespace KJS { 29 29 30 class JSNumberCell; 31 30 32 class NumberObject : public JSWrapperObject { 31 33 public: 32 34 NumberObject(JSObject* prototype); 35 static const ClassInfo info; 33 36 37 private: 34 38 virtual const ClassInfo* classInfo() const { return &info; } 35 static const ClassInfo info;36 39 }; 40 41 NumberObject* constructNumber(ExecState*, JSNumberCell*); 42 NumberObject* constructNumberFromImmediateNumber(ExecState*, JSValue*); 37 43 38 44 /** … … 56 62 NumberConstructor(ExecState*, FunctionPrototype*, NumberPrototype*); 57 63 58 virtual ConstructType getConstructData(ConstructData&);59 virtual JSObject* construct(ExecState*, const ArgList&);60 61 virtual JSValue* callAsFunction(ExecState*, JSObject*, const ArgList&);62 63 64 bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 64 65 JSValue* getValueProperty(ExecState*, int token) const; 65 66 66 virtual const ClassInfo* classInfo() const { return &info; }67 67 static const ClassInfo info; 68 68 69 69 enum { NaNValue, NegInfinity, PosInfinity, MaxValue, MinValue }; 70 70 71 JSObject* construct(const ArgList&); 71 private: 72 virtual ConstructType getConstructData(ConstructData&); 73 virtual CallType getCallData(CallData&); 74 virtual const ClassInfo* classInfo() const { return &info; } 72 75 }; 73 76 -
trunk/JavaScriptCore/kjs/PropertySlot.cpp
r34582 r34754 37 37 JSValue* PropertySlot::functionGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) 38 38 { 39 CallData data;40 CallType callType = slot.m_data.getterFunc->getCallData( data);39 CallData callData; 40 CallType callType = slot.m_data.getterFunc->getCallData(callData); 41 41 if (callType == CallTypeNative) 42 return slot.m_data.getterFunc->callAsFunction(exec, static_cast<JSObject*>(slot.slotBase()), exec->emptyList());42 return callData.native.function(exec, slot.m_data.getterFunc, slot.slotBase(), exec->emptyList()); 43 43 ASSERT(callType == CallTypeJS); 44 44 RegisterFileStack* stack = &exec->dynamicGlobalObject()->registerFileStack(); 45 45 stack->pushFunctionRegisterFile(); 46 JSValue* result = slot.m_data.getterFunc->callAsFunction(exec, static_cast<JSObject*>(slot.slotBase()), exec->emptyList()); 46 // FIXME: This can be done more efficiently using the callData. 47 JSValue* result = static_cast<JSFunction*>(slot.m_data.getterFunc)->call(exec, slot.slotBase(), exec->emptyList()); 47 48 stack->popFunctionRegisterFile(); 48 return result; 49 return result; 49 50 } 50 51 -
trunk/JavaScriptCore/kjs/RegExpObject.cpp
r34659 r34754 39 39 // ------------------------------ RegExpPrototype --------------------------- 40 40 41 static JSValue* regExpProtoFuncTest(ExecState*, JSObject*, const ArgList&);42 static JSValue* regExpProtoFuncExec(ExecState*, JSObject*, const ArgList&);43 static JSValue* regExpProtoFuncCompile(ExecState*, JSObject*, const ArgList&);44 static JSValue* regExpProtoFuncToString(ExecState*, JSObject*, const ArgList&);41 static JSValue* regExpProtoFuncTest(ExecState*, JSObject*, JSValue*, const ArgList&); 42 static JSValue* regExpProtoFuncExec(ExecState*, JSObject*, JSValue*, const ArgList&); 43 static JSValue* regExpProtoFuncCompile(ExecState*, JSObject*, JSValue*, const ArgList&); 44 static JSValue* regExpProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&); 45 45 46 46 // ECMA 15.10.5 … … 59 59 // ------------------------------ Functions --------------------------- 60 60 61 JSValue* regExpProtoFuncTest(ExecState* exec, JSObject* thisObj, const ArgList& args)62 { 63 if (!this Obj->inherits(&RegExpObject::info))61 JSValue* regExpProtoFuncTest(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 62 { 63 if (!thisValue->isObject(&RegExpObject::info)) 64 64 return throwError(exec, TypeError); 65 66 return static_cast<RegExpObject*>(thisObj)->test(exec, args); 67 } 68 69 JSValue* regExpProtoFuncExec(ExecState* exec, JSObject* thisObj, const ArgList& args) 70 { 71 if (!thisObj->inherits(&RegExpObject::info)) 65 return static_cast<RegExpObject*>(thisValue)->test(exec, args); 66 } 67 68 JSValue* regExpProtoFuncExec(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 69 { 70 if (!thisValue->isObject(&RegExpObject::info)) 72 71 return throwError(exec, TypeError); 73 74 return static_cast<RegExpObject*>(thisObj)->exec(exec, args); 75 } 76 77 JSValue* regExpProtoFuncCompile(ExecState* exec, JSObject* thisObj, const ArgList& args) 78 { 79 if (!thisObj->inherits(&RegExpObject::info)) 72 return static_cast<RegExpObject*>(thisValue)->exec(exec, args); 73 } 74 75 JSValue* regExpProtoFuncCompile(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 76 { 77 if (!thisValue->isObject(&RegExpObject::info)) 80 78 return throwError(exec, TypeError); 81 79 … … 97 95 return throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage())); 98 96 99 static_cast<RegExpObject*>(this Obj)->setRegExp(regExp.release());100 static_cast<RegExpObject*>(this Obj)->setLastIndex(0);97 static_cast<RegExpObject*>(thisValue)->setRegExp(regExp.release()); 98 static_cast<RegExpObject*>(thisValue)->setLastIndex(0); 101 99 return jsUndefined(); 102 100 } 103 101 104 JSValue* regExpProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList&)105 { 106 if (!this Obj->inherits(&RegExpObject::info)) {107 if (this Obj->inherits(&RegExpPrototype::info))102 JSValue* regExpProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 103 { 104 if (!thisValue->isObject(&RegExpObject::info)) { 105 if (thisValue->isObject(&RegExpPrototype::info)) 108 106 return jsString(exec, "//"); 109 107 return throwError(exec, TypeError); 110 108 } 111 109 112 UString result = "/" + thisObj->get(exec, exec->propertyNames().source)->toString(exec) + "/";113 if ( thisObj->get(exec, exec->propertyNames().global)->toBoolean(exec))110 UString result = "/" + static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().source)->toString(exec) + "/"; 111 if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().global)->toBoolean(exec)) 114 112 result += "g"; 115 if ( thisObj->get(exec, exec->propertyNames().ignoreCase)->toBoolean(exec))113 if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().ignoreCase)->toBoolean(exec)) 116 114 result += "i"; 117 if ( thisObj->get(exec, exec->propertyNames().multiline)->toBoolean(exec))115 if (static_cast<RegExpObject*>(thisValue)->get(exec, exec->propertyNames().multiline)->toBoolean(exec)) 118 116 result += "m"; 119 117 return jsString(exec, result); … … 125 123 126 124 /* Source for RegExpObject.lut.h 127 @begin regExpTable 5125 @begin regExpTable 128 126 global RegExpObject::Global DontDelete|ReadOnly|DontEnum 129 127 ignoreCase RegExpObject::IgnoreCase DontDelete|ReadOnly|DontEnum … … 230 228 } 231 229 232 CallType RegExpObject::getCallData(CallData&) 233 { 230 static JSValue* callRegExpObject(ExecState* exec, JSObject* function, JSValue*, const ArgList& args) 231 { 232 return static_cast<RegExpObject*>(function)->exec(exec, args); 233 } 234 235 CallType RegExpObject::getCallData(CallData& callData) 236 { 237 callData.native.function = callRegExpObject; 234 238 return CallTypeNative; 235 239 } 236 240 237 JSValue* RegExpObject::callAsFunction(ExecState* exec, JSObject*, const ArgList& args)238 {239 return RegExpObject::exec(exec, args);240 }241 242 241 // ------------------------------ RegExpConstructor ------------------------------ 243 242 … … 245 244 246 245 /* Source for RegExpObject.lut.h 247 @begin regExpConstructorTable 21246 @begin regExpConstructorTable 248 247 input RegExpConstructor::Input None 249 248 $_ RegExpConstructor::Input DontEnum … … 317 316 public: 318 317 RegExpMatchesArray(ExecState*, RegExpConstructorPrivate*); 319 320 318 virtual ~RegExpMatchesArray(); 321 319 320 private: 322 321 virtual bool getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) { if (lazyCreationData()) fillArrayInstance(exec); return JSArray::getOwnPropertySlot(exec, propertyName, slot); } 323 322 virtual bool getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot) { if (lazyCreationData()) fillArrayInstance(exec); return JSArray::getOwnPropertySlot(exec, propertyName, slot); } … … 328 327 virtual void getPropertyNames(ExecState* exec, PropertyNameArray& arr) { if (lazyCreationData()) fillArrayInstance(exec); JSArray::getPropertyNames(exec, arr); } 329 328 330 private:331 329 void fillArrayInstance(ExecState*); 332 330 }; … … 472 470 } 473 471 474 ConstructType RegExpConstructor::getConstructData(ConstructData&)475 {476 return ConstructTypeNative;477 }478 479 472 // ECMA 15.10.4 480 JSObject *RegExpConstructor::construct(ExecState *exec, const ArgList &args)473 static JSObject* constructRegExp(ExecState* exec, const ArgList& args) 481 474 { 482 475 JSValue* arg0 = args[0]; … … 498 491 } 499 492 493 static JSObject* constructWithRegExpConstructor(ExecState* exec, JSObject*, const ArgList& args) 494 { 495 return constructRegExp(exec, args); 496 } 497 498 ConstructType RegExpConstructor::getConstructData(ConstructData& constructData) 499 { 500 constructData.native.function = constructWithRegExpConstructor; 501 return ConstructTypeNative; 502 } 503 500 504 // ECMA 15.10.3 501 JSValue *RegExpConstructor::callAsFunction(ExecState *exec, JSObject * /*thisObj*/, const ArgList &args) 502 { 503 return construct(exec, args); 505 static JSValue* callRegExpConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 506 { 507 return constructRegExp(exec, args); 508 } 509 510 CallType RegExpConstructor::getCallData(CallData& callData) 511 { 512 callData.native.function = callRegExpConstructor; 513 return CallTypeNative; 504 514 } 505 515 -
trunk/JavaScriptCore/kjs/RegExpObject.h
r34659 r34754 47 47 RegExp* regExp() const { return m_regExp.get(); } 48 48 49 JSValue* test(ExecState*, const ArgList& args); 50 JSValue* exec(ExecState*, const ArgList& args); 51 52 virtual CallType getCallData(CallData&); 53 virtual JSValue* callAsFunction(ExecState*, JSObject*, const ArgList&); 49 JSValue* test(ExecState*, const ArgList&); 50 JSValue* exec(ExecState*, const ArgList&); 54 51 55 52 bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); … … 64 61 65 62 private: 66 bool match(ExecState*, const ArgList& args); 63 bool match(ExecState*, const ArgList&); 64 65 virtual CallType getCallData(CallData&); 67 66 68 67 RefPtr<RegExp> m_regExp; … … 77 76 RegExpConstructor(ExecState*, FunctionPrototype*, RegExpPrototype*); 78 77 79 virtual ConstructType getConstructData(ConstructData&);80 virtual JSObject* construct(ExecState*, const ArgList&);81 82 virtual JSValue* callAsFunction(ExecState*, JSObject*, const ArgList&);83 84 78 virtual void put(ExecState*, const Identifier&, JSValue*); 85 79 void putValueProperty(ExecState*, int token, JSValue*); … … 87 81 JSValue* getValueProperty(ExecState*, int token) const; 88 82 89 virtual const ClassInfo* classInfo() const { return &info; }90 83 static const ClassInfo info; 91 84 … … 95 88 96 89 private: 90 virtual ConstructType getConstructData(ConstructData&); 91 virtual CallType getCallData(CallData&); 92 virtual const ClassInfo* classInfo() const { return &info; } 93 97 94 JSValue* getBackref(ExecState*, unsigned) const; 98 95 JSValue* getLastParen(ExecState*) const; -
trunk/JavaScriptCore/kjs/Shell.cpp
r34728 r34754 73 73 static bool fillBufferWithContentsOfFile(const UString& fileName, Vector<char>& buffer); 74 74 75 static JSValue* functionPrint(ExecState*, JSObject*, const ArgList&);76 static JSValue* functionDebug(ExecState*, JSObject*, const ArgList&);77 static JSValue* functionGC(ExecState*, JSObject*, const ArgList&);78 static JSValue* functionVersion(ExecState*, JSObject*, const ArgList&);79 static JSValue* functionRun(ExecState*, JSObject*, const ArgList&);80 static JSValue* functionLoad(ExecState*, JSObject*, const ArgList&);81 static JSValue* functionReadline(ExecState*, JSObject*, const ArgList&);82 static JSValue* functionQuit(ExecState*, JSObject*, const ArgList&);75 static JSValue* functionPrint(ExecState*, JSObject*, JSValue*, const ArgList&); 76 static JSValue* functionDebug(ExecState*, JSObject*, JSValue*, const ArgList&); 77 static JSValue* functionGC(ExecState*, JSObject*, JSValue*, const ArgList&); 78 static JSValue* functionVersion(ExecState*, JSObject*, JSValue*, const ArgList&); 79 static JSValue* functionRun(ExecState*, JSObject*, JSValue*, const ArgList&); 80 static JSValue* functionLoad(ExecState*, JSObject*, JSValue*, const ArgList&); 81 static JSValue* functionReadline(ExecState*, JSObject*, JSValue*, const ArgList&); 82 static JSValue* functionQuit(ExecState*, JSObject*, JSValue*, const ArgList&); 83 83 84 84 struct Options { … … 174 174 putDirectFunction(new (globalExec()) PrototypeFunction(globalExec(), functionPrototype(), 0, Identifier(globalExec(), "readline"), functionReadline)); 175 175 176 JSObject* array = arrayConstructor()->construct(globalExec(), globalExec()->emptyList());176 JSObject* array = constructEmptyArray(globalExec()); 177 177 for (size_t i = 0; i < arguments.size(); ++i) 178 178 array->put(globalExec(), i, jsString(globalExec(), arguments[i])); … … 182 182 } 183 183 184 JSValue* functionPrint(ExecState* exec, JSObject*, const ArgList& args)184 JSValue* functionPrint(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 185 185 { 186 186 for (unsigned i = 0; i < args.size(); ++i) { … … 196 196 } 197 197 198 JSValue* functionDebug(ExecState* exec, JSObject*, const ArgList& args)198 JSValue* functionDebug(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 199 199 { 200 200 fprintf(stderr, "--> %s\n", args[0]->toString(exec).UTF8String().c_str()); … … 202 202 } 203 203 204 JSValue* functionGC(ExecState* exec, JSObject*, const ArgList&)204 JSValue* functionGC(ExecState* exec, JSObject*, JSValue*, const ArgList&) 205 205 { 206 206 JSLock lock; … … 209 209 } 210 210 211 JSValue* functionVersion(ExecState*, JSObject*, const ArgList&)211 JSValue* functionVersion(ExecState*, JSObject*, JSValue*, const ArgList&) 212 212 { 213 213 // We need this function for compatibility with the Mozilla JS tests but for now … … 216 216 } 217 217 218 JSValue* functionRun(ExecState* exec, JSObject*, const ArgList& args)218 JSValue* functionRun(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 219 219 { 220 220 StopWatch stopWatch; … … 233 233 } 234 234 235 JSValue* functionLoad(ExecState* exec, JSObject*, const ArgList& args)235 JSValue* functionLoad(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 236 236 { 237 237 UString fileName = args[0]->toString(exec); … … 246 246 } 247 247 248 JSValue* functionReadline(ExecState* exec, JSObject*, const ArgList&)248 JSValue* functionReadline(ExecState* exec, JSObject*, JSValue*, const ArgList&) 249 249 { 250 250 Vector<char, 256> line; … … 260 260 } 261 261 262 JSValue* functionQuit(ExecState*, JSObject*, const ArgList&)262 JSValue* functionQuit(ExecState*, JSObject*, JSValue*, const ArgList&) 263 263 { 264 264 exit(0); -
trunk/JavaScriptCore/kjs/date_object.cpp
r34659 r34754 22 22 #include "config.h" 23 23 #include "date_object.h" 24 #include "date_object.lut.h" 24 25 #include "DateMath.h" 25 26 #include "JSString.h" 26 27 #if HAVE(ERRNO_H) 28 #include <errno.h> 29 #endif 30 31 #if HAVE(SYS_PARAM_H) 32 #include <sys/param.h> 33 #endif 34 35 #if HAVE(SYS_TIME_H) 36 #include <sys/time.h> 37 #endif 38 39 #if HAVE(SYS_TIMEB_H) 40 #include <sys/timeb.h> 41 #endif 42 27 #include "error_object.h" 28 #include "operations.h" 43 29 #include <float.h> 44 30 #include <limits.h> … … 49 35 #include <string.h> 50 36 #include <time.h> 51 52 #include "error_object.h"53 #include "operations.h"54 #include "DateMath.h"55 56 37 #include <wtf/ASCIICType.h> 57 38 #include <wtf/Assertions.h> … … 60 41 #include <wtf/UnusedParam.h> 61 42 43 #if HAVE(ERRNO_H) 44 #include <errno.h> 45 #endif 46 47 #if HAVE(SYS_PARAM_H) 48 #include <sys/param.h> 49 #endif 50 51 #if HAVE(SYS_TIME_H) 52 #include <sys/time.h> 53 #endif 54 55 #if HAVE(SYS_TIMEB_H) 56 #include <sys/timeb.h> 57 #endif 58 62 59 #if PLATFORM(MAC) 63 60 #include <CoreFoundation/CoreFoundation.h> 64 61 #endif 65 62 66 63 using namespace WTF; 64 65 namespace KJS { 66 67 static JSValue* dateProtoFuncGetDate(ExecState*, JSObject*, JSValue*, const ArgList&); 68 static JSValue* dateProtoFuncGetDay(ExecState*, JSObject*, JSValue*, const ArgList&); 69 static JSValue* dateProtoFuncGetFullYear(ExecState*, JSObject*, JSValue*, const ArgList&); 70 static JSValue* dateProtoFuncGetHours(ExecState*, JSObject*, JSValue*, const ArgList&); 71 static JSValue* dateProtoFuncGetMilliSeconds(ExecState*, JSObject*, JSValue*, const ArgList&); 72 static JSValue* dateProtoFuncGetMinutes(ExecState*, JSObject*, JSValue*, const ArgList&); 73 static JSValue* dateProtoFuncGetMonth(ExecState*, JSObject*, JSValue*, const ArgList&); 74 static JSValue* dateProtoFuncGetSeconds(ExecState*, JSObject*, JSValue*, const ArgList&); 75 static JSValue* dateProtoFuncGetTime(ExecState*, JSObject*, JSValue*, const ArgList&); 76 static JSValue* dateProtoFuncGetTimezoneOffset(ExecState*, JSObject*, JSValue*, const ArgList&); 77 static JSValue* dateProtoFuncGetUTCDate(ExecState*, JSObject*, JSValue*, const ArgList&); 78 static JSValue* dateProtoFuncGetUTCDay(ExecState*, JSObject*, JSValue*, const ArgList&); 79 static JSValue* dateProtoFuncGetUTCFullYear(ExecState*, JSObject*, JSValue*, const ArgList&); 80 static JSValue* dateProtoFuncGetUTCHours(ExecState*, JSObject*, JSValue*, const ArgList&); 81 static JSValue* dateProtoFuncGetUTCMilliseconds(ExecState*, JSObject*, JSValue*, const ArgList&); 82 static JSValue* dateProtoFuncGetUTCMinutes(ExecState*, JSObject*, JSValue*, const ArgList&); 83 static JSValue* dateProtoFuncGetUTCMonth(ExecState*, JSObject*, JSValue*, const ArgList&); 84 static JSValue* dateProtoFuncGetUTCSeconds(ExecState*, JSObject*, JSValue*, const ArgList&); 85 static JSValue* dateProtoFuncGetYear(ExecState*, JSObject*, JSValue*, const ArgList&); 86 static JSValue* dateProtoFuncSetDate(ExecState*, JSObject*, JSValue*, const ArgList&); 87 static JSValue* dateProtoFuncSetFullYear(ExecState*, JSObject*, JSValue*, const ArgList&); 88 static JSValue* dateProtoFuncSetHours(ExecState*, JSObject*, JSValue*, const ArgList&); 89 static JSValue* dateProtoFuncSetMilliSeconds(ExecState*, JSObject*, JSValue*, const ArgList&); 90 static JSValue* dateProtoFuncSetMinutes(ExecState*, JSObject*, JSValue*, const ArgList&); 91 static JSValue* dateProtoFuncSetMonth(ExecState*, JSObject*, JSValue*, const ArgList&); 92 static JSValue* dateProtoFuncSetSeconds(ExecState*, JSObject*, JSValue*, const ArgList&); 93 static JSValue* dateProtoFuncSetTime(ExecState*, JSObject*, JSValue*, const ArgList&); 94 static JSValue* dateProtoFuncSetUTCDate(ExecState*, JSObject*, JSValue*, const ArgList&); 95 static JSValue* dateProtoFuncSetUTCFullYear(ExecState*, JSObject*, JSValue*, const ArgList&); 96 static JSValue* dateProtoFuncSetUTCHours(ExecState*, JSObject*, JSValue*, const ArgList&); 97 static JSValue* dateProtoFuncSetUTCMilliseconds(ExecState*, JSObject*, JSValue*, const ArgList&); 98 static JSValue* dateProtoFuncSetUTCMinutes(ExecState*, JSObject*, JSValue*, const ArgList&); 99 static JSValue* dateProtoFuncSetUTCMonth(ExecState*, JSObject*, JSValue*, const ArgList&); 100 static JSValue* dateProtoFuncSetUTCSeconds(ExecState*, JSObject*, JSValue*, const ArgList&); 101 static JSValue* dateProtoFuncSetYear(ExecState*, JSObject*, JSValue*, const ArgList&); 102 static JSValue* dateProtoFuncToDateString(ExecState*, JSObject*, JSValue*, const ArgList&); 103 static JSValue* dateProtoFuncToGMTString(ExecState*, JSObject*, JSValue*, const ArgList&); 104 static JSValue* dateProtoFuncToLocaleDateString(ExecState*, JSObject*, JSValue*, const ArgList&); 105 static JSValue* dateProtoFuncToLocaleString(ExecState*, JSObject*, JSValue*, const ArgList&); 106 static JSValue* dateProtoFuncToLocaleTimeString(ExecState*, JSObject*, JSValue*, const ArgList&); 107 static JSValue* dateProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&); 108 static JSValue* dateProtoFuncToTimeString(ExecState*, JSObject*, JSValue*, const ArgList&); 109 static JSValue* dateProtoFuncToUTCString(ExecState*, JSObject*, JSValue*, const ArgList&); 110 static JSValue* dateProtoFuncValueOf(ExecState*, JSObject*, JSValue*, const ArgList&); 111 112 } 113 114 #include "date_object.lut.h" 67 115 68 116 namespace KJS { … … 71 119 static double timeClip(double); 72 120 73 inline int gmtoffset(const GregorianDateTime& t)121 static inline int gmtoffset(const GregorianDateTime& t) 74 122 { 75 123 return t.utcOffset; 76 124 } 77 78 79 /**80 * @internal81 *82 * Class to implement all methods that are properties of the83 * Date object84 */85 class DateFunction : public InternalFunction {86 public:87 DateFunction(ExecState *, FunctionPrototype *, int i, int len, const Identifier& );88 89 virtual JSValue *callAsFunction(ExecState *, JSObject *thisObj, const ArgList &args);90 91 enum { Parse, UTC, Now };92 93 private:94 int id;95 };96 125 97 126 struct DateInstance::Cache { … … 117 146 } 118 147 119 static UString formatLocaleDate(ExecState *exec, double time, bool includeDate, bool includeTime, const ArgList &args)148 static UString formatLocaleDate(ExecState *exec, double time, bool includeDate, bool includeTime, const ArgList& args) 120 149 { 121 150 CFDateFormatterStyle dateStyle = (includeDate ? kCFDateFormatterLongStyle : kCFDateFormatterNoStyle); … … 302 331 // 303 332 // Format of member function: f([years,] [months,] [days]) 304 static bool fillStructuresUsingDateArgs(ExecState *exec, const ArgList &args, int maxArgs, double *ms, GregorianDateTime *t)333 static bool fillStructuresUsingDateArgs(ExecState *exec, const ArgList& args, int maxArgs, double *ms, GregorianDateTime *t) 305 334 { 306 335 int idx = 0; … … 369 398 bool DateInstance::getTime(GregorianDateTime &t, int &offset) const 370 399 { 371 double milli = internal Value()->getNumber();400 double milli = internalNumber(); 372 401 if (isnan(milli)) 373 402 return false; … … 380 409 bool DateInstance::getUTCTime(GregorianDateTime &t) const 381 410 { 382 double milli = internal Value()->getNumber();411 double milli = internalNumber(); 383 412 if (isnan(milli)) 384 413 return false; … … 390 419 bool DateInstance::getTime(double &milli, int &offset) const 391 420 { 392 milli = internal Value()->getNumber();421 milli = internalNumber(); 393 422 if (isnan(milli)) 394 423 return false; … … 402 431 bool DateInstance::getUTCTime(double &milli) const 403 432 { 404 milli = internal Value()->getNumber();433 milli = internalNumber(); 405 434 if (isnan(milli)) 406 435 return false; … … 420 449 421 450 /* Source for date_object.lut.h 422 FIXME LWe could use templates to simplify the UTC variants.423 @begin dateTable 61451 FIXME: We could use templates to simplify the UTC variants. 452 @begin dateTable 424 453 toString dateProtoFuncToString DontEnum|Function 0 425 454 toUTCString dateProtoFuncToUTCString DontEnum|Function 0 … … 486 515 // TODO: MakeTime (15.9.11.1) etc. ? 487 516 517 static JSValue* dateParse(ExecState*, JSObject*, JSValue*, const ArgList&); 518 static JSValue* dateNow(ExecState*, JSObject*, JSValue*, const ArgList&); 519 static JSValue* dateUTC(ExecState*, JSObject*, JSValue*, const ArgList&); 520 488 521 DateConstructor::DateConstructor(ExecState* exec, FunctionPrototype* funcProto, DatePrototype* dateProto) 489 522 : InternalFunction(funcProto, Identifier(exec, dateProto->classInfo()->className)) 490 523 { 491 524 putDirect(exec->propertyNames().prototype, dateProto, DontEnum|DontDelete|ReadOnly); 492 putDirectFunction(new (exec) DateFunction(exec, funcProto, DateFunction::Parse, 1, exec->propertyNames().parse), DontEnum); 493 putDirectFunction(new (exec) DateFunction(exec, funcProto, DateFunction::UTC, 7, exec->propertyNames().UTC), DontEnum); 494 putDirectFunction(new (exec) DateFunction(exec, funcProto, DateFunction::Now, 0, exec->propertyNames().now), DontEnum); 495 putDirect(exec, exec->propertyNames().length, 7, ReadOnly|DontDelete|DontEnum); 496 } 497 498 ConstructType DateConstructor::getConstructData(ConstructData&) 499 { 500 return ConstructTypeNative; 525 putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 1, exec->propertyNames().parse, dateParse), DontEnum); 526 putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 7, exec->propertyNames().UTC, dateUTC), DontEnum); 527 putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 0, exec->propertyNames().now, dateNow), DontEnum); 528 putDirect(exec, exec->propertyNames().length, 7, ReadOnly | DontEnum | DontDelete); 501 529 } 502 530 503 531 // ECMA 15.9.3 504 JSObject *DateConstructor::construct(ExecState *exec, const ArgList &args)532 static JSObject* constructDate(ExecState* exec, JSObject*, const ArgList& args) 505 533 { 506 534 int numArgs = args.size(); … … 512 540 } else if (numArgs == 1) { 513 541 if (args[0]->isObject(&DateInstance::info)) 514 value = static_cast<DateInstance*>(args[0])->internal Value()->toNumber(exec);542 value = static_cast<DateInstance*>(args[0])->internalNumber(); 515 543 else { 516 544 JSValue* primitive = args[0]->toPrimitive(exec); … … 549 577 } 550 578 579 ConstructType DateConstructor::getConstructData(ConstructData& constructData) 580 { 581 constructData.native.function = constructDate; 582 return ConstructTypeNative; 583 } 584 551 585 // ECMA 15.9.2 552 JSValue* DateConstructor::callAsFunction(ExecState* exec, JSObject * /*thisObj*/, const ArgList &/*args*/)586 static JSValue* callDate(ExecState* exec, JSObject*, JSValue*, const ArgList&) 553 587 { 554 588 time_t localTime = time(0); … … 559 593 } 560 594 561 // ------------------------------ DateFunction ---------------------------- 562 563 DateFunction::DateFunction(ExecState* exec, FunctionPrototype* funcProto, int i, int len, const Identifier& name) 564 : InternalFunction(funcProto, name), id(i) 565 { 566 putDirect(exec, exec->propertyNames().length, len, DontDelete|ReadOnly|DontEnum); 567 } 568 569 // ECMA 15.9.4.2 - 3 570 JSValue *DateFunction::callAsFunction(ExecState* exec, JSObject*, const ArgList& args) 571 { 572 if (id == Parse) 595 CallType DateConstructor::getCallData(CallData& callData) 596 { 597 callData.native.function = callDate; 598 return CallTypeNative; 599 } 600 601 static JSValue* dateParse(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 602 { 573 603 return jsNumber(exec, parseDate(args[0]->toString(exec))); 574 else if (id == Now) 604 } 605 606 static JSValue* dateNow(ExecState* exec, JSObject*, JSValue*, const ArgList&) 607 { 575 608 return jsNumber(exec, getCurrentUTCTime()); 576 else { // UTC 609 } 610 611 static JSValue* dateUTC(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 612 { 577 613 int n = args.size(); 578 614 if (isnan(args[0]->toNumber(exec)) 579 || isnan(args[1]->toNumber(exec))580 || (n >= 3 && isnan(args[2]->toNumber(exec)))581 || (n >= 4 && isnan(args[3]->toNumber(exec)))582 || (n >= 5 && isnan(args[4]->toNumber(exec)))583 || (n >= 6 && isnan(args[5]->toNumber(exec)))584 || (n >= 7 && isnan(args[6]->toNumber(exec)))) {585 return jsNaN(exec);615 || isnan(args[1]->toNumber(exec)) 616 || (n >= 3 && isnan(args[2]->toNumber(exec))) 617 || (n >= 4 && isnan(args[3]->toNumber(exec))) 618 || (n >= 5 && isnan(args[4]->toNumber(exec))) 619 || (n >= 6 && isnan(args[5]->toNumber(exec))) 620 || (n >= 7 && isnan(args[6]->toNumber(exec)))) { 621 return jsNaN(exec); 586 622 } 587 623 … … 596 632 double ms = (n >= 7) ? args[6]->toNumber(exec) : 0; 597 633 return jsNumber(exec, gregorianDateTimeToMS(t, ms, true)); 598 }599 634 } 600 635 … … 979 1014 // Functions 980 1015 981 JSValue* dateProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList&)982 { 983 if (!this Obj->inherits(&DateInstance::info))1016 JSValue* dateProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1017 { 1018 if (!thisValue->isObject(&DateInstance::info)) 984 1019 return throwError(exec, TypeError); 985 1020 986 1021 const bool utc = false; 987 1022 988 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 989 JSValue* v = thisDateObj->internalValue(); 990 double milli = v->toNumber(exec); 1023 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1024 double milli = thisDateObj->internalNumber(); 991 1025 if (isnan(milli)) 992 1026 return jsString(exec, "Invalid Date"); … … 997 1031 } 998 1032 999 JSValue* dateProtoFuncToUTCString(ExecState* exec, JSObject* thisObj, const ArgList&)1000 { 1001 if (!this Obj->inherits(&DateInstance::info))1033 JSValue* dateProtoFuncToUTCString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1034 { 1035 if (!thisValue->isObject(&DateInstance::info)) 1002 1036 return throwError(exec, TypeError); 1003 1037 1004 1038 const bool utc = true; 1005 1039 1006 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1007 JSValue* v = thisDateObj->internalValue(); 1008 double milli = v->toNumber(exec); 1040 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1041 double milli = thisDateObj->internalNumber(); 1009 1042 if (isnan(milli)) 1010 1043 return jsString(exec, "Invalid Date"); … … 1015 1048 } 1016 1049 1017 JSValue* dateProtoFuncToDateString(ExecState* exec, JSObject* thisObj, const ArgList&)1018 { 1019 if (!this Obj->inherits(&DateInstance::info))1050 JSValue* dateProtoFuncToDateString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1051 { 1052 if (!thisValue->isObject(&DateInstance::info)) 1020 1053 return throwError(exec, TypeError); 1021 1054 1022 1055 const bool utc = false; 1023 1056 1024 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1025 JSValue* v = thisDateObj->internalValue(); 1026 double milli = v->toNumber(exec); 1057 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1058 double milli = thisDateObj->internalNumber(); 1027 1059 if (isnan(milli)) 1028 1060 return jsString(exec, "Invalid Date"); … … 1033 1065 } 1034 1066 1035 JSValue* dateProtoFuncToTimeString(ExecState* exec, JSObject* thisObj, const ArgList&)1036 { 1037 if (!this Obj->inherits(&DateInstance::info))1067 JSValue* dateProtoFuncToTimeString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1068 { 1069 if (!thisValue->isObject(&DateInstance::info)) 1038 1070 return throwError(exec, TypeError); 1039 1071 1040 1072 const bool utc = false; 1041 1073 1042 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1043 JSValue* v = thisDateObj->internalValue(); 1044 double milli = v->toNumber(exec); 1074 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1075 double milli = thisDateObj->internalNumber(); 1045 1076 if (isnan(milli)) 1046 1077 return jsString(exec, "Invalid Date"); … … 1051 1082 } 1052 1083 1053 JSValue* dateProtoFuncToLocaleString(ExecState* exec, JSObject* thisObj, const ArgList& args) 1054 { 1055 if (!thisObj->inherits(&DateInstance::info)) 1056 return throwError(exec, TypeError); 1057 1058 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1059 JSValue* v = thisDateObj->internalValue(); 1060 double milli = v->toNumber(exec); 1084 JSValue* dateProtoFuncToLocaleString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1085 { 1086 if (!thisValue->isObject(&DateInstance::info)) 1087 return throwError(exec, TypeError); 1088 1089 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1090 double milli = thisDateObj->internalNumber(); 1061 1091 if (isnan(milli)) 1062 1092 return jsString(exec, "Invalid Date"); … … 1076 1106 } 1077 1107 1078 JSValue* dateProtoFuncToLocaleDateString(ExecState* exec, JSObject* thisObj, const ArgList& args) 1079 { 1080 if (!thisObj->inherits(&DateInstance::info)) 1081 return throwError(exec, TypeError); 1082 1083 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1084 JSValue* v = thisDateObj->internalValue(); 1085 double milli = v->toNumber(exec); 1108 JSValue* dateProtoFuncToLocaleDateString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1109 { 1110 if (!thisValue->isObject(&DateInstance::info)) 1111 return throwError(exec, TypeError); 1112 1113 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1114 double milli = thisDateObj->internalNumber(); 1086 1115 if (isnan(milli)) 1087 1116 return jsString(exec, "Invalid Date"); … … 1101 1130 } 1102 1131 1103 JSValue* dateProtoFuncToLocaleTimeString(ExecState* exec, JSObject* thisObj, const ArgList& args) 1104 { 1105 if (!thisObj->inherits(&DateInstance::info)) 1106 return throwError(exec, TypeError); 1107 1108 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1109 JSValue* v = thisDateObj->internalValue(); 1110 double milli = v->toNumber(exec); 1132 JSValue* dateProtoFuncToLocaleTimeString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1133 { 1134 if (!thisValue->isObject(&DateInstance::info)) 1135 return throwError(exec, TypeError); 1136 1137 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1138 double milli = thisDateObj->internalNumber(); 1111 1139 if (isnan(milli)) 1112 1140 return jsString(exec, "Invalid Date"); … … 1126 1154 } 1127 1155 1128 JSValue* dateProtoFuncValueOf(ExecState* exec, JSObject* thisObj, const ArgList&) 1129 { 1130 if (!thisObj->inherits(&DateInstance::info)) 1131 return throwError(exec, TypeError); 1132 1133 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1134 JSValue* v = thisDateObj->internalValue(); 1135 double milli = v->toNumber(exec); 1156 JSValue* dateProtoFuncValueOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1157 { 1158 if (!thisValue->isObject(&DateInstance::info)) 1159 return throwError(exec, TypeError); 1160 1161 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1162 double milli = thisDateObj->internalNumber(); 1136 1163 if (isnan(milli)) 1137 1164 return jsNaN(exec); … … 1140 1167 } 1141 1168 1142 JSValue* dateProtoFuncGetTime(ExecState* exec, JSObject* thisObj, const ArgList&) 1143 { 1144 if (!thisObj->inherits(&DateInstance::info)) 1145 return throwError(exec, TypeError); 1146 1147 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1148 JSValue* v = thisDateObj->internalValue(); 1149 double milli = v->toNumber(exec); 1169 JSValue* dateProtoFuncGetTime(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1170 { 1171 if (!thisValue->isObject(&DateInstance::info)) 1172 return throwError(exec, TypeError); 1173 1174 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1175 double milli = thisDateObj->internalNumber(); 1150 1176 if (isnan(milli)) 1151 1177 return jsNaN(exec); … … 1154 1180 } 1155 1181 1156 JSValue* dateProtoFuncGetFullYear(ExecState* exec, JSObject* thisObj, const ArgList&)1157 { 1158 if (!this Obj->inherits(&DateInstance::info))1182 JSValue* dateProtoFuncGetFullYear(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1183 { 1184 if (!thisValue->isObject(&DateInstance::info)) 1159 1185 return throwError(exec, TypeError); 1160 1186 1161 1187 const bool utc = false; 1162 1188 1163 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1164 JSValue* v = thisDateObj->internalValue(); 1165 double milli = v->toNumber(exec); 1189 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1190 double milli = thisDateObj->internalNumber(); 1166 1191 if (isnan(milli)) 1167 1192 return jsNaN(exec); … … 1172 1197 } 1173 1198 1174 JSValue* dateProtoFuncGetUTCFullYear(ExecState* exec, JSObject* thisObj, const ArgList&)1175 { 1176 if (!this Obj->inherits(&DateInstance::info))1199 JSValue* dateProtoFuncGetUTCFullYear(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1200 { 1201 if (!thisValue->isObject(&DateInstance::info)) 1177 1202 return throwError(exec, TypeError); 1178 1203 1179 1204 const bool utc = true; 1180 1205 1181 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1182 JSValue* v = thisDateObj->internalValue(); 1183 double milli = v->toNumber(exec); 1206 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1207 double milli = thisDateObj->internalNumber(); 1184 1208 if (isnan(milli)) 1185 1209 return jsNaN(exec); … … 1190 1214 } 1191 1215 1192 JSValue* dateProtoFuncToGMTString(ExecState* exec, JSObject* thisObj, const ArgList&)1193 { 1194 if (!this Obj->inherits(&DateInstance::info))1216 JSValue* dateProtoFuncToGMTString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1217 { 1218 if (!thisValue->isObject(&DateInstance::info)) 1195 1219 return throwError(exec, TypeError); 1196 1220 1197 1221 const bool utc = true; 1198 1222 1199 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1200 JSValue* v = thisDateObj->internalValue(); 1201 double milli = v->toNumber(exec); 1223 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1224 double milli = thisDateObj->internalNumber(); 1202 1225 if (isnan(milli)) 1203 1226 return jsString(exec, "Invalid Date"); … … 1208 1231 } 1209 1232 1210 JSValue* dateProtoFuncGetMonth(ExecState* exec, JSObject* thisObj, const ArgList&)1211 { 1212 if (!this Obj->inherits(&DateInstance::info))1233 JSValue* dateProtoFuncGetMonth(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1234 { 1235 if (!thisValue->isObject(&DateInstance::info)) 1213 1236 return throwError(exec, TypeError); 1214 1237 1215 1238 const bool utc = false; 1216 1239 1217 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1218 JSValue* v = thisDateObj->internalValue(); 1219 double milli = v->toNumber(exec); 1240 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1241 double milli = thisDateObj->internalNumber(); 1220 1242 if (isnan(milli)) 1221 1243 return jsNaN(exec); … … 1226 1248 } 1227 1249 1228 JSValue* dateProtoFuncGetUTCMonth(ExecState* exec, JSObject* thisObj, const ArgList&)1229 { 1230 if (!this Obj->inherits(&DateInstance::info))1250 JSValue* dateProtoFuncGetUTCMonth(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1251 { 1252 if (!thisValue->isObject(&DateInstance::info)) 1231 1253 return throwError(exec, TypeError); 1232 1254 1233 1255 const bool utc = true; 1234 1256 1235 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1236 JSValue* v = thisDateObj->internalValue(); 1237 double milli = v->toNumber(exec); 1257 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1258 double milli = thisDateObj->internalNumber(); 1238 1259 if (isnan(milli)) 1239 1260 return jsNaN(exec); … … 1244 1265 } 1245 1266 1246 JSValue* dateProtoFuncGetDate(ExecState* exec, JSObject* thisObj, const ArgList&)1247 { 1248 if (!this Obj->inherits(&DateInstance::info))1267 JSValue* dateProtoFuncGetDate(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1268 { 1269 if (!thisValue->isObject(&DateInstance::info)) 1249 1270 return throwError(exec, TypeError); 1250 1271 1251 1272 const bool utc = false; 1252 1273 1253 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1254 JSValue* v = thisDateObj->internalValue(); 1255 double milli = v->toNumber(exec); 1274 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1275 double milli = thisDateObj->internalNumber(); 1256 1276 if (isnan(milli)) 1257 1277 return jsNaN(exec); … … 1262 1282 } 1263 1283 1264 JSValue* dateProtoFuncGetUTCDate(ExecState* exec, JSObject* thisObj, const ArgList&)1265 { 1266 if (!this Obj->inherits(&DateInstance::info))1284 JSValue* dateProtoFuncGetUTCDate(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1285 { 1286 if (!thisValue->isObject(&DateInstance::info)) 1267 1287 return throwError(exec, TypeError); 1268 1288 1269 1289 const bool utc = true; 1270 1290 1271 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1272 JSValue* v = thisDateObj->internalValue(); 1273 double milli = v->toNumber(exec); 1291 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1292 double milli = thisDateObj->internalNumber(); 1274 1293 if (isnan(milli)) 1275 1294 return jsNaN(exec); … … 1280 1299 } 1281 1300 1282 JSValue* dateProtoFuncGetDay(ExecState* exec, JSObject* thisObj, const ArgList&)1283 { 1284 if (!this Obj->inherits(&DateInstance::info))1301 JSValue* dateProtoFuncGetDay(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1302 { 1303 if (!thisValue->isObject(&DateInstance::info)) 1285 1304 return throwError(exec, TypeError); 1286 1305 1287 1306 const bool utc = false; 1288 1307 1289 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1290 JSValue* v = thisDateObj->internalValue(); 1291 double milli = v->toNumber(exec); 1308 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1309 double milli = thisDateObj->internalNumber(); 1292 1310 if (isnan(milli)) 1293 1311 return jsNaN(exec); … … 1298 1316 } 1299 1317 1300 JSValue* dateProtoFuncGetUTCDay(ExecState* exec, JSObject* thisObj, const ArgList&)1301 { 1302 if (!this Obj->inherits(&DateInstance::info))1318 JSValue* dateProtoFuncGetUTCDay(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1319 { 1320 if (!thisValue->isObject(&DateInstance::info)) 1303 1321 return throwError(exec, TypeError); 1304 1322 1305 1323 const bool utc = true; 1306 1324 1307 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1308 JSValue* v = thisDateObj->internalValue(); 1309 double milli = v->toNumber(exec); 1325 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1326 double milli = thisDateObj->internalNumber(); 1310 1327 if (isnan(milli)) 1311 1328 return jsNaN(exec); … … 1316 1333 } 1317 1334 1318 JSValue* dateProtoFuncGetHours(ExecState* exec, JSObject* thisObj, const ArgList&)1319 { 1320 if (!this Obj->inherits(&DateInstance::info))1335 JSValue* dateProtoFuncGetHours(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1336 { 1337 if (!thisValue->isObject(&DateInstance::info)) 1321 1338 return throwError(exec, TypeError); 1322 1339 1323 1340 const bool utc = false; 1324 1341 1325 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1326 JSValue* v = thisDateObj->internalValue(); 1327 double milli = v->toNumber(exec); 1342 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1343 double milli = thisDateObj->internalNumber(); 1328 1344 if (isnan(milli)) 1329 1345 return jsNaN(exec); … … 1334 1350 } 1335 1351 1336 JSValue* dateProtoFuncGetUTCHours(ExecState* exec, JSObject* thisObj, const ArgList&)1337 { 1338 if (!this Obj->inherits(&DateInstance::info))1352 JSValue* dateProtoFuncGetUTCHours(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1353 { 1354 if (!thisValue->isObject(&DateInstance::info)) 1339 1355 return throwError(exec, TypeError); 1340 1356 1341 1357 const bool utc = true; 1342 1358 1343 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1344 JSValue* v = thisDateObj->internalValue(); 1345 double milli = v->toNumber(exec); 1359 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1360 double milli = thisDateObj->internalNumber(); 1346 1361 if (isnan(milli)) 1347 1362 return jsNaN(exec); … … 1352 1367 } 1353 1368 1354 JSValue* dateProtoFuncGetMinutes(ExecState* exec, JSObject* thisObj, const ArgList&)1355 { 1356 if (!this Obj->inherits(&DateInstance::info))1369 JSValue* dateProtoFuncGetMinutes(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1370 { 1371 if (!thisValue->isObject(&DateInstance::info)) 1357 1372 return throwError(exec, TypeError); 1358 1373 1359 1374 const bool utc = false; 1360 1375 1361 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1362 JSValue* v = thisDateObj->internalValue(); 1363 double milli = v->toNumber(exec); 1376 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1377 double milli = thisDateObj->internalNumber(); 1364 1378 if (isnan(milli)) 1365 1379 return jsNaN(exec); … … 1370 1384 } 1371 1385 1372 JSValue* dateProtoFuncGetUTCMinutes(ExecState* exec, JSObject* thisObj, const ArgList&)1373 { 1374 if (!this Obj->inherits(&DateInstance::info))1386 JSValue* dateProtoFuncGetUTCMinutes(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1387 { 1388 if (!thisValue->isObject(&DateInstance::info)) 1375 1389 return throwError(exec, TypeError); 1376 1390 1377 1391 const bool utc = true; 1378 1392 1379 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1380 JSValue* v = thisDateObj->internalValue(); 1381 double milli = v->toNumber(exec); 1393 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1394 double milli = thisDateObj->internalNumber(); 1382 1395 if (isnan(milli)) 1383 1396 return jsNaN(exec); … … 1388 1401 } 1389 1402 1390 JSValue* dateProtoFuncGetSeconds(ExecState* exec, JSObject* thisObj, const ArgList&)1391 { 1392 if (!this Obj->inherits(&DateInstance::info))1403 JSValue* dateProtoFuncGetSeconds(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1404 { 1405 if (!thisValue->isObject(&DateInstance::info)) 1393 1406 return throwError(exec, TypeError); 1394 1407 1395 1408 const bool utc = false; 1396 1409 1397 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1398 JSValue* v = thisDateObj->internalValue(); 1399 double milli = v->toNumber(exec); 1410 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1411 double milli = thisDateObj->internalNumber(); 1400 1412 if (isnan(milli)) 1401 1413 return jsNaN(exec); … … 1406 1418 } 1407 1419 1408 JSValue* dateProtoFuncGetUTCSeconds(ExecState* exec, JSObject* thisObj, const ArgList&)1409 { 1410 if (!this Obj->inherits(&DateInstance::info))1420 JSValue* dateProtoFuncGetUTCSeconds(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1421 { 1422 if (!thisValue->isObject(&DateInstance::info)) 1411 1423 return throwError(exec, TypeError); 1412 1424 1413 1425 const bool utc = true; 1414 1426 1415 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1416 JSValue* v = thisDateObj->internalValue(); 1417 double milli = v->toNumber(exec); 1427 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1428 double milli = thisDateObj->internalNumber(); 1418 1429 if (isnan(milli)) 1419 1430 return jsNaN(exec); … … 1424 1435 } 1425 1436 1426 JSValue* dateProtoFuncGetMilliSeconds(ExecState* exec, JSObject* thisObj, const ArgList&) 1427 { 1428 if (!thisObj->inherits(&DateInstance::info)) 1429 return throwError(exec, TypeError); 1430 1431 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1432 JSValue* v = thisDateObj->internalValue(); 1433 double milli = v->toNumber(exec); 1437 JSValue* dateProtoFuncGetMilliSeconds(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1438 { 1439 if (!thisValue->isObject(&DateInstance::info)) 1440 return throwError(exec, TypeError); 1441 1442 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1443 double milli = thisDateObj->internalNumber(); 1434 1444 if (isnan(milli)) 1435 1445 return jsNaN(exec); … … 1440 1450 } 1441 1451 1442 JSValue* dateProtoFuncGetUTCMilliseconds(ExecState* exec, JSObject* thisObj, const ArgList&) 1443 { 1444 if (!thisObj->inherits(&DateInstance::info)) 1445 return throwError(exec, TypeError); 1446 1447 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1448 JSValue* v = thisDateObj->internalValue(); 1449 double milli = v->toNumber(exec); 1452 JSValue* dateProtoFuncGetUTCMilliseconds(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1453 { 1454 if (!thisValue->isObject(&DateInstance::info)) 1455 return throwError(exec, TypeError); 1456 1457 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1458 double milli = thisDateObj->internalNumber(); 1450 1459 if (isnan(milli)) 1451 1460 return jsNaN(exec); … … 1456 1465 } 1457 1466 1458 JSValue* dateProtoFuncGetTimezoneOffset(ExecState* exec, JSObject* thisObj, const ArgList&)1459 { 1460 if (!this Obj->inherits(&DateInstance::info))1467 JSValue* dateProtoFuncGetTimezoneOffset(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1468 { 1469 if (!thisValue->isObject(&DateInstance::info)) 1461 1470 return throwError(exec, TypeError); 1462 1471 1463 1472 const bool utc = false; 1464 1473 1465 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1466 JSValue* v = thisDateObj->internalValue(); 1467 double milli = v->toNumber(exec); 1474 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1475 double milli = thisDateObj->internalNumber(); 1468 1476 if (isnan(milli)) 1469 1477 return jsNaN(exec); … … 1474 1482 } 1475 1483 1476 JSValue* dateProtoFuncSetTime(ExecState* exec, JSObject* thisObj, const ArgList& args)1477 { 1478 if (!this Obj->inherits(&DateInstance::info))1479 return throwError(exec, TypeError); 1480 1481 DateInstance* thisDateObj = static_cast<DateInstance*>(this Obj);1484 JSValue* dateProtoFuncSetTime(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1485 { 1486 if (!thisValue->isObject(&DateInstance::info)) 1487 return throwError(exec, TypeError); 1488 1489 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1482 1490 1483 1491 double milli = timeClip(args[0]->toNumber(exec)); … … 1487 1495 } 1488 1496 1489 static JSValue* setNewValueFromTimeArgs(ExecState* exec, JSObject* thisObj, const ArgList& args, int numArgsToUse, bool inputIsUTC) 1490 { 1491 if (!thisObj->inherits(&DateInstance::info)) 1492 return throwError(exec, TypeError); 1493 1494 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1495 JSValue* v = thisDateObj->internalValue(); 1496 double milli = v->toNumber(exec); 1497 static JSValue* setNewValueFromTimeArgs(ExecState* exec, JSValue* thisValue, const ArgList& args, int numArgsToUse, bool inputIsUTC) 1498 { 1499 if (!thisValue->isObject(&DateInstance::info)) 1500 return throwError(exec, TypeError); 1501 1502 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1503 double milli = thisDateObj->internalNumber(); 1497 1504 1498 1505 if (args.isEmpty() || isnan(milli)) { … … 1519 1526 } 1520 1527 1521 static JSValue* setNewValueFromDateArgs(ExecState* exec, JS Object* thisObj, const ArgList& args, int numArgsToUse, bool inputIsUTC)1522 { 1523 if (!this Obj->inherits(&DateInstance::info))1524 return throwError(exec, TypeError); 1525 1526 DateInstance* thisDateObj = static_cast<DateInstance*>(this Obj);1528 static JSValue* setNewValueFromDateArgs(ExecState* exec, JSValue* thisValue, const ArgList& args, int numArgsToUse, bool inputIsUTC) 1529 { 1530 if (!thisValue->isObject(&DateInstance::info)) 1531 return throwError(exec, TypeError); 1532 1533 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1527 1534 if (args.isEmpty()) { 1528 1535 JSValue* result = jsNaN(exec); … … 1531 1538 } 1532 1539 1533 JSValue* v = thisDateObj->internalValue(); 1534 double milli = v->toNumber(exec); 1540 double milli = thisDateObj->internalNumber(); 1535 1541 double ms = 0; 1536 1542 … … 1557 1563 } 1558 1564 1559 JSValue* dateProtoFuncSetMilliSeconds(ExecState* exec, JSObject* thisObj, const ArgList& args)1565 JSValue* dateProtoFuncSetMilliSeconds(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1560 1566 { 1561 1567 const bool inputIsUTC = false; 1562 return setNewValueFromTimeArgs(exec, this Obj, args, 1, inputIsUTC);1563 } 1564 1565 JSValue* dateProtoFuncSetUTCMilliseconds(ExecState* exec, JSObject* thisObj, const ArgList& args)1568 return setNewValueFromTimeArgs(exec, thisValue, args, 1, inputIsUTC); 1569 } 1570 1571 JSValue* dateProtoFuncSetUTCMilliseconds(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1566 1572 { 1567 1573 const bool inputIsUTC = true; 1568 return setNewValueFromTimeArgs(exec, this Obj, args, 1, inputIsUTC);1569 } 1570 1571 JSValue* dateProtoFuncSetSeconds(ExecState* exec, JSObject* thisObj, const ArgList& args)1574 return setNewValueFromTimeArgs(exec, thisValue, args, 1, inputIsUTC); 1575 } 1576 1577 JSValue* dateProtoFuncSetSeconds(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1572 1578 { 1573 1579 const bool inputIsUTC = false; 1574 return setNewValueFromTimeArgs(exec, this Obj, args, 2, inputIsUTC);1575 } 1576 1577 JSValue* dateProtoFuncSetUTCSeconds(ExecState* exec, JSObject* thisObj, const ArgList& args)1580 return setNewValueFromTimeArgs(exec, thisValue, args, 2, inputIsUTC); 1581 } 1582 1583 JSValue* dateProtoFuncSetUTCSeconds(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1578 1584 { 1579 1585 const bool inputIsUTC = true; 1580 return setNewValueFromTimeArgs(exec, this Obj, args, 2, inputIsUTC);1581 } 1582 1583 JSValue* dateProtoFuncSetMinutes(ExecState* exec, JSObject* thisObj, const ArgList& args)1586 return setNewValueFromTimeArgs(exec, thisValue, args, 2, inputIsUTC); 1587 } 1588 1589 JSValue* dateProtoFuncSetMinutes(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1584 1590 { 1585 1591 const bool inputIsUTC = false; 1586 return setNewValueFromTimeArgs(exec, this Obj, args, 3, inputIsUTC);1587 } 1588 1589 JSValue* dateProtoFuncSetUTCMinutes(ExecState* exec, JSObject* thisObj, const ArgList& args)1592 return setNewValueFromTimeArgs(exec, thisValue, args, 3, inputIsUTC); 1593 } 1594 1595 JSValue* dateProtoFuncSetUTCMinutes(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1590 1596 { 1591 1597 const bool inputIsUTC = true; 1592 return setNewValueFromTimeArgs(exec, this Obj, args, 3, inputIsUTC);1593 } 1594 1595 JSValue* dateProtoFuncSetHours(ExecState* exec, JSObject* thisObj, const ArgList& args)1598 return setNewValueFromTimeArgs(exec, thisValue, args, 3, inputIsUTC); 1599 } 1600 1601 JSValue* dateProtoFuncSetHours(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1596 1602 { 1597 1603 const bool inputIsUTC = false; 1598 return setNewValueFromTimeArgs(exec, this Obj, args, 4, inputIsUTC);1599 } 1600 1601 JSValue* dateProtoFuncSetUTCHours(ExecState* exec, JSObject* thisObj, const ArgList& args)1604 return setNewValueFromTimeArgs(exec, thisValue, args, 4, inputIsUTC); 1605 } 1606 1607 JSValue* dateProtoFuncSetUTCHours(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1602 1608 { 1603 1609 const bool inputIsUTC = true; 1604 return setNewValueFromTimeArgs(exec, this Obj, args, 4, inputIsUTC);1605 } 1606 1607 JSValue* dateProtoFuncSetDate(ExecState* exec, JSObject* thisObj, const ArgList& args)1610 return setNewValueFromTimeArgs(exec, thisValue, args, 4, inputIsUTC); 1611 } 1612 1613 JSValue* dateProtoFuncSetDate(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1608 1614 { 1609 1615 const bool inputIsUTC = false; 1610 return setNewValueFromDateArgs(exec, this Obj, args, 1, inputIsUTC);1611 } 1612 1613 JSValue* dateProtoFuncSetUTCDate(ExecState* exec, JSObject* thisObj, const ArgList& args)1616 return setNewValueFromDateArgs(exec, thisValue, args, 1, inputIsUTC); 1617 } 1618 1619 JSValue* dateProtoFuncSetUTCDate(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1614 1620 { 1615 1621 const bool inputIsUTC = true; 1616 return setNewValueFromDateArgs(exec, this Obj, args, 1, inputIsUTC);1617 } 1618 1619 JSValue* dateProtoFuncSetMonth(ExecState* exec, JSObject* thisObj, const ArgList& args)1622 return setNewValueFromDateArgs(exec, thisValue, args, 1, inputIsUTC); 1623 } 1624 1625 JSValue* dateProtoFuncSetMonth(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1620 1626 { 1621 1627 const bool inputIsUTC = false; 1622 return setNewValueFromDateArgs(exec, this Obj, args, 2, inputIsUTC);1623 } 1624 1625 JSValue* dateProtoFuncSetUTCMonth(ExecState* exec, JSObject* thisObj, const ArgList& args)1628 return setNewValueFromDateArgs(exec, thisValue, args, 2, inputIsUTC); 1629 } 1630 1631 JSValue* dateProtoFuncSetUTCMonth(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1626 1632 { 1627 1633 const bool inputIsUTC = true; 1628 return setNewValueFromDateArgs(exec, this Obj, args, 2, inputIsUTC);1629 } 1630 1631 JSValue* dateProtoFuncSetFullYear(ExecState* exec, JSObject* thisObj, const ArgList& args)1634 return setNewValueFromDateArgs(exec, thisValue, args, 2, inputIsUTC); 1635 } 1636 1637 JSValue* dateProtoFuncSetFullYear(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1632 1638 { 1633 1639 const bool inputIsUTC = false; 1634 return setNewValueFromDateArgs(exec, this Obj, args, 3, inputIsUTC);1635 } 1636 1637 JSValue* dateProtoFuncSetUTCFullYear(ExecState* exec, JSObject* thisObj, const ArgList& args)1640 return setNewValueFromDateArgs(exec, thisValue, args, 3, inputIsUTC); 1641 } 1642 1643 JSValue* dateProtoFuncSetUTCFullYear(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1638 1644 { 1639 1645 const bool inputIsUTC = true; 1640 return setNewValueFromDateArgs(exec, this Obj, args, 3, inputIsUTC);1641 } 1642 1643 JSValue* dateProtoFuncSetYear(ExecState* exec, JSObject* thisObj, const ArgList& args)1644 { 1645 if (!this Obj->inherits(&DateInstance::info))1646 return setNewValueFromDateArgs(exec, thisValue, args, 3, inputIsUTC); 1647 } 1648 1649 JSValue* dateProtoFuncSetYear(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 1650 { 1651 if (!thisValue->isObject(&DateInstance::info)) 1646 1652 return throwError(exec, TypeError); 1647 1653 1648 1654 const bool utc = false; 1649 1655 1650 DateInstance* thisDateObj = static_cast<DateInstance*>(this Obj);1656 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1651 1657 if (args.isEmpty()) { 1652 1658 JSValue* result = jsNaN(exec); … … 1655 1661 } 1656 1662 1657 JSValue* v = thisDateObj->internalValue(); 1658 double milli = v->toNumber(exec); 1663 double milli = thisDateObj->internalNumber(); 1659 1664 double ms = 0; 1660 1665 … … 1684 1689 } 1685 1690 1686 JSValue* dateProtoFuncGetYear(ExecState* exec, JSObject* thisObj, const ArgList&)1687 { 1688 if (!this Obj->inherits(&DateInstance::info))1691 JSValue* dateProtoFuncGetYear(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 1692 { 1693 if (!thisValue->isObject(&DateInstance::info)) 1689 1694 return throwError(exec, TypeError); 1690 1695 1691 1696 const bool utc = false; 1692 1697 1693 DateInstance* thisDateObj = static_cast<DateInstance*>(thisObj); 1694 JSValue* v = thisDateObj->internalValue(); 1695 double milli = v->toNumber(exec); 1698 DateInstance* thisDateObj = static_cast<DateInstance*>(thisValue); 1699 double milli = thisDateObj->internalNumber(); 1696 1700 if (isnan(milli)) 1697 1701 return jsNaN(exec); -
trunk/JavaScriptCore/kjs/date_object.h
r34587 r34754 34 34 class DateInstance : public JSWrapperObject { 35 35 public: 36 DateInstance(JSObject *proto);36 DateInstance(JSObject* prototype); 37 37 virtual ~DateInstance(); 38 38 39 double internalNumber() const { return internalValue()->uncheckedGetNumber(); } 40 39 41 bool getTime(GregorianDateTime&, int& offset) const; 40 42 bool getUTCTime(GregorianDateTime&) const; 41 bool getTime(double& milli , int& offset) const;42 bool getUTCTime(double& milli ) const;43 bool getTime(double& milliseconds, int& offset) const; 44 bool getUTCTime(double& milliseconds) const; 43 45 44 virtual const ClassInfo *classInfo() const { return &info; }45 46 static const ClassInfo info; 46 47 … … 48 49 49 50 private: 51 virtual const ClassInfo* classInfo() const { return &info; } 52 53 using JSWrapperObject::internalValue; 54 50 55 struct Cache; 51 56 mutable Cache* m_cache; … … 69 74 * @internal 70 75 * 71 * Functions to implement all methods that are properties of the72 * Date.prototype object73 */74 75 // Non-normative properties (Appendix B)76 // GetYear, SetYear, ToGMTString77 78 JSValue* dateProtoFuncToString(ExecState*, JSObject*, const ArgList&);79 JSValue* dateProtoFuncToUTCString(ExecState*, JSObject*, const ArgList&);80 JSValue* dateProtoFuncToDateString(ExecState*, JSObject*, const ArgList&);81 JSValue* dateProtoFuncToTimeString(ExecState*, JSObject*, const ArgList&);82 JSValue* dateProtoFuncToLocaleString(ExecState*, JSObject*, const ArgList&);83 JSValue* dateProtoFuncToLocaleDateString(ExecState*, JSObject*, const ArgList&);84 JSValue* dateProtoFuncToLocaleTimeString(ExecState*, JSObject*, const ArgList&);85 JSValue* dateProtoFuncValueOf(ExecState*, JSObject*, const ArgList&);86 JSValue* dateProtoFuncGetTime(ExecState*, JSObject*, const ArgList&);87 JSValue* dateProtoFuncGetFullYear(ExecState*, JSObject*, const ArgList&);88 JSValue* dateProtoFuncGetUTCFullYear(ExecState*, JSObject*, const ArgList&);89 JSValue* dateProtoFuncToGMTString(ExecState*, JSObject*, const ArgList&);90 JSValue* dateProtoFuncGetMonth(ExecState*, JSObject*, const ArgList&);91 JSValue* dateProtoFuncGetUTCMonth(ExecState*, JSObject*, const ArgList&);92 JSValue* dateProtoFuncGetDate(ExecState*, JSObject*, const ArgList&);93 JSValue* dateProtoFuncGetUTCDate(ExecState*, JSObject*, const ArgList&);94 JSValue* dateProtoFuncGetDay(ExecState*, JSObject*, const ArgList&);95 JSValue* dateProtoFuncGetUTCDay(ExecState*, JSObject*, const ArgList&);96 JSValue* dateProtoFuncGetHours(ExecState*, JSObject*, const ArgList&);97 JSValue* dateProtoFuncGetUTCHours(ExecState*, JSObject*, const ArgList&);98 JSValue* dateProtoFuncGetMinutes(ExecState*, JSObject*, const ArgList&);99 JSValue* dateProtoFuncGetUTCMinutes(ExecState*, JSObject*, const ArgList&);100 JSValue* dateProtoFuncGetSeconds(ExecState*, JSObject*, const ArgList&);101 JSValue* dateProtoFuncGetUTCSeconds(ExecState*, JSObject*, const ArgList&);102 JSValue* dateProtoFuncGetMilliSeconds(ExecState*, JSObject*, const ArgList&);103 JSValue* dateProtoFuncGetUTCMilliseconds(ExecState*, JSObject*, const ArgList&);104 JSValue* dateProtoFuncGetTimezoneOffset(ExecState*, JSObject*, const ArgList&);105 JSValue* dateProtoFuncSetTime(ExecState*, JSObject*, const ArgList&);106 JSValue* dateProtoFuncSetMilliSeconds(ExecState*, JSObject*, const ArgList&);107 JSValue* dateProtoFuncSetUTCMilliseconds(ExecState*, JSObject*, const ArgList&);108 JSValue* dateProtoFuncSetSeconds(ExecState*, JSObject*, const ArgList&);109 JSValue* dateProtoFuncSetUTCSeconds(ExecState*, JSObject*, const ArgList&);110 JSValue* dateProtoFuncSetMinutes(ExecState*, JSObject*, const ArgList&);111 JSValue* dateProtoFuncSetUTCMinutes(ExecState*, JSObject*, const ArgList&);112 JSValue* dateProtoFuncSetHours(ExecState*, JSObject*, const ArgList&);113 JSValue* dateProtoFuncSetUTCHours(ExecState*, JSObject*, const ArgList&);114 JSValue* dateProtoFuncSetDate(ExecState*, JSObject*, const ArgList&);115 JSValue* dateProtoFuncSetUTCDate(ExecState*, JSObject*, const ArgList&);116 JSValue* dateProtoFuncSetMonth(ExecState*, JSObject*, const ArgList&);117 JSValue* dateProtoFuncSetUTCMonth(ExecState*, JSObject*, const ArgList&);118 JSValue* dateProtoFuncSetFullYear(ExecState*, JSObject*, const ArgList&);119 JSValue* dateProtoFuncSetUTCFullYear(ExecState*, JSObject*, const ArgList&);120 JSValue* dateProtoFuncSetYear(ExecState*, JSObject*, const ArgList&);121 JSValue* dateProtoFuncGetYear(ExecState*, JSObject*, const ArgList&);122 123 /**124 * @internal125 *126 76 * The initial value of the the global variable's "Date" property 127 77 */ … … 129 79 public: 130 80 DateConstructor(ExecState*, FunctionPrototype*, DatePrototype*); 131 81 private: 132 82 virtual ConstructType getConstructData(ConstructData&); 133 virtual JSObject* construct(ExecState*, const ArgList& args); 134 135 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const ArgList& args); 136 137 JSObject* construct(const ArgList&); 83 virtual CallType getCallData(CallData&); 138 84 }; 139 85 -
trunk/JavaScriptCore/kjs/error_object.cpp
r34659 r34754 40 40 // ------------------------------ ErrorPrototype ---------------------------- 41 41 42 static JSValue* errorProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&); 43 42 44 // ECMA 15.9.4 43 45 ErrorPrototype::ErrorPrototype(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype) … … 52 54 } 53 55 54 JSValue* errorProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList&)56 JSValue* errorProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 55 57 { 58 JSObject* thisObj = thisValue->toThisObject(exec); 59 56 60 UString s = "Error"; 57 61 … … 61 65 62 66 v = thisObj->get(exec, exec->propertyNames().message); 63 if (!v->isUndefined()) 64 // Mozilla compatible format 65 s += ": " + v->toString(exec); 67 if (!v->isUndefined()) { 68 // Mozilla-compatible format. 69 s += ": "; 70 s += v->toString(exec); 71 } 66 72 67 73 return jsString(exec, s); … … 78 84 } 79 85 80 ConstructType ErrorConstructor::getConstructData(ConstructData&) 86 // ECMA 15.9.3 87 static ErrorInstance* constructError(ExecState* exec, const ArgList& args) 81 88 { 89 ErrorInstance* obj = new (exec) ErrorInstance(exec->lexicalGlobalObject()->errorPrototype()); 90 if (!args[0]->isUndefined()) 91 obj->putDirect(exec->propertyNames().message, jsString(exec, args[0]->toString(exec))); 92 return obj; 93 } 94 95 static JSObject* constructWithErrorConstructor(ExecState* exec, JSObject*, const ArgList& args) 96 { 97 return constructError(exec, args); 98 } 99 100 ConstructType ErrorConstructor::getConstructData(ConstructData& constructData) 101 { 102 constructData.native.function = constructWithErrorConstructor; 82 103 return ConstructTypeNative; 83 104 } 84 105 85 // ECMA 15.9. 386 JSObject* ErrorConstructor::construct(ExecState* exec, const ArgList& args)106 // ECMA 15.9.2 107 static JSValue* callErrorConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 87 108 { 88 JSObject* proto = static_cast<JSObject*>(exec->lexicalGlobalObject()->errorPrototype()); 89 JSObject* imp = new (exec) ErrorInstance(proto); 90 JSObject* obj(imp); 91 92 if (!args[0]->isUndefined()) 93 imp->putDirect(exec->propertyNames().message, jsString(exec, args[0]->toString(exec))); 94 95 return obj; 109 // "Error()" gives the sames result as "new Error()" 110 return constructError(exec, args); 96 111 } 97 112 98 // ECMA 15.9.2 99 JSValue* ErrorConstructor::callAsFunction(ExecState* exec, JSObject* /*thisObj*/, const ArgList& args) 113 CallType ErrorConstructor::getCallData(CallData& callData) 100 114 { 101 // "Error()" gives the sames result as "new Error()"102 return construct(exec, args);115 callData.native.function = callErrorConstructor; 116 return CallTypeNative; 103 117 } 104 118 … … 124 138 } 125 139 126 ConstructType NativeErrorConstructor::getConstructData(ConstructData&)140 ErrorInstance* NativeErrorConstructor::construct(ExecState* exec, const ArgList& args) 127 141 { 142 ErrorInstance* object = new (exec) ErrorInstance(proto); 143 if (!args[0]->isUndefined()) 144 object->putDirect(exec->propertyNames().message, jsString(exec, args[0]->toString(exec))); 145 return object; 146 } 147 148 static JSObject* constructWithNativeErrorConstructor(ExecState* exec, JSObject* constructor, const ArgList& args) 149 { 150 return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args); 151 } 152 153 ConstructType NativeErrorConstructor::getConstructData(ConstructData& constructData) 154 { 155 constructData.native.function = constructWithNativeErrorConstructor; 128 156 return ConstructTypeNative; 129 157 } 130 158 131 JSObject* NativeErrorConstructor::construct(ExecState* exec, const ArgList& args)159 static JSValue* callNativeErrorConstructor(ExecState* exec, JSObject* constructor, JSValue*, const ArgList& args) 132 160 { 133 JSObject* imp = new (exec) ErrorInstance(proto); 134 JSObject* obj(imp); 135 if (!args[0]->isUndefined()) 136 imp->putDirect(exec->propertyNames().message, jsString(exec, args[0]->toString(exec))); 137 return obj; 161 return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args); 138 162 } 139 163 140 JSValue* NativeErrorConstructor::callAsFunction(ExecState* exec, JSObject*, const ArgList& args)164 CallType NativeErrorConstructor::getCallData(CallData& callData) 141 165 { 142 return construct(exec, args); 166 callData.native.function = callNativeErrorConstructor; 167 return CallTypeNative; 143 168 } 144 169 -
trunk/JavaScriptCore/kjs/error_object.h
r34587 r34754 39 39 }; 40 40 41 JSValue* errorProtoFuncToString(ExecState*, JSObject*, const ArgList&);42 43 41 class ErrorConstructor : public InternalFunction { 44 42 public: 45 43 ErrorConstructor(ExecState*, FunctionPrototype*, ErrorPrototype*); 46 44 45 private: 47 46 virtual ConstructType getConstructData(ConstructData&); 48 virtual JSObject* construct(ExecState*, const ArgList&); 49 50 virtual JSValue* callAsFunction(ExecState*, JSObject*, const ArgList&); 47 virtual CallType getCallData(CallData&); 51 48 }; 52 49 … … 59 56 public: 60 57 NativeErrorConstructor(ExecState*, FunctionPrototype*, NativeErrorPrototype*); 61 62 virtual ConstructType getConstructData(ConstructData&);63 virtual JSObject* construct(ExecState*, const ArgList&);64 65 virtual JSValue* callAsFunction(ExecState*, JSObject*, const ArgList&);66 67 58 virtual void mark(); 68 69 virtual const ClassInfo* classInfo() const { return &info; }70 59 static const ClassInfo info; 60 ErrorInstance* construct(ExecState*, const ArgList&); 71 61 72 62 private: 73 JSObject* proto; 63 virtual const ClassInfo* classInfo() const { return &info; } 64 virtual ConstructType getConstructData(ConstructData&); 65 virtual CallType getCallData(CallData&); 66 67 NativeErrorPrototype* proto; 74 68 }; 75 69 -
trunk/JavaScriptCore/kjs/internal.cpp
r34659 r34754 176 176 } 177 177 178 JSObject *JSNumberCell::toObject(ExecState *exec) const 179 { 180 ArgList args; 181 args.append(const_cast<JSNumberCell*>(this)); 182 return static_cast<JSObject *>(exec->lexicalGlobalObject()->numberConstructor()->construct(exec,args)); 178 JSObject* JSNumberCell::toObject(ExecState* exec) const 179 { 180 return constructNumber(exec, const_cast<JSNumberCell*>(this)); 183 181 } 184 182 185 183 JSObject* JSNumberCell::toThisObject(ExecState* exec) const 186 184 { 187 ArgList args; 188 args.append(const_cast<JSNumberCell*>(this)); 189 return static_cast<JSObject*>(exec->lexicalGlobalObject()->numberConstructor()->construct(exec, args)); 185 return constructNumber(exec, const_cast<JSNumberCell*>(this)); 190 186 } 191 187 … … 213 209 214 210 // --------------------------- GetterSetter --------------------------------- 211 215 212 void GetterSetter::mark() 216 213 { 217 214 JSCell::mark(); 218 219 if ( getter && !getter->marked())220 getter->mark();221 if ( setter && !setter->marked())222 setter->mark();215 216 if (m_getter && !m_getter->marked()) 217 m_getter->mark(); 218 if (m_setter && !m_setter->marked()) 219 m_setter->mark(); 223 220 } 224 221 225 222 JSValue* GetterSetter::toPrimitive(ExecState*, JSType) const 226 223 { 227 ASSERT (false);224 ASSERT_NOT_REACHED(); 228 225 return jsNull(); 229 226 } … … 239 236 bool GetterSetter::toBoolean(ExecState*) const 240 237 { 241 ASSERT (false);238 ASSERT_NOT_REACHED(); 242 239 return false; 243 240 } 244 241 245 double GetterSetter::toNumber(ExecState 246 { 247 ASSERT (false);242 double GetterSetter::toNumber(ExecState*) const 243 { 244 ASSERT_NOT_REACHED(); 248 245 return 0.0; 249 246 } 250 247 251 UString GetterSetter::toString(ExecState 252 { 253 ASSERT (false);248 UString GetterSetter::toString(ExecState*) const 249 { 250 ASSERT_NOT_REACHED(); 254 251 return UString::null(); 255 252 } 256 253 257 JSObject *GetterSetter::toObject(ExecState *exec) const258 { 259 ASSERT (false);254 JSObject* GetterSetter::toObject(ExecState* exec) const 255 { 256 ASSERT_NOT_REACHED(); 260 257 return jsNull()->toObject(exec); 261 }262 263 bool GetterSetter::getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&)264 {265 ASSERT_NOT_REACHED();266 return false;267 }268 269 bool GetterSetter::getOwnPropertySlot(ExecState*, unsigned, PropertySlot&)270 {271 ASSERT_NOT_REACHED();272 return false;273 }274 275 void GetterSetter::put(ExecState*, const Identifier&, JSValue*)276 {277 ASSERT_NOT_REACHED();278 }279 280 void GetterSetter::put(ExecState*, unsigned, JSValue*)281 {282 ASSERT_NOT_REACHED();283 }284 285 JSObject* GetterSetter::toThisObject(ExecState*) const286 {287 ASSERT_NOT_REACHED();288 return 0;289 258 } 290 259 … … 323 292 } 324 293 325 InternalFunction::InternalFunction(FunctionPrototype* funcProto, const Identifier& name) 326 : JSObject(funcProto) 327 , m_name(name) 328 { 329 } 330 331 CallType InternalFunction::getCallData(CallData&) 332 { 333 return CallTypeNative; 294 InternalFunction::InternalFunction(FunctionPrototype* prototype, const Identifier& name) 295 : JSObject(prototype) 296 , m_name(name) 297 { 334 298 } 335 299 336 300 bool InternalFunction::implementsHasInstance() const 337 301 { 338 return true;339 } 340 341 } 302 return true; 303 } 304 305 } -
trunk/JavaScriptCore/kjs/lookup.h
r34659 r34754 46 46 union { 47 47 intptr_t integerValue; 48 PrototypeFunction::JSMemberFunction functionValue;48 NativeFunction functionValue; 49 49 }; 50 50 unsigned char attributes; // JSObject attributes -
trunk/JavaScriptCore/kjs/nodes.cpp
r34711 r34754 1683 1683 JSFunction* func = new (exec) JSFunction(exec, m_ident, m_body.get(), scopeChain); 1684 1684 1685 JSObject* proto = exec->lexicalGlobalObject()->objectConstructor()->construct(exec, exec->emptyList());1685 JSObject* proto = constructEmptyObject(exec); 1686 1686 proto->putDirect(exec->propertyNames().constructor, func, DontEnum); 1687 1687 func->putDirect(exec->propertyNames().prototype, proto, DontDelete); … … 1705 1705 { 1706 1706 JSFunction* func = new (exec) JSFunction(exec, m_ident, m_body.get(), scopeChain); 1707 JSObject* proto = exec->lexicalGlobalObject()->objectConstructor()->construct(exec, exec->emptyList());1707 JSObject* proto = constructEmptyObject(exec); 1708 1708 proto->putDirect(exec->propertyNames().constructor, func, DontEnum); 1709 1709 func->putDirect(exec->propertyNames().prototype, proto, DontDelete); -
trunk/JavaScriptCore/kjs/object_object.cpp
r34659 r34754 31 31 // ------------------------------ ObjectPrototype -------------------------------- 32 32 33 static JSValue* objectProtoFuncValueOf(ExecState*, JSObject*, const ArgList&);34 static JSValue* objectProtoFuncHasOwnProperty(ExecState*, JSObject*, const ArgList&);35 static JSValue* objectProtoFuncIsPrototypeOf(ExecState*, JSObject*, const ArgList&);36 static JSValue* objectProtoFuncDefineGetter(ExecState*, JSObject*, const ArgList&);37 static JSValue* objectProtoFuncDefineSetter(ExecState*, JSObject*, const ArgList&);38 static JSValue* objectProtoFuncLookupGetter(ExecState*, JSObject*, const ArgList&);39 static JSValue* objectProtoFuncLookupSetter(ExecState*, JSObject*, const ArgList&);40 static JSValue* objectProtoFuncPropertyIsEnumerable(ExecState*, JSObject*, const ArgList&);41 static JSValue* objectProtoFuncToLocaleString(ExecState*, JSObject*, const ArgList&);33 static JSValue* objectProtoFuncValueOf(ExecState*, JSObject*, JSValue*, const ArgList&); 34 static JSValue* objectProtoFuncHasOwnProperty(ExecState*, JSObject*, JSValue*, const ArgList&); 35 static JSValue* objectProtoFuncIsPrototypeOf(ExecState*, JSObject*, JSValue*, const ArgList&); 36 static JSValue* objectProtoFuncDefineGetter(ExecState*, JSObject*, JSValue*, const ArgList&); 37 static JSValue* objectProtoFuncDefineSetter(ExecState*, JSObject*, JSValue*, const ArgList&); 38 static JSValue* objectProtoFuncLookupGetter(ExecState*, JSObject*, JSValue*, const ArgList&); 39 static JSValue* objectProtoFuncLookupSetter(ExecState*, JSObject*, JSValue*, const ArgList&); 40 static JSValue* objectProtoFuncPropertyIsEnumerable(ExecState*, JSObject*, JSValue*, const ArgList&); 41 static JSValue* objectProtoFuncToLocaleString(ExecState*, JSObject*, JSValue*, const ArgList&); 42 42 43 43 ObjectPrototype::ObjectPrototype(ExecState* exec, FunctionPrototype* functionPrototype) … … 63 63 // ECMA 15.2.4.2, 15.2.4.4, 15.2.4.5, 15.2.4.7 64 64 65 JSValue* objectProtoFuncValueOf(ExecState* , JSObject* thisObj, const ArgList&)65 JSValue* objectProtoFuncValueOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 66 66 { 67 return this Obj;67 return thisValue->toThisObject(exec); 68 68 } 69 69 70 JSValue* objectProtoFuncHasOwnProperty(ExecState* exec, JSObject* thisObj, const ArgList& args)70 JSValue* objectProtoFuncHasOwnProperty(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 71 71 { 72 return jsBoolean(this Obj->hasOwnProperty(exec, Identifier(exec, args[0]->toString(exec))));72 return jsBoolean(thisValue->toThisObject(exec)->hasOwnProperty(exec, Identifier(exec, args[0]->toString(exec)))); 73 73 } 74 74 75 JSValue* objectProtoFuncIsPrototypeOf(ExecState* , JSObject* thisObj, const ArgList& args)75 JSValue* objectProtoFuncIsPrototypeOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 76 76 { 77 JSObject* thisObj = thisValue->toThisObject(exec); 78 77 79 if (!args[0]->isObject()) 78 80 return jsBoolean(false); … … 83 85 if (!v->isObject()) 84 86 return jsBoolean(false); 85 if (thisObj == static_cast<JSObject*>(v))87 if (thisObj == v) 86 88 87 89 return jsBoolean(true); … … 90 92 } 91 93 92 JSValue* objectProtoFuncDefineGetter(ExecState* exec, JSObject* thisObj, const ArgList& args)94 JSValue* objectProtoFuncDefineGetter(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 93 95 { 94 if (!args[1]->isObject() || !static_cast<JSObject*>(args[1])->implementsCall()) 96 CallData callData; 97 if (args[1]->getCallData(callData) == CallTypeNone) 95 98 return throwError(exec, SyntaxError, "invalid getter usage"); 96 97 thisObj->defineGetter(exec, Identifier(exec, args[0]->toString(exec)), static_cast<JSObject *>(args[1])); 99 thisValue->toThisObject(exec)->defineGetter(exec, Identifier(exec, args[0]->toString(exec)), static_cast<JSObject*>(args[1])); 98 100 return jsUndefined(); 99 101 } 100 102 101 JSValue* objectProtoFuncDefineSetter(ExecState* exec, JSObject* thisObj, const ArgList& args)103 JSValue* objectProtoFuncDefineSetter(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 102 104 { 103 if (!args[1]->isObject() || !static_cast<JSObject*>(args[1])->implementsCall()) 105 CallData callData; 106 if (args[1]->getCallData(callData) == CallTypeNone) 104 107 return throwError(exec, SyntaxError, "invalid setter usage"); 105 106 thisObj->defineSetter(exec, Identifier(exec, args[0]->toString(exec)), static_cast<JSObject *>(args[1])); 108 thisValue->toThisObject(exec)->defineSetter(exec, Identifier(exec, args[0]->toString(exec)), static_cast<JSObject*>(args[1])); 107 109 return jsUndefined(); 108 110 } 109 111 110 JSValue* objectProtoFuncLookupGetter(ExecState* exec, JSObject* thisObj, const ArgList& args)112 JSValue* objectProtoFuncLookupGetter(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 111 113 { 112 return this Obj->lookupGetter(exec, Identifier(exec, args[0]->toString(exec)));114 return thisValue->toThisObject(exec)->lookupGetter(exec, Identifier(exec, args[0]->toString(exec))); 113 115 } 114 116 115 JSValue* objectProtoFuncLookupSetter(ExecState* exec, JSObject* thisObj, const ArgList& args)117 JSValue* objectProtoFuncLookupSetter(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 116 118 { 117 return this Obj->lookupSetter(exec, Identifier(exec, args[0]->toString(exec)));119 return thisValue->toThisObject(exec)->lookupSetter(exec, Identifier(exec, args[0]->toString(exec))); 118 120 } 119 121 120 JSValue* objectProtoFuncPropertyIsEnumerable(ExecState* exec, JSObject* thisObj, const ArgList& args)122 JSValue* objectProtoFuncPropertyIsEnumerable(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 121 123 { 122 return jsBoolean(this Obj->propertyIsEnumerable(exec, Identifier(exec, args[0]->toString(exec))));124 return jsBoolean(thisValue->toThisObject(exec)->propertyIsEnumerable(exec, Identifier(exec, args[0]->toString(exec)))); 123 125 } 124 126 125 JSValue* objectProtoFuncToLocaleString(ExecState* exec, JSObject* thisObj, const ArgList&)127 JSValue* objectProtoFuncToLocaleString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 126 128 { 127 return jsString(exec, this Obj->toString(exec));129 return jsString(exec, thisValue->toThisObject(exec)->toString(exec)); 128 130 } 129 131 130 JSValue* objectProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList&)132 JSValue* objectProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 131 133 { 132 return jsString(exec, "[object " + this Obj->className() + "]");134 return jsString(exec, "[object " + thisValue->toThisObject(exec)->className() + "]"); 133 135 } 134 136 … … 142 144 143 145 // no. of arguments for constructor 144 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly |DontDelete|DontEnum);146 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete); 145 147 } 146 148 147 ConstructType ObjectConstructor::getConstructData(ConstructData&) 149 // ECMA 15.2.2 150 static ALWAYS_INLINE JSObject* constructObject(ExecState* exec, const ArgList& args) 148 151 { 152 JSValue* arg = args[0]; 153 if (arg->isUndefinedOrNull()) 154 return new (exec) JSObject(exec->lexicalGlobalObject()->objectPrototype()); 155 return arg->toObject(exec); 156 } 157 158 static JSObject* constructWithObjectConstructor(ExecState* exec, JSObject*, const ArgList& args) 159 { 160 return constructObject(exec, args); 161 } 162 163 ConstructType ObjectConstructor::getConstructData(ConstructData& constructData) 164 { 165 constructData.native.function = constructWithObjectConstructor; 149 166 return ConstructTypeNative; 150 167 } 151 168 152 // ECMA 15.2.2 153 JSObject* ObjectConstructor::construct(ExecState* exec, const ArgList& args) 169 static JSValue* callObjectConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 154 170 { 155 JSValue* arg = args[0]; 156 switch (arg->type()) { 157 case StringType: 158 case BooleanType: 159 case NumberType: 160 case ObjectType: 161 return arg->toObject(exec); 162 case NullType: 163 case UndefinedType: 164 return new (exec) JSObject(exec->lexicalGlobalObject()->objectPrototype()); 165 default: 166 ASSERT_NOT_REACHED(); 167 return 0; 168 } 171 return constructObject(exec, args); 169 172 } 170 173 171 JSValue* ObjectConstructor::callAsFunction(ExecState* exec, JSObject* /*thisObj*/, const ArgList &args)174 CallType ObjectConstructor::getCallData(CallData& callData) 172 175 { 173 return construct(exec, args); 176 callData.native.function = callObjectConstructor; 177 return CallTypeNative; 174 178 } 175 179 -
trunk/JavaScriptCore/kjs/object_object.h
r34587 r34754 37 37 }; 38 38 39 JSValue* objectProtoFuncToString(ExecState*, JSObject*, const ArgList&);39 JSValue* objectProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&); 40 40 41 41 /** … … 47 47 public: 48 48 ObjectConstructor(ExecState*, ObjectPrototype*, FunctionPrototype*); 49 49 private: 50 50 virtual ConstructType getConstructData(ConstructData&); 51 virtual JSObject* construct(ExecState*, const ArgList&); 52 53 virtual JSValue* callAsFunction(ExecState*, JSObject*, const ArgList&); 51 virtual CallType getCallData(CallData&); 54 52 }; 55 53 -
trunk/JavaScriptCore/kjs/string_object.cpp
r34659 r34754 22 22 #include "config.h" 23 23 #include "string_object.h" 24 #include "string_object.lut.h"25 24 26 25 #include "JSWrapperObject.h" … … 37 36 namespace KJS { 38 37 38 static JSValue* stringProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&); 39 static JSValue* stringProtoFuncValueOf(ExecState*, JSObject*, JSValue*, const ArgList&); 40 static JSValue* stringProtoFuncCharAt(ExecState*, JSObject*, JSValue*, const ArgList&); 41 static JSValue* stringProtoFuncCharCodeAt(ExecState*, JSObject*, JSValue*, const ArgList&); 42 static JSValue* stringProtoFuncConcat(ExecState*, JSObject*, JSValue*, const ArgList&); 43 static JSValue* stringProtoFuncIndexOf(ExecState*, JSObject*, JSValue*, const ArgList&); 44 static JSValue* stringProtoFuncLastIndexOf(ExecState*, JSObject*, JSValue*, const ArgList&); 45 static JSValue* stringProtoFuncMatch(ExecState*, JSObject*, JSValue*, const ArgList&); 46 static JSValue* stringProtoFuncReplace(ExecState*, JSObject*, JSValue*, const ArgList&); 47 static JSValue* stringProtoFuncSearch(ExecState*, JSObject*, JSValue*, const ArgList&); 48 static JSValue* stringProtoFuncSlice(ExecState*, JSObject*, JSValue*, const ArgList&); 49 static JSValue* stringProtoFuncSplit(ExecState*, JSObject*, JSValue*, const ArgList&); 50 static JSValue* stringProtoFuncSubstr(ExecState*, JSObject*, JSValue*, const ArgList&); 51 static JSValue* stringProtoFuncSubstring(ExecState*, JSObject*, JSValue*, const ArgList&); 52 static JSValue* stringProtoFuncToLowerCase(ExecState*, JSObject*, JSValue*, const ArgList&); 53 static JSValue* stringProtoFuncToUpperCase(ExecState*, JSObject*, JSValue*, const ArgList&); 54 static JSValue* stringProtoFuncToLocaleLowerCase(ExecState*, JSObject*, JSValue*, const ArgList&); 55 static JSValue* stringProtoFuncToLocaleUpperCase(ExecState*, JSObject*, JSValue*, const ArgList&); 56 static JSValue* stringProtoFuncLocaleCompare(ExecState*, JSObject*, JSValue*, const ArgList&); 57 58 static JSValue* stringProtoFuncBig(ExecState*, JSObject*, JSValue*, const ArgList&); 59 static JSValue* stringProtoFuncSmall(ExecState*, JSObject*, JSValue*, const ArgList&); 60 static JSValue* stringProtoFuncBlink(ExecState*, JSObject*, JSValue*, const ArgList&); 61 static JSValue* stringProtoFuncBold(ExecState*, JSObject*, JSValue*, const ArgList&); 62 static JSValue* stringProtoFuncFixed(ExecState*, JSObject*, JSValue*, const ArgList&); 63 static JSValue* stringProtoFuncItalics(ExecState*, JSObject*, JSValue*, const ArgList&); 64 static JSValue* stringProtoFuncStrike(ExecState*, JSObject*, JSValue*, const ArgList&); 65 static JSValue* stringProtoFuncSub(ExecState*, JSObject*, JSValue*, const ArgList&); 66 static JSValue* stringProtoFuncSup(ExecState*, JSObject*, JSValue*, const ArgList&); 67 static JSValue* stringProtoFuncFontcolor(ExecState*, JSObject*, JSValue*, const ArgList&); 68 static JSValue* stringProtoFuncFontsize(ExecState*, JSObject*, JSValue*, const ArgList&); 69 static JSValue* stringProtoFuncAnchor(ExecState*, JSObject*, JSValue*, const ArgList&); 70 static JSValue* stringProtoFuncLink(ExecState*, JSObject*, JSValue*, const ArgList&); 71 72 } 73 74 #include "string_object.lut.h" 75 76 namespace KJS { 77 39 78 // ------------------------------ StringObject ---------------------------- 40 79 … … 99 138 /* Source for string_object.lut.h 100 139 @begin stringTable 26 101 toString &stringProtoFuncToString DontEnum|Function 0102 valueOf &stringProtoFuncValueOf DontEnum|Function 0103 charAt &stringProtoFuncCharAt DontEnum|Function 1104 charCodeAt &stringProtoFuncCharCodeAt DontEnum|Function 1105 concat &stringProtoFuncConcat DontEnum|Function 1106 indexOf &stringProtoFuncIndexOf DontEnum|Function 1107 lastIndexOf &stringProtoFuncLastIndexOf DontEnum|Function 1108 match &stringProtoFuncMatch DontEnum|Function 1109 replace &stringProtoFuncReplace DontEnum|Function 2110 search &stringProtoFuncSearch DontEnum|Function 1111 slice &stringProtoFuncSlice DontEnum|Function 2112 split &stringProtoFuncSplit DontEnum|Function 2113 substr &stringProtoFuncSubstr DontEnum|Function 2114 substring &stringProtoFuncSubstring DontEnum|Function 2115 toLowerCase &stringProtoFuncToLowerCase DontEnum|Function 0116 toUpperCase &stringProtoFuncToUpperCase DontEnum|Function 0117 toLocaleLowerCase &stringProtoFuncToLocaleLowerCase DontEnum|Function 0118 toLocaleUpperCase &stringProtoFuncToLocaleUpperCase DontEnum|Function 0119 localeCompare &stringProtoFuncLocaleCompare DontEnum|Function 1120 121 big &stringProtoFuncBig DontEnum|Function 0122 small &stringProtoFuncSmall DontEnum|Function 0123 blink &stringProtoFuncBlink DontEnum|Function 0124 bold &stringProtoFuncBold DontEnum|Function 0125 fixed &stringProtoFuncFixed DontEnum|Function 0126 italics &stringProtoFuncItalics DontEnum|Function 0127 strike &stringProtoFuncStrike DontEnum|Function 0128 sub &stringProtoFuncSub DontEnum|Function 0129 sup &stringProtoFuncSup DontEnum|Function 0130 fontcolor &stringProtoFuncFontcolor DontEnum|Function 1131 fontsize &stringProtoFuncFontsize DontEnum|Function 1132 anchor &stringProtoFuncAnchor DontEnum|Function 1133 link &stringProtoFuncLink DontEnum|Function 1140 toString stringProtoFuncToString DontEnum|Function 0 141 valueOf stringProtoFuncValueOf DontEnum|Function 0 142 charAt stringProtoFuncCharAt DontEnum|Function 1 143 charCodeAt stringProtoFuncCharCodeAt DontEnum|Function 1 144 concat stringProtoFuncConcat DontEnum|Function 1 145 indexOf stringProtoFuncIndexOf DontEnum|Function 1 146 lastIndexOf stringProtoFuncLastIndexOf DontEnum|Function 1 147 match stringProtoFuncMatch DontEnum|Function 1 148 replace stringProtoFuncReplace DontEnum|Function 2 149 search stringProtoFuncSearch DontEnum|Function 1 150 slice stringProtoFuncSlice DontEnum|Function 2 151 split stringProtoFuncSplit DontEnum|Function 2 152 substr stringProtoFuncSubstr DontEnum|Function 2 153 substring stringProtoFuncSubstring DontEnum|Function 2 154 toLowerCase stringProtoFuncToLowerCase DontEnum|Function 0 155 toUpperCase stringProtoFuncToUpperCase DontEnum|Function 0 156 toLocaleLowerCase stringProtoFuncToLocaleLowerCase DontEnum|Function 0 157 toLocaleUpperCase stringProtoFuncToLocaleUpperCase DontEnum|Function 0 158 localeCompare stringProtoFuncLocaleCompare DontEnum|Function 1 159 160 big stringProtoFuncBig DontEnum|Function 0 161 small stringProtoFuncSmall DontEnum|Function 0 162 blink stringProtoFuncBlink DontEnum|Function 0 163 bold stringProtoFuncBold DontEnum|Function 0 164 fixed stringProtoFuncFixed DontEnum|Function 0 165 italics stringProtoFuncItalics DontEnum|Function 0 166 strike stringProtoFuncStrike DontEnum|Function 0 167 sub stringProtoFuncSub DontEnum|Function 0 168 sup stringProtoFuncSup DontEnum|Function 0 169 fontcolor stringProtoFuncFontcolor DontEnum|Function 1 170 fontsize stringProtoFuncFontsize DontEnum|Function 1 171 anchor stringProtoFuncAnchor DontEnum|Function 1 172 link stringProtoFuncLink DontEnum|Function 1 134 173 @end 135 174 */ … … 268 307 { 269 308 UString source = sourceVal->value(); 270 JSObject *replacementFunction = 0;309 CallData callData; 271 310 UString replacementString; 272 311 273 if (replacement->isObject() && replacement->toObject(exec)->implementsCall()) 274 replacementFunction = replacement->toObject(exec); 275 else 312 CallType callType = replacement->getCallData(callData); 313 if (callType == CallTypeNone) 276 314 replacementString = replacement->toString(exec); 277 315 … … 304 342 305 343 UString substitutedReplacement; 306 if ( replacementFunction) {344 if (callType != CallTypeNone) { 307 345 int completeMatchStart = ovector[0]; 308 346 ArgList args; … … 321 359 args.append(sourceVal); 322 360 323 substitutedReplacement = replacementFunction->callAsFunction(exec, exec->globalThisValue(), args)->toString(exec);361 substitutedReplacement = call(exec, replacement, callType, callData, exec->globalThisValue(), args)->toString(exec); 324 362 } else 325 363 substitutedReplacement = substituteBackreferences(replacementString, source, ovector, reg); … … 363 401 return sourceVal; 364 402 365 if ( replacementFunction) {403 if (callType != CallTypeNone) { 366 404 ArgList args; 367 405 … … 370 408 args.append(sourceVal); 371 409 372 replacementString = replacementFunction->callAsFunction(exec, exec->globalThisValue(), args)->toString(exec);410 replacementString = call(exec, replacement, callType, callData, exec->globalThisValue(), args)->toString(exec); 373 411 } 374 412 … … 376 414 } 377 415 378 JSValue* stringProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList&)379 { 380 if (!this Obj->inherits(&StringObject::info))416 JSValue* stringProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 417 { 418 if (!thisValue->isObject(&StringObject::info)) 381 419 return throwError(exec, TypeError); 382 420 383 return static_cast<StringObject*>(this Obj)->internalValue();384 } 385 386 JSValue* stringProtoFuncValueOf(ExecState* exec, JSObject* thisObj, const ArgList&)387 { 388 if (!this Obj->inherits(&StringObject::info))421 return static_cast<StringObject*>(thisValue)->internalValue(); 422 } 423 424 JSValue* stringProtoFuncValueOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 425 { 426 if (!thisValue->isObject(&StringObject::info)) 389 427 return throwError(exec, TypeError); 390 428 391 return static_cast<StringObject*>(this Obj)->internalValue();392 } 393 394 JSValue* stringProtoFuncCharAt(ExecState* exec, JSObject* thisObj, const ArgList& args)395 { 396 // This optimizes the common case that thisObj is a StringObject 397 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);429 return static_cast<StringObject*>(thisValue)->internalValue(); 430 } 431 432 JSValue* stringProtoFuncCharAt(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 433 { 434 // This optimizes the common case that thisObj is a StringObject 435 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 398 436 int len = s.size(); 399 437 … … 408 446 } 409 447 410 JSValue* stringProtoFuncCharCodeAt(ExecState* exec, JSObject* thisObj, const ArgList& args)411 { 412 // This optimizes the common case that thisObj is a StringObject 413 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);448 JSValue* stringProtoFuncCharCodeAt(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 449 { 450 // This optimizes the common case that thisObj is a StringObject 451 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 414 452 int len = s.size(); 415 453 … … 425 463 } 426 464 427 JSValue* stringProtoFuncConcat(ExecState* exec, JSObject* thisObj, const ArgList& args)428 { 429 // This optimizes the common case that thisObj is a StringObject 430 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);465 JSValue* stringProtoFuncConcat(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 466 { 467 // This optimizes the common case that thisObj is a StringObject 468 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 431 469 432 470 ArgList::const_iterator end = args.end(); … … 437 475 } 438 476 439 JSValue* stringProtoFuncIndexOf(ExecState* exec, JSObject* thisObj, const ArgList& args)440 { 441 // This optimizes the common case that thisObj is a StringObject 442 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);477 JSValue* stringProtoFuncIndexOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 478 { 479 // This optimizes the common case that thisObj is a StringObject 480 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 443 481 int len = s.size(); 444 482 … … 454 492 } 455 493 456 JSValue* stringProtoFuncLastIndexOf(ExecState* exec, JSObject* thisObj, const ArgList& args)457 { 458 // This optimizes the common case that thisObj is a StringObject 459 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);494 JSValue* stringProtoFuncLastIndexOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 495 { 496 // This optimizes the common case that thisObj is a StringObject 497 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 460 498 int len = s.size(); 461 499 … … 472 510 } 473 511 474 JSValue* stringProtoFuncMatch(ExecState* exec, JSObject* thisObj, const ArgList& args)475 { 476 // This optimizes the common case that thisObj is a StringObject 477 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);512 JSValue* stringProtoFuncMatch(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 513 { 514 // This optimizes the common case that thisObj is a StringObject 515 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 478 516 479 517 JSValue* a0 = args[0]; … … 521 559 result = jsNull(); 522 560 } else { 523 result = exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, list);561 result = constructArray(exec, list); 524 562 } 525 563 } … … 527 565 } 528 566 529 JSValue* stringProtoFuncSearch(ExecState* exec, JSObject* thisObj, const ArgList& args)530 { 531 // This optimizes the common case that thisObj is a StringObject 532 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);567 JSValue* stringProtoFuncSearch(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 568 { 569 // This optimizes the common case that thisObj is a StringObject 570 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 533 571 534 572 JSValue* a0 = args[0]; … … 553 591 } 554 592 555 JSValue* stringProtoFuncReplace(ExecState* exec, JSObject* thisObj, const ArgList& args)556 { 557 // This optimizes the common case that thisObj is a StringObject 558 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);559 560 JSString* sVal = this Obj->inherits(&StringObject::info) ?561 static_cast<StringObject*>(this Obj)->internalValue() :593 JSValue* stringProtoFuncReplace(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 594 { 595 // This optimizes the common case that thisObj is a StringObject 596 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 597 598 JSString* sVal = thisValue->isObject(&StringObject::info) ? 599 static_cast<StringObject*>(thisValue)->internalValue() : 562 600 static_cast<JSString*>(jsString(exec, s)); 563 601 … … 568 606 } 569 607 570 JSValue* stringProtoFuncSlice(ExecState* exec, JSObject* thisObj, const ArgList& args)571 { 572 // This optimizes the common case that thisObj is a StringObject 573 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);608 JSValue* stringProtoFuncSlice(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 609 { 610 // This optimizes the common case that thisObj is a StringObject 611 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 574 612 int len = s.size(); 575 613 … … 593 631 } 594 632 595 JSValue* stringProtoFuncSplit(ExecState* exec, JSObject* thisObj, const ArgList& args)596 { 597 // This optimizes the common case that thisObj is a StringObject 598 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);633 JSValue* stringProtoFuncSplit(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 634 { 635 // This optimizes the common case that thisObj is a StringObject 636 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 599 637 600 638 JSValue* a0 = args[0]; 601 639 JSValue* a1 = args[1]; 602 640 603 JSObject *constructor = exec->lexicalGlobalObject()->arrayConstructor(); 604 JSObject* res = static_cast<JSObject*>(constructor->construct(exec, exec->emptyList())); 641 JSObject* res = constructEmptyArray(exec); 605 642 JSValue* result = res; 606 643 UString u = s; … … 663 700 } 664 701 665 JSValue* stringProtoFuncSubstr(ExecState* exec, JSObject* thisObj, const ArgList& args)666 { 667 // This optimizes the common case that thisObj is a StringObject 668 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);702 JSValue* stringProtoFuncSubstr(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 703 { 704 // This optimizes the common case that thisObj is a StringObject 705 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 669 706 int len = s.size(); 670 707 … … 688 725 } 689 726 690 JSValue* stringProtoFuncSubstring(ExecState* exec, JSObject* thisObj, const ArgList& args)691 { 692 // This optimizes the common case that thisObj is a StringObject 693 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);727 JSValue* stringProtoFuncSubstring(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 728 { 729 // This optimizes the common case that thisObj is a StringObject 730 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 694 731 int len = s.size(); 695 732 … … 721 758 } 722 759 723 JSValue* stringProtoFuncToLowerCase(ExecState* exec, JSObject* thisObj, const ArgList&)724 { 725 // This optimizes the common case that thisObj is a StringObject 726 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);760 JSValue* stringProtoFuncToLowerCase(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 761 { 762 // This optimizes the common case that thisObj is a StringObject 763 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 727 764 728 JSString* sVal = this Obj->inherits(&StringObject::info)729 ? static_cast<StringObject*>(this Obj)->internalValue()765 JSString* sVal = thisValue->isObject(&StringObject::info) 766 ? static_cast<StringObject*>(thisValue)->internalValue() 730 767 : static_cast<JSString*>(jsString(exec, s)); 731 768 int ssize = s.size(); … … 746 783 } 747 784 748 JSValue* stringProtoFuncToUpperCase(ExecState* exec, JSObject* thisObj, const ArgList&)749 { 750 // This optimizes the common case that thisObj is a StringObject 751 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);752 753 JSString* sVal = this Obj->inherits(&StringObject::info)754 ? static_cast<StringObject*>(this Obj)->internalValue()785 JSValue* stringProtoFuncToUpperCase(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 786 { 787 // This optimizes the common case that thisObj is a StringObject 788 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 789 790 JSString* sVal = thisValue->isObject(&StringObject::info) 791 ? static_cast<StringObject*>(thisValue)->internalValue() 755 792 : static_cast<JSString*>(jsString(exec, s)); 756 793 int ssize = s.size(); … … 771 808 } 772 809 773 JSValue* stringProtoFuncToLocaleLowerCase(ExecState* exec, JSObject* thisObj, const ArgList&)774 { 775 // This optimizes the common case that thisObj is a StringObject 776 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);810 JSValue* stringProtoFuncToLocaleLowerCase(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 811 { 812 // This optimizes the common case that thisObj is a StringObject 813 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 777 814 778 815 // FIXME: See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt for locale-sensitive mappings that aren't implemented. 779 JSString* sVal = this Obj->inherits(&StringObject::info)780 ? static_cast<StringObject*>(this Obj)->internalValue()816 JSString* sVal = thisValue->isObject(&StringObject::info) 817 ? static_cast<StringObject*>(thisValue)->internalValue() 781 818 : static_cast<JSString*>(jsString(exec, s)); 782 819 int ssize = s.size(); … … 797 834 } 798 835 799 JSValue* stringProtoFuncToLocaleUpperCase(ExecState* exec, JSObject* thisObj, const ArgList&)800 { 801 // This optimizes the common case that thisObj is a StringObject 802 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);803 804 JSString* sVal = this Obj->inherits(&StringObject::info)805 ? static_cast<StringObject*>(this Obj)->internalValue()836 JSValue* stringProtoFuncToLocaleUpperCase(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 837 { 838 // This optimizes the common case that thisObj is a StringObject 839 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 840 841 JSString* sVal = thisValue->isObject(&StringObject::info) 842 ? static_cast<StringObject*>(thisValue)->internalValue() 806 843 : static_cast<JSString*>(jsString(exec, s)); 807 844 int ssize = s.size(); … … 822 859 } 823 860 824 JSValue* stringProtoFuncLocaleCompare(ExecState* exec, JSObject* thisObj, const ArgList& args)861 JSValue* stringProtoFuncLocaleCompare(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 825 862 { 826 863 if (args.size() < 1) … … 828 865 829 866 // This optimizes the common case that thisObj is a StringObject 830 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);867 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 831 868 JSValue* a0 = args[0]; 832 869 return jsNumber(exec, localeCompare(s, a0->toString(exec))); 833 870 } 834 871 835 JSValue* stringProtoFuncBig(ExecState* exec, JSObject* thisObj, const ArgList&)836 { 837 // This optimizes the common case that thisObj is a StringObject 838 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);872 JSValue* stringProtoFuncBig(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 873 { 874 // This optimizes the common case that thisObj is a StringObject 875 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 839 876 return jsString(exec, "<big>" + s + "</big>"); 840 877 } 841 878 842 JSValue* stringProtoFuncSmall(ExecState* exec, JSObject* thisObj, const ArgList&)843 { 844 // This optimizes the common case that thisObj is a StringObject 845 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);879 JSValue* stringProtoFuncSmall(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 880 { 881 // This optimizes the common case that thisObj is a StringObject 882 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 846 883 return jsString(exec, "<small>" + s + "</small>"); 847 884 } 848 885 849 JSValue* stringProtoFuncBlink(ExecState* exec, JSObject* thisObj, const ArgList&)850 { 851 // This optimizes the common case that thisObj is a StringObject 852 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);886 JSValue* stringProtoFuncBlink(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 887 { 888 // This optimizes the common case that thisObj is a StringObject 889 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 853 890 return jsString(exec, "<blink>" + s + "</blink>"); 854 891 } 855 892 856 JSValue* stringProtoFuncBold(ExecState* exec, JSObject* thisObj, const ArgList&)857 { 858 // This optimizes the common case that thisObj is a StringObject 859 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);893 JSValue* stringProtoFuncBold(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 894 { 895 // This optimizes the common case that thisObj is a StringObject 896 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 860 897 return jsString(exec, "<b>" + s + "</b>"); 861 898 } 862 899 863 JSValue* stringProtoFuncFixed(ExecState* exec, JSObject* thisObj, const ArgList&)864 { 865 // This optimizes the common case that thisObj is a StringObject 866 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);900 JSValue* stringProtoFuncFixed(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 901 { 902 // This optimizes the common case that thisObj is a StringObject 903 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 867 904 return jsString(exec, "<tt>" + s + "</tt>"); 868 905 } 869 906 870 JSValue* stringProtoFuncItalics(ExecState* exec, JSObject* thisObj, const ArgList&)871 { 872 // This optimizes the common case that thisObj is a StringObject 873 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);907 JSValue* stringProtoFuncItalics(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 908 { 909 // This optimizes the common case that thisObj is a StringObject 910 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 874 911 return jsString(exec, "<i>" + s + "</i>"); 875 912 } 876 913 877 JSValue* stringProtoFuncStrike(ExecState* exec, JSObject* thisObj, const ArgList&)878 { 879 // This optimizes the common case that thisObj is a StringObject 880 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);914 JSValue* stringProtoFuncStrike(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 915 { 916 // This optimizes the common case that thisObj is a StringObject 917 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 881 918 return jsString(exec, "<strike>" + s + "</strike>"); 882 919 } 883 920 884 JSValue* stringProtoFuncSub(ExecState* exec, JSObject* thisObj, const ArgList&)885 { 886 // This optimizes the common case that thisObj is a StringObject 887 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);921 JSValue* stringProtoFuncSub(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 922 { 923 // This optimizes the common case that thisObj is a StringObject 924 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 888 925 return jsString(exec, "<sub>" + s + "</sub>"); 889 926 } 890 927 891 JSValue* stringProtoFuncSup(ExecState* exec, JSObject* thisObj, const ArgList&)892 { 893 // This optimizes the common case that thisObj is a StringObject 894 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);928 JSValue* stringProtoFuncSup(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 929 { 930 // This optimizes the common case that thisObj is a StringObject 931 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 895 932 return jsString(exec, "<sup>" + s + "</sup>"); 896 933 } 897 934 898 JSValue* stringProtoFuncFontcolor(ExecState* exec, JSObject* thisObj, const ArgList& args)899 { 900 // This optimizes the common case that thisObj is a StringObject 901 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);935 JSValue* stringProtoFuncFontcolor(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 936 { 937 // This optimizes the common case that thisObj is a StringObject 938 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 902 939 JSValue* a0 = args[0]; 903 940 return jsString(exec, "<font color=\"" + a0->toString(exec) + "\">" + s + "</font>"); 904 941 } 905 942 906 JSValue* stringProtoFuncFontsize(ExecState* exec, JSObject* thisObj, const ArgList& args)907 { 908 // This optimizes the common case that thisObj is a StringObject 909 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);943 JSValue* stringProtoFuncFontsize(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 944 { 945 // This optimizes the common case that thisObj is a StringObject 946 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 910 947 JSValue* a0 = args[0]; 911 948 return jsString(exec, "<font size=\"" + a0->toString(exec) + "\">" + s + "</font>"); 912 949 } 913 950 914 JSValue* stringProtoFuncAnchor(ExecState* exec, JSObject* thisObj, const ArgList& args)915 { 916 // This optimizes the common case that thisObj is a StringObject 917 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);951 JSValue* stringProtoFuncAnchor(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 952 { 953 // This optimizes the common case that thisObj is a StringObject 954 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 918 955 JSValue* a0 = args[0]; 919 956 return jsString(exec, "<a name=\"" + a0->toString(exec) + "\">" + s + "</a>"); 920 957 } 921 958 922 JSValue* stringProtoFuncLink(ExecState* exec, JSObject* thisObj, const ArgList& args)923 { 924 // This optimizes the common case that thisObj is a StringObject 925 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);959 JSValue* stringProtoFuncLink(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 960 { 961 // This optimizes the common case that thisObj is a StringObject 962 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 926 963 JSValue* a0 = args[0]; 927 964 return jsString(exec, "<a href=\"" + a0->toString(exec) + "\">" + s + "</a>"); … … 929 966 930 967 // ------------------------------ StringConstructor ------------------------------ 968 969 static JSValue* stringFromCharCode(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 970 { 971 UString s; 972 if (args.size()) { 973 UChar* buf = static_cast<UChar*>(fastMalloc(args.size() * sizeof(UChar))); 974 UChar* p = buf; 975 ArgList::const_iterator end = args.end(); 976 for (ArgList::const_iterator it = args.begin(); it != end; ++it) 977 *p++ = static_cast<UChar>((*it)->toUInt32(exec)); 978 s = UString(buf, args.size(), false); 979 } else 980 s = ""; 981 982 return jsString(exec, s); 983 } 931 984 932 985 StringConstructor::StringConstructor(ExecState* exec, FunctionPrototype* funcProto, StringPrototype* stringProto) … … 934 987 { 935 988 // ECMA 15.5.3.1 String.prototype 936 putDirect(exec->propertyNames().prototype, stringProto, DontEnum|DontDelete|ReadOnly); 937 938 putDirectFunction(new (exec) StringConstructorFunction(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum); 989 putDirect(exec->propertyNames().prototype, stringProto, ReadOnly | DontEnum | DontDelete); 990 991 // ECMA 15.5.3.2 fromCharCode() 992 putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 1, exec->propertyNames().fromCharCode, stringFromCharCode), DontEnum); 939 993 940 994 // no. of arguments for constructor 941 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum); 942 } 943 944 945 ConstructType StringConstructor::getConstructData(ConstructData&) 946 { 995 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete); 996 } 997 998 // ECMA 15.5.2 999 static JSObject* constructWithStringConstructor(ExecState* exec, JSObject*, const ArgList& args) 1000 { 1001 JSObject* prototype = exec->lexicalGlobalObject()->stringPrototype(); 1002 if (args.isEmpty()) 1003 return new (exec) StringObject(exec, prototype); 1004 return new (exec) StringObject(exec, prototype, args[0]->toString(exec)); 1005 } 1006 1007 ConstructType StringConstructor::getConstructData(ConstructData& constructData) 1008 { 1009 constructData.native.function = constructWithStringConstructor; 947 1010 return ConstructTypeNative; 948 1011 } 949 1012 950 // ECMA 15.5.2951 JSObject* StringConstructor::construct(ExecState* exec, const ArgList& args)952 {953 JSObject* proto = exec->lexicalGlobalObject()->stringPrototype();954 if (!args.size())955 return new (exec) StringObject(exec, proto);956 return new (exec) StringObject(exec, proto, args[0]->toString(exec));957 }958 959 1013 // ECMA 15.5.1 960 JSValue *StringConstructor::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const ArgList &args) 961 { 962 if (args.isEmpty()) 963 return jsString(exec, ""); 964 else { 965 JSValue *v = args[0]; 966 return jsString(exec, v->toString(exec)); 967 } 968 } 969 970 // ------------------------------ StringConstructorFunction -------------------------- 971 972 // ECMA 15.5.3.2 fromCharCode() 973 StringConstructorFunction::StringConstructorFunction(ExecState* exec, FunctionPrototype* funcProto, const Identifier& name) 974 : InternalFunction(funcProto, name) 975 { 976 putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete|ReadOnly|DontEnum); 977 } 978 979 JSValue *StringConstructorFunction::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const ArgList &args) 980 { 981 UString s; 982 if (args.size()) { 983 UChar *buf = static_cast<UChar *>(fastMalloc(args.size() * sizeof(UChar))); 984 UChar *p = buf; 985 ArgList::const_iterator end = args.end(); 986 for (ArgList::const_iterator it = args.begin(); it != end; ++it) { 987 unsigned short u = static_cast<unsigned short>((*it)->toUInt32(exec)); 988 *p++ = UChar(u); 989 } 990 s = UString(buf, args.size(), false); 991 } else 992 s = ""; 993 994 return jsString(exec, s); 1014 static JSValue* callStringConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 1015 { 1016 if (args.isEmpty()) 1017 return jsString(exec, ""); 1018 return jsString(exec, args[0]->toString(exec)); 1019 } 1020 1021 CallType StringConstructor::getCallData(CallData& callData) 1022 { 1023 callData.native.function = callStringConstructor; 1024 return CallTypeNative; 995 1025 } 996 1026 -
trunk/JavaScriptCore/kjs/string_object.h
r34659 r34754 80 80 * @internal 81 81 * 82 * Functions to implement all methods that are properties of the83 * String.prototype object84 */85 86 JSValue* stringProtoFuncToString(ExecState*, JSObject*, const ArgList&);87 JSValue* stringProtoFuncValueOf(ExecState*, JSObject*, const ArgList&);88 JSValue* stringProtoFuncCharAt(ExecState*, JSObject*, const ArgList&);89 JSValue* stringProtoFuncCharCodeAt(ExecState*, JSObject*, const ArgList&);90 JSValue* stringProtoFuncConcat(ExecState*, JSObject*, const ArgList&);91 JSValue* stringProtoFuncIndexOf(ExecState*, JSObject*, const ArgList&);92 JSValue* stringProtoFuncLastIndexOf(ExecState*, JSObject*, const ArgList&);93 JSValue* stringProtoFuncMatch(ExecState*, JSObject*, const ArgList&);94 JSValue* stringProtoFuncReplace(ExecState*, JSObject*, const ArgList&);95 JSValue* stringProtoFuncSearch(ExecState*, JSObject*, const ArgList&);96 JSValue* stringProtoFuncSlice(ExecState*, JSObject*, const ArgList&);97 JSValue* stringProtoFuncSplit(ExecState*, JSObject*, const ArgList&);98 JSValue* stringProtoFuncSubstr(ExecState*, JSObject*, const ArgList&);99 JSValue* stringProtoFuncSubstring(ExecState*, JSObject*, const ArgList&);100 JSValue* stringProtoFuncToLowerCase(ExecState*, JSObject*, const ArgList&);101 JSValue* stringProtoFuncToUpperCase(ExecState*, JSObject*, const ArgList&);102 JSValue* stringProtoFuncToLocaleLowerCase(ExecState*, JSObject*, const ArgList&);103 JSValue* stringProtoFuncToLocaleUpperCase(ExecState*, JSObject*, const ArgList&);104 JSValue* stringProtoFuncLocaleCompare(ExecState*, JSObject*, const ArgList&);105 106 JSValue* stringProtoFuncBig(ExecState*, JSObject*, const ArgList&);107 JSValue* stringProtoFuncSmall(ExecState*, JSObject*, const ArgList&);108 JSValue* stringProtoFuncBlink(ExecState*, JSObject*, const ArgList&);109 JSValue* stringProtoFuncBold(ExecState*, JSObject*, const ArgList&);110 JSValue* stringProtoFuncFixed(ExecState*, JSObject*, const ArgList&);111 JSValue* stringProtoFuncItalics(ExecState*, JSObject*, const ArgList&);112 JSValue* stringProtoFuncStrike(ExecState*, JSObject*, const ArgList&);113 JSValue* stringProtoFuncSub(ExecState*, JSObject*, const ArgList&);114 JSValue* stringProtoFuncSup(ExecState*, JSObject*, const ArgList&);115 JSValue* stringProtoFuncFontcolor(ExecState*, JSObject*, const ArgList&);116 JSValue* stringProtoFuncFontsize(ExecState*, JSObject*, const ArgList&);117 JSValue* stringProtoFuncAnchor(ExecState*, JSObject*, const ArgList&);118 JSValue* stringProtoFuncLink(ExecState*, JSObject*, const ArgList&);119 120 /**121 * @internal122 *123 82 * The initial value of the the global variable's "String" property 124 83 */ … … 126 85 public: 127 86 StringConstructor(ExecState*, FunctionPrototype*, StringPrototype*); 128 129 87 virtual ConstructType getConstructData(ConstructData&); 130 virtual JSObject* construct(ExecState*, const ArgList&); 131 132 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const ArgList& args); 88 virtual CallType getCallData(CallData&); 133 89 }; 134 90 … … 142 98 public: 143 99 StringConstructorFunction(ExecState*, FunctionPrototype*, const Identifier&); 144 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const ArgList& args);100 virtual CallType getCallData(CallData&); 145 101 }; 146 102
Note:
See TracChangeset
for help on using the changeset viewer.