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

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

JavaScriptCore:

Merged in changes from KDE 3.0.1.

  • kjs/collector.cpp:
  • kjs/date_object.cpp:
  • kjs/function.cpp:
  • kjs/internal.cpp:
  • kjs/lookup.h:
  • kjs/object.cpp:
  • kjs/operations.cpp:
  • kjs/regexp.cpp:
  • kjs/regexp_object.cpp:
  • kjs/regexp_object.h:
  • kjs/string_object.cpp:
  • kjs/testkjs.cpp:
  • kjs/ustring.cpp:
  • kjs/value.cpp:
  • kjs/value.h: Do the merge, and add APPLE_CHANGES as needed to make things compile.
  • kjs/date_object.lut.h: Re-generated.

WebCore:

Merged in changes from KDE 3.0.1.

  • kwq/kdecore/kurl.h:
  • kwq/KWQKURL.mm: (operator==): New, needed by some 3.0.1 code.
  • kwq/qt/qpalette.h: Add QPalette::NColorGroups and QColorGroup::NColorRoles.
  • kwq/KWQPalette.mm: Simplify by getting rid of "private" indirection. (QPalette::color): New, needed by some 3.0.1 code.
  • kwq/KWQColorGroup.mm: Simplify by getting rid of "private" indirection.
  • kwq/qt/qstring.h:
  • kwq/KWQString.mm: (QConstString::QConstString): Change parameter to const QChar * to match Qt so we compile.
  • kwq/qt/qtextedit.h:
  • kwq/KWQTextEdit.mm: (QTextEdit::setTabStopWidth): Add unimplemented placeholder, needed by some 3.0.1 code.
  • kwq/qt/qvaluelist.h:
  • kwq/KWQValueListImpl.h:
  • kwq/KWQValueListImpl.mm: Simplify implementation.
  • WebCore-tests.exp: Update for changes in QValueList implementation.
  • kwq/kdecore/klibloader.h: Add include of <kio/global.h> to make something compile.
  • kwq/khtml/java/kjavaappletcontext.h: Add JType and constructor that takes DCOPObject*.
  • kwq/kio/global.h: Add KIO::CacheControl.
  • khtml/css/css_ruleimpl.cpp:
  • khtml/css/css_ruleimpl.h:
  • khtml/css/css_stylesheetimpl.cpp:
  • khtml/css/css_stylesheetimpl.h:
  • khtml/css/css_valueimpl.cpp:
  • khtml/css/css_valueimpl.h:
  • khtml/css/cssparser.cpp:
  • khtml/css/cssparser.h:
  • khtml/css/cssstyleselector.cpp:
  • khtml/css/cssstyleselector.h:
  • khtml/css/html4.css:
  • khtml/dom/css_rule.cpp:
  • khtml/dom/css_rule.h:
  • khtml/dom/css_stylesheet.cpp:
  • khtml/dom/css_stylesheet.h:
  • khtml/dom/css_value.cpp:
  • khtml/dom/dom2_events.cpp:
  • khtml/dom/dom2_range.cpp:
  • khtml/dom/dom2_range.h:
  • khtml/dom/dom2_views.cpp:
  • khtml/dom/dom_doc.cpp:
  • khtml/dom/dom_element.cpp:
  • khtml/dom/dom_exception.h:
  • khtml/dom/dom_node.cpp:
  • khtml/dom/dom_string.cpp:
  • khtml/dom/dom_text.cpp:
  • khtml/dom/dom_xml.cpp:
  • khtml/dom/html_base.cpp:
  • khtml/dom/html_block.cpp:
  • khtml/dom/html_document.cpp:
  • khtml/dom/html_element.cpp:
  • khtml/dom/html_element.h:
  • khtml/dom/html_form.cpp:
  • khtml/dom/html_head.cpp:
  • khtml/dom/html_image.cpp:
  • khtml/dom/html_inline.cpp:
  • khtml/dom/html_list.cpp:
  • khtml/dom/html_misc.cpp:
  • khtml/dom/html_object.cpp:
  • khtml/dom/html_table.cpp:
  • khtml/ecma/kjs_html.cpp:
  • khtml/ecma/kjs_proxy.cpp:
  • khtml/ecma/kjs_traversal.cpp:
  • khtml/ecma/kjs_window.cpp:
  • khtml/html/html_baseimpl.cpp:
  • khtml/html/html_formimpl.cpp:
  • khtml/html/html_miscimpl.h:
  • khtml/html/html_objectimpl.cpp:
  • khtml/html/html_objectimpl.h:
  • khtml/html/htmlparser.cpp:
  • khtml/html/htmlparser.h:
  • khtml/html/htmltokenizer.cpp:
  • khtml/html/htmltokenizer.h:
  • khtml/khtml_part.cpp:
  • khtml/khtmlpart_p.h:
  • khtml/khtmlview.cpp:
  • khtml/misc/helper.cpp:
  • khtml/misc/khtmllayout.h:
  • khtml/misc/loader.cpp:
  • khtml/misc/loader.h:
  • khtml/misc/loader_client.h:
  • khtml/misc/shared.h: Added.
  • khtml/rendering/bidi.cpp:
  • khtml/rendering/break_lines.cpp:
  • khtml/rendering/font.cpp:
  • khtml/rendering/render_applet.cpp:
  • khtml/rendering/render_applet.h:
  • khtml/rendering/render_container.cpp:
  • khtml/rendering/render_form.cpp:
  • khtml/rendering/render_form.h:
  • khtml/rendering/render_frames.cpp:
  • khtml/rendering/render_image.cpp:
  • khtml/rendering/render_object.cpp:
  • khtml/rendering/render_object.h:
  • khtml/rendering/render_replaced.cpp:
  • khtml/rendering/render_replaced.h:
  • khtml/rendering/render_root.cpp:
  • khtml/rendering/render_style.cpp:
  • khtml/rendering/render_style.h:
  • khtml/rendering/render_table.cpp:
  • khtml/rendering/render_table.h:
  • khtml/rendering/render_text.cpp:
  • khtml/rendering/render_text.h:
  • khtml/xml/dom2_eventsimpl.h:
  • khtml/xml/dom2_rangeimpl.h:
  • khtml/xml/dom2_traversalimpl.cpp:
  • khtml/xml/dom2_traversalimpl.h:
  • khtml/xml/dom2_viewsimpl.h:
  • khtml/xml/dom_docimpl.cpp:
  • khtml/xml/dom_docimpl.h:
  • khtml/xml/dom_elementimpl.h:
  • khtml/xml/dom_nodeimpl.cpp:
  • khtml/xml/dom_nodeimpl.h:
  • khtml/xml/dom_stringimpl.cpp:
  • khtml/xml/dom_stringimpl.h:
  • khtml/xml/xml_tokenizer.h: Merge in 3.0.1 changes and add APPLE_CHANGES as necessary to get it to compile.
  • 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 Number n1 = v1.toNumber(exec);
248 Number n2 = v2.toNumber(exec);
249
250 double result;
251
252 if (oper == '*')
253 result = n1.value() * n2.value();
254 else if (oper == '/')
255 result = n1.value() / n2.value();
256 else
257 result = fmod(n1.value(), n2.value());
258
259 return Number(result);
260}
Note: See TracBrowser for help on using the repository browser.