1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5 *
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.
10 *
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.
15 *
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.
20 *
21 */
22
23#ifndef _KJS_OPERATIONS_H_
24#define _KJS_OPERATIONS_H_
25
26#include "global.h"
27#include <math.h>
28
29namespace KJS {
30
31 class ExecState;
32 class JSValue;
33
34 enum Operator { OpEqual,
35 OpEqEq,
36 OpPlus,
37 OpMinus,
38 OpMult,
39 OpDiv,
40 OpMod,
41 OpNotEq,
42 OpStrEq,
43 OpStrNEq,
44 OpPlusEq,
45 OpMinusEq,
46 OpMultEq,
47 OpDivEq,
48 OpPlusPlus,
49 OpMinusMinus,
50 OpLess,
51 OpLessEq,
52 OpGreater,
53 OpGreaterEq,
54 OpAndEq,
55 OpXOrEq,
56 OpOrEq,
57 OpModEq,
58 OpAnd,
59 OpOr,
60 OpBitAnd,
61 OpBitXOr,
62 OpBitOr,
63 OpLShift,
64 OpRShift,
65 OpURShift,
66 OpIn,
67 OpInstanceOf
68 };
69
70#if PLATFORM(DARWIN)
71 inline bool isNaN(double d) { return isnan(d); }
72 inline bool isInf(double d) { return isinf(d); }
73 inline bool isPosInf(double d) { return isinf(d) && d > 0; }
74 inline bool isNegInf(double d) { return isinf(d) && d < 0; }
75#else
76 KJS_EXPORT bool isNaN(double d);
77 KJS_EXPORT bool isInf(double d);
78 KJS_EXPORT bool isPosInf(double d);
79 KJS_EXPORT bool isNegInf(double d);
80#endif
81
82 bool equal(ExecState *exec, JSValue *v1, JSValue *v2);
83 bool strictEqual(ExecState *exec, JSValue *v1, JSValue *v2);
84 // Same as strictEqual, except for "-0" and "0" difference.
85 // Used in PropertyDescriptor::equalTo and Object::defineOwnProperty to check
86 // if the value changed and we need to update.
87 bool sameValue(ExecState *exec, JSValue *v1, JSValue *v2);
88 /**
89 * This operator performs an abstract relational comparison of the two
90 * arguments that can be of arbitrary type. If possible, conversions to the
91 * string or number type will take place before the comparison.
92 *
93 * @return 1 if v1 is "less-than" v2, 0 if the relation is "greater-than-or-
94 * equal". -1 if the result is undefined.
95 */
96 int relation(ExecState *exec, JSValue *v1, JSValue *v2, bool leftFirst = true);
97 int relation(ExecState *exec, JSValue *v1, double n2);
98 int maxInt(int d1, int d2);
99 int minInt(int d1, int d2);
100
101}
102
103#endif
104