Chromium Code Reviews| 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/argument_spec.h" | 5 #include "extensions/renderer/argument_spec.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "content/public/child/v8_value_converter.h" | 10 #include "content/public/child/v8_value_converter.h" |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 | 413 |
| 414 v8::Local<v8::Value> prop_value; | 414 v8::Local<v8::Value> prop_value; |
| 415 // Fun: It's possible that a previous getter has removed the property from | 415 // Fun: It's possible that a previous getter has removed the property from |
| 416 // the object. This isn't that big of a deal, since it would only manifest | 416 // the object. This isn't that big of a deal, since it would only manifest |
| 417 // in the case of some reasonably-crazy script objects, and it's probably | 417 // in the case of some reasonably-crazy script objects, and it's probably |
| 418 // not worth optimizing for the uncommon case to the detriment of the | 418 // not worth optimizing for the uncommon case to the detriment of the |
| 419 // common (and either should be totally safe). We can always add a | 419 // common (and either should be totally safe). We can always add a |
| 420 // HasOwnProperty() check here in the future, if we desire. | 420 // HasOwnProperty() check here in the future, if we desire. |
| 421 // See also comment in ParseArgumentToArray() about passing in custom | 421 // See also comment in ParseArgumentToArray() about passing in custom |
| 422 // crazy values here. | 422 // crazy values here. |
| 423 if (!object->Get(context, key).ToLocal(&prop_value)) | 423 if (!object->Get(context, key).ToLocal(&prop_value)) { |
| 424 // Technically, in the case of the property being removed before access, | |
|
jbroman
2017/04/27 19:37:20
Hmm? Getting a nonexistent property will successfu
Devlin
2017/05/01 22:22:09
Ah, good point. Comment removed.
| |
| 425 // this error message will be wrong. But since that can only happen if | |
| 426 // someone removes a property after the initial GetOwnPropertyNames() | |
| 427 // check, this seems reasonable enough - these error messages are meant | |
| 428 // to be helpful, but don't need 100% accuracy in deliberately-crazy | |
| 429 // cases. | |
| 430 *error = api_errors::ScriptThrewError(); | |
| 424 return false; | 431 return false; |
| 432 } | |
| 425 | 433 |
| 426 // Note: We don't serialize undefined or null values. | 434 // Note: We don't serialize undefined or null values. |
| 427 // TODO(devlin): This matches current behavior, but it is correct? | 435 // TODO(devlin): This matches current behavior, but it is correct? |
| 428 if (prop_value->IsUndefined() || prop_value->IsNull()) { | 436 if (prop_value->IsUndefined() || prop_value->IsNull()) { |
| 429 if (!property_spec->optional_) { | 437 if (!property_spec->optional_) { |
| 430 *error = api_errors::MissingRequiredProperty(*utf8_key); | 438 *error = api_errors::MissingRequiredProperty(*utf8_key); |
| 431 return false; | 439 return false; |
| 432 } | 440 } |
| 433 continue; | 441 continue; |
| 434 } | 442 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 break; | 603 break; |
| 596 case ArgumentType::CHOICES: | 604 case ArgumentType::CHOICES: |
| 597 case ArgumentType::ANY: | 605 case ArgumentType::ANY: |
| 598 NOTREACHED(); | 606 NOTREACHED(); |
| 599 } | 607 } |
| 600 | 608 |
| 601 return api_errors::InvalidType(expected_type, GetV8ValueTypeString(value)); | 609 return api_errors::InvalidType(expected_type, GetV8ValueTypeString(value)); |
| 602 } | 610 } |
| 603 | 611 |
| 604 } // namespace extensions | 612 } // namespace extensions |
| OLD | NEW |