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

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

Issue 23479016: Introduce Promise mapping to the IDL generator (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef GCObservation_h 31 #ifndef ScriptPromise_h
32 #define GCObservation_h 32 #define ScriptPromise_h
33 33
34 #include "bindings/v8/ScopedPersistent.h" 34 #include "bindings/v8/ScopedPersistent.h"
35 #include "wtf/PassRefPtr.h" 35 #include "bindings/v8/ScriptValue.h"
36 #include "wtf/RefCounted.h" 36 #include "bindings/v8/V8ScriptRunner.h"
37 #include <v8.h> 37 #include <v8.h>
38 38
39 namespace WebCore { 39 namespace WebCore {
40 40
41 class GCObservation : public RefCounted<GCObservation> { 41 class ScriptPromise {
yhirano 2013/09/02 11:58:17 Can ScriptPromise be a subclass of ScriptValue?
yusukesuzuki 2013/09/03 08:33:11 Done.
yusukesuzuki 2013/09/04 06:37:00 ScriptPromise may have different semantics from Sc
42 public: 42 public:
43 static PassRefPtr<GCObservation> create(v8::Handle<v8::Value> observedValue) { return adoptRef(new GCObservation(observedValue)); } 43 ScriptPromise()
44 ~GCObservation() { } 44 : m_promise()
45 {
46 }
45 47
46 // Caution: It is only feasible to determine whether an object was 48 explicit ScriptPromise(ScriptValue promise)
47 // "near death"; it may have been kept alive through a weak 49 : m_promise(promise)
48 // handle. After reaching near-death, having been collected is the 50 {
49 // common case. 51 ASSERT(!m_promise.hasNoValue());
50 bool wasCollected() const { return m_collected; } 52 }
51 void setWasCollected(); 53
54 explicit ScriptPromise(v8::Handle<v8::Value> promise)
55 : m_promise(promise)
56 {
57 ASSERT(!m_promise.hasNoValue());
58 }
59
60 bool isObject() const
61 {
62 return m_promise.isObject();
63 }
64
65 bool isNull() const
66 {
67 return m_promise.isNull();
68 }
69
70 bool isUndefinedOrNull() const
71 {
72 return m_promise.isUndefined() || m_promise.isNull();
73 }
74
75 v8::Handle<v8::Value> v8Value() const
76 {
77 return m_promise.v8Value();
78 }
79
80 void clear()
81 {
82 m_promise.clear();
83 }
52 84
53 private: 85 private:
54 explicit GCObservation(v8::Handle<v8::Value>); 86 ScriptValue m_promise;
haraken 2013/09/02 21:44:21 Why can't you use ScopedPersistent?
55
56 ScopedPersistent<v8::Value> m_observed;
57 bool m_collected;
58 }; 87 };
59 88
60 } 89 } // namespace WebCore
61 90
62 #endif // GCObservation_h 91
92 #endif // ScriptPromise_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698