weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 24 | #include "JSNumberCell.h" |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 25 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 26 | #if USE(JSVALUE32) |
| 27 | |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 28 | #include "NumberObject.h" |
cwzwarich@webkit.org | 0b51a73 | 2008-11-05 23:21:32 +0000 | [diff] [blame] | 29 | #include "UString.h" |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 30 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 31 | namespace JSC { |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 32 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 33 | JSValue JSNumberCell::toPrimitive(ExecState*, PreferredPrimitiveType) const |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 34 | { |
| 35 | return const_cast<JSNumberCell*>(this); |
| 36 | } |
| 37 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 38 | bool JSNumberCell::getPrimitiveNumber(ExecState*, double& number, JSValue& value) |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 39 | { |
weinig@apple.com | 2947a91 | 2008-07-07 02:49:29 +0000 | [diff] [blame] | 40 | number = m_value; |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 41 | value = this; |
| 42 | return true; |
| 43 | } |
| 44 | |
mjs@apple.com | 6c3268c | 2008-10-06 18:31:07 +0000 | [diff] [blame] | 45 | bool JSNumberCell::toBoolean(ExecState*) const |
| 46 | { |
| 47 | return m_value < 0.0 || m_value > 0.0; // false for NaN |
| 48 | } |
| 49 | |
weinig@apple.com | 2947a91 | 2008-07-07 02:49:29 +0000 | [diff] [blame] | 50 | double JSNumberCell::toNumber(ExecState*) const |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 51 | { |
weinig@apple.com | 2947a91 | 2008-07-07 02:49:29 +0000 | [diff] [blame] | 52 | return m_value; |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | UString JSNumberCell::toString(ExecState*) const |
| 56 | { |
weinig@apple.com | 2947a91 | 2008-07-07 02:49:29 +0000 | [diff] [blame] | 57 | return UString::from(m_value); |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | UString JSNumberCell::toThisString(ExecState*) const |
| 61 | { |
weinig@apple.com | 2947a91 | 2008-07-07 02:49:29 +0000 | [diff] [blame] | 62 | return UString::from(m_value); |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | JSObject* JSNumberCell::toObject(ExecState* exec) const |
| 66 | { |
| 67 | return constructNumber(exec, const_cast<JSNumberCell*>(this)); |
| 68 | } |
| 69 | |
| 70 | JSObject* JSNumberCell::toThisObject(ExecState* exec) const |
| 71 | { |
| 72 | return constructNumber(exec, const_cast<JSNumberCell*>(this)); |
| 73 | } |
| 74 | |
| 75 | bool JSNumberCell::getUInt32(uint32_t& uint32) const |
| 76 | { |
weinig@apple.com | 2947a91 | 2008-07-07 02:49:29 +0000 | [diff] [blame] | 77 | uint32 = static_cast<uint32_t>(m_value); |
| 78 | return uint32 == m_value; |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 79 | } |
| 80 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 81 | JSValue JSNumberCell::getJSNumber() |
weinig@apple.com | efdce0f | 2008-06-30 20:52:03 +0000 | [diff] [blame] | 82 | { |
| 83 | return this; |
| 84 | } |
| 85 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 86 | JSValue jsNumberCell(ExecState* exec, double d) |
darin@apple.com | 8281d83 | 2008-09-21 02:29:12 +0000 | [diff] [blame] | 87 | { |
| 88 | return new (exec) JSNumberCell(exec, d); |
| 89 | } |
| 90 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 91 | JSValue jsNumberCell(JSGlobalData* globalData, double d) |
darin@apple.com | 3d73fee | 2008-10-03 21:39:16 +0000 | [diff] [blame] | 92 | { |
| 93 | return new (globalData) JSNumberCell(globalData, d); |
| 94 | } |
| 95 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 96 | } // namespace JSC |
weinig@apple.com | 5176d51 | 2009-05-03 21:02:04 +0000 | [diff] [blame] | 97 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 98 | #else // USE(JSVALUE32) |
| 99 | |
| 100 | // Keep our exported symbols lists happy. |
| 101 | namespace JSC { |
| 102 | |
| 103 | JSValue jsNumberCell(ExecState*, double); |
barraclough@apple.com | 2c253ce | 2009-01-16 03:20:35 +0000 | [diff] [blame] | 104 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 105 | JSValue jsNumberCell(ExecState*, double) |
darin@apple.com | 3d73fee | 2008-10-03 21:39:16 +0000 | [diff] [blame] | 106 | { |
barraclough@apple.com | 2c253ce | 2009-01-16 03:20:35 +0000 | [diff] [blame] | 107 | ASSERT_NOT_REACHED(); |
ggaren@apple.com | acea358 | 2009-05-03 01:58:45 +0000 | [diff] [blame] | 108 | return JSValue(); |
darin@apple.com | 3d73fee | 2008-10-03 21:39:16 +0000 | [diff] [blame] | 109 | } |
| 110 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 111 | } // namespace JSC |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 112 | |
| 113 | #endif // USE(JSVALUE32) |