From e53bba60a5bac2a327c2b9a4dd5e384255233aa3 Mon Sep 17 00:00:00 2001 From: Rafael Weinstein Date: Tue, 24 Feb 2015 12:11:19 -0800 Subject: [PATCH] Add dart_invoke to tonic for calls into App code. This patch adds utility functions which provide a single choke point for calling into sky application code. For now this is only serving the purpose of having a common trace event for calls into app code. R=abarth@chromium.org, abarth BUG= Review URL: https://codereview.chromium.org/941153003 --- engine/bindings/builtin_natives.cc | 3 ++- engine/bindings/dart_callback.cc | 3 ++- engine/bindings/dart_event_listener.cc | 3 ++- engine/bindings/scheduled_action.cc | 3 ++- engine/core/dom/custom/custom_element.cc | 3 ++- engine/core/script/dart_controller.cc | 5 ++-- engine/tonic/BUILD.gn | 2 ++ engine/tonic/dart_invoke.cc | 29 ++++++++++++++++++++++++ engine/tonic/dart_invoke.h | 23 +++++++++++++++++++ 9 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 engine/tonic/dart_invoke.cc create mode 100644 engine/tonic/dart_invoke.h diff --git a/engine/bindings/builtin_natives.cc b/engine/bindings/builtin_natives.cc index afe3c3d37e2..55584a3d017 100644 --- a/engine/bindings/builtin_natives.cc +++ b/engine/bindings/builtin_natives.cc @@ -19,6 +19,7 @@ #include "sky/engine/tonic/dart_api_scope.h" #include "sky/engine/tonic/dart_builtin.h" #include "sky/engine/tonic/dart_error.h" +#include "sky/engine/tonic/dart_invoke.h" #include "sky/engine/tonic/dart_isolate_scope.h" #include "sky/engine/tonic/dart_state.h" #include "sky/engine/tonic/dart_value.h" @@ -154,7 +155,7 @@ static void ExecuteMicrotask(base::WeakPtr dart_state, return; DartIsolateScope scope(dart_state->isolate()); DartApiScope api_scope; - LogIfError(Dart_InvokeClosure(callback->dart_value(), 0, nullptr)); + DartInvokeAppClosure(callback->dart_value(), 0, nullptr); } void ScheduleMicrotask(Dart_NativeArguments args) { diff --git a/engine/bindings/dart_callback.cc b/engine/bindings/dart_callback.cc index 1966631087c..61975e5f6f4 100644 --- a/engine/bindings/dart_callback.cc +++ b/engine/bindings/dart_callback.cc @@ -7,6 +7,7 @@ #include "sky/engine/tonic/dart_converter.h" #include "sky/engine/tonic/dart_error.h" +#include "sky/engine/tonic/dart_invoke.h" #include "sky/engine/tonic/dart_state.h" namespace blink { @@ -33,7 +34,7 @@ Dart_Isolate DartCallback::GetIsolate() const { } bool DartCallback::handleEvent(int argc, Dart_Handle* argv) { - LogIfError(Dart_InvokeClosure(callback_.value(), argc, argv)); + DartInvokeAppClosure(callback_.value(), argc, argv); return true; } diff --git a/engine/bindings/dart_event_listener.cc b/engine/bindings/dart_event_listener.cc index 2c16f656c8e..b3734490178 100644 --- a/engine/bindings/dart_event_listener.cc +++ b/engine/bindings/dart_event_listener.cc @@ -10,6 +10,7 @@ #include "sky/engine/tonic/dart_error.h" #include "sky/engine/tonic/dart_exception_factory.h" #include "sky/engine/tonic/dart_gc_visitor.h" +#include "sky/engine/tonic/dart_invoke.h" #include "sky/engine/tonic/dart_isolate_scope.h" namespace blink { @@ -51,7 +52,7 @@ void DartEventListener::handleEvent(ExecutionContext* context, Event* event) { DCHECK(event_handle); Dart_Handle params[] = {event_handle}; - LogIfError(Dart_InvokeClosure(closure_handle, arraysize(params), params)); + DartInvokeAppClosure(closure_handle, arraysize(params), params); } void DartEventListener::AcceptDartGCVisitor(DartGCVisitor& visitor) const { diff --git a/engine/bindings/scheduled_action.cc b/engine/bindings/scheduled_action.cc index b03286965ab..6d96466bfcd 100644 --- a/engine/bindings/scheduled_action.cc +++ b/engine/bindings/scheduled_action.cc @@ -7,6 +7,7 @@ #include "sky/engine/tonic/dart_api_scope.h" #include "sky/engine/tonic/dart_error.h" +#include "sky/engine/tonic/dart_invoke.h" #include "sky/engine/tonic/dart_isolate_scope.h" namespace blink { @@ -24,7 +25,7 @@ void ScheduledAction::Execute(ExecutionContext*) { return; DartIsolateScope scope(closure_.dart_state()->isolate()); DartApiScope api_scope; - LogIfError(Dart_InvokeClosure(closure_.value(), 0, nullptr)); + DartInvokeAppClosure(closure_.value(), 0, nullptr); } } // namespace blink diff --git a/engine/core/dom/custom/custom_element.cc b/engine/core/dom/custom/custom_element.cc index 1661c03edb5..c9099e8d089 100644 --- a/engine/core/dom/custom/custom_element.cc +++ b/engine/core/dom/custom/custom_element.cc @@ -13,6 +13,7 @@ #include "sky/engine/core/dom/custom/custom_element_callback_scope.h" #include "sky/engine/core/dom/custom/custom_element_registry.h" #include "sky/engine/tonic/dart_converter.h" +#include "sky/engine/tonic/dart_invoke.h" #include "sky/engine/tonic/dart_state.h" #include "sky/engine/wtf/text/AtomicString.h" @@ -42,7 +43,7 @@ void CallAttributeDidChangedCallback(RefPtr element, StringToDart(dart_state, oldValue), StringToDart(dart_state, newValue), }; - LogIfError(Dart_Invoke(wrapper, callback, arraysize(args), args)); + DartInvokeAppField(wrapper, callback, arraysize(args), args); } void CallDidAttachedCallback(RefPtr element, RefPtr document) { diff --git a/engine/core/script/dart_controller.cc b/engine/core/script/dart_controller.cc index ecbcad02b91..8e2a0608438 100644 --- a/engine/core/script/dart_controller.cc +++ b/engine/core/script/dart_controller.cc @@ -28,6 +28,7 @@ #include "sky/engine/tonic/dart_class_library.h" #include "sky/engine/tonic/dart_error.h" #include "sky/engine/tonic/dart_gc_controller.h" +#include "sky/engine/tonic/dart_invoke.h" #include "sky/engine/tonic/dart_isolate_scope.h" #include "sky/engine/tonic/dart_state.h" #include "sky/engine/tonic/dart_wrappable.h" @@ -139,7 +140,7 @@ void DartController::ExecuteLibraryInModule(AbstractModule* module, // TODO(rmacnak): Dart_LookupFunction won't find re-exports, etc. Dart_Handle entry = Dart_LookupFunction(library, ToDart(name)); if (module->isApplication()) { - LogIfError(Dart_Invoke(library, ToDart(name), 0, nullptr)); + DartInvokeAppField(library, ToDart(name), 0, nullptr); return; } @@ -149,7 +150,7 @@ void DartController::ExecuteLibraryInModule(AbstractModule* module, Dart_Handle args[] = { ToDart(script), }; - LogIfError(Dart_Invoke(library, ToDart(name), arraysize(args), args)); + DartInvokeAppField(library, ToDart(name), arraysize(args), args); } static void UnhandledExceptionCallback(Dart_Handle error) { diff --git a/engine/tonic/BUILD.gn b/engine/tonic/BUILD.gn index f6a6ae05707..fd6ca5e1055 100644 --- a/engine/tonic/BUILD.gn +++ b/engine/tonic/BUILD.gn @@ -23,6 +23,8 @@ source_set("tonic") { "dart_gc_controller.h", "dart_gc_visitor.cc", "dart_gc_visitor.h", + "dart_invoke.cc", + "dart_invoke.h", "dart_isolate_scope.cc", "dart_isolate_scope.h", "dart_persistent_value.cc", diff --git a/engine/tonic/dart_invoke.cc b/engine/tonic/dart_invoke.cc new file mode 100644 index 00000000000..92c4055d261 --- /dev/null +++ b/engine/tonic/dart_invoke.cc @@ -0,0 +1,29 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sky/engine/config.h" +#include "sky/engine/tonic/dart_invoke.h" + +#include "base/logging.h" +#include "base/trace_event/trace_event.h" +#include "sky/engine/tonic/dart_error.h" + +namespace blink { + +bool DartInvokeAppField(Dart_Handle target, Dart_Handle name, + int number_of_arguments, + Dart_Handle* arguments) { + TRACE_EVENT0("sky", "DartInvoke::DartInvokeAppField"); + return LogIfError(Dart_Invoke(target, name, number_of_arguments, arguments)); +} + +bool DartInvokeAppClosure(Dart_Handle closure, + int number_of_arguments, + Dart_Handle* arguments) { + TRACE_EVENT0("sky", "DartInvoke::DartInvokeAppClosure"); + return LogIfError( + Dart_InvokeClosure(closure, number_of_arguments, arguments)); +} + +} // namespace blink diff --git a/engine/tonic/dart_invoke.h b/engine/tonic/dart_invoke.h new file mode 100644 index 00000000000..7d5888507d2 --- /dev/null +++ b/engine/tonic/dart_invoke.h @@ -0,0 +1,23 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SKY_ENGINE_TONIC_DART_INVOKE_H_ +#define SKY_ENGINE_TONIC_DART_INVOKE_H_ + +#include "dart/runtime/include/dart_api.h" + +namespace blink { + +bool DartInvokeAppField(Dart_Handle target, Dart_Handle name, + int number_of_arguments, + Dart_Handle* arguments); + +bool DartInvokeAppClosure(Dart_Handle closure, + int number_of_arguments, + Dart_Handle* arguments); + +} // namespace blink + +#endif // SKY_ENGINE_TONIC_DART_INVOKE_H_ +