Changeset 35830 in webkit for trunk/JavaScriptCore/kjs/operations.cpp
- Timestamp:
- Aug 18, 2008, 9:39:04 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/operations.cpp
r35027 r35830 37 37 38 38 // ECMA 11.9.3 39 bool equal(ExecState *exec, JSValue *v1, JSValue *v2)39 bool equal(ExecState* exec, JSValue* v1, JSValue* v2) 40 40 { 41 JSType t1 = v1->type(); 42 JSType t2 = v2->type(); 43 44 if (t1 != t2) { 45 if (t1 == UndefinedType) 46 t1 = NullType; 47 if (t2 == UndefinedType) 48 t2 = NullType; 49 50 if (t1 == BooleanType) 51 t1 = NumberType; 52 if (t2 == BooleanType) 53 t2 = NumberType; 54 55 if (t1 == NumberType && t2 == StringType) { 56 // use toNumber 57 } else if (t1 == StringType && t2 == NumberType) 58 t1 = NumberType; 59 // use toNumber 60 else { 61 if ((t1 == StringType || t1 == NumberType) && t2 == ObjectType) { 62 v2 = v2->toPrimitive(exec); 63 if (exec->hadException()) 64 return false; 65 return equal(exec, v1, v2); 66 } 67 if (t1 == NullType && t2 == ObjectType) 68 return static_cast<JSObject *>(v2)->masqueradeAsUndefined(); 69 if (t1 == ObjectType && (t2 == StringType || t2 == NumberType)) { 70 v1 = v1->toPrimitive(exec); 71 if (exec->hadException()) 72 return false; 73 return equal(exec, v1, v2); 74 } 75 if (t1 == ObjectType && t2 == NullType) 76 return static_cast<JSObject *>(v1)->masqueradeAsUndefined(); 77 if (t1 != t2) 78 return false; 79 } 41 startOver: 42 if (JSImmediate::areBothImmediateNumbers(v1, v2)) 43 return v1 == v2; 44 45 if (v1->isNumber() && v2->isNumber()) 46 return v1->uncheckedGetNumber() == v2->uncheckedGetNumber(); 47 48 bool s1 = v1->isString(); 49 bool s2 = v2->isString(); 50 if (s1 && s2) 51 return static_cast<JSString*>(v1)->value() == static_cast<JSString*>(v2)->value(); 52 53 if (v1->isUndefinedOrNull()) { 54 if (v2->isUndefinedOrNull()) 55 return true; 56 if (!v2->isObject()) 57 return false; 58 return static_cast<JSObject*>(v2)->masqueradeAsUndefined(); 80 59 } 81 82 if (t1 == UndefinedType || t1 == NullType) 83 return true; 84 85 if (t1 == NumberType) { 60 61 if (v2->isUndefinedOrNull()) { 62 if (!v1->isObject()) 63 return false; 64 return static_cast<JSObject*>(v1)->masqueradeAsUndefined(); 65 } 66 67 if (v1->isObject()) { 68 if (v2->isObject()) 69 return v1 == v2; 70 JSValue* p1 = v1->toPrimitive(exec); 71 if (exec->hadException()) 72 return false; 73 v1 = p1; 74 goto startOver; 75 } 76 77 if (v2->isObject()) { 78 JSValue* p2 = v2->toPrimitive(exec); 79 if (exec->hadException()) 80 return false; 81 v2 = p2; 82 goto startOver; 83 } 84 85 if (s1 || s2) { 86 86 double d1 = v1->toNumber(exec); 87 87 double d2 = v2->toNumber(exec); 88 88 return d1 == d2; 89 89 } 90 91 if (t1 == StringType) 92 return static_cast<JSString*>(v1)->value() == static_cast<JSString*>(v2)->value(); 93 94 if (t1 == BooleanType) 95 return v1->toBoolean(exec) == v2->toBoolean(exec); 96 97 // types are Object 90 91 if (v1->isBoolean()) { 92 if (v2->isNumber()) 93 return v1->getBoolean() == v2->uncheckedGetNumber(); 94 } else if (v2->isBoolean()) { 95 if (v1->isNumber()) 96 return v1->uncheckedGetNumber() == v2->getBoolean(); 97 } 98 98 99 return v1 == v2; 99 100 } … … 101 102 bool strictEqual(JSValue* v1, JSValue* v2) 102 103 { 103 JSType t1 = v1->type(); 104 JSType t2 = v2->type(); 105 106 if (t1 != t2) 107 return false; 104 if (JSImmediate::isEitherImmediate(v1, v2)) { 105 if (v1 == v2) 106 return true; 108 107 109 if (t1 == NumberType) 110 return v1->getNumber() == v2->getNumber(); 111 112 if (t1 == StringType) 113 return static_cast<JSString*>(v1)->value() == static_cast<JSString*>(v2)->value(); 114 115 return v1 == v2; // covers object, boolean, null, and undefined types 108 // The reason we can't just return false here is that 0 === -0, 109 // and while the former is an immediate number, the latter is not. 110 if (v1 == JSImmediate::from(0)) 111 return !JSImmediate::isImmediate(v2) 112 && static_cast<JSCell*>(v2)->isNumber() 113 && static_cast<JSNumberCell*>(v2)->value() == 0; 114 return v2 == JSImmediate::from(0) 115 && !JSImmediate::isImmediate(v1) 116 && static_cast<JSCell*>(v1)->isNumber() 117 && static_cast<JSNumberCell*>(v1)->value() == 0; 118 } 119 120 if (static_cast<JSCell*>(v1)->isNumber()) 121 return static_cast<JSCell*>(v2)->isNumber() 122 && static_cast<JSNumberCell*>(v1)->value() == static_cast<JSNumberCell*>(v2)->value(); 123 124 if (static_cast<JSCell*>(v1)->isString()) 125 return static_cast<JSCell*>(v2)->isString() 126 && static_cast<JSString*>(v1)->value() == static_cast<JSString*>(v2)->value(); 127 128 return v1 == v2; 116 129 } 117 130
Note:
See TracChangeset
for help on using the changeset viewer.