| 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 24 matching lines...) Expand all Loading... |
| 35 #include "bindings/v8/V8Binding.h" | 35 #include "bindings/v8/V8Binding.h" |
| 36 #include <v8.h> | 36 #include <v8.h> |
| 37 #include "wtf/OwnPtr.h" | 37 #include "wtf/OwnPtr.h" |
| 38 #include "wtf/Threading.h" | 38 #include "wtf/Threading.h" |
| 39 #include "wtf/text/TextPosition.h" | 39 #include "wtf/text/TextPosition.h" |
| 40 | 40 |
| 41 namespace WebCore { | 41 namespace WebCore { |
| 42 | 42 |
| 43 class ScriptSourceCode; | 43 class ScriptSourceCode; |
| 44 class ScriptValue; | 44 class ScriptValue; |
| 45 class WorkerContext; | 45 class WorkerGlobalScope; |
| 46 | 46 |
| 47 struct WorkerContextExecutionState { | 47 struct WorkerGlobalScopeExecutionState { |
| 48 WorkerContextExecutionState() | 48 WorkerGlobalScopeExecutionState() |
| 49 : hadException(false) | 49 : hadException(false) |
| 50 , lineNumber(0) | 50 , lineNumber(0) |
| 51 { | 51 { |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool hadException; | 54 bool hadException; |
| 55 ScriptValue exception; | 55 ScriptValue exception; |
| 56 String errorMessage; | 56 String errorMessage; |
| 57 int lineNumber; | 57 int lineNumber; |
| 58 String sourceURL; | 58 String sourceURL; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class WorkerScriptController { | 61 class WorkerScriptController { |
| 62 public: | 62 public: |
| 63 WorkerScriptController(WorkerContext*); | 63 WorkerScriptController(WorkerGlobalScope*); |
| 64 ~WorkerScriptController(); | 64 ~WorkerScriptController(); |
| 65 | 65 |
| 66 WorkerContext* workerContext() { return m_workerContext; } | 66 WorkerGlobalScope* workerGlobalScope() { return m_workerGlobalScope; } |
| 67 | 67 |
| 68 void evaluate(const ScriptSourceCode&, ScriptValue* = 0); | 68 void evaluate(const ScriptSourceCode&, ScriptValue* = 0); |
| 69 | 69 |
| 70 void setException(const ScriptValue&); | 70 void setException(const ScriptValue&); |
| 71 | 71 |
| 72 // Async request to terminate a future JS execution. Eventually causes t
ermination | 72 // Async request to terminate a future JS execution. Eventually causes t
ermination |
| 73 // exception raised during JS execution, if the worker thread happens to
run JS. | 73 // exception raised during JS execution, if the worker thread happens to
run JS. |
| 74 // After JS execution was terminated in this way, the Worker thread has
to use | 74 // After JS execution was terminated in this way, the Worker thread has
to use |
| 75 // forbidExecution()/isExecutionForbidden() to guard against reentry int
o JS. | 75 // forbidExecution()/isExecutionForbidden() to guard against reentry int
o JS. |
| 76 // Can be called from any thread. | 76 // Can be called from any thread. |
| 77 void scheduleExecutionTermination(); | 77 void scheduleExecutionTermination(); |
| 78 bool isExecutionTerminating() const; | 78 bool isExecutionTerminating() const; |
| 79 | 79 |
| 80 // Called on Worker thread when JS exits with termination exception caus
ed by forbidExecution() request, | 80 // Called on Worker thread when JS exits with termination exception caus
ed by forbidExecution() request, |
| 81 // or by Worker thread termination code to prevent future entry into JS. | 81 // or by Worker thread termination code to prevent future entry into JS. |
| 82 void forbidExecution(); | 82 void forbidExecution(); |
| 83 bool isExecutionForbidden() const; | 83 bool isExecutionForbidden() const; |
| 84 | 84 |
| 85 void disableEval(const String&); | 85 void disableEval(const String&); |
| 86 | 86 |
| 87 // Returns WorkerScriptController for the currently executing context. 0
will be returned if the current executing context is not the worker context. | 87 // Returns WorkerScriptController for the currently executing context. 0
will be returned if the current executing context is not the worker context. |
| 88 static WorkerScriptController* controllerForContext(); | 88 static WorkerScriptController* controllerForContext(); |
| 89 | 89 |
| 90 // Evaluate a script file in the current execution environment. | 90 // Evaluate a script file in the current execution environment. |
| 91 ScriptValue evaluate(const String& script, const String& fileName, const
TextPosition& scriptStartPosition, WorkerContextExecutionState*); | 91 ScriptValue evaluate(const String& script, const String& fileName, const
TextPosition& scriptStartPosition, WorkerGlobalScopeExecutionState*); |
| 92 | 92 |
| 93 // Returns a local handle of the context. | 93 // Returns a local handle of the context. |
| 94 v8::Local<v8::Context> context() { return m_context.newLocal(v8::Isolate
::GetCurrent()); } | 94 v8::Local<v8::Context> context() { return m_context.newLocal(v8::Isolate
::GetCurrent()); } |
| 95 | 95 |
| 96 // Send a notification about current thread is going to be idle. | 96 // Send a notification about current thread is going to be idle. |
| 97 // hint suggests the upcoming idleness interval duration. | 97 // hint suggests the upcoming idleness interval duration. |
| 98 // The return value of true means that the script engine has done | 98 // The return value of true means that the script engine has done |
| 99 // most of the work and there's no need to call it again for a while. | 99 // most of the work and there's no need to call it again for a while. |
| 100 bool idleNotification(int hint = 1000) { return v8::V8::IdleNotification
(hint); } | 100 bool idleNotification(int hint = 1000) { return v8::V8::IdleNotification
(hint); } |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 bool initializeContextIfNeeded(); | 103 bool initializeContextIfNeeded(); |
| 104 void disposeContext(); | 104 void disposeContext(); |
| 105 | 105 |
| 106 WorkerContext* m_workerContext; | 106 WorkerGlobalScope* m_workerGlobalScope; |
| 107 v8::Isolate* m_isolate; | 107 v8::Isolate* m_isolate; |
| 108 ScopedPersistent<v8::Context> m_context; | 108 ScopedPersistent<v8::Context> m_context; |
| 109 OwnPtr<V8PerContextData> m_perContextData; | 109 OwnPtr<V8PerContextData> m_perContextData; |
| 110 String m_disableEvalPending; | 110 String m_disableEvalPending; |
| 111 OwnPtr<DOMDataStore> m_domDataStore; | 111 OwnPtr<DOMDataStore> m_domDataStore; |
| 112 bool m_executionForbidden; | 112 bool m_executionForbidden; |
| 113 bool m_executionScheduledToTerminate; | 113 bool m_executionScheduledToTerminate; |
| 114 mutable Mutex m_scheduledTerminationMutex; | 114 mutable Mutex m_scheduledTerminationMutex; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 } // namespace WebCore | 117 } // namespace WebCore |
| 118 | 118 |
| 119 #endif // WorkerScriptController_h | 119 #endif // WorkerScriptController_h |
| OLD | NEW |