JavaScriptCore:
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Dec 2007 02:31:41 +0000 (02:31 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Dec 2007 02:31:41 +0000 (02:31 +0000)
        Reviewed by Darin Adler.

        Third step in refactoring JSGlobalObject: Moved data members and
        functions accessing data members from Interpreter to JSGlobalObject.
        Changed Interpreter member functions to static functions.

        This resolves a bug in global object bootstrapping, where the global
        ExecState could be used when uninitialized.

        This is a big change, but it's mostly code motion and renaming.

        Layout and JS tests, and testjsglue and testapi, pass. SunSpider reports
        a .7% regression, but Shark sees no difference related to this patch,
        and SunSpider reported a .7% speedup from an earlier step in this
        refactoring, so I think it's fair to call that a wash.

JavaScriptGlue:

        Reviewed by Darin Adler.

        Third step in refactoring JSGlobalObject: Moved data members and data
        member access from Interpreter to JSGlobalObject. Replaced JSInterpreter
        subclass with JSGlobalObject subclass.

        * JSRun.cpp:
        (JSRun::JSRun):
        (JSRun::Evaluate):
        (JSRun::CheckSyntax):
        * JSRun.h:
        (JSGlueGlobalObject::JSGlueGlobalObject):
        * JSUtils.cpp:
        (KJSValueToCFTypeInternal):
        * JSValueWrapper.cpp:
        (getThreadGlobalExecState):

WebCore:

        Reviewed by Darin Adler.

        Third step in refactoring JSGlobalObject: Moved data members and data
        member access from Interpreter to JSGlobalObject. Changed Interpreter
        member functions to static functions. Same for the subclass,
        ScriptInterpreter.

        This is a big change, but it's mostly code motion and renaming.

WebKit/mac:

        Reviewed by Darin Adler.

        Third step in refactoring JSGlobalObject: Moved data members and data
        member access from Interpreter to JSGlobalObject.

        * WebView/WebFrame.mm:
        (-[WebFrame _attachScriptDebugger]):

WebKit/win:

        Reviewed by Darin Adler.

        Third step in refactoring JSGlobalObject: Moved data members and data
        member access from Interpreter to JSGlobalObject.

        * WebFrame.cpp:
        (WebFrame::globalContext):
        (WebFrame::attachScriptDebugger):
        (WebFrame::windowObjectCleared):
        * WebScriptDebugger.cpp:
        (WebScriptDebugger::WebScriptDebugger):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28468 268f45cc-cd09-0410-ab3c-d52691b4dbfc

114 files changed:
JavaScriptCore/API/JSBase.cpp
JavaScriptCore/API/JSCallbackConstructor.cpp
JavaScriptCore/API/JSCallbackFunction.cpp
JavaScriptCore/API/JSCallbackObject.h
JavaScriptCore/API/JSCallbackObjectFunctions.h
JavaScriptCore/API/JSClassRef.cpp
JavaScriptCore/API/JSClassRef.h
JavaScriptCore/API/JSContextRef.cpp
JavaScriptCore/API/JSObjectRef.cpp
JavaScriptCore/ChangeLog
JavaScriptCore/JavaScriptCore.exp
JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
JavaScriptCore/bindings/NP_jsobject.cpp
JavaScriptCore/bindings/c/c_utility.cpp
JavaScriptCore/bindings/jni/jni_jsobject.cpp
JavaScriptCore/bindings/jni/jni_utility.cpp
JavaScriptCore/bindings/objc/objc_runtime.mm
JavaScriptCore/bindings/objc/objc_utility.mm
JavaScriptCore/bindings/runtime_array.cpp
JavaScriptCore/bindings/runtime_method.cpp
JavaScriptCore/bindings/runtime_root.cpp
JavaScriptCore/bindings/runtime_root.h
JavaScriptCore/kjs/ExecState.cpp
JavaScriptCore/kjs/ExecState.h
JavaScriptCore/kjs/JSGlobalObject.cpp
JavaScriptCore/kjs/JSGlobalObject.h
JavaScriptCore/kjs/JSImmediate.cpp
JavaScriptCore/kjs/JSLock.h
JavaScriptCore/kjs/SavedBuiltins.h
JavaScriptCore/kjs/array_instance.cpp
JavaScriptCore/kjs/array_object.cpp
JavaScriptCore/kjs/bool_object.cpp
JavaScriptCore/kjs/collector.cpp
JavaScriptCore/kjs/collector.h
JavaScriptCore/kjs/date_object.cpp
JavaScriptCore/kjs/debugger.cpp
JavaScriptCore/kjs/debugger.h
JavaScriptCore/kjs/error_object.cpp
JavaScriptCore/kjs/function.cpp
JavaScriptCore/kjs/function_object.cpp
JavaScriptCore/kjs/grammar.y
JavaScriptCore/kjs/internal.cpp
JavaScriptCore/kjs/internal.h
JavaScriptCore/kjs/interpreter.cpp
JavaScriptCore/kjs/interpreter.h
JavaScriptCore/kjs/lexer.cpp
JavaScriptCore/kjs/lookup.h
JavaScriptCore/kjs/nodes.cpp
JavaScriptCore/kjs/number_object.cpp
JavaScriptCore/kjs/object.cpp
JavaScriptCore/kjs/object.h
JavaScriptCore/kjs/object_object.cpp
JavaScriptCore/kjs/regexp.h
JavaScriptCore/kjs/regexp_object.cpp
JavaScriptCore/kjs/string_object.cpp
JavaScriptCore/kjs/testkjs.cpp
JavaScriptGlue/ChangeLog
JavaScriptGlue/JSRun.cpp
JavaScriptGlue/JSRun.h
JavaScriptGlue/JSUtils.cpp
JavaScriptGlue/JSValueWrapper.cpp
WebCore/ChangeLog
WebCore/ForwardingHeaders/kjs/JSGlobalObject.h [new file with mode: 0644]
WebCore/ForwardingHeaders/kjs/array_object.h [new file with mode: 0644]
WebCore/ForwardingHeaders/kjs/bool_object.h [new file with mode: 0644]
WebCore/ForwardingHeaders/kjs/function_object.h [new file with mode: 0644]
WebCore/ForwardingHeaders/kjs/object_object.h [new file with mode: 0644]
WebCore/WebCore.base.exp
WebCore/bindings/js/JSCSSRuleCustom.cpp
WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp
WebCore/bindings/js/JSCSSValueCustom.cpp
WebCore/bindings/js/JSCustomSQLStatementCallback.cpp
WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp
WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp
WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp
WebCore/bindings/js/JSCustomVoidCallback.cpp
WebCore/bindings/js/JSCustomXPathNSResolver.cpp
WebCore/bindings/js/JSDOMExceptionConstructor.cpp
WebCore/bindings/js/JSDocumentCustom.cpp
WebCore/bindings/js/JSEventCustom.cpp
WebCore/bindings/js/JSHTMLAudioElementConstructor.cpp
WebCore/bindings/js/JSHTMLCollectionCustom.cpp
WebCore/bindings/js/JSHTMLOptionElementConstructor.cpp
WebCore/bindings/js/JSNamedNodesCollection.cpp
WebCore/bindings/js/JSNodeCustom.cpp
WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp
WebCore/bindings/js/JSStyleSheetCustom.cpp
WebCore/bindings/js/JSXMLHttpRequest.cpp
WebCore/bindings/js/JSXSLTProcessor.cpp
WebCore/bindings/js/kjs_binding.cpp
WebCore/bindings/js/kjs_binding.h
WebCore/bindings/js/kjs_css.cpp
WebCore/bindings/js/kjs_dom.cpp
WebCore/bindings/js/kjs_events.cpp
WebCore/bindings/js/kjs_events.h
WebCore/bindings/js/kjs_html.cpp
WebCore/bindings/js/kjs_navigator.cpp
WebCore/bindings/js/kjs_proxy.cpp
WebCore/bindings/js/kjs_proxy.h
WebCore/bindings/js/kjs_window.cpp
WebCore/bindings/js/kjs_window.h
WebCore/bindings/objc/WebScriptObject.mm
WebCore/bindings/scripts/CodeGeneratorJS.pm
WebCore/bridge/JavaScriptStatistics.cpp
WebCore/bridge/mac/WebCoreScriptDebugger.mm
WebCore/history/CachedPage.cpp
WebCore/history/CachedPage.h
WebCore/loader/FrameLoader.cpp
WebCore/page/Frame.cpp
WebKit/mac/ChangeLog
WebKit/mac/WebView/WebFrame.mm
WebKit/win/ChangeLog
WebKit/win/WebFrame.cpp
WebKit/win/WebScriptDebugger.cpp

index 197357cbf51d8a8de835c6a0ef86da5b5d94d271..d8acc42d7c8e6686609a2f1a9ef03479d8ae212a 100644 (file)
  */
 
 #include "config.h"
-
-#include <wtf/Platform.h>
 #include "JSBase.h"
 
 #include "APICast.h"
-
 #include <kjs/ExecState.h>
-#include <kjs/interpreter.h>
+#include <kjs/JSGlobalObject.h>
 #include <kjs/JSLock.h>
+#include <kjs/interpreter.h>
 #include <kjs/object.h>
 
 using namespace KJS;
@@ -46,7 +44,7 @@ JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef th
     UString::Rep* scriptRep = toJS(script);
     UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
     // Interpreter::evaluate sets "this" to the global object if it is NULL
-    Completion completion = exec->dynamicInterpreter()->evaluate(UString(sourceURLRep), startingLineNumber, UString(scriptRep), jsThisObject);
+    Completion completion = Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep), jsThisObject);
 
     if (completion.complType() == Throw) {
         if (exception)
@@ -68,7 +66,7 @@ bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourc
     ExecState* exec = toJS(ctx);
     UString::Rep* scriptRep = toJS(script);
     UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
-    Completion completion = exec->dynamicInterpreter()->checkSyntax(UString(sourceURLRep), startingLineNumber, UString(scriptRep));
+    Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep));
     if (completion.complType() == Throw) {
         if (exception)
             *exception = toRef(completion.value());
index 72304335e2a8ed9d6282e4da4216804534b8bb88..46c1823d21e2cad982ab699ebe4d09d055853015 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: c++; c-basic-offset: 4 -*-
 /*
- * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  */
 
 #include "config.h"
-
-#include <wtf/Platform.h>
 #include "JSCallbackConstructor.h"
 
 #include "APICast.h"
+#include <kjs/JSGlobalObject.h>
+#include <kjs/object_object.h>
 #include <wtf/Vector.h>
 
 namespace KJS {
@@ -37,7 +37,7 @@ namespace KJS {
 const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0};
 
 JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback)
-    : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype())
+    : JSObject(exec->lexicalGlobalObject()->objectPrototype())
     , m_class(jsClass)
     , m_callback(callback)
 {
index 54da5b92424db0f6632596ded8ed03b019808153..fb3937dd0dc30d0d6347de9c12fe89b2a0327c0e 100644 (file)
@@ -31,6 +31,7 @@
 #include "APICast.h"
 #include "function.h"
 #include "function_object.h"
+#include <kjs/JSGlobalObject.h>
 #include <wtf/Vector.h>
 
 namespace KJS {
@@ -38,7 +39,7 @@ namespace KJS {
 const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunctionImp::info, 0};
 
 JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name)
-    : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
+    : InternalFunctionImp(exec->lexicalGlobalObject()->functionPrototype(), name)
     , m_callback(callback)
 {
 }
index d88a74c6c01bf97d7660e66385e6168d50f55a18..7eb32a680e4fb1b11028915461461adeb8ab6d39 100644 (file)
@@ -39,11 +39,9 @@ class JSCallbackObject : public Base
 {
 public:
     JSCallbackObject(ExecState*, JSClassRef, JSValue* prototype, void* data);
-    JSCallbackObject(JSClassRef, JSValue* prototype, void* data);
+    JSCallbackObject(JSClassRef);
     virtual ~JSCallbackObject();
 
-    void init(ExecState*);
-
     virtual UString className() const;
 
     virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
@@ -76,11 +74,9 @@ public:
     static const ClassInfo info;
 
     bool inherits(JSClassRef) const;
-
+    
 private:
-    JSCallbackObject(); // prevent default construction
-    JSCallbackObject(const JSCallbackObject&);
-
+    void init(ExecState*);
     
     static JSValue* cachedValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
     static JSValue* staticValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot);
index 65991b97ef9083c3f9b3cbe691432a7cc68641a2..0218790edc97e4198b7219569213210ed257ae97 100644 (file)
@@ -47,12 +47,14 @@ JSCallbackObject<Base>::JSCallbackObject(ExecState* exec, JSClassRef jsClass, JS
     init(exec);
 }
 
+// Global object constructor. FIXME: Move this into a JSGlobalCallbackObject subclass.
 template <class Base>
-JSCallbackObject<Base>::JSCallbackObject(JSClassRef jsClass, JSValue* prototype, void* data)
-    : Base(prototype)
-    , m_privateData(data)
+JSCallbackObject<Base>::JSCallbackObject(JSClassRef jsClass)
+    : m_privateData(0)
     , m_class(JSClassRetain(jsClass))
 {
+    ASSERT(Base::isGlobalObject());
+    init(static_cast<JSGlobalObject*>(this)->globalExec());
 }
 
 template <class Base>
index f82c769f57f569a11be2b99c7e4f0e47edb29819..98aaaf5290350574b200c388c4de05d25ea11f5b 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: c++; c-basic-offset: 4 -*-
 /*
- * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  */
 
 #include "config.h"
-#include <wtf/Platform.h>
+#include "JSClassRef.h"
+
 #include "APICast.h"
 #include "JSCallbackObject.h"
-#include "JSClassRef.h"
 #include "JSObjectRef.h"
-#include "identifier.h"
+#include <kjs/JSGlobalObject.h>
+#include <kjs/identifier.h>
+#include <kjs/object_object.h>
 
 using namespace KJS;
 
@@ -155,7 +157,7 @@ JSObject* OpaqueJSClass::prototype(JSContextRef ctx)
         if (parentClass)
             parentPrototype = parentClass->prototype(ctx); // can be null
         if (!parentPrototype)
-            parentPrototype = exec->dynamicInterpreter()->builtinObjectPrototype();
+            parentPrototype = exec->dynamicGlobalObject()->objectPrototype();
         cachedPrototype = new JSCallbackObject<JSObject>(exec, prototypeClass, parentPrototype, this); // set ourself as the object's private data, so it can clear our reference on destruction
     }
     return cachedPrototype;
index 9198c3cbb6ed0637958da5795aa7b8e52b787d43..eb2b35b0190e0aaa7d658a4da45c7e7939c36ff4 100644 (file)
@@ -33,6 +33,7 @@
 #include <kjs/protect.h>
 #include <kjs/ustring.h>
 #include <wtf/HashMap.h>
+#include <wtf/RefCounted.h>
 
 struct StaticValueEntry {
     StaticValueEntry(JSObjectGetPropertyCallback _getProperty, JSObjectSetPropertyCallback _setProperty, JSPropertyAttributes _attributes)
index f53ff00a9aed415721212a6c8c4c1ab1bd0223ee..4fa1c8cbe1368c034d43d599c0a83e04c20028c5 100644 (file)
@@ -32,7 +32,6 @@
 #include "JSClassRef.h"
 #include "JSGlobalObject.h"
 #include "completion.h"
-#include "interpreter.h"
 #include "object.h"
 #include <wtf/Platform.h>
 
@@ -42,19 +41,17 @@ JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass)
 {
     JSLock lock;
 
-    Interpreter* interpreter = new Interpreter();
-    ExecState* globalExec = &interpreter->m_globalExec;
-    JSGlobalContextRef ctx = toGlobalRef(globalExec);
-
-     if (globalObjectClass) {
-        // FIXME: ctx is not fully initialized yet, so this call to prototype() might return an object with a garbage pointer in its prototype chain.
-        JSObject* prototype = globalObjectClass->prototype(ctx);
-        JSCallbackObject<JSGlobalObject>* globalObject = new JSCallbackObject<JSGlobalObject>(globalObjectClass, prototype ? prototype : jsNull(), 0);
-        interpreter->setGlobalObject(globalObject);
-        globalObject->init(globalExec);
-    } else
-        interpreter->setGlobalObject(new JSGlobalObject());
+    if (!globalObjectClass) {
+        JSGlobalObject* globalObject = new JSGlobalObject;
+        return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
+    }
 
+    JSGlobalObject* globalObject = new JSCallbackObject<JSGlobalObject>(globalObjectClass);
+    JSGlobalContextRef ctx = toGlobalRef(globalObject->globalExec());
+    JSValue* prototype = globalObjectClass->prototype(ctx);
+    if (!prototype)
+        prototype = jsNull();
+    globalObject->reset(prototype);
     return JSGlobalContextRetain(ctx);
 }
 
@@ -62,7 +59,7 @@ JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx)
 {
     JSLock lock;
     ExecState* exec = toJS(ctx);
-    gcProtect(exec->dynamicInterpreter()->globalObject());
+    gcProtect(exec->dynamicGlobalObject());
     return ctx;
 }
 
@@ -70,11 +67,11 @@ void JSGlobalContextRelease(JSGlobalContextRef ctx)
 {
     JSLock lock;
     ExecState* exec = toJS(ctx);
-    gcUnprotect(exec->dynamicInterpreter()->globalObject());
+    gcUnprotect(exec->dynamicGlobalObject());
 }
 
 JSObjectRef JSContextGetGlobalObject(JSContextRef ctx)
 {
     ExecState* exec = toJS(ctx);
-    return toRef(exec->dynamicInterpreter()->globalObject());
+    return toRef(exec->dynamicGlobalObject());
 }
index f65cafc2c02d8dbeb37c0f7ea0399fedd971bc39..8c3e35eeae8f347e7cec989097b672ead98e98b8 100644 (file)
 #include "JSClassRef.h"
 #include "JSGlobalObject.h"
 
-#include "identifier.h"
+#include "PropertyNameArray.h"
 #include "function.h"
+#include "function_object.h"
+#include "identifier.h"
 #include "internal.h"
 #include "object.h"
-#include "PropertyNameArray.h"
+#include "object_object.h"
 
 using namespace KJS;
 
@@ -73,11 +75,11 @@ JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data)
     ExecState* exec = toJS(ctx);
 
     if (!jsClass)
-        return toRef(new JSObject(exec->lexicalInterpreter()->builtinObjectPrototype())); // slightly more efficient
+        return toRef(new JSObject(exec->lexicalGlobalObject()->objectPrototype())); // slightly more efficient
 
     JSValue* jsPrototype = jsClass->prototype(ctx);
     if (!jsPrototype)
-        jsPrototype = exec->lexicalInterpreter()->builtinObjectPrototype();
+        jsPrototype = exec->lexicalGlobalObject()->objectPrototype();
 
     return toRef(new JSCallbackObject<JSObject>(exec, jsClass, jsPrototype, data));
 }
@@ -98,7 +100,7 @@ JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObje
     
     JSValue* jsPrototype = jsClass 
         ? jsClass->prototype(ctx)
-        : exec->dynamicInterpreter()->builtinObjectPrototype();
+        : exec->dynamicGlobalObject()->objectPrototype();
     
     JSObject* constructor = new JSCallbackConstructor(exec, jsClass, callAsConstructor);
     constructor->put(exec, exec->propertyNames().prototype, jsPrototype, DontEnum|DontDelete|ReadOnly);
@@ -120,7 +122,7 @@ JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned pa
         args.append(jsString(UString(toJS(parameterNames[i]))));
     args.append(jsString(UString(bodyRep)));
 
