Changeset 28309 in webkit


Ignore:
Timestamp:
Dec 1, 2007 3:56:56 PM (16 years ago)
Author:
ggaren@apple.com
Message:

JavaScriptCore:

Reviewed by Beth Dakin.


Reversed the ownership relationship between Interpreter and JSGlobalObject.
Now, the JSGlobalObject owns the Interpreter, and top-level objects
that need the two to persist just protect the JSGlobalObject from GC.


Global object bootstrapping looks a little odd right now, but it will
make much more sense soon, after further rounds of refactoring.

  • bindings/runtime_root.h: Made this class inherit from RefCounted, to avoid code duplication.
  • kjs/collector.cpp: (KJS::Collector::collect): No need to give special GC treatment to Interpreters, since we mark their global objects, which mark them.
  • kjs/interpreter.cpp: (KJS::Interpreter::mark): No need to mark our global object, since it marks us.
  • kjs/interpreter.h: Don't inherit from RefCounted -- JSGlobalObject owns us directly.
  • kjs/testkjs.cpp: Modified to follow the new rules. (createGlobalObject): (runWithScripts):

JavaScriptGlue:

Reviewed by Beth Dakin.


Modified to follow new JSGlobalObject/Interpreter ownership rules
in JavaScriptCore.

  • JSRun.cpp: (JSRun::JSRun): (JSRun::GetInterpreter): (JSRun::Evaluate): (JSRun::CheckSyntax):
  • JSRun.h:
  • JSValueWrapper.cpp: (unprotectGlobalObject): (initializeGlobalObjectKey): (getThreadGlobalExecState):

WebCore:

Reviewed by Beth Dakin.


Modified WebCore to follow the new JSGlobalObject/Interpreter ownership
rules in JavaScriptCore.

  • bindings/js/kjs_binding.cpp:
  • bindings/js/kjs_binding.h: Removed stale, unused interpreterForGlobalObject().
  • bindings/js/kjs_proxy.cpp: Changed to store a global object, rather than an interpreter. (WebCore::KJSProxy::finishedWithEvent): Need to NULL check m_globalObject here because we no longer unnecessarily instantiate it.
  • bindings/js/kjs_window.cpp: (KJS::ScheduledAction::execute):
  • bindings/js/kjs_window.h: Removed redundant and less efficient interpreter() function -- global objects have direct access to their interpreters now.

Changed these functions to pass around JSGlobalObjects instead of
Interpreters:

  • page/Frame.cpp: (WebCore::Frame::bindingRootObject): (WebCore::Frame::createRootObject):
  • page/Frame.h:
  • page/mac/WebCoreFrameBridge.mm: (createRootObject):
