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

Unified Diff: extensions/renderer/resources/binding.js

Issue 1864733002: Prepare Chrome Extensions for ES2015 RegExp semantics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move comment Created 4 years, 8 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 | « no previous file | extensions/renderer/safe_builtins.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/resources/binding.js
diff --git a/extensions/renderer/resources/binding.js b/extensions/renderer/resources/binding.js
index d40b18f6a26a17741df7e41df1112f4466c39800..0c96fce85dbd7fce8c442fc1fd610a2e8cfca9ad 100644
--- a/extensions/renderer/resources/binding.js
+++ b/extensions/renderer/resources/binding.js
@@ -138,7 +138,7 @@ function getPlatform() {
];
for (var i = 0; i < platforms.length; i++) {
- if ($RegExp.test(platforms[i][0], navigator.appVersion)) {
+ if ($RegExp.exec(platforms[i][0], navigator.appVersion)) {
return platforms[i][1];
}
}
@@ -302,15 +302,29 @@ Binding.prototype = {
enumValue.name : enumValue;
if (enumValue) { // Avoid setting any empty enums.
// Make all properties in ALL_CAPS_STYLE.
- // Replace myEnum-Foo with my_Enum-Foo:
- var propertyName =
- $String.replace(enumValue, /([a-z])([A-Z])/g, '$1_$2');
- // Replace my_Enum-Foo with my_Enum_Foo:
- propertyName = $String.replace(propertyName, /\W/g, '_');
+ //
+ // The built-in versions of $String.replace call other built-ins,
+ // which may be clobbered. Instead, manually build the property
+ // name.
+ //
// If the first character is a digit (we know it must be one of
// a digit, a letter, or an underscore), precede it with an
// underscore.
- propertyName = $String.replace(propertyName, /^(\d)/g, '_$1');
+ var propertyName = ($RegExp.exec(/\d/, enumValue[0])) ? '_' : '';
+ for (var i = 0; i < enumValue.length; ++i) {
+ var next;
+ if (i > 0 && $RegExp.exec(/[a-z]/, enumValue[i-1]) &&
+ $RegExp.exec(/[A-Z]/, enumValue[i])) {
+ // Replace myEnum-Foo with my_Enum-Foo:
+ next = '_' + enumValue[i];
+ } else if ($RegExp.exec(/\W/, enumValue[i])) {
+ // Replace my_Enum-Foo with my_Enum_Foo:
+ next = '_';
+ } else {
+ next = enumValue[i];
+ }
+ propertyName += next;
+ }
// Uppercase (replace my_Enum_Foo with MY_ENUM_FOO):
propertyName = $String.toUpperCase(propertyName);
mod[id][propertyName] = enumValue;
« no previous file with comments | « no previous file | extensions/renderer/safe_builtins.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698