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

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: remove AbstractGlobalScope. 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 CachedMetadataHandler; 47 class CachedMetadataHandler;
48 class ErrorEvent; 48 class ErrorEvent;
49 class ExceptionState; 49 class ExceptionState;
50 class ScriptSourceCode; 50 class ScriptSourceCode;
51 class WorkerGlobalScope;
52 51
53 class CORE_EXPORT WorkerScriptController : public NoBaseWillBeGarbageCollectedFi nalized<WorkerScriptController> { 52 class CORE_EXPORT GlobalScopeScriptController : public NoBaseWillBeGarbageCollec tedFinalized<GlobalScopeScriptController> {
54 USING_FAST_MALLOC_WILL_BE_REMOVED(WorkerScriptController);
55 WTF_MAKE_NONCOPYABLE(WorkerScriptController);
56 public: 53 public:
57 static PassOwnPtrWillBeRawPtr<WorkerScriptController> create(WorkerGlobalSco pe*, v8::Isolate*); 54 virtual ~GlobalScopeScriptController();
58 virtual ~WorkerScriptController();
59 void dispose(); 55 void dispose();
60 56
61 bool isExecutionForbidden() const; 57 bool isExecutionForbidden() const;
62 bool isExecutionTerminating() const; 58 bool isExecutionTerminating() const;
63 59
64 // Returns true if the evaluation completed with no uncaught exception. 60 // Returns true if the evaluation completed with no uncaught exception.
65 bool evaluate(const ScriptSourceCode&, RefPtrWillBeRawPtr<ErrorEvent>* = nul lptr, CachedMetadataHandler* = nullptr, V8CacheOptions = V8CacheOptionsDefault); 61 bool evaluate(const ScriptSourceCode&, RefPtrWillBeRawPtr<ErrorEvent>* = nul lptr, CachedMetadataHandler* = nullptr, V8CacheOptions = V8CacheOptionsDefault);
66 62
67 // Prevents future JavaScript execution. See 63 // Prevents future JavaScript execution. See
68 // willScheduleExecutionTermination, isExecutionForbidden. 64 // willScheduleExecutionTermination, isExecutionForbidden.
69 void forbidExecution(); 65 void forbidExecution();
70 66
71 // Used by WorkerThread: 67 // Used by WorkerThread:
72 bool initializeContextIfNeeded(); 68 bool initializeContextIfNeeded();
73 // Async request to terminate future JavaScript execution on the 69 // Async request to terminate future JavaScript execution on the
74 // worker thread. JavaScript evaluation exits with a 70 // worker thread. JavaScript evaluation exits with a
75 // non-continuable exception and WorkerScriptController calls 71 // non-continuable exception and GlobalScopeScriptController calls
76 // forbidExecution to prevent further JavaScript execution. Use 72 // forbidExecution to prevent further JavaScript execution. Use
77 // forbidExecution()/isExecutionForbidden() to guard against 73 // forbidExecution()/isExecutionForbidden() to guard against
78 // reentry into JavaScript. 74 // reentry into JavaScript.
79 void willScheduleExecutionTermination(); 75 void willScheduleExecutionTermination();
80 76
81 // Used by WorkerGlobalScope: 77 // Used by WorkerGlobalScope:
82 void rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent>, ExceptionState&); 78 void rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent>, ExceptionState&);
83 void disableEval(const String&); 79 void disableEval(const String&);
84 80
85 // Used by Inspector agents: 81 // Used by Inspector agents:
86 ScriptState* scriptState() { return m_scriptState.get(); } 82 ScriptState* scriptState() { return m_scriptState.get(); }
87 83
88 // Used by V8 bindings: 84 // Used by V8 bindings:
89 v8::Local<v8::Context> context() { return m_scriptState ? m_scriptState->con text() : v8::Local<v8::Context>(); } 85 v8::Local<v8::Context> context() { return m_scriptState ? m_scriptState->con text() : v8::Local<v8::Context>(); }
90 86
91 RejectedPromises* rejectedPromises() const { return m_rejectedPromises.get() ; } 87 RejectedPromises* rejectedPromises() const { return m_rejectedPromises.get() ; }
92 88
93 DECLARE_TRACE(); 89 DECLARE_VIRTUAL_TRACE();
94 90
95 bool isContextInitialized() const { return m_scriptState && !!m_scriptState- >perContextData(); } 91 bool isContextInitialized() const { return m_scriptState && !!m_scriptState- >perContextData(); }
96 92
93 protected:
94 GlobalScopeScriptController(v8::Isolate*);
95
96 virtual void didStopRunLoop() = 0;
kinuko 2015/12/24 04:45:51 (I think we can remove this from Worker*ScriptCont
ikilpatrick 2015/12/27 20:22:39 Done.
97 virtual v8::Isolate* isolate() const = 0;
kinuko 2015/12/24 04:45:51 We can just store isolate ptr given to the ctor as
ikilpatrick 2015/12/27 20:22:39 Done.
98 virtual bool isContextThread() const = 0;
kinuko 2015/12/24 04:45:51 For this, runCompiledScript, shouldSanitizedScript
ikilpatrick 2015/12/27 20:22:39 Done.
99
100 virtual const WrapperTypeInfo* wrapperTypeInfoForGlobalScope() const = 0;
101 virtual v8::Local<v8::Object> associateGlobalScopeWithWrapper(const WrapperT ypeInfo*, v8::Local<v8::Object> wrapper) = 0;
kinuko 2015/12/24 04:45:51 For these ones similarly I think we can basically
ikilpatrick 2015/12/27 20:22:39 Done.
102 virtual v8::MaybeLocal<v8::Value> runCompiledScript(v8::Local<v8::Script>) = 0;
103
104 virtual bool shouldSanitizeScriptError(const String& sourceURL, AccessContro lStatus) = 0;
105 virtual void reportException(PassRefPtrWillBeRawPtr<ErrorEvent>, int scriptI d, PassRefPtrWillBeRawPtr<ScriptCallStack>, AccessControlStatus) = 0;
106
97 private: 107 private:
98 WorkerScriptController(WorkerGlobalScope*, v8::Isolate*); 108 class ExecutionState;
99 class WorkerGlobalScopeExecutionState;
100 109
101 v8::Isolate* isolate() const;
102 110
103 // Evaluate a script file in the current execution environment. 111 // Evaluate a script file in the current execution environment.
104 ScriptValue evaluate(const String& script, const String& fileName, const Tex tPosition& scriptStartPosition, CachedMetadataHandler*, V8CacheOptions); 112 ScriptValue evaluate(const String& script, const String& fileName, const Tex tPosition& scriptStartPosition, CachedMetadataHandler*, V8CacheOptions);
105 113
106 RawPtrWillBeMember<WorkerGlobalScope> m_workerGlobalScope;
107 RefPtr<ScriptState> m_scriptState; 114 RefPtr<ScriptState> m_scriptState;
108 RefPtr<DOMWrapperWorld> m_world; 115 RefPtr<DOMWrapperWorld> m_world;
109 String m_disableEvalPending; 116 String m_disableEvalPending;
110 bool m_executionForbidden; 117 bool m_executionForbidden;
111 bool m_executionScheduledToTerminate; 118 bool m_executionScheduledToTerminate;
112 mutable Mutex m_scheduledTerminationMutex; 119 mutable Mutex m_scheduledTerminationMutex;
113 120
114 RefPtrWillBeMember<RejectedPromises> m_rejectedPromises; 121 RefPtrWillBeMember<RejectedPromises> m_rejectedPromises;
115 122
116 // |m_globalScopeExecutionState| refers to a stack object 123 // |m_executionState| refers to a stack object that evaluate() allocates;
117 // that evaluate() allocates; evaluate() ensuring that the 124 // evaluate() ensuring that the pointer reference to it is removed upon
118 // pointer reference to it is removed upon returning. Hence 125 // returning. Hence kept as a bare pointer here, and not a Persistent with
119 // kept as a bare pointer here, and not a Persistent with
120 // Oilpan enabled; stack scanning will visit the object and 126 // Oilpan enabled; stack scanning will visit the object and
121 // trace its on-heap fields. 127 // trace its on-heap fields.
122 GC_PLUGIN_IGNORE("394615") 128 GC_PLUGIN_IGNORE("394615")
123 WorkerGlobalScopeExecutionState* m_globalScopeExecutionState; 129 ExecutionState* m_executionState;
124 }; 130 };
125 131
126 } // namespace blink 132 } // namespace blink
127 133
128 #endif // WorkerScriptController_h 134 #endif // GlobalScopeScriptController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698