Chromium Code Reviews| 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..30d0a996fcfbcc045c8a71fb9280bf1c0e7b549f |
| --- /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(v8::Isolate* isolate) |
| + : m_isolate(isolate) |
| + , m_object(v8::Object::New(isolate)) |
| +{ |
| +} |
| + |
| +ScriptValue V8ObjectBuilder::scriptValue() const |
| +{ |
| + return ScriptValue(ScriptState::current(m_isolate), m_object); |
|
haraken
2015/03/24 14:33:32
Using ScriptState::current is not nice, since the
Jens Widell
2015/03/24 15:16:29
Done.
The constructor now takes (and stores) a Sc
|
| +} |
| + |
| +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_isolate)); |
| + return *this; |
| +} |
| + |
| +V8ObjectBuilder& V8ObjectBuilder::addBoolean(String name, bool value) |
| +{ |
| + add(name, value ? v8::True(m_isolate) : v8::False(m_isolate)); |
| + return *this; |
| +} |
| + |
| +V8ObjectBuilder& V8ObjectBuilder::addNumber(String name, double value) |
| +{ |
| + add(name, v8::Number::New(m_isolate, value)); |
| + return *this; |
| +} |
| + |
| +V8ObjectBuilder& V8ObjectBuilder::addString(String name, String value) |
| +{ |
| + add(name, v8String(m_isolate, value)); |
| + return *this; |
| +} |
| + |
| +void V8ObjectBuilder::add(String name, v8::Local<v8::Value> value) |
| +{ |
| + m_object->ForceSet(m_isolate->GetCurrentContext(), v8String(m_isolate, name), value); |
|
haraken
2015/03/24 14:33:32
Why do we use ForceSet, not Set?
haraken
2015/03/24 14:33:33
Also we should use m_scriptState->context().
Jens Widell
2015/03/24 14:38:40
Web IDL uses [[DefineOwnProperty]] to describe ECM
Jens Widell
2015/03/24 15:16:29
Done.
|
| +} |
| + |
| +} // namespace blink |