Changeset 126446 in webkit
- Timestamp:
- Aug 23, 2012 10:51:26 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r126445 r126446 1 2012-08-23 Adam Barth <abarth@webkit.org> 2 3 [V8] ScheduledAction is ugly and needs a cleanup 4 https://bugs.webkit.org/show_bug.cgi?id=94784 5 6 Reviewed by Eric Seidel. 7 8 This patch updates ScheduledAction to use modern WebKit machinery, like 9 OwnHandle and Vector. 10 11 * bindings/v8/OwnHandle.h: 12 (OwnHandle): 13 * bindings/v8/ScheduledAction.cpp: 14 (WebCore::ScheduledAction::ScheduledAction): 15 (WebCore::ScheduledAction::~ScheduledAction): 16 (WebCore::ScheduledAction::execute): 17 * bindings/v8/ScheduledAction.h: 18 (WebCore): 19 (ScheduledAction): 20 (WebCore::ScheduledAction::ScheduledAction): 21 1 22 2012-08-23 Andrey Kosyakov <caseq@chromium.org> 2 23 -
trunk/Source/WebCore/bindings/v8/OwnHandle.h
r126376 r126446 33 33 34 34 #include <v8.h> 35 #include <wtf/Noncopyable.h> 35 36 36 37 namespace WebCore { … … 38 39 template<typename T> 39 40 class OwnHandle { 41 WTF_MAKE_NONCOPYABLE(OwnHandle); 40 42 public: 41 43 OwnHandle() { } -
trunk/Source/WebCore/bindings/v8/ScheduledAction.cpp
r126399 r126446 50 50 namespace WebCore { 51 51 52 ScheduledAction::ScheduledAction(v8::Handle<v8::Context> context, v8::Handle<v8::Function> func , int argc, v8::Handle<v8::Value> argv[])52 ScheduledAction::ScheduledAction(v8::Handle<v8::Context> context, v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[]) 53 53 : m_context(context) 54 , m_function(function) 54 55 , m_code(String(), KURL(), TextPosition::belowRangePosition()) 55 56 { 56 m_function = v8::Persistent<v8::Function>::New(func); 57 58 #ifndef NDEBUG 59 V8GCController::registerGlobalHandle(SCHEDULED_ACTION, this, m_function); 60 #endif 61 62 m_argc = argc; 63 if (argc > 0) { 64 m_argv = new v8::Persistent<v8::Value>[argc]; 65 for (int i = 0; i < argc; i++) { 66 m_argv[i] = v8::Persistent<v8::Value>::New(argv[i]); 67 68 #ifndef NDEBUG 69 V8GCController::registerGlobalHandle(SCHEDULED_ACTION, this, m_argv[i]); 70 #endif 71 } 72 } else 73 m_argv = 0; 57 m_args.reserveCapacity(argc); 58 for (int i = 0; i < argc; ++i) 59 m_args.append(v8::Persistent<v8::Value>::New(argv[i])); 74 60 } 75 61 76 62 ScheduledAction::~ScheduledAction() 77 63 { 78 if (m_function.IsEmpty()) 79 return; 80 81 #ifndef NDEBUG 82 V8GCController::unregisterGlobalHandle(this, m_function); 83 #endif 84 m_function.Dispose(); 85 86 for (int i = 0; i < m_argc; i++) { 87 #ifndef NDEBUG 88 V8GCController::unregisterGlobalHandle(this, m_argv[i]); 89 #endif 90 m_argv[i].Dispose(); 91 } 92 93 if (m_argc > 0) 94 delete[] m_argv; 64 for (size_t i = 0; i < m_args.size(); ++i) 65 m_args[i].Dispose(); 95 66 } 96 67 … … 103 74 if (!frame->script()->canExecuteScripts(AboutToExecuteScript)) 104 75 return; 105 execute(frame ->script());76 execute(frame); 106 77 } 107 78 #if ENABLE(WORKERS) … … 113 84 } 114 85 115 void ScheduledAction::execute( ScriptController* script)86 void ScheduledAction::execute(Frame* frame) 116 87 { 117 ASSERT(script->proxy());88 v8::HandleScope handleScope; 118 89 119 v8::Handle Scope handleScope;120 v8::Handle<v8::Context> v8Context = v8::Local<v8::Context>::New(m_context.get());121 if (v8Context.IsEmpty())122 return; // JS may not be enabled.90 v8::Handle<v8::Context> context = v8::Local<v8::Context>::New(m_context.get()); 91 if (context.IsEmpty()) 92 return; 93 v8::Context::Scope scope(context); 123 94 124 95 #if PLATFORM(CHROMIUM) … … 126 97 #endif 127 98 128 v8::Context::Scope scope(v8Context); 99 v8::Handle<v8::Function> function = m_function.get(); 100 if (!function.IsEmpty()) 101 frame->script()->callFunction(function, context->Global(), m_args.size(), m_args.data()); 102 else 103 frame->script()->compileAndRunScript(m_code); 129 104 130 // FIXME: Need to implement timeouts for preempting a long-running script. 131 if (!m_function.IsEmpty() && m_function->IsFunction()) 132 script->callFunction(v8::Persistent<v8::Function>::Cast(m_function), v8Context->Global(), m_argc, m_argv); 133 else 134 script->compileAndRunScript(m_code); 135 136 // The 'proxy' may be invalid at this point since JS could have released the owning Frame. 105 // The frame might be invalid at this point because JavaScript could have released it. 137 106 } 138 107 139 108 #if ENABLE(WORKERS) 140 void ScheduledAction::execute(WorkerContext* worker Context)109 void ScheduledAction::execute(WorkerContext* worker) 141 110 { 142 // In a Worker, the execution should always happen on a worker thread. 143 ASSERT(workerContext->thread()->threadID() == currentThread()); 111 ASSERT(worker->thread()->threadID() == currentThread()); 144 112 145 V8RecursionScope recursionScope(workerContext); 146 WorkerScriptController* scriptController = workerContext->script(); 113 V8RecursionScope recursionScope(worker); 147 114 148 if (!m_function.IsEmpty() && m_function->IsFunction()) { 115 v8::Handle<v8::Function> function = m_function.get(); 116 if (!function.IsEmpty()) { 149 117 v8::HandleScope handleScope; 150 v8::Handle<v8::Context> v8Context = v8::Local<v8::Context>::New(m_context.get()); 151 ASSERT(!v8Context.IsEmpty()); 152 v8::Context::Scope scope(v8Context); 153 m_function->Call(v8Context->Global(), m_argc, m_argv); 118 119 v8::Handle<v8::Context> context = v8::Local<v8::Context>::New(m_context.get()); 120 ASSERT(!context.IsEmpty()); 121 v8::Context::Scope scope(context); 122 123 function->Call(context->Global(), m_args.size(), m_args.data()); 154 124 } else 155 scriptController->evaluate(m_code);125 worker->script()->evaluate(m_code); 156 126 } 157 127 #endif -
trunk/Source/WebCore/bindings/v8/ScheduledAction.h
r125998 r126446 34 34 #include "OwnHandle.h" 35 35 #include "ScriptSourceCode.h" 36 #include "V8GCController.h"36 #include <v8.h> 37 37 #include <wtf/Forward.h> 38 39 #include <v8.h> 38 #include <wtf/Vector.h> 40 39 41 40 namespace WebCore { 42 41 43 class ScriptController;44 45 42 class Frame; 43 class ScriptExecutionContext; 44 class WorkerContext; 46 45 47 class ScheduledAction { 48 public: 49 ScheduledAction(v8::Handle<v8::Context>, v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]); 50 explicit ScheduledAction(v8::Handle<v8::Context> context, const WTF::String& code, const KURL& url = KURL()) 51 : m_context(context) 52 , m_argc(0) 53 , m_argv(0) 54 , m_code(code, url) 55 { 56 } 46 class ScheduledAction { 47 public: 48 ScheduledAction(v8::Handle<v8::Context>, v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]); 57 49 58 virtual ~ScheduledAction(); 59 virtual void execute(ScriptExecutionContext*); 50 ScheduledAction(v8::Handle<v8::Context> context, const String& code, const KURL& url = KURL()) 51 : m_context(context) 52 , m_code(code, url) 53 { 54 } 60 55 61 private: 62 void execute(ScriptController*); 56 ~ScheduledAction(); 57 void execute(ScriptExecutionContext*); 58 59 private: 60 void execute(Frame*); 63 61 #if ENABLE(WORKERS) 64 62 void execute(WorkerContext*); 65 63 #endif 66 64 67 OwnHandle<v8::Context> m_context; 68 v8::Persistent<v8::Function> m_function; 69 int m_argc; 70 v8::Persistent<v8::Value>* m_argv; 71 ScriptSourceCode m_code; 72 }; 65 OwnHandle<v8::Context> m_context; 66 OwnHandle<v8::Function> m_function; 67 Vector<v8::Persistent<v8::Value> > m_args; 68 ScriptSourceCode m_code; 69 }; 73 70 74 71 } // namespace WebCore
Note: See TracChangeset
for help on using the changeset viewer.