1// -*- c-basic-offset: 2 -*-
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.
7 *
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.
12 *
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.
17 *
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.
22 *
23 */
24
25#ifndef INTERNAL_H
26#define INTERNAL_H
27
28#include "JSType.h"
29#include "interpreter.h"
30#include "object.h"
31#include "protect.h"
32#include "scope_chain.h"
33#include "types.h"
34#include "ustring.h"
35
36#include <wtf/Noncopyable.h>
37
38#ifndef I18N_NOOP
39#define I18N_NOOP(s) s
40#endif
41
42namespace KJS {
43
44
45 // ---------------------------------------------------------------------------
46 // Primitive impls
47 // ---------------------------------------------------------------------------
48
49 class StringImp : public JSCell {
50 public:
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; }
58
59 virtual JSType type() const { return StringType; }
60
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;
67
68 private:
69 UString val;
70 };
71
72 class NumberImp : public JSCell {
73 friend class ConstantValues;
74 friend KJS_EXPORT JSValue *jsNumberCell(double);
75 public:
76 double value() const { return val; }
77
78 JSType type() const { return NumberType; }
79
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;
86
87 private:
88 NumberImp(double v) : val(v) { }
89
90 virtual bool getUInt32(uint32_t&) const;
91 virtual bool getTruncatedInt32(int32_t&) const;
92 virtual bool getTruncatedUInt32(uint32_t&) const;
93
94 double val;
95 };
96
97 // ---------------------------------------------------------------------------
98 // Evaluation
99 // ---------------------------------------------------------------------------
100
101 struct AttachedInterpreter;
102 class DebuggerImp {
103 public:
104
105 DebuggerImp() {
106 interps = 0;
107 isAborted = false;
108 }
109
110 void abort() { isAborted = true; }
111 bool aborted() const { return isAborted; }
112
113 AttachedInterpreter *interps;
114 bool isAborted;
115 };
116
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)); }
120
121 int32_t toInt32(double dd);
122 uint32_t toUInt32(double dd);
123 uint16_t toUInt16(double dd);
124
125//#ifndef NDEBUG
126 void printInfo(ExecState *exec, const char *s, JSValue *, int lineno = -1);
127//#endif
128
129} // namespace
130
131#endif // INTERNAL_H
132