-    JSObject* result = exec->dynamicInterpreter()->builtinFunction()->construct(exec, args, nameID, UString(sourceURLRep), startingLineNumber);
+    JSObject* result = exec->dynamicGlobalObject()->functionConstructor()->construct(exec, args, nameID, UString(sourceURLRep), startingLineNumber);
     if (exec->hadException()) {
         if (exception)
             *exception = toRef(exec->exception());
@@ -274,7 +276,7 @@ JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObject
     JSObject* jsThisObject = toJS(thisObject);
 
     if (!jsThisObject)
-        jsThisObject = exec->dynamicInterpreter()->globalObject();
+        jsThisObject = exec->dynamicGlobalObject();
     
     List argList;
     for (size_t i = 0; i < argumentCount; i++)
index 71d347413161f2596de9d0425c44cd6e41bdfb4a..9852824c25dcff37857657b47d57c33a00c5f75c 100644 (file)
@@ -1,3 +1,21 @@
+2007-12-05  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Third step in refactoring JSGlobalObject: Moved data members and 
+        functions accessing data members from Interpreter to JSGlobalObject.
+        Changed Interpreter member functions to static functions.
+        
+        This resolves a bug in global object bootstrapping, where the global
+        ExecState could be used when uninitialized.
+        
+        This is a big change, but it's mostly code motion and renaming.
+        
+        Layout and JS tests, and testjsglue and testapi, pass. SunSpider reports
+        a .7% regression, but Shark sees no difference related to this patch,
+        and SunSpider reported a .7% speedup from an earlier step in this 
+        refactoring, so I think it's fair to call that a wash.
+
 2007-12-05  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Darin Adler. (Or vice versa.)
index 4a5694fc72c2fc3cb029e9b1c7bbcf4b9a0e08cd..022e250091cabd30ac732c8289081d9f14b40f28 100644 (file)
@@ -112,22 +112,11 @@ __ZN3KJS10Identifier3addEPKc
 __ZN3KJS10Identifier5equalEPKNS_7UString3RepEPKc
 __ZN3KJS10throwErrorEPNS_9ExecStateENS_9ErrorTypeE
 __ZN3KJS10throwErrorEPNS_9ExecStateENS_9ErrorTypeEPKc
-__ZN3KJS11Interpreter11checkSyntaxERKNS_7UStringEiPKNS_5UCharEi
-__ZN3KJS11Interpreter11checkSyntaxERKNS_7UStringEiS3_
-__ZN3KJS11Interpreter15restoreBuiltinsERKNS_13SavedBuiltinsE
-__ZN3KJS11Interpreter15setGlobalObjectEPNS_14JSGlobalObjectE
-__ZN3KJS11Interpreter16stopTimeoutCheckEv
-__ZN3KJS11Interpreter17startTimeoutCheckEv
+__ZN3KJS11Interpreter11checkSyntaxEPNS_9ExecStateERKNS_7UStringEiPKNS_5UCharEi
 __ZN3KJS11Interpreter21shouldPrintExceptionsEv
 __ZN3KJS11Interpreter24setShouldPrintExceptionsEb
-__ZN3KJS11Interpreter27resetGlobalObjectPropertiesEv
-__ZN3KJS11Interpreter6s_hookE
-__ZN3KJS11Interpreter8evaluateERKNS_7UStringEiPKNS_5UCharEiPNS_7JSValueE
-__ZN3KJS11Interpreter8evaluateERKNS_7UStringEiS3_PNS_7JSValueE
-__ZN3KJS11InterpreterC1Ev
-__ZN3KJS11InterpreterC2Ev
-__ZN3KJS11InterpreterD1Ev
-__ZN3KJS11InterpreterD2Ev
+__ZN3KJS11Interpreter8evaluateEPNS_9ExecStateERKNS_7UStringEiPKNS_5UCharEiPNS_7JSValueE
+__ZN3KJS11Interpreter8evaluateEPNS_9ExecStateERKNS_7UStringEiS5_PNS_7JSValueE
 __ZN3KJS11JSImmediate4typeEPKNS_7JSValueE
 __ZN3KJS11JSImmediate8toObjectEPKNS_7JSValueEPNS_9ExecStateE
 __ZN3KJS11JSImmediate8toStringEPKNS_7JSValueE
@@ -139,11 +128,16 @@ __ZN3KJS12DateInstance4infoE
 __ZN3KJS12PropertySlot15undefinedGetterEPNS_9ExecStateEPNS_8JSObjectERKNS_10IdentifierERKS0_
 __ZN3KJS12jsNumberCellEd
 __ZN3KJS13ArrayInstance4infoE
-__ZN3KJS13SavedBuiltinsC1Ev
-__ZN3KJS13SavedBuiltinsD1Ev
 __ZN3KJS13jsOwnedStringERKNS_7UStringE
 __ZN3KJS14JSGlobalObject10globalExecEv
+__ZN3KJS14JSGlobalObject15restoreBuiltinsERKNS_13SavedBuiltinsE
+__ZN3KJS14JSGlobalObject16stopTimeoutCheckEv
+__ZN3KJS14JSGlobalObject17startTimeoutCheckEv
+__ZN3KJS14JSGlobalObject4initEv
 __ZN3KJS14JSGlobalObject4markEv
+__ZN3KJS14JSGlobalObject5resetEPNS_7JSValueE
+__ZN3KJS14JSGlobalObject6s_headE
+__ZN3KJS14JSGlobalObjectD2Ev
 __ZN3KJS14StringInstance14deletePropertyEPNS_9ExecStateERKNS_10IdentifierE
 __ZN3KJS14StringInstance16getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE
 __ZN3KJS14StringInstance18getOwnPropertySlotEPNS_9ExecStateERKNS_10IdentifierERNS_12PropertySlotE
@@ -192,11 +186,12 @@ __ZN3KJS8Bindings10RootObjectD1Ev
 __ZN3KJS8Bindings10throwErrorEPNS_9ExecStateENS_9ErrorTypeEP8NSString
 __ZN3KJS8Bindings23convertObjcValueToValueEPNS_9ExecStateEPvNS0_13ObjcValueTypeEPNS0_10RootObjectE
 __ZN3KJS8Bindings23convertValueToObjcValueEPNS_9ExecStateEPNS_7JSValueENS0_13ObjcValueTypeE
+__ZN3KJS8Bindings24findProtectingRootObjectEPNS_8JSObjectE
 __ZN3KJS8Bindings8Instance18didExecuteFunctionEv
 __ZN3KJS8Bindings8Instance21setDidExecuteFunctionEPFvPNS_9ExecStateEPNS_8JSObjectEE
 __ZN3KJS8Bindings8Instance32createBindingForLanguageInstanceENS1_15BindingLanguageEPvN3WTF10PassRefPtrINS0_10RootObjectEEE
 __ZN3KJS8Debugger12sourceUnusedEPNS_9ExecStateEi
-__ZN3KJS8Debugger6attachEPNS_11InterpreterE
+__ZN3KJS8Debugger6attachEPNS_14JSGlobalObjectE
 __ZN3KJS8Debugger9exceptionEPNS_9ExecStateEiiPNS_7JSValueE
 __ZN3KJS8DebuggerC2Ev
 __ZN3KJS8DebuggerD2Ev
@@ -219,8 +214,8 @@ __ZN3KJS8JSObject9putDirectERKNS_10IdentifierEPNS_7JSValueEi
 __ZN3KJS8JSObject9putDirectERKNS_10IdentifierEii
 __ZN3KJS8jsStringEPKc
 __ZN3KJS8jsStringERKNS_7UStringE
-__ZN3KJS9Collector15numInterpretersEv
 __ZN3KJS9Collector15recordExtraCostEm
+__ZN3KJS9Collector16numGlobalObjectsEv
 __ZN3KJS9Collector19numProtectedObjectsEv
 __ZN3KJS9Collector20rootObjectTypeCountsEv
 __ZN3KJS9Collector23collectOnMainThreadOnlyEPNS_7JSValueE
@@ -228,23 +223,18 @@ __ZN3KJS9Collector4sizeEv
 __ZN3KJS9Collector7collectEv
 __ZN3KJS9Collector7protectEPNS_7JSValueE
 __ZN3KJS9Collector9unprotectEPNS_7JSValueE
+__ZN3KJS9ExecStateD1Ev
 __ZN3KJSeqERKNS_7UStringEPKc
 __ZN3WTF10fastCallocEmm
 __ZN3WTF10fastMallocEm
 __ZN3WTF11fastReallocEPvm
 __ZN3WTF16fastZeroedMallocEm
 __ZN3WTF8fastFreeEPv
-__ZNK3KJS11Interpreter12builtinArrayEv
-__ZNK3KJS11Interpreter12globalObjectEv
-__ZNK3KJS11Interpreter12saveBuiltinsERNS_13SavedBuiltinsE
-__ZNK3KJS11Interpreter15builtinFunctionEv
-__ZNK3KJS11Interpreter22builtinObjectPrototypeEv
-__ZNK3KJS11Interpreter22builtinStringPrototypeEv
-__ZNK3KJS11Interpreter24builtinFunctionPrototypeEv
 __ZNK3KJS11PropertyMap3getERKNS_10IdentifierE
 __ZNK3KJS11PropertyMap4saveERNS_15SavedPropertiesE
 __ZNK3KJS12DateInstance7getTimeERdRi
 __ZNK3KJS13ArrayInstance7getItemEj
+__ZNK3KJS14JSGlobalObject12saveBuiltinsERNS_13SavedBuiltinsE
 __ZNK3KJS19InternalFunctionImp14implementsCallEv
 __ZNK3KJS19InternalFunctionImp21implementsHasInstanceEv
 __ZNK3KJS4List8getSliceEiRS0_
@@ -266,7 +256,6 @@ __ZNK3KJS7UString5asciiEv
 __ZNK3KJS7UString6is8BitEv
 __ZNK3KJS7UString8toUInt32EPb
 __ZNK3KJS7UString8toUInt32EPbb
-__ZNK3KJS8Bindings10RootObject11interpreterEv
 __ZNK3KJS8Bindings10RootObject12globalObjectEv
 __ZNK3KJS8Bindings8Instance10rootObjectEv
 __ZNK3KJS8JSObject11hasPropertyEPNS_9ExecStateERKNS_10IdentifierE
@@ -284,7 +273,7 @@ __ZNK3KJS8JSObject8toStringEPNS_9ExecStateE
 __ZNK3KJS8JSObject9classInfoEv
 __ZNK3KJS8JSObject9classNameEv
 __ZNK3KJS8JSObject9toBooleanEPNS_9ExecStateE
-__ZNK3KJS9ExecState18lexicalInterpreterEv
+__ZNK3KJS9ExecState19lexicalGlobalObjectEv
 __ZTVN3KJS14JSGlobalObjectE
 __ZTVN3KJS14StringInstanceE
 __ZTVN3KJS15JSWrapperObjectE
index 429e00c0f3c9c1fcc2a46935fa7360a7a7432055..ced6efae5d1d8e3ef41663a22c5229a7553d2db7 100644 (file)
                932F5B6F0822A1C700736975 /* jni_utility.h in Headers */ = {isa = PBXBuildFile; fileRef = 51856D900562EE95008B9D83 /* jni_utility.h */; };
                932F5B700822A1C700736975 /* runtime.h in Headers */ = {isa = PBXBuildFile; fileRef = 511B0870056468730080E486 /* runtime.h */; settings = {ATTRIBUTES = (Private, ); }; };
                932F5B710822A1C700736975 /* jni_runtime.h in Headers */ = {isa = PBXBuildFile; fileRef = 511B0876056468BB0080E486 /* jni_runtime.h */; };
-               932F5B720822A1C700736975 /* bool_object.h in Headers */ = {isa = PBXBuildFile; fileRef = 704FD35305697E6D003DBED9 /* bool_object.h */; };
+               932F5B720822A1C700736975 /* bool_object.h in Headers */ = {isa = PBXBuildFile; fileRef = 704FD35305697E6D003DBED9 /* bool_object.h */; settings = {ATTRIBUTES = (Private, ); }; };
                932F5B730822A1C700736975 /* runtime_object.h in Headers */ = {isa = PBXBuildFile; fileRef = 70B16A270569A10900DB756D /* runtime_object.h */; settings = {ATTRIBUTES = (Private, ); }; };
                932F5B740822A1C700736975 /* jni_class.h in Headers */ = {isa = PBXBuildFile; fileRef = 517D52DD056BF2F6003851BD /* jni_class.h */; };
                932F5B750822A1C700736975 /* jni_instance.h in Headers */ = {isa = PBXBuildFile; fileRef = 517D5348056BFB5D003851BD /* jni_instance.h */; settings = {ATTRIBUTES = (); }; };
index bdcd8bd4903bede39614e6af7dc1f15ae50c3614..ab841c0ca75b4077a8ecf623b4d20a29055ebaad 100644 (file)
@@ -32,6 +32,7 @@
 #include "JSGlobalObject.h"
 #include "PropertyNameArray.h"
 #include "c_utility.h"
+#include "interpreter.h"
 #include "npruntime_impl.h"
 #include "npruntime_priv.h"
 #include "object.h"
@@ -127,9 +128,9 @@ bool _NPN_InvokeDefault(NPP, NPObject* o, const NPVariant* args, uint32_t argCou
         
         List argList;
         getListFromVariantArgs(exec, args, argCount, rootObject, argList);
-        rootObject->interpreter()->startTimeoutCheck();
+        rootObject->globalObject()->startTimeoutCheck();
         JSValue *resultV = funcImp->call (exec, funcImp, argList);
-        rootObject->interpreter()->stopTimeoutCheck();
+        rootObject->globalObject()->stopTimeoutCheck();
 
         // Convert and return the result of the function call.
         convertValueToNPVariant(exec, resultV, result);
@@ -183,9 +184,9 @@ bool _NPN_Invoke(NPP npp, NPObject* o, NPIdentifier methodName, const NPVariant*
         JSObject *thisObj = const_cast<JSObject*>(obj->imp);
         List argList;
         getListFromVariantArgs(exec, args, argCount, rootObject, argList);
-        rootObject->interpreter()->startTimeoutCheck();
+        rootObject->globalObject()->startTimeoutCheck();
         JSValue *resultV = funcImp->call (exec, thisObj, argList);
-        rootObject->interpreter()->stopTimeoutCheck();
+        rootObject->globalObject()->stopTimeoutCheck();
 
         // Convert and return the result of the function call.
         convertValueToNPVariant(exec, resultV, result);
@@ -217,9 +218,9 @@ bool _NPN_Evaluate(NPP, NPObject* o, NPString* s, NPVariant* variant)
         NPUTF16* scriptString;
         unsigned int UTF16Length;
         convertNPStringToUTF16(s, &scriptString, &UTF16Length); // requires free() of returned memory
-        rootObject->interpreter()->startTimeoutCheck();
-        Completion completion = rootObject->interpreter()->evaluate(UString(), 0, UString((const UChar*)scriptString,UTF16Length));
-        rootObject->interpreter()->stopTimeoutCheck();
+        rootObject->globalObject()->startTimeoutCheck();
+        Completion completion = Interpreter::evaluate(rootObject->globalObject()->globalExec(), UString(), 0, UString(reinterpret_cast<const UChar*>(scriptString), UTF16Length));
+        rootObject->globalObject()->stopTimeoutCheck();
         ComplType type = completion.complType();
         
         JSValue* result;
index 3831bed1fa479783d5589e10cc76d427c094d5e2..50c93e8d0669f507893c6104d9044ceb750b5e30 100644 (file)
@@ -115,17 +115,17 @@ void convertValueToNPVariant(ExecState *exec, JSValue *value, NPVariant *result)
                 OBJECT_TO_NPVARIANT(obj, *result);
             }
         } else {
-            Interpreter* originInterpreter = exec->dynamicInterpreter();
-            RootObject* originRootObject = findRootObject(originInterpreter);
+            JSGlobalObject* originGlobalObject = exec->dynamicGlobalObject();
+            RootObject* originRootObject = findRootObject(originGlobalObject);
 
-            Interpreter* interpreter = 0;
+            JSGlobalObject* globalObject = 0;
             if (object->isGlobalObject())
-                interpreter = static_cast<JSGlobalObject*>(object)->interpreter();
+                globalObject = static_cast<JSGlobalObject*>(object);
 
-            if (!interpreter)
-                interpreter = originInterpreter;
+            if (!globalObject)
+                globalObject = originGlobalObject;
 
-            RootObject* rootObject = findRootObject(interpreter);
+            RootObject* rootObject = findRootObject(globalObject);
             if (rootObject) {
                 NPObject* npObject = _NPN_CreateScriptObject(0, object, originRootObject, rootObject);
                 OBJECT_TO_NPVARIANT(npObject, *result);
index 7f902b3e0066726468164c716663cabdd9669b79..f694f68691ebf9be111f65ffca67e639bd932c1c 100644 (file)
@@ -79,7 +79,7 @@ jvalue JavaJSObject::invoke (JSObjectCallContext *context)
         }
         else {
             JSObject *imp = jlong_to_impptr(nativeHandle);
-            if (!findRootObject(imp)) {
+            if (!findProtectingRootObject(imp)) {
                 fprintf (stderr, "%s:%d:  Attempt to access JavaScript from destroyed applet, type %d.\n", __FILE__, __LINE__, context->type);
                 return result;
             }
@@ -147,7 +147,7 @@ JavaJSObject::JavaJSObject(jlong nativeJSObject)
     _imp = jlong_to_impptr(nativeJSObject);
     
     ASSERT(_imp);
-    _rootObject = findRootObject(_imp);
+    _rootObject = findProtectingRootObject(_imp);
     ASSERT(_rootObject);
 }
 
@@ -178,9 +178,9 @@ jobject JavaJSObject::call(jstring methodName, jobjectArray args) const
     JSObject *thisObj = const_cast<JSObject*>(_imp);
     List argList;
     getListFromJArray(args, argList);
-    rootObject->interpreter()->startTimeoutCheck();
+    rootObject->globalObject()->startTimeoutCheck();
     JSValue *result = funcImp->call(exec, thisObj, argList);
-    rootObject->interpreter()->stopTimeoutCheck();
+    rootObject->globalObject()->stopTimeoutCheck();
 
     return convertValueToJObject(result);
 }
@@ -198,9 +198,9 @@ jobject JavaJSObject::eval(jstring script) const
     if (!rootObject)
         return 0;
 
-    rootObject->interpreter()->startTimeoutCheck();
-    Completion completion = rootObject->interpreter()->evaluate(UString(), 0, JavaString(script).ustring(),thisObj);
-    rootObject->interpreter()->stopTimeoutCheck();
+    rootObject->globalObject()->startTimeoutCheck();
+    Completion completion = Interpreter::evaluate(rootObject->globalObject()->globalExec(), UString(), 0, JavaString(script).ustring(),thisObj);
+    rootObject->globalObject()->stopTimeoutCheck();
     ComplType type = completion.complType();
     
     if (type == Normal) {
@@ -326,7 +326,7 @@ jlong JavaJSObject::createNative(jlong nativeHandle)
     if (nativeHandle == UndefinedHandle)
         return nativeHandle;
 
-    if (findRootObject(jlong_to_impptr(nativeHandle)))
+    if (findProtectingRootObject(jlong_to_impptr(nativeHandle)))
         return nativeHandle;
 
     CreateRootObjectFunction createRootObject = RootObject::createRootObject();
@@ -339,7 +339,7 @@ jlong JavaJSObject::createNative(jlong nativeHandle)
     // otherwise we are being called after creating a JavaJSObject in
     // JavaJSObject::convertValueToJObject().
     if (rootObject) {
-        JSObject* globalObject = rootObject->interpreter()->globalObject();
+        JSObject* globalObject = rootObject->globalObject();
         // We call gcProtect here to get the object into the root object's "protect set" which
         // is used to test if a native handle is valid as well as getting the root object given the handle.
         rootObject->gcProtect(globalObject);
index 2e491dafb48c5892dc6bcd31bb3f500dc93234be..8a8c6560ee480a4e224ee4ac385db7a73c7b093a 100644 (file)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "jni_utility.h"
 
-#include "interpreter.h"
 #include "list.h"
 #include "jni_runtime.h"
 #include "runtime_array.h"
index 800f790ec667a8298213511cafd911bdb204807b..ec0b41fc0764935b274611d80edecc1a765c07e6 100644 (file)
@@ -123,7 +123,7 @@ JSValue* ObjcField::valueFromInstance(ExecState* exec, const Instance* instance)
 
 static id convertValueToObjcObject(ExecState* exec, JSValue* value)
 {
-    RefPtr<RootObject> rootObject = findRootObject(exec->dynamicInterpreter());
+    RefPtr<RootObject> rootObject = findRootObject(exec->dynamicGlobalObject());
     if (!rootObject)
         return nil;
     return [webScriptObjectClass() _convertValueToObjcValue:value originRootObject:rootObject.get() rootObject:rootObject.get()];
index 6c2f5d77f85e29b62b5f8a8f754ee6bc8314ac22..62a0ad01dc76651818b678139553644f55d937f0 100644 (file)
@@ -137,17 +137,17 @@ ObjcValue convertValueToObjcValue(ExecState *exec, JSValue *value, ObjcValueType
         case ObjcObjectType: {
             JSLock lock;
             
-            Interpreter *originInterpreter = exec->dynamicInterpreter();
-            RootObject* originRootObject = findRootObject(originInterpreter);
+            JSGlobalObject *originGlobalObject = exec->dynamicGlobalObject();
+            RootObject* originRootObject = findRootObject(originGlobalObject);
 
-            Interpreter *interpreter = 0;
+            JSGlobalObject* globalObject = 0;
             if (value->isObject() && static_cast<JSObject*>(value)->isGlobalObject())
-                interpreter = static_cast<JSGlobalObject*>(value)->interpreter();
+                globalObject = static_cast<JSGlobalObject*>(value);
 
-            if (!interpreter)
-                interpreter = originInterpreter;
+            if (!globalObject)
+                globalObject = originGlobalObject;
                 
-            RootObject* rootObject = findRootObject(interpreter);
+            RootObject* rootObject = findRootObject(globalObject);
             result.objectValue =  rootObject
                 ? [webScriptObjectClass() _convertValueToObjcValue:value originRootObject:originRootObject rootObject:rootObject]
                 : nil;
index 10ea975ad8b600cfc31d9df253daffb14d9d828f..c8ff075ff0b2bb88af446abdb2934786919b809d 100644 (file)
 #include "config.h"
 #include "runtime_array.h"
 
+#include "JSGlobalObject.h"
+#include "array_object.h"
+
 using namespace KJS;
 
 const ClassInfo RuntimeArray::info = { "RuntimeArray", &ArrayInstance::info, 0 };
 
 RuntimeArray::RuntimeArray(ExecState *exec, Bindings::Array *a)
-    : JSObject(exec->lexicalInterpreter()->builtinArrayPrototype())
+    : JSObject(exec->lexicalGlobalObject()->arrayPrototype())
     , _array(a)
 {
 }
index 06e88fd3eac451f1f61294e7b0d6b583795538b6..50ae64e7c7a89ccc5a2d4abf7a0da878018adc16 100644 (file)
@@ -27,6 +27,7 @@
 #include "runtime_method.h"
 
 #include "ExecState.h"
+#include "JSGlobalObject.h"
 #include "runtime_object.h"
 #include "function_object.h"
 
@@ -34,7 +35,7 @@ using namespace KJS::Bindings;
 using namespace KJS;
 
 RuntimeMethod::RuntimeMethod(ExecState *exec, const Identifier &ident, Bindings::MethodList &m) 
-    : InternalFunctionImp (static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), ident)
+    : InternalFunctionImp(exec->lexicalGlobalObject()->functionPrototype(), ident)
     , _methodList(new MethodList(m))
 {
 }
index 7f5200523785166f5cf3e35ad52f0ec146a235ac..738cfd6f7496226b902736e5a35492158e337412 100644 (file)
@@ -50,7 +50,7 @@ static RootObjectSet* rootObjectSet()
 // FIXME:  These two functions are a potential performance problem.  We could 
 // fix them by adding a JSObject to RootObject dictionary.
 
-RootObject* findRootObject(JSObject* jsObject)
+RootObject* findProtectingRootObject(JSObject* jsObject)
 {
     RootObjectSet::const_iterator end = rootObjectSet()->end();
     for (RootObjectSet::const_iterator it = rootObjectSet()->begin(); it != end; ++it) {
@@ -60,11 +60,11 @@ RootObject* findRootObject(JSObject* jsObject)
     return 0;
 }
 
-RootObject* findRootObject(Interpreter* interpreter)
+RootObject* findRootObject(JSGlobalObject* globalObject)
 {
     RootObjectSet::const_iterator end = rootObjectSet()->end();
     for (RootObjectSet::const_iterator it = rootObjectSet()->begin(); it != end; ++it) {
-        if ((*it)->interpreter() == interpreter)
+        if ((*it)->globalObject() == globalObject)
             return *it;
     }
     return 0;
@@ -280,12 +280,6 @@ const void* RootObject::nativeHandle() const
     return m_nativeHandle; 
 }
 
-Interpreter* RootObject::interpreter() const 
-{ 
-    ASSERT(m_isValid);
-    return m_globalObject->interpreter();
-}
-
 JSGlobalObject* RootObject::globalObject() const
 {
     ASSERT(m_isValid);
index 37628ee86b38774d7605aec1c66cbeeb5eb2dc8e..4db02d41b41d8e91a045be2b685e9eb250573bd7 100644 (file)
@@ -48,8 +48,8 @@ class RootObject;
 typedef PassRefPtr<RootObject> (*CreateRootObjectFunction)(void* nativeHandle);
 typedef HashCountedSet<JSObject*> ProtectCountSet;
 
-extern RootObject* findRootObject(JSObject*);
-extern RootObject* findRootObject(Interpreter*);
+extern RootObject* findProtectingRootObject(JSObject*);
+extern RootObject* findRootObject(JSGlobalObject*);
 
 class RootObject : public RefCounted<RootObject> {
     friend class JavaJSObject;
@@ -67,7 +67,6 @@ public:
     bool gcIsProtected(JSObject*);
 
     const void* nativeHandle() const;
-    Interpreter* interpreter() const;
     JSGlobalObject* globalObject() const;
 
 #if PLATFORM(MAC)
index f828a691404b120f4ef073de6a72cd1823bd18ab..e8e74bc09e771ff7743712523104fb19e296bf20 100644 (file)
 
 namespace KJS {
 
-
 // ECMA 10.2
-ExecState::ExecState(Interpreter* interpreter, JSGlobalObject* globalObject, JSObject* thisV, 
-                     FunctionBodyNode* currentBody, CodeType type, ExecState* callingExec, 
+ExecState::ExecState(JSGlobalObject* globalObject, JSObject* thisV, 
+                     FunctionBodyNode* currentBody, CodeType type, ExecState* callingExec, ExecState* currentExec,
                      FunctionImp* func, const List* args)
-    : m_interpreter(interpreter)
+    : m_globalObject(globalObject)
     , m_exception(0)
     , m_propertyNames(CommonIdentifiers::shared())
-    , m_savedExecState(interpreter->currentExec())
+    , m_callingExec(callingExec)
+    , m_savedExec(currentExec)
     , m_currentBody(currentBody)
     , m_function(func)
     , m_arguments(args)
     , m_iterationDepth(0)
     , m_switchDepth(0) 
+    , m_codeType(type)
 {
-    m_codeType = type;
-    m_callingExecState = callingExec;
-    
     // create and initialize activation object (ECMA 10.1.6)
     if (type == FunctionCode) {
         m_activation = new ActivationImp(this);
@@ -61,15 +59,15 @@ ExecState::ExecState(Interpreter* interpreter, JSGlobalObject* globalObject, JSO
     // ECMA 10.2
     switch(type) {
     case EvalCode:
-        if (m_callingExecState) {
-            m_scopeChain = m_callingExecState->scopeChain();
-            m_variable = m_callingExecState->variableObject();
-            m_thisVal = m_callingExecState->thisValue();
+        if (m_callingExec) {
+            m_scopeChain = m_callingExec->scopeChain();
+            m_variable = m_callingExec->variableObject();
+            m_thisVal = m_callingExec->thisValue();
             break;
         } // else same as GlobalCode
     case GlobalCode:
-        if (globalObject)
-            setGlobalObject(globalObject);
+        m_scopeChain.push(globalObject);
+        m_thisVal = globalObject;
         break;
     case FunctionCode:
         m_scopeChain = func->scope();
@@ -80,37 +78,30 @@ ExecState::ExecState(Interpreter* interpreter, JSGlobalObject* globalObject, JSO
     }
 
     if (currentBody)
-        m_interpreter->setCurrentExec(this);
+        m_globalObject->setCurrentExec(this);
 }
 
 ExecState::~ExecState()
 {
-    m_interpreter->setCurrentExec(m_savedExecState);
+    m_globalObject->setCurrentExec(m_savedExec);
 }
 
 void ExecState::mark()
 {
-    for (ExecState* exec = this; exec; exec = exec->m_callingExecState)
+    for (ExecState* exec = this; exec; exec = exec->m_callingExec)
         exec->m_scopeChain.mark();
 }
 
-void ExecState::setGlobalObject(JSGlobalObject* globalObject)
-{
-    m_scopeChain.clear();
-    m_scopeChain.push(globalObject);
-    m_thisVal = static_cast<JSObject*>(globalObject);
-}
-
-Interpreter* ExecState::lexicalInterpreter() const
+JSGlobalObject* ExecState::lexicalGlobalObject() const
 {
     if (scopeChain().isEmpty())
-        return dynamicInterpreter();
+        return dynamicGlobalObject();
     
     JSObject* object = scopeChain().bottom();
     if (object && object->isGlobalObject())
-        return static_cast<JSGlobalObject*>(object)->interpreter();
+        return static_cast<JSGlobalObject*>(object);
 
-    return dynamicInterpreter();
+    return dynamicGlobalObject();
 }
     
 void ExecState::updateLocalStorage() 
index 5012350be7e837de778e5728227c7ea00c703c20..64be7ac7d7c384b8010c97899fc42a1403751ae5 100644 (file)
@@ -56,14 +56,14 @@ namespace KJS  {
         friend class GlobalFuncImp;
     public:
         /**
-         * Returns the interpreter currently running code
+         * Returns the global object that was in scope when the current script started executing.
          */
-        Interpreter* dynamicInterpreter() const { return m_interpreter; }
+        JSGlobalObject* dynamicGlobalObject() const { return m_globalObject; }
         
         /**
-         * Returns the interpreter associated with the current scope's global object
+         * Returns the global object that was in scope when the current body of code was defined.
          */
-        Interpreter* lexicalInterpreter() const;
+        JSGlobalObject* lexicalGlobalObject() const;
                 
         void setException(JSValue* e) { m_exception = e; }
         void clearException() { m_exception = 0; }
@@ -78,7 +78,7 @@ namespace KJS  {
         
         JSObject* thisValue() const { return m_thisVal; }
         
-        ExecState* callingExecState() { return m_callingExecState; }
+        ExecState* callingExecState() { return m_callingExec; }
         
         JSObject* activationObject() { return m_activation; }
         CodeType codeType() { return m_codeType; }
@@ -98,8 +98,6 @@ namespace KJS  {
         void popSwitch() { m_switchDepth--; }
         bool inSwitch() const { return (m_switchDepth > 0); }
 
-        void setGlobalObject(JSGlobalObject*);
-        
         void mark();
         
         // This is a workaround to avoid accessing the global variables for these identifiers in
@@ -109,21 +107,23 @@ namespace KJS  {
         LocalStorageEntry* localStorage() { return m_localStorageBuffer; }
         void updateLocalStorage();
     
-    private:
-        ExecState(Interpreter* interp, JSGlobalObject* glob, JSObject* thisV,
+    public:
+        ExecState(JSGlobalObject* glob, JSObject* thisV,
                   FunctionBodyNode* currentBody, CodeType type = GlobalCode,
-                  ExecState* callingExecState = 0, FunctionImp* function = 0, const List* args = 0);
+                  ExecState* callingExecState = 0, ExecState* currentExec = 0, 
+                  FunctionImp* function = 0, const List* args = 0);
         ~ExecState();
 
+    private:
         // ExecStates are always stack-allocated, and the garbage collector
         // marks the stack, so we don't need to protect the objects below from GC.
 
-        Interpreter* m_interpreter;
+        JSGlobalObject* m_globalObject;
         JSValue* m_exception;
         CommonIdentifiers* m_propertyNames;
 
-        ExecState* m_callingExecState;
-        ExecState* m_savedExecState;
+        ExecState* m_callingExec;
+        ExecState* m_savedExec;
         FunctionBodyNode* m_currentBody;
         
         FunctionImp* m_function;
index 695d6650e2f104cf59fdd4fe7391ba0ce076a841..b779f4304e36f72742fe97de03bfd7937d83c467 100644 (file)
 #include "config.h"
 #include "JSGlobalObject.h"
 
-#include "object_object.h"
-#include "function_object.h"
+#include "SavedBuiltins.h"
 #include "array_object.h"
 #include "bool_object.h"
-#include "string_object.h"
-#include "number_object.h"
 #include "date_object.h"
-#include "regexp_object.h"
+#include "debugger.h"
 #include "error_object.h"
+#include "function_object.h"
+#include "math_object.h"
+#include "number_object.h"
+#include "object_object.h"
+#include "regexp_object.h"
+#include "string_object.h"
 
 namespace KJS {
 
+// Default number of ticks before a timeout check should be done.
+static const int initialTickCountThreshold = 255;
+
+// Preferred number of milliseconds between each timeout check
+static const int preferredScriptCheckTimeInterval = 1000;
+
 static inline void markIfNeeded(JSValue* v)
 {
     if (v && !v->marked())
         v->mark();
 }
+    
+// Returns the current time in milliseconds
+// It doesn't matter what "current time" is here, just as long as
+// it's possible to measure the time difference correctly.
+static inline unsigned getCurrentTime() {
+#if HAVE(SYS_TIME_H)
+    struct timeval tv;
+    gettimeofday(&tv, 0);
+    return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+#elif PLATFORM(QT)
+    QDateTime t = QDateTime::currentDateTime();
+    return t.toTime_t() * 1000 + t.time().msec();
+#elif PLATFORM(WIN_OS)
+    return timeGetTime();
+#else
+#error Platform does not have getCurrentTime function
+#endif
+}
 
-void JSGlobalObject::mark()
+JSGlobalObject* JSGlobalObject::s_head = 0;
+
+JSGlobalObject::~JSGlobalObject()
 {
-    JSObject::mark();
+    ASSERT(JSLock::currentThreadIsHoldingLock());
+
+    if (d->debugger)
+        d->debugger->detach(this);
+
+    d->next->d->prev = d->prev;
+    d->prev->d->next = d->next;
+    s_head = d->next;
+    if (s_head == this)
+        s_head = 0;
+}
+
+void JSGlobalObject::init()
+{
+    ASSERT(JSLock::currentThreadIsHoldingLock());
+
+    d.reset(new JSGlobalObjectData(this));
+
+    if (s_head) {
+        d->prev = s_head;
+        d->next = s_head->d->next;
+        s_head->d->next->d->prev = this;
+        s_head->d->next = this;
+    } else
+        s_head = d->next = d->prev = this;
+
+    d->compatMode = NativeMode;
+
+    resetTimeoutCheck();
+    d->timeoutTime = 0;
+    d->timeoutCheckCount = 0;
+
+    d->currentExec = 0;
+    d->recursion = 0;
+    d->debugger = 0;
+    
+    reset(prototype());
+}
+
+static inline JSObject* lastInPrototypeChain(JSObject* object)
+{
+    JSObject* o = object;
+    while (o->prototype()->isObject())
+        o = static_cast<JSObject*>(o->prototype());
+    return o;
+}
+
+void JSGlobalObject::reset(JSValue* prototype)
+{
+    // Clear before inititalizing, to avoid marking uninitialized (dangerous) or 
+    // stale (wasteful) pointers during possible garbage collection while creating
+    // new objects below.
+
+    ExecState* exec = &d->globalExec;
+
+    // Prototypes
+    d->functionPrototype = 0;
+    d->objectPrototype = 0;
+
+    d->arrayPrototype = 0;
+    d->stringPrototype = 0;
+    d->booleanPrototype = 0;
+    d->numberPrototype = 0;
+    d->datePrototype = 0;
+    d->regExpPrototype = 0;
+    d->errorPrototype = 0;
+    
+    d->evalErrorPrototype = 0;
+    d->rangeErrorPrototype = 0;
+    d->referenceErrorPrototype = 0;
+    d->syntaxErrorPrototype = 0;
+    d->typeErrorPrototype = 0;
+    d->URIErrorPrototype = 0;
+
+    // Constructors
+    d->objectConstructor = 0;
+    d->functionConstructor = 0;
+    d->arrayConstructor = 0;
+    d->stringConstructor = 0;
+    d->booleanConstructor = 0;
+    d->numberConstructor = 0;
+    d->dateConstructor = 0;
+    d->regExpConstructor = 0;
+    d->errorConstructor = 0;
+    
+    d->evalErrorConstructor = 0;
+    d->rangeErrorConstructor = 0;
+    d->referenceErrorConstructor = 0;
+    d->syntaxErrorConstructor = 0;
+    d->typeErrorConstructor = 0;
+    d->URIErrorConstructor = 0;
+
+    // Prototypes
+    d->functionPrototype = new FunctionPrototype(exec);
+    d->objectPrototype = new ObjectPrototype(exec, d->functionPrototype);
+    d->functionPrototype->setPrototype(d->objectPrototype);
+
+    d->arrayPrototype = new ArrayPrototype(exec, d->objectPrototype);
+    d->stringPrototype = new StringPrototype(exec, d->objectPrototype);
+    d->booleanPrototype = new BooleanPrototype(exec, d->objectPrototype, d->functionPrototype);
+    d->numberPrototype = new NumberPrototype(exec, d->objectPrototype, d->functionPrototype);
+    d->datePrototype = new DatePrototype(exec, d->objectPrototype);
+    d->regExpPrototype = new RegExpPrototype(exec, d->objectPrototype, d->functionPrototype);;
+    d->errorPrototype = new ErrorPrototype(exec, d->objectPrototype, d->functionPrototype);
+    
+    d->evalErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, EvalError, "EvalError", "EvalError");
+    d->rangeErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, RangeError, "RangeError", "RangeError");
+    d->referenceErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, ReferenceError, "ReferenceError", "ReferenceError");
+    d->syntaxErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, SyntaxError, "SyntaxError", "SyntaxError");
+    d->typeErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, TypeError, "TypeError", "TypeError");
+    d->URIErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, URIError, "URIError", "URIError");
+
+    // Constructors
+    d->objectConstructor = new ObjectObjectImp(exec, d->objectPrototype, d->functionPrototype);
+    d->functionConstructor = new FunctionObjectImp(exec, d->functionPrototype);
+    d->arrayConstructor = new ArrayObjectImp(exec, d->functionPrototype, d->arrayPrototype);
+    d->stringConstructor = new StringObjectImp(exec, d->functionPrototype, d->stringPrototype);
+    d->booleanConstructor = new BooleanObjectImp(exec, d->functionPrototype, d->booleanPrototype);
+    d->numberConstructor = new NumberObjectImp(exec, d->functionPrototype, d->numberPrototype);
+    d->dateConstructor = new DateObjectImp(exec, d->functionPrototype, d->datePrototype);
+    d->regExpConstructor = new RegExpObjectImp(exec, d->functionPrototype, d->regExpPrototype);
+    d->errorConstructor = new ErrorObjectImp(exec, d->functionPrototype, d->errorPrototype);
+    
+    d->evalErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->evalErrorPrototype);
+    d->rangeErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->rangeErrorPrototype);
+    d->referenceErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->referenceErrorPrototype);
+    d->syntaxErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->syntaxErrorPrototype);
+    d->typeErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->typeErrorPrototype);
+    d->URIErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->URIErrorPrototype);
+    
+    d->functionPrototype->put(exec, exec->propertyNames().constructor, d->functionConstructor, DontEnum);
 
-    if (m_interpreter->m_currentExec)
-        m_interpreter->m_currentExec->mark();
+    d->objectPrototype->put(exec, exec->propertyNames().constructor, d->objectConstructor, DontEnum | DontDelete | ReadOnly);
+    d->functionPrototype->put(exec, exec->propertyNames().constructor, d->functionConstructor, DontEnum | DontDelete | ReadOnly);
+    d->arrayPrototype->put(exec, exec->propertyNames().constructor, d->arrayConstructor, DontEnum | DontDelete | ReadOnly);
+    d->booleanPrototype->put(exec, exec->propertyNames().constructor, d->booleanConstructor, DontEnum | DontDelete | ReadOnly);
+    d->stringPrototype->put(exec, exec->propertyNames().constructor, d->stringConstructor, DontEnum | DontDelete | ReadOnly);
+    d->numberPrototype->put(exec, exec->propertyNames().constructor, d->numberConstructor, DontEnum | DontDelete | ReadOnly);
+    d->datePrototype->put(exec, exec->propertyNames().constructor, d->dateConstructor, DontEnum | DontDelete | ReadOnly);
+    d->regExpPrototype->put(exec, exec->propertyNames().constructor, d->regExpConstructor, DontEnum | DontDelete | ReadOnly);
+    d->errorPrototype->put(exec, exec->propertyNames().constructor, d->errorConstructor, DontEnum | DontDelete | ReadOnly);
+    d->evalErrorPrototype->put(exec, exec->propertyNames().constructor, d->evalErrorConstructor, DontEnum | DontDelete | ReadOnly);
+    d->rangeErrorPrototype->put(exec, exec->propertyNames().constructor, d->rangeErrorConstructor, DontEnum | DontDelete | ReadOnly);
+    d->referenceErrorPrototype->put(exec, exec->propertyNames().constructor, d->referenceErrorConstructor, DontEnum | DontDelete | ReadOnly);
+    d->syntaxErrorPrototype->put(exec, exec->propertyNames().constructor, d->syntaxErrorConstructor, DontEnum | DontDelete | ReadOnly);
+    d->typeErrorPrototype->put(exec, exec->propertyNames().constructor, d->typeErrorConstructor, DontEnum | DontDelete | ReadOnly);
+    d->URIErrorPrototype->put(exec, exec->propertyNames().constructor, d->URIErrorConstructor, DontEnum | DontDelete | ReadOnly);
 
-    markIfNeeded(m_interpreter->m_globalExec.exception());
+    // Set global constructors
 
-    markIfNeeded(m_interpreter->m_Object);
-    markIfNeeded(m_interpreter->m_Function);
-    markIfNeeded(m_interpreter->m_Array);
-    markIfNeeded(m_interpreter->m_Boolean);
-    markIfNeeded(m_interpreter->m_String);
-    markIfNeeded(m_interpreter->m_Number);
-    markIfNeeded(m_interpreter->m_Date);
-    markIfNeeded(m_interpreter->m_RegExp);
-    markIfNeeded(m_interpreter->m_Error);
+    // FIXME: kjs_window.cpp checks Internal/DontEnum as a performance hack, to
+    // see that these values can be put directly without a check for override
+    // properties.
+
+    // FIXME: These properties should be handled by a static hash table.
+
+    putDirect("Object", d->objectConstructor, DontEnum);
+    putDirect("Function", d->functionConstructor, DontEnum);
+    putDirect("Array", d->arrayConstructor, DontEnum);
+    putDirect("Boolean", d->booleanConstructor, DontEnum);
+    putDirect("String", d->stringConstructor, DontEnum);
+    putDirect("Number", d->numberConstructor, DontEnum);
+    putDirect("Date", d->dateConstructor, DontEnum);
+    putDirect("RegExp", d->regExpConstructor, DontEnum);
+    putDirect("Error", d->errorConstructor, DontEnum);
+    putDirect("EvalError", d->evalErrorConstructor, Internal);
+    putDirect("RangeError", d->rangeErrorConstructor, Internal);
+    putDirect("ReferenceError", d->referenceErrorConstructor, Internal);
+    putDirect("SyntaxError", d->syntaxErrorConstructor, Internal);
+    putDirect("TypeError", d->typeErrorConstructor, Internal);
+    putDirect("URIError", d->URIErrorConstructor, Internal);
+
+    // Set global values.
+
+    putDirect("Math", new MathObjectImp(exec, d->objectPrototype), DontEnum);
+
+    putDirect("NaN", jsNaN(), DontEnum | DontDelete);
+    putDirect("Infinity", jsNumber(Inf), DontEnum | DontDelete);
+    putDirect("undefined", jsUndefined(), DontEnum | DontDelete);
+
+    // Set global functions.
+
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::Eval, 1, "eval"), DontEnum);
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::ParseInt, 2, "parseInt"), DontEnum);
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::ParseFloat, 1, "parseFloat"), DontEnum);
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::IsNaN, 1, "isNaN"), DontEnum);
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::IsFinite, 1, "isFinite"), DontEnum);
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::Escape, 1, "escape"), DontEnum);
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::UnEscape, 1, "unescape"), DontEnum);
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::DecodeURI, 1, "decodeURI"), DontEnum);
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::DecodeURIComponent, 1, "decodeURIComponent"), DontEnum);
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::EncodeURI, 1, "encodeURI"), DontEnum);
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::EncodeURIComponent, 1, "encodeURIComponent"), DontEnum);
+#ifndef NDEBUG
+    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::KJSPrint, 1, "kjsprint"), DontEnum);
+#endif
+
+    // Set prototype, and also insert the object prototype at the end of the chain.
+
+    setPrototype(prototype);
+    lastInPrototypeChain(this)->setPrototype(d->objectPrototype);
+}
+
+void JSGlobalObject::startTimeoutCheck()
+{
+    if (!d->timeoutCheckCount)
+        resetTimeoutCheck();
+    
+    ++d->timeoutCheckCount;
+}
+
+void JSGlobalObject::stopTimeoutCheck()
+{
+    --d->timeoutCheckCount;
+}
+
+void JSGlobalObject::resetTimeoutCheck()
+{
+    d->tickCount = 0;
+    d->ticksUntilNextTimeoutCheck = initialTickCountThreshold;
+    d->timeAtLastCheckTimeout = 0;
+    d->timeExecuting = 0;
+}
+
+bool JSGlobalObject::checkTimeout()
+{    
+    d->tickCount = 0;
+    
+    unsigned currentTime = getCurrentTime();
+
+    if (!d->timeAtLastCheckTimeout) {
+        // Suspicious amount of looping in a script -- start timing it
+        d->timeAtLastCheckTimeout = currentTime;
+        return false;
+    }
+
+    unsigned timeDiff = currentTime - d->timeAtLastCheckTimeout;
+
+    if (timeDiff == 0)
+        timeDiff = 1;
+    
+    d->timeExecuting += timeDiff;
+    d->timeAtLastCheckTimeout = currentTime;
+    
+    // Adjust the tick threshold so we get the next checkTimeout call in the interval specified in 
+    // preferredScriptCheckTimeInterval
+    d->ticksUntilNextTimeoutCheck = (unsigned)((float)preferredScriptCheckTimeInterval / timeDiff) * d->ticksUntilNextTimeoutCheck;
+
+    // If the new threshold is 0 reset it to the default threshold. This can happen if the timeDiff is higher than the
+    // preferred script check time interval.
+    if (d->ticksUntilNextTimeoutCheck == 0)
+        d->ticksUntilNextTimeoutCheck = initialTickCountThreshold;
+
+    if (d->timeoutTime && d->timeExecuting > d->timeoutTime) {
+        if (shouldInterruptScript())
+            return true;
+        
+        resetTimeoutCheck();
+    }
     
-    markIfNeeded(m_interpreter->m_ObjectPrototype);
-    markIfNeeded(m_interpreter->m_FunctionPrototype);
-    markIfNeeded(m_interpreter->m_ArrayPrototype);
-    markIfNeeded(m_interpreter->m_BooleanPrototype);
-    markIfNeeded(m_interpreter->m_StringPrototype);
-    markIfNeeded(m_interpreter->m_NumberPrototype);
-    markIfNeeded(m_interpreter->m_DatePrototype);
-    markIfNeeded(m_interpreter->m_RegExpPrototype);
-    markIfNeeded(m_interpreter->m_ErrorPrototype);
+    return false;
+}
+
+void JSGlobalObject::saveBuiltins(SavedBuiltins& builtins) const
+{
+    if (!builtins._internal)
+        builtins._internal = new SavedBuiltinsInternal;
+
+    builtins._internal->objectConstructor = d->objectConstructor;
+    builtins._internal->functionConstructor = d->functionConstructor;
+    builtins._internal->arrayConstructor = d->arrayConstructor;
+    builtins._internal->booleanConstructor = d->booleanConstructor;
+    builtins._internal->stringConstructor = d->stringConstructor;
+    builtins._internal->numberConstructor = d->numberConstructor;
+    builtins._internal->dateConstructor = d->dateConstructor;
+    builtins._internal->regExpConstructor = d->regExpConstructor;
+    builtins._internal->errorConstructor = d->errorConstructor;
+    builtins._internal->evalErrorConstructor = d->evalErrorConstructor;
+    builtins._internal->rangeErrorConstructor = d->rangeErrorConstructor;
+    builtins._internal->referenceErrorConstructor = d->referenceErrorConstructor;
+    builtins._internal->syntaxErrorConstructor = d->syntaxErrorConstructor;
+    builtins._internal->typeErrorConstructor = d->typeErrorConstructor;
+    builtins._internal->URIErrorConstructor = d->URIErrorConstructor;
     
-    markIfNeeded(m_interpreter->m_EvalError);
-    markIfNeeded(m_interpreter->m_RangeError);
-    markIfNeeded(m_interpreter->m_ReferenceError);
-    markIfNeeded(m_interpreter->m_SyntaxError);
-    markIfNeeded(m_interpreter->m_TypeError);
-    markIfNeeded(m_interpreter->m_UriError);
+    builtins._internal->objectPrototype = d->objectPrototype;
+    builtins._internal->functionPrototype = d->functionPrototype;
+    builtins._internal->arrayPrototype = d->arrayPrototype;
+    builtins._internal->booleanPrototype = d->booleanPrototype;
+    builtins._internal->stringPrototype = d->stringPrototype;
+    builtins._internal->numberPrototype = d->numberPrototype;
+    builtins._internal->datePrototype = d->datePrototype;
+    builtins._internal->regExpPrototype = d->regExpPrototype;
+    builtins._internal->errorPrototype = d->errorPrototype;
+    builtins._internal->evalErrorPrototype = d->evalErrorPrototype;
+    builtins._internal->rangeErrorPrototype = d->rangeErrorPrototype;
+    builtins._internal->referenceErrorPrototype = d->referenceErrorPrototype;
+    builtins._internal->syntaxErrorPrototype = d->syntaxErrorPrototype;
+    builtins._internal->typeErrorPrototype = d->typeErrorPrototype;
+    builtins._internal->URIErrorPrototype = d->URIErrorPrototype;
+}
+
+void JSGlobalObject::restoreBuiltins(const SavedBuiltins& builtins)
+{
+    if (!builtins._internal)
+        return;
+
+    d->objectConstructor = builtins._internal->objectConstructor;
+    d->functionConstructor = builtins._internal->functionConstructor;
+    d->arrayConstructor = builtins._internal->arrayConstructor;
+    d->booleanConstructor = builtins._internal->booleanConstructor;
+    d->stringConstructor = builtins._internal->stringConstructor;
+    d->numberConstructor = builtins._internal->numberConstructor;
+    d->dateConstructor = builtins._internal->dateConstructor;
+    d->regExpConstructor = builtins._internal->regExpConstructor;
+    d->errorConstructor = builtins._internal->errorConstructor;
+    d->evalErrorConstructor = builtins._internal->evalErrorConstructor;
+    d->rangeErrorConstructor = builtins._internal->rangeErrorConstructor;
+    d->referenceErrorConstructor = builtins._internal->referenceErrorConstructor;
+    d->syntaxErrorConstructor = builtins._internal->syntaxErrorConstructor;
+    d->typeErrorConstructor = builtins._internal->typeErrorConstructor;
+    d->URIErrorConstructor = builtins._internal->URIErrorConstructor;
+
+    d->objectPrototype = builtins._internal->objectPrototype;
+    d->functionPrototype = builtins._internal->functionPrototype;
+    d->arrayPrototype = builtins._internal->arrayPrototype;
+    d->booleanPrototype = builtins._internal->booleanPrototype;
+    d->stringPrototype = builtins._internal->stringPrototype;
+    d->numberPrototype = builtins._internal->numberPrototype;
+    d->datePrototype = builtins._internal->datePrototype;
+    d->regExpPrototype = builtins._internal->regExpPrototype;
+    d->errorPrototype = builtins._internal->errorPrototype;
+    d->evalErrorPrototype = builtins._internal->evalErrorPrototype;
+    d->rangeErrorPrototype = builtins._internal->rangeErrorPrototype;
+    d->referenceErrorPrototype = builtins._internal->referenceErrorPrototype;
+    d->syntaxErrorPrototype = builtins._internal->syntaxErrorPrototype;
+    d->typeErrorPrototype = builtins._internal->typeErrorPrototype;
+    d->URIErrorPrototype = builtins._internal->URIErrorPrototype;
+}
+
+void JSGlobalObject::mark()
+{
+    JSObject::mark();
+
+    if (d->currentExec)
+        d->currentExec->mark();
+
+    markIfNeeded(d->globalExec.exception());
+
+    markIfNeeded(d->objectConstructor);
+    markIfNeeded(d->functionConstructor);
+    markIfNeeded(d->arrayConstructor);
+    markIfNeeded(d->booleanConstructor);
+    markIfNeeded(d->stringConstructor);
+    markIfNeeded(d->numberConstructor);
+    markIfNeeded(d->dateConstructor);
+    markIfNeeded(d->regExpConstructor);
+    markIfNeeded(d->errorConstructor);
+    markIfNeeded(d->evalErrorConstructor);
+    markIfNeeded(d->rangeErrorConstructor);
+    markIfNeeded(d->referenceErrorConstructor);
+    markIfNeeded(d->syntaxErrorConstructor);
+    markIfNeeded(d->typeErrorConstructor);
+    markIfNeeded(d->URIErrorConstructor);
     
-    markIfNeeded(m_interpreter->m_EvalErrorPrototype);
-    markIfNeeded(m_interpreter->m_RangeErrorPrototype);
-    markIfNeeded(m_interpreter->m_ReferenceErrorPrototype);
-    markIfNeeded(m_interpreter->m_SyntaxErrorPrototype);
-    markIfNeeded(m_interpreter->m_TypeErrorPrototype);
-    markIfNeeded(m_interpreter->m_UriErrorPrototype);
+    markIfNeeded(d->objectPrototype);
+    markIfNeeded(d->functionPrototype);
+    markIfNeeded(d->arrayPrototype);
+    markIfNeeded(d->booleanPrototype);
+    markIfNeeded(d->stringPrototype);
+    markIfNeeded(d->numberPrototype);
+    markIfNeeded(d->datePrototype);
+    markIfNeeded(d->regExpPrototype);
+    markIfNeeded(d->errorPrototype);
+    markIfNeeded(d->evalErrorPrototype);
+    markIfNeeded(d->rangeErrorPrototype);
+    markIfNeeded(d->referenceErrorPrototype);
+    markIfNeeded(d->syntaxErrorPrototype);
+    markIfNeeded(d->typeErrorPrototype);
+    markIfNeeded(d->URIErrorPrototype);
 }
 
 ExecState* JSGlobalObject::globalExec()
 {
-    return &m_interpreter->m_globalExec;
+    return &d->globalExec;
 }
 
 } // namespace KJS
