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

Last change on this file since 12729 was 12729, checked in by ggaren, 19 years ago

JavaScriptCore:

Reviewed by eric.


  • Fixed build. As it goes without saying, I will not mention that I blame Kevin.
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/JSImmediate.cpp: (KJS::JSImmediate::toObject):

JavaScriptGlue:

Reviewed by eric.

  • Fixed build.
  • UserObjectImp.cpp: (UserObjectImp::toPrimitive):
  • UserObjectImp.h:

WebCore:

Reviewed by eric.

  • Fixed build.
  • bridge/mac/WebCoreFrameBridge.mm:
  • khtml/ecma/kjs_binding.h: (KJS::DOMFunction::toPrimitive):
  • khtml/ecma/kjs_dom.cpp: (KJS::DOMNode::toPrimitive): (KJS::DOMNodeList::toPrimitive):
  • khtml/ecma/kjs_dom.h:
  • khtml/ecma/kjs_window.cpp: (KJS::Location::toPrimitive): (KJS::Selection::toPrimitive):
  • khtml/ecma/kjs_window.h:
File size: 2.3 KB
Line 
1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 2003-2006 Apple Computer, Inc
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#include "JSImmediate.h"
23#include "kxmlcore/Assertions.h"
24#include "object.h"
25#include "value.h"
26
27namespace KJS {
28
29JSObject *JSImmediate::toObject(const JSValue *v, ExecState *exec)
30{
31 assert(isImmediate(v));
32 if (v == jsNull())
33 return throwError(exec, TypeError, "Null value");
34 else if (v == jsUndefined())
35 return throwError(exec, TypeError, "Undefined value");
36 else if (isBoolean(v)) {
37 List args;
38 args.append(const_cast<JSValue *>(v));
39 return exec->lexicalInterpreter()->builtinBoolean()->construct(exec, args);
40 } else {
41 ASSERT(isNumber(v));
42 List args;
43 args.append(const_cast<JSValue *>(v));
44 return exec->lexicalInterpreter()->builtinNumber()->construct(exec, args);
45 }
46}
47
48UString JSImmediate::toString(const JSValue *v)
49{
50 ASSERT(isImmediate(v));
51
52 if (v == jsNull())
53 return "null";
54 else if (v == jsUndefined())
55 return "undefined";
56 else if (v == jsBoolean(true))
57 return "true";
58 else if (v == jsBoolean(false))
59 return "false";
60 else {
61 assert(isNumber(v));
62 double d = toDouble(v);
63 if (d == 0.0) // +0.0 or -0.0
64 return "0";
65 return UString::from(d);
66 }
67}
68
69JSType JSImmediate::type(const JSValue *v)
70{
71 ASSERT(isImmediate(v));
72
73 uintptr_t tag = getTag(v);
74 if (tag == UndefinedType)
75 return v == jsUndefined() ? UndefinedType : NullType;
76 return static_cast<JSType>(tag);
77}
78
79} // namespace KJS
Note: See TracBrowser for help on using the repository browser.