Changeset 10084 in webkit for trunk/JavaScriptCore/kjs/internal.cpp
- Timestamp:
- Aug 7, 2005, 9:07:46 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/internal.cpp
r10076 r10084 54 54 extern int kjsyyparse(); 55 55 56 using namespace KJS; 56 namespace KJS { 57 57 58 58 #if !APPLE_CHANGES 59 59 60 namespace KJS {61 60 #ifdef WORDS_BIGENDIAN 62 61 const unsigned char NaN_Bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 }; … … 72 71 const double NaN = *(const double*) NaN_Bytes; 73 72 const double Inf = *(const double*) Inf_Bytes; 74 };75 73 76 74 #endif // APPLE_CHANGES … … 108 106 // ------------------------------ UndefinedImp --------------------------------- 109 107 110 UndefinedImp *UndefinedImp::staticUndefined = 0; 111 112 Value UndefinedImp::toPrimitive(ExecState */*exec*/, Type) const 113 { 114 return Value((ValueImp*)this); 108 ValueImp *UndefinedImp::toPrimitive(ExecState */*exec*/, Type) const 109 { 110 return const_cast<UndefinedImp *>(this); 115 111 } 116 112 … … 130 126 } 131 127 132 Object 133 { 134 Object 128 ObjectImp *UndefinedImp::toObject(ExecState *exec) const 129 { 130 ObjectImp *err = Error::create(exec, TypeError, I18N_NOOP("Undefined value")); 135 131 exec->setException(err); 136 132 return err; … … 139 135 // ------------------------------ NullImp -------------------------------------- 140 136 141 NullImp *NullImp::staticNull = 0; 142 143 Value NullImp::toPrimitive(ExecState */*exec*/, Type) const 144 { 145 return Value((ValueImp*)this); 137 ValueImp *NullImp::toPrimitive(ExecState */*exec*/, Type) const 138 { 139 return const_cast<NullImp *>(this); 146 140 } 147 141 … … 161 155 } 162 156 163 Object 164 { 165 Object 157 ObjectImp *NullImp::toObject(ExecState *exec) const 158 { 159 ObjectImp *err = Error::create(exec, TypeError, I18N_NOOP("Null value")); 166 160 exec->setException(err); 167 161 return err; … … 170 164 // ------------------------------ BooleanImp ----------------------------------- 171 165 172 BooleanImp* BooleanImp::staticTrue = 0; 173 BooleanImp* BooleanImp::staticFalse = 0; 174 175 Value BooleanImp::toPrimitive(ExecState */*exec*/, Type) const 176 { 177 return Value((ValueImp*)this); 166 ValueImp *BooleanImp::toPrimitive(ExecState */*exec*/, Type) const 167 { 168 return const_cast<BooleanImp *>(this); 178 169 } 179 170 … … 193 184 } 194 185 195 Object 186 ObjectImp *BooleanImp::toObject(ExecState *exec) const 196 187 { 197 188 List args; 198 189 args.append(const_cast<BooleanImp*>(this)); 199 return Object::dynamicCast(exec->lexicalInterpreter()->builtinBoolean().construct(exec,args));190 return static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinBoolean()->construct(exec,args)); 200 191 } 201 192 202 193 // ------------------------------ StringImp ------------------------------------ 203 194 204 Value 205 { 206 return Value((ValueImp*)this);195 ValueImp *StringImp::toPrimitive(ExecState */*exec*/, Type) const 196 { 197 return const_cast<StringImp *>(this); 207 198 } 208 199 … … 222 213 } 223 214 224 Object 215 ObjectImp *StringImp::toObject(ExecState *exec) const 225 216 { 226 217 List args; 227 218 args.append(const_cast<StringImp*>(this)); 228 return Object(static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinString().construct(exec, args).imp()));219 return static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinString()->construct(exec, args)); 229 220 } 230 221 231 222 // ------------------------------ NumberImp ------------------------------------ 232 223 233 NumberImp *NumberImp::staticNaN; 234 235 ValueImp *NumberImp::create(int i) 236 { 237 if (SimpleNumber::fits(i)) 238 return SimpleNumber::make(i); 239 return new NumberImp(static_cast<double>(i)); 240 } 241 242 ValueImp *NumberImp::create(double d) 243 { 244 if (SimpleNumber::fits(d)) 245 return SimpleNumber::make((int)d); 246 if (isNaN(d)) 247 return staticNaN; 248 return new NumberImp(d); 249 } 250 251 Value NumberImp::toPrimitive(ExecState *, Type) const 252 { 253 return Number((NumberImp*)this); 224 ValueImp *NumberImp::toPrimitive(ExecState *, Type) const 225 { 226 return const_cast<NumberImp *>(this); 254 227 } 255 228 … … 271 244 } 272 245 273 Object 246 ObjectImp *NumberImp::toObject(ExecState *exec) const 274 247 { 275 248 List args; 276 249 args.append(const_cast<NumberImp*>(this)); 277 return Object::dynamicCast(exec->lexicalInterpreter()->builtinNumber().construct(exec,args));278 } 279 280 bool NumberImp:: toUInt32(unsigned& uint32) const281 { 282 uint32 = (u nsigned)val;250 return static_cast<ObjectImp *>(exec->lexicalInterpreter()->builtinNumber()->construct(exec,args)); 251 } 252 253 bool NumberImp::getUInt32(uint32_t& uint32) const 254 { 255 uint32 = (uint32_t)val; 283 256 return (double)uint32 == val; 284 257 } … … 316 289 bool LabelStack::push(const Identifier &id) 317 290 { 318 if ( id.isEmpty() ||contains(id))291 if (contains(id)) 319 292 return false; 320 293 … … 366 339 367 340 // ECMA 10.2 368 ContextImp::ContextImp(Object &glob, InterpreterImp *interpreter, Object &thisV, CodeType type,341 ContextImp::ContextImp(ObjectImp *glob, InterpreterImp *interpreter, ObjectImp *thisV, CodeType type, 369 342 ContextImp *callingCon, FunctionImp *func, const List *args) 370 343 : _interpreter(interpreter), _function(func), _arguments(args) … … 375 348 // create and initialize activation object (ECMA 10.1.6) 376 349 if (type == FunctionCode || type == AnonymousCode ) { 377 activation = Object(new ActivationImp(func, *args));350 activation = new ActivationImp(func, *args); 378 351 variable = activation; 379 352 } else { 380 activation = Object();353 activation = NULL; 381 354 variable = glob; 382 355 } … … 393 366 case GlobalCode: 394 367 scope.clear(); 395 scope.push(glob .imp());396 thisVal = Object(static_cast<ObjectImp*>(glob.imp()));368 scope.push(glob); 369 thisVal = static_cast<ObjectImp*>(glob); 397 370 break; 398 371 case FunctionCode: … … 400 373 if (type == FunctionCode) { 401 374 scope = func->scope(); 402 scope.push(activation .imp());375 scope.push(activation); 403 376 } else { 404 377 scope.clear(); 405 scope.push(glob .imp());406 scope.push(activation .imp());378 scope.push(glob); 379 scope.push(activation); 407 380 } 408 381 variable = activation; // TODO: DontDelete ? (ECMA 10.2.3) … … 479 452 void InterpreterImp::globalInit() 480 453 { 481 //fprintf( stderr, "InterpreterImp::globalInit()\n" ); 482 UndefinedImp::staticUndefined = new UndefinedImp(); 483 NullImp::staticNull = new NullImp(); 484 BooleanImp::staticTrue = new BooleanImp(true); 485 BooleanImp::staticFalse = new BooleanImp(false); 486 NumberImp::staticNaN = new NumberImp(NaN); 454 ConstantValues::init(); 487 455 } 488 456 489 457 void InterpreterImp::globalClear() 490 458 { 491 //fprintf( stderr, "InterpreterImp::globalClear()\n" ); 492 UndefinedImp::staticUndefined = 0; 493 NullImp::staticNull = 0; 494 BooleanImp::staticTrue = 0; 495 BooleanImp::staticFalse = 0; 496 NumberImp::staticNaN = 0; 497 } 498 499 InterpreterImp::InterpreterImp(Interpreter *interp, const Object &glob) 500 : globExec(interp, 0) 501 , _context(0) 459 ConstantValues::clear(); 460 } 461 462 InterpreterImp::InterpreterImp(Interpreter *interp, ObjectImp *glob) 463 : globExec(interp, 0) 464 , _context(0) 502 465 { 503 466 // add this interpreter to the global chain … … 516 479 } 517 480 518 InterpreterMap::setInterpreterForGlobalObject(this, glob .imp());481 InterpreterMap::setInterpreterForGlobalObject(this, glob); 519 482 520 483 global = glob; … … 551 514 552 515 FunctionPrototypeImp *funcProto = new FunctionPrototypeImp(&globExec); 553 b_FunctionPrototype = Object(funcProto);516 b_FunctionPrototype = funcProto; 554 517 ObjectPrototypeImp *objProto = new ObjectPrototypeImp(&globExec, funcProto); 555 b_ObjectPrototype = Object(objProto);518 b_ObjectPrototype = objProto; 556 519 funcProto->setPrototype(b_ObjectPrototype); 557 520 558 521 ArrayPrototypeImp *arrayProto = new ArrayPrototypeImp(&globExec, objProto); 559 b_ArrayPrototype = Object(arrayProto);522 b_ArrayPrototype = arrayProto; 560 523 StringPrototypeImp *stringProto = new StringPrototypeImp(&globExec, objProto); 561 b_StringPrototype = Object(stringProto);524 b_StringPrototype = stringProto; 562 525 BooleanPrototypeImp *booleanProto = new BooleanPrototypeImp(&globExec, objProto, funcProto); 563 b_BooleanPrototype = Object(booleanProto);526 b_BooleanPrototype = booleanProto; 564 527 NumberPrototypeImp *numberProto = new NumberPrototypeImp(&globExec, objProto, funcProto); 565 b_NumberPrototype = Object(numberProto);528 b_NumberPrototype = numberProto; 566 529 DatePrototypeImp *dateProto = new DatePrototypeImp(&globExec, objProto); 567 b_DatePrototype = Object(dateProto);530 b_DatePrototype = dateProto; 568 531 RegExpPrototypeImp *regexpProto = new RegExpPrototypeImp(&globExec, objProto, funcProto); 569 b_RegExpPrototype = Object(regexpProto);532 b_RegExpPrototype = regexpProto; 570 533 ErrorPrototypeImp *errorProto = new ErrorPrototypeImp(&globExec, objProto, funcProto); 571 b_ErrorPrototype = Object(errorProto);572 573 static_cast<ObjectImp*>(global .imp())->setPrototype(b_ObjectPrototype);534 b_ErrorPrototype = errorProto; 535 536 static_cast<ObjectImp*>(global)->setPrototype(b_ObjectPrototype); 574 537 575 538 // Constructors (Object, Array, etc.) 576 b_Object = Object(new ObjectObjectImp(&globExec, objProto, funcProto));577 b_Function = Object(new FunctionObjectImp(&globExec, funcProto));578 b_Array = Object(new ArrayObjectImp(&globExec, funcProto, arrayProto));579 b_String = Object(new StringObjectImp(&globExec, funcProto, stringProto));580 b_Boolean = Object(new BooleanObjectImp(&globExec, funcProto, booleanProto));581 b_Number = Object(new NumberObjectImp(&globExec, funcProto, numberProto));582 b_Date = Object(new DateObjectImp(&globExec, funcProto, dateProto));583 b_RegExp = Object(new RegExpObjectImp(&globExec, funcProto, regexpProto));584 b_Error = Object(new ErrorObjectImp(&globExec, funcProto, errorProto));539 b_Object = new ObjectObjectImp(&globExec, objProto, funcProto); 540 b_Function = new FunctionObjectImp(&globExec, funcProto); 541 b_Array = new ArrayObjectImp(&globExec, funcProto, arrayProto); 542 b_String = new StringObjectImp(&globExec, funcProto, stringProto); 543 b_Boolean = new BooleanObjectImp(&globExec, funcProto, booleanProto); 544 b_Number = new NumberObjectImp(&globExec, funcProto, numberProto); 545 b_Date = new DateObjectImp(&globExec, funcProto, dateProto); 546 b_RegExp = new RegExpObjectImp(&globExec, funcProto, regexpProto); 547 b_Error = new ErrorObjectImp(&globExec, funcProto, errorProto); 585 548 586 549 // Error object prototypes 587 b_evalErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, EvalError, 588 "EvalError", "EvalError")); 589 b_rangeErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, RangeError, 590 "RangeError", "RangeError")); 591 b_referenceErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, ReferenceError, 592 "ReferenceError", "ReferenceError")); 593 b_syntaxErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, SyntaxError, 594 "SyntaxError", "SyntaxError")); 595 b_typeErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, TypeError, 596 "TypeError", "TypeError")); 597 b_uriErrorPrototype = Object(new NativeErrorPrototypeImp(&globExec, errorProto, URIError, 598 "URIError", "URIError")); 550 b_evalErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, EvalError, "EvalError", "EvalError"); 551 b_rangeErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, RangeError, "RangeError", "RangeError"); 552 b_referenceErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, ReferenceError, "ReferenceError", "ReferenceError"); 553 b_syntaxErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, SyntaxError, "SyntaxError", "SyntaxError"); 554 b_typeErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, TypeError, "TypeError", "TypeError"); 555 b_uriErrorPrototype = new NativeErrorPrototypeImp(&globExec, errorProto, URIError, "URIError", "URIError"); 599 556 600 557 // Error objects 601 b_evalError = Object(new NativeErrorImp(&globExec, funcProto, b_evalErrorPrototype));602 b_rangeError = Object(new NativeErrorImp(&globExec, funcProto, b_rangeErrorPrototype));603 b_referenceError = Object(new NativeErrorImp(&globExec, funcProto, b_referenceErrorPrototype));604 b_syntaxError = Object(new NativeErrorImp(&globExec, funcProto, b_syntaxErrorPrototype));605 b_typeError = Object(new NativeErrorImp(&globExec, funcProto, b_typeErrorPrototype));606 b_uriError = Object(new NativeErrorImp(&globExec, funcProto, b_uriErrorPrototype));558 b_evalError = new NativeErrorImp(&globExec, funcProto, b_evalErrorPrototype); 559 b_rangeError = new NativeErrorImp(&globExec, funcProto, b_rangeErrorPrototype); 560 b_referenceError = new NativeErrorImp(&globExec, funcProto, b_referenceErrorPrototype); 561 b_syntaxError = new NativeErrorImp(&globExec, funcProto, b_syntaxErrorPrototype); 562 b_typeError = new NativeErrorImp(&globExec, funcProto, b_typeErrorPrototype); 563 b_uriError = new NativeErrorImp(&globExec, funcProto, b_uriErrorPrototype); 607 564 608 565 // ECMA 15.3.4.1 609 566 funcProto->put(&globExec, "constructor", b_Function, DontEnum); 610 567 611 global .put(&globExec, "Object", b_Object, DontEnum);612 global .put(&globExec, "Function", b_Function, DontEnum);613 global .put(&globExec, "Array", b_Array, DontEnum);614 global .put(&globExec, "Boolean", b_Boolean, DontEnum);615 global .put(&globExec, "String", b_String, DontEnum);616 global .put(&globExec, "Number", b_Number, DontEnum);617 global .put(&globExec, "Date", b_Date, DontEnum);618 global .put(&globExec, "RegExp", b_RegExp, DontEnum);619 global .put(&globExec, "Error", b_Error, DontEnum);568 global->put(&globExec, "Object", b_Object, DontEnum); 569 global->put(&globExec, "Function", b_Function, DontEnum); 570 global->put(&globExec, "Array", b_Array, DontEnum); 571 global->put(&globExec, "Boolean", b_Boolean, DontEnum); 572 global->put(&globExec, "String", b_String, DontEnum); 573 global->put(&globExec, "Number", b_Number, DontEnum); 574 global->put(&globExec, "Date", b_Date, DontEnum); 575 global->put(&globExec, "RegExp", b_RegExp, DontEnum); 576 global->put(&globExec, "Error", b_Error, DontEnum); 620 577 // Using Internal for those to have something != 0 621 578 // (see kjs_window). Maybe DontEnum would be ok too ? 622 global .put(&globExec, "EvalError",b_evalError, Internal);623 global .put(&globExec, "RangeError",b_rangeError, Internal);624 global .put(&globExec, "ReferenceError",b_referenceError, Internal);625 global .put(&globExec, "SyntaxError",b_syntaxError, Internal);626 global .put(&globExec, "TypeError",b_typeError, Internal);627 global .put(&globExec, "URIError",b_uriError, Internal);579 global->put(&globExec, "EvalError",b_evalError, Internal); 580 global->put(&globExec, "RangeError",b_rangeError, Internal); 581 global->put(&globExec, "ReferenceError",b_referenceError, Internal); 582 global->put(&globExec, "SyntaxError",b_syntaxError, Internal); 583 global->put(&globExec, "TypeError",b_typeError, Internal); 584 global->put(&globExec, "URIError",b_uriError, Internal); 628 585 629 586 // Set the "constructor" property of all builtin constructors … … 637 594 regexpProto->put(&globExec, "constructor", b_RegExp, DontEnum | DontDelete | ReadOnly); 638 595 errorProto->put(&globExec, "constructor", b_Error, DontEnum | DontDelete | ReadOnly); 639 b_evalErrorPrototype .put(&globExec, "constructor", b_evalError, DontEnum | DontDelete | ReadOnly);640 b_rangeErrorPrototype .put(&globExec, "constructor", b_rangeError, DontEnum | DontDelete | ReadOnly);641 b_referenceErrorPrototype .put(&globExec, "constructor", b_referenceError, DontEnum | DontDelete | ReadOnly);642 b_syntaxErrorPrototype .put(&globExec, "constructor", b_syntaxError, DontEnum | DontDelete | ReadOnly);643 b_typeErrorPrototype .put(&globExec, "constructor", b_typeError, DontEnum | DontDelete | ReadOnly);644 b_uriErrorPrototype .put(&globExec, "constructor", b_uriError, DontEnum | DontDelete | ReadOnly);596 b_evalErrorPrototype->put(&globExec, "constructor", b_evalError, DontEnum | DontDelete | ReadOnly); 597 b_rangeErrorPrototype->put(&globExec, "constructor", b_rangeError, DontEnum | DontDelete | ReadOnly); 598 b_referenceErrorPrototype->put(&globExec, "constructor", b_referenceError, DontEnum | DontDelete | ReadOnly); 599 b_syntaxErrorPrototype->put(&globExec, "constructor", b_syntaxError, DontEnum | DontDelete | ReadOnly); 600 b_typeErrorPrototype->put(&globExec, "constructor", b_typeError, DontEnum | DontDelete | ReadOnly); 601 b_uriErrorPrototype->put(&globExec, "constructor", b_uriError, DontEnum | DontDelete | ReadOnly); 645 602 646 603 // built-in values 647 global .put(&globExec, "NaN", Number(NaN), DontEnum|DontDelete);648 global .put(&globExec, "Infinity", Number(Inf), DontEnum|DontDelete);649 global .put(&globExec, "undefined", Undefined(), DontEnum|DontDelete);604 global->put(&globExec, "NaN", jsNaN(), DontEnum|DontDelete); 605 global->put(&globExec, "Infinity", Number(Inf), DontEnum|DontDelete); 606 global->put(&globExec, "undefined", Undefined(), DontEnum|DontDelete); 650 607 651 608 // built-in functions 652 global .put(&globExec, "eval", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Eval, 1)), DontEnum);653 global .put(&globExec, "parseInt", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseInt, 2)), DontEnum);654 global .put(&globExec, "parseFloat", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseFloat, 1)), DontEnum);655 global .put(&globExec, "isNaN", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsNaN, 1)), DontEnum);656 global .put(&globExec, "isFinite", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsFinite, 1)), DontEnum);657 global .put(&globExec, "escape", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Escape, 1)), DontEnum);658 global .put(&globExec, "unescape", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::UnEscape, 1)), DontEnum);659 global .put(&globExec, "decodeURI", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURI, 1)), DontEnum);660 global .put(&globExec, "decodeURIComponent", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURIComponent, 1)), DontEnum);661 global .put(&globExec, "encodeURI", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURI, 1)), DontEnum);662 global .put(&globExec, "encodeURIComponent", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURIComponent, 1)), DontEnum);609 global->put(&globExec, "eval", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Eval, 1), DontEnum); 610 global->put(&globExec, "parseInt", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseInt, 2), DontEnum); 611 global->put(&globExec, "parseFloat", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseFloat, 1), DontEnum); 612 global->put(&globExec, "isNaN", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsNaN, 1), DontEnum); 613 global->put(&globExec, "isFinite", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsFinite, 1), DontEnum); 614 global->put(&globExec, "escape", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Escape, 1), DontEnum); 615 global->put(&globExec, "unescape", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::UnEscape, 1), DontEnum); 616 global->put(&globExec, "decodeURI", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURI, 1), DontEnum); 617 global->put(&globExec, "decodeURIComponent", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURIComponent, 1), DontEnum); 618 global->put(&globExec, "encodeURI", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURI, 1), DontEnum); 619 global->put(&globExec, "encodeURIComponent", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURIComponent, 1), DontEnum); 663 620 #ifndef NDEBUG 664 global .put(&globExec, "kjsprint", Object(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::KJSPrint, 1)), DontEnum);621 global->put(&globExec, "kjsprint", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::KJSPrint, 1), DontEnum); 665 622 #endif 666 623 667 624 // built-in objects 668 global .put(&globExec, "Math", Object(new MathObjectImp(&globExec, objProto)), DontEnum);625 global->put(&globExec, "Math", new MathObjectImp(&globExec, objProto), DontEnum); 669 626 } 670 627 … … 692 649 globalClear(); 693 650 } 694 InterpreterMap::removeInterpreterForGlobalObject(global .imp());651 InterpreterMap::removeInterpreterForGlobalObject(global); 695 652 696 653 #if APPLE_CHANGES … … 701 658 void InterpreterImp::mark() 702 659 { 703 //if (exVal && !exVal->marked()) 704 // exVal->mark(); 705 //if (retVal && !retVal->marked()) 706 // retVal->mark(); 707 if (UndefinedImp::staticUndefined && !UndefinedImp::staticUndefined->marked()) 708 UndefinedImp::staticUndefined->mark(); 709 if (NullImp::staticNull && !NullImp::staticNull->marked()) 710 NullImp::staticNull->mark(); 711 if (NumberImp::staticNaN && !NumberImp::staticNaN->marked()) 712 NumberImp::staticNaN->mark(); 713 if (BooleanImp::staticTrue && !BooleanImp::staticTrue->marked()) 714 BooleanImp::staticTrue->mark(); 715 if (BooleanImp::staticFalse && !BooleanImp::staticFalse->marked()) 716 BooleanImp::staticFalse->mark(); 717 //fprintf( stderr, "InterpreterImp::mark this=%p global.imp()=%p\n", this, global.imp() ); 660 ConstantValues::mark(); 718 661 if (m_interpreter) 719 662 m_interpreter->mark(); … … 736 679 } 737 680 738 Completion InterpreterImp::evaluate(const UString &code, const Value &thisV, const UString &sourceURL, int startingLineNumber)681 Completion InterpreterImp::evaluate(const UString &code, ValueImp *thisV, const UString &sourceURL, int startingLineNumber) 739 682 { 740 683 #if APPLE_CHANGES … … 774 717 // no program node means a syntax error occurred 775 718 if (!progNode) { 776 Object 777 err .put(&globExec, "sid", Number(sid));719 ObjectImp *err = Error::create(&globExec, SyntaxError, errMsg.ascii(), errLine, -1, &sourceURL); 720 err->put(&globExec, "sid", Number(sid)); 778 721 #if APPLE_CHANGES 779 722 unlockInterpreter(); … … 787 730 progNode->ref(); 788 731 789 Object &globalObj = globalObject();790 Object 791 792 if ( !thisV.isNull()) {732 ObjectImp *globalObj = globalObject(); 733 ObjectImp *thisObj = globalObject(); 734 735 if (thisV) { 793 736 // "this" must be an object... use same rules as Function.prototype.apply() 794 if (thisV .isA(NullType) || thisV.isA(UndefinedType))737 if (thisV->isUndefinedOrNull()) 795 738 thisObj = globalObject(); 796 739 else { 797 thisObj = thisV .toObject(&globExec);740 thisObj = thisV->toObject(&globExec); 798 741 } 799 742 } … … 801 744 Completion res; 802 745 if (globExec.hadException()) { 803 // the thisArg .toObject() conversion above might have thrown an exception - if so,746 // the thisArg->toObject() conversion above might have thrown an exception - if so, 804 747 // propagate it back 805 748 res = Completion(Throw, globExec.exception()); … … 925 868 } 926 869 927 Boolean InternalFunctionImp::hasInstance(ExecState *exec, const Value &value)928 { 929 if ( value.type() != ObjectType)930 return Boolean(false);931 932 Value 933 if ( prot.type() != ObjectType && prot.type() != NullType) {934 Object 870 bool InternalFunctionImp::hasInstance(ExecState *exec, ValueImp *value) 871 { 872 if (!value->isObject()) 873 return false; 874 875 ValueImp *prot = get(exec,prototypePropertyName); 876 if (!prot->isObject() && !prot->isNull()) { 877 ObjectImp *err = Error::create(exec, TypeError, "Invalid prototype encountered " 935 878 "in instanceof operation."); 936 879 exec->setException(err); 937 return Boolean(false);938 } 939 940 Object v = Object(static_cast<ObjectImp*>(value.imp()));941 while ((v = Object::dynamicCast(v.prototype())).imp()) {942 if (v .imp() == prot.imp())943 return Boolean(true);944 } 945 return Boolean(false);880 return false; 881 } 882 883 ObjectImp *v = static_cast<ObjectImp *>(value); 884 while ((v = v->prototype()->getObject())) { 885 if (v == prot) 886 return true; 887 } 888 return false; 946 889 } 947 890 948 891 // ------------------------------ global functions ----------------------------- 949 892 950 double KJS::roundValue(ExecState *exec, const Value &v) 951 { 952 Number n = v.toNumber(exec); 953 double d = n.value(); 893 double roundValue(ExecState *exec, ValueImp *v) 894 { 895 double d = v->toNumber(exec); 954 896 double ad = fabs(d); 955 897 if (ad == 0 || isNaN(d) || isInf(d)) … … 960 902 #ifndef NDEBUG 961 903 #include <stdio.h> 962 void KJS::printInfo(ExecState *exec, const char *s, const Value &o, int lineno)963 { 964 if ( o.isNull())904 void printInfo(ExecState *exec, const char *s, ValueImp *o, int lineno) 905 { 906 if (!o) 965 907 fprintf(stderr, "KJS: %s: (null)", s); 966 908 else { 967 Value 909 ValueImp *v = o; 968 910 969 911 UString name; 970 switch ( v.type()) {912 switch (v->type()) { 971 913 case UnspecifiedType: 972 914 name = "Unspecified"; … … 988 930 break; 989 931 case ObjectType: 990 name = Object::dynamicCast(v).className();932 name = static_cast<ObjectImp *>(v)->className(); 991 933 if (name.isNull()) 992 934 name = "(unknown class)"; 993 935 break; 994 936 } 995 UString vString = v .toString(exec);937 UString vString = v->toString(exec); 996 938 if ( vString.size() > 50 ) 997 939 vString = vString.substr( 0, 50 ) + "..."; … … 1000 942 1001 943 fprintf(stderr, "KJS: %s: %s : %s (%p)", 1002 s, tempString.c_str(), name.ascii(), (void*)v .imp());944 s, tempString.c_str(), name.ascii(), (void*)v); 1003 945 1004 946 if (lineno >= 0) … … 1009 951 } 1010 952 #endif 953 954 }
Note:
See TracChangeset
for help on using the changeset viewer.