index 59272e2c6f105e643b46017d9d82218ba7015278..8f14b85b2acc4b527cfc27e9739e4e7fe1211a16 100644 (file)
@@ -1,7 +1,7 @@
 // -*- c-basic-offset: 4 -*-
 /*
  *  Copyright (C) 2007 Eric Seidel <eric@webkit.org>
- *  Copyright (C) 2007 Apple Ince. All rights reserved.
+ *  Copyright (C) 2007 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
 
 namespace KJS {
 
-    class Interpreter;
+    class ArrayObjectImp;
+    class ArrayPrototype;
+    class BooleanObjectImp;
+    class BooleanPrototype;
+    class DateObjectImp;
+    class DatePrototype;
+    class Debugger;
+    class ErrorObjectImp;
+    class ErrorPrototype;
+    class EvalError;
+    class EvalErrorPrototype;
+    class FunctionObjectImp;
+    class FunctionPrototype;
+    class JSGlobalObject;
+    class NativeErrorImp;
+    class NativeErrorPrototype;
+    class NumberObjectImp;
+    class NumberPrototype;
+    class ObjectObjectImp;
+    class ObjectPrototype;
+    class RangeError;
+    class RangeErrorPrototype;
+    class ReferenceError;
+    class ReferenceError;
+    class ReferenceErrorPrototype;
+    class RegExpObjectImp;
+    class RegExpPrototype;
+    class RuntimeMethod;
+    class SavedBuiltins;
+    class ScopeChain;
+    class StringObjectImp;
+    class StringPrototype;
+    class SyntaxErrorPrototype;
+    class TypeError;
+    class TypeErrorPrototype;
+    class UriError;
+    class UriErrorPrototype;
+
+    enum CompatMode { NativeMode, IECompat, NetscapeCompat };
 
     class JSGlobalObject : public JSObject {
+    protected:
+        struct JSGlobalObjectData {
+            JSGlobalObjectData(JSGlobalObject* globalObject)
+                : globalExec(globalObject, globalObject, 0)
+            {
+            }
+
+            JSGlobalObject* next;
+            JSGlobalObject* prev;
+
+            Debugger* debugger;
+            CompatMode compatMode;
+
+            ExecState globalExec;
+            ExecState* currentExec;
+            int recursion;
+
+            unsigned timeoutTime;
+            unsigned timeAtLastCheckTimeout;
+            unsigned timeExecuting;
+            unsigned timeoutCheckCount;
+            unsigned tickCount;
+            unsigned ticksUntilNextTimeoutCheck;
+
+            ObjectObjectImp* objectConstructor;
+            FunctionObjectImp* functionConstructor;
+            ArrayObjectImp* arrayConstructor;
+            BooleanObjectImp* booleanConstructor;
+            StringObjectImp* stringConstructor;
+            NumberObjectImp* numberConstructor;
+            DateObjectImp* dateConstructor;
+            RegExpObjectImp* regExpConstructor;
+            ErrorObjectImp* errorConstructor;
+            NativeErrorImp* evalErrorConstructor;
+            NativeErrorImp* rangeErrorConstructor;
+            NativeErrorImp* referenceErrorConstructor;
+            NativeErrorImp* syntaxErrorConstructor;
+            NativeErrorImp* typeErrorConstructor;
+            NativeErrorImp* URIErrorConstructor;
+
+            ObjectPrototype* objectPrototype;
+            FunctionPrototype* functionPrototype;
+            ArrayPrototype* arrayPrototype;
+            BooleanPrototype* booleanPrototype;
+            StringPrototype* stringPrototype;
+            NumberPrototype* numberPrototype;
+            DatePrototype* datePrototype;
+            RegExpPrototype* regExpPrototype;
+            ErrorPrototype* errorPrototype;
+            NativeErrorPrototype* evalErrorPrototype;
+            NativeErrorPrototype* rangeErrorPrototype;
+            NativeErrorPrototype* referenceErrorPrototype;
+            NativeErrorPrototype* syntaxErrorPrototype;
+            NativeErrorPrototype* typeErrorPrototype;
+            NativeErrorPrototype* URIErrorPrototype;
+        };
+
+    public:
+        JSGlobalObject()
+        {
+            init();
+        }
+
+    protected:
+        JSGlobalObject(JSValue* proto)
+            : JSObject(proto)
+        {
+            init();
+        }
+
     public:
-        JSGlobalObject() { }
-        JSGlobalObject(JSValue* proto) : JSObject(proto) { }
+        virtual ~JSGlobalObject();
+
+        // Linked list of all global objects.
+        static JSGlobalObject* head() { return s_head; }
+        JSGlobalObject* next() { return d->next; }
+
+        // Resets the global object to contain only built-in properties, sets
+        // the global object's prototype to "prototype," then adds the 
+        // default object prototype to the tail of the global object's 
+        // prototype chain.
+        void reset(JSValue* prototype);
 
-        Interpreter* interpreter() const { return m_interpreter.get(); }
-        void setInterpreter(std::auto_ptr<Interpreter> i) { m_interpreter = i; }
+        // The following accessors return pristine values, even if a script 
+        // replaces the global object's associated property.
+
+        ObjectObjectImp* objectConstructor() const { return d->objectConstructor; }
+        FunctionObjectImp* functionConstructor() const { return d->functionConstructor; }
+        ArrayObjectImp* arrayConstructor() const { return d->arrayConstructor; }
+        BooleanObjectImp* booleanConstructor() const { return d->booleanConstructor; }
+        StringObjectImp* stringConstructor() const{ return d->stringConstructor; }
+        NumberObjectImp* numberConstructor() const{ return d->numberConstructor; }
+        DateObjectImp* dateConstructor() const{ return d->dateConstructor; }
+        RegExpObjectImp* regExpConstructor() const { return d->regExpConstructor; }
+        ErrorObjectImp* errorConstructor() const { return d->errorConstructor; }
+        NativeErrorImp* evalErrorConstructor() const { return d->evalErrorConstructor; }
+        NativeErrorImp* rangeErrorConstructor() const { return d->rangeErrorConstructor; }
+        NativeErrorImp* referenceErrorConstructor() const { return d->referenceErrorConstructor; }
+        NativeErrorImp* syntaxErrorConstructor() const { return d->syntaxErrorConstructor; }
+        NativeErrorImp* typeErrorConstructor() const { return d->typeErrorConstructor; }
+        NativeErrorImp* URIErrorConstructor() const { return d->URIErrorConstructor; }
+
+        ObjectPrototype* objectPrototype() const { return d->objectPrototype; }
+        FunctionPrototype* functionPrototype() const { return d->functionPrototype; }
+        ArrayPrototype* arrayPrototype() const { return d->arrayPrototype; }
+        BooleanPrototype* booleanPrototype() const { return d->booleanPrototype; }
+        StringPrototype* stringPrototype() const { return d->stringPrototype; }
+        NumberPrototype* numberPrototype() const { return d->numberPrototype; }
+        DatePrototype* datePrototype() const { return d->datePrototype; }
+        RegExpPrototype* regExpPrototype() const { return d->regExpPrototype; }
+        ErrorPrototype* errorPrototype() const { return d->errorPrototype; }
+        NativeErrorPrototype* evalErrorPrototype() const { return d->evalErrorPrototype; }
+        NativeErrorPrototype* rangeErrorPrototype() const { return d->rangeErrorPrototype; }
+        NativeErrorPrototype* referenceErrorPrototype() const { return d->referenceErrorPrototype; }
+        NativeErrorPrototype* syntaxErrorPrototype() const { return d->syntaxErrorPrototype; }
+        NativeErrorPrototype* typeErrorPrototype() const { return d->typeErrorPrototype; }
+        NativeErrorPrototype* URIErrorPrototype() const { return d->URIErrorPrototype; }
+
+        void saveBuiltins(SavedBuiltins&) const;
+        void restoreBuiltins(const SavedBuiltins&);
+
+        void setTimeoutTime(unsigned timeoutTime) { d->timeoutTime = timeoutTime; }
+        void startTimeoutCheck();
+        void stopTimeoutCheck();
+        bool timedOut();
+
+        Debugger* debugger() const { return d->debugger; }
+        void setDebugger(Debugger* debugger) { d->debugger = debugger; }
+
+        void setCurrentExec(ExecState* exec) { d->currentExec = exec; }
+        ExecState* currentExec() const { return d->currentExec; }
+
+        // FIXME: Let's just pick one compatible behavior and go with it.
+        void setCompatMode(CompatMode mode) { d->compatMode = mode; }
+        CompatMode compatMode() const { return d->compatMode; }
+        
+        int recursion() { return d->recursion; }
+        void incRecursion() { ++d->recursion; }
+        void decRecursion() { --d->recursion; }
 
         virtual void mark();
 
@@ -47,10 +218,28 @@ namespace KJS {
 
         virtual bool isSafeScript(const JSGlobalObject*) const { return true; }
 
+    protected:
+        std::auto_ptr<JSGlobalObjectData> d;
+
     private:
-        std::auto_ptr<Interpreter> m_interpreter;
+        void init();
+
+        bool checkTimeout();
+        void resetTimeoutCheck();
+
+        static JSGlobalObject* s_head;
     };
 
+    inline bool JSGlobalObject::timedOut()
+    {
+        d->tickCount++;
+
+        if (d->tickCount != d->ticksUntilNextTimeoutCheck)
+            return false;
+
+        return checkTimeout();
+    }
+
 } // namespace KJS
 
 #endif // KJS_GlobalObject_h
index 8d2b3c9f77ed4eb4c8f3721667d485feb54aaeec..c3c91d541af688425e80b9043c3ab548302953dd 100644 (file)
@@ -36,12 +36,12 @@ JSObject *JSImmediate::toObject(const JSValue *v, ExecState *exec)
     else if (isBoolean(v)) {
         List args;
         args.append(const_cast<JSValue *>(v));
-        return exec->lexicalInterpreter()->builtinBoolean()->construct(exec, args);
+        return exec->lexicalGlobalObject()->booleanConstructor()->construct(exec, args);
     } else {
         ASSERT(isNumber(v));
         List args;
         args.append(const_cast<JSValue *>(v));
-        return exec->lexicalInterpreter()->builtinNumber()->construct(exec, args);
+        return exec->lexicalGlobalObject()->numberConstructor()->construct(exec, args);
     }
 }
 
index ae0e7f4ab3c34e5eec7bacc659e921d762275b8e..f6cda5d142f9256d1bf36a53c6f74b5e23537c03 100644 (file)
@@ -20,8 +20,8 @@
  *
  */
 
-#ifndef KJS_INTERPRETER_LOCK_H
-#define KJS_INTERPRETER_LOCK_H
+#ifndef KJS_JSLock_h
+#define KJS_JSLock_h
 
 #include <wtf/Assertions.h>
 #include <wtf/Noncopyable.h>
@@ -78,4 +78,4 @@ namespace KJS {
 
 } // namespace
 
-#endif // KJS_INTERPRETER_LOCK_H
+#endif // KJS_JSLock_h
index 5b6d1d1fed8b787979e18da8851cbbbe734ba463..9901e41b97200fd04cd307117c166e3a677a5bb2 100644 (file)
 #define SavedBuiltins_H
 
 #include "protect.h"
+#include "object_object.h"
+#include "string_object.h"
+#include "error_object.h"
+#include "regexp_object.h"
+#include "array_object.h"
+#include "bool_object.h"
+#include "date_object.h"
+#include "number_object.h"
+#include "math_object.h"
 
 namespace KJS {
     
-class SavedBuiltinsInternal;
+struct SavedBuiltinsInternal {
+    ProtectedPtr<ObjectObjectImp> objectConstructor;
+    ProtectedPtr<FunctionObjectImp> functionConstructor;
+    ProtectedPtr<ArrayObjectImp> arrayConstructor;
+    ProtectedPtr<BooleanObjectImp> booleanConstructor;
+    ProtectedPtr<StringObjectImp> stringConstructor;
+    ProtectedPtr<NumberObjectImp> numberConstructor;
+    ProtectedPtr<DateObjectImp> dateConstructor;
+    ProtectedPtr<RegExpObjectImp> regExpConstructor;
+    ProtectedPtr<ErrorObjectImp> errorConstructor;
+    ProtectedPtr<NativeErrorImp> evalErrorConstructor;
+    ProtectedPtr<NativeErrorImp> rangeErrorConstructor;
+    ProtectedPtr<NativeErrorImp> referenceErrorConstructor;
+    ProtectedPtr<NativeErrorImp> syntaxErrorConstructor;
+    ProtectedPtr<NativeErrorImp> typeErrorConstructor;
+    ProtectedPtr<NativeErrorImp> URIErrorConstructor;
+    
+    ProtectedPtr<ObjectPrototype> objectPrototype;
+    ProtectedPtr<FunctionPrototype> functionPrototype;
+    ProtectedPtr<ArrayPrototype> arrayPrototype;
+    ProtectedPtr<BooleanPrototype> booleanPrototype;
+    ProtectedPtr<StringPrototype> stringPrototype;
+    ProtectedPtr<NumberPrototype> numberPrototype;
+    ProtectedPtr<DatePrototype> datePrototype;
+    ProtectedPtr<RegExpPrototype> regExpPrototype;
+    ProtectedPtr<ErrorPrototype> errorPrototype;
+    ProtectedPtr<NativeErrorPrototype> evalErrorPrototype;
+    ProtectedPtr<NativeErrorPrototype> rangeErrorPrototype;
+    ProtectedPtr<NativeErrorPrototype> referenceErrorPrototype;
+    ProtectedPtr<NativeErrorPrototype> syntaxErrorPrototype;
+    ProtectedPtr<NativeErrorPrototype> typeErrorPrototype;
+    ProtectedPtr<NativeErrorPrototype> URIErrorPrototype;
+};
 
 class SavedBuiltins {
-    friend class Interpreter;
+    friend class JSGlobalObject;
 public:
-    SavedBuiltins();
-    ~SavedBuiltins();
-private:
-    SavedBuiltinsInternal *_internal;
-};
+    SavedBuiltins()
+        : _internal(0)
+    {
+    }
+
+    ~SavedBuiltins()
+    {
+        delete _internal;
+    }
 
-class SavedBuiltinsInternal {
-    friend class Interpreter;
 private:
-    ProtectedPtr<ObjectObjectImp> m_Object;
-    ProtectedPtr<FunctionObjectImp> m_Function;
-    ProtectedPtr<ArrayObjectImp> m_Array;
-    ProtectedPtr<BooleanObjectImp> m_Boolean;
-    ProtectedPtr<StringObjectImp> m_String;
-    ProtectedPtr<NumberObjectImp> m_Number;
-    ProtectedPtr<DateObjectImp> m_Date;
-    ProtectedPtr<RegExpObjectImp> m_RegExp;
-    ProtectedPtr<ErrorObjectImp> m_Error;
-    
-    ProtectedPtr<ObjectPrototype> m_ObjectPrototype;
-    ProtectedPtr<FunctionPrototype> m_FunctionPrototype;
-    ProtectedPtr<ArrayPrototype> m_ArrayPrototype;
-    ProtectedPtr<BooleanPrototype> m_BooleanPrototype;
-    ProtectedPtr<StringPrototype> m_StringPrototype;
-    ProtectedPtr<NumberPrototype> m_NumberPrototype;
-    ProtectedPtr<DatePrototype> m_DatePrototype;
-    ProtectedPtr<RegExpPrototype> m_RegExpPrototype;
-    ProtectedPtr<ErrorPrototype> m_ErrorPrototype;
-    
-    ProtectedPtr<NativeErrorImp> m_EvalError;
-    ProtectedPtr<NativeErrorImp> m_RangeError;
-    ProtectedPtr<NativeErrorImp> m_ReferenceError;
-    ProtectedPtr<NativeErrorImp> m_SyntaxError;
-    ProtectedPtr<NativeErrorImp> m_TypeError;
-    ProtectedPtr<NativeErrorImp> m_UriError;
-    
-    ProtectedPtr<NativeErrorPrototype> m_EvalErrorPrototype;
-    ProtectedPtr<NativeErrorPrototype> m_RangeErrorPrototype;
-    ProtectedPtr<NativeErrorPrototype> m_ReferenceErrorPrototype;
-    ProtectedPtr<NativeErrorPrototype> m_SyntaxErrorPrototype;
-    ProtectedPtr<NativeErrorPrototype> m_TypeErrorPrototype;
-    ProtectedPtr<NativeErrorPrototype> m_UriErrorPrototype;
+    SavedBuiltinsInternal* _internal;
 };
 
 } // namespace
index dc8b58ff21aea8c66512b6ca6cd3794d6cd27243..cc91de3e4692304ea58574b65dc38260eb836a77 100644 (file)
@@ -483,7 +483,7 @@ struct CompareWithCompareFunctionArguments {
     CompareWithCompareFunctionArguments(ExecState *e, JSObject *cf)
         : exec(e)
         , compareFunction(cf)
-        , globalObject(e->dynamicInterpreter()->globalObject())
+        , globalObject(e->dynamicGlobalObject())
     {
     }
 
index b85d3ad71eca53722f663c75699c392d2e37960c..38608339394ac6c8d5866e3c3c4e4e08cd2ace32 100644 (file)
@@ -225,7 +225,7 @@ JSValue* ArrayProtoFuncJoin::callAsFunction(ExecState* exec, JSObject* thisObj,
 
 JSValue* ArrayProtoFuncConcat::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
 {
-    JSObject* arr = static_cast<JSObject*>(exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty()));
+    JSObject* arr = static_cast<JSObject*>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, List::empty()));
     int n = 0;
     JSValue *curArg = thisObj;
     JSObject *curObj = static_cast<JSObject *>(thisObj);
@@ -333,7 +333,7 @@ JSValue* ArrayProtoFuncSlice::callAsFunction(ExecState* exec, JSObject* thisObj,
     // http://developer.netscape.com/docs/manuals/js/client/jsref/array.htm#1193713 or 15.4.4.10
 
     // We return a new array
-    JSObject *resObj = static_cast<JSObject *>(exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty()));
+    JSObject *resObj = static_cast<JSObject *>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec,List::empty()));
     JSValue* result = resObj;
     double begin = args[0]->toInteger(exec);
     unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
@@ -420,7 +420,7 @@ JSValue* ArrayProtoFuncSort::callAsFunction(ExecState* exec, JSObject* thisObj,
                 List l;
                 l.append(jObj);
                 l.append(minObj);
-                cmp = sortFunction->call(exec, exec->dynamicInterpreter()->globalObject(), l)->toNumber(exec);
+                cmp = sortFunction->call(exec, exec->dynamicGlobalObject(), l)->toNumber(exec);
             } else {
               cmp = (jObj->toString(exec) < minObj->toString(exec)) ? -1 : 1;
             }
@@ -449,7 +449,7 @@ JSValue* ArrayProtoFuncSort::callAsFunction(ExecState* exec, JSObject* thisObj,
 JSValue* ArrayProtoFuncSplice::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
 {
     // 15.4.4.12 - oh boy this is huge
-    JSObject *resObj = static_cast<JSObject *>(exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty()));
+    JSObject *resObj = static_cast<JSObject *>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, List::empty()));
     JSValue* result = resObj;
     unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
     int begin = args[0]->toUInt32(exec);
@@ -526,8 +526,8 @@ JSValue* ArrayProtoFuncFilter::callAsFunction(ExecState* exec, JSObject* thisObj
     if (!eachFunction->implementsCall())
         return throwError(exec, TypeError);
     
-    JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1]->toObject(exec);
-    JSObject *resultArray = static_cast<JSObject*>(exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty()));
+    JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
+    JSObject *resultArray = static_cast<JSObject*>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, List::empty()));
 
     unsigned filterIndex = 0;
     unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
@@ -559,13 +559,13 @@ JSValue* ArrayProtoFuncMap::callAsFunction(ExecState* exec, JSObject* thisObj, c
     if (!eachFunction->implementsCall())
         return throwError(exec, TypeError);
     
-    JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1]->toObject(exec);
+    JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
 
     unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
 
     List mapArgs;
     mapArgs.append(jsNumber(length));
-    JSObject* resultArray = static_cast<JSObject*>(exec->lexicalInterpreter()->builtinArray()->construct(exec, mapArgs));
+    JSObject* resultArray = static_cast<JSObject*>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, mapArgs));
 
     for (unsigned k = 0; k < length && !exec->hadException(); ++k) {
         PropertySlot slot;
@@ -599,7 +599,7 @@ JSValue* ArrayProtoFuncEvery::callAsFunction(ExecState* exec, JSObject* thisObj,
     if (!eachFunction->implementsCall())
         return throwError(exec, TypeError);
     
-    JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1]->toObject(exec);
+    JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
     
     JSValue* result = jsBoolean(true);
     
@@ -634,7 +634,7 @@ JSValue* ArrayProtoFuncForEach::callAsFunction(ExecState* exec, JSObject* thisOb
     if (!eachFunction->implementsCall())
         return throwError(exec, TypeError);
 
-    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1]->toObject(exec);
+    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
 
     unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
     for (unsigned k = 0; k < length && !exec->hadException(); ++k) {
@@ -659,7 +659,7 @@ JSValue* ArrayProtoFuncSome::callAsFunction(ExecState* exec, JSObject* thisObj,
     if (!eachFunction->implementsCall())
         return throwError(exec, TypeError);
 
-    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1]->toObject(exec);
+    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
 
     JSValue* result = jsBoolean(false);
 
@@ -769,11 +769,11 @@ JSObject *ArrayObjectImp::construct(ExecState *exec, const List &args)
     uint32_t n = args[0]->toUInt32(exec);
     if (n != args[0]->toNumber(exec))
       return throwError(exec, RangeError, "Array size is not a small enough positive integer.");
-    return new ArrayInstance(exec->lexicalInterpreter()->builtinArrayPrototype(), n);
+    return new ArrayInstance(exec->lexicalGlobalObject()->arrayPrototype(), n);
   }
 
   // otherwise the array is constructed with the arguments in it
-  return new ArrayInstance(exec->lexicalInterpreter()->builtinArrayPrototype(), args);
+  return new ArrayInstance(exec->lexicalGlobalObject()->arrayPrototype(), args);
 }
 
 // ECMA 15.6.1
index 916fe53ce555198321291424dbda3e83148407d4..19783a9e23f85ec363e72b4e085074bcba94583e 100644 (file)
@@ -45,8 +45,6 @@ BooleanInstance::BooleanInstance(JSObject *proto)
 BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectProto, FunctionPrototype* funcProto)
   : BooleanInstance(objectProto)
 {
-  // The constructor will be added later by Interpreter::Interpreter()
-
   putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ToString, 0, exec->propertyNames().toString), DontEnum);
   putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ValueOf, 0, exec->propertyNames().valueOf),  DontEnum);
   setInternalValue(jsBoolean(false));
