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