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

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

Issue 2476393003: V8ObjectBuilder::addString support Nullable. (Closed)
Patch Set: Add V8ObjectBuilderTest 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
(...skipping 17 matching lines...) Expand all
28 : v8::False(m_scriptState->isolate())); 28 : v8::False(m_scriptState->isolate()));
29 return *this; 29 return *this;
30 } 30 }
31 31
32 V8ObjectBuilder& V8ObjectBuilder::addNumber(const String& name, double value) { 32 V8ObjectBuilder& V8ObjectBuilder::addNumber(const String& name, double value) {
33 addInternal(name, v8::Number::New(m_scriptState->isolate(), value)); 33 addInternal(name, v8::Number::New(m_scriptState->isolate(), value));
34 return *this; 34 return *this;
35 } 35 }
36 36
37 V8ObjectBuilder& V8ObjectBuilder::addString(const String& name, 37 V8ObjectBuilder& V8ObjectBuilder::addString(const String& name,
38 const String& value) { 38 const String& value,
39 addInternal(name, v8String(m_scriptState->isolate(), value)); 39 bool isNullable) {
40 if (isNullable && value.isNull()) {
41 addInternal(name, v8::Null(m_scriptState->isolate()));
42 } else {
43 addInternal(name, v8String(m_scriptState->isolate(), value));
44 }
40 return *this; 45 return *this;
41 } 46 }
42 47
43 ScriptValue V8ObjectBuilder::scriptValue() const { 48 ScriptValue V8ObjectBuilder::scriptValue() const {
44 return ScriptValue(m_scriptState.get(), m_object); 49 return ScriptValue(m_scriptState.get(), m_object);
45 } 50 }
46 51
47 void V8ObjectBuilder::addInternal(const String& name, 52 void V8ObjectBuilder::addInternal(const String& name,
48 v8::Local<v8::Value> value) { 53 v8::Local<v8::Value> value) {
49 if (m_object.IsEmpty()) 54 if (m_object.IsEmpty())
50 return; 55 return;
51 if (value.IsEmpty() || 56 if (value.IsEmpty() ||
52 m_object 57 m_object
53 ->CreateDataProperty(m_scriptState->context(), 58 ->CreateDataProperty(m_scriptState->context(),
54 v8String(m_scriptState->isolate(), name), value) 59 v8String(m_scriptState->isolate(), name), value)
55 .IsNothing()) 60 .IsNothing())
56 m_object.Clear(); 61 m_object.Clear();
57 } 62 }
58 63
59 } // namespace blink 64 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698