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

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

Issue 2709103004: [Content] Allow V8ValueConverter to convert -0 to an integer (Closed)
Patch Set: Created 3 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 unified diff | Download patch
« no previous file with comments | « content/public/child/v8_value_converter.h ('k') | extensions/renderer/send_request_natives.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 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 var resolvedSignature = resolveSignature(args, definedSignature); 110 var resolvedSignature = resolveSignature(args, definedSignature);
111 if (!resolvedSignature) 111 if (!resolvedSignature)
112 throw new Error('Invocation of form ' + 112 throw new Error('Invocation of form ' +
113 getArgumentSignatureString(funDef.name, args) + 113 getArgumentSignatureString(funDef.name, args) +
114 " doesn't match definition " + 114 " doesn't match definition " +
115 getParameterSignatureString(funDef.name, definedSignature)); 115 getParameterSignatureString(funDef.name, definedSignature));
116 validate(args, resolvedSignature); 116 validate(args, resolvedSignature);
117 var normalizedArgs = []; 117 var normalizedArgs = [];
118 var ai = 0; 118 var ai = 0;
119 for (var si = 0; si < definedSignature.length; ++si) { 119 for (var si = 0; si < definedSignature.length; ++si) {
120 // Handle integer -0 as 0.
121 if (JSONSchemaValidator.getType(args[ai]) === 'integer' && args[ai] === 0)
122 args[ai] = 0;
123 if (definedSignature[si] === resolvedSignature[ai]) 120 if (definedSignature[si] === resolvedSignature[ai])
124 $Array.push(normalizedArgs, args[ai++]); 121 $Array.push(normalizedArgs, args[ai++]);
125 else 122 else
126 $Array.push(normalizedArgs, null); 123 $Array.push(normalizedArgs, null);
127 } 124 }
128 return normalizedArgs; 125 return normalizedArgs;
129 }; 126 };
130 127
131 // Validates that a given schema for an API function is not ambiguous. 128 // Validates that a given schema for an API function is not ambiguous.
132 function isFunctionSignatureAmbiguous(functionDef) { 129 function isFunctionSignatureAmbiguous(functionDef) {
(...skipping 16 matching lines...) Expand all
149 return true; 146 return true;
150 } 147 }
151 } 148 }
152 return false; 149 return false;
153 }; 150 };
154 151
155 exports.$set('isFunctionSignatureAmbiguous', isFunctionSignatureAmbiguous); 152 exports.$set('isFunctionSignatureAmbiguous', isFunctionSignatureAmbiguous);
156 exports.$set('normalizeArgumentsAndValidate', normalizeArgumentsAndValidate); 153 exports.$set('normalizeArgumentsAndValidate', normalizeArgumentsAndValidate);
157 exports.$set('schemaValidator', schemaValidator); 154 exports.$set('schemaValidator', schemaValidator);
158 exports.$set('validate', validate); 155 exports.$set('validate', validate);
OLDNEW
« no previous file with comments | « content/public/child/v8_value_converter.h ('k') | extensions/renderer/send_request_natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698