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

Side by Side Diff: extensions/renderer/resources/schema_utils.js

Issue 1126983009: Handle integer -0 as 0 in extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // Routines used to validate and normalize arguments. 5 // Routines used to validate and normalize arguments.
6 // TODO(benwells): unit test this file. 6 // TODO(benwells): unit test this file.
7 7
8 var JSONSchemaValidator = require('json_schema').JSONSchemaValidator; 8 var JSONSchemaValidator = require('json_schema').JSONSchemaValidator;
9 9
10 var schemaValidator = new JSONSchemaValidator(); 10 var schemaValidator = new JSONSchemaValidator();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 var resolvedSignature = resolveSignature(args, definedSignature); 111 var resolvedSignature = resolveSignature(args, definedSignature);
112 if (!resolvedSignature) 112 if (!resolvedSignature)
113 throw new Error("Invocation of form " + 113 throw new Error("Invocation of form " +
114 getArgumentSignatureString(funDef.name, args) + 114 getArgumentSignatureString(funDef.name, args) +
115 " doesn't match definition " + 115 " doesn't match definition " +
116 getParameterSignatureString(funDef.name, definedSignature)); 116 getParameterSignatureString(funDef.name, definedSignature));
117 validate(args, resolvedSignature); 117 validate(args, resolvedSignature);
118 var normalizedArgs = []; 118 var normalizedArgs = [];
119 var ai = 0; 119 var ai = 0;
120 for (var si = 0; si < definedSignature.length; si++) { 120 for (var si = 0; si < definedSignature.length; si++) {
121 // Handle integer -0 as 0.
122 if (JSONSchemaValidator.getType(args[ai]) === "integer" && args[ai] === 0)
123 args[ai] = 0;
121 if (definedSignature[si] === resolvedSignature[ai]) 124 if (definedSignature[si] === resolvedSignature[ai])
122 $Array.push(normalizedArgs, args[ai++]); 125 $Array.push(normalizedArgs, args[ai++]);
123 else 126 else
124 $Array.push(normalizedArgs, null); 127 $Array.push(normalizedArgs, null);
125 } 128 }
126 return normalizedArgs; 129 return normalizedArgs;
127 }; 130 };
128 131
129 // Validates that a given schema for an API function is not ambiguous. 132 // Validates that a given schema for an API function is not ambiguous.
130 function isFunctionSignatureAmbiguous(functionDef) { 133 function isFunctionSignatureAmbiguous(functionDef) {
(...skipping 16 matching lines...) Expand all
147 return true; 150 return true;
148 } 151 }
149 } 152 }
150 return false; 153 return false;
151 }; 154 };
152 155
153 exports.isFunctionSignatureAmbiguous = isFunctionSignatureAmbiguous; 156 exports.isFunctionSignatureAmbiguous = isFunctionSignatureAmbiguous;
154 exports.normalizeArgumentsAndValidate = normalizeArgumentsAndValidate; 157 exports.normalizeArgumentsAndValidate = normalizeArgumentsAndValidate;
155 exports.schemaValidator = schemaValidator; 158 exports.schemaValidator = schemaValidator;
156 exports.validate = validate; 159 exports.validate = validate;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698