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 "JSNumberCell.h"
|
---|
25 |
|
---|
26 | #include "NumberObject.h"
|
---|
27 | #include "ustring.h"
|
---|
28 |
|
---|
29 | namespace JSC {
|
---|
30 |
|
---|
31 | JSValuePtr JSNumberCell::toPrimitive(ExecState*, PreferredPrimitiveType) const
|
---|
32 | {
|
---|
33 | return const_cast<JSNumberCell*>(this);
|
---|
34 | }
|
---|
35 |
|
---|
36 | bool JSNumberCell::getPrimitiveNumber(ExecState*, double& number, JSValuePtr& value)
|
---|
37 | {
|
---|
38 | number = m_value;
|
---|
39 | value = this;
|
---|
40 | return true;
|
---|
41 | }
|
---|
42 |
|
---|
43 | bool JSNumberCell::toBoolean(ExecState*) const
|
---|
44 | {
|
---|
45 | return m_value < 0.0 || m_value > 0.0; // false for NaN
|
---|
46 | }
|
---|
47 |
|
---|
48 | double JSNumberCell::toNumber(ExecState*) const
|
---|
49 | {
|
---|
50 | return m_value;
|
---|
51 | }
|
---|
52 |
|
---|
53 | UString JSNumberCell::toString(ExecState*) const
|
---|
54 | {
|
---|
55 | if (m_value == 0.0) // +0.0 or -0.0
|
---|
56 | return "0";
|
---|
57 | return UString::from(m_value);
|
---|
58 | }
|
---|
59 |
|
---|
60 | UString JSNumberCell::toThisString(ExecState*) const
|
---|
61 | {
|
---|
62 | if (m_value == 0.0) // +0.0 or -0.0
|
---|
63 | return "0";
|
---|
64 | return UString::from(m_value);
|
---|
65 | }
|
---|
66 |
|
---|
67 | JSObject* JSNumberCell::toObject(ExecState* exec) const
|
---|
68 | {
|
---|
69 | return constructNumber(exec, const_cast<JSNumberCell*>(this));
|
---|
70 | }
|
---|
71 |
|
---|
72 | JSObject* JSNumberCell::toThisObject(ExecState* exec) const
|
---|
73 | {
|
---|
74 | return constructNumber(exec, const_cast<JSNumberCell*>(this));
|
---|
75 | }
|
---|
76 |
|
---|
77 | bool JSNumberCell::getUInt32(uint32_t& uint32) const
|
---|
78 | {
|
---|
79 | uint32 = static_cast<uint32_t>(m_value);
|
---|
80 | return uint32 == m_value;
|
---|
81 | }
|
---|
82 |
|
---|
83 | bool JSNumberCell::getTruncatedInt32(int32_t& int32) const
|
---|
84 | {
|
---|
85 | if (!(m_value >= -2147483648.0 && m_value < 2147483648.0))
|
---|
86 | return false;
|
---|
87 | int32 = static_cast<int32_t>(m_value);
|
---|
88 | return true;
|
---|
89 | }
|
---|
90 |
|
---|
91 | bool JSNumberCell::getTruncatedUInt32(uint32_t& uint32) const
|
---|
92 | {
|
---|
93 | if (!(m_value >= 0.0 && m_value < 4294967296.0))
|
---|
94 | return false;
|
---|
95 | uint32 = static_cast<uint32_t>(m_value);
|
---|
96 | return true;
|
---|
97 | }
|
---|
98 |
|
---|
99 | JSValuePtr JSNumberCell::getJSNumber()
|
---|
100 | {
|
---|
101 | return this;
|
---|
102 | }
|
---|
103 |
|
---|
104 | NEVER_INLINE JSValuePtr jsNumberCell(ExecState* exec, double d)
|
---|
105 | {
|
---|
106 | return new (exec) JSNumberCell(exec, d);
|
---|
107 | }
|
---|
108 |
|
---|
109 | NEVER_INLINE JSValuePtr jsNaN(ExecState* exec)
|
---|
110 | {
|
---|
111 | return new (exec) JSNumberCell(exec, NaN);
|
---|
112 | }
|
---|
113 |
|
---|
114 | NEVER_INLINE JSValuePtr jsNumberCell(JSGlobalData* globalData, double d)
|
---|
115 | {
|
---|
116 | return new (globalData) JSNumberCell(globalData, d);
|
---|
117 | }
|
---|
118 |
|
---|
119 | NEVER_INLINE JSValuePtr jsNaN(JSGlobalData* globalData)
|
---|
120 | {
|
---|
121 | return new (globalData) JSNumberCell(globalData, NaN);
|
---|
122 | }
|
---|
123 |
|
---|
124 | } // namespace JSC
|
---|