]>
git.saurik.com Git - apple/javascriptcore.git/blob - kjs/JSImmediate.cpp
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.
23 #include "JSImmediate.h"
25 #include "JSGlobalObject.h"
26 #include "bool_object.h"
27 #include "number_object.h"
32 JSObject
*JSImmediate::toObject(const JSValue
*v
, ExecState
*exec
)
34 ASSERT(isImmediate(v
));
36 return throwError(exec
, TypeError
, "Null value");
37 else if (v
== jsUndefined())
38 return throwError(exec
, TypeError
, "Undefined value");
39 else if (isBoolean(v
)) {
41 args
.append(const_cast<JSValue
*>(v
));
42 return exec
->lexicalGlobalObject()->booleanConstructor()->construct(exec
, args
);
46 args
.append(const_cast<JSValue
*>(v
));
47 return exec
->lexicalGlobalObject()->numberConstructor()->construct(exec
, args
);
51 UString
JSImmediate::toString(const JSValue
*v
)
53 ASSERT(isImmediate(v
));
57 else if (v
== jsUndefined())
59 else if (v
== jsBoolean(true))
61 else if (v
== jsBoolean(false))
65 double d
= toDouble(v
);
66 if (d
== 0.0) // +0.0 or -0.0
68 return UString::from(d
);
72 JSType
JSImmediate::type(const JSValue
*v
)
74 ASSERT(isImmediate(v
));
76 uintptr_t tag
= getTag(v
);
77 if (tag
== UndefinedType
)
78 return v
== jsUndefined() ? UndefinedType
: NullType
;
79 return static_cast<JSType
>(tag
);