blob: f1009b9c010983f9d9530b5ec0b34d73b20a51ef [file] [log] [blame]
weinig@apple.comefdce0f2008-06-30 20:52:03 +00001/*
2 * Copyright (C) 1999-2002 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
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"
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000024#include "JSNumberCell.h"
weinig@apple.comefdce0f2008-06-30 20:52:03 +000025
ggaren@apple.com540d71a62009-07-30 20:57:44 +000026#if USE(JSVALUE32)
27
weinig@apple.comefdce0f2008-06-30 20:52:03 +000028#include "NumberObject.h"
cwzwarich@webkit.org0b51a732008-11-05 23:21:32 +000029#include "UString.h"
weinig@apple.comefdce0f2008-06-30 20:52:03 +000030
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000031namespace JSC {
weinig@apple.comefdce0f2008-06-30 20:52:03 +000032
ggaren@apple.comdc067b62009-05-01 22:43:39 +000033JSValue JSNumberCell::toPrimitive(ExecState*, PreferredPrimitiveType) const
weinig@apple.comefdce0f2008-06-30 20:52:03 +000034{
35 return const_cast<JSNumberCell*>(this);
36}
37
ggaren@apple.comdc067b62009-05-01 22:43:39 +000038bool JSNumberCell::getPrimitiveNumber(ExecState*, double& number, JSValue& value)
weinig@apple.comefdce0f2008-06-30 20:52:03 +000039{
weinig@apple.com2947a912008-07-07 02:49:29 +000040 number = m_value;
weinig@apple.comefdce0f2008-06-30 20:52:03 +000041 value = this;
42 return true;
43}
44
mjs@apple.com6c3268c2008-10-06 18:31:07 +000045bool JSNumberCell::toBoolean(ExecState*) const
46{
47 return m_value < 0.0 || m_value > 0.0; // false for NaN
48}
49
weinig@apple.com2947a912008-07-07 02:49:29 +000050double JSNumberCell::toNumber(ExecState*) const
weinig@apple.comefdce0f2008-06-30 20:52:03 +000051{
weinig@apple.com2947a912008-07-07 02:49:29 +000052 return m_value;
weinig@apple.comefdce0f2008-06-30 20:52:03 +000053}
54
55UString JSNumberCell::toString(ExecState*) const
56{
weinig@apple.com2947a912008-07-07 02:49:29 +000057 return UString::from(m_value);
weinig@apple.comefdce0f2008-06-30 20:52:03 +000058}
59
60UString JSNumberCell::toThisString(ExecState*) const
61{
weinig@apple.com2947a912008-07-07 02:49:29 +000062 return UString::from(m_value);
weinig@apple.comefdce0f2008-06-30 20:52:03 +000063}
64
65JSObject* JSNumberCell::toObject(ExecState* exec) const
66{
67 return constructNumber(exec, const_cast<JSNumberCell*>(this));
68}
69
70JSObject* JSNumberCell::toThisObject(ExecState* exec) const
71{
72 return constructNumber(exec, const_cast<JSNumberCell*>(this));
73}
74
75bool JSNumberCell::getUInt32(uint32_t& uint32) const
76{
weinig@apple.com2947a912008-07-07 02:49:29 +000077 uint32 = static_cast<uint32_t>(m_value);
78 return uint32 == m_value;
weinig@apple.comefdce0f2008-06-30 20:52:03 +000079}
80
ggaren@apple.comdc067b62009-05-01 22:43:39 +000081JSValue JSNumberCell::getJSNumber()
weinig@apple.comefdce0f2008-06-30 20:52:03 +000082{
83 return this;
84}
85
ggaren@apple.comdc067b62009-05-01 22:43:39 +000086JSValue jsNumberCell(ExecState* exec, double d)
darin@apple.com8281d832008-09-21 02:29:12 +000087{
88 return new (exec) JSNumberCell(exec, d);
89}
90
ggaren@apple.comdc067b62009-05-01 22:43:39 +000091JSValue jsNumberCell(JSGlobalData* globalData, double d)
darin@apple.com3d73fee2008-10-03 21:39:16 +000092{
93 return new (globalData) JSNumberCell(globalData, d);
94}
95
ggaren@apple.com540d71a62009-07-30 20:57:44 +000096} // namespace JSC
weinig@apple.com5176d512009-05-03 21:02:04 +000097
ggaren@apple.com540d71a62009-07-30 20:57:44 +000098#else // USE(JSVALUE32)
99
100// Keep our exported symbols lists happy.
101namespace JSC {
102
103JSValue jsNumberCell(ExecState*, double);
barraclough@apple.com2c253ce2009-01-16 03:20:35 +0000104
ggaren@apple.comdc067b62009-05-01 22:43:39 +0000105JSValue jsNumberCell(ExecState*, double)
darin@apple.com3d73fee2008-10-03 21:39:16 +0000106{
barraclough@apple.com2c253ce2009-01-16 03:20:35 +0000107 ASSERT_NOT_REACHED();
ggaren@apple.comacea3582009-05-03 01:58:45 +0000108 return JSValue();
darin@apple.com3d73fee2008-10-03 21:39:16 +0000109}
110
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +0000111} // namespace JSC
ggaren@apple.com540d71a62009-07-30 20:57:44 +0000112
113#endif // USE(JSVALUE32)