Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: Source/WebCore/bindings/v8/V8ScheduledAction.cpp

Issue 8806015: Changes to support a second VM. (Closed) Base URL: svn://svn.chromium.org/dash/experimental/chrome/src/webkit-full
Patch Set: . Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007-2009 Google Inc. All rights reserved. 2 * Copyright (C) 2007-2009 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 11 matching lines...) Expand all
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 #include "config.h" 31 #include "config.h"
32 #include "ScheduledAction.h" 32 #include "V8ScheduledAction.h"
33 33
34 #include "Document.h" 34 #include "Document.h"
35 #include "ScriptExecutionContext.h" 35 #include "ScriptExecutionContext.h"
36 #include "ScriptSourceCode.h" 36 #include "ScriptSourceCode.h"
37 37
38 #if PLATFORM(CHROMIUM) 38 #if PLATFORM(CHROMIUM)
39 #include "TraceEvent.h" 39 #include "TraceEvent.h"
40 #endif 40 #endif
41 41
42 #include "V8Binding.h" 42 #include "V8Binding.h"
43 #include "V8Proxy.h" 43 #include "V8Proxy.h"
44 #include "WorkerContext.h" 44 #include "WorkerContext.h"
45 #include "WorkerContextExecutionProxy.h" 45 #include "WorkerContextExecutionProxy.h"
46 #include "WorkerThread.h" 46 #include "WorkerThread.h"
47 47
48 namespace WebCore { 48 namespace WebCore {
49 49
50 ScheduledAction::ScheduledAction(v8::Handle<v8::Context> context, v8::Handle<v8: :Function> func, int argc, v8::Handle<v8::Value> argv[]) 50 V8ScheduledAction::V8ScheduledAction(v8::Handle<v8::Context> context, v8::Handle <v8::Function> func, int argc, v8::Handle<v8::Value> argv[])
51 : m_context(context) 51 : m_context(context)
52 , m_code(String(), KURL(), TextPosition::belowRangePosition()) 52 , m_code(String(), KURL(), TextPosition::belowRangePosition())
53 { 53 {
54 m_function = v8::Persistent<v8::Function>::New(func); 54 m_function = v8::Persistent<v8::Function>::New(func);
55 55
56 #ifndef NDEBUG 56 #ifndef NDEBUG
57 V8GCController::registerGlobalHandle(SCHEDULED_ACTION, this, m_function); 57 V8GCController::registerGlobalHandle(SCHEDULED_ACTION, this, m_function);
58 #endif 58 #endif
59 59
60 m_argc = argc; 60 m_argc = argc;
61 if (argc > 0) { 61 if (argc > 0) {
62 m_argv = new v8::Persistent<v8::Value>[argc]; 62 m_argv = new v8::Persistent<v8::Value>[argc];
63 for (int i = 0; i < argc; i++) { 63 for (int i = 0; i < argc; i++) {
64 m_argv[i] = v8::Persistent<v8::Value>::New(argv[i]); 64 m_argv[i] = v8::Persistent<v8::Value>::New(argv[i]);
65 65
66 #ifndef NDEBUG 66 #ifndef NDEBUG
67 V8GCController::registerGlobalHandle(SCHEDULED_ACTION, this, m_argv[i]); 67 V8GCController::registerGlobalHandle(SCHEDULED_ACTION, this, m_argv[i]);
68 #endif 68 #endif
69 } 69 }
70 } else 70 } else
71 m_argv = 0; 71 m_argv = 0;
72 } 72 }
73 73
74 ScheduledAction::~ScheduledAction() 74 V8ScheduledAction::~V8ScheduledAction()
75 { 75 {
76 if (m_function.IsEmpty()) 76 if (m_function.IsEmpty())
77 return; 77 return;
78 78
79 #ifndef NDEBUG 79 #ifndef NDEBUG
80 V8GCController::unregisterGlobalHandle(this, m_function); 80 V8GCController::unregisterGlobalHandle(this, m_function);
81 #endif 81 #endif
82 m_function.Dispose(); 82 m_function.Dispose();
83 83
84 for (int i = 0; i < m_argc; i++) { 84 for (int i = 0; i < m_argc; i++) {
85 #ifndef NDEBUG 85 #ifndef NDEBUG
86 V8GCController::unregisterGlobalHandle(this, m_argv[i]); 86 V8GCController::unregisterGlobalHandle(this, m_argv[i]);
87 #endif 87 #endif
88 m_argv[i].Dispose(); 88 m_argv[i].Dispose();
89 } 89 }
90 90
91 if (m_argc > 0) 91 if (m_argc > 0)
92 delete[] m_argv; 92 delete[] m_argv;
93 } 93 }
94 94
95 void ScheduledAction::execute(ScriptExecutionContext* context) 95 void V8ScheduledAction::execute(ScriptExecutionContext* context)
96 { 96 {
97 V8Proxy* proxy = V8Proxy::retrieve(context); 97 V8Proxy* proxy = V8Proxy::retrieve(context);
98 if (proxy) 98 if (proxy)
99 execute(proxy); 99 execute(proxy);
100 #if ENABLE(WORKERS) 100 #if ENABLE(WORKERS)
101 else if (context->isWorkerContext()) 101 else if (context->isWorkerContext())
102 execute(static_cast<WorkerContext*>(context)); 102 execute(static_cast<WorkerContext*>(context));
103 #endif 103 #endif
104 // It's possible that Javascript is disabled and that we have neither a V8Pr oxy 104 // It's possible that Javascript is disabled and that we have neither a V8Pr oxy
105 // nor a WorkerContext. Do nothing in that case. 105 // nor a WorkerContext. Do nothing in that case.
106 } 106 }
107 107
108 void ScheduledAction::execute(V8Proxy* proxy) 108 void V8ScheduledAction::execute(V8Proxy* proxy)
109 { 109 {
110 ASSERT(proxy); 110 ASSERT(proxy);
111 111
112 v8::HandleScope handleScope; 112 v8::HandleScope handleScope;
113 v8::Handle<v8::Context> v8Context = v8::Local<v8::Context>::New(m_context.ge t()); 113 v8::Handle<v8::Context> v8Context = v8::Local<v8::Context>::New(m_context.ge t());
114 if (v8Context.IsEmpty()) 114 if (v8Context.IsEmpty())
115 return; // JS may not be enabled. 115 return; // JS may not be enabled.
116 116
117 #if PLATFORM(CHROMIUM) 117 #if PLATFORM(CHROMIUM)
118 TRACE_EVENT("ScheduledAction::execute", this, 0); 118 TRACE_EVENT("V8ScheduledAction::execute", this, 0);
119 #endif 119 #endif
120 120
121 v8::Context::Scope scope(v8Context); 121 v8::Context::Scope scope(v8Context);
122 122
123 // FIXME: Need to implement timeouts for preempting a long-running script. 123 // FIXME: Need to implement timeouts for preempting a long-running script.
124 if (!m_function.IsEmpty() && m_function->IsFunction()) { 124 if (!m_function.IsEmpty() && m_function->IsFunction()) {
125 proxy->callFunction(v8::Persistent<v8::Function>::Cast(m_function), v8Co ntext->Global(), m_argc, m_argv); 125 proxy->callFunction(v8::Persistent<v8::Function>::Cast(m_function), v8Co ntext->Global(), m_argc, m_argv);
126 Document::updateStyleForAllDocuments(); 126 Document::updateStyleForAllDocuments();
127 } else 127 } else
128 proxy->evaluate(m_code, 0); 128 proxy->evaluate(m_code, 0);
129 129
130 // The 'proxy' may be invalid at this point since JS could have released the owning Frame. 130 // The 'proxy' may be invalid at this point since JS could have released the owning Frame.
131 } 131 }
132 132
133 #if ENABLE(WORKERS) 133 #if ENABLE(WORKERS)
134 void ScheduledAction::execute(WorkerContext* workerContext) 134 void V8ScheduledAction::execute(WorkerContext* workerContext)
135 { 135 {
136 // In a Worker, the execution should always happen on a worker thread. 136 // In a Worker, the execution should always happen on a worker thread.
137 ASSERT(workerContext->thread()->threadID() == currentThread()); 137 ASSERT(workerContext->thread()->threadID() == currentThread());
138 138
139 WorkerScriptController* scriptController = workerContext->script(); 139 WorkerScriptController* scriptController = workerContext->script();
140 140
141 if (!m_function.IsEmpty() && m_function->IsFunction()) { 141 if (!m_function.IsEmpty() && m_function->IsFunction()) {
142 v8::HandleScope handleScope; 142 v8::HandleScope handleScope;
143 v8::Handle<v8::Context> v8Context = v8::Local<v8::Context>::New(m_contex t.get()); 143 v8::Handle<v8::Context> v8Context = v8::Local<v8::Context>::New(m_contex t.get());
144 ASSERT(!v8Context.IsEmpty()); 144 ASSERT(!v8Context.IsEmpty());
145 v8::Context::Scope scope(v8Context); 145 v8::Context::Scope scope(v8Context);
146 m_function->Call(v8Context->Global(), m_argc, m_argv); 146 m_function->Call(v8Context->Global(), m_argc, m_argv);
147 } else 147 } else
148 scriptController->evaluate(m_code); 148 scriptController->evaluate(m_code);
149 } 149 }
150 #endif 150 #endif
151 151
152 } // namespace WebCore 152 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698