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

Side by Side Diff: extensions/renderer/script_context.cc

Issue 2339683006: [Blink] Modify SuspendableScriptExecutor to take a v8::Function (Closed)
Patch Set: polish Created 4 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/script_context.h" 5 #include "extensions/renderer/script_context.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 195 }
196 196
197 v8::Local<v8::Object> global = v8_context()->Global(); 197 v8::Local<v8::Object> global = v8_context()->Global();
198 if (!web_frame_) 198 if (!web_frame_)
199 return handle_scope.Escape(function->Call(global, argc, argv)); 199 return handle_scope.Escape(function->Call(global, argc, argv));
200 return handle_scope.Escape( 200 return handle_scope.Escape(
201 v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled( 201 v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled(
202 function, global, argc, argv))); 202 function, global, argc, argv)));
203 } 203 }
204 204
205 void ScriptContext::SafeCallFunction(
206 const v8::Local<v8::Function>& function,
207 int argc,
208 v8::Local<v8::Value> argv[]) {
209 v8::HandleScope handle_scope(isolate());
210 v8::Context::Scope scope(v8_context());
211 v8::MicrotasksScope microtasks(
212 isolate(), v8::MicrotasksScope::kDoNotRunMicrotasks);
213 v8::Local<v8::Object> global = v8_context()->Global();
214 if (web_frame_) {
215 web_frame_->requestExecuteV8Function(function, global, argc, argv, nullptr);
216 } else {
Devlin 2016/09/16 18:16:31 This can happen in the case of e.g. ServiceWorker
dcheng 2016/09/27 08:30:57 Handwaving a bit... maybe this is OK? I don't thin
falken 2016/09/28 00:04:14 +nhiroki, +yhirano I probably don't understand en
yhirano 2016/09/28 05:55:03 This topic is about sync loading on a worker threa
217 // TODO(devlin): This probably isn't safe.
218 function->Call(global, argc, argv);
219 }
220 }
221
205 v8::Local<v8::Value> ScriptContext::CallFunction( 222 v8::Local<v8::Value> ScriptContext::CallFunction(
206 const v8::Local<v8::Function>& function) const { 223 const v8::Local<v8::Function>& function) const {
207 DCHECK(thread_checker_.CalledOnValidThread()); 224 DCHECK(thread_checker_.CalledOnValidThread());
208 return CallFunction(function, 0, nullptr); 225 return CallFunction(function, 0, nullptr);
209 } 226 }
210 227
211 Feature::Availability ScriptContext::GetAvailability( 228 Feature::Availability ScriptContext::GetAvailability(
212 const std::string& api_name) { 229 const std::string& api_name) {
213 DCHECK(thread_checker_.CalledOnValidThread()); 230 DCHECK(thread_checker_.CalledOnValidThread());
214 if (base::StartsWith(api_name, "test", base::CompareCase::SENSITIVE)) { 231 if (base::StartsWith(api_name, "test", base::CompareCase::SENSITIVE)) {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 v8::Local<v8::Value> argv[]) { 518 v8::Local<v8::Value> argv[]) {
502 return context_->CallFunction(function, argc, argv); 519 return context_->CallFunction(function, argc, argv);
503 } 520 }
504 521
505 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 522 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
506 v8::HandleScope handle_scope(context_->isolate()); 523 v8::HandleScope handle_scope(context_->isolate());
507 return gin::PerContextData::From(context_->v8_context())->context_holder(); 524 return gin::PerContextData::From(context_->v8_context())->context_holder();
508 } 525 }
509 526
510 } // namespace extensions 527 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698