Commit fd7c1022 authored by ggaren's avatar ggaren

Reviewed by Eric (yay!).

        
        - Removed Context wrapper for ContextImp, renamed ContextImp to Context,
        split Context into its own file -- Context.cpp -- renamed _var to m_var,
        change ' *' to '* '.

        * JavaScriptCore.xcodeproj/project.pbxproj:
        * kjs/Context.cpp: Added.
        (KJS::Context::Context):
        (KJS::Context::~Context):
        (KJS::Context::mark):
        * kjs/context.h:
        (KJS::Context::scopeChain):
        (KJS::Context::variableObject):
        (KJS::Context::setVariableObject):
        (KJS::Context::thisValue):
        (KJS::Context::callingContext):
        (KJS::Context::activationObject):
        (KJS::Context::currentBody):
        (KJS::Context::function):
        (KJS::Context::arguments):
        (KJS::Context::pushScope):
        (KJS::Context::seenLabels):
        * kjs/function.cpp:
        (KJS::FunctionImp::callAsFunction):
        (KJS::FunctionImp::processParameters):
        (KJS::FunctionImp::argumentsGetter):
        (KJS::GlobalFuncImp::callAsFunction):
        * kjs/internal.cpp:
        (KJS::InterpreterImp::evaluate):
        * kjs/internal.h:
        (KJS::InterpreterImp::setContext):
        (KJS::InterpreterImp::context):
        * kjs/interpreter.cpp:
        * kjs/interpreter.h:
        (KJS::ExecState::context):
        (KJS::ExecState::ExecState):
        * kjs/nodes.cpp:
        (currentSourceId):
        (currentSourceURL):
        (ThisNode::evaluate):
        (ResolveNode::evaluate):
        (FunctionCallResolveNode::evaluate):
        (PostfixResolveNode::evaluate):
        (DeleteResolveNode::evaluate):
        (TypeOfResolveNode::evaluate):
        (PrefixResolveNode::evaluate):
        (AssignResolveNode::evaluate):
        (VarDeclNode::evaluate):
        (VarDeclNode::processVarDecls):
        (DoWhileNode::execute):
        (WhileNode::execute):
        (ForNode::execute):
        (ForInNode::execute):
        (ContinueNode::execute):
        (BreakNode::execute):
        (ReturnNode::execute):
        (WithNode::execute):
        (SwitchNode::execute):
        (LabelNode::execute):
        (TryNode::execute):
        (FuncDeclNode::processFuncDecl):
        (FuncExprNode::evaluate):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@14799 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5b8ad11c
