source: webkit/trunk/JavaScriptCore/kjs/internal.cpp@ 33038

Last change on this file since 33038 was 33038, checked in by [email protected], 17 years ago

Roll out recent threading changes (r32807, r32810, r32819, r32822) to simplify
SquirrelFish merging.

  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
1/*
2 * Copyright (C) 1999-2002 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2004, 2007, 2008 Apple Inc. All rights reserved.
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#include "config.h"
24#include "internal.h"
25
26#include "ExecState.h"
27#include "array_object.h"
28#include "bool_object.h"
29#include "collector.h"
30#include "date_object.h"
31#include "debugger.h"
32#include "error_object.h"
33#include "function_object.h"
34#include "lexer.h"
35#include "math_object.h"
36#include "nodes.h"
37#include "number_object.h"
38#include "object.h"
39#include "object_object.h"
40#include "operations.h"
41#include "regexp_object.h"
42#include "string_object.h"
43#include <math.h>
44#include <stdio.h>
45#include <wtf/Assertions.h>
46#include <wtf/HashMap.h>
47#include <wtf/HashSet.h>
48#include <wtf/Vector.h>
49
50namespace KJS {
51
52// ------------------------------ StringImp ------------------------------------
53
54JSValue* StringImp::toPrimitive(ExecState*, JSType) const
55{
56 return const_cast<StringImp*>(this);
57}
58
59bool StringImp::getPrimitiveNumber(ExecState*, double& number, JSValue*& value)
60{
61 value = this;
62 number = val.toDouble();
63 return false;
64}
65
66bool StringImp::toBoolean(ExecState *) const
67{
68 return (val.size() > 0);
69}
70
71double StringImp::toNumber(ExecState *) const
72{
73 return val.toDouble();
74}
75
76UString StringImp::toString(ExecState *) const
77{
78 return val;
79}
80
81JSObject* StringImp::toObject(ExecState *exec) const
82{
83 return new StringInstance(exec->lexicalGlobalObject()->stringPrototype(), const_cast<StringImp*>(this));
84}
85
86// ------------------------------ NumberImp ------------------------------------
87
88JSValue* NumberImp::toPrimitive(ExecState*, JSType) const
89{
90 return const_cast<NumberImp*>(this);
91}
92
93bool NumberImp::getPrimitiveNumber(ExecState*, double& number, JSValue*& value)
94{
95 number = val;
96 value = this;
97 return true;
98}
99
100bool NumberImp::toBoolean(ExecState *) const
101{
102 return val < 0.0 || val > 0.0; // false for NaN
103}
104
105double NumberImp::toNumber(ExecState *) const
106{
107 return val;
108}
109
110UString NumberImp::toString(ExecState *) const
111{
112 if (val == 0.0) // +0.0 or -0.0
113 return "0";
114 return UString::from(val);
115}
116
117JSObject *NumberImp::toObject(ExecState *exec) const
118{
119 List args;
120 args.append(const_cast<NumberImp*>(this));
121 return static_cast<JSObject *>(exec->lexicalGlobalObject()->numberConstructor()->construct(exec,args));
122}
123
124bool NumberImp::getUInt32(uint32_t& uint32) const
125{
126 uint32 = static_cast<uint32_t>(val);
127 return uint32 == val;
128}
129
130bool NumberImp::getTruncatedInt32(int32_t& int32) const
131{
132 if (!(val >= -2147483648.0 && val < 2147483648.0))
133 return false;
134 int32 = static_cast<int32_t>(val);
135 return true;
136}
137
138bool NumberImp::getTruncatedUInt32(uint32_t& uint32) const
139{
140 if (!(val >= 0.0 && val < 4294967296.0))
141 return false;
142 uint32 = static_cast<uint32_t>(val);
143 return true;
144}
145
146// --------------------------- GetterSetterImp ---------------------------------
147void GetterSetterImp::mark()
148{
149 JSCell::mark();
150
151 if (getter && !getter->marked())
152 getter->mark();
153 if (setter && !setter->marked())
154 setter->mark();
155}
156
157JSValue* GetterSetterImp::toPrimitive(ExecState*, JSType) const
158{
159 ASSERT(false);
160 return jsNull();
161}
162
163bool GetterSetterImp::getPrimitiveNumber(ExecState*, double& number, JSValue*& value)
164{
165 ASSERT_NOT_REACHED();
166 number = 0;
167 value = 0;
168 return true;
169}
170
171bool GetterSetterImp::toBoolean(ExecState*) const
172{
173 ASSERT(false);
174 return false;
175}
176
177double GetterSetterImp::toNumber(ExecState *) const
178{
179 ASSERT(false);
180 return 0.0;
181}
182
183UString GetterSetterImp::toString(ExecState *) const
184{
185 ASSERT(false);
186 return UString::null();
187}
188
189JSObject *GetterSetterImp::toObject(ExecState *exec) const
190{
191 ASSERT(false);
192 return jsNull()->toObject(exec);
193}
194
195// ------------------------------ LabelStack -----------------------------------
196
197bool LabelStack::push(const Identifier &id)
198{
199 if (contains(id))
200 return false;
201
202 StackElem *newtos = new StackElem;
203 newtos->id = id;
204 newtos->prev = tos;
205 tos = newtos;
206 return true;
207}
208
209bool LabelStack::contains(const Identifier &id) const
210{
211 if (id.isEmpty())
212 return true;
213
214 for (StackElem *curr = tos; curr; curr = curr->prev)
215 if (curr->id == id)
216 return true;
217
218 return false;
219}
220
221// ------------------------------ InternalFunctionImp --------------------------
222
223const ClassInfo InternalFunctionImp::info = { "Function", 0, 0, 0 };
224
225InternalFunctionImp::InternalFunctionImp()
226{
227}
228
229InternalFunctionImp::InternalFunctionImp(FunctionPrototype* funcProto, const Identifier& name)
230 : JSObject(funcProto)
231 , m_name(name)
232{
233}
234
235bool InternalFunctionImp::implementsCall() const
236{
237 return true;
238}
239
240bool InternalFunctionImp::implementsHasInstance() const
241{
242 return true;
243}
244
245}
Note: See TracBrowser for help on using the repository browser.