@@ -101,7 +99,7 @@ bool BooleanObjectImp::implementsConstruct() const
 // ECMA 15.6.2
 JSObject *BooleanObjectImp::construct(ExecState *exec, const List &args)
 {
-  BooleanInstance *obj(new BooleanInstance(exec->lexicalInterpreter()->builtinBooleanPrototype()));
+  BooleanInstance *obj(new BooleanInstance(exec->lexicalGlobalObject()->booleanPrototype()));
 
   bool b;
   if (args.size() > 0)
index 9c938654fa8445a173737d0d48a1e6bec25744c4..01d7f23d2dc1197bc243cb603bc746452a58ecd7 100644 (file)
@@ -962,7 +962,7 @@ bool Collector::collect()
   
   bool newMemoryFull = (numLiveObjects >= KJS_MEM_LIMIT);
   if (newMemoryFull && newMemoryFull != memoryFull)
-      reportOutOfMemoryToAllInterpreters();
+      reportOutOfMemoryToAllExecStates();
   memoryFull = newMemoryFull;
 
   return numLiveObjects < originalLiveObjects;
@@ -973,15 +973,15 @@ size_t Collector::size()
   return primaryHeap.numLiveObjects + numberHeap.numLiveObjects; 
 }
 
-size_t Collector::numInterpreters()
+size_t Collector::numGlobalObjects()
 {
   size_t count = 0;
-  if (Interpreter::s_hook) {
-    Interpreter* scr = Interpreter::s_hook;
+  if (JSGlobalObject::head()) {
+    JSGlobalObject* o = JSGlobalObject::head();
     do {
       ++count;
-      scr = scr->next;
-    } while (scr != Interpreter::s_hook);
+      o = o->next();
+    } while (o != JSGlobalObject::head());
   }
   return count;
 }
@@ -1041,19 +1041,17 @@ bool Collector::isBusy()
     return (primaryHeap.operationInProgress != NoOperation) | (numberHeap.operationInProgress != NoOperation);
 }
 
-void Collector::reportOutOfMemoryToAllInterpreters()
+void Collector::reportOutOfMemoryToAllExecStates()
 {
-    if (!Interpreter::s_hook)
+    JSGlobalObject* o = JSGlobalObject::head();
+    if (!o)
         return;
     
-    Interpreter* interpreter = Interpreter::s_hook;
     do {
-        ExecState* exec = interpreter->currentExec() ? interpreter->currentExec() : interpreter->globalObject()->globalExec();
-        
+        ExecState* exec = o->currentExec() ? o->currentExec() : o->globalExec();
         exec->setException(Error::create(exec, GeneralError, "Out of memory"));
-        
-        interpreter = interpreter->next;
-    } while(interpreter != Interpreter::s_hook);
+        o = o->next();
+    } while(o != JSGlobalObject::head());
 }
 
 } // namespace KJS
index c8372f7d01c1aa69c95ea00078764fe2698a84de..ed1a68027b787f9344a92fda8316a359ee8b0223 100644 (file)
@@ -54,7 +54,7 @@ namespace KJS {
     
     static void collectOnMainThreadOnly(JSValue*);
 
-    static size_t numInterpreters();
+    static size_t numGlobalObjects();
     static size_t numProtectedObjects();
     static HashCountedSet<const char*>* rootObjectTypeCounts();
 
@@ -87,7 +87,7 @@ namespace KJS {
 
     static size_t mainThreadOnlyObjectCount;
     static bool memoryFull;
-    static void reportOutOfMemoryToAllInterpreters();
+    static void reportOutOfMemoryToAllExecStates();
   };
 
   // tunable parameters
index 2107fae71bc177dd77bab4b515714c9554adbb2c..9634d3f635ff0f80617a2ac94ca6331e88c97cd0 100644 (file)
@@ -502,7 +502,7 @@ JSObject *DateObjectImp::construct(ExecState *exec, const List &args)
     }
   }
   
-  DateInstance *ret = new DateInstance(exec->lexicalInterpreter()->builtinDatePrototype());
+  DateInstance *ret = new DateInstance(exec->lexicalGlobalObject()->datePrototype());
   ret->setInternalValue(jsNumber(timeClip(value)));
   return ret;
 }
@@ -1806,7 +1806,7 @@ JSValue* DateProtoFuncGetYear::callAsFunction(ExecState* exec, JSObject* thisObj
     msToGregorianDateTime(milli, utc, t);
 
     // IE returns the full year even in getYear.
-    if (exec->dynamicInterpreter()->compatMode() == Interpreter::IECompat)
+    if (exec->dynamicGlobalObject()->compatMode() == IECompat)
         return jsNumber(1900 + t.year);
     return jsNumber(t.year);
 }
index 3ec3ea4d3550f8508d6107ecb52e02c6ea6f11e0..884e9c8ccf7d25dc112df16b110e9e1db4d2faef 100644 (file)
@@ -31,13 +31,13 @@ using namespace KJS;
 // ------------------------------ Debugger -------------------------------------
 
 namespace KJS {
-  struct AttachedInterpreter
+  struct AttachedGlobalObject
   {
   public:
-    AttachedInterpreter(Interpreter *i, AttachedInterpreter *ai) : interp(i), next(ai) { ++Debugger::debuggersPresent; }
-    ~AttachedInterpreter() { --Debugger::debuggersPresent; }
-    Interpreter *interp;
-    AttachedInterpreter *next;
+    AttachedGlobalObject(JSGlobalObject* o, AttachedGlobalObject* ai) : globalObj(o), next(ai) { ++Debugger::debuggersPresent; }
+    ~AttachedGlobalObject() { --Debugger::debuggersPresent; }
+    JSGlobalObject* globalObj;
+    AttachedGlobalObject* next;
   };
 
 }
@@ -55,44 +55,44 @@ Debugger::~Debugger()
   delete rep;
 }
 
-void Debugger::attach(Interpreter* interp)
+void Debugger::attach(JSGlobalObject* globalObject)
 {
-  Debugger *other = interp->debugger();
+  Debugger* other = globalObject->debugger();
   if (other == this)
     return;
   if (other)
-    other->detach(interp);
-  interp->setDebugger(this);
-  rep->interps = new AttachedInterpreter(interp, rep->interps);
+    other->detach(globalObject);
+  globalObject->setDebugger(this);
+  rep->globalObjects = new AttachedGlobalObject(globalObject, rep->globalObjects);
 }
 
