Changeset 13598 in webkit for trunk/JavaScriptCore/kjs/operations.cpp
- Timestamp:
- Mar 30, 2006, 10:52:16 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/operations.cpp
r13089 r13598 42 42 43 43 namespace KJS { 44 44 45 45 #if !PLATFORM(DARWIN) 46 47 48 49 46 // FIXME: should probably be inlined on other platforms too, and controlled exclusively 47 // by HAVE macros 48 49 50 50 bool isNaN(double d) 51 51 { 52 52 #if HAVE(FUNC_ISNAN) 53 return isnan(d);53 return isnan(d); 54 54 #elif HAVE(FLOAT_H) 55 return _isnan(d) != 0;56 #else 57 return !(d == d);55 return _isnan(d) != 0; 56 #else 57 return !(d == d); 58 58 #endif 59 59 } … … 61 61 bool isInf(double d) 62 62 { 63 // FIXME: should be HAVE(_FPCLASS)63 // FIXME: should be HAVE(_FPCLASS) 64 64 #if PLATFORM(WIN_OS) 65 int fpClass = _fpclass(d);66 return _FPCLASS_PINF == fpClass || _FPCLASS_NINF == fpClass;65 int fpClass = _fpclass(d); 66 return _FPCLASS_PINF == fpClass || _FPCLASS_NINF == fpClass; 67 67 #elif HAVE(FUNC_ISINF) 68 return isinf(d);68 return isinf(d); 69 69 #elif HAVE(FUNC_FINITE) 70 return finite(d) == 0 && d == d;70 return finite(d) == 0 && d == d; 71 71 #elif HAVE(FUNC__FINITE) 72 return _finite(d) == 0 && d == d;73 #else 74 return false;72 return _finite(d) == 0 && d == d; 73 #else 74 return false; 75 75 #endif 76 76 } … … 78 78 bool isPosInf(double d) 79 79 { 80 // FIXME: should be HAVE(_FPCLASS)80 // FIXME: should be HAVE(_FPCLASS) 81 81 #if PLATFORM(WIN_OS) 82 return _FPCLASS_PINF == _fpclass(d);82 return _FPCLASS_PINF == _fpclass(d); 83 83 #elif HAVE(FUNC_ISINF) 84 return (isinf(d) == 1);84 return (isinf(d) == 1); 85 85 #elif HAVE(FUNC_FINITE) 86 return !finite(d) && d == d; // ### can we distinguish between + and - ?86 return !finite(d) && d == d; // ### can we distinguish between + and - ? 87 87 #elif HAVE(FUNC__FINITE) 88 return !_finite(d) && d == d; // ###89 #else 90 return false;88 return !_finite(d) && d == d; // ### 89 #else 90 return false; 91 91 #endif 92 92 } … … 94 94 bool isNegInf(double d) 95 95 { 96 // FIXME: should be HAVE(_FPCLASS)96 // FIXME: should be HAVE(_FPCLASS) 97 97 #if PLATFORM(WIN_OS) 98 return _FPCLASS_NINF == _fpclass(d);98 return _FPCLASS_NINF == _fpclass(d); 99 99 #elif HAVE(FUNC_ISINF) 100 return (isinf(d) == -1);100 return (isinf(d) == -1); 101 101 #elif HAVE(FUNC_FINITE) 102 return finite(d) == 0 && d == d; // ###102 return finite(d) == 0 && d == d; // ### 103 103 #elif HAVE(FUNC__FINITE) 104 return _finite(d) == 0 && d == d; // ###105 #else 106 return false;104 return _finite(d) == 0 && d == d; // ### 105 #else 106 return false; 107 107 #endif 108 108 } … … 115 115 JSType t1 = v1->type(); 116 116 JSType t2 = v2->type(); 117 117 118 118 if (t1 != t2) { 119 119 if (t1 == UndefinedType) … … 121 121 if (t2 == UndefinedType) 122 122 t2 = NullType; 123 123 124 124 if (t1 == BooleanType) 125 125 t1 = NumberType; 126 126 if (t2 == BooleanType) 127 127 t2 = NumberType; 128 128 129 129 if (t1 == NumberType && t2 == StringType) { 130 130 // use toNumber … … 145 145 } 146 146 } 147 147 148 148 if (t1 == UndefinedType || t1 == NullType) 149 149 return true; 150 150 151 151 if (t1 == NumberType) { 152 152 double d1 = v1->toNumber(exec); … … 154 154 return d1 == d2; 155 155 } 156 156 157 157 if (t1 == StringType) 158 158 return v1->toString(exec) == v2->toString(exec); 159 159 160 160 if (t1 == BooleanType) 161 161 return v1->toBoolean(exec) == v2->toBoolean(exec); 162 162 163 163 // types are Object 164 164 return v1 == v2; … … 167 167 bool strictEqual(ExecState *exec, JSValue *v1, JSValue *v2) 168 168 { 169 JSType t1 = v1->type(); 170 JSType t2 = v2->type(); 171 172 if (t1 != t2) 173 return false; 174 if (t1 == UndefinedType || t1 == NullType) 175 return true; 176 if (t1 == NumberType) { 169 JSType t1 = v1->type(); 170 JSType t2 = v2->type(); 171 172 if (t1 != t2) 173 return false; 174 if (t1 == UndefinedType || t1 == NullType) 175 return true; 176 if (t1 == NumberType) { 177 double n1 = v1->toNumber(exec); 178 double n2 = v2->toNumber(exec); 179 if (n1 == n2) 180 return true; 181 return false; 182 } else if (t1 == StringType) 183 return v1->toString(exec) == v2->toString(exec); 184 else if (t2 == BooleanType) 185 return v1->toBoolean(exec) == v2->toBoolean(exec); 186 187 if (v1 == v2) 188 return true; 189 /* TODO: joined objects */ 190 191 return false; 192 } 193 194 int relation(ExecState *exec, JSValue *v1, JSValue *v2) 195 { 196 JSValue *p1 = v1->toPrimitive(exec,NumberType); 197 JSValue *p2 = v2->toPrimitive(exec,NumberType); 198 199 if (p1->isString() && p2->isString()) 200 return p1->toString(exec) < p2->toString(exec) ? 1 : 0; 201 202 double n1 = p1->toNumber(exec); 203 double n2 = p2->toNumber(exec); 204 if (n1 < n2) 205 return 1; 206 if (n1 >= n2) 207 return 0; 208 return -1; // must be NaN, so undefined 209 } 210 211 int maxInt(int d1, int d2) 212 { 213 return (d1 > d2) ? d1 : d2; 214 } 215 216 int minInt(int d1, int d2) 217 { 218 return (d1 < d2) ? d1 : d2; 219 } 220 221 // ECMA 11.6 222 JSValue *add(ExecState *exec, JSValue *v1, JSValue *v2, char oper) 223 { 224 // exception for the Date exception in defaultValue() 225 JSType preferred = oper == '+' ? UnspecifiedType : NumberType; 226 JSValue *p1 = v1->toPrimitive(exec, preferred); 227 JSValue *p2 = v2->toPrimitive(exec, preferred); 228 229 if ((p1->isString() || p2->isString()) && oper == '+') 230 return jsString(p1->toString(exec) + p2->toString(exec)); 231 232 if (oper == '+') 233 return jsNumber(p1->toNumber(exec) + p2->toNumber(exec)); 234 else 235 return jsNumber(p1->toNumber(exec) - p2->toNumber(exec)); 236 } 237 238 // ECMA 11.5 239 JSValue *mult(ExecState *exec, JSValue *v1, JSValue *v2, char oper) 240 { 177 241 double n1 = v1->toNumber(exec); 178 242 double n2 = v2->toNumber(exec); 179 if (n1 == n2) 180 return true; 181 return false; 182 } else if (t1 == StringType) { 183 return v1->toString(exec) == v2->toString(exec); 184 } else if (t2 == BooleanType) { 185 return v1->toBoolean(exec) == v2->toBoolean(exec); 186 } 187 if (v1 == v2) 188 return true; 189 /* TODO: joined objects */ 190 191 return false; 192 } 193 194 int relation(ExecState *exec, JSValue *v1, JSValue *v2) 195 { 196 JSValue *p1 = v1->toPrimitive(exec,NumberType); 197 JSValue *p2 = v2->toPrimitive(exec,NumberType); 198 199 if (p1->isString() && p2->isString()) 200 return p1->toString(exec) < p2->toString(exec) ? 1 : 0; 201 202 double n1 = p1->toNumber(exec); 203 double n2 = p2->toNumber(exec); 204 if (n1 < n2) 205 return 1; 206 if (n1 >= n2) 207 return 0; 208 return -1; // must be NaN, so undefined 209 } 210 211 int maxInt(int d1, int d2) 212 { 213 return (d1 > d2) ? d1 : d2; 214 } 215 216 int minInt(int d1, int d2) 217 { 218 return (d1 < d2) ? d1 : d2; 219 } 220 221 // ECMA 11.6 222 JSValue *add(ExecState *exec, JSValue *v1, JSValue *v2, char oper) 223 { 224 // exception for the Date exception in defaultValue() 225 JSType preferred = oper == '+' ? UnspecifiedType : NumberType; 226 JSValue *p1 = v1->toPrimitive(exec, preferred); 227 JSValue *p2 = v2->toPrimitive(exec, preferred); 228 229 if ((p1->isString() || p2->isString()) && oper == '+') { 230 return jsString(p1->toString(exec) + p2->toString(exec)); 231 } 232 233 if (oper == '+') 234 return jsNumber(p1->toNumber(exec) + p2->toNumber(exec)); 235 else 236 return jsNumber(p1->toNumber(exec) - p2->toNumber(exec)); 237 } 238 239 // ECMA 11.5 240 JSValue *mult(ExecState *exec, JSValue *v1, JSValue *v2, char oper) 241 { 242 double n1 = v1->toNumber(exec); 243 double n2 = v2->toNumber(exec); 244 245 double result; 246 247 if (oper == '*') { 248 result = n1 * n2; 249 } else if (oper == '/') { 250 result = n1 / n2; 251 } else { 252 result = fmod(n1, n2); 253 } 254 255 return jsNumber(result); 256 } 257 258 } 243 244 double result; 245 246 if (oper == '*') 247 result = n1 * n2; 248 else if (oper == '/') 249 result = n1 / n2; 250 else 251 result = fmod(n1, n2); 252 253 return jsNumber(result); 254 } 255 256 }
Note:
See TracChangeset
for help on using the changeset viewer.