Changeset 10084 in webkit for trunk/JavaScriptCore/kjs/operations.cpp
- Timestamp:
- Aug 7, 2005, 9:07:46 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/operations.cpp
r9768 r10084 112 112 113 113 // ECMA 11.9.3 114 bool KJS::equal(ExecState *exec, const Value& v1, const Value&v2)115 { 116 Type t1 = v1 .type();117 Type t2 = v2 .type();114 bool KJS::equal(ExecState *exec, ValueImp *v1, ValueImp *v2) 115 { 116 Type t1 = v1->type(); 117 Type t2 = v2->type(); 118 118 119 119 if (t1 != t2) { … … 135 135 } else { 136 136 if ((t1 == StringType || t1 == NumberType) && t2 >= ObjectType) 137 return equal(exec, v1, v2 .toPrimitive(exec));137 return equal(exec, v1, v2->toPrimitive(exec)); 138 138 if (t1 >= ObjectType && (t2 == StringType || t2 == NumberType)) 139 return equal(exec, v1 .toPrimitive(exec), v2);139 return equal(exec, v1->toPrimitive(exec), v2); 140 140 if (t1 != t2) 141 141 return false; … … 147 147 148 148 if (t1 == NumberType) { 149 double d1 = v1 .toNumber(exec);150 double d2 = v2 .toNumber(exec);149 double d1 = v1->toNumber(exec); 150 double d2 = v2->toNumber(exec); 151 151 // FIXME: Isn't this already how NaN behaves? 152 152 // Why the extra line of code? … … 157 157 158 158 if (t1 == StringType) 159 return v1 .toString(exec) == v2.toString(exec);159 return v1->toString(exec) == v2->toString(exec); 160 160 161 161 if (t1 == BooleanType) 162 return v1 .toBoolean(exec) == v2.toBoolean(exec);162 return v1->toBoolean(exec) == v2->toBoolean(exec); 163 163 164 164 // types are Object 165 return v1 .imp() == v2.imp();166 } 167 168 bool KJS::strictEqual(ExecState *exec, const Value &v1, const Value &v2)169 { 170 Type t1 = v1 .type();171 Type t2 = v2 .type();165 return v1 == v2; 166 } 167 168 bool KJS::strictEqual(ExecState *exec, ValueImp *v1, ValueImp *v2) 169 { 170 Type t1 = v1->type(); 171 Type t2 = v2->type(); 172 172 173 173 if (t1 != t2) … … 176 176 return true; 177 177 if (t1 == NumberType) { 178 double n1 = v1 .toNumber(exec);179 double n2 = v2 .toNumber(exec);178 double n1 = v1->toNumber(exec); 179 double n2 = v2->toNumber(exec); 180 180 // FIXME: Isn't this already how NaN behaves? 181 181 // Why the extra line of code? … … 187 187 return false; 188 188 } else if (t1 == StringType) { 189 return v1 .toString(exec) == v2.toString(exec);189 return v1->toString(exec) == v2->toString(exec); 190 190 } else if (t2 == BooleanType) { 191 return v1 .toBoolean(exec) == v2.toBoolean(exec);191 return v1->toBoolean(exec) == v2->toBoolean(exec); 192 192 } 193 if (v1 .imp() == v2.imp())193 if (v1 == v2) 194 194 return true; 195 195 /* TODO: joined objects */ … … 198 198 } 199 199 200 int KJS::relation(ExecState *exec, const Value& v1, const Value&v2)201 { 202 Value p1 = v1.toPrimitive(exec,NumberType);203 Value p2 = v2.toPrimitive(exec,NumberType);204 205 if (p1 .type() == StringType && p2.type() == StringType)206 return p1 .toString(exec) < p2.toString(exec) ? 1 : 0;207 208 double n1 = p1 .toNumber(exec);209 double n2 = p2 .toNumber(exec);200 int KJS::relation(ExecState *exec, ValueImp *v1, ValueImp *v2) 201 { 202 ValueImp *p1 = v1->toPrimitive(exec,NumberType); 203 ValueImp *p2 = v2->toPrimitive(exec,NumberType); 204 205 if (p1->isString() && p2->isString()) 206 return p1->toString(exec) < p2->toString(exec) ? 1 : 0; 207 208 double n1 = p1->toNumber(exec); 209 double n2 = p2->toNumber(exec); 210 210 if (n1 < n2) 211 211 return 1; … … 226 226 227 227 // ECMA 11.6 228 Value KJS::add(ExecState *exec, const Value &v1, const Value &v2, char oper)228 ValueImp *KJS::add(ExecState *exec, ValueImp *v1, ValueImp *v2, char oper) 229 229 { 230 230 // exception for the Date exception in defaultValue() 231 231 Type preferred = oper == '+' ? UnspecifiedType : NumberType; 232 Value p1 = v1.toPrimitive(exec, preferred);233 Value p2 = v2.toPrimitive(exec, preferred);234 235 if ((p1 .type() == StringType || p2.type() == StringType) && oper == '+') {236 return p1.toString(exec) + p2.toString(exec);232 ValueImp *p1 = v1->toPrimitive(exec, preferred); 233 ValueImp *p2 = v2->toPrimitive(exec, preferred); 234 235 if ((p1->isString() || p2->isString()) && oper == '+') { 236 return jsString(p1->toString(exec) + p2->toString(exec)); 237 237 } 238 238 239 239 bool n1KnownToBeInteger; 240 double n1 = p1 .toNumber(exec, n1KnownToBeInteger);240 double n1 = p1->toNumber(exec, n1KnownToBeInteger); 241 241 bool n2KnownToBeInteger; 242 double n2 = p2 .toNumber(exec, n2KnownToBeInteger);242 double n2 = p2->toNumber(exec, n2KnownToBeInteger); 243 243 244 244 bool resultKnownToBeInteger = n1KnownToBeInteger && n2KnownToBeInteger; 245 245 246 246 if (oper == '+') 247 return Value(n1 + n2, resultKnownToBeInteger);247 return jsNumber(n1 + n2, resultKnownToBeInteger); 248 248 else 249 return Value(n1 - n2, resultKnownToBeInteger);249 return jsNumber(n1 - n2, resultKnownToBeInteger); 250 250 } 251 251 252 252 // ECMA 11.5 253 Value KJS::mult(ExecState *exec, const Value &v1, const Value &v2, char oper)253 ValueImp *KJS::mult(ExecState *exec, ValueImp *v1, ValueImp *v2, char oper) 254 254 { 255 255 bool n1KnownToBeInteger; 256 double n1 = v1 .toNumber(exec, n1KnownToBeInteger);256 double n1 = v1->toNumber(exec, n1KnownToBeInteger); 257 257 bool n2KnownToBeInteger; 258 double n2 = v2 .toNumber(exec, n2KnownToBeInteger);258 double n2 = v2->toNumber(exec, n2KnownToBeInteger); 259 259 260 260 double result; … … 272 272 } 273 273 274 return Value(result, resultKnownToBeInteger);275 } 274 return jsNumber(result, resultKnownToBeInteger); 275 }
Note:
See TracChangeset
for help on using the changeset viewer.