2006-06-09 Geoffrey Garen <ggaren@apple.com>
Reviewed by Eric (yay!).
- Removed Context wrapper for ContextImp, renamed ContextImp to Context,
split Context into its own file -- Context.cpp -- renamed _var to m_var,
change ' *' to '* '.
* JavaScriptCore.xcodeproj/project.pbxproj:
* kjs/Context.cpp: Added.
(KJS::Context::Context):
(KJS::Context::~Context):
(KJS::Context::mark):
* kjs/context.h:
(KJS::Context::scopeChain):
(KJS::Context::variableObject):
(KJS::Context::setVariableObject):
(KJS::Context::thisValue):
(KJS::Context::callingContext):
(KJS::Context::activationObject):
(KJS::Context::currentBody):
(KJS::Context::function):
(KJS::Context::arguments):
(KJS::Context::pushScope):
(KJS::Context::seenLabels):
* kjs/function.cpp:
(KJS::FunctionImp::callAsFunction):
(KJS::FunctionImp::processParameters):
(KJS::FunctionImp::argumentsGetter):
(KJS::GlobalFuncImp::callAsFunction):
* kjs/internal.cpp:
(KJS::InterpreterImp::evaluate):
* kjs/internal.h:
(KJS::InterpreterImp::setContext):
(KJS::InterpreterImp::context):
* kjs/interpreter.cpp:
* kjs/interpreter.h:
(KJS::ExecState::context):
(KJS::ExecState::ExecState):
* kjs/nodes.cpp:
(currentSourceId):
(currentSourceURL):
(ThisNode::evaluate):
(ResolveNode::evaluate):
(FunctionCallResolveNode::evaluate):
(PostfixResolveNode::evaluate):
(DeleteResolveNode::evaluate):
(TypeOfResolveNode::evaluate):
(PrefixResolveNode::evaluate):
(AssignResolveNode::evaluate):
(VarDeclNode::evaluate):
(VarDeclNode::processVarDecls):
(DoWhileNode::execute):
(WhileNode::execute):
(ForNode::execute):
(ForInNode::execute):
(ContinueNode::execute):
(BreakNode::execute):
(ReturnNode::execute):
(WithNode::execute):
(SwitchNode::execute):
(LabelNode::execute):
(TryNode::execute):
(FuncDeclNode::processFuncDecl):
(FuncExprNode::evaluate):
2006-06-07 Geoffrey Garen <ggaren@apple.com>
Removed API directory I prematurely/accidentally added.
......
......@@ -204,6 +204,10 @@
RelativePath="..\..\kjs\config.h"
>
</File>
<File
RelativePath="..\..\kjs\Context.cpp"
>
</File>
<File
RelativePath="..\..\kjs\context.h"
>
......
......@@ -36,6 +36,8 @@
148A1627095D16BB00666D0D /* ListRefPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 148A1626095D16BB00666D0D /* ListRefPtr.h */; };
14ABB36F099C076400E2A24F /* value.h in Headers */ = {isa = PBXBuildFile; fileRef = 14ABB36E099C076400E2A24F /* value.h */; settings = {ATTRIBUTES = (Private, ); }; };
14ABB455099C2A0F00E2A24F /* JSType.h in Headers */ = {isa = PBXBuildFile; fileRef = 14ABB454099C2A0F00E2A24F /* JSType.h */; settings = {ATTRIBUTES = (Private, ); }; };
14F137590A3A727E00F26F90 /* Context.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14F137580A3A727E00F26F90 /* Context.cpp */; };
14F137830A3A765B00F26F90 /* context.h in Headers */ = {isa = PBXBuildFile; fileRef = 14F137820A3A765B00F26F90 /* context.h */; };
652C107F08DA7B1E0020887D /* protected_reference.h in Headers */ = {isa = PBXBuildFile; fileRef = 652C107E08DA7B1E0020887D /* protected_reference.h */; };
6541BD7208E80A17002CBEE7 /* TCPageMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 6541BD6E08E80A17002CBEE7 /* TCPageMap.h */; };
6541BD7308E80A17002CBEE7 /* TCSpinLock.h in Headers */ = {isa = PBXBuildFile; fileRef = 6541BD6F08E80A17002CBEE7 /* TCSpinLock.h */; };
......@@ -110,7 +112,6 @@
932F5B660822A1C700736975 /* identifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 933A349A038AE7C6008635CE /* identifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
932F5B670822A1C700736975 /* array_instance.h in Headers */ = {isa = PBXBuildFile; fileRef = 938772E5038BFE19008635CE /* array_instance.h */; settings = {ATTRIBUTES = (Private, ); }; };
932F5B680822A1C700736975 /* scope_chain.h in Headers */ = {isa = PBXBuildFile; fileRef = 9374D3A7038D9D74008635CE /* scope_chain.h */; settings = {ATTRIBUTES = (Private, ); }; };
932F5B690822A1C700736975 /* context.h in Headers */ = {isa = PBXBuildFile; fileRef = 9373524E038DA8C2008635CE /* context.h */; settings = {ATTRIBUTES = (Private, ); }; };
932F5B6A0822A1C700736975 /* list.h in Headers */ = {isa = PBXBuildFile; fileRef = 931C6CEF038EE8DE008635CE /* list.h */; settings = {ATTRIBUTES = (Private, ); }; };
932F5B6B0822A1C700736975 /* dtoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 651F6413039D5B5F0078395C /* dtoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
932F5B6C0822A1C700736975 /* pcre.h in Headers */ = {isa = PBXBuildFile; fileRef = 6541720F039E08B90058BFEB /* pcre.h */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -266,6 +267,8 @@
148A1626095D16BB00666D0D /* ListRefPtr.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ListRefPtr.h; sourceTree = "<group>"; };
14ABB36E099C076400E2A24F /* value.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = value.h; sourceTree = "<group>"; };
14ABB454099C2A0F00E2A24F /* JSType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSType.h; sourceTree = "<group>"; };
14F137580A3A727E00F26F90 /* Context.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Context.cpp; sourceTree = "<group>"; };
14F137820A3A765B00F26F90 /* context.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = context.h; sourceTree = "<group>"; };
45E12D8806A49B0F00E9DF84 /* testkjs.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; path = testkjs.cpp; sourceTree = "<group>"; tabWidth = 8; };
5114F47B05E4426200D1BBBD /* runtime_root.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; name = runtime_root.cpp; path = bindings/runtime_root.cpp; sourceTree = "<group>"; tabWidth = 8; };
5114F47C05E4426200D1BBBD /* runtime_root.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; name = runtime_root.h; path = bindings/runtime_root.h; sourceTree = "<group>"; tabWidth = 8; };
......@@ -384,7 +387,6 @@
935AF46B09E9D9DB00ACD1D8 /* UnusedParam.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnusedParam.h; sourceTree = "<group>"; };
935F69F608244FEA003D1A45 /* dftables */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = dftables; sourceTree = BUILT_PRODUCTS_DIR; };
9364B273045B7D6C00A9CAC1 /* fpconst.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fpconst.cpp; sourceTree = "<group>"; tabWidth = 8; };
9373524E038DA8C2008635CE /* context.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = context.h; sourceTree = "<group>"; tabWidth = 8; };
9374D3A7038D9D74008635CE /* scope_chain.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = scope_chain.h; sourceTree = "<group>"; tabWidth = 8; };
9374D3A8038D9D74008635CE /* scope_chain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scope_chain.cpp; sourceTree = "<group>"; tabWidth = 8; };
937B63CC09E766D200A671DD /* DerivedSources.make */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = DerivedSources.make; sourceTree = "<group>"; usesTabs = 1; };
......@@ -659,7 +661,8 @@
F692A8530255597D01FF60F7 /* collector.h */,
F5BB2BC5030F772101FCFE1D /* completion.h */,
F68EBB8C0255D4C601FF60F7 /* config.h */,
9373524E038DA8C2008635CE /* context.h */,
14F137580A3A727E00F26F90 /* Context.cpp */,
14F137820A3A765B00F26F90 /* context.h */,
F692A8540255597D01FF60F7 /* create_hash_table */,
F692A8550255597D01FF60F7 /* date_object.cpp */,
F692A8560255597D01FF60F7 /* date_object.h */,
......@@ -834,7 +837,6 @@
932F5B660822A1C700736975 /* identifier.h in Headers */,
932F5B670822A1C700736975 /* array_instance.h in Headers */,
932F5B680822A1C700736975 /* scope_chain.h in Headers */,
932F5B690822A1C700736975 /* context.h in Headers */,
932F5B6A0822A1C700736975 /* list.h in Headers */,
932F5B6B0822A1C700736975 /* dtoa.h in Headers */,
932F5B6C0822A1C700736975 /* pcre.h in Headers */,
......@@ -916,6 +918,7 @@
935AF46C09E9D9DB00ACD1D8 /* Forward.h in Headers */,
935AF46E09E9D9DB00ACD1D8 /* UnusedParam.h in Headers */,
BCF655590A2049710038A194 /* MathExtras.h in Headers */,
14F137830A3A765B00F26F90 /* context.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -1107,6 +1110,7 @@
14760864099C633800437128 /* JSImmediate.cpp in Sources */,
93F0B3AB09BB4DC00068FCE3 /* Parser.cpp in Sources */,
65FB3F5009D11B2400F49DEB /* grammar.cpp in Sources */,
14F137590A3A727E00F26F90 /* Context.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
// -*- c-basic-offset: 2 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2003, 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "context.h"
namespace KJS {
// ECMA 10.2
Context::Context(JSObject* glob, InterpreterImp* interpreter, JSObject* thisV,
FunctionBodyNode* currentBody, CodeType type, Context* callingCon,
FunctionImp* func, const List* args)
: m_interpreter(interpreter)
, m_currentBody(currentBody)
, m_function(func)
, m_arguments(args)
, m_iterationDepth(0)
, m_switchDepth(0)
{
m_codeType = type;
m_callingContext = callingCon;
// create and initialize activation object (ECMA 10.1.6)
if (type == FunctionCode || type == AnonymousCode ) {
m_activation = new ActivationImp(func, *args);
m_variable = m_activation;
} else {
m_activation = 0;
m_variable = glob;
}
// ECMA 10.2
switch(type) {
case EvalCode:
if (m_callingContext) {
scope = m_callingContext->scopeChain();
m_variable = m_callingContext->variableObject();
m_thisVal = m_callingContext->thisValue();
break;
} // else same as GlobalCode
case GlobalCode:
scope.clear();
scope.push(glob);
m_thisVal = static_cast<JSObject*>(glob);
break;
case FunctionCode:
case AnonymousCode:
if (type == FunctionCode) {
scope = func->scope();
scope.push(m_activation);
} else {
scope.clear();
scope.push(glob);
scope.push(m_activation);
}
m_variable = m_activation; // TODO: DontDelete ? (ECMA 10.2.3)
m_thisVal = thisV;
break;
}
m_interpreter->setContext(this);
}
Context::~Context()
{
m_interpreter->setContext(m_callingContext);
}
void Context::mark()
{
for (Context* context = this; context; context = context->m_callingContext)
context->scope.mark();
}
} // namespace KJS
......@@ -3,7 +3,7 @@
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2003 Apple Computer, Inc.
* Copyright (C) 2003, 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -22,38 +22,90 @@
*
*/
#ifndef KJS_CONTEXT_H
#define KJS_CONTEXT_H
#ifndef KJS_Context_h
#define KJS_Context_h
#include "function.h"
namespace KJS {
/**
/**
* @short Execution context.
*/
class ContextImp {
*
* Represents an execution context, as specified by section 10 of the ECMA
* spec.
*
* An execution context contains information about the current state of the
* script - the scope for variable lookup, the value of "this", etc. A new
* execution context is entered whenever global code is executed (e.g. with
* Interpreter::evaluate()), a function is called (see
* Object::call()), or the builtin "eval" function is executed.
*
* Most inheritable functions in the KJS api take a ExecState pointer as
* their first parameter. This can be used to obtain a handle to the current
* execution context.
*/
class Context {
public:
ContextImp(JSObject* global, InterpreterImp*, JSObject* thisV, FunctionBodyNode* currentBody,
CodeType type = GlobalCode, ContextImp* callingContext = 0, FunctionImp* function = 0, const List* args = 0);
~ContextImp();
Context(JSObject* global, InterpreterImp*, JSObject* thisV,
FunctionBodyNode* currentBody, CodeType type = GlobalCode,
Context* callingContext = 0, FunctionImp* function = 0, const List* args = 0);
~Context();
FunctionBodyNode* currentBody() { return m_currentBody; }
/**
* Returns the scope chain for this execution context. This is used for
* variable lookup, with the list being searched from start to end until a
* variable is found.
*
* @return The execution context's scope chain
*/
const ScopeChain& scopeChain() const { return scope; }
/**
* Returns the variable object for the execution context. This contains a
* property for each variable declared in the execution context.
*
* @return The execution context's variable object
*/
JSObject* variableObject() const { return m_variable; }
void setVariableObject(JSObject* v) { m_variable = v; }
const ScopeChain &scopeChain() const { return scope; }
/**
* Returns the "this" value for the execution context. This is the value
* returned when a script references the special variable "this". It should
* always be an Object, unless application-specific code has passed in a
* different type.
*
* The object that is used as the "this" value depends on the type of
* execution context - for global contexts, the global object is used. For
* function objewcts, the value is given by the caller (e.g. in the case of
* obj.func(), obj would be the "this" value). For code executed by the
* built-in "eval" function, the this value is the same as the calling
* context.
*
* @return The execution context's "this" value
*/
JSObject* thisValue() const { return m_thisVal; }
/**
* Returns the context from which the current context was invoked. For
* global code this will be a null context (i.e. one for which
* isNull() returns true). You should check isNull() on the returned
* value before calling any of it's methods.
*
* @return The calling execution context
*/
Context* callingContext() { return m_callingContext; }
JSObject* activationObject() { return m_activation; }
CodeType codeType() { return m_codeType; }
JSObject *variableObject() const { return variable; }
void setVariableObject(JSObject *v) { variable = v; }
JSObject *thisValue() const { return thisVal; }
ContextImp *callingContext() { return _callingContext; }
JSObject *activationObject() { return activation; }
FunctionImp *function() const { return _function; }
const List *arguments() const { return _arguments; }
void pushScope(JSObject *s) { scope.push(s); }
void popScope() { scope.pop(); }
LabelStack *seenLabels() { return &ls; }
FunctionBodyNode* currentBody() { return m_currentBody; }
FunctionImp* function() const { return m_function; }
const List* arguments() const { return m_arguments; }
void pushScope(JSObject* s) { scope.push(s); }
void popScope() { scope.pop(); }
LabelStack* seenLabels() { return &ls; }
void pushIteration() { m_iterationDepth++; }
void popIteration() { m_iterationDepth--; }
......@@ -66,20 +118,20 @@ namespace KJS {
void mark();
private:
InterpreterImp *_interpreter;
ContextImp *_callingContext;
// Contexts are always stack-allocated, and the garbage collector
// marks the stack, so we don't need to protect the objects below from GC.
InterpreterImp* m_interpreter;
Context* m_callingContext;
FunctionBodyNode* m_currentBody;
FunctionImp *_function;
const List *_arguments;
// because ContextImp is always allocated on the stack,
// there is no need to protect various pointers from conservative
// GC since they will be caught by the conservative sweep anyway!
JSObject *activation;
FunctionImp* m_function;
const List* m_arguments;
JSObject* m_activation;
ScopeChain scope;
JSObject *variable;
JSObject *thisVal;
JSObject* m_variable;
JSObject* m_thisVal;
LabelStack ls;
int m_iterationDepth;
......
......@@ -71,8 +71,8 @@ JSValue *FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const L
JSObject *globalObj = exec->dynamicInterpreter()->globalObject();
// enter a new execution context
ContextImp ctx(globalObj, exec->dynamicInterpreter()->imp(), thisObj, body.get(),
codeType(), exec->context().imp(), this, &args);
Context ctx(globalObj, exec->dynamicInterpreter()->imp(), thisObj, body.get(),
codeType(), exec->context(), this, &args);
ExecState newExec(exec->dynamicInterpreter(), &ctx);
newExec.setException(exec->exception()); // could be null
......@@ -163,7 +163,7 @@ UString FunctionImp::parameterString() const
// ECMA 10.1.3q
void FunctionImp::processParameters(ExecState *exec, const List &args)
{
JSObject *variable = exec->context().imp()->variableObject();
JSObject* variable = exec->context()->variableObject();
#ifdef KJS_VERBOSE
fprintf(stderr, "---------------------------------------------------\n"
......@@ -203,7 +203,7 @@ void FunctionImp::processVarDecls(ExecState */*exec*/)
JSValue *FunctionImp::argumentsGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
{
FunctionImp *thisObj = static_cast<FunctionImp *>(slot.slotBase());
ContextImp *context = exec->m_context;
Context *context = exec->m_context;
while (context) {
if (context->function() == thisObj) {
return static_cast<ActivationImp *>(context->activationObject())->get(exec, propertyName);
......@@ -799,13 +799,13 @@ JSValue *GlobalFuncImp::callAsFunction(ExecState *exec, JSObject */*thisObj*/, c
return throwError(exec, SyntaxError, errMsg, errLine, sid, NULL);
// enter a new execution context
JSObject *thisVal = static_cast<JSObject *>(exec->context().thisValue());
ContextImp ctx(exec->dynamicInterpreter()->globalObject(),
JSObject *thisVal = static_cast<JSObject *>(exec->context()->thisValue());
Context ctx(exec->dynamicInterpreter()->globalObject(),
exec->dynamicInterpreter()->imp(),
thisVal,
progNode.get(),
EvalCode,
exec->context().imp());
exec->context());
ExecState newExec(exec->dynamicInterpreter(), &ctx);
newExec.setException(exec->exception()); // could be null
......
......@@ -187,75 +187,6 @@ bool LabelStack::contains(const Identifier &id) const
return false;
}
// ------------------------------ ContextImp -----------------------------------
// ECMA 10.2
ContextImp::ContextImp(JSObject *glob, InterpreterImp *interpreter, JSObject *thisV, FunctionBodyNode* currentBody,
CodeType type, ContextImp *callingCon, FunctionImp *func, const List *args)
: _interpreter(interpreter)
, m_currentBody(currentBody)
, _function(func)
, _arguments(args)
, m_iterationDepth(0)
, m_switchDepth(0)
{
m_codeType = type;
_callingContext = callingCon;
// create and initialize activation object (ECMA 10.1.6)
if (type == FunctionCode || type == AnonymousCode ) {
activation = new ActivationImp(func, *args);
variable = activation;
} else {
activation = NULL;
variable = glob;
}
// ECMA 10.2
switch(type) {
case EvalCode:
if (_callingContext) {
scope = _callingContext->scopeChain();
variable = _callingContext->variableObject();
thisVal = _callingContext->thisValue();
break;
} // else same as GlobalCode
case GlobalCode:
scope.clear();
scope.push(glob);
thisVal = static_cast<JSObject*>(glob);
break;
case FunctionCode:
case AnonymousCode:
if (type == FunctionCode) {
scope = func->scope();
scope.push(activation);
} else {
scope.clear();
scope.push(glob);
scope.push(activation);
}
variable = activation; // TODO: DontDelete ? (ECMA 10.2.3)
thisVal = thisV;
break;
}
_interpreter->setContext(this);
}
ContextImp::~ContextImp()
{
_interpreter->setContext(_callingContext);
}
void ContextImp::mark()
{
for (ContextImp *context = this; context; context = context->_callingContext) {
context->scope.mark();
}
}
// ------------------------------ InterpreterImp -------------------------------
InterpreterImp* InterpreterImp::s_hook = 0L;
......@@ -508,7 +439,7 @@ Completion InterpreterImp::evaluate(const UChar* code, int codeLength, JSValue*
res = Completion(Throw, globExec.exception());
else {
// execute the code
ContextImp ctx(globalObj, this, thisObj, progNode.get());
Context ctx(globalObj, this, thisObj, progNode.get());
ExecState newExec(m_interpreter, &ctx);
progNode->processVarDecls(&newExec);
res = progNode->execute(&newExec);
......
......@@ -232,8 +232,8 @@ namespace KJS {
static InterpreterImp *interpreterWithGlobalObject(JSObject *);
void setContext(ContextImp *c) { _context = c; }
ContextImp *context() const { return _context; }
void setContext(Context *c) { _context = c; }
Context *context() const { return _context; }
void saveBuiltins (SavedBuiltins &builtins) const;
void restoreBuiltins (const SavedBuiltins &builtins);
......@@ -289,7 +289,7 @@ namespace KJS {
static InterpreterImp* s_hook;
InterpreterImp *next, *prev;
ContextImp *_context;
Context *_context;
int recursion;
};
......
......@@ -45,28 +45,6 @@
namespace KJS {
// ------------------------------ Context --------------------------------------
const ScopeChain &Context::scopeChain() const
{
return rep->scopeChain();
}
JSObject *Context::variableObject() const
{
return rep->variableObject();
}
JSObject *Context::thisValue() const
{
return rep->thisValue();
}
const Context Context::callingContext() const
{
return rep->callingContext();
}
// ------------------------------ Interpreter ----------------------------------
Interpreter::Interpreter(JSObject *global)
......
......@@ -29,7 +29,7 @@
namespace KJS {
class ContextImp;
class Context;
class InterpreterImp;
class RuntimeMethod;
class ScopeChain;
......@@ -38,84 +38,6 @@ namespace KJS {
class RootObject;
}
/**
* Represents an execution context, as specified by section 10 of the ECMA
* spec.
*
* An execution context contains information about the current state of the
* script - the scope for variable lookup, the value of "this", etc. A new
* execution context is entered whenever global code is executed (e.g. with
* Interpreter::evaluate()), a function is called (see
* Object::call()), or the builtin "eval" function is executed.
*
* Most inheritable functions in the KJS api take a ExecState pointer as
* their first parameter. This can be used to obtain a handle to the current
* execution context.
*
* Note: Context objects are wrapper classes/smart pointers for the internal
* KJS ContextImp type. When one context variable is assigned to another, it
* is still referencing the same internal object.
*/
class Context {
public:
Context(ContextImp *i) : rep(i) { }
ContextImp *imp() const { return rep; }
/**
* Returns the scope chain for this execution context. This is used for
* variable lookup, with the list being searched from start to end until a
* variable is found.
*
* @return The execution context's scope chain
*/
const ScopeChain &scopeChain() const;
/**