| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "extensions/renderer/bindings/api_signature.h" | 5 #include "extensions/renderer/bindings/api_signature.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return false; | 203 return false; |
| 204 } | 204 } |
| 205 // This is safe to call even if |arguments| is at the end (which can happen | 205 // This is safe to call even if |arguments| is at the end (which can happen |
| 206 // if n optional arguments are omitted at the end of the signature). | 206 // if n optional arguments are omitted at the end of the signature). |
| 207 ConsumeArgument(); | 207 ConsumeArgument(); |
| 208 | 208 |
| 209 AddNull(); | 209 AddNull(); |
| 210 return true; | 210 return true; |
| 211 } | 211 } |
| 212 | 212 |
| 213 if (!spec.ParseArgument(context_, value, type_refs_, GetBuffer(), | 213 if (!spec.IsCorrectType(value, type_refs_, &parse_error_)) { |
| 214 &parse_error_)) { | |
| 215 if (!spec.optional()) { | 214 if (!spec.optional()) { |
| 216 *error_ = api_errors::ArgumentError(spec.name(), parse_error_); | 215 *error_ = api_errors::ArgumentError(spec.name(), parse_error_); |
| 217 return false; | 216 return false; |
| 218 } | 217 } |
| 219 | 218 |
| 220 AddNull(); | 219 AddNull(); |
| 221 return true; | 220 return true; |
| 222 } | 221 } |
| 223 | 222 |
| 223 if (!spec.ParseArgument(context_, value, type_refs_, GetBuffer(), |
| 224 &parse_error_)) { |
| 225 *error_ = api_errors::ArgumentError(spec.name(), parse_error_); |
| 226 return false; |
| 227 } |
| 228 |
| 224 ConsumeArgument(); | 229 ConsumeArgument(); |
| 225 AddParsedArgument(value); | 230 AddParsedArgument(value); |
| 226 return true; | 231 return true; |
| 227 } | 232 } |
| 228 | 233 |
| 229 bool ArgumentParser::ParseCallback(const ArgumentSpec& spec) { | 234 bool ArgumentParser::ParseCallback(const ArgumentSpec& spec) { |
| 230 v8::Local<v8::Value> value = next_argument(); | 235 v8::Local<v8::Value> value = next_argument(); |
| 231 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) { | 236 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) { |
| 232 if (!spec.optional()) { | 237 if (!spec.optional()) { |
| 233 *error_ = api_errors::MissingRequiredArgument(spec.name().c_str()); | 238 *error_ = api_errors::MissingRequiredArgument(spec.name().c_str()); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 pieces.push_back( | 359 pieces.push_back( |
| 355 base::StringPrintf("%s%s %s", spec->optional() ? kOptionalPrefix : "", | 360 base::StringPrintf("%s%s %s", spec->optional() ? kOptionalPrefix : "", |
| 356 spec->GetTypeName().c_str(), spec->name().c_str())); | 361 spec->GetTypeName().c_str(), spec->name().c_str())); |
| 357 } | 362 } |
| 358 expected_signature_ = base::JoinString(pieces, ", "); | 363 expected_signature_ = base::JoinString(pieces, ", "); |
| 359 | 364 |
| 360 return expected_signature_; | 365 return expected_signature_; |
| 361 } | 366 } |
| 362 | 367 |
| 363 } // namespace extensions | 368 } // namespace extensions |
| OLD | NEW |