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::toObject(JSValue* v, ExecState* exec)
|
---|
36 | {
|
---|
37 | ASSERT(isImmediate(v));
|
---|
38 | if (isNumber(v))
|
---|
39 | return constructNumberFromImmediateNumber(exec, v);
|
---|
40 | if (isBoolean(v))
|
---|
41 | return constructBooleanFromImmediateBoolean(exec, v);
|
---|
42 |
|
---|
43 | JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, v->isNull());
|
---|
44 | exec->setException(exception);
|
---|
45 | return new (exec) JSNotAnObject(exec, exception);
|
---|
46 | }
|
---|
47 |
|
---|
48 | JSObject* JSImmediate::prototype(JSValue* v, ExecState* exec)
|
---|
49 | {
|
---|
50 | ASSERT(isImmediate(v));
|
---|
51 | if (isNumber(v))
|
---|
52 | return exec->lexicalGlobalObject()->numberPrototype();
|
---|
53 | if (isBoolean(v))
|
---|
54 | return exec->lexicalGlobalObject()->booleanPrototype();
|
---|
55 |
|
---|
56 | JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, v->isNull());
|
---|
57 | exec->setException(exception);
|
---|
58 | return new (exec) JSNotAnObject(exec, exception);
|
---|
59 | }
|
---|
60 |
|
---|
61 | UString JSImmediate::toString(JSValue* v)
|
---|
62 | {
|
---|
63 | ASSERT(isImmediate(v));
|
---|
64 | if (isNumber(v))
|
---|
65 | return UString::from(getTruncatedInt32(v));
|
---|
66 | if (v == jsBoolean(false))
|
---|
67 | return "false";
|
---|
68 | if (v == jsBoolean(true))
|
---|
69 | return "true";
|
---|
70 | if (v->isNull())
|
---|
71 | return "null";
|
---|
72 | ASSERT(v == jsUndefined());
|
---|
73 | return "undefined";
|
---|
74 | }
|
---|
75 |
|
---|
76 | NEVER_INLINE double JSImmediate::nonInlineNaN()
|
---|
77 | {
|
---|
78 | return std::numeric_limits<double>::quiet_NaN();
|
---|
79 | }
|
---|
80 |
|
---|
81 | } // namespace JSC
|
---|