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 "JSGlobalObject.h"
|
---|
28 | #include "JSNotAnObject.h"
|
---|
29 | #include "NumberConstructor.h"
|
---|
30 | #include "NumberPrototype.h"
|
---|
31 |
|
---|
32 | namespace KJS {
|
---|
33 |
|
---|
34 | JSObject* JSImmediate::toObject(const JSValue* v, ExecState* exec)
|
---|
35 | {
|
---|
36 | ASSERT(isImmediate(v));
|
---|
37 | if (isNumber(v))
|
---|
38 | return constructNumberFromImmediateNumber(exec, const_cast<JSValue*>(v));
|
---|
39 | if (isBoolean(v))
|
---|
40 | return constructBooleanFromImmediateBoolean(exec, const_cast<JSValue*>(v));
|
---|
41 | if (v == jsNull())
|
---|
42 | return new (exec) JSNotAnObject(throwError(exec, TypeError, "Null value"));
|
---|
43 | ASSERT(v == jsUndefined());
|
---|
44 | return new (exec) JSNotAnObject(throwError(exec, TypeError, "Undefined value"));
|
---|
45 | }
|
---|
46 |
|
---|
47 | JSObject* JSImmediate::prototype(const JSValue* v, ExecState* exec)
|
---|
48 | {
|
---|
49 | ASSERT(isImmediate(v));
|
---|
50 | if (isNumber(v))
|
---|
51 | return exec->lexicalGlobalObject()->numberPrototype();
|
---|
52 | if (isBoolean(v))
|
---|
53 | return exec->lexicalGlobalObject()->booleanPrototype();
|
---|
54 | if (v == jsNull())
|
---|
55 | return new (exec) JSNotAnObject(throwError(exec, TypeError, "Null value"));
|
---|
56 | ASSERT(v == jsUndefined());
|
---|
57 | return new (exec) JSNotAnObject(throwError(exec, TypeError, "Undefined value"));
|
---|
58 | }
|
---|
59 |
|
---|
60 | UString JSImmediate::toString(const JSValue* v)
|
---|
61 | {
|
---|
62 | ASSERT(isImmediate(v));
|
---|
63 | if (isNumber(v))
|
---|
64 | return UString::from(getTruncatedInt32(v));
|
---|
65 | if (v == jsBoolean(false))
|
---|
66 | return "false";
|
---|
67 | if (v == jsBoolean(true))
|
---|
68 | return "true";
|
---|
69 | if (v == jsNull())
|
---|
70 | return "null";
|
---|
71 | ASSERT(v == jsUndefined());
|
---|
72 | return "undefined";
|
---|
73 | }
|
---|
74 |
|
---|
75 | } // namespace KJS
|
---|