Location:
trunk
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r27885 r28309  
    6363    JSLock lock;
    6464    ExecState* exec = toJS(ctx);
    65     exec->dynamicInterpreter()->ref();
     65    gcProtect(exec->dynamicInterpreter()->globalObject());
    6666    return ctx;
    6767}
     
    7171    JSLock lock;
    7272    ExecState* exec = toJS(ctx);
    73     exec->dynamicInterpreter()->deref();
     73    gcUnprotect(exec->dynamicInterpreter()->globalObject());
    7474}
    7575
  • trunk/JavaScriptCore/ChangeLog

    r28272 r28309  
     12007-11-30  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Beth Dakin.
     4       
     5        Reversed the ownership relationship between Interpreter and JSGlobalObject.
     6        Now, the JSGlobalObject owns the Interpreter, and top-level objects
     7        that need the two to persist just protect the JSGlobalObject from GC.
     8       
     9        Global object bootstrapping looks a little odd right now, but it will
     10        make much more sense soon, after further rounds of refactoring.
     11
     12        * bindings/runtime_root.h: Made this class inherit from RefCounted,
     13        to avoid code duplication.
     14
     15        * kjs/collector.cpp:
     16        (KJS::Collector::collect): No need to give special GC treatment to
     17        Interpreters, since we mark their global objects, which mark them.
     18
     19        * kjs/interpreter.cpp:
     20        (KJS::Interpreter::mark): No need to mark our global object, since it
     21        marks us.
     22        * kjs/interpreter.h: Don't inherit from RefCounted -- JSGlobalObject
     23        owns us directly.
     24
     25        * kjs/testkjs.cpp: Modified to follow the new rules.
     26        (createGlobalObject):
     27        (runWithScripts):
     28
    1292007-11-30  Brent Fulgham  <bfulgham@gmail.com>
    230
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r28110 r28309  
    187187__ZN3KJS8Bindings10RootObject17_createRootObjectE
    188188__ZN3KJS8Bindings10RootObject19setCreateRootObjectEPFN3WTF10PassRefPtrIS1_EEPvE
    189 __ZN3KJS8Bindings10RootObject6createEPKvN3WTF10PassRefPtrINS_11InterpreterEEE
     189__ZN3KJS8Bindings10RootObject6createEPKvPNS_14JSGlobalObjectE
    190190__ZN3KJS8Bindings10RootObject9gcProtectEPNS_8JSObjectE
    191191__ZN3KJS8Bindings10RootObjectD1Ev
  • trunk/JavaScriptCore/bindings/jni/jni_jsobject.h

    r27373 r28309  
    3030
    3131#include <JavaVM/jni.h>
     32#include <wtf/RefPtr.h>
    3233
    3334#define jlong_to_ptr(a) ((void*)(uintptr_t)(a))
  • trunk/JavaScriptCore/bindings/runtime_root.cpp

    r23538 r28309  
    2626#include "runtime_root.h"
    2727
     28#include "JSGlobalObject.h"
    2829#include "object.h"
    2930#include "runtime.h"
    3031#include "runtime_object.h"
    31 
    3232#include <wtf/HashCountedSet.h>
    3333#include <wtf/HashSet.h>
     
    196196#endif
    197197
    198 PassRefPtr<RootObject> RootObject::create(const void* nativeHandle, PassRefPtr<Interpreter> interpreter)
    199 {
    200     return new RootObject(nativeHandle, interpreter);
    201 }
    202 
    203 RootObject::RootObject(const void* nativeHandle, PassRefPtr<Interpreter> interpreter)
    204     : m_refCount(0)
    205     , m_isValid(true)
     198PassRefPtr<RootObject> RootObject::create(const void* nativeHandle, JSGlobalObject* globalObject)
     199{
     200    return new RootObject(nativeHandle, globalObject);
     201}
     202
     203RootObject::RootObject(const void* nativeHandle, JSGlobalObject* globalObject)
     204    : m_isValid(true)
    206205    , m_nativeHandle(nativeHandle)
    207     , m_interpreter(interpreter)
    208 {
    209     ASSERT(m_interpreter);
     206    , m_globalObject(globalObject)
     207{
     208    ASSERT(globalObject);
    210209    rootObjectSet()->add(this);
    211210}
     
    233232
    234233    m_nativeHandle = 0;
    235     m_interpreter = 0;
     234    m_globalObject = 0;
    236235
    237236    ProtectCountSet::iterator end = m_protectCountSet.end();
     
    285284{
    286285    ASSERT(m_isValid);
    287     return m_interpreter.get();
     286    return m_globalObject->interpreter();
    288287}
    289288
  • trunk/JavaScriptCore/bindings/runtime_root.h

    r23538 r28309  
    2727#define RUNTIME_ROOT_H_
    2828
    29 #include "interpreter.h"
    3029#if PLATFORM(MAC)
    3130#include "jni_jsobject.h"
     
    3534#include <wtf/HashSet.h>
    3635#include <wtf/Noncopyable.h>
     36#include <wtf/RefCounted.h>
    3737
    3838namespace KJS {
    3939
     40class Interpreter;
     41class JSGlobalObject;
    4042class RuntimeObjectImp;
    41    
     43
    4244namespace Bindings {
    4345
     
    5052extern RootObject* findRootObject(Interpreter*);
    5153
    52 class RootObject : Noncopyable
    53 {
    54 friend class JavaJSObject;
     54class RootObject : public RefCounted<RootObject> {
     55    friend class JavaJSObject;
     56
    5557public:
    56     static PassRefPtr<RootObject> create(const void* nativeHandle, PassRefPtr<Interpreter> interpreter);
    57 
    58     void ref() { m_refCount++; }
    59     void deref()
    60     {
    61         if (--m_refCount == 0)
    62             delete this;
    63     }
     58    ~RootObject();
     59   
     60    static PassRefPtr<RootObject> create(const void* nativeHandle, JSGlobalObject*);
    6461
    6562    bool isValid() { return m_isValid; }
     
    8986    void removeRuntimeObject(RuntimeObjectImp*);
    9087private:
    91     RootObject(const void* nativeHandle, PassRefPtr<Interpreter> interpreter);
    92     ~RootObject();
     88    RootObject(const void* nativeHandle, JSGlobalObject*);
    9389   
    94     unsigned m_refCount;
    9590    bool m_isValid;
    9691   
    9792    const void* m_nativeHandle;
    98     RefPtr<Interpreter> m_interpreter;
     93    ProtectedPtr<JSGlobalObject> m_globalObject;
    9994    ProtectCountSet m_protectCountSet;
    10095
  • trunk/JavaScriptCore/kjs/JSGlobalObject.h

    r27022 r28309  
    22/*
    33 *  Copyright (C) 2007 Eric Seidel <eric@webkit.org>
     4 *  Copyright (C) 2007 Apple Ince. All rights reserved.
    45 *
    56 *  This library is free software; you can redistribute it and/or
     
    2627
    2728namespace KJS {
     29
    2830    class Interpreter;
     31
    2932    class JSGlobalObject : public JSObject {
    3033    public:
    3134        JSGlobalObject() { }
    3235        JSGlobalObject(JSValue* proto) : JSObject(proto) { }
    33        
     36
    3437        virtual bool isGlobalObject() const { return true; }
    35        
    36         Interpreter* interpreter() const { return m_interpreter; }
    37         void setInterpreter(Interpreter* i) { m_interpreter = i; }
     38
     39        virtual void mark()
     40        {
     41            JSObject::mark();
     42            m_interpreter->mark();
     43        }
     44
     45        Interpreter* interpreter() const { return m_interpreter.get(); }
     46        void setInterpreter(std::auto_ptr<Interpreter> i) { m_interpreter = i; }
     47
    3848    private:
    39         Interpreter* m_interpreter;
     49        std::auto_ptr<Interpreter> m_interpreter;
    4050    };
     51
    4152} // namespace KJS
    4253
  • trunk/JavaScriptCore/kjs/collector.cpp

    r28223 r28309  
    941941#endif
    942942
    943   if (Interpreter::s_hook) {
    944     Interpreter* scr = Interpreter::s_hook;
    945     do {
    946       scr->mark();
    947       scr = scr->next;
    948     } while (scr != Interpreter::s_hook);
    949   }
    950 
    951943  markStackObjectsConservatively();
    952944  markProtectedObjects();
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r28110 r28309  
    257257{
    258258    ASSERT(m_globalObject);
    259     m_globalObject->setInterpreter(this);
     259    m_globalObject->setInterpreter(std::auto_ptr<Interpreter>(this));
    260260
    261261    // Set global object prototype
     
    553553        m_globalExec.exception()->mark();
    554554
    555     if (m_globalObject && !m_globalObject->marked())
    556         m_globalObject->mark();
    557 
    558555    if (m_Object && !m_Object->marked())
    559556        m_Object->mark();
  • trunk/JavaScriptCore/kjs/interpreter.h

    r28110 r28309  
    7777   * " Object" and "Number".
    7878   */
    79   class Interpreter : public RefCounted<Interpreter> {
     79  class Interpreter {
    8080    friend class Collector;
    8181  public:
  • trunk/JavaScriptCore/kjs/testkjs.cpp

    r27885 r28309  
    222222}
    223223
    224 static PassRefPtr<Interpreter> setupInterpreter()
    225 {
    226   GlobalImp* global = new GlobalImp();
    227   RefPtr<Interpreter> interp = new Interpreter();
    228   interp->setGlobalObject(global);
     224static GlobalImp* createGlobalObject()
     225{
     226  GlobalImp* global = new GlobalImp;
     227  Interpreter* interp = new Interpreter;
     228  interp->setGlobalObject(global); // global now owns interp.
     229
    229230  // add debug() function
    230231  global->put(interp->globalExec(), "debug", new TestFunctionImp(TestFunctionImp::Debug, 1));
     
    241242
    242243  Interpreter::setShouldPrintExceptions(true);
    243   return interp.release();
     244  return global;
    244245}
    245246
     
    261262static bool runWithScripts(const Vector<UString>& fileNames, bool prettyPrint)
    262263{
    263   RefPtr<Interpreter> interp = setupInterpreter();
     264  GlobalImp* globalObject = createGlobalObject();
    264265  Vector<char> script;
    265266 
     
    275276      prettyPrintScript(fileName, script);
    276277    else {
    277       Completion completion = interp->evaluate(fileName, 0, script.data());
     278      Completion completion = globalObject->interpreter()->evaluate(fileName, 0, script.data());
    278279      success = success && completion.complType() != Throw;
    279280    }
  • trunk/JavaScriptGlue/ChangeLog

    r28137 r28309  
     12007-11-30  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Beth Dakin.
     4       
     5        Modified to follow new JSGlobalObject/Interpreter ownership rules
     6        in JavaScriptCore.
     7
     8        * JSRun.cpp:
     9        (JSRun::JSRun):
     10        (JSRun::GetInterpreter):
     11        (JSRun::Evaluate):
     12        (JSRun::CheckSyntax):
     13        * JSRun.h:
     14        * JSValueWrapper.cpp:
     15        (unprotectGlobalObject):
     16        (initializeGlobalObjectKey):
     17        (getThreadGlobalExecState):
     18
    1192007-11-29  Mark Rowe  <mrowe@apple.com>
    220
  • trunk/JavaScriptGlue/JSRun.cpp

    r27023 r28309  
    3434        fSource(CFStringToUString(source)),
    3535        fGlobalObject(new JSGlobalObject()),
    36         fInterpreter(new JSInterpreter(fGlobalObject, inFlags)),
    3736        fFlags(inFlags)
    3837{
     38    Interpreter* interpreter = new JSInterpreter(fGlobalObject, inFlags);
     39    interpreter->setGlobalObject(fGlobalObject); // fGlobalObject now owns interpreter
    3940}
    4041
     
    6061JSInterpreter* JSRun::GetInterpreter()
    6162{
    62     return fInterpreter.get();
     63    return static_cast<JSInterpreter*>(fGlobalObject->interpreter());
    6364}
    6465
    6566Completion JSRun::Evaluate()
    6667{
    67     return fInterpreter->evaluate(UString(), 0, fSource.data(), fSource.size());
     68    return fGlobalObject->interpreter()->evaluate(UString(), 0, fSource.data(), fSource.size());
    6869}
    6970
    7071bool JSRun::CheckSyntax()
    7172{
    72     return fInterpreter->checkSyntax(UString(), 0, fSource.data(), fSource.size()).complType() != Throw;
     73    return fGlobalObject->interpreter()->checkSyntax(UString(), 0, fSource.data(), fSource.size()).complType() != Throw;
    7374}
  • trunk/JavaScriptGlue/JSRun.h

    r27951 r28309  
    6161        UString fSource;
    6262        ProtectedPtr<JSGlobalObject> fGlobalObject;
    63         RefPtr<JSInterpreter> fInterpreter;
    6463        JSFlags fFlags;
    6564};
  • trunk/JavaScriptGlue/JSValueWrapper.cpp

    r28137 r28309  
    2929#include "config.h"
    3030#include "JSValueWrapper.h"
     31#include "JSRun.h"
    3132#include <JavaScriptCore/PropertyNameArray.h>
    3233#include <pthread.h>
     
    6162 */     
    6263
    63 pthread_key_t interpreterKey;
    64 pthread_once_t interpreterKeyOnce = PTHREAD_ONCE_INIT;
    65 
    66 static void derefInterpreter(void* data)
    67 {
    68     static_cast<Interpreter*>(data)->deref();
    69 }
    70 
    71 static void initializeInterpreterKey()
    72 {
    73     pthread_key_create(&interpreterKey, derefInterpreter);
     64pthread_key_t globalObjectKey;
     65pthread_once_t globalObjectKeyOnce = PTHREAD_ONCE_INIT;
     66
     67static void unprotectGlobalObject(void* data)
     68{
     69    gcUnprotect(static_cast<JSGlobalObject*>(data));
     70}
     71
     72static void initializeGlobalObjectKey()
     73{
     74    pthread_key_create(&globalObjectKey, unprotectGlobalObject);
    7475}
    7576
    7677static ExecState* getThreadGlobalExecState()
    7778{
    78     pthread_once(&interpreterKeyOnce, initializeInterpreterKey);
    79     Interpreter* interpreter = static_cast<Interpreter*>(pthread_getspecific(interpreterKey));
    80     if (!interpreter) {
    81         interpreter = new Interpreter();
    82         interpreter->setGlobalObject(new JSGlobalObject());
    83         interpreter->ref();
    84         pthread_setspecific(interpreterKey, interpreter);
    85     }
     79    pthread_once(&globalObjectKeyOnce, initializeGlobalObjectKey);
     80    JSGlobalObject* globalObject = static_cast<JSGlobalObject*>(pthread_getspecific(globalObjectKey));
     81    if (!globalObject) {
     82        globalObject = new JSGlobalObject;
     83        Interpreter* interpreter = new JSInterpreter;
     84        interpreter->setGlobalObject(globalObject); // globalObject now owns interpreter
     85       
     86        gcProtect(globalObject);
     87        pthread_setspecific(globalObjectKey, globalObject);
     88    }
     89   
     90    ExecState* exec = globalObject->interpreter()->globalExec();
    8691
    8792    // Discard exceptions -- otherwise an exception would forestall JS
    8893    // evaluation throughout the thread
    89     interpreter->globalExec()->clearException();
    90 
    91     return interpreter->globalExec();
     94    exec->clearException();
     95    return exec;
    9296}
    9397
  • trunk/WebCore/ChangeLog

    r28304 r28309  
     12007-11-30  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Beth Dakin.
     4       
     5        Modified WebCore to follow the new JSGlobalObject/Interpreter ownership
     6        rules in JavaScriptCore.
     7
     8        * bindings/js/kjs_binding.cpp:
     9        * bindings/js/kjs_binding.h: Removed stale, unused
     10        interpreterForGlobalObject().
     11
     12        * bindings/js/kjs_proxy.cpp: Changed to store a global object, rather
     13        than an interpreter.
     14        (WebCore::KJSProxy::finishedWithEvent): Need to NULL check
     15        m_globalObject here because we no longer unnecessarily instantiate it.
     16
     17        * bindings/js/kjs_window.cpp:
     18        (KJS::ScheduledAction::execute):
     19        * bindings/js/kjs_window.h: Removed redundant and less efficient
     20        interpreter() function -- global objects have direct access to their
     21        interpreters now.
     22
     23        Changed these functions to pass around JSGlobalObjects instead of
     24        Interpreters:
     25
     26        * page/Frame.cpp:
     27        (WebCore::Frame::bindingRootObject):
     28        (WebCore::Frame::createRootObject):
     29        * page/Frame.h:
     30        * page/mac/WebCoreFrameBridge.mm:
     31        (createRootObject):
     32
    1332007-12-01  Darin Adler  <darin@apple.com>
    234
  • trunk/WebCore/bindings/js/kjs_binding.cpp

    r28110 r28309  
    288288}
    289289
    290 Interpreter* ScriptInterpreter::interpreterForGlobalObject(const JSValue* imp)
    291 {
    292     const Window* win = static_cast<const Window*>(imp);
    293     return win->interpreter();
    294 }
    295 
    296290bool ScriptInterpreter::shouldInterruptScript() const
    297291{
  • trunk/WebCore/bindings/js/kjs_binding.h

    r28110 r28309  
    105105
    106106        virtual bool isGlobalObject(JSValue*);
    107         virtual Interpreter* interpreterForGlobalObject(const JSValue*);
    108107        virtual bool isSafeScript(const Interpreter* target);
    109108
  • trunk/WebCore/bindings/js/kjs_proxy.cpp

    r27108 r28309  
    4343
    4444KJSProxy::KJSProxy(Frame* frame)
     45    : m_frame(frame)
     46    , m_handlerLineno(0)
    4547{
    46     m_frame = frame;
    47     m_handlerLineno = 0;
    4848}
    4949
     
    5252    // Check for <rdar://problem/4876466>. In theory, no JS should be executing
    5353    // in our interpreter.
    54     ASSERT(!m_script || !m_script->currentExec());
     54    ASSERT(!m_globalObject || !m_globalObject->interpreter()->currentExec());
    5555   
    56     if (m_script) {
    57         m_script = 0;
     56    if (m_globalObject) {
     57        m_globalObject = 0;
    5858   
    5959        // It's likely that destroying the interpreter has created a lot of garbage.
     
    7474    bool inlineCode = filename.isNull();
    7575
    76     m_script->setInlineCode(inlineCode);
     76    ScriptInterpreter* interpreter = static_cast<ScriptInterpreter*>(m_globalObject->interpreter());
     77    ExecState* exec = interpreter->globalExec();
     78
     79    interpreter->setInlineCode(inlineCode);
    7780
    7881    JSLock lock;
     
    8487    JSValue* thisNode = KJS::Window::retrieve(m_frame);
    8588 
    86     m_script->startTimeoutCheck();
    87     Completion comp = m_script->evaluate(filename, baseLine, reinterpret_cast<const KJS::UChar*>(str.characters()), str.length(), thisNode);
    88     m_script->stopTimeoutCheck();
     89    interpreter->startTimeoutCheck();
     90    Completion comp = interpreter->evaluate(filename, baseLine, reinterpret_cast<const KJS::UChar*>(str.characters()), str.length(), thisNode);
     91    interpreter->stopTimeoutCheck();
    8992 
    9093    if (comp.complType() == Normal || comp.complType() == ReturnValue)
     
    9295
    9396    if (comp.complType() == Throw) {
    94         UString errorMessage = comp.value()->toString(m_script->globalExec());
    95         int lineNumber = comp.value()->toObject(m_script->globalExec())->get(m_script->globalExec(), "line")->toInt32(m_script->globalExec());
    96         UString sourceURL = comp.value()->toObject(m_script->globalExec())->get(m_script->globalExec(), "sourceURL")->toString(m_script->globalExec());
     97        UString errorMessage = comp.value()->toString(exec);
     98        int lineNumber = comp.value()->toObject(exec)->get(exec, "line")->toInt32(exec);
     99        UString sourceURL = comp.value()->toObject(exec)->get(exec, "sourceURL")->toString(exec);
    97100        if (Page* page = m_frame->page())
    98101            page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, sourceURL);
     
    106109  // We have to keep it, so that the KJS::Window object for the frame remains the same.
    107110  // (we used to delete and re-create it, previously)
    108   if (m_script) {
    109     KJS::Window *win = KJS::Window::retrieveWindow(m_frame);
    110     if (win)
    111         win->clear();
    112   }
     111  if (m_globalObject)
     112    m_globalObject->clear();
    113113}
    114114
     
    135135  // e.g. an image load or mouse move. Once the event has been dispatched, it is forgotten
    136136  // by the DOM implementation and so does not need to be cached still by the interpreter
    137   m_script->forgetDOMObject(event);
     137  if (!m_globalObject)
     138    return;
     139  static_cast<ScriptInterpreter*>(m_globalObject->interpreter())->forgetDOMObject(event);
    138140}
    139141
     
    141143{
    142144  initScriptIfNeeded();
    143   ASSERT(m_script);
    144   return m_script.get();
     145  ASSERT(m_globalObject);
     146  return static_cast<ScriptInterpreter*>(m_globalObject->interpreter());
    145147}
    146148
    147149void KJSProxy::initScriptIfNeeded()
    148150{
    149   if (m_script)
     151  if (m_globalObject)
    150152    return;
    151153
    152154  // Build the global object - which is a Window instance
    153155  JSLock lock;
    154   JSDOMWindow* globalObject = new JSDOMWindow(m_frame->domWindow());
    155 
    156   // Create a KJS interpreter for this frame
    157   m_script = new ScriptInterpreter(globalObject, m_frame);
     156 
     157  m_globalObject = new JSDOMWindow(m_frame->domWindow());
     158  ScriptInterpreter* interpreter = new ScriptInterpreter(m_globalObject, m_frame); // m_globalObject now owns interpreter
    158159
    159160  String userAgent = m_frame->loader()->userAgent(m_frame->document() ? m_frame->document()->URL() : KURL());
    160161  if (userAgent.find("Microsoft") >= 0 || userAgent.find("MSIE") >= 0)
    161     m_script->setCompatMode(Interpreter::IECompat);
     162    interpreter->setCompatMode(Interpreter::IECompat);
    162163  else
    163164    // If we find "Mozilla" but not "(compatible, ...)" we are a real Netscape
    164165    if (userAgent.find("Mozilla") >= 0 && userAgent.find("compatible") == -1)
    165       m_script->setCompatMode(Interpreter::NetscapeCompat);
     166      interpreter->setCompatMode(Interpreter::NetscapeCompat);
    166167
    167168  m_frame->loader()->dispatchWindowObjectAvailable();
     
    170171void KJSProxy::clearDocumentWrapper()
    171172{
    172     if (!m_script)
     173    if (!m_globalObject)
    173174        return;
    174175
    175176    JSLock lock;
    176     m_script->globalObject()->removeDirect("document");
     177    m_globalObject->removeDirect("document");
    177178}
    178179
    179 }
     180} // namespace WebCore
  • trunk/WebCore/bindings/js/kjs_proxy.h

    r26074 r28309  
    2222#define kjs_proxy_h
    2323
     24#include <kjs/protect.h>
    2425#include <wtf/RefPtr.h>
    2526
     
    3435class EventListener;
    3536class Frame;
     37class JSDOMWindow;
    3638class Node;
    3739class String;
     40
     41// FIXME: Rename this class to JSController and merge functions from
     42// ScriptInterpreter into it.
    3843
    3944class KJSProxy {
     
    5459    void initScriptIfNeeded();
    5560
    56     bool haveInterpreter() const { return m_script; }
     61    bool haveInterpreter() const { return m_globalObject; }
    5762   
    5863    void clearDocumentWrapper();
    5964
    6065private:
    61     RefPtr<KJS::ScriptInterpreter> m_script;
     66    KJS::ProtectedPtr<JSDOMWindow> m_globalObject;
    6267    Frame* m_frame;
    6368    int m_handlerLineno;
  • trunk/WebCore/bindings/js/kjs_window.cpp

    r28300 r28309  
    248248    for (; i1 != e1; ++i1)
    249249        i1->second->clearWindowObj();
    250 }
    251 
    252 ScriptInterpreter* Window::interpreter() const
    253 {
    254     Frame* frame = impl()->frame();
    255     if (!frame)
    256         return 0;
    257 
    258     return frame->scriptProxy()->interpreter();
    259250}
    260251
     
    16641655        return;
    16651656
    1666     RefPtr<ScriptInterpreter> interpreter = scriptProxy->interpreter();
     1657    ScriptInterpreter* interpreter = scriptProxy->interpreter();
    16671658
    16681659    interpreter->setProcessingTimerCallback(true);
  • trunk/WebCore/bindings/js/kjs_window.h

    r28110 r28309  
    104104    void timerFired(DOMWindowTimer*);
    105105   
    106     KJS::ScriptInterpreter *interpreter() const;
    107        
    108106    bool isSafeScript(ExecState*) const;
    109107    static bool isSafeScript(const ScriptInterpreter *origin, const ScriptInterpreter *target);
  • trunk/WebCore/page/Frame.cpp

    r28066 r28309  
    11111111    if (!d->m_bindingRootObject) {
    11121112        JSLock lock;
    1113         d->m_bindingRootObject = KJS::Bindings::RootObject::create(0, scriptProxy()->interpreter());
     1113        d->m_bindingRootObject = KJS::Bindings::RootObject::create(0, scriptProxy()->interpreter()->globalObject());
    11141114    }
    11151115    return d->m_bindingRootObject.get();
    11161116}
    11171117
    1118 PassRefPtr<KJS::Bindings::RootObject> Frame::createRootObject(void* nativeHandle, PassRefPtr<KJS::Interpreter> interpreter)
     1118PassRefPtr<KJS::Bindings::RootObject> Frame::createRootObject(void* nativeHandle, KJS::JSGlobalObject* globalObject)
    11191119{
    11201120    RootObjectMap::iterator it = d->m_rootObjects.find(nativeHandle);
     
    11221122        return it->second;
    11231123   
    1124     RefPtr<KJS::Bindings::RootObject> rootObject = KJS::Bindings::RootObject::create(nativeHandle, interpreter);
     1124    RefPtr<KJS::Bindings::RootObject> rootObject = KJS::Bindings::RootObject::create(nativeHandle, globalObject);
    11251125   
    11261126    d->m_rootObjects.set(nativeHandle, rootObject);
  • trunk/WebCore/page/Frame.h

    r27776 r28309  
    4242
    4343namespace KJS {
     44
    4445    class Interpreter;
     46    class JSGlobalObject;
     47
    4548    namespace Bindings {
    4649        class Instance;
    4750        class RootObject;
    4851    }
     52
    4953}
    5054
     
    170174    KJS::Bindings::RootObject* bindingRootObject();
    171175   
    172     PassRefPtr<KJS::Bindings::RootObject> createRootObject(void* nativeHandle, PassRefPtr<KJS::Interpreter>);
     176    PassRefPtr<KJS::Bindings::RootObject> createRootObject(void* nativeHandle, KJS::JSGlobalObject*);
    173177
    174178#if PLATFORM(MAC)
  • trunk/WebCore/page/mac/WebCoreFrameBridge.mm

    r27873 r28309  
    131131
    132132    Frame* frame = [bridge _frame];
    133     return frame->createRootObject(nativeHandle, frame->scriptProxy()->interpreter());
     133    return frame->createRootObject(nativeHandle, frame->scriptProxy()->interpreter()->globalObject());
    134134}
    135135
Note: See TracChangeset for help on using the changeset viewer.