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

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

Issue 1863573004: Prepare Chrome Extensions for ES2015 RegExp semantics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor change and fix rebase 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') | extensions/renderer/safe_builtins.cc » ('J')
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..31abbb4386b719fce09afd8afc1c494b96c5762b 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,22 @@ 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, '_');
// 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
// 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++) {
Devlin 2016/04/05 19:15:50 ++i
Dan Ehrenberg 2016/04/05 20:20:57 Done
+ 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
+ $RegExp.exec(/[A-Z]/, enumValue[i])) {
+ // Replace myEnum-Foo with my_Enum-Foo:
+ propertyName = propertyName + '_' + enumValue[i];
+ } else if ($RegExp.exec(/\W/, enumValue[i])) {
+ // Replace my_Enum-Foo with my_Enum_Foo:
+ propertyName = propertyName + '_';
+ } else {
+ propertyName = propertyName + enumValue[i];
+ }
+ }
// 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') | extensions/renderer/safe_builtins.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698