OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 12 matching lines...) Expand all Loading... |
23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "bindings/core/v8/V8PerIsolateData.h" | 26 #include "bindings/core/v8/V8PerIsolateData.h" |
27 | 27 |
28 #include "bindings/core/v8/DOMDataStore.h" | 28 #include "bindings/core/v8/DOMDataStore.h" |
29 #include "bindings/core/v8/ScriptSourceCode.h" | 29 #include "bindings/core/v8/ScriptSourceCode.h" |
30 #include "bindings/core/v8/V8Binding.h" | 30 #include "bindings/core/v8/V8Binding.h" |
31 #include "bindings/core/v8/V8HiddenValue.h" | 31 #include "bindings/core/v8/V8HiddenValue.h" |
32 #include "bindings/core/v8/V8ObjectConstructor.h" | 32 #include "bindings/core/v8/V8ObjectConstructor.h" |
| 33 #include "bindings/core/v8/V8RecursionScope.h" |
33 #include "bindings/core/v8/V8ScriptRunner.h" | 34 #include "bindings/core/v8/V8ScriptRunner.h" |
34 #include "core/frame/Deprecation.h" | 35 #include "core/frame/Deprecation.h" |
35 #include "core/inspector/MainThreadDebugger.h" | 36 #include "core/inspector/MainThreadDebugger.h" |
36 #include "platform/ScriptForbiddenScope.h" | 37 #include "platform/ScriptForbiddenScope.h" |
37 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
38 #include "wtf/LeakAnnotations.h" | 39 #include "wtf/LeakAnnotations.h" |
39 #include "wtf/MainThread.h" | 40 #include "wtf/MainThread.h" |
40 | 41 |
41 namespace blink { | 42 namespace blink { |
42 | 43 |
43 static V8PerIsolateData* mainThreadPerIsolateData = 0; | 44 static V8PerIsolateData* mainThreadPerIsolateData = 0; |
44 | 45 |
45 static void beforeCallEnteredCallback(v8::Isolate* isolate) | 46 static void beforeCallEnteredCallback(v8::Isolate* isolate) |
46 { | 47 { |
47 RELEASE_ASSERT(!ScriptForbiddenScope::isScriptForbidden()); | 48 RELEASE_ASSERT(!ScriptForbiddenScope::isScriptForbidden()); |
48 } | 49 } |
49 | 50 |
50 static void microtasksCompletedCallback(v8::Isolate* isolate) | 51 static void microtasksCompletedCallback(v8::Isolate* isolate) |
51 { | 52 { |
52 V8PerIsolateData::from(isolate)->runEndOfScopeTasks(); | 53 V8PerIsolateData::from(isolate)->runEndOfScopeTasks(); |
53 } | 54 } |
54 | 55 |
| 56 #if ENABLE(ASSERT) |
| 57 static void assertV8RecursionScope(v8::Isolate* isolate) |
| 58 { |
| 59 ASSERT(V8RecursionScope::properlyUsed(isolate)); |
| 60 } |
| 61 |
| 62 static bool runningUnitTest() |
| 63 { |
| 64 return Platform::current()->unitTestSupport(); |
| 65 } |
| 66 #endif |
| 67 |
55 static void useCounterCallback(v8::Isolate* isolate, v8::Isolate::UseCounterFeat
ure feature) | 68 static void useCounterCallback(v8::Isolate* isolate, v8::Isolate::UseCounterFeat
ure feature) |
56 { | 69 { |
57 UseCounter::Feature blinkFeature; | 70 UseCounter::Feature blinkFeature; |
58 bool deprecated = false; | 71 bool deprecated = false; |
59 switch (feature) { | 72 switch (feature) { |
60 case v8::Isolate::kUseAsm: | 73 case v8::Isolate::kUseAsm: |
61 blinkFeature = UseCounter::UseAsm; | 74 blinkFeature = UseCounter::UseAsm; |
62 break; | 75 break; |
63 case v8::Isolate::kBreakIterator: | 76 case v8::Isolate::kBreakIterator: |
64 blinkFeature = UseCounter::BreakIterator; | 77 blinkFeature = UseCounter::BreakIterator; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // does not know about. It's harmless. | 136 // does not know about. It's harmless. |
124 return; | 137 return; |
125 } | 138 } |
126 if (deprecated) | 139 if (deprecated) |
127 Deprecation::countDeprecation(currentExecutionContext(isolate), blinkFea
ture); | 140 Deprecation::countDeprecation(currentExecutionContext(isolate), blinkFea
ture); |
128 else | 141 else |
129 UseCounter::count(currentExecutionContext(isolate), blinkFeature); | 142 UseCounter::count(currentExecutionContext(isolate), blinkFeature); |
130 } | 143 } |
131 | 144 |
132 V8PerIsolateData::V8PerIsolateData() | 145 V8PerIsolateData::V8PerIsolateData() |
133 : m_isolateHolder(adoptPtr(new gin::IsolateHolder())) | 146 : m_destructionPending(false) |
| 147 , m_isolateHolder(adoptPtr(new gin::IsolateHolder())) |
134 , m_stringCache(adoptPtr(new StringCache(isolate()))) | 148 , m_stringCache(adoptPtr(new StringCache(isolate()))) |
135 , m_hiddenValue(V8HiddenValue::create()) | 149 , m_hiddenValue(V8HiddenValue::create()) |
136 , m_constructorMode(ConstructorMode::CreateNewObject) | 150 , m_constructorMode(ConstructorMode::CreateNewObject) |
| 151 , m_recursionLevel(0) |
137 , m_isHandlingRecursionLevelError(false) | 152 , m_isHandlingRecursionLevelError(false) |
138 , m_isReportingException(false) | 153 , m_isReportingException(false) |
| 154 #if ENABLE(ASSERT) |
| 155 , m_internalScriptRecursionLevel(0) |
| 156 #endif |
| 157 , m_performingMicrotaskCheckpoint(false) |
139 { | 158 { |
140 // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone. | 159 // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone. |
141 isolate()->Enter(); | 160 isolate()->Enter(); |
| 161 #if ENABLE(ASSERT) |
| 162 if (!runningUnitTest()) |
| 163 isolate()->AddCallCompletedCallback(&assertV8RecursionScope); |
| 164 #endif |
142 isolate()->AddBeforeCallEnteredCallback(&beforeCallEnteredCallback); | 165 isolate()->AddBeforeCallEnteredCallback(&beforeCallEnteredCallback); |
143 isolate()->AddMicrotasksCompletedCallback(µtasksCompletedCallback); | 166 isolate()->AddMicrotasksCompletedCallback(µtasksCompletedCallback); |
144 if (isMainThread()) | 167 if (isMainThread()) |
145 mainThreadPerIsolateData = this; | 168 mainThreadPerIsolateData = this; |
146 isolate()->SetUseCounterCallback(&useCounterCallback); | 169 isolate()->SetUseCounterCallback(&useCounterCallback); |
147 } | 170 } |
148 | 171 |
149 V8PerIsolateData::~V8PerIsolateData() | 172 V8PerIsolateData::~V8PerIsolateData() |
150 { | 173 { |
151 } | 174 } |
(...skipping 24 matching lines...) Expand all Loading... |
176 m_liveRoot.set(isolate(), v8::Null(isolate())); | 199 m_liveRoot.set(isolate(), v8::Null(isolate())); |
177 return m_liveRoot.getUnsafe(); | 200 return m_liveRoot.getUnsafe(); |
178 } | 201 } |
179 | 202 |
180 // willBeDestroyed() clear things that should be cleared before | 203 // willBeDestroyed() clear things that should be cleared before |
181 // ThreadState::detach() gets called. | 204 // ThreadState::detach() gets called. |
182 void V8PerIsolateData::willBeDestroyed(v8::Isolate* isolate) | 205 void V8PerIsolateData::willBeDestroyed(v8::Isolate* isolate) |
183 { | 206 { |
184 V8PerIsolateData* data = from(isolate); | 207 V8PerIsolateData* data = from(isolate); |
185 | 208 |
| 209 ASSERT(!data->m_destructionPending); |
| 210 data->m_destructionPending = true; |
| 211 |
186 data->m_threadDebugger.clear(); | 212 data->m_threadDebugger.clear(); |
187 // Clear any data that may have handles into the heap, | 213 // Clear any data that may have handles into the heap, |
188 // prior to calling ThreadState::detach(). | 214 // prior to calling ThreadState::detach(). |
189 data->clearEndOfScopeTasks(); | 215 data->clearEndOfScopeTasks(); |
190 } | 216 } |
191 | 217 |
192 // destroy() clear things that should be cleared after ThreadState::detach() | 218 // destroy() clear things that should be cleared after ThreadState::detach() |
193 // gets called but before the Isolate exits. | 219 // gets called but before the Isolate exits. |
194 void V8PerIsolateData::destroy(v8::Isolate* isolate) | 220 void V8PerIsolateData::destroy(v8::Isolate* isolate) |
195 { | 221 { |
| 222 #if ENABLE(ASSERT) |
| 223 if (!runningUnitTest()) |
| 224 isolate->RemoveCallCompletedCallback(&assertV8RecursionScope); |
| 225 #endif |
196 isolate->RemoveBeforeCallEnteredCallback(&beforeCallEnteredCallback); | 226 isolate->RemoveBeforeCallEnteredCallback(&beforeCallEnteredCallback); |
197 isolate->RemoveMicrotasksCompletedCallback(µtasksCompletedCallback); | 227 isolate->RemoveMicrotasksCompletedCallback(µtasksCompletedCallback); |
198 V8PerIsolateData* data = from(isolate); | 228 V8PerIsolateData* data = from(isolate); |
199 | 229 |
200 // Clear everything before exiting the Isolate. | 230 // Clear everything before exiting the Isolate. |
201 if (data->m_scriptRegexpScriptState) | 231 if (data->m_scriptRegexpScriptState) |
202 data->m_scriptRegexpScriptState->disposePerContextData(); | 232 data->m_scriptRegexpScriptState->disposePerContextData(); |
203 data->m_liveRoot.clear(); | 233 data->m_liveRoot.clear(); |
204 data->m_hiddenValue.clear(); | 234 data->m_hiddenValue.clear(); |
205 data->m_stringCache->dispose(); | 235 data->m_stringCache->dispose(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 ASSERT(!m_threadDebugger); | 352 ASSERT(!m_threadDebugger); |
323 m_threadDebugger = std::move(threadDebugger); | 353 m_threadDebugger = std::move(threadDebugger); |
324 } | 354 } |
325 | 355 |
326 ThreadDebugger* V8PerIsolateData::threadDebugger() | 356 ThreadDebugger* V8PerIsolateData::threadDebugger() |
327 { | 357 { |
328 return m_threadDebugger.get(); | 358 return m_threadDebugger.get(); |
329 } | 359 } |
330 | 360 |
331 } // namespace blink | 361 } // namespace blink |
OLD | NEW |