| 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 25 matching lines...) Expand all Loading... |
| 36 #include "wtf/OwnPtr.h" | 36 #include "wtf/OwnPtr.h" |
| 37 #include "wtf/ThreadingPrimitives.h" | 37 #include "wtf/ThreadingPrimitives.h" |
| 38 #include "wtf/text/TextPosition.h" | 38 #include "wtf/text/TextPosition.h" |
| 39 #include <v8.h> | 39 #include <v8.h> |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 class ErrorEvent; | 43 class ErrorEvent; |
| 44 class ExceptionState; | 44 class ExceptionState; |
| 45 class ScriptSourceCode; | 45 class ScriptSourceCode; |
| 46 class ScriptValue; | |
| 47 class WorkerGlobalScope; | 46 class WorkerGlobalScope; |
| 48 class WorkerGlobalScopeExecutionState; | |
| 49 | 47 |
| 50 class WorkerScriptController { | 48 class WorkerScriptController { |
| 51 public: | 49 public: |
| 52 explicit WorkerScriptController(WorkerGlobalScope&); | 50 explicit WorkerScriptController(WorkerGlobalScope&); |
| 53 ~WorkerScriptController(); | 51 ~WorkerScriptController(); |
| 54 | 52 |
| 55 WorkerGlobalScope& workerGlobalScope() { return m_workerGlobalScope; } | 53 bool isExecutionForbidden() const; |
| 56 | 54 bool isExecutionTerminating() const; |
| 57 bool initializeContextIfNeeded(); | |
| 58 | |
| 59 void evaluate(const ScriptSourceCode&, RefPtrWillBeRawPtr<ErrorEvent>* = 0); | 55 void evaluate(const ScriptSourceCode&, RefPtrWillBeRawPtr<ErrorEvent>* = 0); |
| 60 | 56 |
| 57 // Prevents future JavaScript execution. See |
| 58 // scheduleExecutionTermination, isExecutionForbidden. |
| 59 void forbidExecution(); |
| 60 |
| 61 // Used by WorkerThread: |
| 62 bool initializeContextIfNeeded(); |
| 63 // Async request to terminate future JavaScript execution on the |
| 64 // worker thread. JavaScript evaluation exits with a |
| 65 // non-continuable exception and WorkerScriptController calls |
| 66 // forbidExecution to prevent further JavaScript execution. Use |
| 67 // forbidExecution()/isExecutionForbidden() to guard against |
| 68 // reentry into JavaScript. |
| 69 void scheduleExecutionTermination(); |
| 70 |
| 71 // Used by WorkerGlobalScope: |
| 61 void rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent>,
ExceptionState&); | 72 void rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent>,
ExceptionState&); |
| 62 | |
| 63 // Async request to terminate a future JS execution. Eventually causes termi
nation | |
| 64 // exception raised during JS execution, if the worker thread happens to run
JS. | |
| 65 // After JS execution was terminated in this way, the Worker thread has to u
se | |
| 66 // forbidExecution()/isExecutionForbidden() to guard against reentry into JS
. | |
| 67 // Can be called from any thread. | |
| 68 void scheduleExecutionTermination(); | |
| 69 bool isExecutionTerminating() const; | |
| 70 | |
| 71 // Called on Worker thread when JS exits with termination exception caused b
y forbidExecution() request, | |
| 72 // or by Worker thread termination code to prevent future entry into JS. | |
| 73 void forbidExecution(); | |
| 74 bool isExecutionForbidden() const; | |
| 75 | |
| 76 void disableEval(const String&); | 73 void disableEval(const String&); |
| 77 | |
| 78 v8::Isolate* isolate() const { return m_isolate; } | |
| 79 DOMWrapperWorld& world() const { return *m_world; } | |
| 80 ScriptState* scriptState() { return m_scriptState.get(); } | |
| 81 v8::Local<v8::Context> context() { return m_scriptState ? m_scriptState->con
text() : v8::Local<v8::Context>(); } | |
| 82 bool isContextInitialized() { return m_scriptState && !!m_scriptState->perCo
ntextData(); } | |
| 83 | |
| 84 // Send a notification about current thread is going to be idle. | 74 // Send a notification about current thread is going to be idle. |
| 85 // Returns true if the embedder should stop calling idleNotification | 75 // Returns true if the embedder should stop calling idleNotification |
| 86 // until real work has been done. | 76 // until real work has been done. |
| 87 bool idleNotification() { return m_isolate->IdleNotification(1000); } | 77 bool idleNotification() { return m_isolate->IdleNotification(1000); } |
| 88 | 78 |
| 79 // Used by Inspector agents: |
| 80 ScriptState* scriptState() { return m_scriptState.get(); } |
| 81 |
| 82 // Used by V8 bindings: |
| 83 v8::Local<v8::Context> context() { return m_scriptState ? m_scriptState->con
text() : v8::Local<v8::Context>(); } |
| 84 |
| 89 private: | 85 private: |
| 90 class WorkerGlobalScopeExecutionState; | 86 class WorkerGlobalScopeExecutionState; |
| 91 | 87 |
| 88 bool isContextInitialized() { return m_scriptState && !!m_scriptState->perCo
ntextData(); } |
| 89 |
| 92 // Evaluate a script file in the current execution environment. | 90 // Evaluate a script file in the current execution environment. |
| 93 ScriptValue evaluate(const String& script, const String& fileName, const Tex
tPosition& scriptStartPosition); | 91 ScriptValue evaluate(const String& script, const String& fileName, const Tex
tPosition& scriptStartPosition); |
| 94 | 92 |
| 95 v8::Isolate* m_isolate; | 93 v8::Isolate* m_isolate; |
| 96 WorkerGlobalScope& m_workerGlobalScope; | 94 WorkerGlobalScope& m_workerGlobalScope; |
| 97 RefPtr<ScriptState> m_scriptState; | 95 RefPtr<ScriptState> m_scriptState; |
| 98 RefPtr<DOMWrapperWorld> m_world; | 96 RefPtr<DOMWrapperWorld> m_world; |
| 99 String m_disableEvalPending; | 97 String m_disableEvalPending; |
| 100 bool m_executionForbidden; | 98 bool m_executionForbidden; |
| 101 bool m_executionScheduledToTerminate; | 99 bool m_executionScheduledToTerminate; |
| 102 mutable Mutex m_scheduledTerminationMutex; | 100 mutable Mutex m_scheduledTerminationMutex; |
| 103 | 101 |
| 104 // |m_globalScopeExecutionState| refers to a stack object | 102 // |m_globalScopeExecutionState| refers to a stack object |
| 105 // that evaluate() allocates; evaluate() ensuring that the | 103 // that evaluate() allocates; evaluate() ensuring that the |
| 106 // pointer reference to it is removed upon returning. Hence | 104 // pointer reference to it is removed upon returning. Hence |
| 107 // kept as a bare pointer here, and not a Persistent with | 105 // kept as a bare pointer here, and not a Persistent with |
| 108 // Oilpan enabled; stack scanning will visit the object and | 106 // Oilpan enabled; stack scanning will visit the object and |
| 109 // trace its on-heap fields. | 107 // trace its on-heap fields. |
| 110 GC_PLUGIN_IGNORE("394615") | 108 GC_PLUGIN_IGNORE("394615") |
| 111 WorkerGlobalScopeExecutionState* m_globalScopeExecutionState; | 109 WorkerGlobalScopeExecutionState* m_globalScopeExecutionState; |
| 112 OwnPtr<V8IsolateInterruptor> m_interruptor; | 110 OwnPtr<V8IsolateInterruptor> m_interruptor; |
| 113 }; | 111 }; |
| 114 | 112 |
| 115 } // namespace blink | 113 } // namespace blink |
| 116 | 114 |
| 117 #endif // WorkerScriptController_h | 115 #endif // WorkerScriptController_h |
| OLD | NEW |