| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8ObjectBuilder_h | 5 #ifndef V8ObjectBuilder_h |
| 6 #define V8ObjectBuilder_h | 6 #define V8ObjectBuilder_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ToV8.h" | 8 #include "bindings/core/v8/ToV8.h" |
| 9 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
| 10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 11 #include "wtf/text/WTFString.h" | 11 #include "wtf/text/WTFString.h" |
| 12 #include <v8.h> | 12 #include <v8.h> |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 class ScriptState; | 16 class ScriptState; |
| 17 class ScriptValue; | 17 class ScriptValue; |
| 18 | 18 |
| 19 class CORE_EXPORT V8ObjectBuilder final { | 19 class CORE_EXPORT V8ObjectBuilder final { |
| 20 STACK_ALLOCATED(); | 20 STACK_ALLOCATED(); |
| 21 public: | 21 public: |
| 22 explicit V8ObjectBuilder(ScriptState*); | 22 explicit V8ObjectBuilder(ScriptState*); |
| 23 | 23 |
| 24 ScriptState* scriptState() const { return m_scriptState.get(); } | 24 ScriptState* getScriptState() const { return m_scriptState.get(); } |
| 25 | 25 |
| 26 V8ObjectBuilder& add(const String& name, const V8ObjectBuilder&); | 26 V8ObjectBuilder& add(const String& name, const V8ObjectBuilder&); |
| 27 | 27 |
| 28 V8ObjectBuilder& addNull(const String& name); | 28 V8ObjectBuilder& addNull(const String& name); |
| 29 V8ObjectBuilder& addBoolean(const String& name, bool value); | 29 V8ObjectBuilder& addBoolean(const String& name, bool value); |
| 30 V8ObjectBuilder& addNumber(const String& name, double value); | 30 V8ObjectBuilder& addNumber(const String& name, double value); |
| 31 V8ObjectBuilder& addString(const String& name, const String& value); | 31 V8ObjectBuilder& addString(const String& name, const String& value); |
| 32 | 32 |
| 33 template <typename T> | 33 template <typename T> |
| 34 V8ObjectBuilder& add(const String& name, const T& value) | 34 V8ObjectBuilder& add(const String& name, const T& value) |
| 35 { | 35 { |
| 36 addInternal(name, v8::Local<v8::Value>(toV8(value, m_scriptState->contex
t()->Global(), m_scriptState->isolate()))); | 36 addInternal(name, v8::Local<v8::Value>(toV8(value, m_scriptState->contex
t()->Global(), m_scriptState->isolate()))); |
| 37 return *this; | 37 return *this; |
| 38 } | 38 } |
| 39 | 39 |
| 40 ScriptValue scriptValue() const; | 40 ScriptValue scriptValue() const; |
| 41 v8::Local<v8::Object> v8Value() const { return m_object; } | 41 v8::Local<v8::Object> v8Value() const { return m_object; } |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 void addInternal(const String& name, v8::Local<v8::Value>); | 44 void addInternal(const String& name, v8::Local<v8::Value>); |
| 45 | 45 |
| 46 RefPtr<ScriptState> m_scriptState; | 46 RefPtr<ScriptState> m_scriptState; |
| 47 v8::Local<v8::Object> m_object; | 47 v8::Local<v8::Object> m_object; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 } // namespace blink | 50 } // namespace blink |
| 51 | 51 |
| 52 #endif // V8ObjectBuilder_h | 52 #endif // V8ObjectBuilder_h |
| OLD | NEW |