OLD | NEW |
---|---|
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 var Event = require('event_bindings').Event; | 5 var Event = require('event_bindings').Event; |
6 var forEach = require('utils').forEach; | 6 var forEach = require('utils').forEach; |
7 var GetAvailability = requireNative('v8_context').GetAvailability; | 7 var GetAvailability = requireNative('v8_context').GetAvailability; |
8 var exceptionHandler = require('uncaught_exception_handler'); | 8 var exceptionHandler = require('uncaught_exception_handler'); |
9 var lastError = require('lastError'); | 9 var lastError = require('lastError'); |
10 var logActivity = requireNative('activityLogger'); | 10 var logActivity = requireNative('activityLogger'); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 function getPlatform() { | 131 function getPlatform() { |
132 var platforms = [ | 132 var platforms = [ |
133 [/CrOS Touch/, "chromeos touch"], | 133 [/CrOS Touch/, "chromeos touch"], |
134 [/CrOS/, "chromeos"], | 134 [/CrOS/, "chromeos"], |
135 [/Linux/, "linux"], | 135 [/Linux/, "linux"], |
136 [/Mac/, "mac"], | 136 [/Mac/, "mac"], |
137 [/Win/, "win"], | 137 [/Win/, "win"], |
138 ]; | 138 ]; |
139 | 139 |
140 for (var i = 0; i < platforms.length; i++) { | 140 for (var i = 0; i < platforms.length; i++) { |
141 if ($RegExp.test(platforms[i][0], navigator.appVersion)) { | 141 if ($RegExp.exec(platforms[i][0], navigator.appVersion)) { |
142 return platforms[i][1]; | 142 return platforms[i][1]; |
143 } | 143 } |
144 } | 144 } |
145 return "unknown"; | 145 return "unknown"; |
146 } | 146 } |
147 | 147 |
148 function isPlatformSupported(schemaNode, platform) { | 148 function isPlatformSupported(schemaNode, platform) { |
149 return !schemaNode.platforms || | 149 return !schemaNode.platforms || |
150 $Array.indexOf(schemaNode.platforms, platform) > -1; | 150 $Array.indexOf(schemaNode.platforms, platform) > -1; |
151 } | 151 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 var id = $String.substr(t.id, schema.namespace.length + 1); | 295 var id = $String.substr(t.id, schema.namespace.length + 1); |
296 mod[id] = {}; | 296 mod[id] = {}; |
297 $Array.forEach(enumValues, function(enumValue) { | 297 $Array.forEach(enumValues, function(enumValue) { |
298 // Note: enums can be declared either as a list of strings | 298 // Note: enums can be declared either as a list of strings |
299 // ['foo', 'bar'] or as a list of objects | 299 // ['foo', 'bar'] or as a list of objects |
300 // [{'name': 'foo'}, {'name': 'bar'}]. | 300 // [{'name': 'foo'}, {'name': 'bar'}]. |
301 enumValue = $Object.hasOwnProperty(enumValue, 'name') ? | 301 enumValue = $Object.hasOwnProperty(enumValue, 'name') ? |
302 enumValue.name : enumValue; | 302 enumValue.name : enumValue; |
303 if (enumValue) { // Avoid setting any empty enums. | 303 if (enumValue) { // Avoid setting any empty enums. |
304 // Make all properties in ALL_CAPS_STYLE. | 304 // Make all properties in ALL_CAPS_STYLE. |
305 // Replace myEnum-Foo with my_Enum-Foo: | |
306 var propertyName = | |
307 $String.replace(enumValue, /([a-z])([A-Z])/g, '$1_$2'); | |
308 // Replace my_Enum-Foo with my_Enum_Foo: | |
309 propertyName = $String.replace(propertyName, /\W/g, '_'); | |
310 // If the first character is a digit (we know it must be one of | 305 // If the first character is a digit (we know it must be one of |
Devlin
2016/04/05 19:15:50
We should add a new comment here explaining why th
Dan Ehrenberg
2016/04/05 20:20:57
Done
| |
311 // a digit, a letter, or an underscore), precede it with an | 306 // a digit, a letter, or an underscore), precede it with an |
312 // underscore. | 307 // underscore. |
313 propertyName = $String.replace(propertyName, /^(\d)/g, '_$1'); | 308 var propertyName = ($RegExp.exec(/\d/, enumValue[0])) ? '_' : ''; |
309 for (var i = 0; i < enumValue.length; i++) { | |
Devlin
2016/04/05 19:15:50
++i
Dan Ehrenberg
2016/04/05 20:20:57
Done
| |
310 if (i > 0 && $RegExp.exec(/[a-z]/, enumValue[i-1]) && | |
Devlin
2016/04/05 19:15:50
I think this block would be a little easier to rea
Dan Ehrenberg
2016/04/05 20:20:57
Done
| |
311 $RegExp.exec(/[A-Z]/, enumValue[i])) { | |
312 // Replace myEnum-Foo with my_Enum-Foo: | |
313 propertyName = propertyName + '_' + enumValue[i]; | |
314 } else if ($RegExp.exec(/\W/, enumValue[i])) { | |
315 // Replace my_Enum-Foo with my_Enum_Foo: | |
316 propertyName = propertyName + '_'; | |
317 } else { | |
318 propertyName = propertyName + enumValue[i]; | |
319 } | |
320 } | |
314 // Uppercase (replace my_Enum_Foo with MY_ENUM_FOO): | 321 // Uppercase (replace my_Enum_Foo with MY_ENUM_FOO): |
315 propertyName = $String.toUpperCase(propertyName); | 322 propertyName = $String.toUpperCase(propertyName); |
316 mod[id][propertyName] = enumValue; | 323 mod[id][propertyName] = enumValue; |
317 } | 324 } |
318 }); | 325 }); |
319 } | 326 } |
320 }, this); | 327 }, this); |
321 } | 328 } |
322 | 329 |
323 // TODO(cduvall): Take out when all APIs have been converted to features. | 330 // TODO(cduvall): Take out when all APIs have been converted to features. |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 availability.message); | 525 availability.message); |
519 return; | 526 return; |
520 } | 527 } |
521 | 528 |
522 this.runHooks_(mod); | 529 this.runHooks_(mod); |
523 return mod; | 530 return mod; |
524 } | 531 } |
525 }; | 532 }; |
526 | 533 |
527 exports.$set('Binding', Binding); | 534 exports.$set('Binding', Binding); |
OLD | NEW |