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