-void Debugger::detach(Interpreter* interp)
+void Debugger::detach(JSGlobalObject* globalObj)
 {
-  // iterate the addresses where AttachedInterpreter pointers are stored
+  // iterate the addresses where AttachedGlobalObject pointers are stored
   // so we can unlink items from the list
-  AttachedInterpreter **p = &rep->interps;
-  AttachedInterpreter *q;
+  AttachedGlobalObject **p = &rep->globalObjects;
+  AttachedGlobalObject *q;
   while ((q = *p)) {
-    if (!interp || q->interp == interp) {
+    if (!globalObj || q->globalObj == globalObj) {
       *p = q->next;
-      q->interp->setDebugger(0);
+      q->globalObj->setDebugger(0);
       delete q;
     } else
       p = &q->next;
   }
 
-  if (interp)
-    latestExceptions.remove(interp);
+  if (globalObj)
+    latestExceptions.remove(globalObj);
   else
     latestExceptions.clear();
 }
 
 bool Debugger::hasHandledException(ExecState *exec, JSValue *exception)
 {
-    if (latestExceptions.get(exec->dynamicInterpreter()).get() == exception)
+    if (latestExceptions.get(exec->dynamicGlobalObject()).get() == exception)
         return true;
 
-    latestExceptions.set(exec->dynamicInterpreter(), exception);
+    latestExceptions.set(exec->dynamicGlobalObject(), exception);
     return false;
 }
 
index 70a5ffdb5009753f92e34e864589d790b266be36..688d192d44e1dd1f7e5530bf74c06c1831908162 100644 (file)
@@ -29,7 +29,6 @@
 namespace KJS {
 
   class DebuggerImp;
-  class Interpreter;
   class ExecState;
   class JSObject;
   class JSValue;
@@ -58,7 +57,7 @@ namespace KJS {
     Debugger();
 
     /**
-     * Destroys the debugger. If the debugger is attached to any interpreters,
+     * Destroys the debugger. If the debugger is attached to any global objects,
      * it is automatically detached.
      */
     virtual ~Debugger();
@@ -66,31 +65,30 @@ namespace KJS {
     DebuggerImp *imp() const { return rep; }
 
     /**
-     * Attaches the debugger to specified interpreter. This will cause this
-     * object to receive notification of events from the interpreter.
+     * Attaches the debugger to specified global object. This will cause this
+     * object to receive notification of events during execution.
      *
-     * If the interpreter is deleted, the debugger will automatically be
-     * detached.
+     * If the global object is deleted, it will detach the debugger.
      *
-     * Note: only one debugger can be attached to an interpreter at a time.
-     * Attaching another debugger to the same interpreter will cause the
-     * original debugger to be detached from that interpreter.
+     * Note: only one debugger can be attached to a global object at a time.
+     * Attaching another debugger to the same global object will cause the
+     * original debugger to be detached.
      *
-     * @param interp The interpreter to attach to
+     * @param The global object to attach to.
      *
      * @see detach()
      */
-    void attach(Interpreter *interp);
+    void attach(JSGlobalObject*);
 
     /**
-     * Detach the debugger from an interpreter
+     * Detach the debugger from a global object.
      *
-     * @param interp The interpreter to detach from. If 0, the debugger will be
-     * detached from all interpreters to which it is attached.
+     * @param The global object to detach from. If 0, the debugger will be
+     * detached from all global objects to which it is attached.
      *
      * @see attach()
      */
-    void detach(Interpreter *interp);
+    void detach(JSGlobalObject*);
 
     /**
      * Called to notify the debugger that some javascript source code has
@@ -215,7 +213,7 @@ namespace KJS {
 
   private:
     DebuggerImp *rep;
-    HashMap<Interpreter*, ProtectedPtr<JSValue> > latestExceptions;
+    HashMap<JSGlobalObject*, ProtectedPtr<JSValue> > latestExceptions;
 
   public:
     static int debuggersPresent;
index 0697f107bd22d8f6c380dcb0de8eda9791b60e3f..74d1bae4ccf624d35a3cf5232c17c5d94e433fff 100644 (file)
@@ -24,7 +24,6 @@
 #include "value.h"
 #include "object.h"
 #include "types.h"
-#include "interpreter.h"
 #include "operations.h"
 #include "error_object.h"
 //#include "debugger.h"
@@ -98,7 +97,7 @@ bool ErrorObjectImp::implementsConstruct() const
 // ECMA 15.9.3
 JSObject* ErrorObjectImp::construct(ExecState* exec, const List &args)
 {
-  JSObject* proto = static_cast<JSObject*>(exec->lexicalInterpreter()->builtinErrorPrototype());
+  JSObject* proto = static_cast<JSObject*>(exec->lexicalGlobalObject()->errorPrototype());
   JSObject* imp = new ErrorInstance(proto);
   JSObject* obj(imp);
 
index 8e082cc800f90510d076f6323d9d0860667e61ed..61b9647d2a48d74de879e5130c034a7e9ac65b38 100644 (file)
@@ -55,7 +55,7 @@ namespace KJS {
 const ClassInfo FunctionImp::info = { "Function", &InternalFunctionImp::info, 0 };
 
 FunctionImp::FunctionImp(ExecState* exec, const Identifier& name, FunctionBodyNode* b, const ScopeChain& sc)
-  : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
+  : InternalFunctionImp(exec->lexicalGlobalObject()->functionPrototype(), name)
   , body(b)
   , _scope(sc)
 {
@@ -69,11 +69,8 @@ void FunctionImp::mark()
 
 JSValue* FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
 {
-  JSGlobalObject* globalObj = exec->dynamicInterpreter()->globalObject();
-
   // enter a new execution context
-  ExecState newExec(exec->dynamicInterpreter(), globalObj, thisObj, body.get(),
-                    FunctionCode, exec, this, &args);
+  ExecState newExec(exec->dynamicGlobalObject(), thisObj, body.get(), FunctionCode, exec, exec->dynamicGlobalObject()->currentExec(), this, &args);
   if (exec->hadException())
     newExec.setException(exec->exception());
 
@@ -204,7 +201,7 @@ JSObject* FunctionImp::construct(ExecState* exec, const List& args)
   if (p->isObject())
     proto = static_cast<JSObject*>(p);
   else
-    proto = exec->lexicalInterpreter()->builtinObjectPrototype();
+    proto = exec->lexicalGlobalObject()->objectPrototype();
 
   JSObject* obj(new JSObject(proto));
 
@@ -299,7 +296,7 @@ const ClassInfo Arguments::info = { "Arguments", 0, 0 };
 
 // ECMA 10.1.8
 Arguments::Arguments(ExecState* exec, FunctionImp* func, const List& args, ActivationImp* act)
-: JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()), 
+: JSObject(exec->lexicalGlobalObject()->objectPrototype()), 
 _activationObject(act),
 indexToNameMap(func, args)
 {
@@ -744,7 +741,7 @@ JSValue* GlobalFuncImp::callAsFunction(ExecState* exec, JSObject* thisObj, const
         UString errMsg;
         RefPtr<ProgramNode> progNode(parser().parseProgram(UString(), 0, s.data(), s.size(), &sourceId, &errLine, &errMsg));
 
-        Debugger* dbg = exec->dynamicInterpreter()->debugger();
+        Debugger* dbg = exec->dynamicGlobalObject()->debugger();
         if (dbg) {
           bool cont = dbg->sourceParsed(exec, sourceId, UString(), s, 0, errLine, errMsg);
           if (!cont)
@@ -755,12 +752,12 @@ JSValue* GlobalFuncImp::callAsFunction(ExecState* exec, JSObject* thisObj, const
         if (!progNode)
           return throwError(exec, SyntaxError, errMsg, errLine, sourceId, NULL);
 
-        bool switchGlobal = thisObj && thisObj != exec->dynamicInterpreter()->globalObject();
-          
+        bool switchGlobal = thisObj && thisObj != exec->dynamicGlobalObject() && thisObj->isGlobalObject();
+
         // enter a new execution context
-        Interpreter* interpreter = switchGlobal ? static_cast<JSGlobalObject*>(thisObj)->interpreter() : exec->dynamicInterpreter();
+        JSGlobalObject* globalObject = switchGlobal ? static_cast<JSGlobalObject*>(thisObj) : exec->dynamicGlobalObject();
         JSObject* thisVal = static_cast<JSObject*>(exec->thisValue());
-        ExecState newExec(interpreter, interpreter->globalObject(), thisVal, progNode.get(), EvalCode, exec);
+        ExecState newExec(globalObject, thisVal, progNode.get(), EvalCode, exec, globalObject->currentExec());
         if (exec->hadException())
             newExec.setException(exec->exception());
           
index 33d3f70d52f020c3a5646feac1bf248f3744f076..140ca3692eb481346067f5141f2b48eccb86da2c 100644 (file)
@@ -103,7 +103,7 @@ JSValue* FunctionProtoFunc::callAsFunction(ExecState* exec, JSObject* thisObj, c
 
     JSObject *applyThis;
     if (thisArg->isUndefinedOrNull())
-      applyThis = exec->dynamicInterpreter()->globalObject();
+      applyThis = exec->dynamicGlobalObject();
     else
       applyThis = thisArg->toObject(exec);
 
@@ -133,7 +133,7 @@ JSValue* FunctionProtoFunc::callAsFunction(ExecState* exec, JSObject* thisObj, c
 
     JSObject *callThis;
     if (thisArg->isUndefinedOrNull())
-      callThis = exec->dynamicInterpreter()->globalObject();
+      callThis = exec->dynamicGlobalObject();
     else
       callThis = thisArg->toObject(exec);
 
@@ -191,7 +191,7 @@ JSObject* FunctionObjectImp::construct(ExecState* exec, const List& args, const
   RefPtr<FunctionBodyNode> functionBody = parser().parseFunctionBody(sourceURL, lineNumber, body.data(), body.size(), &sourceId, &errLine, &errMsg);
 
   // notify debugger that source has been parsed
-  Debugger *dbg = exec->dynamicInterpreter()->debugger();
+  Debugger *dbg = exec->dynamicGlobalObject()->debugger();
   if (dbg) {
     // send empty sourceURL to indicate constructed code
     bool cont = dbg->sourceParsed(exec, sourceId, UString(), body, lineNumber, errLine, errMsg);
@@ -208,7 +208,7 @@ JSObject* FunctionObjectImp::construct(ExecState* exec, const List& args, const
     return throwError(exec, SyntaxError, errMsg, errLine, sourceId, sourceURL);
 
   ScopeChain scopeChain;
-  scopeChain.push(exec->lexicalInterpreter()->globalObject());
+  scopeChain.push(exec->lexicalGlobalObject());
 
   FunctionImp* fimp = new FunctionImp(exec, functionName, functionBody.get(), scopeChain);
   
@@ -245,7 +245,7 @@ JSObject* FunctionObjectImp::construct(ExecState* exec, const List& args, const
   
   List consArgs;
 
-  JSObject* objCons = exec->lexicalInterpreter()->builtinObject();
+  JSObject* objCons = exec->lexicalGlobalObject()->objectConstructor();
   JSObject* prototype = objCons->construct(exec,List::empty());
   prototype->put(exec, exec->propertyNames().constructor, fimp, DontEnum|DontDelete|ReadOnly);
   fimp->put(exec, exec->propertyNames().prototype, prototype, Internal|DontDelete);
index d8589e82fe4c7fa978aa817523b4b3f59befa1ee..7d6bff47d9a508e0f82ab1d00df3b8769a791639 100644 (file)
@@ -28,7 +28,6 @@
 #include "value.h"
 #include "object.h"
 #include "types.h"
-#include "interpreter.h"
 #include "nodes.h"
 #include "lexer.h"
 #include "internal.h"
index 125244e2e66ed534153b0dd395d57baf332122e7..74e4e998f3c6c401d1ce4cf3bd1df3789ade58b1 100644 (file)
@@ -80,7 +80,7 @@ UString StringImp::toString(ExecState *) const
 
 JSObject* StringImp::toObject(ExecState *exec) const
 {
-    return new StringInstance(exec->lexicalInterpreter()->builtinStringPrototype(), const_cast<StringImp*>(this));
+    return new StringInstance(exec->lexicalGlobalObject()->stringPrototype(), const_cast<StringImp*>(this));
 }
 
 // ------------------------------ NumberImp ------------------------------------
@@ -118,7 +118,7 @@ JSObject *NumberImp::toObject(ExecState *exec) const
 {
   List args;
   args.append(const_cast<NumberImp*>(this));
-  return static_cast<JSObject *>(exec->lexicalInterpreter()->builtinNumber()->construct(exec,args));
+  return static_cast<JSObject *>(exec->lexicalGlobalObject()->numberConstructor()->construct(exec,args));
 }
 
 bool NumberImp::getUInt32(uint32_t& uint32) const
index c4e5c77c822b3cb3c977a32768604add6cd29a2e..51438b3e2e45d726919c9dd996282c4e05c0b64f 100644 (file)
@@ -25,7 +25,6 @@
 #define INTERNAL_H
 
 #include "JSType.h"
-#include "interpreter.h"
 #include "object.h"
 #include "protect.h"
 #include "scope_chain.h"
@@ -98,19 +97,19 @@ namespace KJS {
   //                            Evaluation
   // ---------------------------------------------------------------------------
 
-  struct AttachedInterpreter;
+  struct AttachedGlobalObject;
   class DebuggerImp {
   public:
 
     DebuggerImp() {
-      interps = 0;
+      globalObjects = 0;
       isAborted = false;
     }
 
     void abort() { isAborted = true; }
     bool aborted() const { return isAborted; }
 
-    AttachedInterpreter *interps;
+    AttachedGlobalObject* globalObjects;
     bool isAborted;
   };
 
index fded882a241e08a55c8f18f9038b66ceb95b5f44..4fb3764c1629eb480436fe6d7ef56618e4a7cdaf 100644 (file)
@@ -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, 2007 Apple Inc.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
 
 namespace KJS {
 
-// Default number of ticks before a timeout check should be done.
-static const int initialTickCountThreshold = 255;
-
-// Preferred number of milliseconds between each timeout check
-static const int preferredScriptCheckTimeInterval = 1000;
-
-Interpreter* Interpreter::s_hook = 0;
-    
-typedef HashMap<JSObject*, Interpreter*> InterpreterMap;
-static inline InterpreterMap &interpreterMap()
-{
-    static InterpreterMap* map = new InterpreterMap;
-    return* map;
-}
-
-Interpreter::Interpreter()
-    : m_globalExec(this, 0, 0, 0)
-    , m_currentExec(0)
-    , m_globalObject(0)
-{
-    init();
-}
-
-void Interpreter::init()
-{
-    JSLock lock;
-
-    m_timeoutTime = 0;
-    m_recursion = 0;
-    m_debugger= 0;
-
-    resetTimeoutCheck();
-    m_timeoutCheckCount = 0;
-    
-    m_compatMode = NativeMode;
-
-    if (s_hook) {
-        prev = s_hook;
-        next = s_hook->next;
-        s_hook->next->prev = this;
-        s_hook->next = this;
-    } else {
-        // This is the first interpreter
-        s_hook = next = prev = this;
-    }
-
-    createObjectsForGlobalObjectProperties();
-}
-
-Interpreter::~Interpreter()
-{
-    JSLock lock;
-    
-    if (m_debugger)
-        m_debugger->detach(this);
-
-    next->prev = prev;
-    prev->next = next;
-    s_hook = next;
-    if (s_hook == this) {
-        // This was the last interpreter
-        s_hook = 0;
-    }
-}
-
-JSGlobalObject* Interpreter::globalObject() const
-{
-    // Now that we delay setting of the global object, people retrieving it before it is set may be in for a nasty surprise
-    ASSERT(m_globalObject);
-    return m_globalObject;
-}
-
-void Interpreter::setGlobalObject(JSGlobalObject* globalObject)
-{
-    ASSERT(!m_globalObject);
-    ASSERT(globalObject);
-    m_globalObject = globalObject;
-    m_globalExec.setGlobalObject(globalObject);
-
-    setGlobalObjectProperties();
-}
-
-void Interpreter::resetGlobalObjectProperties()
-{
-    ASSERT(m_globalObject);
-    createObjectsForGlobalObjectProperties();
-    setGlobalObjectProperties();
-}
-
-void Interpreter::createObjectsForGlobalObjectProperties()
-{
-    // Clear before inititalizing, to avoid marking uninitialized (dangerous) or 
-    // stale (wasteful) pointers during initialization.
-    
-    // Prototypes
-    m_FunctionPrototype = 0;
-    m_ObjectPrototype = 0;
-
-    m_ArrayPrototype = 0;
-    m_StringPrototype = 0;
-    m_BooleanPrototype = 0;
-    m_NumberPrototype = 0;
-    m_DatePrototype = 0;
-    m_RegExpPrototype = 0;
-    m_ErrorPrototype = 0;
-    
-    m_EvalErrorPrototype = 0;
-    m_RangeErrorPrototype = 0;
-    m_ReferenceErrorPrototype = 0;
-    m_SyntaxErrorPrototype = 0;
-    m_TypeErrorPrototype = 0;
-    m_UriErrorPrototype = 0;
-
-    // Constructors
-    m_Object = 0;
-    m_Function = 0;
-    m_Array = 0;
-    m_String = 0;
-    m_Boolean = 0;
-    m_Number = 0;
-    m_Date = 0;
-    m_RegExp = 0;
-    m_Error = 0;
-    
-    m_EvalError = 0;
-    m_RangeError = 0;
-    m_ReferenceError = 0;
-    m_SyntaxError = 0;
-    m_TypeError = 0;
-    m_UriError = 0;
-
-    // Prototypes
-    m_FunctionPrototype = new FunctionPrototype(&m_globalExec);
-    m_ObjectPrototype = new ObjectPrototype(&m_globalExec, m_FunctionPrototype);
-    m_FunctionPrototype->setPrototype(m_ObjectPrototype);
-    
-    m_ArrayPrototype = new ArrayPrototype(&m_globalExec, m_ObjectPrototype);
-    m_StringPrototype = new StringPrototype(&m_globalExec, m_ObjectPrototype);
-    m_BooleanPrototype = new BooleanPrototype(&m_globalExec, m_ObjectPrototype, m_FunctionPrototype);
-    m_NumberPrototype = new NumberPrototype(&m_globalExec, m_ObjectPrototype, m_FunctionPrototype);
-    m_DatePrototype = new DatePrototype(&m_globalExec, m_ObjectPrototype);
-    m_RegExpPrototype = new RegExpPrototype(&m_globalExec, m_ObjectPrototype, m_FunctionPrototype);;
-    m_ErrorPrototype = new ErrorPrototype(&m_globalExec, m_ObjectPrototype, m_FunctionPrototype);
-    
-    m_EvalErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, EvalError, "EvalError", "EvalError");
-    m_RangeErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, RangeError, "RangeError", "RangeError");
-    m_ReferenceErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, ReferenceError, "ReferenceError", "ReferenceError");
-    m_SyntaxErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, SyntaxError, "SyntaxError", "SyntaxError");
-    m_TypeErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, TypeError, "TypeError", "TypeError");
-    m_UriErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, URIError, "URIError", "URIError");
-
-    // Constructors
-    m_Object = new ObjectObjectImp(&m_globalExec, m_ObjectPrototype, m_FunctionPrototype);
-    m_Function = new FunctionObjectImp(&m_globalExec, m_FunctionPrototype);
-    m_Array = new ArrayObjectImp(&m_globalExec, m_FunctionPrototype, m_ArrayPrototype);
-    m_String = new StringObjectImp(&m_globalExec, m_FunctionPrototype, m_StringPrototype);
-    m_Boolean = new BooleanObjectImp(&m_globalExec, m_FunctionPrototype, m_BooleanPrototype);
-    m_Number = new NumberObjectImp(&m_globalExec, m_FunctionPrototype, m_NumberPrototype);
-    m_Date = new DateObjectImp(&m_globalExec, m_FunctionPrototype, m_DatePrototype);
-    m_RegExp = new RegExpObjectImp(&m_globalExec, m_FunctionPrototype, m_RegExpPrototype);
-    m_Error = new ErrorObjectImp(&m_globalExec, m_FunctionPrototype, m_ErrorPrototype);
-    
-    m_EvalError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_EvalErrorPrototype);
-    m_RangeError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_RangeErrorPrototype);
-    m_ReferenceError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_ReferenceErrorPrototype);
-    m_SyntaxError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_SyntaxErrorPrototype);
-    m_TypeError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_TypeErrorPrototype);
-    m_UriError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_UriErrorPrototype);
-    
-    m_FunctionPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Function, DontEnum);
-    m_ObjectPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Object, DontEnum | DontDelete | ReadOnly);
-    m_FunctionPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Function, DontEnum | DontDelete | ReadOnly);
-    m_ArrayPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Array, DontEnum | DontDelete | ReadOnly);
-    m_BooleanPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Boolean, DontEnum | DontDelete | ReadOnly);
-    m_StringPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_String, DontEnum | DontDelete | ReadOnly);
-    m_NumberPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Number, DontEnum | DontDelete | ReadOnly);
-    m_DatePrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Date, DontEnum | DontDelete | ReadOnly);
-    m_RegExpPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_RegExp, DontEnum | DontDelete | ReadOnly);
-    m_ErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Error, DontEnum | DontDelete | ReadOnly);
-    m_EvalErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_EvalError, DontEnum | DontDelete | ReadOnly);
-    m_RangeErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_RangeError, DontEnum | DontDelete | ReadOnly);
-    m_ReferenceErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_ReferenceError, DontEnum | DontDelete | ReadOnly);
-    m_SyntaxErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_SyntaxError, DontEnum | DontDelete | ReadOnly);
-    m_TypeErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_TypeError, DontEnum | DontDelete | ReadOnly);
-    m_UriErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_UriError, DontEnum | DontDelete | ReadOnly);
-}
-
-void Interpreter::setGlobalObjectProperties()
+Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code)
 {
-    ASSERT(m_globalObject);
-    m_globalObject->setInterpreter(std::auto_ptr<Interpreter>(this));
-
-    // Set global object prototype
-    JSObject* o = m_globalObject;
-    while (o->prototype()->isObject())
-        o = static_cast<JSObject*>(o->prototype());
-    o->setPrototype(m_ObjectPrototype);
-
-    // Set global constructors
-    // FIXME: kjs_window.cpp checks Internal/DontEnum as a performance hack, to
-    // see that these values can be put directly without a check for override
-    // properties.
-    // FIXME: These properties should be handled by JSGlobalObject
-    m_globalObject->putDirect("Object", m_Object, DontEnum);
-    m_globalObject->putDirect("Function", m_Function, DontEnum);
-    m_globalObject->putDirect("Array", m_Array, DontEnum);
-    m_globalObject->putDirect("Boolean", m_Boolean, DontEnum);
-    m_globalObject->putDirect("String", m_String, DontEnum);
-    m_globalObject->putDirect("Number", m_Number, DontEnum);
-    m_globalObject->putDirect("Date", m_Date, DontEnum);
-    m_globalObject->putDirect("RegExp", m_RegExp, DontEnum);
-    m_globalObject->putDirect("Error", m_Error, DontEnum);
-    m_globalObject->putDirect("EvalError",m_EvalError, Internal);
-    m_globalObject->putDirect("RangeError",m_RangeError, Internal);
-    m_globalObject->putDirect("ReferenceError",m_ReferenceError, Internal);
-    m_globalObject->putDirect("SyntaxError",m_SyntaxError, Internal);
-    m_globalObject->putDirect("TypeError",m_TypeError, Internal);
-    m_globalObject->putDirect("URIError",m_UriError, Internal);
-
-    // Set global values
-    m_globalObject->putDirect("Math", new MathObjectImp(&m_globalExec, m_ObjectPrototype), DontEnum);
-    m_globalObject->putDirect("NaN", jsNaN(), DontEnum|DontDelete);
-    m_globalObject->putDirect("Infinity", jsNumber(Inf), DontEnum|DontDelete);
-    m_globalObject->putDirect("undefined", jsUndefined(), DontEnum|DontDelete);
-    
-    // Set global functions
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::Eval, 1, "eval"), DontEnum);
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::ParseInt, 2, "parseInt"), DontEnum);
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::ParseFloat, 1, "parseFloat"), DontEnum);
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::IsNaN, 1, "isNaN"), DontEnum);
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::IsFinite, 1, "isFinite"), DontEnum);
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::Escape, 1, "escape"), DontEnum);
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::UnEscape, 1, "unescape"), DontEnum);
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::DecodeURI, 1, "decodeURI"), DontEnum);
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::DecodeURIComponent, 1, "decodeURIComponent"), DontEnum);
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::EncodeURI, 1, "encodeURI"), DontEnum);
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::EncodeURIComponent, 1, "encodeURIComponent"), DontEnum);
-#ifndef NDEBUG
-    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::KJSPrint, 1, "kjsprint"), DontEnum);
-#endif
+    return checkSyntax(exec, sourceURL, startingLineNumber, code.data(), code.size());
 }
 
-Completion Interpreter::checkSyntax(const UString& sourceURL, int startingLineNumber, const UString& code)
-{
-    return checkSyntax(sourceURL, startingLineNumber, code.data(), code.size());
-}
-
-Completion Interpreter::checkSyntax(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength)
+Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength)
 {
     JSLock lock;
 
@@ -321,22 +79,23 @@ Completion Interpreter::checkSyntax(const UString& sourceURL, int startingLineNu
     UString errMsg;
     RefPtr<ProgramNode> progNode = parser().parseProgram(sourceURL, startingLineNumber, code, codeLength, 0, &errLine, &errMsg);
     if (!progNode)
-        return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, 0, sourceURL));
+        return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, 0, sourceURL));
     return Completion(Normal);
 }
 
-Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
+Completion Interpreter::evaluate(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
 {
-    return evaluate(sourceURL, startingLineNumber, code.data(), code.size(), thisV);
+    return evaluate(exec, sourceURL, startingLineNumber, code.data(), code.size(), thisV);
 }
 
-Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV)
+Completion Interpreter::evaluate(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV)
 {
     JSLock lock;
     
-    // prevent against infinite recursion
-    if (m_recursion >= 20)
-        return Completion(Throw, Error::create(&m_globalExec, GeneralError, "Recursion too deep"));
+    JSGlobalObject* globalObject = exec->dynamicGlobalObject();
+
+    if (globalObject->recursion() >= 20)
+        return Completion(Throw, Error::create(exec, GeneralError, "Recursion too deep"));
     
     // parse the source code
     int sourceId;
@@ -345,42 +104,41 @@ Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumbe
     RefPtr<ProgramNode> progNode = parser().parseProgram(sourceURL, startingLineNumber, code, codeLength, &sourceId, &errLine, &errMsg);
     
     // notify debugger that source has been parsed
-    if (m_debugger) {
-        bool cont = m_debugger->sourceParsed(&m_globalExec, sourceId, sourceURL, UString(code, codeLength), startingLineNumber, errLine, errMsg);
+    if (globalObject->debugger()) {
+        bool cont = globalObject->debugger()->sourceParsed(exec, sourceId, sourceURL, UString(code, codeLength), startingLineNumber, errLine, errMsg);
         if (!cont)
             return Completion(Break);
     }
     
     // no program node means a syntax error occurred
     if (!progNode)
-        return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sourceId, sourceURL));
+        return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, sourceId, sourceURL));
     
-    m_globalExec.clearException();
+    exec->clearException();
     
-    m_recursion++;
+    globalObject->incRecursion();
     
-    JSGlobalObject* globalObj = m_globalObject;
-    JSObject* thisObj = globalObj;
+    JSObject* thisObj = globalObject;
     
     // "this" must be an object... use same rules as Function.prototype.apply()
     if (thisV && !thisV->isUndefinedOrNull())
-        thisObj = thisV->toObject(&m_globalExec);
+        thisObj = thisV->toObject(exec);
     
     Completion res;
-    if (m_globalExec.hadException())
+    if (exec->hadException())
         // the thisV->toObject() conversion above might have thrown an exception - if so, propagate it
-        res = Completion(Throw, m_globalExec.exception());
+        res = Completion(Throw, exec->exception());
     else {
         // execute the code
-        ExecState newExec(this, globalObj, thisObj, progNode.get());
+        ExecState newExec(globalObject, thisObj, progNode.get());
         res = progNode->execute(&newExec);
     }
     
-    m_recursion--;
+    globalObject->decRecursion();
     
     if (shouldPrintExceptions() && res.complType() == Throw) {
         JSLock lock;
-        ExecState* exec = m_globalObject->globalExec();
+        ExecState* exec = globalObject->globalExec();
         CString f = sourceURL.UTF8String();
         CString message = res.value()->toObject(exec)->toString(exec).UTF8String();
         int line = res.value()->toObject(exec)->get(exec, "line")->toUInt32(exec);
@@ -394,151 +152,6 @@ Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumbe
     return res;
 }
 
-JSObject *Interpreter::builtinObject() const
-{
-  return m_Object;
-}
-
-JSObject *Interpreter::builtinFunction() const
-{
-  return m_Function;
-}
-
-JSObject *Interpreter::builtinArray() const
-{
-  return m_Array;
-}
-
-JSObject *Interpreter::builtinBoolean() const
-{
-  return m_Boolean;
-}
-
-JSObject *Interpreter::builtinString() const
-{
-  return m_String;
-}
-
-JSObject *Interpreter::builtinNumber() const
-{
-  return m_Number;
-}
-
-JSObject *Interpreter::builtinDate() const
-{
-  return m_Date;
-}
-
-JSObject *Interpreter::builtinError() const
-{
-  return m_Error;
-}
-
-JSObject *Interpreter::builtinObjectPrototype() const
-{
-  return m_ObjectPrototype;
-}
-
-JSObject *Interpreter::builtinFunctionPrototype() const
-{
-  return m_FunctionPrototype;
-}
-
-JSObject *Interpreter::builtinArrayPrototype() const
-{
-  return m_ArrayPrototype;
-}
-
-JSObject *Interpreter::builtinBooleanPrototype() const
-{
-  return m_BooleanPrototype;
-}
-
-JSObject *Interpreter::builtinStringPrototype() const
-{
-  return m_StringPrototype;
-}
-
-JSObject *Interpreter::builtinNumberPrototype() const
-{
-  return m_NumberPrototype;
-}
-
-JSObject *Interpreter::builtinDatePrototype() const
-{
-  return m_DatePrototype;
-}
-
-JSObject *Interpreter::builtinRegExpPrototype() const
-{
-  return m_RegExpPrototype;
-}
-
-JSObject *Interpreter::builtinErrorPrototype() const
-{
-  return m_ErrorPrototype;
-}
-
-JSObject *Interpreter::builtinEvalError() const
-{
-  return m_EvalError;
-}
-
-JSObject *Interpreter::builtinRangeError() const
-{
-  return m_RangeError;
-}
-
-JSObject *Interpreter::builtinReferenceError() const
-{
-  return m_ReferenceError;
-}
-
-JSObject *Interpreter::builtinSyntaxError() const
-{
-  return m_SyntaxError;
-}
-
-JSObject *Interpreter::builtinTypeError() const
-{
-  return m_TypeError;
-}
-
-JSObject *Interpreter::builtinURIError() const
-{
-  return m_UriError;
-}
-
-JSObject *Interpreter::builtinEvalErrorPrototype() const
-{
-  return m_EvalErrorPrototype;
-}
-
-JSObject *Interpreter::builtinRangeErrorPrototype() const
-{
-  return m_RangeErrorPrototype;
-}
-
-JSObject *Interpreter::builtinReferenceErrorPrototype() const
-{
-  return m_ReferenceErrorPrototype;
-}
-
-JSObject *Interpreter::builtinSyntaxErrorPrototype() const
-{
-  return m_SyntaxErrorPrototype;
-}
-
-JSObject *Interpreter::builtinTypeErrorPrototype() const
-{
-  return m_TypeErrorPrototype;
-}
-
-JSObject *Interpreter::builtinURIErrorPrototype() const
-{
-  return m_UriErrorPrototype;
-}
-
 static bool printExceptions = false;
 
 bool Interpreter::shouldPrintExceptions()
@@ -551,173 +164,4 @@ void Interpreter::setShouldPrintExceptions(bool print)
   printExceptions = print;
 }
 
-void Interpreter::saveBuiltins (SavedBuiltins& builtins) const
-{
-    if (!builtins._internal)
-        builtins._internal = new SavedBuiltinsInternal;
-    
-    builtins._internal->m_Object = m_Object;
-    builtins._internal->m_Function = m_Function;
-    builtins._internal->m_Array = m_Array;
-    builtins._internal->m_Boolean = m_Boolean;
-    builtins._internal->m_String = m_String;
-    builtins._internal->m_Number = m_Number;
-    builtins._internal->m_Date = m_Date;
-    builtins._internal->m_RegExp = m_RegExp;
-    builtins._internal->m_Error = m_Error;
-    
-    builtins._internal->m_ObjectPrototype = m_ObjectPrototype;
-    builtins._internal->m_FunctionPrototype = m_FunctionPrototype;
-    builtins._internal->m_ArrayPrototype = m_ArrayPrototype;
-    builtins._internal->m_BooleanPrototype = m_BooleanPrototype;
-    builtins._internal->m_StringPrototype = m_StringPrototype;
-    builtins._internal->m_NumberPrototype = m_NumberPrototype;
-    builtins._internal->m_DatePrototype = m_DatePrototype;
-    builtins._internal->m_RegExpPrototype = m_RegExpPrototype;
-    builtins._internal->m_ErrorPrototype = m_ErrorPrototype;
-    
-    builtins._internal->m_EvalError = m_EvalError;
-    builtins._internal->m_RangeError = m_RangeError;
-    builtins._internal->m_ReferenceError = m_ReferenceError;
-    builtins._internal->m_SyntaxError = m_SyntaxError;
-    builtins._internal->m_TypeError = m_TypeError;
-    builtins._internal->m_UriError = m_UriError;
-    
-    builtins._internal->m_EvalErrorPrototype = m_EvalErrorPrototype;
-    builtins._internal->m_RangeErrorPrototype = m_RangeErrorPrototype;
-    builtins._internal->m_ReferenceErrorPrototype = m_ReferenceErrorPrototype;
-    builtins._internal->m_SyntaxErrorPrototype = m_SyntaxErrorPrototype;
-    builtins._internal->m_TypeErrorPrototype = m_TypeErrorPrototype;
-    builtins._internal->m_UriErrorPrototype = m_UriErrorPrototype;
-}
-
-void Interpreter::restoreBuiltins (const SavedBuiltins& builtins)
-{
-    if (!builtins._internal)
-        return;
-
-    m_Object = builtins._internal->m_Object;
-    m_Function = builtins._internal->m_Function;
-    m_Array = builtins._internal->m_Array;
-    m_Boolean = builtins._internal->m_Boolean;
-    m_String = builtins._internal->m_String;
-    m_Number = builtins._internal->m_Number;
-    m_Date = builtins._internal->m_Date;
-    m_RegExp = builtins._internal->m_RegExp;
-    m_Error = builtins._internal->m_Error;
-    
-    m_ObjectPrototype = builtins._internal->m_ObjectPrototype;
-    m_FunctionPrototype = builtins._internal->m_FunctionPrototype;
-    m_ArrayPrototype = builtins._internal->m_ArrayPrototype;
-    m_BooleanPrototype = builtins._internal->m_BooleanPrototype;
-    m_StringPrototype = builtins._internal->m_StringPrototype;
-    m_NumberPrototype = builtins._internal->m_NumberPrototype;
-    m_DatePrototype = builtins._internal->m_DatePrototype;
-    m_RegExpPrototype = builtins._internal->m_RegExpPrototype;
-    m_ErrorPrototype = builtins._internal->m_ErrorPrototype;
-    
-    m_EvalError = builtins._internal->m_EvalError;
-    m_RangeError = builtins._internal->m_RangeError;
-    m_ReferenceError = builtins._internal->m_ReferenceError;
-    m_SyntaxError = builtins._internal->m_SyntaxError;
-    m_TypeError = builtins._internal->m_TypeError;
-    m_UriError = builtins._internal->m_UriError;
-    
-    m_EvalErrorPrototype = builtins._internal->m_EvalErrorPrototype;
-    m_RangeErrorPrototype = builtins._internal->m_RangeErrorPrototype;
-    m_ReferenceErrorPrototype = builtins._internal->m_ReferenceErrorPrototype;
-    m_SyntaxErrorPrototype = builtins._internal->m_SyntaxErrorPrototype;
-    m_TypeErrorPrototype = builtins._internal->m_TypeErrorPrototype;
-    m_UriErrorPrototype = builtins._internal->m_UriErrorPrototype;
-}
-
-void Interpreter::startTimeoutCheck()
-{
-    if (m_timeoutCheckCount == 0)
-        resetTimeoutCheck();
-    
-    m_timeoutCheckCount++;
-}
-
-void Interpreter::stopTimeoutCheck()
-{
-    m_timeoutCheckCount--;
-}
-
-void Interpreter::resetTimeoutCheck()
-{
-    m_tickCount = 0;
-    m_ticksUntilNextTimeoutCheck = initialTickCountThreshold;
-    m_timeAtLastCheckTimeout = 0;
-    m_timeExecuting = 0;
-}
-
-// Returns the current time in milliseconds
-// It doesn't matter what "current time" is here, just as long as
-// it's possible to measure the time difference correctly.
-static inline unsigned getCurrentTime() {
-#if HAVE(SYS_TIME_H)
-    struct timeval tv;
-    gettimeofday(&tv, 0);
-    return tv.tv_sec * 1000 + tv.tv_usec / 1000;
-#elif PLATFORM(QT)
-    QDateTime t = QDateTime::currentDateTime();
-    return t.toTime_t() * 1000 + t.time().msec();
-#elif PLATFORM(WIN_OS)
-    return timeGetTime();
-#else
-#error Platform does not have getCurrentTime function
-#endif
-}
-
-bool Interpreter::checkTimeout()
-{    
-    m_tickCount = 0;
-    
-    unsigned currentTime = getCurrentTime();
-
-    if (!m_timeAtLastCheckTimeout) {
-        // Suspicious amount of looping in a script -- start timing it
-        m_timeAtLastCheckTimeout = currentTime;
-        return false;
-    }
-
-    unsigned timeDiff = currentTime - m_timeAtLastCheckTimeout;
-
-    if (timeDiff == 0)
-        timeDiff = 1;
-    
-    m_timeExecuting += timeDiff;
-    m_timeAtLastCheckTimeout = currentTime;
-    
-    // Adjust the tick threshold so we get the next checkTimeout call in the interval specified in 
-    // preferredScriptCheckTimeInterval
-    m_ticksUntilNextTimeoutCheck = (unsigned)((float)preferredScriptCheckTimeInterval / timeDiff) * m_ticksUntilNextTimeoutCheck;
-
-    // If the new threshold is 0 reset it to the default threshold. This can happen if the timeDiff is higher than the
-    // preferred script check time interval.
-    if (m_ticksUntilNextTimeoutCheck == 0)
-        m_ticksUntilNextTimeoutCheck = initialTickCountThreshold;
-
-    if (m_timeoutTime && m_timeExecuting > m_timeoutTime) {
-        if (m_globalObject->shouldInterruptScript())
-            return true;
-        
-        resetTimeoutCheck();
-    }
-    
-    return false;
-}
-
-
-SavedBuiltins::SavedBuiltins() : 
-  _internal(0)
-{
-}
-
-SavedBuiltins::~SavedBuiltins()
-{
-  delete _internal;
-}
-
-}
+} // namespace KJS
index 8e8407ce3bb6e824b872e7e1e56ab580611646d3..79b93988ef56a0d9c4d37ad8040035fde4fb2238 100644 (file)
@@ -1,8 +1,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, 2007 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
  *
  */
 
-#ifndef _KJS_INTERPRETER_H_
-#define _KJS_INTERPRETER_H_
-
-#include "ExecState.h"
-#include "protect.h"
-#include "types.h"
-#include "value.h"
-#include <wtf/RefCounted.h>
+#ifndef KJS_Interpreter_h
+#define KJS_Interpreter_h
 
 namespace KJS {
 
-  class ArrayObjectImp;
-  class ArrayPrototype;
-  class BooleanObjectImp;
-  class BooleanPrototype;
-  class DateObjectImp;
-  class DatePrototype;
-  class Debugger;
-  class ErrorObjectImp;
-  class ErrorPrototype;
-  class EvalError;
-  class EvalErrorPrototype;
-  class FunctionObjectImp;
-  class FunctionPrototype;
-  class JSGlobalObject;
-  class NativeErrorImp;
-  class NativeErrorPrototype;
-  class NumberObjectImp;
-  class NumberPrototype;
-  class ObjectObjectImp;
-  class ObjectPrototype;
-  class RangeError;
-  class RangeErrorPrototype;
-  class ReferenceError;
-  class ReferenceError;
-  class ReferenceErrorPrototype;
-  class RegExpObjectImp;
-  class RegExpPrototype;
-  class RuntimeMethod;
-  class SavedBuiltins;
-  class ScopeChain;
-  class StringObjectImp;
-  class StringPrototype;
-  class SyntaxErrorPrototype;
-  class TypeError;
-  class TypeErrorPrototype;
-  class UriError;
-  class UriErrorPrototype;
+  class Completion;
+  class ExecState;
+  class JSValue;
+  class UString;
+
+  struct UChar;
   
-  /**
-   * Interpreter objects can be used to evaluate ECMAScript code. Each
-   * interpreter has a global object which is used for the purposes of code
-   * evaluation, and also provides access to built-in properties such as
-   * " Object" and "Number".
-   */
   class Interpreter {
-    friend class Collector;
-    friend class JSGlobalObject;
-
   public:
-    /**
-     * Creates a new interpreter. The global object must be set via setGlobalObject
-     * before code is executed with this interpreter.
-     */
-    Interpreter();
-    ~Interpreter();
-
-    /**
-     * Set the interpreter's global object. The supplied object will be used as the global
-     * object for all scripts executed with this interpreter. During
-     * construction, all the standard properties such as "Object" and "Number"
-     * will be added to the global object.
-     *
-     * Note: You should not use the same global object for multiple
-     * interpreters.
-     *
-     * This is due do the fact that the built-in properties are set in the
-     * constructor, and if these objects have been modified from another
-     * interpreter (e.g. a script modifying String.prototype), the changes will
-     * be overridden.
-     *
-     * @param The object to use as the global object for this interpreter
-     */
-    void setGlobalObject(JSGlobalObject*);
-
-    /**
-     * Resets the global object's default properties and adds the default object 
-     * prototype to its prototype chain.
-     */
-    void resetGlobalObjectProperties();
-
-    /**
-     * Returns the object that is used as the global object during all script
-     * execution performed by this interpreter
-     */
-    JSGlobalObject* globalObject() const;
-
     /**
      * Parses the supplied ECMAScript code and checks for syntax errors.
      *
@@ -125,8 +41,8 @@ namespace KJS {
      * @return A normal completion if there were no syntax errors in the code, 
      * otherwise a throw completion with the syntax error as its value.
      */
-    Completion checkSyntax(const UString& sourceURL, int startingLineNumber, const UString& code);
-    Completion checkSyntax(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength);
+    static Completion checkSyntax(ExecState*, const UString& sourceURL, int startingLineNumber, const UString& code);
+    static Completion checkSyntax(ExecState*, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength);
 
     /**
      * Evaluates the supplied ECMAScript code.
@@ -143,238 +59,13 @@ namespace KJS {
      * execution. This should either be jsNull() or an Object.
      * @return A completion object representing the result of the execution.
      */
-    Completion evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV = 0);
-    Completion evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV = 0);
-
-    /**
-     * 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
-     * object.
-     *
-     * @return The builtin "Object" object
-     */
-    JSObject *builtinObject() const;
-
-    /**
-     * Returns the builtin "Function" object.
-     */
-    JSObject *builtinFunction() const;
-
-    /**
-     * Returns the builtin "Array" object.
-     */
-    JSObject *builtinArray() const;
-
-    /**
-     * Returns the builtin "Boolean" object.
-     */
-    JSObject *builtinBoolean() const;
-
-    /**
-     * Returns the builtin "String" object.
-     */
-    JSObject *builtinString() const;
-
-    /**
-     * Returns the builtin "Number" object.
-     */
-    JSObject *builtinNumber() const;
-
-    /**
-     * Returns the builtin "Date" object.
-     */
-    JSObject *builtinDate() const;
-
-    /**
-     * Returns the builtin "RegExp" object.
-     */
-    RegExpObjectImp* builtinRegExp() const { return m_RegExp; }
-
-    /**
-     * Returns the builtin "Error" object.
-     */
-    JSObject *builtinError() const;
-
-    /**
-     * Returns the builtin "Object.prototype" object.
-     */
-    JSObject *builtinObjectPrototype() const;
-
-    /**
-     * Returns the builtin "Function.prototype" object.
-     */
-    JSObject *builtinFunctionPrototype() const;
-
-    /**
-     * Returns the builtin "Array.prototype" object.
-     */
-    JSObject *builtinArrayPrototype() const;
-
-    /**
-     * Returns the builtin "Boolean.prototype" object.
-     */
-    JSObject *builtinBooleanPrototype() const;
-
-    /**
-     * Returns the builtin "String.prototype" object.
-     */
-    JSObject *builtinStringPrototype() const;
-
-    /**
-     * Returns the builtin "Number.prototype" object.
-     */
-    JSObject *builtinNumberPrototype() const;
-
-    /**
-     * Returns the builtin "Date.prototype" object.
-     */
-    JSObject *builtinDatePrototype() const;
-
-    /**
-     * Returns the builtin "RegExp.prototype" object.
-     */
-    JSObject *builtinRegExpPrototype() const;
-
-    /**
-     * Returns the builtin "Error.prototype" object.
-     */
-    JSObject *builtinErrorPrototype() const;
-
-    /**
-     * The initial value of "Error" global property
-     */
-    JSObject *builtinEvalError() const;
-    JSObject *builtinRangeError() const;
-    JSObject *builtinReferenceError() const;
-    JSObject *builtinSyntaxError() const;
-    JSObject *builtinTypeError() const;
-    JSObject *builtinURIError() const;
-
-    JSObject *builtinEvalErrorPrototype() const;
-    JSObject *builtinRangeErrorPrototype() const;
-    JSObject *builtinReferenceErrorPrototype() const;
-    JSObject *builtinSyntaxErrorPrototype() const;
-    JSObject *builtinTypeErrorPrototype() const;
-    JSObject *builtinURIErrorPrototype() const;
-
-    enum CompatMode { NativeMode, IECompat, NetscapeCompat };
-    /**
-     * Call this to enable a compatibility mode with another browser.
-     * (by default konqueror is in "native mode").
-     * Currently, in KJS, this only changes the behavior of Date::getYear()
-     * which returns the full year under IE.
-     */
-    void setCompatMode(CompatMode mode) { m_compatMode = mode; }
-    CompatMode compatMode() const { return m_compatMode; }
+    static Completion evaluate(ExecState*, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV = 0);
+    static Completion evaluate(ExecState*, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV = 0);
     
     static bool shouldPrintExceptions();
     static void setShouldPrintExceptions(bool);
-
-    void saveBuiltins (SavedBuiltins&) const;
-    void restoreBuiltins (const SavedBuiltins&);
-    
-    // Chained list of interpreters (ring)
-    static Interpreter* firstInterpreter() { return s_hook; }
-    Interpreter* nextInterpreter() const { return next; }
-    Interpreter* prevInterpreter() const { return prev; }
-
-    Debugger* debugger() const { return m_debugger; }
-    void setDebugger(Debugger* d) { m_debugger = d; }
-    
-    void setCurrentExec(ExecState* exec) { m_currentExec = exec; }
-    ExecState* currentExec() const { return m_currentExec; }
-        
-    void setTimeoutTime(unsigned timeoutTime) { m_timeoutTime = timeoutTime; }
-
-    void startTimeoutCheck();
-    void stopTimeoutCheck();
-    
-    bool timedOut();
-    
-    ExecState m_globalExec; // This is temporarily public to help with bootstrapping.
-
-protected:
-    unsigned m_timeoutTime;
-
-private:
-    void init();
-
-    void createObjectsForGlobalObjectProperties();
-    void setGlobalObjectProperties();
-
-    void resetTimeoutCheck();
-    bool checkTimeout();
-
-    // Uncopyable
-    Interpreter(const Interpreter&);
-    Interpreter operator=(const Interpreter&);
-    
-    ExecState* m_currentExec;
-    JSGlobalObject* m_globalObject;
-
-    // Chained list of interpreters (ring) - for collector
-    static Interpreter* s_hook;
-    Interpreter *next, *prev;
-    
-    int m_recursion;
-    
-    Debugger* m_debugger;
-    CompatMode m_compatMode;
-
-    unsigned m_timeAtLastCheckTimeout;
-    unsigned m_timeExecuting;
-    unsigned m_timeoutCheckCount;
-    
-    unsigned m_tickCount;
-    unsigned m_ticksUntilNextTimeoutCheck;
-
-
-    ObjectObjectImp* m_Object;
-    FunctionObjectImp* m_Function;
-    ArrayObjectImp* m_Array;
-    BooleanObjectImp* m_Boolean;
-    StringObjectImp* m_String;
-    NumberObjectImp* m_Number;
-    DateObjectImp* m_Date;
-    RegExpObjectImp* m_RegExp;
-    ErrorObjectImp* m_Error;
-    
-    ObjectPrototype* m_ObjectPrototype;
-    FunctionPrototype* m_FunctionPrototype;
-    ArrayPrototype* m_ArrayPrototype;
-    BooleanPrototype* m_BooleanPrototype;
-    StringPrototype* m_StringPrototype;
-    NumberPrototype* m_NumberPrototype;
-    DatePrototype* m_DatePrototype;
-    RegExpPrototype* m_RegExpPrototype;
-    ErrorPrototype* m_ErrorPrototype;
-    
-    NativeErrorImp* m_EvalError;
-    NativeErrorImp* m_RangeError;
-    NativeErrorImp* m_ReferenceError;
-    NativeErrorImp* m_SyntaxError;
-    NativeErrorImp* m_TypeError;
-    NativeErrorImp* m_UriError;
-    
-    NativeErrorPrototype* m_EvalErrorPrototype;
-    NativeErrorPrototype* m_RangeErrorPrototype;
-    NativeErrorPrototype* m_ReferenceErrorPrototype;
-    NativeErrorPrototype* m_SyntaxErrorPrototype;
-    NativeErrorPrototype* m_TypeErrorPrototype;
-    NativeErrorPrototype* m_UriErrorPrototype;
   };
 
-  inline bool Interpreter::timedOut()
-  {
-      m_tickCount++;
-      
-      if (m_tickCount != m_ticksUntilNextTimeoutCheck)
-          return false;
-      
-      return checkTimeout();
-  }
-  
-} // namespace
+} // namespace KJS
 
-#endif // _KJS_INTERPRETER_H_
+#endif // KJS_Interpreter_h
index 5350daa85f1a89a71933c5cd7ab6a6535b68de1f..f3234482022f08af68f8417602fabfca972d2a6f 100644 (file)
@@ -25,7 +25,6 @@
 #include "lexer.h"
 
 #include "function.h"
-#include "interpreter.h"
 #include "nodes.h"
 #include <ctype.h>
 #include <limits.h>
index fe59d869a39bd3695c69e15595ab1eeb2c971a4c..f47d304a212615b2eb66941dbd299b8dc43db44d 100644 (file)
@@ -25,7 +25,6 @@
 #include "ExecState.h"
 #include "function.h"
 #include "identifier.h"
-#include "interpreter.h"
 #include "JSGlobalObject.h"
 #include "object.h"
 #include <stdio.h>
@@ -268,15 +267,15 @@ namespace KJS {
 
   /**
    * This template method retrieves or create an object that is unique
-   * (for a given interpreter) The first time this is called (for a given
+   * (for a given global object) The first time this is called (for a given
    * property name), the Object will be constructed, and set as a property
-   * of the interpreter's global object. Later calls will simply retrieve
-   * that cached object. Note that the object constructor must take 1 argument, exec.
+   * of the global object. Later calls will simply retrieve that cached object. 
+   * Note that the object constructor must take 1 argument, exec.
    */
   template <class ClassCtor>
   inline JSObject* cacheGlobalObject(ExecState* exec, const Identifier& propertyName)
   {
-    JSGlobalObject* globalObject = exec->lexicalInterpreter()->globalObject();
+    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
     JSValue* obj = globalObject->getDirect(propertyName);
     if (obj) {
       ASSERT(obj->isObject());
@@ -315,7 +314,7 @@ namespace KJS {
     static const KJS::ClassInfo info; \
     bool getOwnPropertySlot(KJS::ExecState* , const KJS::Identifier&, KJS::PropertySlot&); \
     ClassPrototype(KJS::ExecState* exec) \
-      : KJS::JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()) { } \
+      : KJS::JSObject(exec->lexicalGlobalObject()->objectPrototype()) { } \
     \
   };
 
@@ -351,7 +350,7 @@ namespace KJS {
             return new ClassFunction(exec, len, name); \
         } \
         ClassFunction(KJS::ExecState* exec, int len, const KJS::Identifier& name) \
-            : KJS::InternalFunctionImp(static_cast<KJS::FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name) \
+            : KJS::InternalFunctionImp(static_cast<KJS::FunctionPrototype*>(exec->lexicalGlobalObject()->functionPrototype()), name) \
         { \
             put(exec, exec->propertyNames().length, KJS::jsNumber(len), KJS::DontDelete | KJS::ReadOnly | KJS::DontEnum); \
         } \
index dfdfc306c68c86a401d7048eda725ac223cb864c..54a93df6629e1627b7aa6018e15608b7d4a7fcc1 100644 (file)
@@ -359,7 +359,7 @@ void Node::handleException(ExecState* exec, JSValue* exceptionValue)
             exception->put(exec, "sourceURL", jsString(currentSourceURL(exec)));
         }
     }
-    Debugger* dbg = exec->dynamicInterpreter()->debugger();
+    Debugger* dbg = exec->dynamicGlobalObject()->debugger();
     if (dbg && !dbg->hasHandledException(exec, exceptionValue)) {
         bool cont = dbg->exception(exec, currentSourceId(exec), m_line, exceptionValue);
         if (!cont)
@@ -392,7 +392,7 @@ void StatementNode::setLoc(int firstLine, int lastLine)
 // return true if the debugger wants us to stop at this point
 bool StatementNode::hitStatement(ExecState* exec)
 {
-  Debugger *dbg = exec->dynamicInterpreter()->debugger();
+  Debugger *dbg = exec->dynamicGlobalObject()->debugger();
   if (dbg)
     return dbg->atStatement(exec, currentSourceId(exec), firstLine(), lastLine());
   else
@@ -490,7 +490,7 @@ bool StringNode::evaluateToBoolean(ExecState*)
 
 JSValue* RegExpNode::evaluate(ExecState* exec)
 {
-    return exec->lexicalInterpreter()->builtinRegExp()->createRegExpImp(exec, m_regExp);
+    return exec->lexicalGlobalObject()->regExpConstructor()->createRegExpImp(exec, m_regExp);
 }
 
 // ------------------------------ ThisNode -------------------------------------
@@ -614,7 +614,7 @@ void ElementNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::N
 // ECMA 11.1.4
 JSValue *ElementNode::evaluate(ExecState *exec)
 {
-  JSObject *array = exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty());
+  JSObject *array = exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, List::empty());
   int length = 0;
   for (ElementNode *n = this; n; n = n->next.get()) {
     JSValue *val = n->node->evaluate(exec);
@@ -645,7 +645,7 @@ JSValue *ArrayNode::evaluate(ExecState *exec)
     KJS_CHECKEXCEPTIONVALUE
     length = opt ? array->get(exec, exec->propertyNames().length)->toInt32(exec) : 0;
   } else {
-    JSValue *newArr = exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty());
+    JSValue *newArr = exec->lexicalGlobalObject()->arrayConstructor()->construct(exec,List::empty());
     array = static_cast<JSObject*>(newArr);
     length = 0;
   }
@@ -670,7 +670,7 @@ JSValue *ObjectLiteralNode::evaluate(ExecState *exec)
   if (list)
     return list->evaluate(exec);
 
-  return exec->lexicalInterpreter()->builtinObject()->construct(exec,List::empty());
+  return exec->lexicalGlobalObject()->objectConstructor()->construct(exec,List::empty());
 }
 
 // ------------------------------ PropertyListNode -----------------------------
@@ -685,7 +685,7 @@ void PropertyListNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStac
 // ECMA 11.1.5
 JSValue *PropertyListNode::evaluate(ExecState *exec)
 {
-  JSObject *obj = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
+  JSObject *obj = exec->lexicalGlobalObject()->objectConstructor()->construct(exec, List::empty());
   
   for (PropertyListNode *p = this; p; p = p->next.get()) {
     JSValue *v = p->node->assign->evaluate(exec);
@@ -945,7 +945,7 @@ JSValue *FunctionCallValueNode::evaluate(ExecState *exec)
   args->evaluateList(exec, argList);
   KJS_CHECKEXCEPTIONVALUE
 
-  JSObject *thisObj =  exec->dynamicInterpreter()->globalObject();
+  JSObject *thisObj =  exec->dynamicGlobalObject();
 
   return func->call(exec, thisObj, argList);
 }
@@ -1000,7 +1000,7 @@ JSValue* FunctionCallResolveNode::inlineEvaluate(ExecState* exec)
       // of implementation we use the global object anyway here. This guarantees
       // that in host objects you always get a valid object for this.
       if (thisObj->isActivation())
-        thisObj = exec->dynamicInterpreter()->globalObject();
+        thisObj = exec->dynamicGlobalObject();
 
       return func->call(exec, thisObj, argList);
     }
@@ -1061,7 +1061,7 @@ JSValue* LocalVarFunctionCallNode::inlineEvaluate(ExecState* exec)
     args->evaluateList(exec, argList);
     KJS_CHECKEXCEPTIONVALUE
 
-    return func->call(exec, exec->dynamicInterpreter()->globalObject(), argList);
+    return func->call(exec, exec->dynamicGlobalObject(), argList);
 }
 
 JSValue* LocalVarFunctionCallNode::evaluate(ExecState* exec)
@@ -3783,7 +3783,7 @@ Completion DoWhileNode::execute(ExecState *exec)
         Completion c = statement->execute(exec);
         exec->popIteration();
 
-        if (exec->dynamicInterpreter()->timedOut())
+        if (exec->dynamicGlobalObject()->timedOut())
             return Completion(Interrupted);
 
         if (c.isValueCompletion())
@@ -3836,7 +3836,7 @@ Completion WhileNode::execute(ExecState *exec)
         Completion c = statement->execute(exec);
         exec->popIteration();
 
