Chromium Code Reviews| Index: Source/bindings/v8/ScriptPromise.h |
| diff --git a/Source/core/animation/AnimatableUnknown.h b/Source/bindings/v8/ScriptPromise.h |
| similarity index 59% |
| copy from Source/core/animation/AnimatableUnknown.h |
| copy to Source/bindings/v8/ScriptPromise.h |
| index c136380f5895896249ed7d6e02356791d562c6dc..9f4a98d775cf18c0dd6a17a0d179e2c1c2a4959a 100644 |
| --- a/Source/core/animation/AnimatableUnknown.h |
| +++ b/Source/bindings/v8/ScriptPromise.h |
| @@ -28,52 +28,70 @@ |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| -#ifndef AnimatableUnknown_h |
| -#define AnimatableUnknown_h |
| +#ifndef ScriptPromise_h |
| +#define ScriptPromise_h |
| -#include "core/animation/AnimatableValue.h" |
| +#include "bindings/v8/ScopedPersistent.h" |
| +#include "bindings/v8/ScriptValue.h" |
| +#include "bindings/v8/V8ScriptRunner.h" |
| +#include <v8.h> |
| namespace WebCore { |
| -class AnimatableUnknown : public AnimatableValue { |
| +// ScriptPromise is the class for representing Promise values in C++ world. |
| +// ScriptPromise holds a Promise. |
| +// So holding ScriptPromise as a member variable causes memory leaks |
| +// since it has a reference from C++ to V8. |
| +// |
|
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!
|
| +class ScriptPromise { |
| public: |
| - virtual ~AnimatableUnknown() { } |
| + ScriptPromise() |
| + : m_promise() |
| + { |
| + } |
| - static PassRefPtr<AnimatableUnknown> create(PassRefPtr<CSSValue> value) |
| + explicit ScriptPromise(ScriptValue promise) |
| + : m_promise(promise) |
| { |
| - return adoptRef(new AnimatableUnknown(value)); |
| + ASSERT(!m_promise.hasNoValue()); |
| } |
| - PassRefPtr<CSSValue> toCSSValue() const { return m_value; } |
| + explicit ScriptPromise(v8::Handle<v8::Value> promise) |
| + : m_promise(promise) |
| + { |
| + ASSERT(!m_promise.hasNoValue()); |
| + } |
| -protected: |
| - virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue* value, double fraction) const OVERRIDE |
| + bool isObject() const |
| { |
| - return defaultInterpolateTo(this, value, fraction); |
| + return m_promise.isObject(); |
| } |
| - virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue* value) const OVERRIDE |
| + bool isNull() const |
| { |
| - return defaultAddWith(this, value); |
| + return m_promise.isNull(); |
| } |
| -private: |
| - explicit AnimatableUnknown(PassRefPtr<CSSValue> value) |
| - : AnimatableValue(TypeUnknown) |
| - , m_value(value) |
| + bool isUndefinedOrNull() const |
| { |
| - ASSERT(m_value); |
| + return m_promise.isUndefined() || m_promise.isNull(); |
| } |
| - const RefPtr<CSSValue> m_value; |
| -}; |
| + v8::Handle<v8::Value> v8Value() const |
| + { |
| + return m_promise.v8Value(); |
| + } |
| -inline const AnimatableUnknown* toAnimatableUnknown(const AnimatableValue* value) |
| -{ |
| - ASSERT_WITH_SECURITY_IMPLICATION(value && value->isUnknown()); |
| - return static_cast<const AnimatableUnknown*>(value); |
| -} |
| + void clear() |
| + { |
| + m_promise.clear(); |
| + } |
| + |
| +private: |
| + ScriptValue m_promise; |
| +}; |
| } // namespace WebCore |
| -#endif // AnimatableUnknown_h |
| + |
| +#endif // ScriptPromise_h |