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..fa8d3ce8b5209d1c34d4bd20025ebfc1f2340738 |
--- /dev/null |
+++ b/Source/bindings/core/v8/V8ObjectBuilder.cpp |
@@ -0,0 +1,64 @@ |
+// 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())) |
+{ |
+} |
+ |
+ScriptValue V8ObjectBuilder::scriptValue() const |
+{ |
+ return ScriptValue(m_scriptState.get(), m_object); |
+} |
+ |
+V8ObjectBuilder& V8ObjectBuilder::add(String name, const ScriptValue& value) |
+{ |
+ add(name, value.v8Value()); |
+ return *this; |
+} |
+ |
+V8ObjectBuilder& V8ObjectBuilder::add(String name, const V8ObjectBuilder& value) |
+{ |
+ add(name, value.v8Value()); |
+ return *this; |
+} |
+ |
+V8ObjectBuilder& V8ObjectBuilder::addNull(String name) |
+{ |
+ add(name, v8::Null(m_scriptState->isolate())); |
+ return *this; |
+} |
+ |
+V8ObjectBuilder& V8ObjectBuilder::addBoolean(String name, bool value) |
+{ |
+ add(name, value ? v8::True(m_scriptState->isolate()) : v8::False(m_scriptState->isolate())); |
+ return *this; |
+} |
+ |
+V8ObjectBuilder& V8ObjectBuilder::addNumber(String name, double value) |
+{ |
+ add(name, v8::Number::New(m_scriptState->isolate(), value)); |
+ return *this; |
+} |
+ |
+V8ObjectBuilder& V8ObjectBuilder::addString(String name, String value) |
+{ |
+ add(name, v8String(m_scriptState->isolate(), value)); |
+ return *this; |
+} |
+ |
+void V8ObjectBuilder::add(String name, v8::Local<v8::Value> value) |
+{ |
+ m_object->ForceSet(m_scriptState->context(), v8String(m_scriptState->isolate(), name), value); |
bashi
2015/03/25 01:09:25
Just a note: In the future, we might want to provi
Jens Widell
2015/03/25 11:16:04
I implemented this with a slight variation: lettin
|
+} |
+ |
+} // namespace blink |