Chromium Code Reviews| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef V8PerIsolateData_h | 26 #ifndef V8PerIsolateData_h |
| 27 #define V8PerIsolateData_h | 27 #define V8PerIsolateData_h |
| 28 | 28 |
| 29 #include <v8.h> | |
| 30 #include <memory> | |
| 29 #include "bindings/core/v8/ScopedPersistent.h" | 31 #include "bindings/core/v8/ScopedPersistent.h" |
| 30 #include "bindings/core/v8/ScriptState.h" | 32 #include "bindings/core/v8/ScriptState.h" |
| 31 #include "bindings/core/v8/ScriptWrappableVisitor.h" | 33 #include "bindings/core/v8/ScriptWrappableVisitor.h" |
| 32 #include "bindings/core/v8/V8HiddenValue.h" | 34 #include "bindings/core/v8/V8HiddenValue.h" |
| 33 #include "bindings/core/v8/WrapperTypeInfo.h" | 35 #include "bindings/core/v8/WrapperTypeInfo.h" |
| 34 #include "core/CoreExport.h" | 36 #include "core/CoreExport.h" |
| 35 #include "gin/public/isolate_holder.h" | 37 #include "gin/public/isolate_holder.h" |
| 36 #include "gin/public/v8_idle_task_runner.h" | 38 #include "gin/public/v8_idle_task_runner.h" |
| 37 #include "platform/heap/Handle.h" | 39 #include "platform/heap/Handle.h" |
| 38 #include "wtf/HashMap.h" | 40 #include "wtf/HashMap.h" |
| 39 #include "wtf/Noncopyable.h" | 41 #include "wtf/Noncopyable.h" |
| 40 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 41 #include <memory> | |
| 42 #include <v8.h> | |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 class ActiveScriptWrappableBase; | 46 class ActiveScriptWrappableBase; |
| 47 class DOMDataStore; | 47 class DOMDataStore; |
| 48 class StringCache; | 48 class StringCache; |
| 49 class ThreadDebugger; | |
| 50 class V8PrivateProperty; | 49 class V8PrivateProperty; |
| 51 class WebTaskRunner; | 50 class WebTaskRunner; |
| 52 struct WrapperTypeInfo; | 51 struct WrapperTypeInfo; |
| 53 | 52 |
| 54 typedef WTF::Vector<DOMDataStore*> DOMDataStoreList; | 53 typedef WTF::Vector<DOMDataStore*> DOMDataStoreList; |
| 55 | 54 |
| 56 class CORE_EXPORT V8PerIsolateData { | 55 class CORE_EXPORT V8PerIsolateData { |
| 57 USING_FAST_MALLOC(V8PerIsolateData); | 56 USING_FAST_MALLOC(V8PerIsolateData); |
| 58 WTF_MAKE_NONCOPYABLE(V8PerIsolateData); | 57 WTF_MAKE_NONCOPYABLE(V8PerIsolateData); |
| 59 | 58 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 83 } | 82 } |
| 84 ~UseCounterDisabledScope() { | 83 ~UseCounterDisabledScope() { |
| 85 m_perIsolateData->m_useCounterDisabled = m_originalUseCounterDisabled; | 84 m_perIsolateData->m_useCounterDisabled = m_originalUseCounterDisabled; |
| 86 } | 85 } |
| 87 | 86 |
| 88 private: | 87 private: |
| 89 V8PerIsolateData* m_perIsolateData; | 88 V8PerIsolateData* m_perIsolateData; |
| 90 const bool m_originalUseCounterDisabled; | 89 const bool m_originalUseCounterDisabled; |
| 91 }; | 90 }; |
| 92 | 91 |
| 92 // Use this class to abstract away types of members that are pointers to core/ | |
| 93 // objects, which are simply owned and released by V8PerIsolateData (see | |
| 94 // m_threadDebugger for an example). | |
| 95 class CORE_EXPORT Data { | |
| 96 public: | |
| 97 virtual ~Data() = default; | |
| 98 }; | |
| 99 | |
| 93 static v8::Isolate* initialize(WebTaskRunner*); | 100 static v8::Isolate* initialize(WebTaskRunner*); |
| 94 | 101 |
| 95 static V8PerIsolateData* from(v8::Isolate* isolate) { | 102 static V8PerIsolateData* from(v8::Isolate* isolate) { |
| 96 ASSERT(isolate); | 103 ASSERT(isolate); |
| 97 ASSERT(isolate->GetData(gin::kEmbedderBlink)); | 104 ASSERT(isolate->GetData(gin::kEmbedderBlink)); |
| 98 return static_cast<V8PerIsolateData*>( | 105 return static_cast<V8PerIsolateData*>( |
| 99 isolate->GetData(gin::kEmbedderBlink)); | 106 isolate->GetData(gin::kEmbedderBlink)); |
| 100 } | 107 } |
| 101 | 108 |
| 102 static void willBeDestroyed(v8::Isolate*); | 109 static void willBeDestroyed(v8::Isolate*); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 void clearScriptRegexpContext(); | 159 void clearScriptRegexpContext(); |
| 153 | 160 |
| 154 // EndOfScopeTasks are run when control is returning | 161 // EndOfScopeTasks are run when control is returning |
| 155 // to C++ from script, after executing a script task (e.g. callback, | 162 // to C++ from script, after executing a script task (e.g. callback, |
| 156 // event) or microtasks (e.g. promise). This is explicitly needed for | 163 // event) or microtasks (e.g. promise). This is explicitly needed for |
| 157 // Indexed DB transactions per spec, but should in general be avoided. | 164 // Indexed DB transactions per spec, but should in general be avoided. |
| 158 void addEndOfScopeTask(std::unique_ptr<EndOfScopeTask>); | 165 void addEndOfScopeTask(std::unique_ptr<EndOfScopeTask>); |
| 159 void runEndOfScopeTasks(); | 166 void runEndOfScopeTasks(); |
| 160 void clearEndOfScopeTasks(); | 167 void clearEndOfScopeTasks(); |
| 161 | 168 |
| 162 void setThreadDebugger(std::unique_ptr<ThreadDebugger>); | 169 void setThreadDebugger(std::unique_ptr<Data>); |
| 163 ThreadDebugger* threadDebugger(); | 170 Data* threadDebugger(); |
|
dgozman
2017/02/18 06:11:36
Sorry for coming late, but I'm curios what are we
adithyas
2017/02/21 15:43:04
You are correct, the current solution simply remov
| |
| 164 | 171 |
| 165 using ActiveScriptWrappableSet = | 172 using ActiveScriptWrappableSet = |
| 166 HeapHashSet<WeakMember<ActiveScriptWrappableBase>>; | 173 HeapHashSet<WeakMember<ActiveScriptWrappableBase>>; |
| 167 void addActiveScriptWrappable(ActiveScriptWrappableBase*); | 174 void addActiveScriptWrappable(ActiveScriptWrappableBase*); |
| 168 const ActiveScriptWrappableSet* activeScriptWrappables() const { | 175 const ActiveScriptWrappableSet* activeScriptWrappables() const { |
| 169 return m_activeScriptWrappables.get(); | 176 return m_activeScriptWrappables.get(); |
| 170 } | 177 } |
| 171 | 178 |
| 172 class TemporaryScriptWrappableVisitorScope { | 179 class TemporaryScriptWrappableVisitorScope { |
| 173 WTF_MAKE_NONCOPYABLE(TemporaryScriptWrappableVisitorScope); | 180 WTF_MAKE_NONCOPYABLE(TemporaryScriptWrappableVisitorScope); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 bool m_constructorMode; | 246 bool m_constructorMode; |
| 240 friend class ConstructorMode; | 247 friend class ConstructorMode; |
| 241 | 248 |
| 242 bool m_useCounterDisabled; | 249 bool m_useCounterDisabled; |
| 243 friend class UseCounterDisabledScope; | 250 friend class UseCounterDisabledScope; |
| 244 | 251 |
| 245 bool m_isHandlingRecursionLevelError; | 252 bool m_isHandlingRecursionLevelError; |
| 246 bool m_isReportingException; | 253 bool m_isReportingException; |
| 247 | 254 |
| 248 Vector<std::unique_ptr<EndOfScopeTask>> m_endOfScopeTasks; | 255 Vector<std::unique_ptr<EndOfScopeTask>> m_endOfScopeTasks; |
| 249 std::unique_ptr<ThreadDebugger> m_threadDebugger; | 256 std::unique_ptr<Data> m_threadDebugger; |
| 250 | 257 |
| 251 Persistent<ActiveScriptWrappableSet> m_activeScriptWrappables; | 258 Persistent<ActiveScriptWrappableSet> m_activeScriptWrappables; |
| 252 std::unique_ptr<ScriptWrappableVisitor> m_scriptWrappableVisitor; | 259 std::unique_ptr<ScriptWrappableVisitor> m_scriptWrappableVisitor; |
| 253 }; | 260 }; |
| 254 | 261 |
| 255 } // namespace blink | 262 } // namespace blink |
| 256 | 263 |
| 257 #endif // V8PerIsolateData_h | 264 #endif // V8PerIsolateData_h |
| OLD | NEW |