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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8ObjectBuilder.cpp

Issue 2476393003: V8ObjectBuilder::addString support Nullable. (Closed)
Patch Set: Fix nit. Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "bindings/core/v8/V8ObjectBuilder.h" 5 #include "bindings/core/v8/V8ObjectBuilder.h"
6 6
7 #include "bindings/core/v8/V8Binding.h" 7 #include "bindings/core/v8/V8Binding.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
11 V8ObjectBuilder::V8ObjectBuilder(ScriptState* scriptState) 11 V8ObjectBuilder::V8ObjectBuilder(ScriptState* scriptState)
12 : m_scriptState(scriptState), 12 : m_scriptState(scriptState),
13 m_object(v8::Object::New(scriptState->isolate())) {} 13 m_object(v8::Object::New(scriptState->isolate())) {}
14 14
15 V8ObjectBuilder& V8ObjectBuilder::add(const String& name, 15 V8ObjectBuilder& V8ObjectBuilder::add(const StringView& name,
16 const V8ObjectBuilder& value) { 16 const V8ObjectBuilder& value) {
17 addInternal(name, value.v8Value()); 17 addInternal(name, value.v8Value());
18 return *this; 18 return *this;
19 } 19 }
20 20
21 V8ObjectBuilder& V8ObjectBuilder::addNull(const String& name) { 21 V8ObjectBuilder& V8ObjectBuilder::addNull(const StringView& name) {
22 addInternal(name, v8::Null(m_scriptState->isolate())); 22 addInternal(name, v8::Null(m_scriptState->isolate()));
23 return *this; 23 return *this;
24 } 24 }
25 25
26 V8ObjectBuilder& V8ObjectBuilder::addBoolean(const String& name, bool value) { 26 V8ObjectBuilder& V8ObjectBuilder::addBoolean(const StringView& name,
27 bool value) {
27 addInternal(name, value ? v8::True(m_scriptState->isolate()) 28 addInternal(name, value ? v8::True(m_scriptState->isolate())
28 : v8::False(m_scriptState->isolate())); 29 : v8::False(m_scriptState->isolate()));
29 return *this; 30 return *this;
30 } 31 }
31 32
32 V8ObjectBuilder& V8ObjectBuilder::addNumber(const String& name, double value) { 33 V8ObjectBuilder& V8ObjectBuilder::addNumber(const StringView& name,
34 double value) {
33 addInternal(name, v8::Number::New(m_scriptState->isolate(), value)); 35 addInternal(name, v8::Number::New(m_scriptState->isolate(), value));
34 return *this; 36 return *this;
35 } 37 }
36 38
37 V8ObjectBuilder& V8ObjectBuilder::addString(const String& name, 39 V8ObjectBuilder& V8ObjectBuilder::addString(const StringView& name,
38 const String& value) { 40 const StringView& value) {
39 addInternal(name, v8String(m_scriptState->isolate(), value)); 41 addInternal(name, v8String(m_scriptState->isolate(), value));
40 return *this; 42 return *this;
41 } 43 }
42 44
45 V8ObjectBuilder& V8ObjectBuilder::addStringOrNull(const StringView& name,
46 const StringView& value) {
47 if (value.isNull()) {
48 addInternal(name, v8::Null(m_scriptState->isolate()));
49 } else {
50 addInternal(name, v8String(m_scriptState->isolate(), value));
51 }
52 return *this;
53 }
54
43 ScriptValue V8ObjectBuilder::scriptValue() const { 55 ScriptValue V8ObjectBuilder::scriptValue() const {
44 return ScriptValue(m_scriptState.get(), m_object); 56 return ScriptValue(m_scriptState.get(), m_object);
45 } 57 }
46 58
47 void V8ObjectBuilder::addInternal(const String& name, 59 void V8ObjectBuilder::addInternal(const StringView& name,
48 v8::Local<v8::Value> value) { 60 v8::Local<v8::Value> value) {
49 if (m_object.IsEmpty()) 61 if (m_object.IsEmpty())
50 return; 62 return;
51 if (value.IsEmpty() || 63 if (value.IsEmpty() ||
52 m_object 64 m_object
53 ->CreateDataProperty(m_scriptState->context(), 65 ->CreateDataProperty(m_scriptState->context(),
54 v8String(m_scriptState->isolate(), name), value) 66 v8String(m_scriptState->isolate(), name), value)
55 .IsNothing()) 67 .IsNothing())
56 m_object.Clear(); 68 m_object.Clear();
57 } 69 }
58 70
59 } // namespace blink 71 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698