File indexing completed on 2024-05-12 15:43:24
0001 /* 0002 * This file is part of the KDE libraries 0003 * Copyright (C) 2003-2006 Apple Computer, Inc 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 * 0020 */ 0021 0022 #include "JSImmediate.h" 0023 #include "object.h" 0024 0025 namespace KJS 0026 { 0027 0028 JSObject *JSImmediate::toObject(const JSValue *v, ExecState *exec) 0029 { 0030 assert(isImmediate(v)); 0031 if (v == jsNull()) { 0032 return throwError(exec, TypeError, "Null value"); 0033 } else if (v == jsUndefined()) { 0034 return throwError(exec, TypeError, "Undefined value"); 0035 } else if (isBoolean(v)) { 0036 List args; 0037 args.append(const_cast<JSValue *>(v)); 0038 return exec->lexicalInterpreter()->builtinBoolean()->construct(exec, args); 0039 } else { 0040 ASSERT(isNumber(v)); 0041 List args; 0042 args.append(const_cast<JSValue *>(v)); 0043 return exec->lexicalInterpreter()->builtinNumber()->construct(exec, args); 0044 } 0045 } 0046 0047 UString JSImmediate::toString(const JSValue *v) 0048 { 0049 ASSERT(isImmediate(v)); 0050 0051 if (v == jsNull()) { 0052 return "null"; 0053 } else if (v == jsUndefined()) { 0054 return "undefined"; 0055 } else if (v == jsBoolean(true)) { 0056 return "true"; 0057 } else if (v == jsBoolean(false)) { 0058 return "false"; 0059 } else { 0060 assert(isNumber(v)); 0061 double d = toDouble(v); 0062 if (d == 0.0) { // +0.0 or -0.0 0063 return "0"; 0064 } 0065 return UString::from(d); 0066 } 0067 } 0068 0069 JSType JSImmediate::type(const JSValue *v) 0070 { 0071 ASSERT(isImmediate(v)); 0072 0073 uintptr_t tag = getTag(v); 0074 if (tag == UndefinedType) { 0075 return v == jsUndefined() ? UndefinedType : NullType; 0076 } 0077 return static_cast<JSType>(tag); 0078 } 0079 0080 } // namespace KJS