source: webkit/trunk/JavaScriptCore/kjs/operations.cpp@ 1623

Last change on this file since 1623 was 1623, checked in by darin, 23 years ago

JavaScriptCore:

  • kjs/*: Roll KDE 3.0.2 changes in. Also switch to not using APPLE_CHANGES for some of the changes that we definitely want to contribute upstream.

WebCore:

  • khtml/*: Roll KDE 3.0.2 changes in. Also switch to not using APPLE_CHANGES for some of the changes that we definitely want to contribute upstream.
  • WebCore.pbproj/project.pbxproj: Add KWQStyle.mm, remove KWQStyle.h, moving contents into qstyle.h.
  • kwq/KWQApplication.mm: (QApplication::globalStrut): Remove _logNotYetImplemented().
  • kwq/KWQButton.mm: (QButton::QButton): Use plain release, not autorelease.
  • kwq/KWQComboBox.mm: (QComboBox::init): Use plain release, not autorelease.
  • kwq/KWQListBox.mm: (QListBox::QListBox): Use plain release, not autorelease.
  • kwq/KWQPainter.mm: (QPainter::drawArc): Use plain release, not autorelease.
  • kwq/KWQKHTMLPartBrowserExtension.mm: Remove import of KWQKHTMLPartImpl.h, now that it's always part of khtml_part.h.
  • kwq/KWQKHTMLPartImpl.cpp: Simplify.
  • kwq/KWQKHTMLPartImpl.h: Add wrapper to allow multiple inclusion. Don't include khtml_part.h any more, since that file now includes this one to minimize changes to KDE code that needs to get to functions in here.
  • kwq/KWQKHTMLPartImpl.mm: (KHTMLPart::onURL), (KHTMLPart::nodeActivated), (KHTMLPart::setStatusBarText): Moved here from khtml_part.cpp.
  • kwq/KWQLoaderImpl.mm: Include khtml_part.h instead of KWQKHTMLPartImpl.h.
  • kwq/KWQPushButton.mm: (buttonFontMetrics), (QPushButton::fontMetrics): Added. Used by the form code to size buttons.
  • kwq/KWQStyle.mm: Added. (QStyle::sizeFromContents): Added. Used by the form code to size buttons.
  • kwq/KWQStyle.h: Removed.
  • kwq/qt/qstyle.h: Moved contents of KWQStyle.h in here.
  • kwq/qt/qwidget.h: Include <qstyle.h> rather than KWQStyle.h.
  • kwq/WebCoreBridge.mm: (-[WebCoreBridge isFrameSet]): Call straight to impl.
  • kwq/kdeui/klineedit.h: Add KLineEdit::frameWidth().
  • kwq/qt/qnamespace.h: Remove GUIStyle, MacStyle, and WindowsStyle.
  • kwq/qt/qpaintdevice.h: Add QInternal, QInternal::Printer, and QPaintDevice::devType().
  • kwq/qt/qpainter.h: Add QPainter::device().
  • kwq/qt/qpushbutton.h: Add QPushButton::fontMetrics().
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten ([email protected])
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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26#ifndef HAVE_FLOAT_H /* just for !Windows */
27#define HAVE_FLOAT_H 0
28#define HAVE_FUNC__FINITE 0
29#endif
30
31#include <stdio.h>
32#include <assert.h>
33#include <math.h>
34#include <stdlib.h>
35
36#ifndef HAVE_FUNC_ISINF
37#ifdef HAVE_IEEEFP_H
38#include <ieeefp.h>
39#endif
40#endif /* HAVE_FUNC_ISINF */
41
42#if HAVE_FLOAT_H
43#include <float.h>
44#endif
45
46#include "operations.h"
47#include "object.h"
48
49using namespace KJS;
50
51bool KJS::isNaN(double d)
52{
53#ifdef HAVE_FUNC_ISNAN
54 return isnan(d);
55#elif defined HAVE_FLOAT_H
56 return _isnan(d) != 0;
57#else
58 return !(d == d);
59#endif
60}
61
62bool KJS::isInf(double d)
63{
64#if defined(HAVE_FUNC_ISINF)
65 return isinf(d);
66#elif HAVE_FUNC_FINITE
67 return finite(d) == 0 && d == d;
68#elif HAVE_FUNC__FINITE
69 return _finite(d) == 0 && d == d;
70#else
71 return false;
72#endif
73}
74
75bool KJS::isPosInf(double d)
76{
77#if defined(HAVE_FUNC_ISINF)
78 return (isinf(d) == 1);
79#elif HAVE_FUNC_FINITE
80 return finite(d) == 0 && d == d; // ### can we distinguish between + and - ?
81#elif HAVE_FUNC__FINITE
82 return _finite(d) == 0 && d == d; // ###
83#else
84 return false;
85#endif
86}
87
88bool KJS::isNegInf(double d)
89{
90#if defined(HAVE_FUNC_ISINF)
91 return (isinf(d) == -1);
92#elif HAVE_FUNC_FINITE
93 return finite(d) == 0 && d == d; // ###
94#elif HAVE_FUNC__FINITE
95 return _finite(d) == 0 && d == d; // ###
96#else
97 return false;
98#endif
99}
100
101// ECMA 11.9.3
102bool KJS::equal(ExecState *exec, const Value& v1, const Value& v2)
103{
104 Type t1 = v1.type();
105 Type t2 = v2.type();
106
107 if (t1 == t2) {
108 if (t1 == UndefinedType || t1 == NullType)
109 return true;
110 if (t1 == NumberType)
111 {
112 double d1 = v1.toNumber(exec);
113 double d2 = v2.toNumber(exec);
114 if ( isNaN( d1 ) || isNaN( d2 ) )
115 return false;
116 return ( d1 == d2 ); /* TODO: +0, -0 ? */
117 }
118 if (t1 == StringType)
119 return (v1.toString(exec) == v2.toString(exec));
120 if (t1 == BooleanType)
121 return (v1.toBoolean(exec) == v2.toBoolean(exec));
122
123 // types are Object
124 return (v1.imp() == v2.imp());
125 }
126
127 // different types
128 if ((t1 == NullType && t2 == UndefinedType) || (t1 == UndefinedType && t2 == NullType))
129 return true;
130 if (t1 == NumberType && t2 == StringType) {
131 Number n2 = v2.toNumber(exec);
132 return equal(exec,v1, n2);
133 }
134 if ((t1 == StringType && t2 == NumberType) || t1 == BooleanType) {
135 Number n1 = v1.toNumber(exec);
136 return equal(exec,n1, v2);
137 }
138 if (t2 == BooleanType) {
139 Number n2 = v2.toNumber(exec);
140 return equal(exec,v1, n2);
141 }
142 if ((t1 == StringType || t1 == NumberType) && t2 >= ObjectType) {
143 Value p2 = v2.toPrimitive(exec);
144 return equal(exec,v1, p2);
145 }
146 if (t1 >= ObjectType && (t2 == StringType || t2 == NumberType)) {
147 Value p1 = v1.toPrimitive(exec);
148 return equal(exec,p1, v2);
149 }
150
151 return false;
152}
153
154bool KJS::strictEqual(ExecState *exec, const Value &v1, const Value &v2)
155{
156 Type t1 = v1.type();
157 Type t2 = v2.type();
158
159 if (t1 != t2)
160 return false;
161 if (t1 == UndefinedType || t1 == NullType)
162 return true;
163 if (t1 == NumberType) {
164 double n1 = v1.toNumber(exec);
165 double n2 = v2.toNumber(exec);
166 if (isNaN(n1) || isNaN(n2))
167 return false;
168 if (n1 == n2)
169 return true;
170 /* TODO: +0 and -0 */
171 return false;
172 } else if (t1 == StringType) {
173 return v1.toString(exec) == v2.toString(exec);
174 } else if (t2 == BooleanType) {
175 return v1.toBoolean(exec) == v2.toBoolean(exec);
176 }
177 if (v1.imp() == v2.imp())
178 return true;
179 /* TODO: joined objects */
180
181 return false;
182}
183
184int KJS::relation(ExecState *exec, const Value& v1, const Value& v2)
185{
186 Value p1 = v1.toPrimitive(exec,NumberType);
187 Value p2 = v2.toPrimitive(exec,NumberType);
188
189 if (p1.type() == StringType && p2.type() == StringType)
190 return p1.toString(exec) < p2.toString(exec) ? 1 : 0;
191
192 double n1 = p1.toNumber(exec);
193 double n2 = p2.toNumber(exec);
194 if ( isNaN( n1 ) || isNaN( n2 ) )
195 return -1; // means undefined
196 if (n1 == n2)
197 return 0;
198 /* TODO: +0, -0 */
199 if ( isPosInf( n1 ) )
200 return 0;
201 if ( isPosInf( n2 ) )
202 return 1;
203 if ( isNegInf( n2 ) )
204 return 0;
205 if ( isNegInf( n1 ) )
206 return 1;
207 return (n1 < n2) ? 1 : 0;
208}
209
210int KJS::maxInt(int d1, int d2)
211{
212 return (d1 > d2) ? d1 : d2;
213}
214
215int KJS::minInt(int d1, int d2)
216{
217 return (d1 < d2) ? d1 : d2;
218}
219
220// ECMA 11.6
221Value KJS::add(ExecState *exec, const Value &v1, const Value &v2, char oper)
222{
223 // exception for the Date exception in defaultValue()
224 Type preferred = oper == '+' ? UnspecifiedType : NumberType;
225 Value p1 = v1.toPrimitive(exec, preferred);
226 Value p2 = v2.toPrimitive(exec, preferred);
227
228 if ((p1.type() == StringType || p2.type() == StringType) && oper == '+') {
229 UString s1 = p1.toString(exec);
230 UString s2 = p2.toString(exec);
231
232 return String(s1 + s2);
233 }
234
235 double n1 = p1.toNumber(exec);
236 double n2 = p2.toNumber(exec);
237
238 if (oper == '+')
239 return Number(n1 + n2);
240 else
241 return Number(n1 - n2);
242}
243
244// ECMA 11.5
245Value KJS::mult(ExecState *exec, const Value &v1, const Value &v2, char oper)
246{
247 double n1 = v1.toNumber(exec);
248 double n2 = v2.toNumber(exec);
249
250 double result;
251
252 if (oper == '*')
253 result = n1 * n2;
254 else if (oper == '/')
255 result = n1 / n2;
256 else
257 result = fmod(n1, n2);
258
259 return Number(result);
260}
Note: See TracBrowser for help on using the repository browser.