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

Side by Side Diff: third_party/WebKit/Source/modules/compositorworker/AnimationWorkletGlobalScope.cpp

Issue 2903703003: Use wrapper tracing for worklets. (Closed)
Patch Set: fix comments Created 3 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "modules/compositorworker/AnimationWorkletGlobalScope.h" 5 #include "modules/compositorworker/AnimationWorkletGlobalScope.h"
6 6
7 #include "platform/weborigin/SecurityOrigin.h" 7 #include "platform/weborigin/SecurityOrigin.h"
8 8
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
(...skipping 23 matching lines...) Expand all
34 WorkerThread* thread) 34 WorkerThread* thread)
35 : ThreadedWorkletGlobalScope(url, 35 : ThreadedWorkletGlobalScope(url,
36 user_agent, 36 user_agent,
37 std::move(security_origin), 37 std::move(security_origin),
38 isolate, 38 isolate,
39 thread) {} 39 thread) {}
40 40
41 AnimationWorkletGlobalScope::~AnimationWorkletGlobalScope() {} 41 AnimationWorkletGlobalScope::~AnimationWorkletGlobalScope() {}
42 42
43 DEFINE_TRACE(AnimationWorkletGlobalScope) { 43 DEFINE_TRACE(AnimationWorkletGlobalScope) {
44 visitor->Trace(m_animatorDefinitions); 44 visitor->Trace(animator_definitions_);
45 visitor->Trace(m_animators); 45 visitor->Trace(animators_);
46 ThreadedWorkletGlobalScope::Trace(visitor); 46 ThreadedWorkletGlobalScope::Trace(visitor);
47 } 47 }
48 48
49 void AnimationWorkletGlobalScope::Dispose() { 49 DEFINE_TRACE_WRAPPERS(AnimationWorkletGlobalScope) {
50 DCHECK(IsContextThread()); 50 for (auto animator : animators_)
51 // Clear animators and definitions to avoid reference cycle. 51 visitor->TraceWrappers(animator);
52 m_animatorDefinitions.clear(); 52
53 m_animators.clear(); 53 for (auto definition : animator_definitions_)
54 ThreadedWorkletGlobalScope::Dispose(); 54 visitor->TraceWrappers(definition.value);
55 } 55 }
56 56
57 void AnimationWorkletGlobalScope::registerAnimator( 57 void AnimationWorkletGlobalScope::registerAnimator(
58 const String& name, 58 const String& name,
59 const ScriptValue& ctorValue, 59 const ScriptValue& ctorValue,
60 ExceptionState& exceptionState) { 60 ExceptionState& exceptionState) {
61 DCHECK(IsContextThread()); 61 DCHECK(IsContextThread());
62 if (m_animatorDefinitions.Contains(name)) { 62 if (animator_definitions_.Contains(name)) {
63 exceptionState.ThrowDOMException( 63 exceptionState.ThrowDOMException(
64 kNotSupportedError, 64 kNotSupportedError,
65 "A class with name:'" + name + "' is already registered."); 65 "A class with name:'" + name + "' is already registered.");
66 return; 66 return;
67 } 67 }
68 68
69 if (name.IsEmpty()) { 69 if (name.IsEmpty()) {
70 exceptionState.ThrowTypeError("The empty string is not a valid name."); 70 exceptionState.ThrowTypeError("The empty string is not a valid name.");
71 return; 71 return;
72 } 72 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if (!animateValue->IsFunction()) { 111 if (!animateValue->IsFunction()) {
112 exceptionState.ThrowTypeError( 112 exceptionState.ThrowTypeError(
113 "The 'animate' property on the prototype is not a function."); 113 "The 'animate' property on the prototype is not a function.");
114 return; 114 return;
115 } 115 }
116 116
117 v8::Local<v8::Function> animate = v8::Local<v8::Function>::Cast(animateValue); 117 v8::Local<v8::Function> animate = v8::Local<v8::Function>::Cast(animateValue);
118 118
119 AnimatorDefinition* definition = 119 AnimatorDefinition* definition =
120 new AnimatorDefinition(isolate, constructor, animate); 120 new AnimatorDefinition(isolate, constructor, animate);
121 m_animatorDefinitions.Set(name, definition); 121 animator_definitions_.Set(
122 name, TraceWrapperMember<AnimatorDefinition>(this, definition));
122 123
123 // Immediately instantiate an animator for the registered definition. 124 // Immediately instantiate an animator for the registered definition.
124 // TODO(majidvp): Remove this once you add alternative way to instantiate 125 // TODO(majidvp): Remove this once you add alternative way to instantiate
125 m_animators.push_back(CreateInstance(name)); 126 Animator* animator = CreateInstance(name);
127 animators_.push_back(TraceWrapperMember<Animator>(this, animator));
126 } 128 }
127 129
128 Animator* AnimationWorkletGlobalScope::CreateInstance(const String& name) { 130 Animator* AnimationWorkletGlobalScope::CreateInstance(const String& name) {
129 DCHECK(IsContextThread()); 131 DCHECK(IsContextThread());
130 AnimatorDefinition* definition = m_animatorDefinitions.at(name); 132 AnimatorDefinition* definition = animator_definitions_.at(name);
131 if (!definition) 133 if (!definition)
132 return nullptr; 134 return nullptr;
133 135
134 v8::Isolate* isolate = ScriptController()->GetScriptState()->GetIsolate(); 136 v8::Isolate* isolate = ScriptController()->GetScriptState()->GetIsolate();
135 v8::Local<v8::Function> constructor = definition->ConstructorLocal(isolate); 137 v8::Local<v8::Function> constructor = definition->ConstructorLocal(isolate);
136 DCHECK(!IsUndefinedOrNull(constructor)); 138 DCHECK(!IsUndefinedOrNull(constructor));
137 139
138 v8::Local<v8::Object> instance; 140 v8::Local<v8::Object> instance;
139 if (!V8ObjectConstructor::NewInstance(isolate, constructor) 141 if (!V8ObjectConstructor::NewInstance(isolate, constructor)
140 .ToLocal(&instance)) 142 .ToLocal(&instance))
141 return nullptr; 143 return nullptr;
142 144
143 return new Animator(isolate, definition, instance); 145 return new Animator(isolate, definition, instance);
144 } 146 }
145 147
146 } // namespace blink 148 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698