2 * This file is part of the KDE libraries
3 * Copyright (C) 2003-2006 Apple Computer, Inc
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #include "JSImmediate.h"
27 JSObject
*JSImmediate::toObject(const JSValue
*v
, ExecState
*exec
)
29 assert(isImmediate(v
));
31 return throwError(exec
, TypeError
, "Null value");
32 else if (v
== jsUndefined())
33 return throwError(exec
, TypeError
, "Undefined value");
34 else if (isBoolean(v
)) {
36 args
.append(const_cast<JSValue
*>(v
));
37 return exec
->lexicalInterpreter()->builtinBoolean()->construct(exec
, args
);
41 args
.append(const_cast<JSValue
*>(v
));
42 return exec
->lexicalInterpreter()->builtinNumber()->construct(exec
, args
);
46 UString
JSImmediate::toString(const JSValue
*v
)
48 ASSERT(isImmediate(v
));
52 else if (v
== jsUndefined())
54 else if (v
== jsBoolean(true))
56 else if (v
== jsBoolean(false))
60 double d
= toDouble(v
);
61 if (d
== 0.0) // +0.0 or -0.0
63 return UString::from(d
);
67 JSType
JSImmediate::type(const JSValue
*v
)
69 ASSERT(isImmediate(v
));
71 uintptr_t tag
= getTag(v
);
72 if (tag
== UndefinedType
)
73 return v
== jsUndefined() ? UndefinedType
: NullType
;
74 return static_cast<JSType
>(tag
);