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 // Use exec rather than test to defend against clobbering in the |
Devlin
2016/04/05 20:37:50
Move this comment to safe_builtins.cc.
Dan Ehrenberg
2016/04/05 20:48:47
Done
| |
142 // presence of ES2015 semantics, which read RegExp.prototype.exec. | |
143 if ($RegExp.exec(platforms[i][0], navigator.appVersion)) { | |
142 return platforms[i][1]; | 144 return platforms[i][1]; |
143 } | 145 } |
144 } | 146 } |
145 return "unknown"; | 147 return "unknown"; |
146 } | 148 } |
147 | 149 |
148 function isPlatformSupported(schemaNode, platform) { | 150 function isPlatformSupported(schemaNode, platform) { |
149 return !schemaNode.platforms || | 151 return !schemaNode.platforms || |
150 $Array.indexOf(schemaNode.platforms, platform) > -1; | 152 $Array.indexOf(schemaNode.platforms, platform) > -1; |
151 } | 153 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 var id = $String.substr(t.id, schema.namespace.length + 1); | 297 var id = $String.substr(t.id, schema.namespace.length + 1); |
296 mod[id] = {}; | 298 mod[id] = {}; |
297 $Array.forEach(enumValues, function(enumValue) { | 299 $Array.forEach(enumValues, function(enumValue) { |
298 // Note: enums can be declared either as a list of strings | 300 // Note: enums can be declared either as a list of strings |
299 // ['foo', 'bar'] or as a list of objects | 301 // ['foo', 'bar'] or as a list of objects |
300 // [{'name': 'foo'}, {'name': 'bar'}]. | 302 // [{'name': 'foo'}, {'name': 'bar'}]. |
301 enumValue = $Object.hasOwnProperty(enumValue, 'name') ? | 303 enumValue = $Object.hasOwnProperty(enumValue, 'name') ? |
302 enumValue.name : enumValue; | 304 enumValue.name : enumValue; |
303 if (enumValue) { // Avoid setting any empty enums. | 305 if (enumValue) { // Avoid setting any empty enums. |
304 // Make all properties in ALL_CAPS_STYLE. | 306 // Make all properties in ALL_CAPS_STYLE. |
305 // Replace myEnum-Foo with my_Enum-Foo: | 307 // |
306 var propertyName = | 308 // The built-in versions of $String.replace call other built-ins, |
307 $String.replace(enumValue, /([a-z])([A-Z])/g, '$1_$2'); | 309 // which may be clobbered. Instead, manually build the property |
308 // Replace my_Enum-Foo with my_Enum_Foo: | 310 // name. |
309 propertyName = $String.replace(propertyName, /\W/g, '_'); | 311 // |
310 // If the first character is a digit (we know it must be one of | 312 // If the first character is a digit (we know it must be one of |
311 // a digit, a letter, or an underscore), precede it with an | 313 // a digit, a letter, or an underscore), precede it with an |
312 // underscore. | 314 // underscore. |
313 propertyName = $String.replace(propertyName, /^(\d)/g, '_$1'); | 315 var propertyName = ($RegExp.exec(/\d/, enumValue[0])) ? '_' : ''; |
316 for (var i = 0; i < enumValue.length; ++i) { | |
317 var next; | |
318 if (i > 0 && $RegExp.exec(/[a-z]/, enumValue[i-1]) && | |
319 $RegExp.exec(/[A-Z]/, enumValue[i])) { | |
320 // Replace myEnum-Foo with my_Enum-Foo: | |
321 next = '_' + enumValue[i]; | |
322 } else if ($RegExp.exec(/\W/, enumValue[i])) { | |
323 // Replace my_Enum-Foo with my_Enum_Foo: | |
324 next = '_'; | |
325 } else { | |
326 next = enumValue[i]; | |
327 } | |
328 propertyName += next; | |
329 } | |
314 // Uppercase (replace my_Enum_Foo with MY_ENUM_FOO): | 330 // Uppercase (replace my_Enum_Foo with MY_ENUM_FOO): |
315 propertyName = $String.toUpperCase(propertyName); | 331 propertyName = $String.toUpperCase(propertyName); |
316 mod[id][propertyName] = enumValue; | 332 mod[id][propertyName] = enumValue; |
317 } | 333 } |
318 }); | 334 }); |
319 } | 335 } |
320 }, this); | 336 }, this); |
321 } | 337 } |
322 | 338 |
323 // TODO(cduvall): Take out when all APIs have been converted to features. | 339 // 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); | 534 availability.message); |
519 return; | 535 return; |
520 } | 536 } |
521 | 537 |
522 this.runHooks_(mod); | 538 this.runHooks_(mod); |
523 return mod; | 539 return mod; |
524 } | 540 } |
525 }; | 541 }; |
526 | 542 |
527 exports.$set('Binding', Binding); | 543 exports.$set('Binding', Binding); |
OLD | NEW |