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

Unified Diff: third_party/WebKit/Source/modules/compositorworker/AnimatorDefinition.cpp

Issue 2745823002: [animation-worklet] Implement registerAnimator in worklet scope (Closed)
Patch Set: remove empty array Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/compositorworker/AnimatorDefinition.cpp
diff --git a/third_party/WebKit/Source/modules/compositorworker/AnimatorDefinition.cpp b/third_party/WebKit/Source/modules/compositorworker/AnimatorDefinition.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..27d32d9386edf5c30605fedc25a6a4c755ffeb61
--- /dev/null
+++ b/third_party/WebKit/Source/modules/compositorworker/AnimatorDefinition.cpp
@@ -0,0 +1,66 @@
+// Copyright 2017 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 "modules/compositorworker/AnimatorDefinition.h"
+
+#include "bindings/core/v8/ScriptState.h"
+#include "bindings/core/v8/V8Binding.h"
+#include "bindings/core/v8/V8ObjectConstructor.h"
+#include "core/dom/ExecutionContext.h"
+#include "modules/compositorworker/Animator.h"
+
+namespace blink {
+
+AnimatorDefinition* AnimatorDefinition::create(
+ ScriptState* scriptState,
+ v8::Local<v8::Function> constructor,
+ v8::Local<v8::Function> animate) {
+ return new AnimatorDefinition(scriptState, constructor, animate);
flackr 2017/03/13 19:04:51 I think error checking the animate function on the
+}
+
+AnimatorDefinition::AnimatorDefinition(ScriptState* scriptState,
+ v8::Local<v8::Function> constructor,
+ v8::Local<v8::Function> animate)
+ : m_scriptState(scriptState),
+ m_constructor(scriptState->isolate(), constructor),
+ m_animate(scriptState->isolate(), animate) {}
+
+AnimatorDefinition::~AnimatorDefinition() {}
+
+Animator* AnimatorDefinition::createInstance() {
+ v8::Isolate* isolate = m_scriptState->isolate();
+ v8::Local<v8::Function> constructor = m_constructor.newLocal(isolate);
+ DCHECK(!isUndefinedOrNull(constructor));
+
+ v8::Local<v8::Object> instance;
+ if (!V8ObjectConstructor::newInstance(isolate, constructor)
+ .ToLocal(&instance)) {
+ instance = v8::Local<v8::Object>();
+ }
+
+ return Animator::create(m_scriptState.get(), this, instance);
+}
+
+void AnimatorDefinition::animate(v8::Local<v8::Object> animatorInstance) {
+ ScriptState::Scope scope(m_scriptState.get());
+
+ v8::Isolate* isolate = m_scriptState->isolate();
+
+ if (isUndefinedOrNull(animatorInstance))
+ return;
+
+ v8::Local<v8::Function> animate = m_animate.newLocal(isolate);
+
+ v8::TryCatch block(isolate);
+ block.SetVerbose(true);
+
+ V8ScriptRunner::callFunction(animate, m_scriptState->getExecutionContext(),
+ animatorInstance, 0, nullptr, isolate);
+
+ // The animate function may have produced an error!
+ if (block.HasCaught())
flackr 2017/03/13 19:04:51 Should we not be catching this error? Or logging i
+ return;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698