source:
webkit/trunk/JavaScriptCore/runtime/JSImmediate.cpp@
45545
Last change on this file since 45545 was 43122, checked in by [email protected], 16 years ago | |
---|---|
2009-05-01 Geoffrey Garen <[email protected]>
JavaScriptGlue:
2009-05-01 Geoffrey Garen <[email protected]>
WebCore:
2009-05-01 Geoffrey Garen <[email protected]>
WebKit/mac:
2009-05-01 Geoffrey Garen <[email protected]>
WebKit/qt:
2009-05-01 Geoffrey Garen <[email protected]>
WebKit/win:
2009-05-01 Geoffrey Garen <[email protected]>
WebKit/wx:
2009-05-01 Geoffrey Garen <[email protected]>
|
|
|
|
File size: 3.0 KB |
Line | |
---|---|
1 | /* |
2 | * Copyright (C) 2003-2006, 2008 Apple Inc. All rights reserved. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | * |
19 | */ |
20 | |
21 | #include "config.h" |
22 | #include "JSImmediate.h" |
23 | |
24 | #include "BooleanConstructor.h" |
25 | #include "BooleanPrototype.h" |
26 | #include "Error.h" |
27 | #include "ExceptionHelpers.h" |
28 | #include "JSGlobalObject.h" |
29 | #include "JSNotAnObject.h" |
30 | #include "NumberConstructor.h" |
31 | #include "NumberPrototype.h" |
32 | |
33 | namespace JSC { |
34 | |
35 | JSObject* JSImmediate::toThisObject(JSValue v, ExecState* exec) |
36 | { |
37 | ASSERT(isImmediate(v)); |
38 | if (isNumber(v)) |
39 | return constructNumber(exec, v); |
40 | if (isBoolean(v)) |
41 | return constructBooleanFromImmediateBoolean(exec, v); |
42 | ASSERT(v.isUndefinedOrNull()); |
43 | return exec->globalThisValue(); |
44 | } |
45 | |
46 | JSObject* JSImmediate::toObject(JSValue v, ExecState* exec) |
47 | { |
48 | ASSERT(isImmediate(v)); |
49 | if (isNumber(v)) |
50 | return constructNumber(exec, v); |
51 | if (isBoolean(v)) |
52 | return constructBooleanFromImmediateBoolean(exec, v); |
53 | |
54 | JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, v.isNull()); |
55 | exec->setException(exception); |
56 | return new (exec) JSNotAnObject(exec, exception); |
57 | } |
58 | |
59 | JSObject* JSImmediate::prototype(JSValue v, ExecState* exec) |
60 | { |
61 | ASSERT(isImmediate(v)); |
62 | if (isNumber(v)) |
63 | return exec->lexicalGlobalObject()->numberPrototype(); |
64 | if (isBoolean(v)) |
65 | return exec->lexicalGlobalObject()->booleanPrototype(); |
66 | |
67 | JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, v.isNull()); |
68 | exec->setException(exception); |
69 | return new (exec) JSNotAnObject(exec, exception); |
70 | } |
71 | |
72 | UString JSImmediate::toString(JSValue v) |
73 | { |
74 | ASSERT(isImmediate(v)); |
75 | if (isIntegerNumber(v)) |
76 | return UString::from(getTruncatedInt32(v)); |
77 | #if USE(ALTERNATE_JSIMMEDIATE) |
78 | if (isNumber(v)) { |
79 | ASSERT(isDoubleNumber(v)); |
80 | double value = doubleValue(v); |
81 | if (value == 0.0) // +0.0 or -0.0 |
82 | return "0"; |
83 | return UString::from(value); |
84 | } |
85 | #else |
86 | ASSERT(!isNumber(v)); |
87 | #endif |
88 | if (jsBoolean(false) == v) |
89 | return "false"; |
90 | if (jsBoolean(true) == v) |
91 | return "true"; |
92 | if (v.isNull()) |
93 | return "null"; |
94 | ASSERT(v.isUndefined()); |
95 | return "undefined"; |
96 | } |
97 | |
98 | NEVER_INLINE double JSImmediate::nonInlineNaN() |
99 | { |
100 | return std::numeric_limits<double>::quiet_NaN(); |
101 | } |
102 | |
103 | } // namespace JSC |