Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/GlobalScopeScriptController.h

Issue 1535943005: Initial implementation of bindings and basic classes for worklets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix memory leak. Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2012 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef WorkerScriptController_h 31 #ifndef GlobalScopeScriptController_h
32 #define WorkerScriptController_h 32 #define GlobalScopeScriptController_h
33 33
34 #include "bindings/core/v8/RejectedPromises.h" 34 #include "bindings/core/v8/RejectedPromises.h"
35 #include "bindings/core/v8/ScriptValue.h" 35 #include "bindings/core/v8/ScriptValue.h"
36 #include "bindings/core/v8/V8Binding.h" 36 #include "bindings/core/v8/V8Binding.h"
37 #include "bindings/core/v8/V8CacheOptions.h" 37 #include "bindings/core/v8/V8CacheOptions.h"
38 #include "core/CoreExport.h" 38 #include "core/CoreExport.h"
39 #include "wtf/Allocator.h" 39 #include "wtf/Allocator.h"
40 #include "wtf/OwnPtr.h" 40 #include "wtf/OwnPtr.h"
41 #include "wtf/ThreadingPrimitives.h" 41 #include "wtf/ThreadingPrimitives.h"
42 #include "wtf/text/TextPosition.h" 42 #include "wtf/text/TextPosition.h"
43 #include <v8.h> 43 #include <v8.h>
44 44
45 namespace blink { 45 namespace blink {
46 46
47 class AbstractGlobalScope;
47 class CachedMetadataHandler; 48 class CachedMetadataHandler;
48 class ErrorEvent; 49 class ErrorEvent;
49 class ExceptionState; 50 class ExceptionState;
50 class ScriptSourceCode; 51 class ScriptSourceCode;
51 class WorkerGlobalScope;
52 52
53 class CORE_EXPORT WorkerScriptController : public NoBaseWillBeGarbageCollectedFi nalized<WorkerScriptController> { 53 class CORE_EXPORT GlobalScopeScriptController : public NoBaseWillBeGarbageCollec tedFinalized<GlobalScopeScriptController> {
54 USING_FAST_MALLOC_WILL_BE_REMOVED(WorkerScriptController);
55 WTF_MAKE_NONCOPYABLE(WorkerScriptController);
56 public: 54 public:
57 static PassOwnPtrWillBeRawPtr<WorkerScriptController> create(WorkerGlobalSco pe*, v8::Isolate*); 55 virtual ~GlobalScopeScriptController();
58 virtual ~WorkerScriptController();
59 void dispose(); 56 void dispose();
60 57
61 bool isExecutionForbidden() const; 58 bool isExecutionForbidden() const;
62 bool isExecutionTerminating() const; 59 bool isExecutionTerminating() const;
63 60
64 // Returns true if the evaluation completed with no uncaught exception. 61 // Returns true if the evaluation completed with no uncaught exception.
65 bool evaluate(const ScriptSourceCode&, RefPtrWillBeRawPtr<ErrorEvent>* = nul lptr, CachedMetadataHandler* = nullptr, V8CacheOptions = V8CacheOptionsDefault); 62 bool evaluate(const ScriptSourceCode&, RefPtrWillBeRawPtr<ErrorEvent>* = nul lptr, CachedMetadataHandler* = nullptr, V8CacheOptions = V8CacheOptionsDefault);
66 63
67 // Prevents future JavaScript execution. See 64 // Prevents future JavaScript execution. See
68 // willScheduleExecutionTermination, isExecutionForbidden. 65 // willScheduleExecutionTermination, isExecutionForbidden.
69 void forbidExecution(); 66 void forbidExecution();
70 67
71 // Used by WorkerThread: 68 // Used by WorkerThread:
72 bool initializeContextIfNeeded(); 69 bool initializeContextIfNeeded();
73 // Async request to terminate future JavaScript execution on the 70 // Async request to terminate future JavaScript execution on the
74 // worker thread. JavaScript evaluation exits with a 71 // worker thread. JavaScript evaluation exits with a
75 // non-continuable exception and WorkerScriptController calls 72 // non-continuable exception and GlobalScopeScriptController calls
76 // forbidExecution to prevent further JavaScript execution. Use 73 // forbidExecution to prevent further JavaScript execution. Use
77 // forbidExecution()/isExecutionForbidden() to guard against 74 // forbidExecution()/isExecutionForbidden() to guard against
78 // reentry into JavaScript. 75 // reentry into JavaScript.
79 void willScheduleExecutionTermination(); 76 void willScheduleExecutionTermination();
80 77
81 // Used by WorkerGlobalScope: 78 // Used by WorkerGlobalScope:
82 void rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent>, ExceptionState&); 79 void rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent>, ExceptionState&);
83 void disableEval(const String&); 80 void disableEval(const String&);
84 81
85 // Used by Inspector agents: 82 // Used by Inspector agents:
86 ScriptState* scriptState() { return m_scriptState.get(); } 83 ScriptState* scriptState() { return m_scriptState.get(); }
87 84
88 // Used by V8 bindings: 85 // Used by V8 bindings:
89 v8::Local<v8::Context> context() { return m_scriptState ? m_scriptState->con text() : v8::Local<v8::Context>(); } 86 v8::Local<v8::Context> context() { return m_scriptState ? m_scriptState->con text() : v8::Local<v8::Context>(); }
90 87
91 RejectedPromises* rejectedPromises() const { return m_rejectedPromises.get() ; } 88 RejectedPromises* rejectedPromises() const { return m_rejectedPromises.get() ; }
92 89
93 DECLARE_TRACE(); 90 DECLARE_VIRTUAL_TRACE();
94 91
95 bool isContextInitialized() const { return m_scriptState && !!m_scriptState- >perContextData(); } 92 bool isContextInitialized() const { return m_scriptState && !!m_scriptState- >perContextData(); }
96 93
94 virtual const WrapperTypeInfo* wrapperTypeInfoForGlobalScope() const = 0;
95 virtual v8::Local<v8::Object> associateGlobalScopeWithWrapper(v8::Isolate*, const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) = 0;
96
97 protected:
98 GlobalScopeScriptController(AbstractGlobalScope*, v8::Isolate*);
99
97 private: 100 private:
98 WorkerScriptController(WorkerGlobalScope*, v8::Isolate*); 101 class GlobalScopeExecutionState;
99 class WorkerGlobalScopeExecutionState;
100 102
101 v8::Isolate* isolate() const; 103 v8::Isolate* isolate() const;
102 104
103 // Evaluate a script file in the current execution environment. 105 // Evaluate a script file in the current execution environment.
104 ScriptValue evaluate(const String& script, const String& fileName, const Tex tPosition& scriptStartPosition, CachedMetadataHandler*, V8CacheOptions); 106 ScriptValue evaluate(const String& script, const String& fileName, const Tex tPosition& scriptStartPosition, CachedMetadataHandler*, V8CacheOptions);
105 107
106 RawPtrWillBeMember<WorkerGlobalScope> m_workerGlobalScope; 108 RawPtrWillBeMember<AbstractGlobalScope> m_abstractGlobalScope;
107 RefPtr<ScriptState> m_scriptState; 109 RefPtr<ScriptState> m_scriptState;
108 RefPtr<DOMWrapperWorld> m_world; 110 RefPtr<DOMWrapperWorld> m_world;
109 String m_disableEvalPending; 111 String m_disableEvalPending;
110 bool m_executionForbidden; 112 bool m_executionForbidden;
111 bool m_executionScheduledToTerminate; 113 bool m_executionScheduledToTerminate;
112 mutable Mutex m_scheduledTerminationMutex; 114 mutable Mutex m_scheduledTerminationMutex;
113 115
114 RefPtrWillBeMember<RejectedPromises> m_rejectedPromises; 116 RefPtrWillBeMember<RejectedPromises> m_rejectedPromises;
115 117
116 // |m_globalScopeExecutionState| refers to a stack object 118 // |m_globalScopeExecutionState| refers to a stack object
117 // that evaluate() allocates; evaluate() ensuring that the 119 // that evaluate() allocates; evaluate() ensuring that the
118 // pointer reference to it is removed upon returning. Hence 120 // pointer reference to it is removed upon returning. Hence
119 // kept as a bare pointer here, and not a Persistent with 121 // kept as a bare pointer here, and not a Persistent with
120 // Oilpan enabled; stack scanning will visit the object and 122 // Oilpan enabled; stack scanning will visit the object and
121 // trace its on-heap fields. 123 // trace its on-heap fields.
122 GC_PLUGIN_IGNORE("394615") 124 GC_PLUGIN_IGNORE("394615")
123 WorkerGlobalScopeExecutionState* m_globalScopeExecutionState; 125 GlobalScopeExecutionState* m_globalScopeExecutionState;
kinuko 2015/12/22 08:39:03 nit: given that this is an inner class the class n
ikilpatrick 2015/12/22 23:40:23 Renamed to just ExecutionState which seems ok?
124 }; 126 };
125 127
126 } // namespace blink 128 } // namespace blink
127 129
128 #endif // WorkerScriptController_h 130 #endif // GlobalScopeScriptController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698