| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 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 13 matching lines...) Expand all Loading... |
| 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 ScriptValue_h | 31 #ifndef ScriptValue_h |
| 32 #define ScriptValue_h | 32 #define ScriptValue_h |
| 33 | 33 |
| 34 #include "bindings/core/v8/NativeValueTraits.h" |
| 34 #include "bindings/core/v8/ScriptState.h" | 35 #include "bindings/core/v8/ScriptState.h" |
| 35 #include "bindings/core/v8/SharedPersistent.h" | 36 #include "bindings/core/v8/SharedPersistent.h" |
| 36 #include "core/CoreExport.h" | 37 #include "core/CoreExport.h" |
| 37 #include "wtf/PassRefPtr.h" | 38 #include "wtf/PassRefPtr.h" |
| 38 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
| 39 #include "wtf/text/WTFString.h" | 40 #include "wtf/text/WTFString.h" |
| 40 #include <v8.h> | 41 #include <v8.h> |
| 41 | 42 |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 44 class JSONValue; | 45 class JSONValue; |
| 45 | 46 |
| 46 class CORE_EXPORT ScriptValue final { | 47 class CORE_EXPORT ScriptValue final { |
| 47 public: | 48 public: |
| 48 template<typename T> | 49 template<typename T> |
| 49 static ScriptValue from(ScriptState* scriptState, T value) | 50 static ScriptValue from(ScriptState* scriptState, T value) |
| 50 { | 51 { |
| 51 return ScriptValue(scriptState, toV8(value, scriptState->context()->Glob
al(), scriptState->isolate())); | 52 return ScriptValue(scriptState, toV8(value, scriptState->context()->Glob
al(), scriptState->isolate())); |
| 52 } | 53 } |
| 53 | 54 |
| 55 template<typename T> |
| 56 inline T to(ExceptionState& exceptionState) const |
| 57 { |
| 58 return NativeValueTraits<T>::nativeValue(v8Value(), isolate(), exception
State); |
| 59 } |
| 60 |
| 54 ScriptValue() { } | 61 ScriptValue() { } |
| 55 | 62 |
| 56 ScriptValue(ScriptState* scriptState, v8::Handle<v8::Value> value) | 63 ScriptValue(ScriptState* scriptState, v8::Handle<v8::Value> value) |
| 57 : m_scriptState(scriptState) | 64 : m_scriptState(scriptState) |
| 58 , m_value(value.IsEmpty() ? nullptr : SharedPersistent<v8::Value>::creat
e(value, scriptState->isolate())) | 65 , m_value(value.IsEmpty() ? nullptr : SharedPersistent<v8::Value>::creat
e(value, scriptState->isolate())) |
| 59 { | 66 { |
| 60 ASSERT(isEmpty() || m_scriptState); | 67 ASSERT(isEmpty() || m_scriptState); |
| 61 } | 68 } |
| 62 | 69 |
| 63 ScriptValue(const ScriptValue& value) | 70 ScriptValue(const ScriptValue& value) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 static ScriptValue createNull(ScriptState*); | 158 static ScriptValue createNull(ScriptState*); |
| 152 | 159 |
| 153 private: | 160 private: |
| 154 RefPtr<ScriptState> m_scriptState; | 161 RefPtr<ScriptState> m_scriptState; |
| 155 RefPtr<SharedPersistent<v8::Value>> m_value; | 162 RefPtr<SharedPersistent<v8::Value>> m_value; |
| 156 }; | 163 }; |
| 157 | 164 |
| 158 } // namespace blink | 165 } // namespace blink |
| 159 | 166 |
| 160 #endif // ScriptValue_h | 167 #endif // ScriptValue_h |
| OLD | NEW |