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