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:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@14834 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/kjs/interpreter.h b/JavaScriptCore/kjs/interpreter.h
index defb1d6..32f9760 100644
--- a/JavaScriptCore/kjs/interpreter.h
+++ b/JavaScriptCore/kjs/interpreter.h
@@ -24,31 +24,23 @@
#ifndef _KJS_INTERPRETER_H_
#define _KJS_INTERPRETER_H_
+#include "ExecState.h"
+#include "protect.h"
#include "value.h"
#include "types.h"
namespace KJS {
class Context;
- class InterpreterImp;
+ class Debugger;
class RuntimeMethod;
+ class SavedBuiltins;
class ScopeChain;
namespace Bindings {
class RootObject;
}
- class SavedBuiltinsInternal;
-
- class SavedBuiltins {
- friend class InterpreterImp;
- public:
- SavedBuiltins();
- ~SavedBuiltins();
- private:
- SavedBuiltinsInternal *_internal;
- };
-
/**
* Interpreter objects can be used to evaluate ECMAScript code. Each
* interpreter has a global object which is used for the purposes of code
@@ -56,6 +48,7 @@
* " Object" and "Number".
*/
class Interpreter {
+ friend class Collector;
public:
/**
* Creates a new interpreter. The supplied object will be used as the global
@@ -73,7 +66,7 @@
*
* @param global The object to use as the global object for this interpreter
*/
- Interpreter(JSObject *global);
+ Interpreter(JSObject* globalObject);
/**
* Creates a new interpreter. A global object will be created and
* initialized with the standard global properties.
@@ -85,8 +78,7 @@
* Returns the object that is used as the global object during all script
* execution performed by this interpreter
*/
- JSObject *globalObject() const;
-
+ JSObject* globalObject() const;
void initGlobalObject();
/**
@@ -129,14 +121,6 @@
Completion evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV = 0);
/**
- * @internal
- *
- * Returns the implementation object associated with this interpreter.
- * Only useful for internal KJS operations.
- */
- InterpreterImp *imp() const { return rep; }
-
- /**
* Returns the builtin "Object" object. This is the object that was set
* as a property of the global object during construction; if the property
* is replaced by script code, this method will still return the original
@@ -255,9 +239,9 @@
* Currently, in KJS, this only changes the behavior of Date::getYear()
* which returns the full year under IE.
*/
- void setCompatMode(CompatMode mode);
- CompatMode compatMode() const;
-
+ void setCompatMode(CompatMode mode) { m_compatMode = mode; }
+ CompatMode compatMode() const { return m_compatMode; }
+
/**
* Run the garbage collection. Returns true when at least one object
* was collected; false otherwise.
@@ -265,8 +249,8 @@
static bool collect();
/**
- * Called by InterpreterImp during the mark phase of the garbage collector
- * Default implementation does nothing, this exist for classes that reimplement Interpreter.
+ * Called during the mark phase of the garbage collector. Subclasses
+ * implementing custom mark methods must make sure to chain to this one.
*/
virtual void mark(bool currentThreadIsMainThread);
@@ -288,8 +272,8 @@
static bool shouldPrintExceptions();
static void setShouldPrintExceptions(bool);
- void saveBuiltins (SavedBuiltins &) const;
- void restoreBuiltins (const SavedBuiltins &);
+ void saveBuiltins (SavedBuiltins&) const;
+ void restoreBuiltins (const SavedBuiltins&);
/**
* Determine if the value is a global object (for any interpreter). This may
@@ -326,75 +310,84 @@
const Identifier& argumentsIdentifier() { return *m_argumentsPropertyName; }
const Identifier& specialPrototypeIdentifier() { return *m_specialPrototypePropertyName; }
- private:
- InterpreterImp *rep;
+ // Chained list of interpreters (ring)
+ static Interpreter* firstInterpreter() { return s_hook; }
+ Interpreter* nextInterpreter() const { return next; }
+ Interpreter* prevInterpreter() const { return prev; }
- const Identifier *m_argumentsPropertyName;
- const Identifier *m_specialPrototypePropertyName;
-
+ Debugger* debugger() const { return m_debugger; }
+ void setDebugger(Debugger* d) { m_debugger = d; }
+
+ void setContext(Context* c) { m_context = c; }
+ Context* context() const { return m_context; }
+
+ static Interpreter* interpreterWithGlobalObject(JSObject*);
+private:
+ void init();
+
/**
* This constructor is not implemented, in order to prevent
* copy-construction of Interpreter objects. You should always pass around
* pointers to an interpreter instance instead.
*/
Interpreter(const Interpreter&);
-
+
/**
* This constructor is not implemented, in order to prevent assignment of
* Interpreter objects. You should always pass around pointers to an
* interpreter instance instead.
*/
Interpreter operator=(const Interpreter&);
- };
+
+ ExecState m_globalExec;
+ JSObject* m_globalObject;
- /**
- * Represents the current state of script execution. This object allows you
- * obtain a handle the interpreter that is currently executing the script,
- * and also the current execution state context.
- */
- class ExecState {
- friend class InterpreterImp;
- friend class FunctionImp;
- friend class RuntimeMethodImp;
- friend class GlobalFuncImp;
- public:
- /**
- * Returns the interpreter associated with this execution state
- *
- * @return The interpreter executing the script
- */
- Interpreter *dynamicInterpreter() const { return m_interpreter; }
+ const Identifier *m_argumentsPropertyName;
+ const Identifier *m_specialPrototypePropertyName;
- /**
- * Returns the interpreter associated with the current scope's
- * global object
- *
- * @return The interpreter currently in scope
- */
- Interpreter *lexicalInterpreter() const;
-
- /**
- * Returns the execution context associated with this execution state
- *
- * @return The current execution state context
- */
- Context* context() const { return m_context; }
-
- void setException(JSValue* e) { m_exception = e; }
- void clearException() { m_exception = 0; }
- JSValue* exception() const { return m_exception; }
- bool hadException() const { return m_exception; }
-
- private:
- ExecState(Interpreter* interp, Context* con)
- : m_interpreter(interp)
- , m_context(con)
- , m_exception(0)
- {
- }
- Interpreter* m_interpreter;
+ // Chained list of interpreters (ring) - for collector
+ static Interpreter* s_hook;
+ Interpreter *next, *prev;
+
+ int m_recursion;
+
+ Debugger* m_debugger;
Context* m_context;
- JSValue* m_exception;
+ CompatMode m_compatMode;
+
+ ProtectedPtr<JSObject> m_Object;
+ ProtectedPtr<JSObject> m_Function;
+ ProtectedPtr<JSObject> m_Array;
+ ProtectedPtr<JSObject> m_Boolean;
+ ProtectedPtr<JSObject> m_String;
+ ProtectedPtr<JSObject> m_Number;
+ ProtectedPtr<JSObject> m_Date;
+ ProtectedPtr<JSObject> m_RegExp;
+ ProtectedPtr<JSObject> m_Error;
+
+ ProtectedPtr<JSObject> m_ObjectPrototype;
+ ProtectedPtr<JSObject> m_FunctionPrototype;
+ ProtectedPtr<JSObject> m_ArrayPrototype;
+ ProtectedPtr<JSObject> m_BooleanPrototype;
+ ProtectedPtr<JSObject> m_StringPrototype;
+ ProtectedPtr<JSObject> m_NumberPrototype;
+ ProtectedPtr<JSObject> m_DatePrototype;
+ ProtectedPtr<JSObject> m_RegExpPrototype;
+ ProtectedPtr<JSObject> m_ErrorPrototype;
+
+ ProtectedPtr<JSObject> m_EvalError;
+ ProtectedPtr<JSObject> m_RangeError;
+ ProtectedPtr<JSObject> m_ReferenceError;
+ ProtectedPtr<JSObject> m_SyntaxError;
+ ProtectedPtr<JSObject> m_TypeError;
+ ProtectedPtr<JSObject> m_UriError;
+
+ ProtectedPtr<JSObject> m_EvalErrorPrototype;
+ ProtectedPtr<JSObject> m_RangeErrorPrototype;
+ ProtectedPtr<JSObject> m_ReferenceErrorPrototype;
+ ProtectedPtr<JSObject> m_SyntaxErrorPrototype;
+ ProtectedPtr<JSObject> m_TypeErrorPrototype;
+ ProtectedPtr<JSObject> m_UriErrorPrototype;
};
} // namespace