source: webkit/trunk/JavaScriptCore/kjs/context.h@ 14902

Last change on this file since 14902 was 14834, checked in by ggaren, 19 years ago

JavaScriptCore:

Reviewed by TimO, Maciej.


  • Merged InterpreterImp code into Interpreter, which implements all interpreter functionality now. This is part of my continuing quest to create an external notion of JS "execution context" that is unified and simple -- something to replace the mix of Context, ContextImp, ExecState, Interpreter, InterpreterImp, and JSRun.


All tests pass. Leaks test has not regressed from its baseline ~207 leaks
with ~3460 leaked nodes.

  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bindings/NP_jsobject.cpp:
  • bindings/objc/WebScriptObject.mm: (+[WebScriptObject throwException:]):
  • bindings/runtime_root.cpp:
  • bindings/runtime_root.h:
  • kjs/Context.cpp: (KJS::Context::Context):
  • kjs/ExecState.cpp: Added. (KJS::ExecState::lexicalInterpreter):
  • kjs/ExecState.h: Added. (KJS::ExecState::dynamicInterpreter):
  • kjs/SavedBuiltins.h: Added.
  • kjs/bool_object.cpp: (BooleanPrototype::BooleanPrototype):
  • kjs/collector.cpp: (KJS::Collector::collect): (KJS::Collector::numInterpreters):
  • kjs/context.h:
  • kjs/debugger.cpp: (Debugger::attach): (Debugger::detach):
  • kjs/function.cpp: (KJS::FunctionImp::callAsFunction): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/interpreter.cpp: (KJS::interpreterMap): (KJS::Interpreter::Interpreter): (KJS::Interpreter::init): (KJS::Interpreter::~Interpreter): (KJS::Interpreter::globalObject): (KJS::Interpreter::initGlobalObject): (KJS::Interpreter::globalExec): (KJS::Interpreter::checkSyntax): (KJS::Interpreter::evaluate): (KJS::Interpreter::builtinObject): (KJS::Interpreter::builtinFunction): (KJS::Interpreter::builtinArray): (KJS::Interpreter::builtinBoolean): (KJS::Interpreter::builtinString): (KJS::Interpreter::builtinNumber): (KJS::Interpreter::builtinDate): (KJS::Interpreter::builtinRegExp): (KJS::Interpreter::builtinError): (KJS::Interpreter::builtinObjectPrototype): (KJS::Interpreter::builtinFunctionPrototype): (KJS::Interpreter::builtinArrayPrototype): (KJS::Interpreter::builtinBooleanPrototype): (KJS::Interpreter::builtinStringPrototype): (KJS::Interpreter::builtinNumberPrototype): (KJS::Interpreter::builtinDatePrototype): (KJS::Interpreter::builtinRegExpPrototype): (KJS::Interpreter::builtinErrorPrototype): (KJS::Interpreter::builtinEvalError): (KJS::Interpreter::builtinRangeError): (KJS::Interpreter::builtinReferenceError): (KJS::Interpreter::builtinSyntaxError): (KJS::Interpreter::builtinTypeError): (KJS::Interpreter::builtinURIError): (KJS::Interpreter::builtinEvalErrorPrototype): (KJS::Interpreter::builtinRangeErrorPrototype): (KJS::Interpreter::builtinReferenceErrorPrototype): (KJS::Interpreter::builtinSyntaxErrorPrototype): (KJS::Interpreter::builtinTypeErrorPrototype): (KJS::Interpreter::builtinURIErrorPrototype): (KJS::Interpreter::mark): (KJS::Interpreter::interpreterWithGlobalObject): (KJS::Interpreter::saveBuiltins): (KJS::Interpreter::restoreBuiltins):
  • kjs/interpreter.h: (KJS::Interpreter::setCompatMode): (KJS::Interpreter::compatMode): (KJS::Interpreter::firstInterpreter): (KJS::Interpreter::nextInterpreter): (KJS::Interpreter::prevInterpreter): (KJS::Interpreter::debugger): (KJS::Interpreter::setDebugger): (KJS::Interpreter::setContext): (KJS::Interpreter::context):
  • kjs/nodes.cpp: (StatementNode::hitStatement): (RegExpNode::evaluate):
  • kjs/protect.h:

JavaScriptGlue:

Reviewed by TimO, Maciej.


  • JSGlue part of merging InterpreterImp into Interpreter.


Since there's now a kjs forwarding header, I moved all forwarding
headers into a "ForwardingHeaders" directory, like in WebCore.

  • ForwardingHeaders: Added.
  • ForwardingHeaders/kjs: Added.
  • ForwardingHeaders/kjs/ExecState.h: Added.
  • ForwardingHeaders/wtf: Added.
  • JavaScriptGlue.xcodeproj/project.pbxproj:
  • config.h:
  • wtf: Removed.
  • wtf/AlwaysInline.h: Removed.
  • wtf/Assertions.h: Removed.
  • wtf/FastMalloc.h: Removed.
  • wtf/Forward.h: Removed.
  • wtf/HashCountedSet.h: Removed.
  • wtf/HashSet.h: Removed.
  • wtf/Noncopyable.h: Removed.
  • wtf/OwnArrayPtr.h: Removed.
  • wtf/OwnPtr.h: Removed.
  • wtf/PassRefPtr.h: Removed.
  • wtf/Platform.h: Removed.
  • wtf/RefPtr.h: Removed.
  • wtf/Vector.h: Removed.