-        if (exec->dynamicInterpreter()->timedOut())
+        if (exec->dynamicGlobalObject()->timedOut())
             return Completion(Interrupted);
     
         if (c.isValueCompletion())
@@ -3902,7 +3902,7 @@ Completion ForNode::execute(ExecState *exec)
                 return c;
         }
 
-        if (exec->dynamicInterpreter()->timedOut())
+        if (exec->dynamicGlobalObject()->timedOut())
             return Completion(Interrupted);
 
         if (expr3) {
@@ -4580,7 +4580,7 @@ Completion FunctionBodyNode::execute(ExecState* exec)
 {
     processDeclarations(exec);
 
-    if (Debugger* dbg = exec->dynamicInterpreter()->debugger()) {
+    if (Debugger* dbg = exec->dynamicGlobalObject()->debugger()) {
         if (!dbg->callEvent(exec, sourceId(), lineNo(), exec->function(), *exec->arguments())) {
             dbg->imp()->abort();
             return Completion(Interrupted, jsUndefined());
@@ -4589,7 +4589,7 @@ Completion FunctionBodyNode::execute(ExecState* exec)
     
     Completion completion = BlockNode::execute(exec);
     
-    if (Debugger* dbg = exec->dynamicInterpreter()->debugger()) {
+    if (Debugger* dbg = exec->dynamicGlobalObject()->debugger()) {
         if (completion.complType() == Throw)
             exec->setException(completion.value());
 
@@ -4620,7 +4620,7 @@ FunctionImp* FuncDeclNode::makeFunction(ExecState* exec)
 {
   FunctionImp *func = new FunctionImp(exec, ident, body.get(), exec->scopeChain());
 
-  JSObject *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
+  JSObject *proto = exec->lexicalGlobalObject()->objectConstructor()->construct(exec, List::empty());
   proto->put(exec, exec->propertyNames().constructor, func, ReadOnly | DontDelete | DontEnum);
   func->put(exec, exec->propertyNames().prototype, proto, Internal|DontDelete);
 
@@ -4656,7 +4656,7 @@ JSValue *FuncExprNode::evaluate(ExecState *exec)
   }
 
   FunctionImp* func = new FunctionImp(exec, ident, body.get(), exec->scopeChain());
-  JSObject* proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
+  JSObject* proto = exec->lexicalGlobalObject()->objectConstructor()->construct(exec, List::empty());
   proto->put(exec, exec->propertyNames().constructor, func, ReadOnly | DontDelete | DontEnum);
   func->put(exec, exec->propertyNames().prototype, proto, Internal | DontDelete);
 
index ad68f909a5766b09e9f35d27e4372672e0ed1df1..3a2e32d0482ce67dc8f2ff2cbab14bbd480b56d4 100644 (file)
@@ -463,7 +463,7 @@ bool NumberObjectImp::implementsConstruct() const
 // ECMA 15.7.1
 JSObject *NumberObjectImp::construct(ExecState *exec, const List &args)
 {
-  JSObject *proto = exec->lexicalInterpreter()->builtinNumberPrototype();
+  JSObject *proto = exec->lexicalGlobalObject()->numberPrototype();
   NumberInstance *obj(new NumberInstance(proto));
 
   double n;
index 13d5e6553658d11a668695b6c63e0604f0191d64..f4e83b972460a4898fb4839f377edfedb729fb79 100644 (file)
@@ -68,7 +68,7 @@ JSValue *JSObject::call(ExecState *exec, JSObject *thisObj, const List &args)
   ASSERT(implementsCall());
 
 #if KJS_MAX_STACK > 0
-  static int depth = 0; // sum of all concurrent interpreters
+  static int depth = 0; // sum of all extant function calls
 
 #if JAVASCRIPT_CALL_TRACING
     static bool tracing = false;
@@ -365,7 +365,7 @@ bool JSObject::getPrimitiveNumber(ExecState* exec, double& number, JSValue*& res
 JSValue* JSObject::defaultValue(ExecState* exec, JSType hint) const
 {
   /* Prefer String for Date objects */
-  if ((hint == StringType) || (hint != StringType) && (hint != NumberType) && (_proto == exec->lexicalInterpreter()->builtinDatePrototype())) {
+  if ((hint == StringType) || (hint != NumberType && _proto == exec->lexicalGlobalObject()->datePrototype())) {
     if (JSValue* v = tryGetAndCallProperty(exec, this, exec->propertyNames().toString))
       return v;
     if (JSValue* v = tryGetAndCallProperty(exec, this, exec->propertyNames().valueOf))
@@ -599,25 +599,25 @@ JSObject *Error::create(ExecState *exec, ErrorType errtype, const UString &messa
   JSObject *cons;
   switch (errtype) {
   case EvalError:
-    cons = exec->lexicalInterpreter()->builtinEvalError();
+    cons = exec->lexicalGlobalObject()->evalErrorConstructor();
     break;
   case RangeError:
-    cons = exec->lexicalInterpreter()->builtinRangeError();
+    cons = exec->lexicalGlobalObject()->rangeErrorConstructor();
     break;
   case ReferenceError:
-    cons = exec->lexicalInterpreter()->builtinReferenceError();
+    cons = exec->lexicalGlobalObject()->referenceErrorConstructor();
     break;
   case SyntaxError:
-    cons = exec->lexicalInterpreter()->builtinSyntaxError();
+    cons = exec->lexicalGlobalObject()->syntaxErrorConstructor();
     break;
   case TypeError:
-    cons = exec->lexicalInterpreter()->builtinTypeError();
+    cons = exec->lexicalGlobalObject()->typeErrorConstructor();
     break;
   case URIError:
-    cons = exec->lexicalInterpreter()->builtinURIError();
+    cons = exec->lexicalGlobalObject()->URIErrorConstructor();
     break;
   default:
-    cons = exec->lexicalInterpreter()->builtinError();
+    cons = exec->lexicalGlobalObject()->errorConstructor();
     break;
   }
 
index 1f45f5eb0a21357391f495c02c29638abb18fae5..0ae67cae550fcf08517a33afdc07b9765545b0b2 100644 (file)
 #ifndef KJS_OBJECT_H
 #define KJS_OBJECT_H
 
-#include "JSType.h"
 #include "CommonIdentifiers.h"
-#include "interpreter.h"
+#include "ExecState.h"
+#include "JSType.h"
+#include "list.h"
 #include "property_map.h"
 #include "property_slot.h"
 #include "scope_chain.h"
index 10a91cd2b7a6c18466314de770ca825c33b86eb3..c57902087d3c617a1f129192091d6cfcfc532677 100644 (file)
@@ -180,7 +180,7 @@ JSObject* ObjectObjectImp::construct(ExecState* exec, const List& args)
       return arg->toObject(exec);
   case NullType:
   case UndefinedType:
-      return new JSObject(exec->lexicalInterpreter()->builtinObjectPrototype());
+      return new JSObject(exec->lexicalGlobalObject()->objectPrototype());
   default:
       ASSERT_NOT_REACHED();
       return 0;
index 3ecba535f27eafcd42ff07545ba8a1b86534fea0..2c62085d4f7dd3af7108d4b3852fb2edb957a72b 100644 (file)
@@ -23,7 +23,7 @@
 #define KJS_REGEXP_H
 
 #include "ustring.h"
-#include <pcre.h>
+#include <pcre/pcre.h>
 #include <sys/types.h>
 #include <wtf/OwnArrayPtr.h>
 #include <wtf/RefCounted.h>
index 3a300c8d38830bf3a38f2f3ba875dc00dbab1da6..c8624c38a0428e4b617c7d98f90efd48b2ea045f 100644 (file)
@@ -25,7 +25,6 @@
 #include "array_instance.h"
 #include "error_object.h"
 #include "internal.h"
-#include "interpreter.h"
 #include "object.h"
 #include "operations.h"
 #include "regexp.h"
@@ -186,7 +185,7 @@ void RegExpImp::putValueProperty(ExecState* exec, int token, JSValue* value, int
 
 bool RegExpImp::match(ExecState* exec, const List& args)
 {
-    RegExpObjectImp* regExpObj = exec->lexicalInterpreter()->builtinRegExp();
+    RegExpObjectImp* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();
 
     UString input;
     if (!args.isEmpty())
@@ -230,7 +229,7 @@ JSValue* RegExpImp::test(ExecState* exec, const List& args)
 JSValue* RegExpImp::exec(ExecState* exec, const List& args)
 {
     return match(exec, args)
-        ? exec->lexicalInterpreter()->builtinRegExp()->arrayOfMatches(exec)
+        ? exec->lexicalGlobalObject()->regExpConstructor()->arrayOfMatches(exec)
         :  jsNull();
 }
 
@@ -321,7 +320,7 @@ void RegExpObjectImp::performMatch(RegExp* r, const UString& s, int startOffset,
 JSObject* RegExpObjectImp::arrayOfMatches(ExecState* exec) const
 {
   unsigned lastNumSubpatterns = d->lastNumSubPatterns;
-  ArrayInstance* arr = new ArrayInstance(exec->lexicalInterpreter()->builtinArrayPrototype(), lastNumSubpatterns + 1);
+  ArrayInstance* arr = new ArrayInstance(exec->lexicalGlobalObject()->arrayPrototype(), lastNumSubpatterns + 1);
   for (unsigned i = 0; i <= lastNumSubpatterns; ++i) {
     int start = d->lastOvector[2 * i];
     if (start >= 0)
@@ -455,7 +454,7 @@ JSObject *RegExpObjectImp::construct(ExecState *exec, const List &args)
 JSObject* RegExpObjectImp::createRegExpImp(ExecState* exec, PassRefPtr<RegExp> regExp)
 {
     return regExp->isValid()
-        ? new RegExpImp(static_cast<RegExpPrototype*>(exec->lexicalInterpreter()->builtinRegExpPrototype()), regExp)
+        ? new RegExpImp(static_cast<RegExpPrototype*>(exec->lexicalGlobalObject()->regExpPrototype()), regExp)
         : throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage()));
 }
 
index c74f549c99f1cda50e5ab62c804b7ce987ab5bab..0216eb41d3ea407dc18314592aef18f2f94163dd 100644 (file)
@@ -333,7 +333,7 @@ static JSValue *replace(ExecState *exec, StringImp* sourceVal, JSValue *pattern,
     RegExp *reg = static_cast<RegExpImp *>(pattern)->regExp();
     bool global = reg->global();
 
-    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp());
+    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalGlobalObject()->regExpConstructor());
 
     int lastIndex = 0;
     int startPosition = 0;
@@ -374,7 +374,7 @@ static JSValue *replace(ExecState *exec, StringImp* sourceVal, JSValue *pattern,
           args.append(jsNumber(completeMatchStart));
           args.append(sourceVal);
 
-          substitutedReplacement = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(), 
+          substitutedReplacement = replacementFunction->call(exec, exec->dynamicGlobalObject(), 
                                                              args)->toString(exec);
       } else
           substitutedReplacement = substituteBackreferences(replacementString, source, ovector, reg);
@@ -424,7 +424,7 @@ static JSValue *replace(ExecState *exec, StringImp* sourceVal, JSValue *pattern,
       args.append(jsNumber(matchPos));
       args.append(sourceVal);
       
-      replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(), 
+      replacementString = replacementFunction->call(exec, exec->dynamicGlobalObject(), 
                                                     args)->toString(exec);
   }
 
@@ -548,7 +548,7 @@ JSValue* StringProtoFuncMatch::callAsFunction(ExecState* exec, JSObject* thisObj
        */
       reg = tmpReg = new RegExp(a0->toString(exec));
     }
-    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp());
+    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalGlobalObject()->regExpConstructor());
     int pos;
     int matchLength;
     regExpObj->performMatch(reg, u, 0, pos, matchLength);
@@ -577,7 +577,7 @@ JSValue* StringProtoFuncMatch::callAsFunction(ExecState* exec, JSObject* thisObj
         // other browsers and because Null is a false value.
         result = jsNull();
       } else {
-        result = exec->lexicalInterpreter()->builtinArray()->construct(exec, list);
+        result = exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, list);
       }
     }
     delete tmpReg;
@@ -604,7 +604,7 @@ JSValue* StringProtoFuncSearch::callAsFunction(ExecState* exec, JSObject* thisOb
        */
       reg = tmpReg = new RegExp(a0->toString(exec));
     }
-    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp());
+    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalGlobalObject()->regExpConstructor());
     int pos;
     int matchLength;
     regExpObj->performMatch(reg, u, 0, pos, matchLength);
@@ -660,7 +660,7 @@ JSValue* StringProtoFuncSplit::callAsFunction(ExecState* exec, JSObject* thisObj
     JSValue* a0 = args[0];
     JSValue* a1 = args[1];
 
-    JSObject *constructor = exec->lexicalInterpreter()->builtinArray();
+    JSObject *constructor = exec->lexicalGlobalObject()->arrayConstructor();
     JSObject *res = static_cast<JSObject *>(constructor->construct(exec,List::empty()));
     JSValue* result = res;
     UString u = s;
@@ -1018,7 +1018,7 @@ bool StringObjectImp::implementsConstruct() const
 // ECMA 15.5.2
 JSObject *StringObjectImp::construct(ExecState *exec, const List &args)
 {
-  JSObject *proto = exec->lexicalInterpreter()->builtinStringPrototype();
+  JSObject *proto = exec->lexicalGlobalObject()->stringPrototype();
   if (args.size() == 0)
     return new StringInstance(proto);
   return new StringInstance(proto, args[0]->toString(exec));
index a06e5780c3ec414d8e72ffac55bc2907346509a3..6c14e19ceda755b918454116425623446bb47728 100644 (file)
@@ -27,6 +27,7 @@
 #include "JSLock.h"
 #include "Parser.h"
 #include "collector.h"
+#include "interpreter.h"
 #include "nodes.h"
 #include "object.h"
 #include "protect.h"
@@ -164,7 +165,7 @@ JSValue* TestFunctionImp::callAsFunction(ExecState* exec, JSObject*, const List
         return throwError(exec, GeneralError, "Could not open file.");
 
       stopWatch.start();
-      exec->dynamicInterpreter()->evaluate(fileName, 0, script.data());
+      Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), fileName, 0, script.data());
       stopWatch.stop();
       
       return jsNumber(stopWatch.getElapsedMS());
@@ -176,7 +177,7 @@ JSValue* TestFunctionImp::callAsFunction(ExecState* exec, JSObject*, const List
       if (!fillBufferWithContentsOfFile(fileName, script))
         return throwError(exec, GeneralError, "Could not open file.");
 
-      exec->dynamicInterpreter()->evaluate(fileName, 0, script.data());
+      Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), fileName, 0, script.data());
 
       return jsUndefined();
     }
@@ -224,8 +225,6 @@ int main(int argc, char** argv)
 static GlobalImp* createGlobalObject()
 {
   GlobalImp* global = new GlobalImp;
-  Interpreter* interp = new Interpreter;
-  interp->setGlobalObject(global); // global now owns interp.
 
   // add debug() function
   global->put(global->globalExec(), "debug", new TestFunctionImp(TestFunctionImp::Debug, 1));
@@ -275,7 +274,7 @@ static bool runWithScripts(const Vector<UString>& fileNames, bool prettyPrint)
     if (prettyPrint)
       prettyPrintScript(fileName, script);
     else {
-      Completion completion = globalObject->interpreter()->evaluate(fileName, 0, script.data());
+      Completion completion = Interpreter::evaluate(globalObject->globalExec(), fileName, 0, script.data());
       success = success && completion.complType() != Throw;
     }
   }
index 011752ef6b2582306519c67ae3eb0e4e2cef44a5..d3a43e9f0bce571750e598a0749344ce01770c9a 100644 (file)
@@ -1,3 +1,22 @@
+2007-12-04  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Third step in refactoring JSGlobalObject: Moved data members and data
+        member access from Interpreter to JSGlobalObject. Replaced JSInterpreter
+        subclass with JSGlobalObject subclass.
+        
+        * JSRun.cpp:
+        (JSRun::JSRun):
+        (JSRun::Evaluate):
+        (JSRun::CheckSyntax):
+        * JSRun.h:
+        (JSGlueGlobalObject::JSGlueGlobalObject):
+        * JSUtils.cpp:
+        (KJSValueToCFTypeInternal):
+        * JSValueWrapper.cpp:
+        (getThreadGlobalExecState):
+
 2007-12-02  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Eric Seidel.
index f809017eeb198e259c2c90838db55e09ca474f80..a0dd5efbd8961f53d212655c8e9232f6ff7b2fcc 100644 (file)
 JSRun::JSRun(CFStringRef source, JSFlags inFlags)
     :   JSBase(kJSRunTypeID),
         fSource(CFStringToUString(source)),
-        fGlobalObject(new JSGlobalObject()),
+        fGlobalObject(new JSGlueGlobalObject(inFlags)),
         fFlags(inFlags)
 {
-    Interpreter* interpreter = new JSInterpreter(fGlobalObject, inFlags);
-    interpreter->setGlobalObject(fGlobalObject); // fGlobalObject now owns interpreter
 }
 
 JSRun::~JSRun()
@@ -60,10 +58,10 @@ JSGlobalObject* JSRun::GlobalObject() const
 
 Completion JSRun::Evaluate()
 {
-    return fGlobalObject->interpreter()->evaluate(UString(), 0, fSource.data(), fSource.size());
+    return Interpreter::evaluate(fGlobalObject->globalExec(), UString(), 0, fSource.data(), fSource.size());
 }
 
 bool JSRun::CheckSyntax()
 {
-    return fGlobalObject->interpreter()->checkSyntax(UString(), 0, fSource.data(), fSource.size()).complType() != Throw;
+    return Interpreter::checkSyntax(fGlobalObject->globalExec(), UString(), 0, fSource.data(), fSource.size()).complType() != Throw;
 }
index bff911ce8df5fb873051a6bf79e485762597ec3f..3d5647c2bfd1dcd0588080db1f4a1caed78f83d7 100644 (file)
 #include "JSBase.h"
 #include "JSUtils.h"
 
-class JSInterpreter : public Interpreter {
+class JSGlueGlobalObject : public JSGlobalObject {
     public:
-        JSInterpreter(JSGlobalObject *global, JSFlags flags) : fJSFlags(flags) { setGlobalObject(global); }
-        JSInterpreter(JSGlobalObject *global) : fJSFlags(kJSFlagNone) { setGlobalObject(global); }
-        JSInterpreter() : fJSFlags(kJSFlagNone) { }
+        JSGlueGlobalObject(JSFlags flags) : fJSFlags(flags) { }
+        JSGlueGlobalObject() : fJSFlags(kJSFlagNone) { }
         JSFlags Flags() const { return fJSFlags; }
 
     private:
index 88241a56e7b37a819f7cfc844f83d62b4f8a3d76..dbc370e5488d8a96934a94bcad4526509bac0c48 100644 (file)
@@ -273,8 +273,8 @@ CFTypeRef KJSValueToCFTypeInternal(JSValue *inValue, ExecState *exec, ObjectImpL
 #endif
                     {
                         isArray = true;
-                        JSInterpreter* intrepreter = (JSInterpreter*)exec->dynamicInterpreter();
-                        if (intrepreter && (intrepreter->Flags() & kJSFlagConvertAssociativeArray)) {
+                        JSGlueGlobalObject* globalObject = static_cast<JSGlueGlobalObject*>(exec->dynamicGlobalObject());
+                        if (globalObject && (globalObject->Flags() & kJSFlagConvertAssociativeArray)) {
                             PropertyNameArray propNames;
                             object->getPropertyNames(exec, propNames);
                             PropertyNameArray::const_iterator iter = propNames.begin();
index dcd7af77a518d8cfb0bc5628383d58929840f2fb..f955ed043baa4e7030c7c8721cda45eb83a55440 100644 (file)
@@ -79,10 +79,7 @@ static ExecState* getThreadGlobalExecState()
     pthread_once(&globalObjectKeyOnce, initializeGlobalObjectKey);
     JSGlobalObject* globalObject = static_cast<JSGlobalObject*>(pthread_getspecific(globalObjectKey));
     if (!globalObject) {
-        globalObject = new JSGlobalObject;
-        Interpreter* interpreter = new JSInterpreter;
-        interpreter->setGlobalObject(globalObject); // globalObject now owns interpreter
-        
+        globalObject = new JSGlueGlobalObject;
         gcProtect(globalObject);
         pthread_setspecific(globalObjectKey, globalObject);
     }
index 4765abc5df3d914a2b6209f53e1fe86d8ec0ece4..60e8ccf2ab2f544f7f5ec036516a2593656b66a8 100644 (file)
@@ -1,3 +1,14 @@
+2007-12-04  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Third step in refactoring JSGlobalObject: Moved data members and data
+        member access from Interpreter to JSGlobalObject. Changed Interpreter
+        member functions to static functions. Same for the subclass, 
+        ScriptInterpreter.
+        
+        This is a big change, but it's mostly code motion and renaming.
+        
 2007-12-05  Darin Adler  <darin@apple.com>
 
         "Reviewed" by Geoff.
diff --git a/WebCore/ForwardingHeaders/kjs/JSGlobalObject.h b/WebCore/ForwardingHeaders/kjs/JSGlobalObject.h
new file mode 100644 (file)
index 0000000..915d87a
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/JSGlobalObject.h>
diff --git a/WebCore/ForwardingHeaders/kjs/array_object.h b/WebCore/ForwardingHeaders/kjs/array_object.h
new file mode 100644 (file)
index 0000000..8122fac
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/array_object.h>
diff --git a/WebCore/ForwardingHeaders/kjs/bool_object.h b/WebCore/ForwardingHeaders/kjs/bool_object.h
new file mode 100644 (file)
index 0000000..4755d9a
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/bool_object.h>
diff --git a/WebCore/ForwardingHeaders/kjs/function_object.h b/WebCore/ForwardingHeaders/kjs/function_object.h
new file mode 100644 (file)
index 0000000..42b8b63
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/function_object.h>
diff --git a/WebCore/ForwardingHeaders/kjs/object_object.h b/WebCore/ForwardingHeaders/kjs/object_object.h
new file mode 100644 (file)
index 0000000..6a70f08
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/object_object.h>
index c8dd17edb0ee4c25b27e379ad0c24a29a9d9e71e..bf874753af374eaf69ba55e858cf2fb6177d3ef0 100644 (file)
@@ -472,7 +472,6 @@ __ZN7WebCore8Document4bodyEv
 __ZN7WebCore8DragDataC1EP11objc_objectRKNS_8IntPointES5_NS_13DragOperationEPNS_16PasteboardHelperE
 __ZN7WebCore8IntPointC1ERK8_NSPoint
 __ZN7WebCore8KJSProxy10initScriptEv
-__ZN7WebCore8KJSProxy11interpreterEv
 __ZN7WebCore8Settings14setJavaEnabledEb
 __ZN7WebCore8Settings16setUsesPageCacheEb
 __ZN7WebCore8Settings17setPluginsEnabledEb
index 9d152fcbba87d0651602c60211527c30aa60cd42..7bb4fc8247604cebe335cbd2450a55df05869a29 100644 (file)
@@ -48,8 +48,7 @@ KJS::JSValue* toJS(KJS::ExecState* exec, CSSRule* rule)
     if (!rule)
         return KJS::jsNull();
 
-    KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
-    KJS::DOMObject* ret = interp->getDOMObject(rule);
+    KJS::DOMObject* ret = KJS::ScriptInterpreter::getDOMObject(rule);
 
     if (ret)
         return ret;
@@ -78,7 +77,7 @@ KJS::JSValue* toJS(KJS::ExecState* exec, CSSRule* rule)
             break;
     }
 
-    interp->putDOMObject(rule, ret);
+    KJS::ScriptInterpreter::putDOMObject(rule, ret);
     return ret;
 }
 
index fa47e9760422c5a32a15bced294a3e267e86d20f..3e68ce0e7b0ab6a72c64e16ae63d7381c2346b90 100644 (file)
@@ -107,7 +107,7 @@ JSValue* JSCSSStyleDeclaration::nameGetter(ExecState* exec, JSObject* originalOb
 
     // Make the SVG 'filter' attribute undetectable, to avoid confusion with the IE 'filter' attribute.
     if (propertyName == "filter")
-        return new StringInstanceThatMasqueradesAsUndefined(exec->lexicalInterpreter()->builtinStringPrototype(), thisObj->impl()->getPropertyValue(prop));
+        return new StringInstanceThatMasqueradesAsUndefined(exec->lexicalGlobalObject()->stringPrototype(), thisObj->impl()->getPropertyValue(prop));
 
     return jsString(thisObj->impl()->getPropertyValue(prop));
 }
index e8eec3c4eec2b191ad9ff14b7eb13488b5d30e02..c41603414252fba5b4760eb5b6451884a8302f91 100644 (file)
@@ -47,8 +47,7 @@ KJS::JSValue* toJS(KJS::ExecState* exec, CSSValue* value)
     if (!value)
         return KJS::jsNull();
 
-    KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
-    KJS::DOMObject* ret = interp->getDOMObject(value);
+    KJS::DOMObject* ret = KJS::ScriptInterpreter::getDOMObject(value);
 
     if (ret)
         return ret;
@@ -66,7 +65,7 @@ KJS::JSValue* toJS(KJS::ExecState* exec, CSSValue* value)
     else
         ret = new JSCSSValue(exec, value);
 
-    interp->putDOMObject(value, ret);
+    KJS::ScriptInterpreter::putDOMObject(value, ret);
     return ret;
 }
 
index 0c3d9b97d3017636c15f242558ebf3dcad8482fa..6fc1023281c59dc8da38d14372b73bcfa649d33c 100644 (file)
@@ -54,9 +54,9 @@ void JSCustomSQLStatementCallback::handleEvent(SQLTransaction* transaction, SQLR
     KJSProxy* proxy = m_frame->scriptProxy();
     if (!proxy)
         return;
-        
-    ScriptInterpreter* interpreter = proxy->interpreter();
-    ExecState* exec = proxy->globalObject()->globalExec();
+
+    JSGlobalObject* globalObject = proxy->globalObject();
+    ExecState* exec = globalObject->globalExec();
         
     KJS::JSLock lock;
         
@@ -79,12 +79,12 @@ void JSCustomSQLStatementCallback::handleEvent(SQLTransaction* transaction, SQLR
     args.append(toJS(exec, transaction));
     args.append(toJS(exec, resultSet));
         
-    interpreter->startTimeoutCheck();
+    globalObject->startTimeoutCheck();
     if (handleEventFunc)
         handleEventFunc->call(exec, m_callback, args);
     else
         m_callback->call(exec, m_callback, args);
-    interpreter->stopTimeoutCheck();
+    globalObject->stopTimeoutCheck();
         
     if (exec->hadException()) {
         JSObject* exception = exec->exception()->toObject(exec);
index 21acfc609776d72fbe85c9f7f219ff9fdf137a2a..a8f5e0916b43a6cc066846a749c00c4621372723 100644 (file)
@@ -55,8 +55,8 @@ bool JSCustomSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction,
     if (!proxy)
         return true;
         
-    ExecState* exec = proxy->globalObject()->globalExec();
-    ScriptInterpreter* interpreter = proxy->interpreter();
+    JSGlobalObject* globalObject = proxy->globalObject();
+    ExecState* exec = globalObject->globalExec();
         
     KJS::JSLock lock;
         
@@ -80,12 +80,12 @@ bool JSCustomSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction,
     args.append(toJS(exec, error));
         
     JSValue *result;
-    interpreter->startTimeoutCheck();
+    globalObject->startTimeoutCheck();
     if (handleEventFunc)
         result = handleEventFunc->call(exec, m_callback, args);
     else
         result = m_callback->call(exec, m_callback, args);
-    interpreter->stopTimeoutCheck();
+    globalObject->stopTimeoutCheck();
         
     if (exec->hadException()) {
         JSObject* exception = exec->exception()->toObject(exec);
index b443a5a9b4640b3cdb608b01165da65b42bcfc44..4f42af408414fb22c5667d04d5c7df247bedc7f1 100644 (file)
@@ -54,8 +54,8 @@ void JSCustomSQLTransactionCallback::handleEvent(SQLTransaction* transaction, bo
     if (!proxy)
         return;
         
-    ExecState* exec = proxy->globalObject()->globalExec();
-    ScriptInterpreter* interpreter = proxy->interpreter();
+    JSGlobalObject* globalObject = proxy->globalObject();
+    ExecState* exec = globalObject->globalExec();
         
     KJS::JSLock lock;
         
@@ -77,12 +77,12 @@ void JSCustomSQLTransactionCallback::handleEvent(SQLTransaction* transaction, bo
     List args;
     args.append(toJS(exec, transaction));
 
-    interpreter->startTimeoutCheck();
+    globalObject->startTimeoutCheck();
     if (handleEventFunc)
         handleEventFunc->call(exec, m_callback, args);
     else
         m_callback->call(exec, m_callback, args);
-    interpreter->stopTimeoutCheck();
+    globalObject->stopTimeoutCheck();
         
     if (exec->hadException()) {
         JSObject* exception = exec->exception()->toObject(exec);
index 4c693c66793f34b00b9b242d837802bec0a727d8..ea3c2d68a7b3682dc125a4f315baa2ffd2794791 100644 (file)
@@ -54,8 +54,8 @@ bool JSCustomSQLTransactionErrorCallback::handleEvent(SQLError* error)
     if (!proxy)
         return true;
         
-    ExecState* exec = proxy->globalObject()->globalExec();
-    ScriptInterpreter* interpreter = proxy->interpreter();
+    JSGlobalObject* globalObject = proxy->globalObject();
+    ExecState* exec = globalObject->globalExec();
         
     KJS::JSLock lock;
         
@@ -78,12 +78,12 @@ bool JSCustomSQLTransactionErrorCallback::handleEvent(SQLError* error)
     args.append(toJS(exec, error));
 
     JSValue *result;
-    interpreter->startTimeoutCheck();
+    globalObject->startTimeoutCheck();
     if (handleEventFunc)
         result = handleEventFunc->call(exec, m_callback, args);
     else
         result = m_callback->call(exec, m_callback, args);
-    interpreter->stopTimeoutCheck();
+    globalObject->stopTimeoutCheck();
         
     if (exec->hadException()) {
         JSObject* exception = exec->exception()->toObject(exec);
index cd37676b628cb77bf25943c1b75a87be0dc870f8..0eace5a224c83ad44f402e9e320857fbf13379b1 100644 (file)
@@ -56,8 +56,8 @@ void JSCustomVoidCallback::handleEvent()
     if (!proxy)
         return;
         
-    ExecState* exec = proxy->globalObject()->globalExec();
-    ScriptInterpreter* interpreter = proxy->interpreter();
+    JSGlobalObject* globalObject = proxy->globalObject();
+    ExecState* exec = globalObject->globalExec();
         
     KJS::JSLock lock;
         
@@ -78,12 +78,12 @@ void JSCustomVoidCallback::handleEvent()
         
     List args;
     
-    interpreter->startTimeoutCheck();
+    globalObject->startTimeoutCheck();
     if (handleEventFunc)
         handleEventFunc->call(exec, m_callback, args);
     else
         m_callback->call(exec, m_callback, args);
-    interpreter->stopTimeoutCheck();
+    globalObject->stopTimeoutCheck();
         
     if (exec->hadException()) {
         JSObject* exception = exec->exception()->toObject(exec);
index e2e1412b1e6b8793a107e8d2238fd9bfe7620399..6dc3a596fde277bc06957c807068fb83db53cdd2 100644 (file)
@@ -79,9 +79,9 @@ String JSCustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
 
     JSLock lock;
 
-    ExecState* exec = proxy->globalObject()->globalExec();
-    ScriptInterpreter* interpreter = proxy->interpreter();
-
+    JSGlobalObject* globalObject = proxy->globalObject();
+    ExecState* exec = globalObject->globalExec();
+        
     JSValue* lookupNamespaceURIFuncValue = m_customResolver->get(exec, "lookupNamespaceURI");
     JSObject* lookupNamespaceURIFunc = 0;
     if (lookupNamespaceURIFuncValue->isObject()) {      
@@ -104,12 +104,12 @@ String JSCustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
 
     String result;
     JSValue* retval;
-    interpreter->startTimeoutCheck();
+    globalObject->startTimeoutCheck();
     if (lookupNamespaceURIFunc)
         retval = lookupNamespaceURIFunc->call(exec, m_customResolver, args);
     else
         retval = m_customResolver->call(exec, m_customResolver, args);
-    interpreter->stopTimeoutCheck();
+    globalObject->stopTimeoutCheck();
 
     if (exec->hadException()) {
         JSObject* exception = exec->exception()->toObject(exec);
index b3d64acce8c39f490737ee082ab3ca761adb0ca9..5006265797e330b726446a59af526bf17718d036 100644 (file)
@@ -27,6 +27,7 @@
 #include "JSDOMExceptionConstructor.h"
 
 #include "ExceptionCode.h"
+#include <kjs/object_object.h>
 
 #include "JSDOMExceptionConstructor.lut.h"
 
@@ -58,7 +59,7 @@ const ClassInfo JSDOMExceptionConstructor::info = { "DOMExceptionConstructor", 0
 
 JSDOMExceptionConstructor::JSDOMExceptionConstructor(ExecState* exec) 
 { 
-    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
 }
 
 bool JSDOMExceptionConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
index 20957f0a9a7cb4845002e19c6074fa7f1ddb7c45..f634943905c0428c38fc6d8183e0385d99712382 100644 (file)
 #include "config.h"
 #include "JSDocument.h"
 
+#include "DOMWindow.h"
 #include "Document.h"
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "HTMLDocument.h"
+#include "JSDOMWindow.h"
 #include "JSHTMLDocument.h"
 #include "kjs_binding.h"
-#include "kjs_window.h"
+#include "kjs_proxy.h"
 
 #if ENABLE(SVG)
 #include "JSSVGDocument.h"
@@ -64,11 +66,11 @@ void JSDocument::setLocation(ExecState* exec, JSValue* value)
 
     // IE and Mozilla both resolve the URL relative to the source frame,
     // not the target frame.
-    Frame* activeFrame = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter())->frame();
+    Frame* activeFrame = static_cast<JSDOMWindow*>(exec->dynamicGlobalObject())->impl()->frame();
     if (activeFrame)
         str = activeFrame->document()->completeURL(str);
 
-    bool userGesture = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter())->wasRunByUserGesture();
+    bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
     frame->loader()->scheduleLocationChange(str, activeFrame->loader()->outgoingReferrer(), false, userGesture);
 }
 
@@ -77,8 +79,7 @@ JSValue* toJS(ExecState* exec, Document* doc)
     if (!doc)
         return jsNull();
 
-    ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
-    JSDocument* ret =  static_cast<JSDocument*>(interp->getDOMObject(doc));
+    JSDocument* ret = static_cast<JSDocument*>(ScriptInterpreter::getDOMObject(doc));
     if (ret)
         return ret;
 
@@ -103,7 +104,7 @@ JSValue* toJS(ExecState* exec, Document* doc)
         Collector::reportExtraMemoryCost(nodeCount * sizeof(Node));
     }
 
-    interp->putDOMObject(doc, ret);
+    ScriptInterpreter::putDOMObject(doc, ret);
 
     return ret;
 }
index 50e3e2d67b81ccacfb3a39116764434de92926ba..36292939e4293def3f3943d406aa7a10c01254e9 100644 (file)
 #include "WheelEvent.h"
 #include "kjs_events.h"
 
+using namespace KJS;
+
 namespace WebCore {
 
-KJS::JSValue* JSEvent::clipboardData(KJS::ExecState* exec) const
+JSValue* JSEvent::clipboardData(ExecState* exec) const
 {
-    return impl()->isClipboardEvent() ? toJS(exec, impl()->clipboardData()) : KJS::jsUndefined();
+    return impl()->isClipboardEvent() ? toJS(exec, impl()->clipboardData()) : jsUndefined();
 }
 
-KJS::JSValue* toJS(KJS::ExecState* exec, Event* event)
+JSValue* toJS(ExecState* exec, Event* event)
 {
-    KJS::JSLock lock;
+    JSLock lock;
 
     if (!event)
-        return KJS::jsNull();
+        return jsNull();
 
-    KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
 
-    KJS::DOMObject* ret = interp->getDOMObject(event);
+    DOMObject* ret = ScriptInterpreter::getDOMObject(event);
     if (ret)
         return ret;
 
@@ -88,7 +89,7 @@ KJS::JSValue* toJS(KJS::ExecState* exec, Event* event)
     else
         ret = new JSEvent(exec, event);
 
-    interp->putDOMObject(event, ret);
+    ScriptInterpreter::putDOMObject(event, ret);
     return ret;
 }
 
index 8a8303299855e2139147bd70d092594d99163924..84c8104fb7154fed3e323e1e7b8eaafa6407c2c9 100644 (file)
@@ -40,7 +40,7 @@ namespace WebCore {
 JSHTMLAudioElementConstructor::JSHTMLAudioElementConstructor(ExecState* exec, Document* d)
     : m_doc(d)
 {
-    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
     put(exec, exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);
 }
 
index d737dd261b36dc0ac1d87d03bf0c1c3c59d69358..578f9782173bd6548270ece06e6ea2df94d8e2e5 100644 (file)
 #include "kjs_html.h"
 #include <wtf/Vector.h>
 
+using namespace KJS;
+
 namespace WebCore {
 
-static KJS::JSValue* getNamedItems(KJS::ExecState* exec, HTMLCollection* impl, const KJS::Identifier& propertyName)
+static JSValue* getNamedItems(ExecState* exec, HTMLCollection* impl, const Identifier& propertyName)
 {
     Vector<RefPtr<Node> > namedItems;
     impl->namedItems(propertyName, namedItems);
 
     if (namedItems.isEmpty())
-        return KJS::jsUndefined();
+        return jsUndefined();
 
     if (namedItems.size() == 1)
         return toJS(exec, namedItems[0].get());
@@ -50,10 +52,10 @@ static KJS::JSValue* getNamedItems(KJS::ExecState* exec, HTMLCollection* impl, c
 
 // HTMLCollections are strange objects, they support both get and call,
 // so that document.forms.item(0) and document.forms(0) both work.
-KJS::JSValue* JSHTMLCollection::callAsFunction(KJS::ExecState* exec, KJS::JSObject*, const KJS::List& args)
+JSValue* JSHTMLCollection::callAsFunction(ExecState* exec, JSObject*, const List& args)
 {
     if (args.size() < 1)
-        return KJS::jsUndefined();
+        return jsUndefined();
 
     // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case.
     HTMLCollection* collection = impl();
@@ -63,18 +65,18 @@ KJS::JSValue* JSHTMLCollection::callAsFunction(KJS::ExecState* exec, KJS::JSObje
     if (args.size() == 1) {
         // Support for document.all(<index>) etc.
         bool ok;
-        KJS::UString string = args[0]->toString(exec);
+        UString string = args[0]->toString(exec);
         unsigned index = string.toUInt32(&ok, false);
         if (ok)
             return toJS(exec, collection->item(index));
 
         // Support for document.images('<name>') etc.
-        return getNamedItems(exec, collection, KJS::Identifier(string));
+        return getNamedItems(exec, collection, Identifier(string));
     }
 
     // The second arg, if set, is the index of the item we want
     bool ok;
-    KJS::UString string = args[0]->toString(exec);
+    UString string = args[0]->toString(exec);
     unsigned index = args[1]->toString(exec).toUInt32(&ok, false);
     if (ok) {
         String pstr = string;
@@ -87,7 +89,7 @@ KJS::JSValue* JSHTMLCollection::callAsFunction(KJS::ExecState* exec, KJS::JSObje
         }
     }
 
-    return KJS::jsUndefined();
+    return jsUndefined();
 }
 
 bool JSHTMLCollection::implementsCall() const
@@ -95,38 +97,37 @@ bool JSHTMLCollection::implementsCall() const
     return true;
 }
 
-bool JSHTMLCollection::canGetItemsForName(KJS::ExecState* exec, HTMLCollection* thisObj, const KJS::Identifier& propertyName)
+bool JSHTMLCollection::canGetItemsForName(ExecState* exec, HTMLCollection* thisObj, const Identifier& propertyName)
 {
     return !getNamedItems(exec, thisObj, propertyName)->isUndefined();
 }
 
-KJS::JSValue* JSHTMLCollection::nameGetter(KJS::ExecState* exec, KJS::JSObject* originalObject, const KJS::Identifier& propertyName, const KJS::PropertySlot& slot)
+JSValue* JSHTMLCollection::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
 {
     JSHTMLCollection* thisObj = static_cast<JSHTMLCollection*>(slot.slotBase());
     return getNamedItems(exec, thisObj->impl(), propertyName);
 }
 
-KJS::JSValue* JSHTMLCollection::item(KJS::ExecState* exec, const KJS::List& args)
+JSValue* JSHTMLCollection::item(ExecState* exec, const List& args)
 {
     bool ok;
     uint32_t index = args[0]->toString(exec).toUInt32(&ok, false);
     if (ok)
         return toJS(exec, impl()->item(index));
-    return getNamedItems(exec, impl(), KJS::Identifier(args[0]->toString(exec)));
+    return getNamedItems(exec, impl(), Identifier(args[0]->toString(exec)));
 }
 
-KJS::JSValue* JSHTMLCollection::namedItem(KJS::ExecState* exec, const KJS::List& args)
+JSValue* JSHTMLCollection::namedItem(ExecState* exec, const List& args)
 {
-    return getNamedItems(exec, impl(), KJS::Identifier(args[0]->toString(exec)));
+    return getNamedItems(exec, impl(), Identifier(args[0]->toString(exec)));
 }
 
-KJS::JSValue* toJS(KJS::ExecState* exec, HTMLCollection* collection)
+JSValue* toJS(ExecState* exec, HTMLCollection* collection)
 {
     if (!collection)
-        return KJS::jsNull();
+        return jsNull();
 
-    KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
-    KJS::DOMObject* ret = interp->getDOMObject(collection);
+    DOMObject* ret = ScriptInterpreter::getDOMObject(collection);
 
     if (ret)
         return ret;
@@ -143,7 +144,7 @@ KJS::JSValue* toJS(KJS::ExecState* exec, HTMLCollection* collection)
             break;
     }
 
-    interp->putDOMObject(collection, ret);
+    ScriptInterpreter::putDOMObject(collection, ret);
     return ret;
 }
 
index 3651a0acd9a3b69a7b47c9d5844332fbabfa08b5..4949b3e9eeffe9494913142bbab6369520dd2549 100644 (file)
@@ -32,7 +32,7 @@ using namespace KJS;
 JSHTMLOptionElementConstructor::JSHTMLOptionElementConstructor(ExecState* exec, Document* d)
     : m_doc(d)
 {
-    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
     put(exec, exec->propertyNames().length, jsNumber(4), ReadOnly|DontDelete|DontEnum);
 }
 
index 42c3bea14df56ef144204b359893c12a3d751b04..47715ef34d9df2b155c68ed6e7346d2648eea391 100644 (file)
@@ -43,7 +43,7 @@ const ClassInfo JSNamedNodesCollection::info = { "Collection", 0, 0 };
 JSNamedNodesCollection::JSNamedNodesCollection(ExecState* exec, const Vector<RefPtr<Node> >& nodes)
     : m_nodes(nodes)
 {
-    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
 }
 
 JSValue* JSNamedNodesCollection::lengthGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
index 6a5ce1c5e0d4c603adb612ed35cc2412f5718dfb..720c96981cce60cdd8cc868f8cd5b76124f0da02 100644 (file)
 #include "SVGElement.h"
 #endif
 
+using namespace KJS;
+
 namespace WebCore {
 
 typedef int ExpectionCode;
 
-KJS::JSValue* JSNode::insertBefore(KJS::ExecState* exec, const KJS::List& args)
+JSValue* JSNode::insertBefore(ExecState* exec, const List& args)
 {
     ExceptionCode ec = 0;
     bool ok = impl()->insertBefore(toNode(args[0]), toNode(args[1]), ec);
-    KJS::setDOMException(exec, ec);
+    setDOMException(exec, ec);
     if (ok)
         return args[0];
-    return KJS::jsNull();
+    return jsNull();
 }
 
-KJS::JSValue* JSNode::replaceChild(KJS::ExecState* exec, const KJS::List& args)
+JSValue* JSNode::replaceChild(ExecState* exec, const List& args)
 {
     ExceptionCode ec = 0;
     bool ok = impl()->replaceChild(toNode(args[0]), toNode(args[1]), ec);
-    KJS::setDOMException(exec, ec);
+    setDOMException(exec, ec);
     if (ok)
         return args[1];
-    return KJS::jsNull();
+    return jsNull();
 }
 
-KJS::JSValue* JSNode::removeChild(KJS::ExecState* exec, const KJS::List& args)
+JSValue* JSNode::removeChild(ExecState* exec, const List& args)
 {
     ExceptionCode ec = 0;
     bool ok = impl()->removeChild(toNode(args[0]), ec);
-    KJS::setDOMException(exec, ec);
+    setDOMException(exec, ec);
     if (ok)
         return args[0];
-    return KJS::jsNull();
+    return jsNull();
 }
 
-KJS::JSValue* JSNode::appendChild(KJS::ExecState* exec, const KJS::List& args)
+JSValue* JSNode::appendChild(ExecState* exec, const List& args)
 {
     ExceptionCode ec = 0;
     bool ok = impl()->appendChild(toNode(args[0]), ec);
-    KJS::setDOMException(exec, ec);
+    setDOMException(exec, ec);
     if (ok)
         return args[0];
-    return KJS::jsNull();
+    return jsNull();
 }
 
 void JSNode::mark()
@@ -133,7 +135,7 @@ void JSNode::mark()
     // Mark the whole tree; use the global set of roots to avoid reentering.
     root->m_inSubtreeMark = true;
     for (Node* nodeToMark = root; nodeToMark; nodeToMark = nodeToMark->traverseNextNode()) {
-        JSNode* wrapper = KJS::ScriptInterpreter::getDOMNodeForDocument(m_impl->document(), nodeToMark);
+        JSNode* wrapper = ScriptInterpreter::getDOMNodeForDocument(m_impl->document(), nodeToMark);
         if (wrapper) {
             if (!wrapper->marked())
                 wrapper->mark();
@@ -153,15 +155,14 @@ void JSNode::mark()
     ASSERT(marked());
 }
 
-KJS::JSValue* toJS(KJS::ExecState* exec, PassRefPtr<Node> n)
+JSValue* toJS(ExecState* exec, PassRefPtr<Node> n)
 {
     Node* node = n.get(); 
     if (!node)
-        return KJS::jsNull();
+        return jsNull();
 
-    KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
     Document* doc = node->document();
-    JSNode* ret = interp->getDOMNodeForDocument(doc, node);
+    JSNode* ret = ScriptInterpreter::getDOMNodeForDocument(doc, node);
     if (ret)
         return ret;
 
@@ -213,7 +214,7 @@ KJS::JSValue* toJS(KJS::ExecState* exec, PassRefPtr<Node> n)
             ret = new JSNode(exec, node);
     }
 
-    interp->putDOMNodeForDocument(doc, node, ret);
+    ScriptInterpreter::putDOMNodeForDocument(doc, node, ret);
 
     return ret;
 }
index fba0b5df24df663719b81ec6bd5729d7b46cfc43..1d00eca63d4d6e430fed50caa6e75b0a729c3d48 100644 (file)
@@ -50,7 +50,7 @@ JSValue* JSSQLResultSetRowList::item(ExecState* exec, const List& args)
         return jsUndefined();
     }
 
-    JSObject* object = new JSObject(exec->lexicalInterpreter()->builtinObjectPrototype());
+    JSObject* object = new JSObject(exec->lexicalGlobalObject()->objectPrototype());
 
     unsigned numColumns = m_impl->columnNames().size();
     unsigned valuesIndex = index * numColumns;
index 30fc63ea61ec92ef9d797d8354e278560f0c29f7..68ce4fedc981c11f4ef8b434f74d2da4769359e7 100644 (file)
 #include "JSCSSStyleSheet.h"
 #include "StyleSheet.h"
 
+using namespace KJS;
+
 namespace WebCore {
 
-KJS::JSValue* toJS(KJS::ExecState* exec, StyleSheet* styleSheet)
+JSValue* toJS(ExecState* exec, StyleSheet* styleSheet)
 {
     if (!styleSheet)
-        return KJS::jsNull();
+        return jsNull();
 
-    KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
-    KJS::DOMObject* ret = interp->getDOMObject(styleSheet);
+    DOMObject* ret = ScriptInterpreter::getDOMObject(styleSheet);
     if (ret)
         return ret;
 
@@ -47,7 +48,7 @@ KJS::JSValue* toJS(KJS::ExecState* exec, StyleSheet* styleSheet)
     else
         ret = new JSStyleSheet(exec, styleSheet);
 
-    interp->putDOMObject(styleSheet, ret);
+    ScriptInterpreter::putDOMObject(styleSheet, ret);
     return ret;
 }
 
index 5098785e3100d209f333359361b40ea384af6ead..8b08016826e789d1fa6d94abb70296d22819c554 100644 (file)
@@ -61,7 +61,7 @@ KJS_IMPLEMENT_PROTOTYPE("JSXMLHttpRequest", JSXMLHttpRequestPrototype)
 JSXMLHttpRequestConstructorImp::JSXMLHttpRequestConstructorImp(ExecState* exec, Document* d)
     : doc(d)
 {
-    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
     putDirect(exec->propertyNames().prototype, JSXMLHttpRequestPrototype::self(exec), None);
 }
 
index 6da8bfde3c0c8bff465776ad466865e88178db75..60d67ded04e1828975eab42cd27102cf4849d7f7 100644 (file)
@@ -186,7 +186,7 @@ JSValue* JSXSLTProcessorPrototypeFunctionReset::callAsFunction(ExecState* exec,
 
 XSLTProcessorConstructorImp::XSLTProcessorConstructorImp(ExecState *exec)
 {
-    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
     putDirect(exec->propertyNames().prototype, XSLTProcessorPrototype::self(exec), None);
 }
 
index c5b53f5cef607b855f5e6d8f3be7db70eda9d329..296091d3d1f58a3e04f21757b8b7978eab23c10a 100644 (file)
@@ -137,17 +137,6 @@ static NodePerDocMap& domNodesPerDocument()
     return staticDOMNodesPerDocument;
 }
 
-ScriptInterpreter::ScriptInterpreter(JSGlobalObject* global, Frame* frame)
-    : m_frame(frame)
-    , m_currentEvent(0)
-    , m_inlineCode(false)
-    , m_timerCallback(false)
-{
-    setGlobalObject(global);
-    // Time in milliseconds before the script timeout handler kicks in.
-    setTimeoutTime(10000);
-}
-
 DOMObject* ScriptInterpreter::getDOMObject(void* objectHandle) 
 {
     return domObjects().get(objectHandle);
@@ -244,31 +233,6 @@ void ScriptInterpreter::updateDOMNodeDocument(Node* node, Document* oldDoc, Docu
     }
 }
 
-bool ScriptInterpreter::wasRunByUserGesture() const
-{
-    if (m_currentEvent) {
-        const AtomicString& type = m_currentEvent->type();
-        bool eventOk = ( // mouse events
-            type == clickEvent || type == mousedownEvent ||
-            type == mouseupEvent || type == dblclickEvent ||
-            // keyboard events
-            type == keydownEvent || type == keypressEvent ||
-            type == keyupEvent ||
-            // other accepted events
-            type == selectEvent || type == changeEvent ||
-            type == focusEvent || type == blurEvent ||
-            type == submitEvent);
-        if (eventOk)
-            return true;
-    } else { // no event
-        if (m_inlineCode && !m_timerCallback)
-            // This is the <a href="javascript:window.open('...')> case -> we let it through
-            return true;
-        // This is the <script>window.open(...)</script> case or a timer callback -> block it
-    }
-    return false;
-}
-
 JSValue* jsStringOrNull(const String& s)
 {
     if (s.isNull())
index 411f5dd3819bc9f8693975528e4f763314c37e13..224f5051aa1309e2b70972d9298c48e3dc15885e 100644 (file)
@@ -24,6 +24,7 @@
 #define kjs_binding_h
 
 #include <kjs/function.h>
+#include <kjs/interpreter.h>
 #include <kjs/lookup.h>
 #include <wtf/Noncopyable.h>
 
@@ -65,15 +66,8 @@ namespace KJS {
 #endif
     };
 
-    /**
-     * We inherit from Interpreter, to save a pointer to the HTML part
-     * that the interpreter runs for.
-     * The interpreter also stores the DOM object -> KJS::DOMObject cache.
-     */
     class ScriptInterpreter : public Interpreter {
     public:
-        ScriptInterpreter(JSGlobalObject*, WebCore::Frame*);
-
         static DOMObject* getDOMObject(void* objectHandle);
         static void putDOMObject(void* objectHandle, DOMObject*);
         static void forgetDOMObject(void* objectHandle);
@@ -84,29 +78,6 @@ namespace KJS {
         static void forgetAllDOMNodesForDocument(WebCore::Document*);
         static void updateDOMNodeDocument(WebCore::Node*, WebCore::Document* oldDoc, WebCore::Document* newDoc);
         static void markDOMNodesForDocument(WebCore::Document*);
-
-        WebCore::Frame* frame() const { return m_frame; }
-
-        /**
-         * Set the event that is triggering the execution of a script, if any
-         */
-        void setCurrentEvent(WebCore::Event* event) { m_currentEvent = event; }
-        void setInlineCode(bool inlineCode) { m_inlineCode = inlineCode; }
-        void setProcessingTimerCallback(bool timerCallback) { m_timerCallback = timerCallback; }
-
-        /**
-         * "Smart" window.open policy
-         */
-        bool wasRunByUserGesture() const;
-
-        WebCore::Event* getCurrentEvent() const { return m_currentEvent; }
-
-    private:
-    
-        WebCore::Frame* m_frame;
-        WebCore::Event* m_currentEvent;
-        bool m_inlineCode;
-        bool m_timerCallback;
     };
 
     /**
@@ -116,11 +87,10 @@ namespace KJS {
     {
         if (!domObj)
             return jsNull();
-        ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
-        if (DOMObject* ret = interp->getDOMObject(domObj))
+        if (DOMObject* ret = ScriptInterpreter::getDOMObject(domObj))
             return ret;
         DOMObject* ret = new KJSDOMObj(exec, domObj);
-        interp->putDOMObject(domObj, ret);
+        ScriptInterpreter::putDOMObject(domObj, ret);
         return ret;
     }
 
@@ -132,11 +102,10 @@ namespace KJS {
     {
         if (!domObj)
             return jsNull();
-        ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
-        if (DOMObject* ret = interp->getDOMObject(domObj))
+        if (DOMObject* ret = ScriptInterpreter::getDOMObject(domObj))
             return ret;
         DOMObject* ret = new KJSDOMObj(exec, domObj, context);
-        interp->putDOMObject(domObj, ret);
+        ScriptInterpreter::putDOMObject(domObj, ret);
         return ret;
     }
 #endif
index 0a809d73b1b524396b0c69a12cdf4a08d8065098..dfe23e19cadb1e02f83c8813e7e748cf7095f52b 100644 (file)
@@ -47,7 +47,7 @@ const ClassInfo JSRGBColor::info = { "RGBColor", 0, &JSRGBColorTable };
 JSRGBColor::JSRGBColor(ExecState* exec, unsigned color) 
     : m_color(color) 
 { 
-    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
 }
 
 JSRGBColor::~JSRGBColor()
index 10b2e0dd42f5a4f016a7f9a23187770a1b819b64..a67b3b11b9c188e7717c8fb145a3510abc853b80 100644 (file)
@@ -62,7 +62,7 @@ bool checkNodeSecurity(ExecState* exec, Node* n)
     return false;
 
   // Check to see if the currently executing interpreter is allowed to access the specified node
-  KJS::Window* win = KJS::Window::retrieveWindow(n->document()->frame());
+  Window* win = Window::retrieveWindow(n->document()->frame());
   return win && win->isSafeScript(exec);
 }
 
@@ -82,12 +82,9 @@ JSValue* toJS(ExecState* exec, EventTarget* target)
     if (node)
         return toJS(exec, node);
 
-    XMLHttpRequest* xhr = target->toXMLHttpRequest();
-    if (xhr) {
+    if (XMLHttpRequest* xhr = target->toXMLHttpRequest())
         // XMLHttpRequest is always created via JS, so we don't need to use cacheDOMObject() here.
-        ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
-        return interp->getDOMObject(xhr);
-    }
+        return ScriptInterpreter::getDOMObject(xhr);
 
     // There are two kinds of EventTargets: EventTargetNode and XMLHttpRequest.
     // If SVG support is enabled, there is also SVGElementInstance.
index 0328776e4a649df70afd92ac96c25a55be502a1d..8fded9d8eb50600984585702cf89b1a92ce74b85 100644 (file)
@@ -38,6 +38,8 @@
 #include "Page.h"
 #include "kjs_proxy.h"
 #include "kjs_window.h"
+#include <kjs/array_object.h>
+#include <kjs/function_object.h>
 
 #include "kjs_events.lut.h"
 
@@ -79,8 +81,8 @@ void JSAbstractEventListener::handleEvent(Event* ele, bool isWindowEvent)
 
     JSLock lock;
 
-    ScriptInterpreter* interpreter = proxy->interpreter();
-    ExecState* exec = proxy->globalObject()->globalExec();
+    JSGlobalObject* globalObject = proxy->globalObject();
+    ExecState* exec = globalObject->globalExec();
 
     JSValue* handleEventFuncValue = listener->get(exec, "handleEvent");
     JSObject* handleEventFunc = 0;
@@ -96,14 +98,11 @@ void JSAbstractEventListener::handleEvent(Event* ele, bool isWindowEvent)
         List args;
         args.append(toJS(exec, event));
 
-        // Set the event we're handling in the KJS::Window object
         window->setCurrentEvent(event);
-        // ... and in the interpreter
-        interpreter->setCurrentEvent(event);
 
         JSValue* retval;
         if (handleEventFunc) {
-            interpreter->startTimeoutCheck();
+            globalObject->startTimeoutCheck();
             retval = handleEventFunc->call(exec, listener, args);
         } else {
             JSObject* thisObj;
@@ -111,13 +110,12 @@ void JSAbstractEventListener::handleEvent(Event* ele, bool isWindowEvent)
                 thisObj = window;
             else
                 thisObj = static_cast<JSObject*>(toJS(exec, event->currentTarget()));
-            interpreter->startTimeoutCheck();
+            globalObject->startTimeoutCheck();
             retval = listener->call(exec, thisObj, args);
         }
-        interpreter->stopTimeoutCheck();
+        globalObject->stopTimeoutCheck();
 
         window->setCurrentEvent(0);
-        interpreter->setCurrentEvent(0);
 
         if (exec->hadException()) {
             JSObject* exception = exec->exception()->toObject(exec);
@@ -296,11 +294,10 @@ void JSLazyEventListener::parseCode() const
         proxy = frame->scriptProxy();
 
     if (proxy) {
-        ScriptInterpreter* interpreter = proxy->interpreter();
         ExecState* exec = proxy->globalObject()->globalExec();
 
         JSLock lock;
-        JSObject* constr = interpreter->builtinFunction();
+        JSObject* constr = proxy->globalObject()->functionConstructor();
         List args;
 
         UString sourceURL(frame->loader()->url().url());
@@ -405,7 +402,7 @@ JSValue* JSClipboard::getValueProperty(ExecState* exec, int token) const
                 HashSet<String>::const_iterator end = types.end();
                 for (HashSet<String>::const_iterator it = types.begin(); it != end; ++it)
                     list.append(jsString(UString(*it)));
-                return exec->lexicalInterpreter()->builtinArray()->construct(exec, list);
+                return exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, list);
             }
         }
         default:
index 545e00246efbd83dcbdea889842b7ddec9d46556..52afd95e8341e3511a29a077884bfac1e33f4385 100644 (file)
@@ -25,7 +25,7 @@
 #include "PlatformString.h"
 #include "kjs_dom.h"
 #include "kjs_html.h"
-
+#include <kjs/protect.h>
 
 namespace KJS {
     class Window;
index 23434efe54d3b1a8ffc0aee376baa836ad6a01d9..3ac990d87f88240cbcddea1fe2062b6b6099e712 100644 (file)
@@ -36,7 +36,7 @@ using namespace KJS;
 ImageConstructorImp::ImageConstructorImp(ExecState* exec, Document* doc)
     : m_doc(doc)
 {
-    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
 }
 
 JSObject* ImageConstructorImp::construct(ExecState*  exec, const List& list)
index 651f95c2ca12d272d623adde8f41333adb2feafb..2d9c60a558b2623803851876bff7417ce091d086 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "AtomicString.h"
 #include "CookieJar.h"
+#include "DOMWindow.h"
 #include "Document.h"
 #include "Frame.h"
 #include "FrameLoader.h"
@@ -32,6 +33,8 @@
 #include "Page.h"
 #include "PlugInInfoStore.h"
 #include "Settings.h"
+#include "kjs_window.h"
+#include <kjs/object_object.h>
 
 #ifndef WEBCORE_NAVIGATOR_PLATFORM
 #if PLATFORM(MAC) && PLATFORM(PPC)
@@ -175,7 +178,7 @@ const ClassInfo Navigator::info = { "Navigator", 0, &NavigatorTable };
 Navigator::Navigator(ExecState *exec, Frame *f) 
     : m_frame(f)
 {
-    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
 }
 
 bool Navigator::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
@@ -248,7 +251,7 @@ void PluginBase::cachePluginDataIfNecessary()
 
 PluginBase::PluginBase(ExecState *exec)
 {
-    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
 
     cachePluginDataIfNecessary();
     m_plugInCacheRefCount++;
@@ -512,8 +515,7 @@ JSValue *MimeType::getValueProperty(ExecState *exec, int token) const
     case Description:
         return jsString(m_info->desc);
     case EnabledPlugin: {
-        ScriptInterpreter *interpreter = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter());
-        Frame *frame = interpreter->frame();
+        Frame* frame = Window::retrieveActive(exec)->impl()->frame();
         ASSERT(frame);
         Settings* settings = frame->settings();
         if (settings && settings->arePluginsEnabled())
index fd51f74da657f362cff3c72167a92b70a38ec4f1..dc466c7a58cf13f90935e241edcba6870b1ffdfb 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "Chrome.h"
 #include "Document.h"
+#include "Event.h"
+#include "EventNames.h"
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "GCController.h"
 #endif
 
 using namespace KJS;
+using namespace WebCore::EventNames;
 
 namespace WebCore {
 
 KJSProxy::KJSProxy(Frame* frame)
     : m_frame(frame)
     , m_handlerLineno(0)
+    , m_processingTimerCallback(0)
+    , m_processingInlineCode(0)
 {
 }
 
 KJSProxy::~KJSProxy()
 {
-    // Check for <rdar://problem/4876466>. In theory, no JS should be executing
-    // in our interpreter. 
-    ASSERT(!m_globalObject || !m_globalObject->interpreter()->currentExec());
+    // Check for <rdar://problem/4876466>. In theory, no JS should be executing now.
+    ASSERT(!m_globalObject || !m_globalObject->currentExec());
     
     if (m_globalObject) {
         m_globalObject = 0;
     
-        // It's likely that destroying the interpreter has created a lot of garbage.
+        // It's likely that releasing the global object has created a lot of garbage.
         gcController().garbageCollectSoon();
     }
 }
@@ -71,12 +75,8 @@ JSValue* KJSProxy::evaluate(const String& filename, int baseLine, const String&
     // and false for <script>doSomething()</script>. Check if it has the
     // expected value in all cases.
     // See smart window.open policy for where this is used.
-    bool inlineCode = filename.isNull();
-
-    ScriptInterpreter* interpreter = static_cast<ScriptInterpreter*>(m_globalObject->interpreter());
     ExecState* exec = m_globalObject->globalExec();
-
-    interpreter->setInlineCode(inlineCode);
+    m_processingInlineCode = filename.isNull();
 
     JSLock lock;
 
@@ -86,12 +86,14 @@ JSValue* KJSProxy::evaluate(const String& filename, int baseLine, const String&
     
     JSValue* thisNode = Window::retrieve(m_frame);
   
-    interpreter->startTimeoutCheck();
-    Completion comp = interpreter->evaluate(filename, baseLine, reinterpret_cast<const KJS::UChar*>(str.characters()), str.length(), thisNode);
-    interpreter->stopTimeoutCheck();
+    m_globalObject->startTimeoutCheck();
+    Completion comp = Interpreter::evaluate(exec, filename, baseLine, reinterpret_cast<const KJS::UChar*>(str.characters()), str.length(), thisNode);
+    m_globalObject->stopTimeoutCheck();
   
-    if (comp.complType() == Normal || comp.complType() == ReturnValue)
+    if (comp.complType() == Normal || comp.complType() == ReturnValue) {
+        m_processingInlineCode = false;
         return comp.value();
+    }
 
     if (comp.complType() == Throw) {
         UString errorMessage = comp.value()->toString(exec);
@@ -101,15 +103,17 @@ JSValue* KJSProxy::evaluate(const String& filename, int baseLine, const String&
             page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, sourceURL);
     }
 
+    m_processingInlineCode = false;
     return 0;
 }
 
-void KJSProxy::clear() {
-  // clear resources allocated by the interpreter, and make it ready to be used by another page
-  // We have to keep it, so that the Window object for the frame remains the same.
-  // (we used to delete and re-create it, previously)
-  if (m_globalObject)
-    m_globalObject->clear();
+void KJSProxy::clear()
+{
+    // clear resources allocated by the global object, and make it ready to be used by another page
+    // We have to keep it, so that the Window object for the frame remains the same.
+    // (we used to delete and re-create it, previously)
+    if (m_globalObject)
+        m_globalObject->clear();
 }
 
 EventListener* KJSProxy::createHTMLEventHandler(const String& functionName, const String& code, Node* node)
@@ -134,37 +138,29 @@ void KJSProxy::finishedWithEvent(Event* event)
   // is the case in sitations where an event has been created just for temporary usage,
   // e.g. an image load or mouse move. Once the event has been dispatched, it is forgotten
   // by the DOM implementation and so does not need to be cached still by the interpreter
-  if (!m_globalObject)
-    return;
-  static_cast<ScriptInterpreter*>(m_globalObject->interpreter())->forgetDOMObject(event);
-}
-
-ScriptInterpreter* KJSProxy::interpreter()
-{
-    initScriptIfNeeded();
-    return static_cast<ScriptInterpreter*>(m_globalObject->interpreter());
+  ScriptInterpreter::forgetDOMObject(event);
 }
 
 void KJSProxy::initScript()
 {
-  if (m_globalObject)
-    return;
+    if (m_globalObject)
+        return;
 
-  // Build the global object - which is a Window instance
-  JSLock lock;
-  
-  m_globalObject = new JSDOMWindow(m_frame->domWindow());
-  ScriptInterpreter* interpreter = new ScriptInterpreter(m_globalObject, m_frame); // m_globalObject now owns interpreter
-
-  String userAgent = m_frame->loader()->userAgent(m_frame->document() ? m_frame->document()->URL() : KURL());
-  if (userAgent.find("Microsoft") >= 0 || userAgent.find("MSIE") >= 0)
-    interpreter->setCompatMode(Interpreter::IECompat);
-  else
-    // If we find "Mozilla" but not "(compatible, ...)" we are a real Netscape
-    if (userAgent.find("Mozilla") >= 0 && userAgent.find("compatible") == -1)
-      interpreter->setCompatMode(Interpreter::NetscapeCompat);
-
-  m_frame->loader()->dispatchWindowObjectAvailable();
+    JSLock lock;
+
+    m_globalObject = new JSDOMWindow(m_frame->domWindow());
+
+    // FIXME: We can get rid of this (and eliminate compatMode entirely).
+    String userAgent = m_frame->loader()->userAgent(m_frame->document() ? m_frame->document()->URL() : KURL());
+    if (userAgent.find("Microsoft") >= 0 || userAgent.find("MSIE") >= 0)
+        m_globalObject->setCompatMode(IECompat);
+    else {
+        // If we find "Mozilla" but not "(compatible, ...)" we are a real Netscape
+        if (userAgent.find("Mozilla") >= 0 && userAgent.find("compatible") == -1)
+            m_globalObject->setCompatMode(NetscapeCompat);
+    }
+
+    m_frame->loader()->dispatchWindowObjectAvailable();
 }
     
 void KJSProxy::clearDocumentWrapper() 
@@ -176,4 +172,32 @@ void KJSProxy::clearDocumentWrapper()
     m_globalObject->removeDirect("document");
 }
 
+bool KJSProxy::processingUserGesture() const
+{
+    if (!m_globalObject)
+        return false;
+
+    if (Event* event = m_globalObject->currentEvent()) {
+        const AtomicString& type = event->type();
+        if ( // mouse events
+            type == clickEvent || type == mousedownEvent ||
+            type == mouseupEvent || type == dblclickEvent ||
+            // keyboard events
+            type == keydownEvent || type == keypressEvent ||
+            type == keyupEvent ||
+            // other accepted events
+            type == selectEvent || type == changeEvent ||
+            type == focusEvent || type == blurEvent ||
+            type == submitEvent)
+            return true;
+    } else { // no event
+        if (m_processingInlineCode && !m_processingTimerCallback) {
+            // This is the <a href="javascript:window.open('...')> case -> we let it through
+            return true;
+        }
+        // This is the <script>window.open(...)</script> case or a timer callback -> block it
+    }
+    return false;
+}
+
 } // namespace WebCore
index 7147300381201606c5872907fb58274c2721d20a..411d9bbdefc0743e950ad05d2e79ac04e774b678 100644 (file)
@@ -28,7 +28,6 @@
 namespace KJS {
     class JSGlobalObject;
     class JSValue;
-    class ScriptInterpreter;
 }
 
 namespace WebCore {
@@ -39,17 +38,15 @@ class Frame;
 class Node;
 class String;
 
-// FIXME: Rename this class to JSController and merge functions from 
-// ScriptInterpreter into it.
+// FIXME: Rename this class to JSController and the Frame function to javaScript().
 
 class KJSProxy {
 public:
     KJSProxy(Frame*);
     ~KJSProxy();
 
-    bool haveInterpreter() const { return m_globalObject; }
-    KJS::ScriptInterpreter* interpreter();
-    KJS::JSGlobalObject* globalObject()
+    bool haveGlobalObject() const { return m_globalObject; }
+    JSDOMWindow* globalObject()
     {
         initScriptIfNeeded();
         return m_globalObject;
@@ -66,6 +63,9 @@ public:
 
     void clearDocumentWrapper();
 
+    void setProcessingTimerCallback(bool b) { m_processingTimerCallback = b; }
+    bool processingUserGesture() const;
+
 private:
     void initScriptIfNeeded()
     {
@@ -77,6 +77,9 @@ private:
     KJS::ProtectedPtr<JSDOMWindow> m_globalObject;
     Frame* m_frame;
     int m_handlerLineno;
+    
+    bool m_processingTimerCallback;
+    bool m_processingInlineCode;
 };
 
 }
index cd8414c51d4dfb44c7da08d8372228be0be8afd8..a5a0adf588841d00f909ffde58c0968b7c56e64e 100644 (file)
@@ -222,6 +222,9 @@ Window::Window(DOMWindow* window)
     // Window destruction is not thread-safe because of
     // the non-thread-safe WebCore structures it references.
     Collector::collectOnMainThreadOnly(this);
+
+    // Time in milliseconds before the script timeout handler kicks in.
+    setTimeoutTime(10000);
 }
 
 Window::~Window()
@@ -259,7 +262,7 @@ Window *Window::retrieveWindow(Frame *f)
 
 Window *Window::retrieveActive(ExecState *exec)
 {
-    JSValue *imp = exec->dynamicInterpreter()->globalObject();
+    JSValue *imp = exec->dynamicGlobalObject();
     ASSERT(imp);
     return static_cast<Window*>(imp);
 }
@@ -293,7 +296,7 @@ static bool allowPopUp(ExecState *exec, Window *window)
     Frame* frame = window->impl()->frame();
     if (!frame)
         return false;
-    if (static_cast<ScriptInterpreter*>(exec->dynamicInterpreter())->wasRunByUserGesture())
+    if (window->impl()->frame()->scriptProxy()->processingUserGesture());
         return true;
     Settings* settings = frame->settings();
     return settings && settings->JavaScriptCanOpenWindowsAutomatically();
@@ -389,7 +392,7 @@ static Frame* createWindow(ExecState* exec, Frame* openerFrame, const String& ur
 
     if (!url.startsWith("javascript:", false) || newWindow->isSafeScript(exec)) {
         String completedURL = url.isEmpty() ? url : activeFrame->document()->completeURL(url);
-        bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
+        bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
         
         if (created) {
             newFrame->loader()->changeLocation(KURL(completedURL.deprecatedString()), activeFrame->loader()->outgoingReferrer(), false, userGesture);
@@ -726,7 +729,7 @@ void Window::put(ExecState* exec, const Identifier& propertyName, JSValue* value
           return;
         DeprecatedString dstUrl = p->loader()->completeURL(DeprecatedString(value->toString(exec))).url();
         if (!dstUrl.startsWith("javascript:", false) || isSafeScript(exec)) {
-          bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
+          bool userGesture = p->scriptProxy()->processingUserGesture();
           // We want a new history item if this JS was called via a user gesture
           impl()->frame()->loader()->scheduleLocationChange(dstUrl, p->loader()->outgoingReferrer(), false, userGesture);
         }
@@ -934,7 +937,7 @@ bool Window::isSafeScript(ExecState *exec) const
   Frame* frame = impl()->frame();
   if (!frame)
     return false;
-  Frame* activeFrame = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter())->frame();
+  Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame();
   if (!activeFrame)
     return false;
   if (activeFrame == frame)
@@ -1065,12 +1068,11 @@ void Window::clear()
   clearAllTimeouts();
   clearProperties();
   clearHelperObjectProperties();
-  setPrototype(JSDOMWindowPrototype::self()); // clear the prototype
 
   // Now recreate a working global object for the next URL that will use us; but only if we haven't been
   // disconnected yet
   if (Frame* frame = impl()->frame())
-    frame->scriptProxy()->interpreter()->resetGlobalObjectProperties();
+    frame->scriptProxy()->globalObject()->reset(JSDOMWindowPrototype::self());
 
   // there's likely to be lots of garbage now
   gcController().garbageCollectSoon();
@@ -1081,6 +1083,11 @@ void Window::setCurrentEvent(Event *evt)
   d->m_evt = evt;
 }
 
+Event* Window::currentEvent()
+{
+    return d->m_evt;
+}
+
 static void setWindowFeature(const String& keyString, const String& valueString, WindowFeatures& windowFeatures)
 {
     int value;
@@ -1356,7 +1363,7 @@ JSValue* WindowProtoFuncOpen::callAsFunction(ExecState* exec, JSObject* thisObj,
 
         const Window* window = Window::retrieveWindow(frame);
         if (!completedURL.isEmpty() && (!completedURL.startsWith("javascript:", false) || (window && window->isSafeScript(exec)))) {
-            bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
+            bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
             frame->loader()->scheduleLocationChange(completedURL, activeFrame->loader()->outgoingReferrer(), false, userGesture);
         }
         return Window::retrieve(frame);
@@ -1681,15 +1688,15 @@ void ScheduledAction::execute(Window* window)
     if (!scriptProxy)
         return;
 
-    ScriptInterpreter* interpreter = scriptProxy->interpreter();
+    Window* globalObject = scriptProxy->globalObject();
 
-    interpreter->setProcessingTimerCallback(true);
+    scriptProxy->setProcessingTimerCallback(true);
 
     if (JSValue* func = m_func.get()) {
         JSLock lock;
         if (func->isObject() && static_cast<JSObject*>(func)->implementsCall()) {
             ExecState* exec = window->globalExec();
-            ASSERT(window == interpreter->globalObject());
+            ASSERT(window == globalObject);
             
             List args;
             size_t size = m_args.size();
@@ -1697,9 +1704,9 @@ void ScheduledAction::execute(Window* window)
                 args.append(m_args[i]);
             }
 
-            interpreter->startTimeoutCheck();
+            globalObject->startTimeoutCheck();
             static_cast<JSObject*>(func)->call(exec, window, args);
-            interpreter->stopTimeoutCheck();
+            globalObject->stopTimeoutCheck();
             if (exec->hadException()) {
                 JSObject* exception = exec->exception()->toObject(exec);
                 exec->clearException();
@@ -1722,7 +1729,7 @@ void ScheduledAction::execute(Window* window)
     if (Document* doc = frame->document())
         doc->updateRendering();
   
-    interpreter->setProcessingTimerCallback(false);
+    scriptProxy->setProcessingTimerCallback(false);
 }
 
 ////////////////////// timeouts ////////////////////////
@@ -2031,7 +2038,7 @@ void Location::put(ExecState *exec, const Identifier &p, JSValue *v, int attr)
 
   Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame();
   if (!url.url().startsWith("javascript:", false) || sameDomainAccess) {
-    bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
+    bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
     m_frame->loader()->scheduleLocationChange(url.url(), activeFrame->loader()->outgoingReferrer(), false, userGesture);
   }
 }
@@ -2052,7 +2059,7 @@ JSValue* LocationProtoFuncReplace::callAsFunction(ExecState* exec, JSObject* thi
       DeprecatedString str = args[0]->toString(exec);
       const Window* window = Window::retrieveWindow(frame);
       if (!str.startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
-        bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
+        bool userGesture = p->scriptProxy()->processingUserGesture();
         frame->loader()->scheduleLocationChange(p->loader()->completeURL(str).url(), p->loader()->outgoingReferrer(), true, userGesture);
       }
     }
@@ -2074,7 +2081,7 @@ JSValue* LocationProtoFuncReload::callAsFunction(ExecState* exec, JSObject* this
         return jsUndefined();
 
     if (!frame->loader()->url().url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
-      bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
+      bool userGesture = Window::retrieveActive(exec)->impl()->frame()->scriptProxy()->processingUserGesture();
       frame->loader()->scheduleRefresh(userGesture);
     }
     return jsUndefined();
@@ -2096,7 +2103,7 @@ JSValue* LocationProtoFuncAssign::callAsFunction(ExecState* exec, JSObject* this
         const Window *window = Window::retrieveWindow(frame);
         DeprecatedString dstUrl = p->loader()->completeURL(DeprecatedString(args[0]->toString(exec))).url();
         if (!dstUrl.startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
-            bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
+            bool userGesture = p->scriptProxy()->processingUserGesture();
             // We want a new history item if this JS was called via a user gesture
             frame->loader()->scheduleLocationChange(dstUrl, p->loader()->outgoingReferrer(), false, userGesture);
         }
index 013694bcf315155bed1f26fbc5f63ec0c1649e91..3cc7b5b497d4e8c97dfc6cdf9ba211cd71ea4c0d 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "PlatformString.h"
 #include "kjs_binding.h"
+#include <kjs/protect.h>
 #include <wtf/HashMap.h>
 #include <wtf/OwnPtr.h>
 
@@ -105,6 +106,7 @@ namespace KJS {
     
     static bool isSafeScript(const JSGlobalObject *origin, const JSGlobalObject *target);
     virtual bool isSafeScript(const JSGlobalObject* other) const { return Window::isSafeScript(this, other); }
+    bool isSafeScript(ExecState*) const;
 
     Location* location() const;
 
@@ -122,8 +124,8 @@ namespace KJS {
 
     void clear();
 
-    // Set the current "event" object
     void setCurrentEvent(WebCore::Event*);
+    WebCore::Event* currentEvent();
 
     // Set a place to put a dialog return value when the window is cleared.
     void setReturnValueSlot(JSValue** slot);
@@ -141,7 +143,6 @@ namespace KJS {
     
     virtual ExecState* globalExec();
     virtual bool shouldInterruptScript() const;
-    bool isSafeScript(ExecState*) const;
 
     enum {
         // Attributes
index 1a6c5dc8dfe29ec3e2bbd37e26b77c6659b09273..920b31dd7947a5a0651dcc1105469a124d4d569b 100644 (file)
@@ -36,6 +36,7 @@
 #import <JavaScriptCore/runtime_object.h>
 #import <JavaScriptCore/APICast.h>
 #import <JavaScriptCore/JSGlobalObject.h>
+#import <JavaScriptCore/interpreter.h>
 
 using namespace KJS;
 using namespace KJS::Bindings;
@@ -249,24 +250,24 @@ static void _didExecute(WebScriptObject *obj)
 {
     JSLock lock;
     
-    Interpreter *first, *interp = Interpreter::firstInterpreter();
+    JSGlobalObject* head = JSGlobalObject::head();
 
     // This code assumes that we only ever have one running interpreter.  A
     // good assumption for now, as we depend on that elsewhere.  However,
     // in the future we may have the ability to run multiple interpreters,
     // in which case this will have to change.
-    first = interp;
+    JSGlobalObject* o = head;
     do {
-        if (!interp)
+        if (!o)
             return NO;
 
         // If the interpreter has a current exec state, we set the exception.
-        if (ExecState* exec = interp->currentExec()) {
+        if (ExecState* exec = o->currentExec()) {
             throwError(exec, GeneralError, exceptionMessage);
             return YES;
         }
-        interp = interp->nextInterpreter();
-    } while (interp != first);
+        o = o->next();
+    } while (o != head);
     
     return NO;
 }
@@ -309,9 +310,9 @@ static void getListFromNSArray(ExecState *exec, NSArray *array, RootObject* root
     if (![self _isSafeScript])
         return nil;
 
-    [self _rootObject]->interpreter()->startTimeoutCheck();
+    [self _rootObject]->globalObject()->startTimeoutCheck();
     JSValue *result = funcImp->call(exec, [self _imp], argList);
-    [self _rootObject]->interpreter()->stopTimeoutCheck();
+    [self _rootObject]->globalObject()->stopTimeoutCheck();
 
     if (exec->hadException()) {
         LOG_EXCEPTION(exec);
@@ -338,9 +339,9 @@ static void getListFromNSArray(ExecState *exec, NSArray *array, RootObject* root
     JSValue *result;
     JSLock lock;
     
-    [self _rootObject]->interpreter()->startTimeoutCheck();
-    Completion completion = [self _rootObject]->interpreter()->evaluate(UString(), 0, String(script));
-    [self _rootObject]->interpreter()->stopTimeoutCheck();
+    [self _rootObject]->globalObject()->startTimeoutCheck();
+    Completion completion = Interpreter::evaluate([self _rootObject]->globalObject()->globalExec(), UString(), 0, String(script));
+    [self _rootObject]->globalObject()->stopTimeoutCheck();
     ComplType type = completion.complType();
     
     if (type == Normal) {
@@ -495,7 +496,7 @@ static void getListFromNSArray(ExecState *exec, NSArray *array, RootObject* root
 
     JSLock lock;
     
-    if (ExecState* exec = [self _rootObject]->interpreter()->currentExec()) {
+    if (ExecState* exec = [self _rootObject]->globalObject()->currentExec()) {
         throwError(exec, GeneralError, description);
     } else
         throwError([self _rootObject]->globalObject()->globalExec(), GeneralError, description);
index cc4cf8ec519763572b4e0361aa421624d41b419a..aee89eb6a159746fcdb4a2ad7692644390b590f0 100644 (file)
@@ -296,6 +296,8 @@ sub GenerateHeader
             push(@headerContent, "#include \"$parentClassName.h\"\n");
         } else {
             push(@headerContent, "#include \"kjs_binding.h\"\n");
+            push(@headerContent, "#include <kjs/JSGlobalObject.h>\n");
+            push(@headerContent, "#include <kjs/object_object.h>\n");
         }
     }
 
@@ -540,7 +542,7 @@ sub GenerateHeader
         if ($hasParent && $parentClassName ne "KJS::DOMNodeFilter") {
             push(@headerContent, "        : KJS::JSObject(${parentClassName}Prototype::self(exec)) { }\n");
         } else {
-            push(@headerContent, "        : KJS::JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()) { }\n");
+            push(@headerContent, "        : KJS::JSObject(exec->lexicalGlobalObject()->objectPrototype()) { }\n");
         }
     }
 
@@ -1746,7 +1748,7 @@ class ${className}Constructor : public DOMObject {
 public:
     ${className}Constructor(ExecState* exec)
     {
-        setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
+        setPrototype(exec->lexicalGlobalObject()->objectPrototype());
         putDirect(exec->propertyNames().prototype, ${protoClassName}::self(exec), None);
     }
     virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
@@ -1799,7 +1801,7 @@ public: \
     }
 
     ${name}(KJS::ExecState* exec, int len, const KJS::Identifier& name)
-        : KJS::InternalFunctionImp(static_cast<KJS::FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
+        : KJS::InternalFunctionImp(static_cast<KJS::FunctionPrototype*>(exec->lexicalGlobalObject()->functionPrototype()), name)
     {
         put(exec, exec->propertyNames().length, KJS::jsNumber(len), KJS::DontDelete | KJS::ReadOnly | KJS::DontEnum);
     }
index 002938fbb2ca0ba00f73375de076c60e46e9189d..ded5ef495709e359d636c97495a265eea7a9783e 100644 (file)
@@ -54,7 +54,7 @@ size_t JavaScriptStatistics::objectCount()
 size_t JavaScriptStatistics::interpreterCount()
 {
     JSLock lock;
-    return Collector::numInterpreters();
+    return Collector::numGlobalObjects();
 }
 
 size_t JavaScriptStatistics::protectedObjectCount()
index 4a8f6c4ed763df378d66a3eb50518eec890ef81c..ad9277557a02dd821779e847aa57eeaff0805567 100644 (file)
 #import "PlatformString.h"
 #import "WebCoreObjCExtras.h"
 #import "WebScriptObjectPrivate.h"
-#import <JavaScriptCore/debugger.h>
 #import <JavaScriptCore/ExecState.h>
-#import <JavaScriptCore/function.h>
 #import <JavaScriptCore/JSGlobalObject.h>
+#import <JavaScriptCore/debugger.h>
+#import <JavaScriptCore/function.h>
+#import <JavaScriptCore/interpreter.h>
 
 using namespace KJS;
 using namespace WebCore;
@@ -82,10 +83,10 @@ class WebCoreScriptDebuggerImp : public KJS::Debugger {
 
   public:
     // constructor
-    WebCoreScriptDebuggerImp(WebCoreScriptDebugger *objc, Interpreter *interp) : _objc(objc) {
+    WebCoreScriptDebuggerImp(WebCoreScriptDebugger *objc, JSGlobalObject* globalObject) : _objc(objc) {
         _nested = true;
-        _current = [_objc _enterFrame:interp->globalObject()->globalExec()];
-        attach(interp);
+        _current = [_objc _enterFrame:globalObject->globalExec()];
+        attach(globalObject);
         [[_objc delegate] enteredFrame:_current sourceId:-1 line:-1];
         _nested = false;
     }
@@ -143,7 +144,7 @@ class WebCoreScriptDebuggerImp : public KJS::Debugger {
 // This is the main (behind-the-scenes) debugger class in WebCore.
 //
 // The WebCoreScriptDebugger has two faces, one for Objective-C (this class), and another (WebCoreScriptDebuggerImp)
-// for C++.  The ObjC side creates the C++ side, which does the real work of attaching to the interpreter and
+// for C++.  The ObjC side creates the C++ side, which does the real work of attaching to the global object and
 // forwarding the KJS debugger callbacks to the delegate.
 
 @implementation WebCoreScriptDebugger
@@ -160,7 +161,7 @@ class WebCoreScriptDebuggerImp : public KJS::Debugger {
     if ((self = [super init])) {
         _delegate   = delegate;
         _globalObj = [_delegate globalObject];
-        _debugger  = new WebCoreScriptDebuggerImp(self, [_globalObj _rootObject]->interpreter());
+        _debugger  = new WebCoreScriptDebuggerImp(self, [_globalObj _rootObject]->globalObject());
     }
     return self;
 }
@@ -332,25 +333,27 @@ class WebCoreScriptDebuggerImp : public KJS::Debugger {
 // Calling this method on the global frame is not quite the same as calling the WebScriptObject
 // method of the same name, due to the treatment of exceptions.
 
+// FIXME: If "script" contains var declarations, the machinery to handle local variables
+// efficiently in JavaScriptCore will not work properly. This could lead to crashes or
+// incorrect variable values. So this is not appropriate for evaluating arbitrary script.
 - (id)evaluateWebScript:(NSString *)script
 {
     JSLock lock;
 
     UString code = String(script);
 
-    ExecState   *state   = _state;
-    Interpreter *interp  = state->dynamicInterpreter();
-    JSObject   *globObj = interp->globalObject();
+    ExecState* state = _state;
+    JSGlobalObject* globalObject = state->dynamicGlobalObject();
 
     // find "eval"
     JSObject *eval = NULL;
     if (state->currentBody()) {  // "eval" won't work without context (i.e. at global scope)
-        JSValue *v = globObj->get(state, "eval");
+        JSValue *v = globalObject->get(state, "eval");
         if (v->isObject() && static_cast<JSObject *>(v)->implementsCall())
             eval = static_cast<JSObject *>(v);
         else
             // no "eval" - fallback operates on global exec state
-            state = interp->globalObject()->globalExec();
+            state = globalObject->globalExec();
     }
 
     JSValue *savedException = state->exception();
@@ -364,7 +367,7 @@ class WebCoreScriptDebuggerImp : public KJS::Debugger {
         result = eval->call(state, NULL, args);
     } else
         // no "eval", or no context (i.e. global scope) - use global fallback
-        result = interp->evaluate(UString(), 0, code.data(), code.size(), globObj).value();
+        result = Interpreter::evaluate(state, UString(), 0, code.data(), code.size(), globalObject).value();
 
     if (state->hadException())
         result = state->exception();    // (may be redundant depending on which eval path was used)
index def742f1757f7f06af1bfb0e567546e98e747c1a..dd01f1646320de07d8a20f2e48bac1a064d63064 100644 (file)
@@ -81,7 +81,7 @@ CachedPage::CachedPage(Page* page)
     , m_URL(page->mainFrame()->loader()->url())
     , m_windowProperties(new SavedProperties)
     , m_locationProperties(new SavedProperties)
-    , m_interpreterBuiltins(new SavedBuiltins)
+    , m_windowBuiltins(new SavedBuiltins)
 {
 #ifndef NDEBUG
     ++CachedPageCounter::count;
@@ -98,7 +98,7 @@ CachedPage::CachedPage(Page* page)
     JSLock lock;
 
     if (proxy && window) {
-        proxy->interpreter()->saveBuiltins(*m_interpreterBuiltins.get());
+        proxy->globalObject()->saveBuiltins(*m_windowBuiltins.get());
         window->saveProperties(*m_windowProperties.get());
         window->location()->saveProperties(*m_locationProperties.get());
         m_pausedTimeouts.set(window->pauseTimeouts());
@@ -132,7 +132,7 @@ void CachedPage::restore(Page* page)
     JSLock lock;
 
     if (proxy && window) {
-        proxy->interpreter()->restoreBuiltins(*m_interpreterBuiltins.get());
+        proxy->globalObject()->restoreBuiltins(*m_windowBuiltins.get());
         window->restoreProperties(*m_windowProperties.get());
         window->location()->restoreProperties(*m_locationProperties.get());
         window->resumeTimeouts(m_pausedTimeouts.get());
@@ -186,7 +186,7 @@ void CachedPage::clear()
 
     m_windowProperties.clear();
     m_locationProperties.clear();
-    m_interpreterBuiltins.clear();
+    m_windowBuiltins.clear();
     m_pausedTimeouts.clear();
 
     gcController().garbageCollectSoon();
index c02f48b655c37c4fce9f01525924b453ec6f0b9b..14db22d001a866a0ee70a2fd01dc315d8d063af8 100644 (file)
@@ -86,7 +86,7 @@ private:
     KURL m_URL;
     OwnPtr<KJS::SavedProperties> m_windowProperties;
     OwnPtr<KJS::SavedProperties> m_locationProperties;
-    OwnPtr<KJS::SavedBuiltins> m_interpreterBuiltins;
+    OwnPtr<KJS::SavedBuiltins> m_windowBuiltins;
     OwnPtr<KJS::PausedTimeouts> m_pausedTimeouts;
         
 #if PLATFORM(MAC)
index 5cef859030b144b7068fa14d1cf53bd3a896d48b..0f8a0e831220db50544f67f3f083289b7abeab7d 100644 (file)
@@ -1722,7 +1722,7 @@ bool FrameLoader::userGestureHint()
         rootFrame = rootFrame->tree()->parent();
 
     if (rootFrame->scriptProxy())
-        return rootFrame->scriptProxy()->interpreter()->wasRunByUserGesture();
+        return rootFrame->scriptProxy()->processingUserGesture();
 
     return true; // If JavaScript is disabled, a user gesture must have initiated the navigation
 }
@@ -4535,7 +4535,7 @@ String FrameLoader::referrer() const
 void FrameLoader::dispatchWindowObjectAvailable()
 {
     Settings* settings = m_frame->settings();
-    if (!settings || !settings->isJavaScriptEnabled() || !m_frame->scriptProxy()->haveInterpreter())
+    if (!settings || !settings->isJavaScriptEnabled() || !m_frame->scriptProxy()->haveGlobalObject())
         return;
 
     m_client->windowObjectCleared();
index 47eb18fd1c9c4d504f3234e187a2eab70e14bb30..48b0782e281261e36b62f10bde47140b0128a824 100644 (file)
@@ -194,7 +194,7 @@ Frame::~Frame()
     --FrameCounter::count;
 #endif
 
-    if (d->m_jscript && d->m_jscript->haveInterpreter())
+    if (d->m_jscript && d->m_jscript->haveGlobalObject())
         static_cast<KJS::Window*>(d->m_jscript->globalObject())->disconnectFrame();
 
     disconnectOwnerElement();
@@ -1817,7 +1817,7 @@ void Frame::pageDestroyed()
         d->m_page->focusController()->setFocusedFrame(0);
 
     // This will stop any JS timers
-    if (d->m_jscript && d->m_jscript->haveInterpreter())
+    if (d->m_jscript && d->m_jscript->haveGlobalObject())
         if (KJS::Window* w = KJS::Window::retrieveWindow(this))
             w->disconnectFrame();
 
index 127baceeff5a3d24549f8ffef3e8027f5d0b3776..3e38ff02fad8ea7d3f62059b90db0a3988124e94 100644 (file)
@@ -1,3 +1,13 @@
+2007-12-04  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Third step in refactoring JSGlobalObject: Moved data members and data
+        member access from Interpreter to JSGlobalObject.
+        
+        * WebView/WebFrame.mm:
+        (-[WebFrame _attachScriptDebugger]):
+
 2007-12-04  Kevin McCullough  <kmccullough@apple.com>
 
         Reviewed by Darin.
index ac2fb6902aee4ba80d03926f2ccea52bb0de5b81..71ac0ebabc6820db310f5844140a0e84e9124a96 100644 (file)
@@ -366,7 +366,7 @@ WebView *getWebView(WebFrame *webFrame)
 
 - (void)_attachScriptDebugger
 {
-    if (!_private->scriptDebugger && core(self)->scriptProxy()->haveInterpreter())
+    if (!_private->scriptDebugger && core(self)->scriptProxy()->haveGlobalObject())
         _private->scriptDebugger = [[WebScriptDebugger alloc] initWithWebFrame:self];
 }
 
index 79dd873aa70e9ed3cdd7db14e49a9b5c9d8c781b..9f266a86156bdfee5f018f0a988ad4a7e5d128b7 100644 (file)
@@ -1,3 +1,17 @@
+2007-12-04  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Third step in refactoring JSGlobalObject: Moved data members and data
+        member access from Interpreter to JSGlobalObject.
+        
+        * WebFrame.cpp:
+        (WebFrame::globalContext):
+        (WebFrame::attachScriptDebugger):
+        (WebFrame::windowObjectCleared):
+        * WebScriptDebugger.cpp:
+        (WebScriptDebugger::WebScriptDebugger):
+
 2007-12-05  Steve Falkenburg  <sfalken@apple.com>
 
         <rdar://problem/5625327> Crash toggling check grammar w/ spelling when no spell checker exists.
index 022d48fde0cedb7c533d435a0cc0c30f2e0b3225..a89cc6bb6702469c6f7497ee9f748e394b712cde 100644 (file)
@@ -767,7 +767,7 @@ KURL WebFrame::url() const
 
 void WebFrame::attachScriptDebugger()
 {
-    if (!m_scriptDebugger && core(this)->scriptProxy()->haveInterpreter())
+    if (!m_scriptDebugger && core(this)->scriptProxy()->haveGlobalObject())
         m_scriptDebugger.set(new WebScriptDebugger(this));
 }
 
index 2e704afb9525eb36e6ab7000c0e0be98fdbae79d..54309f6c505ed3bb3489b98ea25ef59ec65d05de 100644 (file)
@@ -56,13 +56,13 @@ WebScriptDebugger::WebScriptDebugger(WebFrame* frame)
     if (!proxy)
         return;
 
-    Interpreter* interp(proxy->interpreter());
-    attach(interp);
+    JSGlobalObject* globalObject = proxy->globalObject();
+    attach(globalObject);
 
     m_frame->webView(&m_webView);
     ASSERT(m_webView);
 
-    callEvent(proxy->globalObject()->globalExec(), -1, -1, 0, List());
+    callEvent(globalObject->globalExec(), -1, -1, 0, List());
     m_callingServer = false;
 }