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

Side by Side Diff: tools/gn/input_conversion.cc

Issue 1048913003: tools/gn: don't allow trailing junk or non-literals in "value" conversion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clang-format Created 5 years, 8 months 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
« no previous file with comments | « no previous file | tools/gn/input_conversion_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "tools/gn/input_conversion.h" 5 #include "tools/gn/input_conversion.h"
6 6
7 #include "base/strings/string_split.h" 7 #include "base/strings/string_split.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "tools/gn/build_settings.h" 9 #include "tools/gn/build_settings.h"
10 #include "tools/gn/err.h" 10 #include "tools/gn/err.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } else { 52 } else {
53 input_file->set_friendly_name("dynamic input"); 53 input_file->set_friendly_name("dynamic input");
54 } 54 }
55 55
56 *tokens = Tokenizer::Tokenize(input_file, err); 56 *tokens = Tokenizer::Tokenize(input_file, err);
57 if (err->has_error()) 57 if (err->has_error())
58 return Value(); 58 return Value();
59 59
60 // Parse the file according to what we're looking for. 60 // Parse the file according to what we're looking for.
61 if (what == PARSE_VALUE) 61 if (what == PARSE_VALUE)
62 *parse_root_ptr = Parser::ParseExpression(*tokens, err); 62 *parse_root_ptr = Parser::ParseValue(*tokens, err);
63 else 63 else
64 *parse_root_ptr = Parser::Parse(*tokens, err); // Will return a Block. 64 *parse_root_ptr = Parser::Parse(*tokens, err); // Will return a Block.
65 if (err->has_error()) 65 if (err->has_error())
66 return Value(); 66 return Value();
67 ParseNode* parse_root = parse_root_ptr->get(); // For nicer syntax below. 67 ParseNode* parse_root = parse_root_ptr->get(); // For nicer syntax below.
68 68
69 // It's valid for the result to be a null pointer, this just means that the 69 // It's valid for the result to be a null pointer, this just means that the
70 // script returned nothing. 70 // script returned nothing.
71 if (!parse_root) 71 if (!parse_root)
72 return Value(); 72 return Value();
73 73
74 // When parsing as a value, the result should either be a list or a literal,
75 // anything else is invalid.
76 if (what == PARSE_VALUE) {
77 if (!parse_root->AsList() && !parse_root->AsLiteral())
78 return Value();
79 }
80
81 scoped_ptr<Scope> scope(new Scope(settings)); 74 scoped_ptr<Scope> scope(new Scope(settings));
82
83 Value result = parse_root->Execute(scope.get(), err); 75 Value result = parse_root->Execute(scope.get(), err);
84 if (err->has_error()) 76 if (err->has_error())
85 return Value(); 77 return Value();
86 78
87 // When we want the result as a scope, the result is actually the scope 79 // When we want the result as a scope, the result is actually the scope
88 // we made, rather than the result of running the block (which will be empty). 80 // we made, rather than the result of running the block (which will be empty).
89 if (what == PARSE_SCOPE) { 81 if (what == PARSE_SCOPE) {
90 DCHECK(result.type() == Value::NONE); 82 DCHECK(result.type() == Value::NONE);
91 result = Value(origin, scope.Pass()); 83 result = Value(origin, scope.Pass());
92 } 84 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 const ParseNode* origin, 200 const ParseNode* origin,
209 const Value& input_conversion_value, 201 const Value& input_conversion_value,
210 Err* err) { 202 Err* err) {
211 if (input_conversion_value.type() == Value::NONE) 203 if (input_conversion_value.type() == Value::NONE)
212 return Value(); // Allow null inputs to mean discard the result. 204 return Value(); // Allow null inputs to mean discard the result.
213 if (!input_conversion_value.VerifyTypeIs(Value::STRING, err)) 205 if (!input_conversion_value.VerifyTypeIs(Value::STRING, err))
214 return Value(); 206 return Value();
215 return DoConvertInputToValue(settings, input, origin, input_conversion_value, 207 return DoConvertInputToValue(settings, input, origin, input_conversion_value,
216 input_conversion_value.string_value(), err); 208 input_conversion_value.string_value(), err);
217 } 209 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/input_conversion_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698