Skip to content

Commit

Permalink
Remove more usage of the base::ListValue::Append(Value*) overload.
Browse files Browse the repository at this point in the history
This overload is deprecated: prefer the std::unique_ptr<Value> version,
which helps the compiler enforce that ownership transfer occurs.

BUG=581865
R=danakj@chromium.org
TBR=brettw@chromium.org

Review-Url: https://codereview.chromium.org/2285933003
Cr-Commit-Position: refs/heads/master@{#417396}
  • Loading branch information
zetafunction authored and Commit bot committed Sep 8, 2016
1 parent 78395bc commit 031a8f8
Show file tree
Hide file tree
Showing 28 changed files with 170 additions and 163 deletions.
40 changes: 20 additions & 20 deletions base/json/json_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ bool JSONParser::EatComment() {
return false;
}

Value* JSONParser::ParseNextToken() {
std::unique_ptr<Value> JSONParser::ParseNextToken() {
return ParseToken(GetNextToken());
}

Value* JSONParser::ParseToken(Token token) {
std::unique_ptr<Value> JSONParser::ParseToken(Token token) {
switch (token) {
case T_OBJECT_BEGIN:
return ConsumeDictionary();
Expand All @@ -491,7 +491,7 @@ Value* JSONParser::ParseToken(Token token) {
}
}

Value* JSONParser::ConsumeDictionary() {
std::unique_ptr<Value> JSONParser::ConsumeDictionary() {
if (*pos_ != '{') {
ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1);
return nullptr;
Expand Down Expand Up @@ -529,13 +529,13 @@ Value* JSONParser::ConsumeDictionary() {

// The next token is the value. Ownership transfers to |dict|.
NextChar();
Value* value = ParseNextToken();
std::unique_ptr<Value> value = ParseNextToken();
if (!value) {
// ReportError from deeper level.
return nullptr;
}

dict->SetWithoutPathExpansion(key.AsString(), value);
dict->SetWithoutPathExpansion(key.AsString(), std::move(value));

NextChar();
token = GetNextToken();
Expand All @@ -552,10 +552,10 @@ Value* JSONParser::ConsumeDictionary() {
}
}

return dict.release();
return std::move(dict);
}

Value* JSONParser::ConsumeList() {
std::unique_ptr<Value> JSONParser::ConsumeList() {
if (*pos_ != '[') {
ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1);
return nullptr;
Expand All @@ -572,13 +572,13 @@ Value* JSONParser::ConsumeList() {
NextChar();
Token token = GetNextToken();
while (token != T_ARRAY_END) {
Value* item = ParseToken(token);
std::unique_ptr<Value> item = ParseToken(token);
if (!item) {
// ReportError from deeper level.
return nullptr;
}

list->Append(item);
list->Append(std::move(item));

NextChar();
token = GetNextToken();
Expand All @@ -595,22 +595,22 @@ Value* JSONParser::ConsumeList() {
}
}

return list.release();
return std::move(list);
}

Value* JSONParser::ConsumeString() {
std::unique_ptr<Value> JSONParser::ConsumeString() {
StringBuilder string;
if (!ConsumeStringRaw(&string))
return nullptr;

// Create the Value representation, using a hidden root, if configured
// to do so, and if the string can be represented by StringPiece.
if (string.CanBeStringPiece() && !(options_ & JSON_DETACHABLE_CHILDREN))
return new JSONStringValue(string.AsStringPiece());
return base::MakeUnique<JSONStringValue>(string.AsStringPiece());

if (string.CanBeStringPiece())
string.Convert();
return new StringValue(string.AsString());
return base::MakeUnique<StringValue>(string.AsString());
}

bool JSONParser::ConsumeStringRaw(StringBuilder* out) {
Expand Down Expand Up @@ -828,7 +828,7 @@ void JSONParser::DecodeUTF8(const int32_t& point, StringBuilder* dest) {
}
}

Value* JSONParser::ConsumeNumber() {
std::unique_ptr<Value> JSONParser::ConsumeNumber() {
const char* num_start = pos_;
const int start_index = index_;
int end_index = start_index;
Expand Down Expand Up @@ -893,12 +893,12 @@ Value* JSONParser::ConsumeNumber() {

int num_int;
if (StringToInt(num_string, &num_int))
return new FundamentalValue(num_int);
return base::MakeUnique<FundamentalValue>(num_int);

double num_double;
if (StringToDouble(num_string.as_string(), &num_double) &&
std::isfinite(num_double)) {
return new FundamentalValue(num_double);
return base::MakeUnique<FundamentalValue>(num_double);
}

return nullptr;
Expand All @@ -923,7 +923,7 @@ bool JSONParser::ReadInt(bool allow_leading_zeros) {
return true;
}

Value* JSONParser::ConsumeLiteral() {
std::unique_ptr<Value> JSONParser::ConsumeLiteral() {
switch (*pos_) {
case 't': {
const char kTrueLiteral[] = "true";
Expand All @@ -934,7 +934,7 @@ Value* JSONParser::ConsumeLiteral() {
return nullptr;
}
NextNChars(kTrueLen - 1);
return new FundamentalValue(true);
return base::MakeUnique<FundamentalValue>(true);
}
case 'f': {
const char kFalseLiteral[] = "false";
Expand All @@ -945,7 +945,7 @@ Value* JSONParser::ConsumeLiteral() {
return nullptr;
}
NextNChars(kFalseLen - 1);
return new FundamentalValue(false);
return base::MakeUnique<FundamentalValue>(false);
}
case 'n': {
const char kNullLiteral[] = "null";
Expand All @@ -956,7 +956,7 @@ Value* JSONParser::ConsumeLiteral() {
return nullptr;
}
NextNChars(kNullLen - 1);
return Value::CreateNullValue().release();
return Value::CreateNullValue();
}
default:
ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1);
Expand Down
21 changes: 10 additions & 11 deletions base/json/json_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,23 @@ class BASE_EXPORT JSONParser {
// currently wound to a '/'.
bool EatComment();

// Calls GetNextToken() and then ParseToken(). Caller owns the result.
Value* ParseNextToken();
// Calls GetNextToken() and then ParseToken().
std::unique_ptr<Value> ParseNextToken();

// Takes a token that represents the start of a Value ("a structural token"
// in RFC terms) and consumes it, returning the result as an object the
// caller owns.
Value* ParseToken(Token token);
// in RFC terms) and consumes it, returning the result as a Value.
std::unique_ptr<Value> ParseToken(Token token);

// Assuming that the parser is currently wound to '{', this parses a JSON
// object into a DictionaryValue.
Value* ConsumeDictionary();
std::unique_ptr<Value> ConsumeDictionary();

// Assuming that the parser is wound to '[', this parses a JSON list into a
// ListValue.
Value* ConsumeList();
// std::unique_ptr<ListValue>.
std::unique_ptr<Value> ConsumeList();

// Calls through ConsumeStringRaw and wraps it in a value.
Value* ConsumeString();
std::unique_ptr<Value> ConsumeString();

// Assuming that the parser is wound to a double quote, this parses a string,
// decoding any escape sequences and converts UTF-16 to UTF-8. Returns true on
Expand All @@ -198,14 +197,14 @@ class BASE_EXPORT JSONParser {

// Assuming that the parser is wound to the start of a valid JSON number,
// this parses and converts it to either an int or double value.
Value* ConsumeNumber();
std::unique_ptr<Value> ConsumeNumber();
// Helper that reads characters that are ints. Returns true if a number was
// read and false on error.
bool ReadInt(bool allow_leading_zeros);

// Consumes the literal values of |true|, |false|, and |null|, assuming the
// parser is wound to the first character of any of those.
Value* ConsumeLiteral();
std::unique_ptr<Value> ConsumeLiteral();

// Compares two string buffers of a given length.
static bool StringsAreEqual(const char* left, const char* right, size_t len);
Expand Down
14 changes: 7 additions & 7 deletions base/json/json_parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ TEST_F(JSONParserTest, ConsumeLiterals) {
// Literal |false|.
input = "false,|";
parser.reset(NewTestParser(input));
value.reset(parser->ConsumeLiteral());
value = parser->ConsumeLiteral();
EXPECT_EQ('e', *parser->pos_);

TestLastThree(parser.get());
Expand All @@ -117,7 +117,7 @@ TEST_F(JSONParserTest, ConsumeLiterals) {
// Literal |null|.
input = "null,|";
parser.reset(NewTestParser(input));
value.reset(parser->ConsumeLiteral());
value = parser->ConsumeLiteral();
EXPECT_EQ('l', *parser->pos_);

TestLastThree(parser.get());
Expand All @@ -143,7 +143,7 @@ TEST_F(JSONParserTest, ConsumeNumbers) {
// Negative integer.
input = "-1234,|";
parser.reset(NewTestParser(input));
value.reset(parser->ConsumeNumber());
value = parser->ConsumeNumber();
EXPECT_EQ('4', *parser->pos_);

TestLastThree(parser.get());
Expand All @@ -155,7 +155,7 @@ TEST_F(JSONParserTest, ConsumeNumbers) {
// Double.
input = "12.34,|";
parser.reset(NewTestParser(input));
value.reset(parser->ConsumeNumber());
value = parser->ConsumeNumber();
EXPECT_EQ('4', *parser->pos_);

TestLastThree(parser.get());
Expand All @@ -168,7 +168,7 @@ TEST_F(JSONParserTest, ConsumeNumbers) {
// Scientific.
input = "42e3,|";
parser.reset(NewTestParser(input));
value.reset(parser->ConsumeNumber());
value = parser->ConsumeNumber();
EXPECT_EQ('3', *parser->pos_);

TestLastThree(parser.get());
Expand All @@ -180,7 +180,7 @@ TEST_F(JSONParserTest, ConsumeNumbers) {
// Negative scientific.
input = "314159e-5,|";
parser.reset(NewTestParser(input));
value.reset(parser->ConsumeNumber());
value = parser->ConsumeNumber();
EXPECT_EQ('5', *parser->pos_);

TestLastThree(parser.get());
Expand All @@ -192,7 +192,7 @@ TEST_F(JSONParserTest, ConsumeNumbers) {
// Positive scientific.
input = "0.42e+3,|";
parser.reset(NewTestParser(input));
value.reset(parser->ConsumeNumber());
value = parser->ConsumeNumber();
EXPECT_EQ('3', *parser->pos_);

TestLastThree(parser.get());
Expand Down
2 changes: 1 addition & 1 deletion base/test/gtest_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool WriteCompiledInTestsToFile(const FilePath& path) {

ListValue root;
for (size_t i = 0; i < tests.size(); ++i) {
std::unique_ptr<class base::DictionaryValue> test_info(new DictionaryValue);
std::unique_ptr<DictionaryValue> test_info(new DictionaryValue);
test_info->SetString("test_case_name", tests[i].test_case_name);
test_info->SetString("test_name", tests[i].test_name);
test_info->SetString("file", tests[i].file);
Expand Down
7 changes: 2 additions & 5 deletions chrome/test/base/javascript_browser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,8 @@ base::string16 JavaScriptBrowserTest::BuildRunTestJSCall(
arguments.push_back(function_name_arg);
base::ListValue* baked_argument_list = new base::ListValue();
ConstValueVector::const_iterator arguments_iterator;
for (arguments_iterator = test_func_args.begin();
arguments_iterator != test_func_args.end();
++arguments_iterator) {
baked_argument_list->Append((*arguments_iterator)->DeepCopy());
}
for (auto* arg : test_func_args)
baked_argument_list->Append(arg->CreateDeepCopy());
arguments.push_back(baked_argument_list);
return content::WebUI::GetJavascriptCall(std::string("runTest"),
arguments.get());
Expand Down
2 changes: 1 addition & 1 deletion chrome/test/chromedriver/chrome/automation_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Status AutomationExtension::GetWindowInfo(int* x,
Status AutomationExtension::UpdateWindow(
const base::DictionaryValue& update_info) {
base::ListValue args;
args.Append(update_info.DeepCopy());
args.Append(update_info.CreateDeepCopy());
std::unique_ptr<base::Value> result;
return web_view_->CallAsyncFunction(std::string(),
"updateWindow",
Expand Down
4 changes: 2 additions & 2 deletions chrome/test/chromedriver/chrome/web_view_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ Status WebViewImpl::SetFileInputFiles(
if (status.IsError())
return status;
base::ListValue args;
args.Append(element.DeepCopy());
args.Append(element.CreateDeepCopy());
bool found_node;
int node_id;
status = internal::GetNodeIdFromFunction(
Expand Down Expand Up @@ -681,7 +681,7 @@ Status WebViewImpl::CallAsyncFunctionInternal(
std::unique_ptr<base::Value>* result) {
base::ListValue async_args;
async_args.AppendString("return (" + function + ").apply(null, arguments);");
async_args.Append(args.DeepCopy());
async_args.Append(args.CreateDeepCopy());
async_args.AppendBoolean(is_user_supplied);
async_args.AppendInteger(timeout.InMilliseconds());
std::unique_ptr<base::Value> tmp;
Expand Down
18 changes: 9 additions & 9 deletions chrome/test/chromedriver/commands_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ class FindElementWebView : public StubWebView {
base::DictionaryValue element2;
element2.SetString("ELEMENT", "2");
base::ListValue list;
list.Append(element1.DeepCopy());
list.Append(element2.DeepCopy());
result_.reset(list.DeepCopy());
list.Append(element1.CreateDeepCopy());
list.Append(element2.CreateDeepCopy());
result_ = list.CreateDeepCopy();
}
break;
}
Expand Down Expand Up @@ -460,7 +460,7 @@ TEST(CommandsTest, SuccessfulFindElement) {
base::DictionaryValue param;
param.SetString("id", "a");
base::ListValue expected_args;
expected_args.Append(param.DeepCopy());
expected_args.Append(param.CreateDeepCopy());
web_view.Verify("frame_id1", &expected_args, result.get());
}

Expand Down Expand Up @@ -491,7 +491,7 @@ TEST(CommandsTest, SuccessfulFindElements) {
base::DictionaryValue param;
param.SetString("name", "b");
base::ListValue expected_args;
expected_args.Append(param.DeepCopy());
expected_args.Append(param.CreateDeepCopy());
web_view.Verify("frame_id2", &expected_args, result.get());
}

Expand Down Expand Up @@ -529,8 +529,8 @@ TEST(CommandsTest, SuccessfulFindChildElement) {
base::DictionaryValue root_element_param;
root_element_param.SetString("ELEMENT", element_id);
base::ListValue expected_args;
expected_args.Append(locator_param.DeepCopy());
expected_args.Append(root_element_param.DeepCopy());
expected_args.Append(locator_param.CreateDeepCopy());
expected_args.Append(root_element_param.CreateDeepCopy());
web_view.Verify("frame_id3", &expected_args, result.get());
}

Expand Down Expand Up @@ -567,8 +567,8 @@ TEST(CommandsTest, SuccessfulFindChildElements) {
base::DictionaryValue root_element_param;
root_element_param.SetString("ELEMENT", element_id);
base::ListValue expected_args;
expected_args.Append(locator_param.DeepCopy());
expected_args.Append(root_element_param.DeepCopy());
expected_args.Append(locator_param.CreateDeepCopy());
expected_args.Append(root_element_param.CreateDeepCopy());
web_view.Verify("frame_id4", &expected_args, result.get());
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/test/chromedriver/element_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ Status ExecuteGetElementLocationOnceScrolledIntoView(
session, web_view, element_id, &offset, &location);
if (status.IsError())
return status;
value->reset(CreateValueFrom(location));
*value = CreateValueFrom(location);
return Status(kOk);
}

Expand Down
Loading

0 comments on commit 031a8f8

Please sign in to comment.