Changeset 29541 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jan 16, 2008, 2:31:17 PM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r29538 r29541 1 2008-01-16 Sam Weinig <[email protected]> 2 3 Reviewed by Oliver. 4 5 Clean up MathObjectImp, it needed a little scrubbing. 6 7 * kjs/math_object.cpp: 8 (KJS::MathObjectImp::MathObjectImp): 9 (KJS::MathObjectImp::getOwnPropertySlot): 10 (KJS::MathObjectImp::getValueProperty): 11 (KJS::mathProtoFuncACos): 12 (KJS::mathProtoFuncASin): 13 (KJS::mathProtoFuncATan): 14 (KJS::mathProtoFuncATan2): 15 (KJS::mathProtoFuncCos): 16 (KJS::mathProtoFuncExp): 17 (KJS::mathProtoFuncLog): 18 (KJS::mathProtoFuncSin): 19 (KJS::mathProtoFuncSqrt): 20 (KJS::mathProtoFuncTan): 21 * kjs/math_object.h: 22 (KJS::MathObjectImp::classInfo): 23 (KJS::MathObjectImp::): 24 1 25 2008-01-16 Sam Weinig <[email protected]> 2 26 -
trunk/JavaScriptCore/kjs/math_object.cpp
r29508 r29541 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 2 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 4 * Copyright (C) 2007 Apple Inc. All Rights Reserved.3 * Copyright (C) 2007, 2008 Apple Inc. All Rights Reserved. 5 4 * 6 5 * This library is free software; you can redistribute it and/or … … 66 65 */ 67 66 68 MathObjectImp::MathObjectImp(ExecState * /*exec*/, 69 ObjectPrototype *objProto) 70 : JSObject(objProto) 67 MathObjectImp::MathObjectImp(ExecState*, ObjectPrototype* objectPrototype) 68 : JSObject(objectPrototype) 71 69 { 72 70 } … … 74 72 // ECMA 15.8 75 73 76 bool MathObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot) 77 { 78 return getStaticPropertySlot<MathObjectImp, JSObject>(exec, &mathTable, this, propertyName, slot); 79 } 80 81 JSValue *MathObjectImp::getValueProperty(ExecState *, int token) const 82 { 83 double d = -42; // ;) 84 switch (token) { 85 case Euler: 86 d = exp(1.0); 87 break; 88 case Ln2: 89 d = log(2.0); 90 break; 91 case Ln10: 92 d = log(10.0); 93 break; 94 case Log2E: 95 d = 1.0/log(2.0); 96 break; 97 case Log10E: 98 d = 1.0/log(10.0); 99 break; 100 case Pi: 101 d = piDouble; 102 break; 103 case Sqrt1_2: 104 d = sqrt(0.5); 105 break; 106 case Sqrt2: 107 d = sqrt(2.0); 108 break; 109 default: 110 ASSERT(0); 111 } 112 113 return jsNumber(d); 74 bool MathObjectImp::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot) 75 { 76 return getStaticPropertySlot<MathObjectImp, JSObject>(exec, &mathTable, this, propertyName, slot); 77 } 78 79 JSValue* MathObjectImp::getValueProperty(ExecState*, int token) const 80 { 81 switch (token) { 82 case Euler: 83 return jsNumber(exp(1.0)); 84 case Ln2: 85 return jsNumber(log(2.0)); 86 case Ln10: 87 return jsNumber(log(10.0)); 88 case Log2E: 89 return jsNumber(1.0 / log(2.0)); 90 case Log10E: 91 return jsNumber(1.0 / log(10.0)); 92 case Pi: 93 return jsNumber(piDouble); 94 case Sqrt1_2: 95 return jsNumber(sqrt(0.5)); 96 case Sqrt2: 97 return jsNumber(sqrt(2.0)); 98 } 99 100 ASSERT_NOT_REACHED(); 101 return 0; 114 102 } 115 103 … … 124 112 JSValue* mathProtoFuncACos(ExecState* exec, JSObject*, const List& args) 125 113 { 126 double arg = args[0]->toNumber(exec); 127 return jsNumber(acos(arg)); 114 return jsNumber(acos(args[0]->toNumber(exec))); 128 115 } 129 116 130 117 JSValue* mathProtoFuncASin(ExecState* exec, JSObject*, const List& args) 131 118 { 132 double arg = args[0]->toNumber(exec); 133 return jsNumber(asin(arg)); 119 return jsNumber(asin(args[0]->toNumber(exec))); 134 120 } 135 121 136 122 JSValue* mathProtoFuncATan(ExecState* exec, JSObject*, const List& args) 137 123 { 138 double arg = args[0]->toNumber(exec); 139 return jsNumber(atan(arg)); 124 return jsNumber(atan(args[0]->toNumber(exec))); 140 125 } 141 126 142 127 JSValue* mathProtoFuncATan2(ExecState* exec, JSObject*, const List& args) 143 128 { 144 double arg = args[0]->toNumber(exec); 145 double arg2 = args[1]->toNumber(exec); 146 return jsNumber(atan2(arg, arg2)); 129 return jsNumber(atan2(args[0]->toNumber(exec), args[1]->toNumber(exec))); 147 130 } 148 131 … … 157 140 JSValue* mathProtoFuncCos(ExecState* exec, JSObject*, const List& args) 158 141 { 159 double arg = args[0]->toNumber(exec); 160 return jsNumber(cos(arg)); 142 return jsNumber(cos(args[0]->toNumber(exec))); 161 143 } 162 144 163 145 JSValue* mathProtoFuncExp(ExecState* exec, JSObject*, const List& args) 164 146 { 165 double arg = args[0]->toNumber(exec); 166 return jsNumber(exp(arg)); 147 return jsNumber(exp(args[0]->toNumber(exec))); 167 148 } 168 149 … … 177 158 JSValue* mathProtoFuncLog(ExecState* exec, JSObject*, const List& args) 178 159 { 179 double arg = args[0]->toNumber(exec); 180 return jsNumber(log(arg)); 160 return jsNumber(log(args[0]->toNumber(exec))); 181 161 } 182 162 … … 248 228 JSValue* mathProtoFuncSin(ExecState* exec, JSObject*, const List& args) 249 229 { 250 double arg = args[0]->toNumber(exec); 251 return jsNumber(sin(arg)); 230 return jsNumber(sin(args[0]->toNumber(exec))); 252 231 } 253 232 254 233 JSValue* mathProtoFuncSqrt(ExecState* exec, JSObject*, const List& args) 255 234 { 256 double arg = args[0]->toNumber(exec); 257 return jsNumber(sqrt(arg)); 235 return jsNumber(sqrt(args[0]->toNumber(exec))); 258 236 } 259 237 260 238 JSValue* mathProtoFuncTan(ExecState* exec, JSObject*, const List& args) 261 239 { 262 double arg = args[0]->toNumber(exec); 263 return jsNumber(tan(arg)); 240 return jsNumber(tan(args[0]->toNumber(exec))); 264 241 } 265 242 -
trunk/JavaScriptCore/kjs/math_object.h
r29508 r29541 28 28 namespace KJS { 29 29 30 class MathObjectImp : public JSObject {31 public:32 MathObjectImp(ExecState*, ObjectPrototype*);30 class MathObjectImp : public JSObject { 31 public: 32 MathObjectImp(ExecState*, ObjectPrototype*); 33 33 34 bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);35 JSValue* getValueProperty(ExecState*, int token) const;34 bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 35 JSValue* getValueProperty(ExecState*, int token) const; 36 36 37 virtual const ClassInfo* classInfo() const { return &info; }38 static const ClassInfo info;37 virtual const ClassInfo* classInfo() const { return &info; } 38 static const ClassInfo info; 39 39 40 enum { Euler, Ln2, Ln10, Log2E, Log10E, Pi, Sqrt1_2, Sqrt2 };41 };40 enum { Euler, Ln2, Ln10, Log2E, Log10E, Pi, Sqrt1_2, Sqrt2 }; 41 }; 42 42 43 JSValue* mathProtoFuncAbs(ExecState*, JSObject*, const List&); 44 JSValue* mathProtoFuncACos(ExecState*, JSObject*, const List&); 45 JSValue* mathProtoFuncASin(ExecState*, JSObject*, const List&); 46 JSValue* mathProtoFuncATan(ExecState*, JSObject*, const List&); 47 JSValue* mathProtoFuncATan2(ExecState*, JSObject*, const List&); 48 JSValue* mathProtoFuncCeil(ExecState*, JSObject*, const List&); 49 JSValue* mathProtoFuncCos(ExecState*, JSObject*, const List&); 50 JSValue* mathProtoFuncExp(ExecState*, JSObject*, const List&); 51 JSValue* mathProtoFuncFloor(ExecState*, JSObject*, const List&); 52 JSValue* mathProtoFuncLog(ExecState*, JSObject*, const List&); 53 JSValue* mathProtoFuncMax(ExecState*, JSObject*, const List&); 54 JSValue* mathProtoFuncMin(ExecState*, JSObject*, const List&); 55 JSValue* mathProtoFuncPow(ExecState*, JSObject*, const List&); 56 JSValue* mathProtoFuncRandom(ExecState*, JSObject*, const List&); 57 JSValue* mathProtoFuncRound(ExecState*, JSObject*, const List&); 58 JSValue* mathProtoFuncSin(ExecState*, JSObject*, const List&); 59 JSValue* mathProtoFuncSqrt(ExecState*, JSObject*, const List&); 60 JSValue* mathProtoFuncTan(ExecState*, JSObject*, const List&); 43 // Functions 44 JSValue* mathProtoFuncAbs(ExecState*, JSObject*, const List&); 45 JSValue* mathProtoFuncACos(ExecState*, JSObject*, const List&); 46 JSValue* mathProtoFuncASin(ExecState*, JSObject*, const List&); 47 JSValue* mathProtoFuncATan(ExecState*, JSObject*, const List&); 48 JSValue* mathProtoFuncATan2(ExecState*, JSObject*, const List&); 49 JSValue* mathProtoFuncCeil(ExecState*, JSObject*, const List&); 50 JSValue* mathProtoFuncCos(ExecState*, JSObject*, const List&); 51 JSValue* mathProtoFuncExp(ExecState*, JSObject*, const List&); 52 JSValue* mathProtoFuncFloor(ExecState*, JSObject*, const List&); 53 JSValue* mathProtoFuncLog(ExecState*, JSObject*, const List&); 54 JSValue* mathProtoFuncMax(ExecState*, JSObject*, const List&); 55 JSValue* mathProtoFuncMin(ExecState*, JSObject*, const List&); 56 JSValue* mathProtoFuncPow(ExecState*, JSObject*, const List&); 57 JSValue* mathProtoFuncRandom(ExecState*, JSObject*, const List&); 58 JSValue* mathProtoFuncRound(ExecState*, JSObject*, const List&); 59 JSValue* mathProtoFuncSin(ExecState*, JSObject*, const List&); 60 JSValue* mathProtoFuncSqrt(ExecState*, JSObject*, const List&); 61 JSValue* mathProtoFuncTan(ExecState*, JSObject*, const List&); 61 62 62 63 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.