1 | // -*- c-basic-offset: 2 -*-
|
---|
2 | /*
|
---|
3 | * This file is part of the KDE libraries
|
---|
4 | * Copyright (C) 1999-2001 Harri Porten ([email protected])
|
---|
5 | * Copyright (C) 2001 Peter Kelly ([email protected])
|
---|
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 | #define I18N_NOOP(s) s
|
---|
39 |
|
---|
40 | namespace KJS {
|
---|
41 |
|
---|
42 | class FunctionPrototype;
|
---|
43 |
|
---|
44 | // ---------------------------------------------------------------------------
|
---|
45 | // Primitive impls
|
---|
46 | // ---------------------------------------------------------------------------
|
---|
47 |
|
---|
48 | class StringImp : public JSCell {
|
---|
49 | public:
|
---|
50 | StringImp(const UString& v) : val(v) { Collector::reportExtraMemoryCost(v.cost()); }
|
---|
51 | enum HasOtherOwnerType { HasOtherOwner };
|
---|
52 | StringImp(const UString& value, HasOtherOwnerType) : val(value) { }
|
---|
53 | UString value() const { return val; }
|
---|
54 |
|
---|
55 | JSType type() const { return StringType; }
|
---|
56 |
|
---|
57 | JSValue *toPrimitive(ExecState *exec, JSType preferred = UnspecifiedType) const;
|
---|
58 | bool toBoolean(ExecState *exec) const;
|
---|
59 | double toNumber(ExecState *exec) const;
|
---|
60 | UString toString(ExecState *exec) const;
|
---|
61 | JSObject *toObject(ExecState *exec) const;
|
---|
62 |
|
---|
63 | private:
|
---|
64 | UString val;
|
---|
65 | };
|
---|
66 |
|
---|
67 | class NumberImp : public JSCell {
|
---|
68 | friend class ConstantValues;
|
---|
69 | friend JSValue *jsNumberCell(double);
|
---|
70 | public:
|
---|
71 | double value() const { return val; }
|
---|
72 |
|
---|
73 | JSType type() const { return NumberType; }
|
---|
74 |
|
---|
75 | JSValue *toPrimitive(ExecState *exec, JSType preferred = UnspecifiedType) const;
|
---|
76 | bool toBoolean(ExecState *exec) const;
|
---|
77 | double toNumber(ExecState *exec) const;
|
---|
78 | UString toString(ExecState *exec) const;
|
---|
79 | JSObject *toObject(ExecState *exec) const;
|
---|
80 |
|
---|
81 | private:
|
---|
82 | NumberImp(double v) : val(v) { }
|
---|
83 |
|
---|
84 | virtual bool getUInt32(uint32_t&) const;
|
---|
85 |
|
---|
86 | double val;
|
---|
87 | };
|
---|
88 |
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * @short The "label set" in Ecma-262 spec
|
---|
92 | */
|
---|
93 | class LabelStack : Noncopyable {
|
---|
94 | public:
|
---|
95 | LabelStack()
|
---|
96 | : tos(0)
|
---|
97 | {
|
---|
98 | }
|
---|
99 | ~LabelStack();
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * If id is not empty and is not in the stack already, puts it on top of
|
---|
103 | * the stack and returns true, otherwise returns false
|
---|
104 | */
|
---|
105 | bool push(const Identifier &id);
|
---|
106 | /**
|
---|
107 | * Is the id in the stack?
|
---|
108 | */
|
---|
109 | bool contains(const Identifier &id) const;
|
---|
110 | /**
|
---|
111 | * Removes from the stack the last pushed id (what else?)
|
---|
112 | */
|
---|
113 | void pop();
|
---|
114 |
|
---|
115 | private:
|
---|
116 | struct StackElem {
|
---|
117 | Identifier id;
|
---|
118 | StackElem *prev;
|
---|
119 | };
|
---|
120 |
|
---|
121 | StackElem *tos;
|
---|
122 | };
|
---|
123 |
|
---|
124 |
|
---|
125 | // ---------------------------------------------------------------------------
|
---|
126 | // Evaluation
|
---|
127 | // ---------------------------------------------------------------------------
|
---|
128 |
|
---|
129 | struct AttachedInterpreter;
|
---|
130 | class DebuggerImp {
|
---|
131 | public:
|
---|
132 |
|
---|
133 | DebuggerImp() {
|
---|
134 | interps = 0;
|
---|
135 | isAborted = false;
|
---|
136 | }
|
---|
137 |
|
---|
138 | void abort() { isAborted = true; }
|
---|
139 | bool aborted() const { return isAborted; }
|
---|
140 |
|
---|
141 | AttachedInterpreter *interps;
|
---|
142 | bool isAborted;
|
---|
143 | };
|
---|
144 |
|
---|
145 | // helper function for toInteger, toInt32, toUInt32 and toUInt16
|
---|
146 | double roundValue(ExecState *, JSValue *);
|
---|
147 |
|
---|
148 | #ifndef NDEBUG
|
---|
149 | void printInfo(ExecState *exec, const char *s, JSValue *, int lineno = -1);
|
---|
150 | #endif
|
---|
151 |
|
---|
152 | inline LabelStack::~LabelStack()
|
---|
153 | {
|
---|
154 | StackElem *prev;
|
---|
155 | for (StackElem *e = tos; e; e = prev) {
|
---|
156 | prev = e->prev;
|
---|
157 | delete e;
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | inline void LabelStack::pop()
|
---|
162 | {
|
---|
163 | if (StackElem *e = tos) {
|
---|
164 | tos = e->prev;
|
---|
165 | delete e;
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | } // namespace
|
---|
170 |
|
---|
171 | #endif // INTERNAL_H
|
---|