Chromium Code Reviews| Index: Source/bindings/core/v8/V8ObjectBuilder.h |
| diff --git a/Source/bindings/core/v8/V8ObjectBuilder.h b/Source/bindings/core/v8/V8ObjectBuilder.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ac97f9e6563f51af87854d07ac5a673154a07fa1 |
| --- /dev/null |
| +++ b/Source/bindings/core/v8/V8ObjectBuilder.h |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef V8ObjectBuilder_h |
| +#define V8ObjectBuilder_h |
| + |
| +#include "bindings/core/v8/ToV8.h" |
| +#include "platform/heap/Handle.h" |
| +#include "wtf/text/WTFString.h" |
| +#include <v8.h> |
| + |
| +namespace blink { |
| + |
| +class ScriptState; |
| +class ScriptValue; |
| + |
| +class V8ObjectBuilder final { |
| + STACK_ALLOCATED(); |
| +public: |
| + explicit V8ObjectBuilder(ScriptState*); |
| + |
| + ScriptState* scriptState() const { return m_scriptState.get(); } |
| + |
| + V8ObjectBuilder& add(String name, const V8ObjectBuilder&); |
|
vivekg
2015/03/26 03:46:50
nit: Can we use `const String&` here and subsequen
|
| + |
| + V8ObjectBuilder& addNull(String name); |
| + V8ObjectBuilder& addBoolean(String name, bool value); |
| + V8ObjectBuilder& addNumber(String name, double value); |
| + V8ObjectBuilder& addString(String name, String value); |
| + |
| + template <typename T> |
| + V8ObjectBuilder& add(String name, const T& value) |
| + { |
| + addInternal(name, v8::Local<v8::Value>(toV8(value, m_scriptState->context()->Global(), m_scriptState->isolate()))); |
| + return *this; |
| + } |
| + |
| + ScriptValue scriptValue() const; |
| + v8::Local<v8::Object> v8Value() const { return m_object; } |
| + |
| +private: |
| + void addInternal(String name, v8::Local<v8::Value>); |
| + |
| + RefPtr<ScriptState> m_scriptState; |
| + v8::Local<v8::Object> m_object; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // V8ObjectBuilder_h |