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 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 KJS_CONTEXT_H
|
---|
26 | #define KJS_CONTEXT_H
|
---|
27 |
|
---|
28 | #include "function.h"
|
---|
29 |
|
---|
30 | namespace KJS {
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * @short Execution context.
|
---|
34 | */
|
---|
35 | class ContextImp {
|
---|
36 | public:
|
---|
37 | ContextImp(JSObject* global, InterpreterImp*, JSObject* thisV, FunctionBodyNode* currentBody,
|
---|
38 | CodeType type = GlobalCode, ContextImp* callingContext = 0, FunctionImp* function = 0, const List* args = 0);
|
---|
39 | ~ContextImp();
|
---|
40 |
|
---|
41 | FunctionBodyNode* currentBody() { return m_currentBody; }
|
---|
42 |
|
---|
43 | const ScopeChain &scopeChain() const { return scope; }
|
---|
44 | CodeType codeType() { return m_codeType; }
|
---|
45 | JSObject *variableObject() const { return variable; }
|
---|
46 | void setVariableObject(JSObject *v) { variable = v; }
|
---|
47 | JSObject *thisValue() const { return thisVal; }
|
---|
48 | ContextImp *callingContext() { return _callingContext; }
|
---|
49 | JSObject *activationObject() { return activation; }
|
---|
50 | FunctionImp *function() const { return _function; }
|
---|
51 | const List *arguments() const { return _arguments; }
|
---|
52 |
|
---|
53 | void pushScope(JSObject *s) { scope.push(s); }
|
---|
54 | void popScope() { scope.pop(); }
|
---|
55 | LabelStack *seenLabels() { return &ls; }
|
---|
56 |
|
---|
57 |
|
---|
58 | void pushIteration() { m_iterationDepth++; }
|
---|
59 | void popIteration() { m_iterationDepth--; }
|
---|
60 | bool inIteration() const { return (m_iterationDepth > 0); }
|
---|
61 |
|
---|
62 | void pushSwitch() { m_switchDepth++; }
|
---|
63 | void popSwitch() { m_switchDepth--; }
|
---|
64 | bool inSwitch() const { return (m_switchDepth > 0); }
|
---|
65 |
|
---|
66 | void mark();
|
---|
67 |
|
---|
68 | private:
|
---|
69 | InterpreterImp *_interpreter;
|
---|
70 | ContextImp *_callingContext;
|
---|
71 | FunctionBodyNode* m_currentBody;
|
---|
72 |
|
---|
73 | FunctionImp *_function;
|
---|
74 | const List *_arguments;
|
---|
75 | // because ContextImp is always allocated on the stack,
|
---|
76 | // there is no need to protect various pointers from conservative
|
---|
77 | // GC since they will be caught by the conservative sweep anyway!
|
---|
78 | JSObject *activation;
|
---|
79 |
|
---|
80 | ScopeChain scope;
|
---|
81 | JSObject *variable;
|
---|
82 | JSObject *thisVal;
|
---|
83 |
|
---|
84 | LabelStack ls;
|
---|
85 | int m_iterationDepth;
|
---|
86 | int m_switchDepth;
|
---|
87 | CodeType m_codeType;
|
---|
88 | };
|
---|
89 |
|
---|
90 | } // namespace KJS
|
---|
91 |
|
---|
92 | #endif
|
---|