| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #ifndef ScriptValue_h | |
| 32 #define ScriptValue_h | |
| 33 | |
| 34 #include "bindings/common/AbstractScriptValue.h" | |
| 35 // FIXMEDART: Move this file to bindings/core/dart. | |
| 36 #include "bindings/core/dart/DartScriptValue.h" | |
| 37 #include "bindings/core/v8/SharedPersistent.h" | |
| 38 #include "bindings/core/v8/V8ScriptValue.h" | |
| 39 #include "wtf/PassRefPtr.h" | |
| 40 #include "wtf/RefPtr.h" | |
| 41 #include "wtf/text/WTFString.h" | |
| 42 #include <v8.h> | |
| 43 | |
| 44 namespace blink { | |
| 45 | |
| 46 class JSONValue; | |
| 47 class ScriptPromise; | |
| 48 class ScriptState; | |
| 49 class V8ScriptState; | |
| 50 | |
| 51 // Indirection to avoid re-writing the parts of Blink that pass ScriptValue by | |
| 52 // value. | |
| 53 // FIXME: Should change pass by value uses to pass by reference and use | |
| 54 // AbstractScriptValue directly. | |
| 55 class ScriptValue FINAL { | |
| 56 public: | |
| 57 ScriptValue() | |
| 58 : m_implScriptValue(V8ScriptValue::create()) | |
| 59 { | |
| 60 } | |
| 61 | |
| 62 ScriptValue(V8ScriptState* scriptState, v8::Handle<v8::Value> value) | |
| 63 : m_implScriptValue(V8ScriptValue::create(scriptState, value)) | |
| 64 { | |
| 65 } | |
| 66 | |
| 67 ScriptValue(const ScriptValue& value) | |
| 68 : m_implScriptValue(value.m_implScriptValue) | |
| 69 { | |
| 70 } | |
| 71 | |
| 72 ScriptValue(PassRefPtr<AbstractScriptValue> value) | |
| 73 : m_implScriptValue(value) | |
| 74 { | |
| 75 } | |
| 76 | |
| 77 ScriptState* scriptState() const | |
| 78 { | |
| 79 return m_implScriptValue->scriptState(); | |
| 80 } | |
| 81 | |
| 82 v8::Isolate* isolate() const | |
| 83 { | |
| 84 ASSERT(m_implScriptValue->isV8()); | |
| 85 return static_cast<V8ScriptValue*>(m_implScriptValue.get())->isolate(); | |
| 86 } | |
| 87 | |
| 88 // FIXMEMULTIVM: Remove. | |
| 89 v8::Handle<v8::Value> v8Value() const | |
| 90 { | |
| 91 if (m_implScriptValue->isV8()) { | |
| 92 return static_cast<V8ScriptValue*>(m_implScriptValue.get())->v8Value
(); | |
| 93 } | |
| 94 if (m_implScriptValue->isDart()) { | |
| 95 return static_cast<DartScriptValue*>(m_implScriptValue.get())->v8Val
ue(); | |
| 96 } | |
| 97 ASSERT_NOT_REACHED(); | |
| 98 return v8::Handle<v8::Value>(); | |
| 99 } | |
| 100 | |
| 101 v8::Handle<v8::Value> v8ValueUnsafe() const | |
| 102 { | |
| 103 ASSERT(m_implScriptValue->isV8()); | |
| 104 return static_cast<V8ScriptValue*>(m_implScriptValue.get())->v8ValueUnsa
fe(); | |
| 105 } | |
| 106 | |
| 107 ScriptValue& operator=(const ScriptValue& value) | |
| 108 { | |
| 109 if (this != &value) { | |
| 110 m_implScriptValue = value.m_implScriptValue; | |
| 111 } | |
| 112 return *this; | |
| 113 } | |
| 114 | |
| 115 bool operator==(const ScriptValue& value) const | |
| 116 { | |
| 117 return m_implScriptValue->equals(value.m_implScriptValue.get()); | |
| 118 } | |
| 119 | |
| 120 bool operator!=(const ScriptValue& value) const | |
| 121 { | |
| 122 return !operator==(value); | |
| 123 } | |
| 124 | |
| 125 // This creates a new local Handle; Don't use this in performance-sensitive
places. | |
| 126 bool isFunction() const | |
| 127 { | |
| 128 return m_implScriptValue->isFunction(); | |
| 129 } | |
| 130 | |
| 131 // This creates a new local Handle; Don't use this in performance-sensitive
places. | |
| 132 bool isNull() const | |
| 133 { | |
| 134 return m_implScriptValue->isNull(); | |
| 135 } | |
| 136 | |
| 137 // This creates a new local Handle; Don't use this in performance-sensitive
places. | |
| 138 bool isUndefined() const | |
| 139 { | |
| 140 return m_implScriptValue->isUndefined(); | |
| 141 } | |
| 142 | |
| 143 // This creates a new local Handle; Don't use this in performance-sensitive
places. | |
| 144 bool isObject() const | |
| 145 { | |
| 146 return m_implScriptValue->isObject(); | |
| 147 } | |
| 148 | |
| 149 bool isEmpty() const | |
| 150 { | |
| 151 return m_implScriptValue->isEmpty(); | |
| 152 } | |
| 153 | |
| 154 void clear() | |
| 155 { | |
| 156 return m_implScriptValue->clear(); | |
| 157 } | |
| 158 | |
| 159 bool toString(String& result) const | |
| 160 { | |
| 161 return m_implScriptValue->toString(result); | |
| 162 } | |
| 163 | |
| 164 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const; | |
| 165 ScriptPromise toPromise() const; | |
| 166 ScriptPromise toRejectedPromise() const; | |
| 167 | |
| 168 // FIXMEDART: Do we need this? If so, move to multivm. | |
| 169 AbstractScriptValue* scriptValue() const | |
| 170 { | |
| 171 return m_implScriptValue.get(); | |
| 172 } | |
| 173 | |
| 174 IDBKey* createIDBKeyFromKeyPath(const IDBKeyPath&) const; | |
| 175 bool canInjectIDBKey(const IDBKeyPath&) const; | |
| 176 IDBKey* toIDBKey() const; | |
| 177 IDBKeyRange* toIDBKeyRange() const; | |
| 178 | |
| 179 private: | |
| 180 RefPtr<AbstractScriptValue> m_implScriptValue; | |
| 181 }; | |
| 182 | |
| 183 } // namespace blink | |
| 184 | |
| 185 #endif // ScriptValue_h | |
| OLD | NEW |