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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScheduledAction.cpp

Issue 2191543002: binding: Disallows to run a function if its context is detached. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 ScheduledAction::ScheduledAction(ScriptState* scriptState, const String& code) 99 ScheduledAction::ScheduledAction(ScriptState* scriptState, const String& code)
100 : m_scriptState(scriptState) 100 : m_scriptState(scriptState)
101 , m_info(scriptState->isolate()) 101 , m_info(scriptState->isolate())
102 , m_code(code, KURL()) 102 , m_code(code, KURL())
103 { 103 {
104 } 104 }
105 105
106 void ScheduledAction::execute(LocalFrame* frame) 106 void ScheduledAction::execute(LocalFrame* frame)
107 { 107 {
108 if (!m_scriptState->contextIsValid()) { 108 if (!m_scriptState->contextIsValid()) {
haraken 2016/07/27 15:28:43 I was thinking that this check was doing what you
Yuki 2016/07/28 06:12:35 No, m_scriptState is different from function's con
109 DVLOG(1) << "ScheduledAction::execute " << this << ": context is empty"; 109 DVLOG(1) << "ScheduledAction::execute " << this << ": context is empty";
110 return; 110 return;
111 } 111 }
112 112
113 TRACE_EVENT0("v8", "ScheduledAction::execute"); 113 TRACE_EVENT0("v8", "ScheduledAction::execute");
114 ScriptState::Scope scope(m_scriptState.get()); 114 ScriptState::Scope scope(m_scriptState.get());
115 if (!m_function.isEmpty()) { 115 if (!m_function.isEmpty()) {
116 DVLOG(1) << "ScheduledAction::execute " << this << ": have function"; 116 DVLOG(1) << "ScheduledAction::execute " << this << ": have function";
117 v8::Local<v8::Function> function = m_function.newLocal(m_scriptState->is olate());
118 ScriptState* scriptStateForFunc = ScriptState::from(function->CreationCo ntext());
119 if (!scriptStateForFunc->contextIsValid()) {
120 DVLOG(1) << "ScheduledAction::execute " << this << ": function's con text is empty";
121 return;
122 }
117 Vector<v8::Local<v8::Value>> info; 123 Vector<v8::Local<v8::Value>> info;
118 createLocalHandlesForArgs(&info); 124 createLocalHandlesForArgs(&info);
119 V8ScriptRunner::callFunction(m_function.newLocal(m_scriptState->isolate( )), frame->document(), m_scriptState->context()->Global(), info.size(), info.dat a(), m_scriptState->isolate()); 125 V8ScriptRunner::callFunction(function, frame->document(), m_scriptState- >context()->Global(), info.size(), info.data(), m_scriptState->isolate());
120 } else { 126 } else {
121 DVLOG(1) << "ScheduledAction::execute " << this << ": executing from sou rce"; 127 DVLOG(1) << "ScheduledAction::execute " << this << ": executing from sou rce";
122 frame->script().executeScriptAndReturnValue(m_scriptState->context(), Sc riptSourceCode(m_code)); 128 frame->script().executeScriptAndReturnValue(m_scriptState->context(), Sc riptSourceCode(m_code));
123 } 129 }
124 130
125 // The frame might be invalid at this point because JavaScript could have re leased it. 131 // The frame might be invalid at this point because JavaScript could have re leased it.
126 } 132 }
127 133
128 void ScheduledAction::execute(WorkerGlobalScope* worker) 134 void ScheduledAction::execute(WorkerGlobalScope* worker)
129 { 135 {
130 ASSERT(worker->thread()->isCurrentThread()); 136 ASSERT(worker->thread()->isCurrentThread());
131 ASSERT(m_scriptState->contextIsValid()); 137
138 if (!m_scriptState->contextIsValid()) {
139 DVLOG(1) << "ScheduledAction::execute " << this << ": context is empty";
140 return;
141 }
142
132 if (!m_function.isEmpty()) { 143 if (!m_function.isEmpty()) {
133 ScriptState::Scope scope(m_scriptState.get()); 144 ScriptState::Scope scope(m_scriptState.get());
145 v8::Local<v8::Function> function = m_function.newLocal(m_scriptState->is olate());
146 ScriptState* scriptStateForFunc = ScriptState::from(function->CreationCo ntext());
147 if (!scriptStateForFunc->contextIsValid()) {
148 DVLOG(1) << "ScheduledAction::execute " << this << ": function's con text is empty";
149 return;
150 }
134 Vector<v8::Local<v8::Value>> info; 151 Vector<v8::Local<v8::Value>> info;
135 createLocalHandlesForArgs(&info); 152 createLocalHandlesForArgs(&info);
136 V8ScriptRunner::callFunction(m_function.newLocal(m_scriptState->isolate( )), worker, m_scriptState->context()->Global(), info.size(), info.data(), m_scri ptState->isolate()); 153 V8ScriptRunner::callFunction(function, worker, m_scriptState->context()- >Global(), info.size(), info.data(), m_scriptState->isolate());
137 } else { 154 } else {
138 worker->scriptController()->evaluate(m_code); 155 worker->scriptController()->evaluate(m_code);
139 } 156 }
140 } 157 }
141 158
142 void ScheduledAction::createLocalHandlesForArgs(Vector<v8::Local<v8::Value>>* ha ndles) 159 void ScheduledAction::createLocalHandlesForArgs(Vector<v8::Local<v8::Value>>* ha ndles)
143 { 160 {
144 handles->reserveCapacity(m_info.Size()); 161 handles->reserveCapacity(m_info.Size());
145 for (size_t i = 0; i < m_info.Size(); ++i) 162 for (size_t i = 0; i < m_info.Size(); ++i)
146 handles->append(m_info.Get(i)); 163 handles->append(m_info.Get(i));
147 } 164 }
148 165
149 } // namespace blink 166 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698