OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8ObjectBuilder_h | |
6 #define V8ObjectBuilder_h | |
7 | |
8 #include "bindings/core/v8/ToV8.h" | |
9 #include "platform/heap/Handle.h" | |
10 #include "wtf/text/WTFString.h" | |
11 #include <v8.h> | |
12 | |
13 namespace blink { | |
14 | |
15 class ScriptState; | |
16 class ScriptValue; | |
17 | |
18 class V8ObjectBuilder final { | |
19 STACK_ALLOCATED(); | |
20 public: | |
21 explicit V8ObjectBuilder(ScriptState*); | |
22 | |
23 ScriptState* scriptState() const { return m_scriptState.get(); } | |
24 | |
25 V8ObjectBuilder& add(String name, const V8ObjectBuilder&); | |
vivekg
2015/03/26 03:46:50
nit: Can we use `const String&` here and subsequen
| |
26 | |
27 V8ObjectBuilder& addNull(String name); | |
28 V8ObjectBuilder& addBoolean(String name, bool value); | |
29 V8ObjectBuilder& addNumber(String name, double value); | |
30 V8ObjectBuilder& addString(String name, String value); | |
31 | |
32 template <typename T> | |
33 V8ObjectBuilder& add(String name, const T& value) | |
34 { | |
35 addInternal(name, v8::Local<v8::Value>(toV8(value, m_scriptState->contex t()->Global(), m_scriptState->isolate()))); | |
36 return *this; | |
37 } | |
38 | |
39 ScriptValue scriptValue() const; | |
40 v8::Local<v8::Object> v8Value() const { return m_object; } | |
41 | |
42 private: | |
43 void addInternal(String name, v8::Local<v8::Value>); | |
44 | |
45 RefPtr<ScriptState> m_scriptState; | |
46 v8::Local<v8::Object> m_object; | |
47 }; | |
48 | |
49 } // namespace blink | |
50 | |
51 #endif // V8ObjectBuilder_h | |
OLD | NEW |