source: webkit/trunk/JavaScriptCore/kjs/JSImmediate.cpp@ 34659

Last change on this file since 34659 was 34659, checked in by [email protected], 17 years ago

Reviewed by Darin.

Prepare JavaScript heap for being per-thread.

  • Property svn:eol-style set to native
File size: 2.1 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 "JSGlobalObject.h"
25#include "BooleanObject.h"
26#include "JSNotAnObject.h"
27#include "NumberObject.h"
28#include "JSObject.h"
29
30namespace KJS {
31
32JSObject *JSImmediate::toObject(const JSValue *v, ExecState *exec)
33{
34 ASSERT(isImmediate(v));
35 if (v == jsNull())
36 return new (exec) JSNotAnObject(throwError(exec, TypeError, "Null value"));
37 else if (v == jsUndefined())
38 return new (exec) JSNotAnObject(throwError(exec, TypeError, "Undefined value"));
39 else if (isBoolean(v)) {
40 ArgList args;
41 args.append(const_cast<JSValue *>(v));
42 return exec->lexicalGlobalObject()->booleanConstructor()->construct(exec, args);
43 } else {
44 ASSERT(isNumber(v));
45 ArgList args;
46 args.append(const_cast<JSValue *>(v));
47 return exec->lexicalGlobalObject()->numberConstructor()->construct(exec, args);
48 }
49}
50
51UString JSImmediate::toString(const JSValue* v)
52{
53 ASSERT(isImmediate(v));
54 if (v == jsNull())
55 return "null";
56 if (v == jsUndefined())
57 return "undefined";
58 if (v == jsBoolean(true))
59 return "true";
60 if (v == jsBoolean(false))
61 return "false";
62 ASSERT(isNumber(v));
63 return UString::from(getTruncatedInt32(v));
64}
65
66} // namespace KJS
Note: See TracBrowser for help on using the repository browser.