Changeset 34754 in webkit for trunk/JavaScriptCore/kjs/NumberObject.cpp
- Timestamp:
- Jun 23, 2008, 10:23:17 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.