Chromium Code Reviews| Index: Source/bindings/dart/DartScriptValue.h |
| diff --git a/Source/bindings/dart/DartScriptValue.h b/Source/bindings/dart/DartScriptValue.h |
| index 4da4128a7c05f3d9e3e7cf26db55b611b1456440..8fcaee87cc6b0b7fe9c7808444b5e55ef885243d 100644 |
| --- a/Source/bindings/dart/DartScriptValue.h |
| +++ b/Source/bindings/dart/DartScriptValue.h |
| @@ -1,5 +1,5 @@ |
| /* |
| - * Copyright (C) 2012 Google Inc. All rights reserved. |
| + * Copyright (C) 2014 Google Inc. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are |
| @@ -31,26 +31,120 @@ |
| #ifndef DartScriptValue_h |
| #define DartScriptValue_h |
| -#include "bindings/dart/DartIsolateDestructionObserver.h" |
| - |
| +#include "bindings/common/AbstractScriptValue.h" |
| +#include "bindings/dart/V8Converter.h" |
| +#include "wtf/PassRefPtr.h" |
| +#include "wtf/RefPtr.h" |
| +#include "wtf/text/WTFString.h" |
| #include <dart_api.h> |
| -#include <wtf/Noncopyable.h> |
| -#include <wtf/RefPtr.h> |
| namespace WebCore { |
| -class DartScriptValue : public DartIsolateDestructionObserver { |
| +class JSONValue; |
| +class ScriptState; |
| + |
| +class DartScriptValue : public AbstractScriptValue { |
| WTF_MAKE_NONCOPYABLE(DartScriptValue); |
| public: |
| - explicit DartScriptValue(Dart_Handle value); |
| - ~DartScriptValue(); |
| + virtual ~DartScriptValue(); |
| + |
| + static PassRefPtr<DartScriptValue> create(Dart_Handle value) |
| + { |
| + return adoptRef(new DartScriptValue(value)); |
| + } |
| + |
| + static PassRefPtr<DartScriptValue> create() |
| + { |
| + return adoptRef(new DartScriptValue()); |
| + } |
| + |
| + bool isV8() const { return false; } |
|
siva
2014/05/21 21:56:17
Is this needed? AbstractScriptValue already has th
rmacnak
2014/05/22 20:27:19
Removed.
|
| + bool isDart() const { return true; } |
| + |
| + Dart_Handle dartValue() const { return m_value; } |
| + |
| + v8::Handle<v8::Value> v8Value() const |
| + { |
| + // FIXMEMUTLIVM: Should not be converting v8 values. Major culprit is IDB. |
| + Dart_Handle exception = 0; |
| + return V8Converter::toV8(m_value, exception); |
| + } |
| + |
| + bool equals(AbstractScriptValue* other) const |
| + { |
| + if (!other->isDart()) |
| + return false; |
| + |
| + DartScriptValue* dartOther = static_cast<DartScriptValue*>(other); |
| + if (hasNoValue()) |
| + return dartOther->hasNoValue(); |
| + if (dartOther->hasNoValue()) |
| + return false; |
| + return Dart_IdentityEquals(m_value, dartOther->m_value); |
| + } |
| + |
| + bool isEqual(ScriptState*, const DartScriptValue& other) const |
|
siva
2014/05/21 21:56:17
Why do we have this unused parameter ScriptState*
rmacnak
2014/05/22 20:27:19
Hm, isEqual is is no longer used and is already re
|
| + { |
| + if (hasNoValue()) |
| + return other.hasNoValue(); |
| + if (other.hasNoValue()) |
| + return false; |
| + return Dart_IdentityEquals(m_value, other.m_value); |
| + } |
| - Dart_PersistentHandle value() { return m_value; } |
| + bool isFunction() const |
| + { |
| + ASSERT(!hasNoValue()); |
| + return Dart_IsClosure(m_value); |
| + } |
| + |
| + bool isNull() const |
| + { |
| + ASSERT(!hasNoValue()); |
| + return Dart_IsNull(m_value); |
| + } |
| + |
| + bool isUndefined() const |
| + { |
| + ASSERT(!hasNoValue()); |
| + return false; |
| + } |
| + |
| + bool isObject() const |
| + { |
| + ASSERT(!hasNoValue()); |
| + return true; |
| + } |
| + |
| + bool hasNoValue() const |
| + { |
| + return !m_value; |
| + } |
| + |
| + void clear() |
| + { |
| + m_value = 0; |
| + } |
| + |
| + bool getString(String& result) const; |
| + String toString() const; |
| + |
| + PassRefPtr<JSONValue> toJSONValue(ScriptState*) const; |
| private: |
| - Dart_PersistentHandle m_value; |
| + Dart_Handle m_value; |
| + |
| + explicit DartScriptValue() |
| + : m_value(0) |
| + { |
| + } |
| + |
| + explicit DartScriptValue(Dart_Handle value) |
| + : m_value(value) |
| + { |
| + } |
| }; |
| -} |
| +} // namespace WebCore |
| #endif // DartScriptValue_h |