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 | 21 |
22 public: | 22 public: |
23 explicit V8ObjectBuilder(ScriptState*); | 23 explicit V8ObjectBuilder(ScriptState*); |
24 | 24 |
25 ScriptState* getScriptState() const { return m_scriptState.get(); } | 25 ScriptState* getScriptState() const { return m_scriptState.get(); } |
26 | 26 |
27 V8ObjectBuilder& add(const String& name, const V8ObjectBuilder&); | 27 V8ObjectBuilder& add(const StringView& name, const V8ObjectBuilder&); |
28 | 28 |
29 V8ObjectBuilder& addNull(const String& name); | 29 V8ObjectBuilder& addNull(const StringView& name); |
30 V8ObjectBuilder& addBoolean(const String& name, bool value); | 30 V8ObjectBuilder& addBoolean(const StringView& name, bool value); |
31 V8ObjectBuilder& addNumber(const String& name, double value); | 31 V8ObjectBuilder& addNumber(const StringView& name, double value); |
32 V8ObjectBuilder& addString(const String& name, const String& value); | 32 V8ObjectBuilder& addString(const StringView& name, const StringView& value); |
| 33 V8ObjectBuilder& addStringOrNull(const StringView& name, |
| 34 const StringView& value); |
33 | 35 |
34 template <typename T> | 36 template <typename T> |
35 V8ObjectBuilder& add(const String& name, const T& value) { | 37 V8ObjectBuilder& add(const StringView& name, const T& value) { |
36 addInternal(name, v8::Local<v8::Value>( | 38 addInternal(name, v8::Local<v8::Value>( |
37 toV8(value, m_scriptState->context()->Global(), | 39 toV8(value, m_scriptState->context()->Global(), |
38 m_scriptState->isolate()))); | 40 m_scriptState->isolate()))); |
39 return *this; | 41 return *this; |
40 } | 42 } |
41 | 43 |
42 ScriptValue scriptValue() const; | 44 ScriptValue scriptValue() const; |
43 v8::Local<v8::Object> v8Value() const { return m_object; } | 45 v8::Local<v8::Object> v8Value() const { return m_object; } |
44 | 46 |
45 private: | 47 private: |
46 void addInternal(const String& name, v8::Local<v8::Value>); | 48 void addInternal(const StringView& name, v8::Local<v8::Value>); |
47 | 49 |
48 RefPtr<ScriptState> m_scriptState; | 50 RefPtr<ScriptState> m_scriptState; |
49 v8::Local<v8::Object> m_object; | 51 v8::Local<v8::Object> m_object; |
50 }; | 52 }; |
51 | 53 |
52 } // namespace blink | 54 } // namespace blink |
53 | 55 |
54 #endif // V8ObjectBuilder_h | 56 #endif // V8ObjectBuilder_h |
OLD | NEW |