OLD | NEW |
---|---|
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 Loading... | |
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 AnimatableUnknown_h | 31 #ifndef ScriptPromise_h |
32 #define AnimatableUnknown_h | 32 #define ScriptPromise_h |
33 | 33 |
34 #include "core/animation/AnimatableValue.h" | 34 #include "bindings/v8/ScopedPersistent.h" |
35 #include "bindings/v8/ScriptValue.h" | |
36 #include "bindings/v8/V8ScriptRunner.h" | |
37 #include <v8.h> | |
35 | 38 |
36 namespace WebCore { | 39 namespace WebCore { |
37 | 40 |
38 class AnimatableUnknown : public AnimatableValue { | 41 // ScriptPromise is the class for representing Promise values in C++ world. |
42 // ScriptPromise holds a Promise. | |
43 // So holding ScriptPromise as a member variable causes memory leaks | |
44 // since it has a reference from C++ to V8. | |
45 // | |
yusukesuzuki
2013/09/04 06:37:00
Added the comment about possible memory leaks.
yhirano
2013/09/04 07:13:17
"So holding a ScriptPromise as a member variable i
yusukesuzuki
2013/09/04 08:02:07
Done. Thanks!
| |
46 class ScriptPromise { | |
39 public: | 47 public: |
40 virtual ~AnimatableUnknown() { } | 48 ScriptPromise() |
41 | 49 : m_promise() |
42 static PassRefPtr<AnimatableUnknown> create(PassRefPtr<CSSValue> value) | |
43 { | 50 { |
44 return adoptRef(new AnimatableUnknown(value)); | |
45 } | 51 } |
46 | 52 |
47 PassRefPtr<CSSValue> toCSSValue() const { return m_value; } | 53 explicit ScriptPromise(ScriptValue promise) |
48 | 54 : m_promise(promise) |
49 protected: | |
50 virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue* val ue, double fraction) const OVERRIDE | |
51 { | 55 { |
52 return defaultInterpolateTo(this, value, fraction); | 56 ASSERT(!m_promise.hasNoValue()); |
53 } | 57 } |
54 | 58 |
55 virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue* value) co nst OVERRIDE | 59 explicit ScriptPromise(v8::Handle<v8::Value> promise) |
60 : m_promise(promise) | |
56 { | 61 { |
57 return defaultAddWith(this, value); | 62 ASSERT(!m_promise.hasNoValue()); |
63 } | |
64 | |
65 bool isObject() const | |
66 { | |
67 return m_promise.isObject(); | |
68 } | |
69 | |
70 bool isNull() const | |
71 { | |
72 return m_promise.isNull(); | |
73 } | |
74 | |
75 bool isUndefinedOrNull() const | |
76 { | |
77 return m_promise.isUndefined() || m_promise.isNull(); | |
78 } | |
79 | |
80 v8::Handle<v8::Value> v8Value() const | |
81 { | |
82 return m_promise.v8Value(); | |
83 } | |
84 | |
85 void clear() | |
86 { | |
87 m_promise.clear(); | |
58 } | 88 } |
59 | 89 |
60 private: | 90 private: |
61 explicit AnimatableUnknown(PassRefPtr<CSSValue> value) | 91 ScriptValue m_promise; |
62 : AnimatableValue(TypeUnknown) | |
63 , m_value(value) | |
64 { | |
65 ASSERT(m_value); | |
66 } | |
67 | |
68 const RefPtr<CSSValue> m_value; | |
69 }; | 92 }; |
70 | 93 |
71 inline const AnimatableUnknown* toAnimatableUnknown(const AnimatableValue* value ) | |
72 { | |
73 ASSERT_WITH_SECURITY_IMPLICATION(value && value->isUnknown()); | |
74 return static_cast<const AnimatableUnknown*>(value); | |
75 } | |
76 | |
77 } // namespace WebCore | 94 } // namespace WebCore |
78 | 95 |
79 #endif // AnimatableUnknown_h | 96 |
97 #endif // ScriptPromise_h | |
OLD | NEW |