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

Unified Diff: chrome/renderer/resources/extensions/json_schema.js

Issue 9584021: Improve implementation of isInstanceOf in JSONSchemaValidator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove a test that cannot work anymore, update docs Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/docs/extension.html ('k') | chrome/test/data/extensions/json_schema_test.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/resources/extensions/json_schema.js
diff --git a/chrome/renderer/resources/extensions/json_schema.js b/chrome/renderer/resources/extensions/json_schema.js
index 9b109bfb6bcd276c2d91f69db2b28663caed4e5e..df91335abf2bbb16f25a5c160aa6f04daebc9d82 100644
--- a/chrome/renderer/resources/extensions/json_schema.js
+++ b/chrome/renderer/resources/extensions/json_schema.js
@@ -280,27 +280,10 @@ chromeHidden.JSONSchemaValidator.prototype.validateObject = function(
// If "instanceof" property is set, check that this object inherits from
// the specified constructor (function).
if (schema.isInstanceOf) {
- var isInstance = function() {
- var constructor = this[schema.isInstanceOf];
- if (constructor) {
- return (instance instanceof constructor);
- }
-
- // Special-case constructors that can not always be found on the global
- // object, but for which we to allow validation.
- var allowedNamedConstructors = {
- "Window": true,
- "ImageData": true
- }
- if (!allowedNamedConstructors[schema.isInstanceOf]) {
- throw "Attempt to validate against an instance ctor that could not be" +
- "found: " + schema.isInstanceOf;
- }
- return (schema.isInstanceOf == instance.constructor.name)
- }();
-
- if (!isInstance)
+ if (Object.prototype.toString.call(instance) !=
arv (Not doing code reviews) 2012/03/05 19:13:07 Maybe we should have walked the prototype chain so
Aaron Boodman 2012/03/05 21:06:08 I agree the recursive search is cooler, but in thi
+ "[object " + schema.isInstanceOf + "]") {
this.addError(propPath, "notInstance", [schema.isInstanceOf]);
+ }
}
// Exit early from additional property check if "type":"any" is defined.
« no previous file with comments | « chrome/common/extensions/docs/extension.html ('k') | chrome/test/data/extensions/json_schema_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698