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

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

2009-01-09 David Levin <[email protected]>

Reviewed by Oliver Hunt.

https://bugs.webkit.org/show_bug.cgi?id=23175

Added a template to make the pointer and flags combination
in UString more readable and less error prone.

  • Property svn:eol-style set to native
File size: 5.6 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 "InitializeThreading.h"
36#include "Interpreter.h"
37#include "JSActivation.h"
38#include "JSClassRef.h"
39#include "JSLock.h"
40#include "JSNotAnObject.h"
41#include "JSStaticScopeObject.h"
42#include "Parser.h"
43#include "Lexer.h"
44#include "Lookup.h"
45#include "Nodes.h"
46
47#if ENABLE(JSC_MULTIPLE_THREADS)
48#include <wtf/Threading.h>
49#endif
50
51#if PLATFORM(MAC)
52#include "ProfilerServer.h"
53#endif
54
55using namespace WTF;
56
57namespace JSC {
58
59extern const HashTable arrayTable;
60extern const HashTable dateTable;
61extern const HashTable mathTable;
62extern const HashTable numberTable;
63extern const HashTable regExpTable;
64extern const HashTable regExpConstructorTable;
65extern const HashTable stringTable;
66
67JSGlobalData::JSGlobalData(bool isShared)
68 : interpreter(new Interpreter)
69 , exception(noValue())
70 , arrayTable(new HashTable(JSC::arrayTable))
71 , dateTable(new HashTable(JSC::dateTable))
72 , mathTable(new HashTable(JSC::mathTable))
73 , numberTable(new HashTable(JSC::numberTable))
74 , regExpTable(new HashTable(JSC::regExpTable))
75 , regExpConstructorTable(new HashTable(JSC::regExpConstructorTable))
76 , stringTable(new HashTable(JSC::stringTable))
77 , activationStructure(JSActivation::createStructure(jsNull()))
78 , interruptedExecutionErrorStructure(JSObject::createStructure(jsNull()))
79 , staticScopeStructure(JSStaticScopeObject::createStructure(jsNull()))
80 , stringStructure(JSString::createStructure(jsNull()))
81 , notAnObjectErrorStubStructure(JSNotAnObjectErrorStub::createStructure(jsNull()))
82 , notAnObjectStructure(JSNotAnObject::createStructure(jsNull()))
83 , numberStructure(JSNumberCell::createStructure(jsNull()))
84 , identifierTable(createIdentifierTable())
85 , propertyNames(new CommonIdentifiers(this))
86 , emptyList(new ArgList)
87 , newParserObjects(0)
88 , parserObjectExtraRefCounts(0)
89 , lexer(new Lexer(this))
90 , parser(new Parser)
91 , head(0)
92 , dynamicGlobalObject(0)
93 , isSharedInstance(isShared)
94 , clientData(0)
95 , heap(this)
96{
97#if PLATFORM(MAC)
98 startProfilerServerIfNeeded();
99#endif
100 interpreter->initialize(this);
101}
102
103JSGlobalData::~JSGlobalData()
104{
105 // By the time this is destroyed, heap.destroy() must already have been called.
106
107 delete interpreter;
108#ifndef NDEBUG
109 // Zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
110 interpreter = 0;
111#endif
112
113 arrayTable->deleteTable();
114 dateTable->deleteTable();
115 mathTable->deleteTable();
116 numberTable->deleteTable();
117 regExpTable->deleteTable();
118 regExpConstructorTable->deleteTable();
119 stringTable->deleteTable();
120 delete arrayTable;
121 delete dateTable;
122 delete mathTable;
123 delete numberTable;
124 delete regExpTable;
125 delete regExpConstructorTable;
126 delete stringTable;
127
128 delete parser;
129 delete lexer;
130
131 deleteAllValues(opaqueJSClassData);
132
133 delete emptyList;
134
135 delete propertyNames;
136 deleteIdentifierTable(identifierTable);
137
138 delete newParserObjects;
139 delete parserObjectExtraRefCounts;
140
141 delete clientData;
142}
143
144PassRefPtr<JSGlobalData> JSGlobalData::create()
145{
146 initializeThreading();
147 return adoptRef(new JSGlobalData);
148}
149
150PassRefPtr<JSGlobalData> JSGlobalData::createLeaked()
151{
152#ifndef NDEBUG
153 Structure::startIgnoringLeaks();
154 RefPtr<JSGlobalData> data = create();
155 Structure::stopIgnoringLeaks();
156 return data.release();
157#else
158 return create();
159#endif
160}
161
162bool JSGlobalData::sharedInstanceExists()
163{
164 return sharedInstanceInternal();
165}
166
167JSGlobalData& JSGlobalData::sharedInstance()
168{
169 JSGlobalData*& instance = sharedInstanceInternal();
170 if (!instance) {
171 instance = new JSGlobalData(true);
172#if ENABLE(JSC_MULTIPLE_THREADS)
173 instance->makeUsableFromMultipleThreads();
174#endif
175 }
176 return *instance;
177}
178
179JSGlobalData*& JSGlobalData::sharedInstanceInternal()
180{
181 ASSERT(JSLock::currentThreadIsHoldingLock());
182 static JSGlobalData* sharedInstance;
183 return sharedInstance;
184}
185
186JSGlobalData::ClientData::~ClientData()
187{
188}
189
190}
Note: See TracBrowser for help on using the repository browser.