Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / v8 / ScriptValue.h
index 15f42b7..80bfc04 100644 (file)
@@ -31,6 +31,7 @@
 #ifndef ScriptValue_h
 #define ScriptValue_h
 
+#include "bindings/v8/ScriptState.h"
 #include "bindings/v8/SharedPersistent.h"
 #include "wtf/PassRefPtr.h"
 #include "wtf/RefPtr.h"
 namespace WebCore {
 
 class JSONValue;
-class ScriptState;
 
 class ScriptValue {
 public:
     ScriptValue()
         : m_isolate(0)
-    { }
+        , m_scriptState(nullptr)
+    {
+    }
 
     virtual ~ScriptValue();
 
+    // FIXME: This method is deprecated and will be removed soon.
+    // We should always pass a ScriptState when creating a new ScriptValue.
     ScriptValue(v8::Handle<v8::Value> value, v8::Isolate* isolate)
         : m_isolate(isolate)
+        , m_scriptState(nullptr)
         , m_value(value.IsEmpty() ? nullptr : SharedPersistent<v8::Value>::create(value, isolate))
     {
     }
 
+    ScriptValue(ScriptState* scriptState, v8::Handle<v8::Value> value)
+        : m_isolate(scriptState->isolate())
+        , m_scriptState(scriptState)
+        , m_value(value.IsEmpty() ? nullptr : SharedPersistent<v8::Value>::create(value, scriptState->isolate()))
+    {
+    }
+
     ScriptValue(const ScriptValue& value)
         : m_isolate(value.m_isolate)
+        , m_scriptState(value.m_scriptState)
         , m_value(value.m_value)
     {
     }
 
+    ScriptState* scriptState() const
+    {
+        return m_scriptState.get();
+    }
+
     v8::Isolate* isolate() const
     {
         if (!m_isolate)
@@ -69,82 +87,63 @@ public:
         return m_isolate;
     }
 
-    static ScriptValue createNull()
-    {
-        v8::Isolate* isolate = v8::Isolate::GetCurrent();
-        return ScriptValue(v8::Null(isolate), isolate);
-    }
-    static ScriptValue createBoolean(bool b)
-    {
-        v8::Isolate* isolate = v8::Isolate::GetCurrent();
-        return ScriptValue(b ? v8::True(isolate) : v8::False(isolate), isolate);
-    }
-
     ScriptValue& operator=(const ScriptValue& value)
     {
         if (this != &value) {
-            m_value = value.m_value;
             m_isolate = value.m_isolate;
+            m_scriptState = value.m_scriptState;
+            m_value = value.m_value;
         }
         return *this;
     }
 
     bool operator==(const ScriptValue& value) const
     {
-        if (hasNoValue())
-            return value.hasNoValue();
-        if (value.hasNoValue())
+        if (isEmpty())
+            return value.isEmpty();
+        if (value.isEmpty())
             return false;
         return *m_value == *value.m_value;
     }
 
-    bool isEqual(ScriptState*, const ScriptValue& value) const
+    bool operator!=(const ScriptValue& value) const
     {
-        return operator==(value);
+        return !operator==(value);
     }
 
-    // Note: This creates a new local Handle; not to be used in cases where is
-    // is an efficiency problem.
+    // This creates a new local Handle; Don't use this in performance-sensitive places.
     bool isFunction() const
     {
-        ASSERT(!hasNoValue());
+        ASSERT(!isEmpty());
         v8::Handle<v8::Value> value = v8Value();
         return !value.IsEmpty() && value->IsFunction();
     }
 
-    bool operator!=(const ScriptValue& value) const
-    {
-        return !operator==(value);
-    }
-
-    // Note: This creates a new local Handle; not to be used in cases where is
-    // is an efficiency problem.
+    // This creates a new local Handle; Don't use this in performance-sensitive places.
     bool isNull() const
     {
-        ASSERT(!hasNoValue());
+        ASSERT(!isEmpty());
         v8::Handle<v8::Value> value = v8Value();
         return !value.IsEmpty() && value->IsNull();
     }
 
-    // Note: This creates a new local Handle; not to be used in cases where is
-    // is an efficiency problem.
+    // This creates a new local Handle; Don't use this in performance-sensitive places.
     bool isUndefined() const
     {
-        ASSERT(!hasNoValue());
+        ASSERT(!isEmpty());
         v8::Handle<v8::Value> value = v8Value();
         return !value.IsEmpty() && value->IsUndefined();
     }
 
-    // Note: This creates a new local Handle; not to be used in cases where is
-    // is an efficiency problem.
+    // This creates a new local Handle; Don't use this in performance-sensitive places.
     bool isObject() const
     {
-        ASSERT(!hasNoValue());
+        ASSERT(!isEmpty());
         v8::Handle<v8::Value> value = v8Value();
         return !value.IsEmpty() && value->IsObject();
     }
 
-    bool hasNoValue() const
+    bool isEmpty() const
     {
         return !m_value.get() || m_value->isEmpty();
     }
@@ -156,16 +155,17 @@ public:
 
     v8::Handle<v8::Value> v8Value() const
     {
-        return m_value.get() ? m_value->newLocal(m_isolate) : v8::Handle<v8::Value>();
+        return m_value.get() ? m_value->newLocal(isolate()) : v8::Handle<v8::Value>();
     }
 
-    bool getString(String& result) const;
-    String toString() const;
-
+    bool toString(String&) const;
     PassRefPtr<JSONValue> toJSONValue(ScriptState*) const;
 
 private:
     mutable v8::Isolate* m_isolate;
+    // FIXME: m_scriptState is not yet used.
+    // We will start using it once we remove ScriptValue(v8::Handle<v8::Value> value, v8::Isolate* isolate).
+    mutable RefPtr<ScriptState> m_scriptState;
     RefPtr<SharedPersistent<v8::Value> > m_value;
 };