source: webkit/trunk/JavaScriptCore/kjs/JSGlobalData.h@ 37190

Last change on this file since 37190 was 37190, checked in by [email protected], 17 years ago

Reviewed by Darin Adler.

https://bugs.webkit.org/show_bug.cgi?id=21304
Stop using a static wrapper map for WebCore JS bindings

The static domObjects map was not thread safe.

  • dom/Document.h: (WebCore::Document::messagePorts): Added an accessor for JSDocument to iterate over message ports. (WebCore::Document::xmlHttpRequests): Ditto for XMLHttpRequests.
  • dom/Document.cpp: (WebCore::Document::createdXMLHttpRequest): (WebCore::Document::destroyedXMLHttpRequest): Moved XMLHttpRequest tracking from a global map to Document.
  • GNUmakefile.am:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • WebCoreSources.bkl:
  • webcore-base.bkl:
  • bindings/DOMProtect.cpp: Removed.
  • bindings/DOMProtect.h: Removed. Removed gcProtect(Unprotect)DOMObject - its callers do not have a JSGlobalData reference, so they can no longer protect bindings objects.
  • dom/MessagePort.cpp: (WebCore::CloseMessagePortTimer::CloseMessagePortTimer): (WebCore::CloseMessagePortTimer::fired): (WebCore::MessagePort::MessagePort): (WebCore::MessagePort::queueCloseEvent): (WebCore::MessagePort::setPendingActivity): (WebCore::MessagePort::unsetPendingActivity):
  • dom/MessagePort.h: (WebCore::MessagePort::hasPendingActivity): MessagePort now counts outstanding async events, so JSDocument::mark can decide whether to protect it.
  • xml/XMLHttpRequest.h: (WebCore::XMLHttpRequest::hasPendingActivity):
  • xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::XMLHttpRequest): (WebCore::XMLHttpRequest::~XMLHttpRequest): (WebCore::XMLHttpRequest::loadRequestAsynchronously): (WebCore::XMLHttpRequest::dropProtection): (WebCore::XMLHttpRequest::didFinishLoadingPreflight): (WebCore::XMLHttpRequest::cancelRequests): (WebCore::XMLHttpRequest::detachRequests): (WebCore::XMLHttpRequest::setPendingActivity): (WebCore::XMLHttpRequest::unsetPendingActivity): Moved XMLHttpRequest tracking from a global map to Document.
  • bindings/js/JSDOMBinding.cpp: (WebCore::wrapperSet): (WebCore::DOMObjectWrapperMap::mapFor): (WebCore::DOMObjectWrapperMap::get): (WebCore::DOMObjectWrapperMap::set): (WebCore::DOMObjectWrapperMap::remove): (WebCore::getCachedDOMObjectWrapper): (WebCore::cacheDOMObjectWrapper): (WebCore::forgetDOMObject): (WebCore::getCachedDOMNodeWrapper): (WebCore::forgetDOMNode): (WebCore::cacheDOMNodeWrapper): (WebCore::markActiveObjectsForDocument):
  • bindings/js/JSDOMBinding.h: (WebCore::createDOMObjectWrapper): (WebCore::getDOMObjectWrapper): Wrapper map is now kept as JSGlobalData::clientData. Also changed debug-only wrapperSet to be per-thread (this is slower than going to JSGlobalData, but fast enough for debug). WebCore objects can never migrate between threads.
  • bindings/js/JSDocumentCustom.cpp: (WebCore::JSDocument::mark): Call markActiveObjectsForDocument() from JSDOMBinding.
  • bindings/js/JSCSSRuleCustom.cpp: (WebCore::toJS):
  • bindings/js/JSCSSValueCustom.cpp: (WebCore::toJS):
  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::markDOMObjectWrapper): (WebCore::JSDOMWindow::mark):
  • bindings/js/JSEventCustom.cpp: (WebCore::toJS):
  • bindings/js/JSEventTarget.cpp: (WebCore::toJS):
  • bindings/js/JSHTMLCollectionCustom.cpp: (WebCore::toJS):
  • bindings/js/JSImageDataCustom.cpp: (WebCore::toJS):
  • bindings/js/JSMessageChannelCustom.cpp: (WebCore::JSMessageChannel::mark):
  • bindings/js/JSMessagePortCustom.cpp: (WebCore::JSMessagePort::mark):
  • bindings/js/JSNodeCustom.cpp: (WebCore::JSNode::mark):
  • bindings/js/JSSVGPathSegCustom.cpp: (WebCore::toJS):
  • bindings/js/JSStyleSheetCustom.cpp: (WebCore::toJS):
  • bindings/js/JSXMLHttpRequestCustom.cpp: (WebCore::JSXMLHttpRequest::mark):
  • bindings/js/JSXMLHttpRequestUploadCustom.cpp: (WebCore::JSXMLHttpRequestUpload::mark):
  • bindings/js/ScriptController.cpp: (WebCore::ScriptController::finishedWithEvent):
  • bindings/scripts/CodeGeneratorJS.pm: Pass a JSGlobalData reference to functions that track JS wrapper objects.

