| OLD | NEW |
| 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/csspaint/PaintWorklet.h" | 5 #include "modules/csspaint/PaintWorklet.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptSourceCode.h" | 7 #include "bindings/core/v8/ScriptSourceCode.h" |
| 8 #include "bindings/core/v8/V8GCController.h" | 8 #include "bindings/core/v8/V8GCController.h" |
| 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 TEST_F(PaintWorkletTest, GarbageCollectionOfCSSPaintDefinition) { | 33 TEST_F(PaintWorkletTest, GarbageCollectionOfCSSPaintDefinition) { |
| 34 PaintWorkletGlobalScopeProxy* proxy = PaintWorkletGlobalScopeProxy::From( | 34 PaintWorkletGlobalScopeProxy* proxy = PaintWorkletGlobalScopeProxy::From( |
| 35 GetPaintWorklet()->GetWorkletGlobalScopeProxy()); | 35 GetPaintWorklet()->GetWorkletGlobalScopeProxy()); |
| 36 PaintWorkletGlobalScope* global_scope = proxy->global_scope(); | 36 PaintWorkletGlobalScope* global_scope = proxy->global_scope(); |
| 37 global_scope->ScriptController()->Evaluate( | 37 global_scope->ScriptController()->Evaluate( |
| 38 ScriptSourceCode("registerPaint('foo', class { paint() { } });")); | 38 ScriptSourceCode("registerPaint('foo', class { paint() { } });")); |
| 39 | 39 |
| 40 CSSPaintDefinition* definition = global_scope->FindDefinition("foo"); | 40 CSSPaintDefinition* definition = global_scope->FindDefinition("foo"); |
| 41 ASSERT(definition); | 41 DCHECK(definition); |
| 42 | 42 |
| 43 v8::Isolate* isolate = | 43 v8::Isolate* isolate = |
| 44 global_scope->ScriptController()->GetScriptState()->GetIsolate(); | 44 global_scope->ScriptController()->GetScriptState()->GetIsolate(); |
| 45 ASSERT(isolate); | 45 DCHECK(isolate); |
| 46 | 46 |
| 47 // Set our ScopedPersistent to the paint function, and make weak. | 47 // Set our ScopedPersistent to the paint function, and make weak. |
| 48 ScopedPersistent<v8::Function> handle; | 48 ScopedPersistent<v8::Function> handle; |
| 49 { | 49 { |
| 50 v8::HandleScope handle_scope(isolate); | 50 v8::HandleScope handle_scope(isolate); |
| 51 handle.Set(isolate, definition->PaintFunctionForTesting(isolate)); | 51 handle.Set(isolate, definition->PaintFunctionForTesting(isolate)); |
| 52 handle.SetPhantom(); | 52 handle.SetPhantom(); |
| 53 } | 53 } |
| 54 ASSERT(!handle.IsEmpty()); | 54 DCHECK(!handle.IsEmpty()); |
| 55 ASSERT(handle.IsWeak()); | 55 DCHECK(handle.IsWeak()); |
| 56 | 56 |
| 57 // Run a GC, persistent shouldn't have been collected yet. | 57 // Run a GC, persistent shouldn't have been collected yet. |
| 58 ThreadState::Current()->CollectAllGarbage(); | 58 ThreadState::Current()->CollectAllGarbage(); |
| 59 V8GCController::CollectAllGarbageForTesting(isolate); | 59 V8GCController::CollectAllGarbageForTesting(isolate); |
| 60 ASSERT(!handle.IsEmpty()); | 60 DCHECK(!handle.IsEmpty()); |
| 61 | 61 |
| 62 // Delete the page & associated objects. | 62 // Delete the page & associated objects. |
| 63 page_.reset(); | 63 page_.reset(); |
| 64 | 64 |
| 65 // Run a GC, the persistent should have been collected. | 65 // Run a GC, the persistent should have been collected. |
| 66 ThreadState::Current()->CollectAllGarbage(); | 66 ThreadState::Current()->CollectAllGarbage(); |
| 67 V8GCController::CollectAllGarbageForTesting(isolate); | 67 V8GCController::CollectAllGarbageForTesting(isolate); |
| 68 ASSERT(handle.IsEmpty()); | 68 DCHECK(handle.IsEmpty()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |