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

Side by Side Diff: Source/bindings/v8/V8GarbageCollected.h

Issue 337053004: Don't assert when ServiceWorker::from is passed an empty promise (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: set state ContextStopped Created 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 ASSERT(value->IsExternal()); 44 ASSERT(value->IsExternal());
45 T* result = static_cast<T*>(value.As<v8::External>()->Value()); 45 T* result = static_cast<T*>(value.As<v8::External>()->Value());
46 RELEASE_ASSERT(result->m_handle == value); 46 RELEASE_ASSERT(result->m_handle == value);
47 return result; 47 return result;
48 } 48 }
49 49
50 protected: 50 protected:
51 V8GarbageCollected(v8::Isolate* isolate) 51 V8GarbageCollected(v8::Isolate* isolate)
52 : m_isolate(isolate) 52 : m_isolate(isolate)
53 , m_handle(isolate, v8::External::New(isolate, static_cast<T*>(this))) 53 , m_handle(isolate, v8::External::New(isolate, static_cast<T*>(this)))
54 , m_releasedToV8GarbageCollector(false)
54 { 55 {
55 } 56 }
56 57
57 v8::Handle<v8::External> releaseToV8GarbageCollector() 58 v8::Handle<v8::External> releaseToV8GarbageCollector()
58 { 59 {
59 ASSERT(!m_handle.isWeak()); // Call this exactly once. 60 ASSERT(!m_handle.isWeak()); // Call this exactly once.
61 m_releasedToV8GarbageCollector = true;
60 v8::Handle<v8::External> result = m_handle.newLocal(m_isolate); 62 v8::Handle<v8::External> result = m_handle.newLocal(m_isolate);
61 m_handle.setWeak(static_cast<T*>(this), &weakCallback); 63 m_handle.setWeak(static_cast<T*>(this), &weakCallback);
62 return result; 64 return result;
63 } 65 }
64 66
65 ~V8GarbageCollected() 67 ~V8GarbageCollected()
66 { 68 {
67 ASSERT(m_handle.isEmpty()); 69 ASSERT(!m_releasedToV8GarbageCollector || m_handle.isEmpty());
68 } 70 }
69 71
70 v8::Isolate* isolate() { return m_isolate; } 72 v8::Isolate* isolate() { return m_isolate; }
71 73
72 private: 74 private:
73 static void weakCallback(const v8::WeakCallbackData<v8::External, T>& data) 75 static void weakCallback(const v8::WeakCallbackData<v8::External, T>& data)
74 { 76 {
75 T* self = data.GetParameter(); 77 T* self = data.GetParameter();
76 self->m_handle.clear(); 78 self->m_handle.clear();
77 delete self; 79 delete self;
78 } 80 }
79 81
80 v8::Isolate* m_isolate; 82 v8::Isolate* m_isolate;
81 ScopedPersistent<v8::External> m_handle; 83 ScopedPersistent<v8::External> m_handle;
84 bool m_releasedToV8GarbageCollector;
82 }; 85 };
83 86
84 } // namespace WebCore 87 } // namespace WebCore
85 88
86 #endif // V8GarbageCollected_h 89 #endif // V8GarbageCollected_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698