source: webkit/trunk/JavaScriptCore/runtime/JSGlobalData.cpp@ 51875

Last change on this file since 51875 was 51512, checked in by [email protected], 15 years ago

Bug 31859 - Make world selection for JSC IsolatedWorlds automagical.

Reviewed by Geoff Garen.

JavaScriptCore:

WebCore presently has to explicitly specify the world before entering into JSC,
which is a little fragile (particularly since property access via a
getter/setter might invoke execution). Instead derive the current world from
the lexical global object.

Remove the temporary duct tape of willExecute/didExecute virtual hooks on the JSGlobalData::ClientData - these are no longer necessary.

  • API/JSBase.cpp:

(JSEvaluateScript):

  • API/JSObjectRef.cpp:

(JSObjectCallAsFunction):

  • JavaScriptCore.exp:
  • runtime/JSGlobalData.cpp:
  • runtime/JSGlobalData.h:

WebCore:

WebCore presently has to explicitly specify the world before entering into JSC,
which is a little fragile (particularly since property access via a
getter/setter might invoke execution). Instead derive the current world from
the lexical global object.

Remove the last uses of mainThreadCurrentWorld(), so the world is always obtained via
currentWorld(). Switch this to obtain the world from the ExecsState's lexical global
object instead. Remove the call/construct/evaluate 'InWorld' methods, since these
are no longer necessary.

  • WebCore.base.exp:
  • bindings/js/JSCallbackData.cpp:

(WebCore::JSCallbackData::invokeCallback):

  • bindings/js/JSCallbackData.h:

(WebCore::JSCallbackData::JSCallbackData):

  • bindings/js/JSCustomXPathNSResolver.cpp:

(WebCore::JSCustomXPathNSResolver::lookupNamespaceURI):

  • bindings/js/JSDOMBinding.cpp:

(WebCore::currentWorld):
(WebCore::mainThreadNormalWorld):

  • bindings/js/JSDOMBinding.h:

(WebCore::WebCoreJSClientData::WebCoreJSClientData):

  • bindings/js/JSDOMWindowBase.cpp:

(WebCore::JSDOMWindowBase::updateDocument):

  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSEventListener.cpp:

(WebCore::JSEventListener::handleEvent):
(WebCore::JSEventListener::reportError):

  • bindings/js/JSHTMLDocumentCustom.cpp:

(WebCore::JSHTMLDocument::open):

  • bindings/js/JSNodeFilterCondition.cpp:

(WebCore::JSNodeFilterCondition::acceptNode):

  • bindings/js/JSQuarantinedObjectWrapper.cpp:

(WebCore::JSQuarantinedObjectWrapper::construct):
(WebCore::JSQuarantinedObjectWrapper::call):

  • bindings/js/ScheduledAction.cpp:

(WebCore::ScheduledAction::executeFunctionInContext):

  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::evaluateInWorld):
(WebCore::ScriptController::initScript):
(WebCore::ScriptController::updateDocument):

  • bindings/js/ScriptFunctionCall.cpp:

(WebCore::ScriptFunctionCall::call):
(WebCore::ScriptFunctionCall::construct):

  • bindings/js/ScriptObjectQuarantine.cpp:

(WebCore::getQuarantinedScriptObject):

  • bindings/js/ScriptState.cpp:

(WebCore::scriptStateFromNode):
(WebCore::scriptStateFromPage):

  • bindings/js/ScriptState.h:
  • bindings/js/WorkerScriptController.cpp:

(WebCore::WorkerScriptController::evaluate):

  • bindings/objc/WebScriptObject.mm:

(-[WebScriptObject callWebScriptMethod:withArguments:]):
(-[WebScriptObject evaluateWebScript:]):

  • bridge/NP_jsobject.cpp:

(_NPN_InvokeDefault):
(_NPN_Invoke):
(_NPN_Evaluate):
(_NPN_Construct):

  • bridge/jni/jni_jsobject.mm:

(JavaJSObject::call):
(JavaJSObject::eval):

  • dom/NodeFilter.h:

(WebCore::NodeFilter::acceptNode):

  • dom/NodeIterator.h:

(WebCore::NodeIterator::nextNode):
(WebCore::NodeIterator::previousNode):

  • dom/TreeWalker.h:

(WebCore::TreeWalker::parentNode):
(WebCore::TreeWalker::firstChild):
(WebCore::TreeWalker::lastChild):
(WebCore::TreeWalker::previousSibling):
(WebCore::TreeWalker::nextSibling):
(WebCore::TreeWalker::previousNode):
(WebCore::TreeWalker::nextNode):

  • inspector/InspectorController.cpp:

(WebCore::InspectorController::windowScriptObjectAvailable):
(WebCore::InspectorController::didEvaluateForTestInFrontend):

  • inspector/JavaScriptCallFrame.cpp:

(WebCore::JavaScriptCallFrame::evaluate):

WebKit/mac:

WebCore presently has to explicitly specify the world before entering into JSC,
which is a little fragile (particularly since property access via a
getter/setter might invoke execution). Instead derive the current world from
the lexical global object.

Since WebCore no longer needs to explicitly specify the world on entry to JSC DebuggerCallFrame::evaluate can be called directly.

  • WebView/WebScriptDebugDelegate.mm:

(-[WebScriptCallFrame evaluateWebScript:]):

  • Property svn:eol-style set to native
