OLD | NEW |
---|---|
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 Loading... | |
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 IsolatedScriptController_h |
32 #define WorkerScriptController_h | 32 #define IsolatedScriptController_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 ExecutionContext; | |
49 class ExceptionState; | 50 class ExceptionState; |
50 class ScriptSourceCode; | 51 class ScriptSourceCode; |
51 class WorkerGlobalScope; | 52 class ScriptWrappable; |
52 | 53 |
53 class CORE_EXPORT WorkerScriptController : public NoBaseWillBeGarbageCollectedFi nalized<WorkerScriptController> { | 54 class CORE_EXPORT IsolatedScriptController : public NoBaseWillBeGarbageCollected Finalized<IsolatedScriptController> { |
kinuko
2016/01/05 04:58:32
Now that the class name is less obvious we should
| |
54 USING_FAST_MALLOC_WILL_BE_REMOVED(WorkerScriptController); | 55 USING_FAST_MALLOC_WILL_BE_REMOVED(IsolatedScriptController); |
55 WTF_MAKE_NONCOPYABLE(WorkerScriptController); | 56 WTF_MAKE_NONCOPYABLE(IsolatedScriptController); |
56 public: | 57 public: |
57 static PassOwnPtrWillBeRawPtr<WorkerScriptController> create(WorkerGlobalSco pe*, v8::Isolate*); | 58 static PassOwnPtrWillBeRawPtr<IsolatedScriptController> create(ExecutionCont ext*, ScriptWrappable*, v8::Isolate*); |
58 virtual ~WorkerScriptController(); | 59 virtual ~IsolatedScriptController(); |
59 void dispose(); | 60 void dispose(); |
60 | 61 |
61 bool isExecutionForbidden() const; | 62 bool isExecutionForbidden() const; |
62 bool isExecutionTerminating() const; | 63 bool isExecutionTerminating() const; |
63 | 64 |
64 // Returns true if the evaluation completed with no uncaught exception. | 65 // Returns true if the evaluation completed with no uncaught exception. |
65 bool evaluate(const ScriptSourceCode&, RefPtrWillBeRawPtr<ErrorEvent>* = nul lptr, CachedMetadataHandler* = nullptr, V8CacheOptions = V8CacheOptionsDefault); | 66 bool evaluate(const ScriptSourceCode&, RefPtrWillBeRawPtr<ErrorEvent>* = nul lptr, CachedMetadataHandler* = nullptr, V8CacheOptions = V8CacheOptionsDefault); |
66 | 67 |
67 // Prevents future JavaScript execution. See | 68 // Prevents future JavaScript execution. See |
68 // willScheduleExecutionTermination, isExecutionForbidden. | 69 // willScheduleExecutionTermination, isExecutionForbidden. |
69 void forbidExecution(); | 70 void forbidExecution(); |
70 | 71 |
71 // Used by WorkerThread: | 72 // Used by WorkerThread: |
72 bool initializeContextIfNeeded(); | 73 bool initializeContextIfNeeded(); |
73 // Async request to terminate future JavaScript execution on the | 74 // Async request to terminate future JavaScript execution on the |
74 // worker thread. JavaScript evaluation exits with a | 75 // worker thread. JavaScript evaluation exits with a |
75 // non-continuable exception and WorkerScriptController calls | 76 // non-continuable exception and IsolatedScriptController calls |
76 // forbidExecution to prevent further JavaScript execution. Use | 77 // forbidExecution to prevent further JavaScript execution. Use |
77 // forbidExecution()/isExecutionForbidden() to guard against | 78 // forbidExecution()/isExecutionForbidden() to guard against |
78 // reentry into JavaScript. | 79 // reentry into JavaScript. |
79 void willScheduleExecutionTermination(); | 80 void willScheduleExecutionTermination(); |
80 | 81 |
81 // Used by WorkerGlobalScope: | 82 // Used by WorkerGlobalScope: |
82 void rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent>, ExceptionState&); | 83 void rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent>, ExceptionState&); |
83 void disableEval(const String&); | 84 void disableEval(const String&); |
84 | 85 |
85 // Used by Inspector agents: | 86 // Used by Inspector agents: |
86 ScriptState* scriptState() { return m_scriptState.get(); } | 87 ScriptState* scriptState() { return m_scriptState.get(); } |
87 | 88 |
88 // Used by V8 bindings: | 89 // Used by V8 bindings: |
89 v8::Local<v8::Context> context() { return m_scriptState ? m_scriptState->con text() : v8::Local<v8::Context>(); } | 90 v8::Local<v8::Context> context() { return m_scriptState ? m_scriptState->con text() : v8::Local<v8::Context>(); } |
90 | 91 |
91 RejectedPromises* rejectedPromises() const { return m_rejectedPromises.get() ; } | 92 RejectedPromises* rejectedPromises() const { return m_rejectedPromises.get() ; } |
92 | 93 |
93 DECLARE_TRACE(); | 94 DECLARE_TRACE(); |
94 | 95 |
95 bool isContextInitialized() const { return m_scriptState && !!m_scriptState- >perContextData(); } | 96 bool isContextInitialized() const { return m_scriptState && !!m_scriptState- >perContextData(); } |
96 | 97 |
97 private: | 98 private: |
98 WorkerScriptController(WorkerGlobalScope*, v8::Isolate*); | 99 IsolatedScriptController(ExecutionContext*, ScriptWrappable*, v8::Isolate*); |
99 class ExecutionState; | 100 class ExecutionState; |
100 | 101 |
101 v8::Isolate* isolate() const; | |
102 | |
103 // Evaluate a script file in the current execution environment. | 102 // Evaluate a script file in the current execution environment. |
104 ScriptValue evaluate(const String& script, const String& fileName, const Tex tPosition& scriptStartPosition, CachedMetadataHandler*, V8CacheOptions); | 103 ScriptValue evaluate(const String& script, const String& fileName, const Tex tPosition& scriptStartPosition, CachedMetadataHandler*, V8CacheOptions); |
105 | 104 |
106 RawPtrWillBeMember<WorkerGlobalScope> m_workerGlobalScope; | 105 RawPtrWillBeMember<ExecutionContext> m_executionContext; |
106 RawPtrWillBeMember<ScriptWrappable> m_scriptWrappable; | |
107 v8::Isolate* m_isolate; | |
kinuko
2016/01/05 04:58:32
Could we have a comment for this too? Something l
ikilpatrick
2016/01/07 22:47:34
Done.
| |
108 | |
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_executionState| refers to a stack object that evaluate() allocates; | 118 // |m_executionState| refers to a stack object that evaluate() allocates; |
117 // evaluate() ensuring that the pointer reference to it is removed upon | 119 // evaluate() ensuring that the pointer reference to it is removed upon |
118 // returning. Hence kept as a bare pointer here, and not a Persistent with | 120 // returning. Hence kept as a bare pointer here, and not a Persistent with |
119 // Oilpan enabled; stack scanning will visit the object and | 121 // Oilpan enabled; stack scanning will visit the object and |
120 // trace its on-heap fields. | 122 // trace its on-heap fields. |
121 GC_PLUGIN_IGNORE("394615") | 123 GC_PLUGIN_IGNORE("394615") |
122 ExecutionState* m_executionState; | 124 ExecutionState* m_executionState; |
123 }; | 125 }; |
124 | 126 |
125 } // namespace blink | 127 } // namespace blink |
126 | 128 |
127 #endif // WorkerScriptController_h | 129 #endif // IsolatedScriptController_h |
OLD | NEW |