1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
24 #include "operations.h"
30 #include <wtf/MathExtras.h>
39 bool equal(ExecState *exec, JSValue *v1, JSValue *v2)
41 JSType t1 = v1->type();
42 JSType t2 = v2->type();
45 if (t1 == UndefinedType)
47 if (t2 == UndefinedType)
50 if (t1 == BooleanType)
52 if (t2 == BooleanType)
55 if (t1 == NumberType && t2 == StringType) {
57 } else if (t1 == StringType && t2 == NumberType)
61 if ((t1 == StringType || t1 == NumberType) && t2 >= ObjectType)
62 return equal(exec, v1, v2->toPrimitive(exec));
63 if (t1 == NullType && t2 == ObjectType)
64 return static_cast<JSObject *>(v2)->masqueradeAsUndefined();
65 if (t1 >= ObjectType && (t2 == StringType || t2 == NumberType))
66 return equal(exec, v1->toPrimitive(exec), v2);
67 if (t1 == ObjectType && t2 == NullType)
68 return static_cast<JSObject *>(v1)->masqueradeAsUndefined();
74 if (t1 == UndefinedType || t1 == NullType)
77 if (t1 == NumberType) {
78 double d1 = v1->toNumber(exec);
79 double d2 = v2->toNumber(exec);
84 return static_cast<StringImp*>(v1)->value() == static_cast<StringImp*>(v2)->value();
86 if (t1 == BooleanType)
87 return v1->toBoolean(exec) == v2->toBoolean(exec);
93 bool strictEqual(ExecState *exec, JSValue *v1, JSValue *v2)
95 JSType t1 = v1->type();
96 JSType t2 = v2->type();
100 if (t1 == UndefinedType || t1 == NullType)
102 if (t1 == NumberType) {
103 double n1 = v1->toNumber(exec);
104 double n2 = v2->toNumber(exec);
108 } else if (t1 == StringType)
109 return v1->toString(exec) == v2->toString(exec);
110 else if (t2 == BooleanType)
111 return v1->toBoolean(exec) == v2->toBoolean(exec);
115 /* TODO: joined objects */
120 int maxInt(int d1, int d2)
122 return (d1 > d2) ? d1 : d2;
125 int minInt(int d1, int d2)
127 return (d1 < d2) ? d1 : d2;