File size: 8.9 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#include "config.h"
30#include "JSGlobalData.h"
31
32#include "ArgList.h"
33#include "Collector.h"
34#include "CommonIdentifiers.h"
35#include "FunctionConstructor.h"
36#include "GetterSetter.h"
37#include "Interpreter.h"
38#include "JSActivation.h"
39#include "JSAPIValueWrapper.h"
40#include "JSArray.h"
41#include "JSByteArray.h"
42#include "JSClassRef.h"
43#include "JSFunction.h"
44#include "JSLock.h"
45#include "JSNotAnObject.h"
46#include "JSPropertyNameIterator.h"
47#include "JSStaticScopeObject.h"
48#include "Parser.h"
49#include "Lexer.h"
50#include "Lookup.h"
51#include "Nodes.h"
52
53#if ENABLE(JSC_MULTIPLE_THREADS)
54#include <wtf/Threading.h>
55#endif
56
57#if PLATFORM(MAC)
58#include "ProfilerServer.h"
59#endif
60
61using namespace WTF;
62
63namespace JSC {
64
65extern JSC_CONST_HASHTABLE HashTable arrayTable;
66extern JSC_CONST_HASHTABLE HashTable jsonTable;
67extern JSC_CONST_HASHTABLE HashTable dateTable;
68extern JSC_CONST_HASHTABLE HashTable mathTable;
69extern JSC_CONST_HASHTABLE HashTable numberTable;
70extern JSC_CONST_HASHTABLE HashTable regExpTable;
71extern JSC_CONST_HASHTABLE HashTable regExpConstructorTable;
72extern JSC_CONST_HASHTABLE HashTable stringTable;
73
74struct VPtrSet {
75 VPtrSet();
76
77 void* jsArrayVPtr;
78 void* jsByteArrayVPtr;
79 void* jsStringVPtr;
80 void* jsFunctionVPtr;
81};
82
83VPtrSet::VPtrSet()
84{
85 CollectorCell cell;
86 void* storage = &cell;
87
88 ASSERT(sizeof(JSArray) <= sizeof(CollectorCell));
89 JSCell* jsArray = new (storage) JSArray(JSArray::createStructure(jsNull()));
90 jsArrayVPtr = jsArray->vptr();
91 jsArray->~JSCell();
92
93 ASSERT(sizeof(JSByteArray) <= sizeof(CollectorCell));
94 JSCell* jsByteArray = new (storage) JSByteArray(JSByteArray::VPtrStealingHack);
95 jsByteArrayVPtr = jsByteArray->vptr();
96 jsByteArray->~JSCell();
97
98 ASSERT(sizeof(JSString) <= sizeof(CollectorCell));
99 JSCell* jsString = new (storage) JSString(JSString::VPtrStealingHack);
100 jsStringVPtr = jsString->vptr();
101 jsString->~JSCell();
102
103 ASSERT(sizeof(JSFunction) <= sizeof(CollectorCell));
104 JSCell* jsFunction = new (storage) JSFunction(JSFunction::createStructure(jsNull()));
105 jsFunctionVPtr = jsFunction->vptr();
106 jsFunction->~JSCell();
107}
108
109JSGlobalData::JSGlobalData(bool isShared, const VPtrSet& vptrSet)
110 : isSharedInstance(isShared)
111 , clientData(0)
112 , arrayTable(fastNew<HashTable>(JSC::arrayTable))
113 , dateTable(fastNew<HashTable>(JSC::dateTable))
114 , jsonTable(fastNew<HashTable>(JSC::jsonTable))
115 , mathTable(fastNew<HashTable>(JSC::mathTable))
116 , numberTable(fastNew<HashTable>(JSC::numberTable))
117 , regExpTable(fastNew<HashTable>(JSC::regExpTable))
118 , regExpConstructorTable(fastNew<HashTable>(JSC::regExpConstructorTable))
119 , stringTable(fastNew<HashTable>(JSC::stringTable))
120 , activationStructure(JSActivation::createStructure(jsNull()))
121 , interruptedExecutionErrorStructure(JSObject::createStructure(jsNull()))
122 , staticScopeStructure(JSStaticScopeObject::createStructure(jsNull()))
123 , stringStructure(JSString::createStructure(jsNull()))
124 , notAnObjectErrorStubStructure(JSNotAnObjectErrorStub::createStructure(jsNull()))
125 , notAnObjectStructure(JSNotAnObject::createStructure(jsNull()))
126 , propertyNameIteratorStructure(JSPropertyNameIterator::createStructure(jsNull()))
127 , getterSetterStructure(GetterSetter::createStructure(jsNull()))
128 , apiWrapperStructure(JSAPIValueWrapper::createStructure(jsNull()))
129#if USE(JSVALUE32)
130 , numberStructure(JSNumberCell::createStructure(jsNull()))
131#endif
132 , jsArrayVPtr(vptrSet.jsArrayVPtr)
133 , jsByteArrayVPtr(vptrSet.jsByteArrayVPtr)
134 , jsStringVPtr(vptrSet.jsStringVPtr)
135 , jsFunctionVPtr(vptrSet.jsFunctionVPtr)
136 , identifierTable(createIdentifierTable())
137 , propertyNames(new CommonIdentifiers(this))
138 , emptyList(new MarkedArgumentBuffer)
139 , lexer(new Lexer(this))
140 , parser(new Parser)
141 , interpreter(new Interpreter)
142#if ENABLE(JIT)
143 , jitStubs(this)
144#endif
145 , heap(this)
146 , initializingLazyNumericCompareFunction(false)
147 , head(0)
148 , dynamicGlobalObject(0)
149 , functionCodeBlockBeingReparsed(0)
150 , firstStringifierToMark(0)
151 , markStack(vptrSet.jsArrayVPtr)
152 , cachedUTCOffset(NaN)
153 , weakRandom(static_cast<int>(currentTime()))
154#ifndef NDEBUG
155 , mainThreadOnly(false)
156#endif
157{
158#if PLATFORM(MAC)
159 startProfilerServerIfNeeded();
160#endif
161}
162
163JSGlobalData::~JSGlobalData()
164{
165 // By the time this is destroyed, heap.destroy() must already have been called.
166
167 delete interpreter;
168#ifndef NDEBUG
169 // Zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
170 interpreter = 0;
171#endif
172
173 arrayTable->deleteTable();
174 dateTable->deleteTable();
175 jsonTable->deleteTable();
176 mathTable->deleteTable();
177 numberTable->deleteTable();
178 regExpTable->deleteTable();
179 regExpConstructorTable->deleteTable();
180 stringTable->deleteTable();
181
182 fastDelete(const_cast<HashTable*>(arrayTable));
183 fastDelete(const_cast<HashTable*>(dateTable));
184 fastDelete(const_cast<HashTable*>(jsonTable));
185 fastDelete(const_cast<HashTable*>(mathTable));
186 fastDelete(const_cast<HashTable*>(numberTable));
187 fastDelete(const_cast<HashTable*>(regExpTable));
188 fastDelete(const_cast<HashTable*>(regExpConstructorTable));
189 fastDelete(const_cast<HashTable*>(stringTable));
190
191 delete parser;
192 delete lexer;
193
194 deleteAllValues(opaqueJSClassData);
195
196 delete emptyList;
197
198 delete propertyNames;
199 deleteIdentifierTable(identifierTable);
200
201 delete clientData;
202}
203
204PassRefPtr<JSGlobalData> JSGlobalData::create(bool isShared)
205{
206 return adoptRef(new JSGlobalData(isShared, VPtrSet()));
207}
208
209PassRefPtr<JSGlobalData> JSGlobalData::createLeaked()
210{
211 Structure::startIgnoringLeaks();
212 RefPtr<JSGlobalData> data = create();
213 Structure::stopIgnoringLeaks();
214 return data.release();
215}
216
217bool JSGlobalData::sharedInstanceExists()
218{
219 return sharedInstanceInternal();
220}
221
222JSGlobalData& JSGlobalData::sharedInstance()
223{
224 JSGlobalData*& instance = sharedInstanceInternal();
225 if (!instance) {
226 instance = create(true).releaseRef();
227#if ENABLE(JSC_MULTIPLE_THREADS)
228 instance->makeUsableFromMultipleThreads();
229#endif
230 }
231 return *instance;
232}
233
234JSGlobalData*& JSGlobalData::sharedInstanceInternal()
235{
236 ASSERT(JSLock::currentThreadIsHoldingLock());
237 static JSGlobalData* sharedInstance;
238 return sharedInstance;
239}
240
241// FIXME: We can also detect forms like v1 < v2 ? -1 : 0, reverse comparison, etc.
242const Vector<Instruction>& JSGlobalData::numericCompareFunction(ExecState* exec)
243{
244 if (!lazyNumericCompareFunction.size() && !initializingLazyNumericCompareFunction) {
245 initializingLazyNumericCompareFunction = true;
246 RefPtr<FunctionExecutable> function = FunctionExecutable::fromGlobalCode(Identifier(exec, "numericCompare"), exec, 0, makeSource(UString("(function (v1, v2) { return v1 - v2; })")), 0, 0);
247 lazyNumericCompareFunction = function->bytecode(exec, exec->scopeChain()).instructions();
248 initializingLazyNumericCompareFunction = false;
249 }
250
251 return lazyNumericCompareFunction;
252}
253
254JSGlobalData::ClientData::~ClientData()
255{
256}
257
258void JSGlobalData::resetDateCache()
259{
260 cachedUTCOffset = NaN;
261 dstOffsetCache.reset();
262 cachedDateString = UString();
263 dateInstanceCache.reset();
264}
265
266void JSGlobalData::startSampling()
267{
268 interpreter->startSampling();
269}
270
271void JSGlobalData::stopSampling()
272{
273 interpreter->stopSampling();
274}
275
276void JSGlobalData::dumpSampleData(ExecState* exec)
277{
278 interpreter->dumpSampleData(exec);
279}
280
281} // namespace JSC
Note: See TracBrowser for help on using the repository browser.