source: webkit/trunk/JavaScriptCore/kjs/value.cpp@ 17372

Last change on this file since 17372 was 17372, checked in by darin, 19 years ago

Reviewed by Geoff.

  • made changes so the code compiles with the highest warning level under MSVC (disabling some warnings, making some code fixes)
  • API/JSCallbackConstructor.cpp: (KJS::JSCallbackConstructor::construct):
  • API/JSCallbackFunction.cpp: (KJS::JSCallbackFunction::callAsFunction):
  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::init): (KJS::JSCallbackObject::construct): (KJS::JSCallbackObject::callAsFunction):
  • API/JSObjectRef.cpp: (JSPropertyNameArrayGetNameAtIndex):
  • API/JSStringRef.cpp: (JSStringCreateWithCharacters):
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • bindings/c/c_utility.cpp: (KJS::Bindings::convertUTF8ToUTF16): (KJS::Bindings::coerceValueToNPVariantStringType): (KJS::Bindings::convertValueToNPVariant):
  • kjs/DateMath.h: (KJS::GregorianDateTime::GregorianDateTime):
  • kjs/ExecState.h: (KJS::ExecState::hadException):
  • kjs/JSImmediate.h: (KJS::JSImmediate::fromDouble): (KJS::JSImmediate::toDouble): (KJS::JSImmediate::NanAsBits): (KJS::JSImmediate::oneAsBits):
  • kjs/Parser.h:
  • kjs/PropertyNameArray.h: (KJS::PropertyNameArray::size):
  • kjs/array_object.cpp: (ArrayObjectImp::callAsFunction):
  • kjs/bool_object.cpp: (BooleanObjectImp::callAsFunction):
  • kjs/collector.cpp: (KJS::Collector::allocate): (KJS::Collector::markCurrentThreadConservatively): (KJS::Collector::collect):
  • kjs/completion.h: (KJS::Completion::isValueCompletion):
  • kjs/date_object.cpp: (KJS::findMonth):
  • kjs/debugger.cpp: (Debugger::sourceParsed): (Debugger::sourceUnused): (Debugger::exception): (Debugger::atStatement): (Debugger::callEvent): (Debugger::returnEvent):
  • kjs/dtoa.cpp:
  • kjs/error_object.cpp: (ErrorObjectImp::callAsFunction): (NativeErrorImp::callAsFunction):
  • kjs/function.cpp: (KJS::FunctionImp::processVarDecls): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/function_object.cpp: (FunctionPrototype::callAsFunction):
  • kjs/grammar.y:
  • kjs/identifier.cpp: (KJS::CStringTranslator::translate): (KJS::Identifier::add):
  • kjs/internal.h:
  • kjs/lexer.cpp: (Lexer::lex): (Lexer::isIdentStart): (Lexer::isIdentPart): (isDecimalDigit): (Lexer::isHexDigit): (Lexer::isOctalDigit): (Lexer::matchPunctuator): (Lexer::singleEscape): (Lexer::convertOctal): (Lexer::convertHex): (Lexer::convertUnicode): (Lexer::record8):
  • kjs/lexer.h:
  • kjs/math_object.cpp: (MathFuncImp::callAsFunction):
  • kjs/number_object.cpp: (integer_part_noexp): (intPow10): (NumberProtoFunc::callAsFunction): (NumberObjectImp::callAsFunction):
  • kjs/object.cpp: (KJS::JSObject::deleteProperty): (KJS::JSObject::callAsFunction): (KJS::JSObject::toBoolean): (KJS::JSObject::toObject):
  • kjs/object.h: (KJS::JSObject::getPropertySlot):
  • kjs/property_map.cpp: (KJS::isValid): (KJS::PropertyMap::put): (KJS::PropertyMap::insert): (KJS::PropertyMap::containsGettersOrSetters):
  • kjs/property_map.h: (KJS::PropertyMap::hasGetterSetterProperties):
  • kjs/property_slot.h:
  • kjs/string_object.cpp: (StringInstance::getPropertyNames): (StringObjectImp::callAsFunction): (StringObjectFuncImp::callAsFunction):
  • kjs/ustring.cpp: (KJS::UString::Rep::computeHash): (KJS::UString::UString): (KJS::UString::from): (KJS::UString::append): (KJS::UString::ascii): (KJS::UString::operator=): (KJS::UString::find): (KJS::UString::rfind):
  • kjs/ustring.h: (KJS::UChar::high): (KJS::UChar::low): (KJS::UCharReference::low): (KJS::UCharReference::high):
  • kjs/value.cpp: (KJS::JSValue::toUInt16):
  • kjs/value.h:
  • pcre/pcre_compile.c: (get_othercase_range):
  • pcre/pcre_exec.c: (match):
  • pcre/pcre_internal.h:
  • wtf/HashFunctions.h: (WTF::intHash): (WTF::PtrHash::hash):
  • wtf/MathExtras.h: (isnan): (lround): (lroundf):
  • wtf/StringExtras.h: (strncasecmp):
  • wtf/unicode/icu/UnicodeIcu.h: (WTF::Unicode::isPrintableChar):
  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 1999-2001 Harri Porten ([email protected])
