Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Unified Diff: Source/bindings/core/v8/V8ObjectBuilder.h

Issue 1031783003: Add V8ObjectBuilder helper and use in modules/crypto/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: use "const String&" Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/core/v8/Dictionary.cpp ('k') | Source/bindings/core/v8/V8ObjectBuilder.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e72cfe725d7e5722348db02ee167874b2a529747
--- /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(const String& name, const V8ObjectBuilder&);
+
+ V8ObjectBuilder& addNull(const String& name);
+ V8ObjectBuilder& addBoolean(const String& name, bool value);
+ V8ObjectBuilder& addNumber(const String& name, double value);
+ V8ObjectBuilder& addString(const String& name, const String& value);
+
+ template <typename T>
+ V8ObjectBuilder& add(const 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(const String& name, v8::Local<v8::Value>);
+
+ RefPtr<ScriptState> m_scriptState;
+ v8::Local<v8::Object> m_object;
+};
+
+} // namespace blink
+
+#endif // V8ObjectBuilder_h
« no previous file with comments | « Source/bindings/core/v8/Dictionary.cpp ('k') | Source/bindings/core/v8/V8ObjectBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698