[webkit-changes] cvs commit: WebCore/kwq WebCoreJavaScript.mm

Maciej mjs at opensource.apple.com
Tue Nov 22 21:41:23 PST 2005


mjs         05/11/22 21:41:23

  Modified:    .        ChangeLog
               JavaScriptCore.xcodeproj project.pbxproj
               kjs      collector.cpp config.h internal.cpp internal.h
                        interpreter.cpp interpreter.h protect.h
                        protected_values.cpp testkjs.cpp
               .        ChangeLog
               khtml/ecma kjs_events.cpp xmlhttprequest.cpp
               kwq      WebCoreJavaScript.mm
  Added:       kjs      JSLock.cpp JSLock.h
  Log:
  JavaScriptCore:
  
          Reviewed by Geoff.
  
  	<rdar://problem/4139620> Seed: WebKit: hang when sending XMLHttpRequest if automatic proxy config is used
  
  	Also factored locking code completely into a separate class, and
  	added a convenient packaged way to temporarily drop locks.
  
          * JavaScriptCore.xcodeproj/project.pbxproj:
          * kjs/JSLock.cpp: Added.
          (KJS::initializeInterpreterLock):
          (KJS::InterpreterLock::lock):
          (KJS::InterpreterLock::unlock):
          (KJS::InterpreterLock::lockCount):
          (KJS::InterpreterLock::DropAllLocks::DropAllLocks):
          (KJS::InterpreterLock::DropAllLocks::~DropAllLocks):
          * kjs/JSLock.h: Added.
          (KJS::InterpreterLock::InterpreterLock):
          (KJS::InterpreterLock::~InterpreterLock):
          * kjs/internal.cpp:
          * kjs/internal.h:
          * kjs/interpreter.cpp:
          * kjs/interpreter.h:
          * kjs/protect.h:
          * kjs/testkjs.cpp:
          (TestFunctionImp::callAsFunction):
  
  WebCore:
  
          Reviewed by Geoff.
  
  	<rdar://problem/4139620> Seed: WebKit: hang when sending XMLHttpRequest if automatic proxy config is used
  
          * khtml/ecma/kjs_events.cpp:
          (KJS::JSLazyEventListener::parseCode):
          * khtml/ecma/xmlhttprequest.cpp:
          (KJS::XMLHttpRequest::send):
          * kwq/WebCoreJavaScript.mm:
  
  Revision  Changes    Path
  1.883     +28 -0     JavaScriptCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
  retrieving revision 1.882
  retrieving revision 1.883
  diff -u -r1.882 -r1.883
  --- ChangeLog	21 Nov 2005 09:39:14 -0000	1.882
  +++ ChangeLog	23 Nov 2005 05:41:18 -0000	1.883
  @@ -1,3 +1,31 @@
  +2005-11-21  Maciej Stachowiak  <mjs at apple.com>
  +
  +        Reviewed by Geoff.
  +
  +	<rdar://problem/4139620> Seed: WebKit: hang when sending XMLHttpRequest if automatic proxy config is used
  +
  +	Also factored locking code completely into a separate class, and
  +	added a convenient packaged way to temporarily drop locks.
  +
  +        * JavaScriptCore.xcodeproj/project.pbxproj:
  +        * kjs/JSLock.cpp: Added.
  +        (KJS::initializeInterpreterLock):
  +        (KJS::InterpreterLock::lock):
  +        (KJS::InterpreterLock::unlock):
  +        (KJS::InterpreterLock::lockCount):
  +        (KJS::InterpreterLock::DropAllLocks::DropAllLocks):
  +        (KJS::InterpreterLock::DropAllLocks::~DropAllLocks):
  +        * kjs/JSLock.h: Added.
  +        (KJS::InterpreterLock::InterpreterLock):
  +        (KJS::InterpreterLock::~InterpreterLock):
  +        * kjs/internal.cpp:
  +        * kjs/internal.h:
  +        * kjs/interpreter.cpp:
  +        * kjs/interpreter.h:
  +        * kjs/protect.h:
  +        * kjs/testkjs.cpp:
  +        (TestFunctionImp::callAsFunction):
  +
   2005-11-21  Eric Seidel  <eseidel at apple.com>
   
           Rubber-stamped by hyatt.
  
  
  
  1.25      +8 -0      JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
  
  Index: project.pbxproj
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- project.pbxproj	21 Nov 2005 09:39:16 -0000	1.24
  +++ project.pbxproj	23 Nov 2005 05:41:18 -0000	1.25
  @@ -45,6 +45,8 @@
   		65E217BE08E7EECC0023E5F6 /* Assertions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 65E217B808E7EECC0023E5F6 /* Assertions.mm */; };
   		65E217BF08E7EECC0023E5F6 /* FastMalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65E217B908E7EECC0023E5F6 /* FastMalloc.cpp */; };
   		65E217C008E7EECC0023E5F6 /* FastMalloc.h in Headers */ = {isa = PBXBuildFile; fileRef = 65E217BA08E7EECC0023E5F6 /* FastMalloc.h */; settings = {ATTRIBUTES = (Private, ); }; };
  +		65EA4C9B092AF9E20093D800 /* JSLock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65EA4C99092AF9E20093D800 /* JSLock.cpp */; };
  +		65EA4C9C092AF9E20093D800 /* JSLock.h in Headers */ = {isa = PBXBuildFile; fileRef = 65EA4C9A092AF9E20093D800 /* JSLock.h */; settings = {ATTRIBUTES = (Private, ); }; };
   		930754C108B0F68000AB3056 /* pcre_compile.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754BF08B0F68000AB3056 /* pcre_compile.c */; };
   		930754D008B0F74600AB3056 /* pcre_tables.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754CE08B0F74500AB3056 /* pcre_tables.c */; };
   		930754D308B0F76300AB3056 /* pcre_globals.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754D108B0F76200AB3056 /* pcre_globals.c */; };
  @@ -348,6 +350,8 @@
   		65E217B808E7EECC0023E5F6 /* Assertions.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = Assertions.mm; sourceTree = "<group>"; };
   		65E217B908E7EECC0023E5F6 /* FastMalloc.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FastMalloc.cpp; sourceTree = "<group>"; };
   		65E217BA08E7EECC0023E5F6 /* FastMalloc.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FastMalloc.h; sourceTree = "<group>"; };
  +		65EA4C99092AF9E20093D800 /* JSLock.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSLock.cpp; sourceTree = "<group>"; };
  +		65EA4C9A092AF9E20093D800 /* JSLock.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSLock.h; sourceTree = "<group>"; };
   		700DA117065984CE00747C0B /* WebScriptObjectPrivate.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = WebScriptObjectPrivate.h; path = bindings/objc/WebScriptObjectPrivate.h; sourceTree = "<group>"; };
   		704FD35305697E6D003DBED9 /* bool_object.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = bool_object.h; sourceTree = "<group>"; };
   		704FD44505698F17003DBED9 /* runtime.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = runtime.cpp; path = bindings/runtime.cpp; sourceTree = "<group>"; };
  @@ -521,6 +525,8 @@
   		08FB77AEFE84172EC02AAC07 /* Classes */ = {
   			isa = PBXGroup;
   			children = (
  +				65EA4C99092AF9E20093D800 /* JSLock.cpp */,
  +				65EA4C9A092AF9E20093D800 /* JSLock.h */,
   				65621E6B089E859700760F35 /* property_slot.cpp */,
   				65621E6C089E859700760F35 /* property_slot.h */,
   				938772E5038BFE19008635CE /* array_instance.h */,
  @@ -840,6 +846,7 @@
   				65DFC93508EA173A00F7300B /* HashTraits.h in Headers */,
   				6557E8F808EA5D4D0049CDFC /* HashMapPtrSpec.h in Headers */,
   				65D7D19C08F10B5B0015ABD8 /* FastMallocInternal.h in Headers */,
  +				65EA4C9C092AF9E20093D800 /* JSLock.h in Headers */,
   			);
   			runOnlyForDeploymentPostprocessing = 0;
   		};
  @@ -1222,6 +1229,7 @@
   				65E217BF08E7EECC0023E5F6 /* FastMalloc.cpp in Sources */,
   				6541BD7408E80A17002CBEE7 /* TCSystemAlloc.cpp in Sources */,
   				65DFC93308EA173A00F7300B /* HashTable.cpp in Sources */,
  +				65EA4C9B092AF9E20093D800 /* JSLock.cpp in Sources */,
   			);
   			runOnlyForDeploymentPostprocessing = 0;
   		};
  
  
  
  1.51      +2 -2      JavaScriptCore/kjs/collector.cpp
  
  Index: collector.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/collector.cpp,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- collector.cpp	16 Nov 2005 01:45:11 -0000	1.50
  +++ collector.cpp	23 Nov 2005 05:41:19 -0000	1.51
  @@ -106,7 +106,7 @@
   
   void* Collector::allocate(size_t s)
   {
  -  assert(Interpreter::lockCount() > 0);
  +  assert(InterpreterLock::lockCount() > 0);
   
     // collect if needed
     size_t numLiveObjects = heap.numLiveObjects;
  @@ -393,7 +393,7 @@
   
   bool Collector::collect()
   {
  -  assert(Interpreter::lockCount() > 0);
  +  assert(InterpreterLock::lockCount() > 0);
   
     if (InterpreterImp::s_hook) {
       InterpreterImp *scr = InterpreterImp::s_hook;
  
  
  
  1.14      +2 -0      JavaScriptCore/kjs/config.h
  
  Index: config.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/config.h,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- config.h	9 Oct 2005 22:56:28 -0000	1.13
  +++ config.h	23 Nov 2005 05:41:19 -0000	1.14
  @@ -10,6 +10,8 @@
   #define HAVE_SYS_TIME_H 1
   #define HAVE_SYS_TIMEB_H 1
   
  +#define KJS_MULTIPLE_THREADS 1
  +
   #elif WIN32
   
   #define HAVE_FLOAT_H 1
  
  
  
  1.78      +0 -61     JavaScriptCore/kjs/internal.cpp
  
  Index: internal.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/internal.cpp,v
  retrieving revision 1.77
  retrieving revision 1.78
  diff -u -r1.77 -r1.78
  --- internal.cpp	16 Nov 2005 01:45:11 -0000	1.77
  +++ internal.cpp	23 Nov 2005 05:41:19 -0000	1.78
  @@ -74,46 +74,6 @@
    
   #endif // APPLE_CHANGES
   
  -#if defined(KJS_MULTIPLE_THREADS) && KJS_MULTIPLE_THREADS
  -
  -static pthread_once_t interpreterLockOnce = PTHREAD_ONCE_INIT;
  -static pthread_mutex_t interpreterLock;
  -static int interpreterLockCount = 0;
  -
  -static void initializeInterpreterLock()
  -{
  -  pthread_mutexattr_t attr;
  -
  -  pthread_mutexattr_init(&attr);
  -  pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
  -
  -  pthread_mutex_init(&interpreterLock, &attr);
  -}
  -
  -static inline void lockInterpreter()
  -{
  -  pthread_once(&interpreterLockOnce, initializeInterpreterLock);
  -  pthread_mutex_lock(&interpreterLock);
  -  interpreterLockCount++;
  -  Collector::registerThread();
  -}
  -
  -static inline void unlockInterpreter()
  -{
  -  interpreterLockCount--;
  -  pthread_mutex_unlock(&interpreterLock);
  -}
  -
  -#else
  -
  -static inline void initializeInterpreterLock() { }
  -static inline void lockInterpreter() { }
  -static inline void unlockInterpreter() { }
  -
  -const int interpreterLockCount = 1;
  -
  -#endif
  -
   // ------------------------------ UndefinedImp ---------------------------------
   
   ValueImp *UndefinedImp::toPrimitive(ExecState *, Type) const
  @@ -473,27 +433,6 @@
     recursion = 0;
   }
   
  -void InterpreterImp::lock()
  -{
  -  lockInterpreter();
  -
  -  // FIXME: Hack-o-rama. To prevent construction of a global object with a null prototype (4342216),
  -  // we need to intialize our constants before the first object is constructed. InterpreterImp::lock()
  -  // is a good place to do this because you have to call it before doing any allocations. Once we change our 
  -  // implementation to use immediate values, we should remove this code.
  -  ConstantValues::initIfNeeded();
  -}
  -
  -int InterpreterImp::lockCount()
  -{
  -  return interpreterLockCount;
  -}
  -
  -void InterpreterImp::unlock()
  -{
  -  unlockInterpreter();
  -}
  -
    void InterpreterImp::initGlobalObject()
   {
     Identifier::init();
  
  
  
  1.45      +0 -7      JavaScriptCore/kjs/internal.h
  
  Index: internal.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/internal.h,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- internal.h	16 Nov 2005 01:45:12 -0000	1.44
  +++ internal.h	23 Nov 2005 05:41:19 -0000	1.45
  @@ -33,10 +33,6 @@
   #include "scope_chain.h"
   #include <kxmlcore/SharedPtr.h>
   
  -#if __APPLE__
  -#define KJS_MULTIPLE_THREADS 1
  -#endif
  -
   #define I18N_NOOP(s) s
   
   namespace KJS {
  @@ -253,9 +249,6 @@
       Interpreter *interpreter() const { return m_interpreter; }
   
       void initGlobalObject();
  -    static void lock();
  -    static void unlock();
  -    static int lockCount();
   
       void mark();
   
  
  
  
  1.32      +0 -15     JavaScriptCore/kjs/interpreter.cpp
  
  Index: interpreter.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/interpreter.cpp,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- interpreter.cpp	3 Oct 2005 21:11:49 -0000	1.31
  +++ interpreter.cpp	23 Nov 2005 05:41:19 -0000	1.32
  @@ -99,21 +99,6 @@
     rep->initGlobalObject();
   }
   
  -void Interpreter::lock()
  -{
  -  InterpreterImp::lock();
  -}
  -
  -void Interpreter::unlock()
  -{
  -  InterpreterImp::unlock();
  -}
  -
  -int Interpreter::lockCount()
  -{
  -  return InterpreterImp::lockCount();
  -}
  -
   ExecState *Interpreter::globalExec()
   {
     return rep->globalExec();
  
  
  
  1.29      +0 -14     JavaScriptCore/kjs/interpreter.h
  
  Index: interpreter.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/interpreter.h,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- interpreter.h	19 Sep 2005 06:57:27 -0000	1.28
  +++ interpreter.h	23 Nov 2005 05:41:19 -0000	1.29
  @@ -167,10 +167,6 @@
   
       void initGlobalObject();
   
  -    static void lock();
  -    static void unlock();
  -    static int lockCount();
  -
       /**
        * Returns the execution state object which can be used to execute
        * scripts using this interpreter at a the "global" level, i.e. one
  @@ -482,16 +478,6 @@
       ValueImp *_exception;
     };
   
  -    class InterpreterLock
  -    {
  -    public:
  -        InterpreterLock() { Interpreter::lock(); }
  -        ~InterpreterLock() { Interpreter::unlock(); }
  -    private:
  -        InterpreterLock(const InterpreterLock &);
  -        InterpreterLock &operator =(const InterpreterLock &);
  -    };
  -
   } // namespace
   
   #endif // _KJS_INTERPRETER_H_
  
  
  
  1.11      +1 -1      JavaScriptCore/kjs/protect.h
  
  Index: protect.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/protect.h,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- protect.h	16 Oct 2005 00:46:23 -0000	1.10
  +++ protect.h	23 Nov 2005 05:41:19 -0000	1.11
  @@ -27,7 +27,7 @@
   #include "reference.h"
   #include "value.h"
   #include "protected_values.h"
  -#include "interpreter.h"
  +#include "JSLock.h"
   
   namespace KJS {
   
  
  
  
  1.9       +3 -3      JavaScriptCore/kjs/protected_values.cpp
  
  Index: protected_values.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/protected_values.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- protected_values.cpp	4 Oct 2005 01:43:58 -0000	1.8
  +++ protected_values.cpp	23 Nov 2005 05:41:19 -0000	1.9
  @@ -42,7 +42,7 @@
   int ProtectedValues::getProtectCount(ValueImp *k)
   {
       assert(k);
  -    assert(InterpreterImp::lockCount() > 0);
  +    assert(InterpreterLock::lockCount() > 0);
   
       if (!_table)
   	return 0;
  @@ -71,7 +71,7 @@
   void ProtectedValues::increaseProtectCount(ValueImp *k)
   {
       assert(k);
  -    assert(InterpreterImp::lockCount() > 0);
  +    assert(InterpreterLock::lockCount() > 0);
   
       if (SimpleNumber::is(k))
         return;
  @@ -121,7 +121,7 @@
   void ProtectedValues::decreaseProtectCount(ValueImp *k)
   {
       assert(k);
  -    assert(InterpreterImp::lockCount() > 0);
  +    assert(InterpreterLock::lockCount() > 0);
   
       if (SimpleNumber::is(k))
         return;
  
  
  
  1.17      +4 -2      JavaScriptCore/kjs/testkjs.cpp
  
  Index: testkjs.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/testkjs.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- testkjs.cpp	3 Oct 2005 21:11:51 -0000	1.16
  +++ testkjs.cpp	23 Nov 2005 05:41:19 -0000	1.17
  @@ -31,6 +31,7 @@
   #include "types.h"
   #include "interpreter.h"
   #include "collector.h"
  +#include "JSLock.h"
   
   using namespace KJS;
   
  @@ -62,9 +63,10 @@
       exit(0);
       return Undefined();
     case GC:
  -    Interpreter::lock();
  +  {
  +    InterpreterLock lock;
       Collector::collect();
  -    Interpreter::unlock();
  +  }
       break;
     default:
       break;
  
  
  
  1.1                  JavaScriptCore/kjs/JSLock.cpp
  
  Index: JSLock.cpp
  ===================================================================
  // -*- mode: c++; c-basic-offset: 4 -*-
  /*
   * This file is part of the KDE libraries
   * Copyright (C) 2005 Apple Computer, Inc.
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Library General Public
   * License as published by the Free Software Foundation; either
   * version 2 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Library General Public License for more details.
   *
   * You should have received a copy of the GNU Library General Public License
   * along with this library; see the file COPYING.LIB.  If not, write to
   * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   * Boston, MA 02111-1307, USA.
   *
   */
  
  #include "config.h"
  #include "JSLock.h"
  
  #include "collector.h"
  
  namespace KJS {
  
  #if KJS_MULTIPLE_THREADS
  
  static pthread_once_t interpreterLockOnce = PTHREAD_ONCE_INIT;
  static pthread_mutex_t interpreterLock;
  static int interpreterLockCount = 0;
  
  static void initializeInterpreterLock()
  {
    pthread_mutexattr_t attr;
  
    pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
  
    pthread_mutex_init(&interpreterLock, &attr);
  }
  
  void InterpreterLock::lock()
  {
    pthread_once(&interpreterLockOnce, initializeInterpreterLock);
    pthread_mutex_lock(&interpreterLock);
    interpreterLockCount++;
    Collector::registerThread();
  
    // FIXME: Hack-o-rama. To prevent construction of a global object with a null prototype (4342216),
    // we need to intialize our constants before the first object is constructed. InterpreterImp::lock()
    // is a good place to do this because you have to call it before doing any allocations. Once we change our 
    // implementation to use immediate values, we should remove this code.
    ConstantValues::initIfNeeded();
  }
  
  void InterpreterLock::unlock()
  {
    interpreterLockCount--;
    pthread_mutex_unlock(&interpreterLock);
  }
  
  #else
  
  // If threading support is off, set the lock count to a constant value of 1 so assertions
  // that the lock is held don't fail
  const int interpreterLockCount = 1;
  
  void InterpreterLock::lock()
  {
  }
  
  void InterpreterLock::unlock()
  {
  }
  
  #endif
  
  int InterpreterLock::lockCount()
  {
      return interpreterLockCount;
  }
          
  InterpreterLock::DropAllLocks::DropAllLocks()
  {
      int lockCount = InterpreterLock::lockCount();
      for (int i = 0; i < lockCount; i++) {
          InterpreterLock::unlock();
      }
      m_lockCount = lockCount;
  }
  
  InterpreterLock::DropAllLocks::~DropAllLocks()
  {
      int lockCount = m_lockCount;
      for (int i = 0; i < lockCount; i++) {
          InterpreterLock::lock();
      }
  }
  
  }
  
  
  
  1.1                  JavaScriptCore/kjs/JSLock.h
  
  Index: JSLock.h
  ===================================================================
  // -*- mode: c++; c-basic-offset: 4 -*-
  /*
   * This file is part of the KDE libraries
   * Copyright (C) 2005 Apple Computer, Inc.
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Library General Public
   * License as published by the Free Software Foundation; either
   * version 2 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Library General Public License for more details.
   *
   * You should have received a copy of the GNU Library General Public License
   * along with this library; see the file COPYING.LIB.  If not, write to
   * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   * Boston, MA 02111-1307, USA.
   *
   */
  
  #ifndef KJS_INTERPRETER_LOCK_H
  #define KJS_INTERPRETER_LOCK_H
  
  namespace KJS {
  
      // to make it safe to use JavaScript on multiple threads, it is
      // important to lock before doing anything that allocates a
      // garbage-collected object or which may affect other shared state
      // such as the protect count hash table. The simplest way to do
      // this is by having a local InterpreterLock object for the scope
      // where the lock must be held. The lock is recursive so nesting
      // is ok.
  
      // Sometimes it is necessary to temporarily release the lock -
      // since it is recursive you have to actually release all locks
      // held by your thread. This is safe to do if you are executing
      // code that doesn't require the lock, and reacquire the right
      // number of locks at the end. You can do this by constructing a
      // locally scoped InterpreterLock::DropAllLocks object.
  
      class InterpreterLock
      {
      public:
          InterpreterLock() 
          {
              lock();
          }
          ~InterpreterLock() { 
              unlock(); 
          }
          
          static void lock();
          static void unlock();
          static int lockCount();
          
          class DropAllLocks {
          public:
              DropAllLocks();
              ~DropAllLocks();
          private:
              int m_lockCount;
              
              DropAllLocks(const DropAllLocks&);
              DropAllLocks& operator=(const DropAllLocks&);
          };
          
      private:
          InterpreterLock(const InterpreterLock&);
          InterpreterLock& operator=(const InterpreterLock&);
      };
  
  } // namespace
  
  #endif // KJS_INTERPRETER_LOCK_H
  
  
  
  1.396     +12 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.395
  retrieving revision 1.396
  diff -u -r1.395 -r1.396
  --- ChangeLog	22 Nov 2005 23:04:25 -0000	1.395
  +++ ChangeLog	23 Nov 2005 05:41:21 -0000	1.396
  @@ -1,3 +1,15 @@
  +2005-11-16  Maciej Stachowiak  <mjs at apple.com>
  +
  +        Reviewed by Geoff.
  +
  +	<rdar://problem/4139620> Seed: WebKit: hang when sending XMLHttpRequest if automatic proxy config is used
  +
  +        * khtml/ecma/kjs_events.cpp:
  +        (KJS::JSLazyEventListener::parseCode):
  +        * khtml/ecma/xmlhttprequest.cpp:
  +        (KJS::XMLHttpRequest::send):
  +        * kwq/WebCoreJavaScript.mm:
  +
   2005-11-22  eseidel  <eseidel at apple.com>
   
           No review required, svg target only.
  
  
  
  1.70      +7 -5      WebCore/khtml/ecma/kjs_events.cpp
  
  Index: kjs_events.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/ecma/kjs_events.cpp,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- kjs_events.cpp	19 Nov 2005 01:26:44 -0000	1.69
  +++ kjs_events.cpp	23 Nov 2005 05:41:22 -0000	1.70
  @@ -319,11 +319,13 @@
           // Add the event's home element to the scope
           // (and the document, and the form - see HTMLElement::eventHandlerScope)
           ScopeChain scope = listener->scope();
  -        
  -        Interpreter::lock();
  -        ObjectImp *thisObj = static_cast<ObjectImp *>(getDOMNode(exec, originalNode));
  -        Interpreter::unlock();
  -        
  +
  +        ObjectImp *thisObj;
  +        { // scope
  +            InterpreterLock lock;
  +            thisObj = static_cast<ObjectImp *>(getDOMNode(exec, originalNode));
  +        }
  +
           if (thisObj) {
             static_cast<DOMNode*>(thisObj)->pushEventHandlerScope(exec, scope);
             listener->setScope(scope);
  
  
  
  1.47      +7 -1      WebCore/khtml/ecma/xmlhttprequest.cpp
  
  Index: xmlhttprequest.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/ecma/xmlhttprequest.cpp,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- xmlhttprequest.cpp	21 Nov 2005 04:01:54 -0000	1.46
  +++ xmlhttprequest.cpp	23 Nov 2005 05:41:22 -0000	1.47
  @@ -346,7 +346,13 @@
       KURL finalURL;
       QString headers;
   
  -    data = KWQServeSynchronousRequest(khtml::Cache::loader(), doc->docLoader(), job, finalURL, headers);
  +    { // scope
  +        // avoid deadlock in case the loader wants to use JS on a background thread
  +        InterpreterLock::DropAllLocks dropLocks;
  +
  +        data = KWQServeSynchronousRequest(khtml::Cache::loader(), doc->docLoader(), job, finalURL, headers);
  +    }
  +
       job = 0;
       processSyncLoadResults(data, finalURL, headers);
       
  
  
  
  1.11      +1 -0      WebCore/kwq/WebCoreJavaScript.mm
  
  Index: WebCoreJavaScript.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/WebCoreJavaScript.mm,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- WebCoreJavaScript.mm	3 Oct 2005 21:13:12 -0000	1.10
  +++ WebCoreJavaScript.mm	23 Nov 2005 05:41:23 -0000	1.11
  @@ -28,6 +28,7 @@
   
   #import <JavaScriptCore/collector.h>
   #import <JavaScriptCore/interpreter.h>
  +#import <JavaScriptCore/JSLock.h>
   
   using KJS::Collector;
   using KJS::Interpreter;
  
  
  



More information about the webkit-changes mailing list