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

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

Issue 24403002: [ABANDONED] Implement ThenableCoercions for AP2 Promises (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 2 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
(Empty)
1 /*
2 * Copyright (C) 2013, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 #ifndef ThenableCoercions_h
26 #define ThenableCoercions_h
27
28 #include "bindings/v8/ScopedPersistent.h"
29 #include "wtf/Assertions.h"
30 #include "wtf/DoublyLinkedList.h"
31 #include "wtf/Noncopyable.h"
32 #include "wtf/PassOwnPtr.h"
33 #include "wtf/Vector.h"
34
35 #include <v8.h>
36
37 namespace WebCore {
38
39 class ThenableCoercions {
40 WTF_MAKE_NONCOPYABLE(ThenableCoercions);
41 public:
42 static PassOwnPtr<ThenableCoercions> create();
43
44 ThenableCoercions();
45 ~ThenableCoercions();
46
47 bool has(v8::Handle<v8::Object> thenable);
48 v8::Handle<v8::Object> get(v8::Handle<v8::Object> thenable);
49 void set(v8::Handle<v8::Object> thenable, v8::Handle<v8::Object> promise, v8 ::Isolate*);
50
51 private:
52 class Entry : public DoublyLinkedListNode<Entry> {
53 WTF_MAKE_NONCOPYABLE(Entry);
54 friend class DoublyLinkedListNode<Entry>;
55 public:
56 static Entry* create(v8::Handle<v8::Object> thenable, v8::Handle<v8::Obj ect> promise, ThenableCoercions* thenableCoercions, v8::Isolate* isolate)
57 {
58 return new Entry(thenable, promise, thenableCoercions, isolate);
59 }
60
61 v8::Local<v8::Object> thenable()
62 {
63 return m_thenable.newLocal(m_isolate);
64 }
65
66 v8::Local<v8::Object> promise()
67 {
68 return m_promise.newLocal(m_isolate);
69 }
70
71 private:
72 Entry(v8::Handle<v8::Object> thenable, v8::Handle<v8::Object> promise, T henableCoercions*, v8::Isolate*);
73
74 static void makeWeakCallback(v8::Isolate*, v8::Persistent<v8::Object>* t henable, Entry*);
75
76 Entry* m_next;
77 Entry* m_prev;
78 ScopedPersistent<v8::Object> m_thenable;
79 ScopedPersistent<v8::Object> m_promise;
80 ThenableCoercions* m_thenableCoercions;
81 v8::Isolate* m_isolate;
82 };
83
84 class GuardEntriesListAgainstGC {
85 WTF_MAKE_NONCOPYABLE(GuardEntriesListAgainstGC);
86 public:
87 GuardEntriesListAgainstGC(ThenableCoercions*);
88 ~GuardEntriesListAgainstGC();
89
90 private:
91 ThenableCoercions* m_thenableCoercions;
92 };
93
94 friend class Entry;
95 friend class GuardEntriesListAgainstGC;
96
97 void tryToDelete(Entry*);
98 void deleteInternal(Entry*);
99
100 DoublyLinkedList<Entry> m_entries;
101 Vector<Entry*> m_entriesToDelete;
102 bool m_entriesListGuarded : 1;
103 };
104
105 } // namespace WebCore
106
107 #endif // ThenableCoercions_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698