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 |