Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 34 #include "bindings/core/v8/ScriptState.h" | 34 #include "bindings/core/v8/ScriptState.h" |
| 35 #include "bindings/core/v8/SharedPersistent.h" | 35 #include "bindings/core/v8/SharedPersistent.h" |
| 36 #include "core/CoreExport.h" | 36 #include "core/CoreExport.h" |
| 37 #include "wtf/PassRefPtr.h" | 37 #include "wtf/PassRefPtr.h" |
| 38 #include "wtf/RefPtr.h" | 38 #include "wtf/RefPtr.h" |
| 39 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
| 40 #include <v8.h> | 40 #include <v8.h> |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 class ExceptionState; | |
| 44 class JSONValue; | 45 class JSONValue; |
| 45 | 46 |
| 47 template <typename T> | |
| 48 T script_value_cast(const v8::Local<v8::Value>&, v8::Isolate*, ExceptionState&); | |
| 49 | |
| 46 class CORE_EXPORT ScriptValue final { | 50 class CORE_EXPORT ScriptValue final { |
| 47 public: | 51 public: |
| 48 template<typename T> | 52 template<typename T> |
| 49 static ScriptValue from(ScriptState* scriptState, T value) | 53 static ScriptValue from(ScriptState* scriptState, T value) |
| 50 { | 54 { |
| 51 return ScriptValue(scriptState, toV8(value, scriptState->context()->Glob al(), scriptState->isolate())); | 55 return ScriptValue(scriptState, toV8(value, scriptState->context()->Glob al(), scriptState->isolate())); |
| 52 } | 56 } |
| 53 | 57 |
| 58 template<typename T> | |
| 59 T to(ExceptionState& exceptionState) const | |
| 60 { | |
| 61 return script_value_cast<T>(v8Value(), isolate(), exceptionState); | |
|
haraken
2015/03/14 01:27:19
I'm wondering why we cannot simply call:
Native
| |
| 62 } | |
| 63 | |
| 54 ScriptValue() { } | 64 ScriptValue() { } |
| 55 | 65 |
| 56 ScriptValue(ScriptState* scriptState, v8::Handle<v8::Value> value) | 66 ScriptValue(ScriptState* scriptState, v8::Handle<v8::Value> value) |
| 57 : m_scriptState(scriptState) | 67 : m_scriptState(scriptState) |
| 58 , m_value(value.IsEmpty() ? nullptr : SharedPersistent<v8::Value>::creat e(value, scriptState->isolate())) | 68 , m_value(value.IsEmpty() ? nullptr : SharedPersistent<v8::Value>::creat e(value, scriptState->isolate())) |
| 59 { | 69 { |
| 60 ASSERT(isEmpty() || m_scriptState); | 70 ASSERT(isEmpty() || m_scriptState); |
| 61 } | 71 } |
| 62 | 72 |
| 63 ScriptValue(const ScriptValue& value) | 73 ScriptValue(const ScriptValue& value) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 static ScriptValue createNull(ScriptState*); | 161 static ScriptValue createNull(ScriptState*); |
| 152 | 162 |
| 153 private: | 163 private: |
| 154 RefPtr<ScriptState> m_scriptState; | 164 RefPtr<ScriptState> m_scriptState; |
| 155 RefPtr<SharedPersistent<v8::Value>> m_value; | 165 RefPtr<SharedPersistent<v8::Value>> m_value; |
| 156 }; | 166 }; |
| 157 | 167 |
| 158 } // namespace blink | 168 } // namespace blink |
| 159 | 169 |
| 160 #endif // ScriptValue_h | 170 #endif // ScriptValue_h |
| OLD | NEW |