JavaScriptCore:

  • kjs/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData): (JSC::JSGlobalData::~JSGlobalData): (JSC::JSGlobalData::ClientData::~ClientData):
  • kjs/JSGlobalData.h: Added a client data member to JSGlobalData. WebCore will use it to store bindings-related global data.
  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef JSGlobalData_h
30#define JSGlobalData_h
31
32#include <wtf/Forward.h>
33#include <wtf/HashCountedSet.h>
34#include <wtf/HashMap.h>
35#include <wtf/HashSet.h>
36#include <wtf/RefCounted.h>
37#include "SmallStrings.h"
38
39struct OpaqueJSClass;
40struct OpaqueJSClassContextData;
41
42namespace JSC {
43
44 class ArgList;
45 class CommonIdentifiers;
46 class Heap;
47 class IdentifierTable;
48 class JSGlobalObject;
49 class JSObject;
50 class Lexer;
51 class Machine;
52 class Parser;
53 class ParserRefCounted;
54 class StructureID;
55 class UString;
56 struct HashTable;
57
58 class JSGlobalData : public RefCounted<JSGlobalData> {
59 public:
60 static bool sharedInstanceExists();
61 static JSGlobalData& sharedInstance();
62
63 static PassRefPtr<JSGlobalData> create();
64 ~JSGlobalData();
65
66 Machine* machine;
67 Heap* heap;
68
69 const HashTable* arrayTable;
70 const HashTable* dateTable;
71 const HashTable* mathTable;
72 const HashTable* numberTable;
73 const HashTable* regExpTable;
74 const HashTable* regExpConstructorTable;
75 const HashTable* stringTable;
76
77 RefPtr<StructureID> nullProtoStructureID;
78 RefPtr<StructureID> stringStructureID;
79 RefPtr<StructureID> numberStructureID;
80
81 IdentifierTable* identifierTable;
82 CommonIdentifiers* propertyNames;
83 const ArgList* emptyList; // Lists are supposed to be allocated on the stack to have their elements properly marked, which is not the case here - but this list has nothing to mark.
84
85 SmallStrings smallStrings;
86
87 HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
88
89 HashSet<ParserRefCounted*>* newParserObjects;
90 HashCountedSet<ParserRefCounted*>* parserObjectExtraRefCounts;
91
92 Lexer* lexer;
93 Parser* parser;
94
95 JSGlobalObject* head;
96
97 bool isSharedInstance;
98
99 struct ClientData {
100 virtual ~ClientData() = 0;
101 };
102
103 ClientData* clientData;
104
105 HashSet<JSObject*> arrayVisitedElements;
106
107 private:
108 JSGlobalData(bool isShared = false);
109
110 static JSGlobalData*& sharedInstanceInternal();
111 };
112
113}
114
115#endif
Note: See TracBrowser for help on using the repository browser.