1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
5 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
6 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
29 #include "interpreter.h"
32 #include "scope_chain.h"
36 #include <wtf/Noncopyable.h>
39 #define I18N_NOOP(s) s
45 // ---------------------------------------------------------------------------
47 // ---------------------------------------------------------------------------
49 class StringImp
: public JSCell
{
51 StringImp() : val(UString::empty
) { }
52 StringImp(const UString
& v
) : val(v
) { Collector::reportExtraMemoryCost(v
.cost()); }
53 enum HasOtherOwnerType
{ HasOtherOwner
}; // e.g. storage cost already accounted for
54 StringImp(const UString
& value
, HasOtherOwnerType
) : val(value
) { }
55 StringImp(const char* v
) : val(v
) { }
56 StringImp(const char* v
, int len
) : val(v
, len
) { }
57 const UString
& value() const { return val
; }
59 virtual JSType
type() const { return StringType
; }
61 virtual JSValue
*toPrimitive(ExecState
*exec
, JSType preferred
= UnspecifiedType
) const;
62 virtual bool getPrimitiveNumber(ExecState
*, double& number
, JSValue
*& value
);
63 virtual bool toBoolean(ExecState
*exec
) const;
64 virtual double toNumber(ExecState
*exec
) const;
65 virtual UString
toString(ExecState
*exec
) const;
66 virtual JSObject
*toObject(ExecState
*exec
) const;
72 class NumberImp
: public JSCell
{
73 friend class ConstantValues
;
74 friend KJS_EXPORT JSValue
*jsNumberCell(double);
76 double value() const { return val
; }
78 JSType
type() const { return NumberType
; }
80 JSValue
*toPrimitive(ExecState
*exec
, JSType preferred
= UnspecifiedType
) const;
81 virtual bool getPrimitiveNumber(ExecState
*, double& number
, JSValue
*& value
);
82 bool toBoolean(ExecState
*exec
) const;
83 double toNumber(ExecState
*exec
) const;
84 UString
toString(ExecState
*exec
) const;
85 JSObject
*toObject(ExecState
*exec
) const;
88 NumberImp(double v
) : val(v
) { }
90 virtual bool getUInt32(uint32_t&) const;
91 virtual bool getTruncatedInt32(int32_t&) const;
92 virtual bool getTruncatedUInt32(uint32_t&) const;
97 // ---------------------------------------------------------------------------
99 // ---------------------------------------------------------------------------
101 struct AttachedInterpreter
;
110 void abort() { isAborted
= true; }
111 bool aborted() const { return isAborted
; }
113 AttachedInterpreter
*interps
;
117 // helper function for toInteger, toInt32, toUInt32 and toUInt16
118 double roundValue(double d
);
119 inline double roundValue(ExecState
*e
, JSValue
*v
) { return roundValue(v
->toNumber(e
)); }
121 int32_t toInt32(double dd
);
122 uint32_t toUInt32(double dd
);
123 uint16_t toUInt16(double dd
);
126 void printInfo(ExecState
*exec
, const char *s
, JSValue
*, int lineno
= -1);