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

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

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/V8ObjectBuilder.h ('k') | Source/bindings/core/v8/v8.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/V8ObjectBuilder.cpp
diff --git a/Source/bindings/core/v8/V8ObjectBuilder.cpp b/Source/bindings/core/v8/V8ObjectBuilder.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e1aaf2cf498321460e3f22a9ce675fd1bd2dbce0
--- /dev/null
+++ b/Source/bindings/core/v8/V8ObjectBuilder.cpp
@@ -0,0 +1,61 @@
+// 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.
+
+#include "config.h"
+#include "bindings/core/v8/V8ObjectBuilder.h"
+
+#include "bindings/core/v8/V8Binding.h"
+
+namespace blink {
+
+V8ObjectBuilder::V8ObjectBuilder(ScriptState* scriptState)
+ : m_scriptState(scriptState)
+ , m_object(v8::Object::New(scriptState->isolate()))
+{
+}
+
+V8ObjectBuilder& V8ObjectBuilder::add(const String& name, const V8ObjectBuilder& value)
+{
+ addInternal(name, value.v8Value());
+ return *this;
+}
+
+V8ObjectBuilder& V8ObjectBuilder::addNull(const String& name)
+{
+ addInternal(name, v8::Null(m_scriptState->isolate()));
+ return *this;
+}
+
+V8ObjectBuilder& V8ObjectBuilder::addBoolean(const String& name, bool value)
+{
+ addInternal(name, value ? v8::True(m_scriptState->isolate()) : v8::False(m_scriptState->isolate()));
+ return *this;
+}
+
+V8ObjectBuilder& V8ObjectBuilder::addNumber(const String& name, double value)
+{
+ addInternal(name, v8::Number::New(m_scriptState->isolate(), value));
+ return *this;
+}
+
+V8ObjectBuilder& V8ObjectBuilder::addString(const String& name, const String& value)
+{
+ addInternal(name, v8String(m_scriptState->isolate(), value));
+ return *this;
+}
+
+ScriptValue V8ObjectBuilder::scriptValue() const
+{
+ return ScriptValue(m_scriptState.get(), m_object);
+}
+
+void V8ObjectBuilder::addInternal(const String& name, v8::Local<v8::Value> value)
+{
+ if (m_object.IsEmpty())
+ return;
+ if (value.IsEmpty() || m_object->ForceSet(m_scriptState->context(), v8String(m_scriptState->isolate(), name), value).IsNothing())
+ m_object.Clear();
+}
+
+} // namespace blink
« no previous file with comments | « Source/bindings/core/v8/V8ObjectBuilder.h ('k') | Source/bindings/core/v8/v8.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698