WebCore:

Reviewed by TimO, Maciej.

  • WebCore part of merging InterpreterImp into Interpreter. No test because there's no behavior change.


A substantive change here is that ScriptInterpreter::mark must now chain to
Interpreter::mark, since Interpreter needs to mark the things that
InterpreterImp used to mark.


  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/kjs_binding.cpp:
  • bindings/js/kjs_window.cpp: (KJS::Window::put):
  • bridge/mac/WebCoreFrameBridge.mm:
  • bridge/mac/WebCoreScriptDebugger.mm: (-[WebCoreScriptCallFrame evaluateWebScript:]):
  • kwq/KWQPageState.mm:
  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
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, 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 KJS_Context_h
26#define KJS_Context_h
27
28#include "function.h"
29
30namespace KJS {
31
32 /**
33 * @short Execution context.
34 *
35 * Represents an execution context, as specified by section 10 of the ECMA
36 * spec.
37 *
38 * An execution context contains information about the current state of the
39 * script - the scope for variable lookup, the value of "this", etc. A new
40 * execution context is entered whenever global code is executed (e.g. with
41 * Interpreter::evaluate()), a function is called (see
42 * Object::call()), or the builtin "eval" function is executed.
43 *
44 * Most inheritable functions in the KJS api take a ExecState pointer as
45 * their first parameter. This can be used to obtain a handle to the current
46 * execution context.
47 */
48 class Context {
49 public:
50 Context(JSObject* global, Interpreter*, JSObject* thisV,
51 FunctionBodyNode* currentBody, CodeType type = GlobalCode,
52 Context* callingContext = 0, FunctionImp* function = 0, const List* args = 0);
53 ~Context();
54
55 /**
56 * Returns the scope chain for this execution context. This is used for
57 * variable lookup, with the list being searched from start to end until a
58 * variable is found.
59 *
60 * @return The execution context's scope chain
61 */
62 const ScopeChain& scopeChain() const { return scope; }
63
64 /**
65 * Returns the variable object for the execution context. This contains a
66 * property for each variable declared in the execution context.
67 *
68 * @return The execution context's variable object
69 */
70 JSObject* variableObject() const { return m_variable; }
71 void setVariableObject(JSObject* v) { m_variable = v; }
72
73 /**
74 * Returns the "this" value for the execution context. This is the value
75 * returned when a script references the special variable "this". It should
76 * always be an Object, unless application-specific code has passed in a
77 * different type.
78 *
79 * The object that is used as the "this" value depends on the type of
80 * execution context - for global contexts, the global object is used. For
81 * function objewcts, the value is given by the caller (e.g. in the case of
82 * obj.func(), obj would be the "this" value). For code executed by the
83 * built-in "eval" function, the this value is the same as the calling
84 * context.
85 *
86 * @return The execution context's "this" value
87 */
88 JSObject* thisValue() const { return m_thisVal; }
89
90 /**
91 * Returns the context from which the current context was invoked. For
92 * global code this will be a null context (i.e. one for which
93 * isNull() returns true). You should check isNull() on the returned
94 * value before calling any of it's methods.
95 *
96 * @return The calling execution context
97 */
98 Context* callingContext() { return m_callingContext; }
99
100 JSObject* activationObject() { return m_activation; }
101 CodeType codeType() { return m_codeType; }
102 FunctionBodyNode* currentBody() { return m_currentBody; }
103 FunctionImp* function() const { return m_function; }
104 const List* arguments() const { return m_arguments; }
105
106 void pushScope(JSObject* s) { scope.push(s); }
107 void popScope() { scope.pop(); }
108 LabelStack* seenLabels() { return &ls; }
109
110 void pushIteration() { m_iterationDepth++; }
111 void popIteration() { m_iterationDepth--; }
112 bool inIteration() const { return (m_iterationDepth > 0); }
113
114 void pushSwitch() { m_switchDepth++; }
115 void popSwitch() { m_switchDepth--; }
116 bool inSwitch() const { return (m_switchDepth > 0); }
117
118 void mark();
119
120 private:
121 // Contexts are always stack-allocated, and the garbage collector
122 // marks the stack, so we don't need to protect the objects below from GC.
123
124 Interpreter* m_interpreter;
125 Context* m_callingContext;
126 FunctionBodyNode* m_currentBody;
127
128 FunctionImp* m_function;
129 const List* m_arguments;
130 JSObject* m_activation;
131
132 ScopeChain scope;
133 JSObject* m_variable;
134 JSObject* m_thisVal;
135
136 LabelStack ls;
137 int m_iterationDepth;
138 int m_switchDepth;
139 CodeType m_codeType;
140 };
141
142} // namespace KJS
143
144#endif
145
Note: See TracBrowser for help on using the repository browser.