4 * Copyright (C) 2001 Peter Kelly ([email protected])
5 * Copyright (C) 2003 Apple Computer, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#include "config.h"
25#include "value.h"
26
27#include "error_object.h"
28#include "nodes.h"
29#include "operations.h"
30#include <stdio.h>
31#include <string.h>
32#include <wtf/MathExtras.h>
33
34namespace KJS {
35
36static const double D16 = 65536.0;
37static const double D32 = 4294967296.0;
38
39void *JSCell::operator new(size_t size)
40{
41 return Collector::allocate(size);
42}
43
44bool JSCell::getUInt32(unsigned&) const
45{
46 return false;
47}
48
49// ECMA 9.4
50double JSValue::toInteger(ExecState *exec) const
51{
52 uint32_t i;
53 if (getUInt32(i))
54 return i;
55 return roundValue(exec, const_cast<JSValue*>(this));
56}
57
58inline int32_t JSValue::toInt32Inline(ExecState* exec, bool& ok) const
59{
60 ok = true;
61
62 uint32_t i;
63 if (getUInt32(i))
64 return i;
65
66 double d = roundValue(exec, const_cast<JSValue*>(this));
67 if (isNaN(d) || isInf(d)) {
68 ok = false;
69 return 0;
70 }
71 double d32 = fmod(d, D32);
72
73 if (d32 >= D32 / 2)
74 d32 -= D32;
75 else if (d32 < -D32 / 2)
76 d32 += D32;
77
78 return static_cast<int32_t>(d32);
79}
80
81int32_t JSValue::toInt32(ExecState* exec) const
82{
83 bool ok;
84 return toInt32(exec, ok);
85}
86
87int32_t JSValue::toInt32(ExecState* exec, bool& ok) const
88{
89 return toInt32Inline(exec, ok);
90}
91
92uint32_t JSValue::toUInt32(ExecState *exec) const
93{
94 uint32_t i;
95 if (getUInt32(i))
96 return i;
97
98 double d = roundValue(exec, const_cast<JSValue*>(this));
99 if (isNaN(d) || isInf(d))
100 return 0;
101 double d32 = fmod(d, D32);
102
103 if (d32 < 0)
104 d32 += D32;
105
106 return static_cast<uint32_t>(d32);
107}
108
109uint16_t JSValue::toUInt16(ExecState *exec) const
110{
111 uint32_t i;
112 if (getUInt32(i))
113 return static_cast<uint16_t>(i);
114
115 double d = roundValue(exec, const_cast<JSValue*>(this));
116 if (isNaN(d) || isInf(d))
117 return 0;
118 double d16 = fmod(d, D16);
119
120 if (d16 < 0)
121 d16 += D16;
122
123 return static_cast<uint16_t>(d16);
124}
125
126bool JSCell::getNumber(double &numericValue) const
127{
128 if (!isNumber())
129 return false;
130 numericValue = static_cast<const NumberImp *>(this)->value();
131 return true;
132}
133
134double JSCell::getNumber() const
135{
136 return isNumber() ? static_cast<const NumberImp *>(this)->value() : NaN;
137}
138
139bool JSCell::getString(UString &stringValue) const
140{
141 if (!isString())
142 return false;
143 stringValue = static_cast<const StringImp *>(this)->value();
144 return true;
145}
146
147UString JSCell::getString() const
148{
149 return isString() ? static_cast<const StringImp *>(this)->value() : UString();
150}
151
152JSObject *JSCell::getObject()
153{
154 return isObject() ? static_cast<JSObject *>(this) : 0;
155}
156
157const JSObject *JSCell::getObject() const
158{
159 return isObject() ? static_cast<const JSObject *>(this) : 0;
160}
161
162JSCell *jsString(const char *s)
163{
164 return new StringImp(s ? s : "");
165}
166
167JSCell *jsString(const UString &s)
168{
169 return s.isNull() ? new StringImp("") : new StringImp(s);
170}
171
172// This method includes a PIC branch to set up the NumberImp's vtable, so we quarantine
173// it in a separate function to keep the normal case speedy.
174JSValue *jsNumberCell(double d)
175{
176 return new NumberImp(d);
177}
178
179} // namespace KJS
Note: See TracBrowser for help on using the repository browser.