diff options
author | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-13 23:47:06 +0000 |
---|---|---|
committer | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-13 23:47:06 +0000 |
commit | 3ed462685a542d3a9625d8fa24a5755a283530ae (patch) | |
tree | 72b60d41d6294059527a5120df595eb7c73f48ab /chrome | |
parent | baa88b42ff4fe68d8bd096b2c4c28a4ebdac6910 (diff) | |
download | chromium_src-3ed462685a542d3a9625d8fa24a5755a283530ae.zip chromium_src-3ed462685a542d3a9625d8fa24a5755a283530ae.tar.gz chromium_src-3ed462685a542d3a9625d8fa24a5755a283530ae.tar.bz2 |
DOMUI etc. Use the built in bind method of Function now that V8 supports it.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/3308030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59303 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
30 files changed, 95 insertions, 165 deletions
diff --git a/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_list.js b/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_list.js index 46db804..7100056 100644 --- a/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_list.js +++ b/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_list.js @@ -72,11 +72,11 @@ cr.define('bmm', function() { this.addEventListener('mousedown', this.handleMouseDown_); // HACK(arv): http://crbug.com/40902 - window.addEventListener('resize', cr.bind(this.redraw, this)); + window.addEventListener('resize', this.redraw.bind(this)); // We could add the ContextMenuButton in the BookmarkListItem but it slows // down redraws a lot so we do this on mouseovers instead. - this.addEventListener('mouseover', cr.bind(this.handleMouseOver_, this)); + this.addEventListener('mouseover', this.handleMouseOver_.bind(this)); }, createItem: function(bookmarkNode) { @@ -110,7 +110,7 @@ cr.define('bmm', function() { reload: function() { var parentId = this.parentId; - var callback = cr.bind(this.handleBookmarkCallback_, this); + var callback = this.handleBookmarkCallback_.bind(this); this.loading_ = true; if (!parentId) { diff --git a/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_tree.js b/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_tree.js index 453692c..c2ec844 100644 --- a/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_tree.js +++ b/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_tree.js @@ -78,7 +78,7 @@ cr.define('bmm', function() { }; // Clean up once per session but wait until things settle down a bit. - setTimeout(cr.bind(expandedManager.cleanUp, expandedManager), 1e4); + setTimeout(expandedManager.cleanUp.bind(expandedManager), 1e4); /** * Creates a new tree item for a bookmark node. diff --git a/chrome/browser/resources/bookmark_manager/main.html b/chrome/browser/resources/bookmark_manager/main.html index a1afc34..ae5fb82 100644 --- a/chrome/browser/resources/bookmark_manager/main.html +++ b/chrome/browser/resources/bookmark_manager/main.html @@ -1017,21 +1017,21 @@ var dnd = { }, init: function() { - var boundClearData = cr.bind(this.clearDragData, this); + var boundClearData = this.clearDragData.bind(this); function deferredClearData() { setTimeout(boundClearData); } - document.addEventListener('dragstart', cr.bind(this.handleDragStart, this)); - document.addEventListener('dragenter', cr.bind(this.handleDragEnter, this)); - document.addEventListener('dragover', cr.bind(this.handleDragOver, this)); - document.addEventListener('dragleave', cr.bind(this.handleDragLeave, this)); - document.addEventListener('drop', cr.bind(this.handleDrop, this)); + document.addEventListener('dragstart', this.handleDragStart.bind(this)); + document.addEventListener('dragenter', this.handleDragEnter.bind(this)); + document.addEventListener('dragover', this.handleDragOver.bind(this)); + document.addEventListener('dragleave', this.handleDragLeave.bind(this)); + document.addEventListener('drop', this.handleDrop.bind(this)); document.addEventListener('dragend', deferredClearData); document.addEventListener('mouseup', deferredClearData); - chrome.experimental.bookmarkManager.onDragEnter.addListener(cr.bind( - this.handleChromeDragEnter, this)); + chrome.experimental.bookmarkManager.onDragEnter.addListener( + this.handleChromeDragEnter.bind(this)); chrome.experimental.bookmarkManager.onDragLeave.addListener( deferredClearData); chrome.experimental.bookmarkManager.onDrop.addListener(deferredClearData); diff --git a/chrome/browser/resources/downloads.html b/chrome/browser/resources/downloads.html index 7fc2f3c..dd40f57 100644 --- a/chrome/browser/resources/downloads.html +++ b/chrome/browser/resources/downloads.html @@ -198,15 +198,6 @@ html[dir=rtl] .name { // Helper functions function $(o) {return document.getElementById(o);} -function bind(fn, selfObj, var_args) { - var boundArgs = Array.prototype.slice.call(arguments, 2); - return function() { - var args = Array.prototype.slice.call(arguments); - args.unshift.apply(args, boundArgs); - return fn.apply(selfObj, args); - } -} - /** * Sets the display style of a node. */ @@ -385,7 +376,7 @@ function Download(download) { // Container for all 'safe download' UI. this.safe_ = createElementWithClassName('div', 'safe'); - this.safe_.ondragstart = bind(this.drag_, this); + this.safe_.ondragstart = this.drag_.bind(this); this.node.appendChild(this.safe_); if (download.state != Download.States.COMPLETE) { @@ -412,7 +403,7 @@ function Download(download) { this.nodeTitleArea_ = createElementWithClassName('div', 'title-area'); this.safe_.appendChild(this.nodeTitleArea_); - this.nodeFileLink_ = createLink(bind(this.openFile_, this), ''); + this.nodeFileLink_ = createLink(this.openFile_.bind(this), ''); this.nodeFileLink_.className = 'name'; this.nodeFileLink_.style.display = 'none'; this.nodeTitleArea_.appendChild(this.nodeFileLink_); @@ -435,26 +426,26 @@ function Download(download) { // http://code.google.com/p/chromium-os/issues/detail?id=916. var showinfolder = localStrings.getString('control_showinfolder'); if (showinfolder) { - this.controlShow_ = createLink(bind(this.show_, this), showinfolder); + this.controlShow_ = createLink(this.show_.bind(this), showinfolder); this.nodeControls_.appendChild(this.controlShow_); } else { this.controlShow_ = null; } // Pause/Resume are a toggle. - this.controlPause_ = createLink(bind(this.togglePause_, this), + this.controlPause_ = createLink(this.togglePause_.bind(this), localStrings.getString('control_pause')); this.nodeControls_.appendChild(this.controlPause_); - this.controlResume_ = createLink(bind(this.togglePause_, this), + this.controlResume_ = createLink(this.togglePause_.bind(this), localStrings.getString('control_resume')); this.nodeControls_.appendChild(this.controlResume_); - this.controlRemove_ = createLink(bind(this.remove_, this), + this.controlRemove_ = createLink(this.remove_.bind(this), localStrings.getString('control_removefromlist')); this.nodeControls_.appendChild(this.controlRemove_); - this.controlCancel_ = createLink(bind(this.cancel_, this), + this.controlCancel_ = createLink(this.cancel_.bind(this), localStrings.getString('control_cancel')); this.nodeControls_.appendChild(this.controlCancel_); @@ -465,11 +456,11 @@ function Download(download) { this.dangerDesc_ = document.createElement("div"); this.danger_.appendChild(this.dangerDesc_); - this.dangerSave_ = createButton(bind(this.saveDangerous_, this), + this.dangerSave_ = createButton(this.saveDangerous_.bind(this), localStrings.getString("danger_save")); this.danger_.appendChild(this.dangerSave_); - this.dangerDiscard_ = createButton(bind(this.discardDangerous_, this), + this.dangerDiscard_ = createButton(this.discardDangerous_.bind(this), localStrings.getString("danger_discard")); this.danger_.appendChild(this.dangerDiscard_); diff --git a/chrome/browser/resources/net_internals/util.js b/chrome/browser/resources/net_internals/util.js index 86284d0..2c5c056 100644 --- a/chrome/browser/resources/net_internals/util.js +++ b/chrome/browser/resources/net_internals/util.js @@ -3,18 +3,6 @@ // found in the LICENSE file. /** - * Helper that binds the |this| object to a method to create a callback. - */ -Function.prototype.bind = function(thisObj) { - var func = this; - var args = Array.prototype.slice.call(arguments, 1); - return function() { - return func.apply(thisObj, - args.concat(Array.prototype.slice.call(arguments, 0))) - }; -}; - -/** * Inherit the prototype methods from one constructor into another. */ function inherits(childCtor, parentCtor) { diff --git a/chrome/browser/resources/new_new_tab.js b/chrome/browser/resources/new_new_tab.js index 895959b..7ba47c1 100644 --- a/chrome/browser/resources/new_new_tab.js +++ b/chrome/browser/resources/new_new_tab.js @@ -743,8 +743,8 @@ recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); */ function WindowTooltip(tooltipEl) { this.tooltipEl = tooltipEl; - this.boundHide_ = bind(this.hide, this); - this.boundHandleMouseOut_ = bind(this.handleMouseOut, this); + this.boundHide_ = this.hide.bind(this); + this.boundHandleMouseOut_ = this.handleMouseOut.bind(this); } WindowTooltip.trackMouseMove_ = function(e) { @@ -768,7 +768,7 @@ WindowTooltip.prototype = { } else { // focus this.linkEl_.addEventListener('blur', this.boundHide_); } - this.timer = window.setTimeout(bind(this.show, this, e.type, linkEl, tabs), + this.timer = window.setTimeout(this.show.bind(this, e.type, linkEl, tabs), WindowTooltip.DELAY); }, show: function(type, linkEl, tabs) { @@ -848,12 +848,12 @@ WindowTooltip.prototype = { var windowTooltip = new WindowTooltip($('window-tooltip')); -window.addEventListener('load', bind(logEvent, global, 'Tab.NewTabOnload', - true)); +window.addEventListener('load', + logEvent.bind(global, 'Tab.NewTabOnload', true)); window.addEventListener('resize', handleWindowResize); document.addEventListener('DOMContentLoaded', - bind(logEvent, global, 'Tab.NewTabDOMContentLoaded', true)); + logEvent.bind(global, 'Tab.NewTabDOMContentLoaded', true)); // Whether or not we should send the initial 'GetSyncMessage' to the backend // depends on the value of the attribue 'syncispresent' which the backend sets diff --git a/chrome/browser/resources/ntp/most_visited.js b/chrome/browser/resources/ntp/most_visited.js index bff2c1f..5b024b2 100644 --- a/chrome/browser/resources/ntp/most_visited.js +++ b/chrome/browser/resources/ntp/most_visited.js @@ -50,25 +50,25 @@ var MostVisited = (function() { this.createThumbnails_(); this.applyMostVisitedRects_(); - el.addEventListener('click', bind(this.handleClick_, this)); - el.addEventListener('keydown', bind(this.handleKeyDown_, this)); + el.addEventListener('click', this.handleClick_.bind(this)); + el.addEventListener('keydown', this.handleKeyDown_.bind(this)); document.addEventListener('DOMContentLoaded', - bind(this.ensureSmallGridCorrect, this)); + this.ensureSmallGridCorrect.bind(this)); // Commands - document.addEventListener('command', bind(this.handleCommand_, this)); - document.addEventListener('canExecute', bind(this.handleCanExecute_, this)); + document.addEventListener('command', this.handleCommand_.bind(this)); + document.addEventListener('canExecute', this.handleCanExecute_.bind(this)); // DND - el.addEventListener('dragstart', bind(this.handleDragStart_, this)); - el.addEventListener('dragenter', bind(this.handleDragEnter_, this)); - el.addEventListener('dragover', bind(this.handleDragOver_, this)); - el.addEventListener('dragleave', bind(this.handleDragLeave_, this)); - el.addEventListener('drop', bind(this.handleDrop_, this)); - el.addEventListener('dragend', bind(this.handleDragEnd_, this)); - el.addEventListener('drag', bind(this.handleDrag_, this)); - el.addEventListener('mousedown', bind(this.handleMouseDown_, this)); + el.addEventListener('dragstart', this.handleDragStart_.bind(this)); + el.addEventListener('dragenter', this.handleDragEnter_.bind(this)); + el.addEventListener('dragover', this.handleDragOver_.bind(this)); + el.addEventListener('dragleave', this.handleDragLeave_.bind(this)); + el.addEventListener('drop', this.handleDrop_.bind(this)); + el.addEventListener('dragend', this.handleDragEnd_.bind(this)); + el.addEventListener('drag', this.handleDrag_.bind(this)); + el.addEventListener('mousedown', this.handleMouseDown_.bind(this)); } MostVisited.prototype = { @@ -418,10 +418,10 @@ var MostVisited = (function() { // The timeout below is to allow WebKit to see that we turned off // pointer-event before moving the thumbnails so that we can get out of // hover mode. - window.setTimeout(bind(function() { + window.setTimeout((function() { this.invalidate_(); this.layout(); - }, this), 10); + }).bind(this), 10); e.preventDefault(); if (this.dragEndTimer_) { window.clearTimeout(this.dragEndTimer_); diff --git a/chrome/browser/resources/ntp/util.js b/chrome/browser/resources/ntp/util.js index b759356..ebd1e4d 100644 --- a/chrome/browser/resources/ntp/util.js +++ b/chrome/browser/resources/ntp/util.js @@ -11,15 +11,6 @@ function $(id) { return document.getElementById(id); } -function bind(fn, selfObj, var_args) { - var boundArgs = Array.prototype.slice.call(arguments, 2); - return function() { - var args = Array.prototype.slice.call(arguments); - args.unshift.apply(args, boundArgs); - return fn.apply(selfObj, args); - } -} - function url(s) { // http://www.w3.org/TR/css3-values/#uris // Parentheses, commas, whitespace characters, single quotes (') and double diff --git a/chrome/browser/resources/options/add_startup_page_overlay.js b/chrome/browser/resources/options/add_startup_page_overlay.js index 3926320..36eacae 100644 --- a/chrome/browser/resources/options/add_startup_page_overlay.js +++ b/chrome/browser/resources/options/add_startup_page_overlay.js @@ -31,7 +31,7 @@ cr.define('options', function() { var self = this; var addForm = $('addStartupPageForm'); - addForm.onreset = cr.bind(this.dismissOverlay_, this); + addForm.onreset = this.dismissOverlay_.bind(this); addForm.onsubmit = function(e) { var urlField = $('addStartupPageURL'); BrowserOptions.addStartupPage(urlField.value); @@ -39,8 +39,7 @@ cr.define('options', function() { self.dismissOverlay_(); return false; }; - $('addStartupPageURL').oninput = - cr.bind(this.updateAddButtonState_, this); + $('addStartupPageURL').oninput = this.updateAddButtonState_.bind(this); $('addStartupPageURL').onkeydown = function(e) { if (e.keyCode == 27) // Esc $('addStartupPageForm').reset(); @@ -52,7 +51,7 @@ cr.define('options', function() { list.selectionModel = selectionModel; selectionModel.addEventListener('change', - cr.bind(this.selectionChanged_, this)); + this.selectionChanged_.bind(this)); this.addEventListener('visibleChange', function(event) { $('addStartupPageURL').focus(); diff --git a/chrome/browser/resources/options/autofill_options.js b/chrome/browser/resources/options/autofill_options.js index 6c90563..d8a69b7 100644 --- a/chrome/browser/resources/options/autofill_options.js +++ b/chrome/browser/resources/options/autofill_options.js @@ -56,7 +56,7 @@ cr.define('options', function() { }; Preferences.getInstance().addEventListener('autofill.enabled', - cr.bind(self.updateEnabledState_, self)); + this.updateEnabledState_.bind(this)); }, /** diff --git a/chrome/browser/resources/options/browser_options.js b/chrome/browser/resources/options/browser_options.js index 71465c1..bdac565 100644 --- a/chrome/browser/resources/options/browser_options.js +++ b/chrome/browser/resources/options/browser_options.js @@ -32,8 +32,8 @@ cr.define('options', function() { $('startupAddButton').onclick = function(event) { OptionsPage.showOverlay('addStartupPageOverlay'); }; - $('startupRemoveButton').onclick = cr.bind( - this.removeSelectedStartupPages_, this); + $('startupRemoveButton').onclick = + this.removeSelectedStartupPages_.bind(this); $('startupUseCurrentButton').onclick = function(event) { chrome.send('setStartupPagesToCurrentPages'); }; @@ -53,7 +53,7 @@ cr.define('options', function() { list.selectionModel = new ListSelectionModel; list.selectionModel.addEventListener( - 'change', cr.bind(this.updateRemoveButtonState_, this)); + 'change', this.updateRemoveButtonState_.bind(this)); this.addEventListener('visibleChange', function(event) { $('startupPages').redraw(); @@ -61,9 +61,9 @@ cr.define('options', function() { // Initialize control enabled states. Preferences.getInstance().addEventListener('session.restore_on_startup', - cr.bind(this.updateCustomStartupPageControlStates_, this)); + this.updateCustomStartupPageControlStates_.bind(this)); Preferences.getInstance().addEventListener('homepage_is_newtabpage', - cr.bind(this.updateHomepageFieldState_, this)); + this.updateHomepageFieldState_.bind(this)); this.updateCustomStartupPageControlStates_(); this.updateHomepageFieldState_(); diff --git a/chrome/browser/resources/options/chromeos_accounts_user_list.js b/chrome/browser/resources/options/chromeos_accounts_user_list.js index 1f37f61..61ac473 100644 --- a/chrome/browser/resources/options/chromeos_accounts_user_list.js +++ b/chrome/browser/resources/options/chromeos_accounts_user_list.js @@ -25,7 +25,7 @@ cr.define('options.accounts', function() { List.prototype.decorate.call(this); // HACK(arv): http://crbug.com/40902 - window.addEventListener('resize', cr.bind(this.redraw, this)); + window.addEventListener('resize', this.redraw.bind(this)); this.addEventListener('click', this.handleClick_); diff --git a/chrome/browser/resources/options/chromeos_accounts_user_name_edit.js b/chrome/browser/resources/options/chromeos_accounts_user_name_edit.js index 33b5308..a590d81 100644 --- a/chrome/browser/resources/options/chromeos_accounts_user_name_edit.js +++ b/chrome/browser/resources/options/chromeos_accounts_user_name_edit.js @@ -39,7 +39,7 @@ cr.define('options.accounts', function() { this.pattern = format1String + '|' + format2String + '|' + format3String; - this.onkeypress = cr.bind(this.handleKeyPress_, this); + this.onkeypress = this.handleKeyPress_.bind(this); }, diff --git a/chrome/browser/resources/options/chromeos_language_add_language_overlay.js b/chrome/browser/resources/options/chromeos_language_add_language_overlay.js index d62f8a8..090b69ac 100644 --- a/chrome/browser/resources/options/chromeos_language_add_language_overlay.js +++ b/chrome/browser/resources/options/chromeos_language_add_language_overlay.js @@ -53,8 +53,7 @@ cr.define('options.language', function() { } button.languageCode = language.code; // Listen to user clicks. - button.addEventListener('click', - cr.bind(this.handleLanguageClick_, this)); + button.addEventListener('click', this.handleLanguageClick_.bind(this)); var li = document.createElement('li'); li.languageCode = language.code; li.appendChild(button); diff --git a/chrome/browser/resources/options/chromeos_language_list.js b/chrome/browser/resources/options/chromeos_language_list.js index 1a3ea13..265e028 100644 --- a/chrome/browser/resources/options/chromeos_language_list.js +++ b/chrome/browser/resources/options/chromeos_language_list.js @@ -82,17 +82,17 @@ cr.define('options.language', function() { this.selectionModel = new ListSingleSelectionModel; // HACK(arv): http://crbug.com/40902 - window.addEventListener('resize', cr.bind(this.redraw, this)); + window.addEventListener('resize', this.redraw.bind(this)); // Listen to pref change. Preferences.getInstance().addEventListener(this.pref, - cr.bind(this.handlePrefChange_, this)); + this.handlePrefChange_.bind(this)); // Listen to drag and drop events. - this.addEventListener('dragstart', cr.bind(this.handleDragStart_, this)); - this.addEventListener('dragenter', cr.bind(this.handleDragEnter_, this)); - this.addEventListener('dragover', cr.bind(this.handleDragOver_, this)); - this.addEventListener('drop', cr.bind(this.handleDrop_, this)); + this.addEventListener('dragstart', this.handleDragStart_.bind(this)); + this.addEventListener('dragenter', this.handleDragEnter_.bind(this)); + this.addEventListener('dragover', this.handleDragOver_.bind(this)); + this.addEventListener('drop', this.handleDrop_.bind(this)); }, createItem: function(languageCode) { diff --git a/chrome/browser/resources/options/chromeos_language_options.js b/chrome/browser/resources/options/chromeos_language_options.js index ac6d02b..2bff38d 100644 --- a/chrome/browser/resources/options/chromeos_language_options.js +++ b/chrome/browser/resources/options/chromeos_language_options.js @@ -51,12 +51,12 @@ cr.define('options', function() { LanguageList.decorate(languageOptionsList); languageOptionsList.addEventListener('change', - cr.bind(this.handleLanguageOptionsListChange_, this)); + this.handleLanguageOptionsListChange_.bind(this)); languageOptionsList.addEventListener('save', - cr.bind(this.handleLanguageOptionsListSave_, this)); + this.handleLanguageOptionsListSave_.bind(this)); this.addEventListener('visibleChange', - cr.bind(this.handleVisibleChange_, this)); + this.handleVisibleChange_.bind(this)); this.initializeInputMethodList_(); this.initializeLanguageCodeToInputMehotdIdsMap_(); @@ -67,7 +67,7 @@ cr.define('options', function() { }; // Set up remove button. $('language-options-remove-button').addEventListener('click', - cr.bind(this.handleRemoveButtonClick_, this)); + this.handleRemoveButtonClick_.bind(this)); // Setup add language overlay page. OptionsPage.registerOverlay(AddLanguageOverlay.getInstance()); @@ -75,7 +75,7 @@ cr.define('options', function() { // Listen to user clicks on the add language list. var addLanguageList = $('add-language-overlay-language-list'); addLanguageList.addEventListener('click', - cr.bind(this.handleAddLanguageListClick_, this)); + this.handleAddLanguageListClick_.bind(this)); }, // The preference is a CSV string that describes preload engines @@ -104,7 +104,7 @@ cr.define('options', function() { input.inputMethodId = inputMethod.id; // Listen to user clicks. input.addEventListener('click', - cr.bind(this.handleCheckboxClick_, this)); + this.handleCheckboxClick_.bind(this)); var label = document.createElement('label'); label.appendChild(input); label.appendChild(document.createTextNode(inputMethod.displayName)); @@ -123,7 +123,7 @@ cr.define('options', function() { } // Listen to pref change once the input method list is initialized. Preferences.getInstance().addEventListener(this.preloadEnginesPref, - cr.bind(this.handlePreloadEnginesPrefChange_, this)); + this.handlePreloadEnginesPrefChange_.bind(this)); }, /** diff --git a/chrome/browser/resources/options/chromeos_proxy_rules_list.js b/chrome/browser/resources/options/chromeos_proxy_rules_list.js index feef79d..063b5e2 100644 --- a/chrome/browser/resources/options/chromeos_proxy_rules_list.js +++ b/chrome/browser/resources/options/chromeos_proxy_rules_list.js @@ -25,7 +25,7 @@ cr.define('options.proxyexceptions', function() { List.prototype.decorate.call(this); // HACK(arv): http://crbug.com/40902 - window.addEventListener('resize', cr.bind(this.redraw, this)); + window.addEventListener('resize', this.redraw.bind(this)); this.addEventListener('click', this.handleClick_); diff --git a/chrome/browser/resources/options/clear_browser_data_overlay.js b/chrome/browser/resources/options/clear_browser_data_overlay.js index aab1af4..a0d13c0 100644 --- a/chrome/browser/resources/options/clear_browser_data_overlay.js +++ b/chrome/browser/resources/options/clear_browser_data_overlay.js @@ -36,7 +36,7 @@ cr.define('options', function() { $('clearBrowsingDataTimePeriod').initializeValues( templateData.clearBrowsingDataTimeList); - var f = cr.bind(this.updateCommitButtonState_, this); + var f = this.updateCommitButtonState_.bind(this); var types = ['browser.clear_data.browsing_history', 'browser.clear_data.download_history', 'browser.clear_data.cache', diff --git a/chrome/browser/resources/options/content_settings_exceptions_area.js b/chrome/browser/resources/options/content_settings_exceptions_area.js index 780159f..305361a 100644 --- a/chrome/browser/resources/options/content_settings_exceptions_area.js +++ b/chrome/browser/resources/options/content_settings_exceptions_area.js @@ -441,7 +441,7 @@ cr.define('options.contentSettings', function() { ExceptionsList.decorate(this.exceptionsList); this.exceptionsList.selectionModel.addEventListener( - 'change', cr.bind(this.handleOnSelectionChange_, this)); + 'change', this.handleOnSelectionChange_.bind(this)); var self = this; if (this.contentType != 'location' && diff --git a/chrome/browser/resources/options/cookies_view.js b/chrome/browser/resources/options/cookies_view.js index eece121..da01daa 100644 --- a/chrome/browser/resources/options/cookies_view.js +++ b/chrome/browser/resources/options/cookies_view.js @@ -31,10 +31,10 @@ cr.define('options', function() { options.CookiesTree.decorate(cookiesTree); cookiesTree.addEventListener('change', - cr.bind(this.handleCookieTreeChange_, this)); + this.handleCookieTreeChange_.bind(this)); $('cookiesSearchBox').addEventListener('keydown', - cr.bind(this.handleQueryEditKeyDown_, this)); + this.handleQueryEditKeyDown_.bind(this)); var self = this; $('clearCookieSearchButton').onclick = function(e) { @@ -199,7 +199,7 @@ cr.define('options', function() { } this.queryDelayTimerId_ = window.setTimeout( - cr.bind(this.searchCookie, this), 500); + this.searchCookie.bind(this), 500); }, initalized_: false, diff --git a/chrome/browser/resources/options/edit_search_engine_overlay.js b/chrome/browser/resources/options/edit_search_engine_overlay.js index f0daf57..b6f9fcc 100644 --- a/chrome/browser/resources/options/edit_search_engine_overlay.js +++ b/chrome/browser/resources/options/edit_search_engine_overlay.js @@ -44,7 +44,7 @@ cr.define('options', function() { 'editSearchEngineURL']; for (var i = 0; i < fieldIDs.length; i++) { var field = $(fieldIDs[i]); - field.oninput = cr.bind(this.validateFields_, this); + field.oninput = this.validateFields_.bind(this); field.onkeydown = function(e) { if (e.keyCode == 27) // Esc editForm.reset(); diff --git a/chrome/browser/resources/options/passwords_exceptions_list.js b/chrome/browser/resources/options/passwords_exceptions_list.js index 261a3b0..d344dd49 100644 --- a/chrome/browser/resources/options/passwords_exceptions_list.js +++ b/chrome/browser/resources/options/passwords_exceptions_list.js @@ -251,7 +251,7 @@ cr.define('options.passwordsExceptions', function() { PasswordsList.decorate(this.passwordsList); this.passwordsList.selectionModel.addEventListener( - 'change', cr.bind(this.handleOnSelectionChange_, this)); + 'change', this.handleOnSelectionChange_.bind(this)); var removeRow = cr.doc.createElement('button'); removeRow.textContent = templateData.passwordsRemoveButton; @@ -339,7 +339,7 @@ cr.define('options.passwordsExceptions', function() { PasswordExceptionsList.decorate(this.passwordExceptionsList); this.passwordExceptionsList.selectionModel.addEventListener( - 'change', cr.bind(this.handleOnSelectionChange_, this)); + 'change', this.handleOnSelectionChange_.bind(this)); var removeRow = cr.doc.createElement('button'); removeRow.textContent = templateData.passwordsRemoveButton; diff --git a/chrome/browser/resources/options/search_engine_manager.js b/chrome/browser/resources/options/search_engine_manager.js index c03c38d..d227905 100644 --- a/chrome/browser/resources/options/search_engine_manager.js +++ b/chrome/browser/resources/options/search_engine_manager.js @@ -33,7 +33,7 @@ cr.define('options', function() { this.list_.selectionModel = selectionModel; selectionModel.addEventListener('change', - cr.bind(this.selectionChanged_, this)); + this.selectionChanged_.bind(this)); var self = this; $('addSearchEngineButton').onclick = function(event) { diff --git a/chrome/browser/resources/shared/js/cr.js b/chrome/browser/resources/shared/js/cr.js index 77bc40d..25ba498 100644 --- a/chrome/browser/resources/shared/js/cr.js +++ b/chrome/browser/resources/shared/js/cr.js @@ -248,37 +248,6 @@ const cr = (function() { } /** - * Partially applies this function to a particular 'this object' and zero or - * more arguments. The result is a new function with some arguments of the - * first function pre-filled and the value of |this| 'pre-specified'. - * - * Remaining arguments specified at call-time are appended to the pre- - * specified ones. - * - * Usage: - * <pre>var barMethBound = bind(myFunction, myObj, 'arg1', 'arg2'); - * barMethBound('arg3', 'arg4');</pre> - * - * @param {Function} fn A function to partially apply. - * @param {Object|undefined} selfObj Specifies the object which |this| should - * point to when the function is run. If the value is null or undefined, - * it will default to the global object. - * @param {...*} var_args Additional arguments that are partially - * applied to the function. - * - * @return {!Function} A partially-applied form of the function bind() was - * invoked as a method of. - */ - function bind(fn, selfObj, var_args) { - var boundArgs = Array.prototype.slice.call(arguments, 2); - return function() { - var args = Array.prototype.slice.call(arguments); - args.unshift.apply(args, boundArgs); - return fn.apply(selfObj, args); - } - } - - /** * Dispatches a simple event on an event target. * @param {!EventTarget} target The event target to dispatch the event on. * @param {string} type The type of the event. @@ -355,7 +324,6 @@ const cr = (function() { PropertyKind: PropertyKind, createUid: createUid, getUid: getUid, - bind: bind, dispatchSimpleEvent: dispatchSimpleEvent, dispatchPropertyChange: dispatchPropertyChange, diff --git a/chrome/browser/resources/shared/js/cr/ui/command.js b/chrome/browser/resources/shared/js/cr/ui/command.js index 4f4610d..1011398 100644 --- a/chrome/browser/resources/shared/js/cr/ui/command.js +++ b/chrome/browser/resources/shared/js/cr/ui/command.js @@ -194,10 +194,10 @@ cr.define('cr.ui', function() { * @constructor */ function CommandManager(doc) { - doc.addEventListener('focus', cr.bind(this.handleFocus_, this), true); + doc.addEventListener('focus', this.handleFocus_.bind(this), true); // Make sure we add the listener to the bubbling phase so that elements can // prevent the command. - doc.addEventListener('keydown', cr.bind(this.handleKeyDown_, this), false); + doc.addEventListener('keydown', this.handleKeyDown_.bind(this), false); } /** diff --git a/chrome/browser/resources/shared/js/cr/ui/list.js b/chrome/browser/resources/shared/js/cr/ui/list.js index 234d8db..1ac2f9c 100644 --- a/chrome/browser/resources/shared/js/cr/ui/list.js +++ b/chrome/browser/resources/shared/js/cr/ui/list.js @@ -92,9 +92,9 @@ cr.define('cr.ui', function() { if (this.dataModel_ != dataModel) { if (!this.boundHandleDataModelSplice_) { this.boundHandleDataModelSplice_ = - cr.bind(this.handleDataModelSplice_, this); + this.handleDataModelSplice_.bind(this); this.boundHandleDataModelChange_ = - cr.bind(this.handleDataModelChange_, this); + this.handleDataModelChange_.bind(this); } if (this.dataModel_) { @@ -139,8 +139,8 @@ cr.define('cr.ui', function() { return; if (!this.boundHandleOnChange_) { - this.boundHandleOnChange_ = cr.bind(this.handleOnChange_, this); - this.boundHandleLeadChange_ = cr.bind(this.handleLeadChange_, this); + this.boundHandleOnChange_ = this.handleOnChange_.bind(this); + this.boundHandleLeadChange_ = this.handleLeadChange_.bind(this); } if (oldSm) { @@ -242,7 +242,7 @@ cr.define('cr.ui', function() { this.addEventListener('mousedown', this.handleMouseDownUp_); this.addEventListener('mouseup', this.handleMouseDownUp_); this.addEventListener('keydown', this.handleKeyDown); - this.addEventListener('scroll', cr.bind(this.redraw, this)); + this.addEventListener('scroll', this.redraw.bind(this)); // Make list focusable if (!this.hasAttribute('tabindex')) diff --git a/chrome/browser/resources/shared/js/cr/ui/splitter.js b/chrome/browser/resources/shared/js/cr/ui/splitter.js index 4f9510e..3ede5ea 100644 --- a/chrome/browser/resources/shared/js/cr/ui/splitter.js +++ b/chrome/browser/resources/shared/js/cr/ui/splitter.js @@ -67,7 +67,7 @@ cr.define('cr.ui', function() { * Initializes the element. */ decorate: function() { - this.addEventListener('mousedown', cr.bind(this.handleMouseDown_, this), + this.addEventListener('mousedown', this.handleMouseDown_.bind(this), true); }, @@ -77,8 +77,8 @@ cr.define('cr.ui', function() { */ startDrag: function(e) { if (!this.boundHandleMouseMove_) { - this.boundHandleMouseMove_ = cr.bind(this.handleMouseMove_, this); - this.boundHandleMouseUp_ = cr.bind(this.handleMouseUp_, this); + this.boundHandleMouseMove_ = this.handleMouseMove_.bind(this); + this.boundHandleMouseUp_ = this.handleMouseUp_.bind(this); } var doc = this.ownerDocument; diff --git a/chrome/browser/resources/shared/js/cr/ui/tree.js b/chrome/browser/resources/shared/js/cr/ui/tree.js index 1fa3352..598bfab 100644 --- a/chrome/browser/resources/shared/js/cr/ui/tree.js +++ b/chrome/browser/resources/shared/js/cr/ui/tree.js @@ -555,9 +555,9 @@ cr.define('cr.ui', function() { labelEl.appendChild(input); input.addEventListener('keydown', handleKeydown); - input.addEventListener('blur', cr.bind(function() { + input.addEventListener('blur', (function() { this.editing = false; - }, this)); + }).bind(this)); // Make sure that double clicks do not expand and collapse the tree // item. diff --git a/chrome/common/extensions/docs/examples/extensions/irc/servlet/index.html b/chrome/common/extensions/docs/examples/extensions/irc/servlet/index.html index f5fff2b..ec9cd0c 100644 --- a/chrome/common/extensions/docs/examples/extensions/irc/servlet/index.html +++ b/chrome/common/extensions/docs/examples/extensions/irc/servlet/index.html @@ -83,10 +83,10 @@ window.onunload = function() { function addServerConnection(server) {
var ws = new WebSocket("ws://" + location.host + "/ws");
var irc = new IRCConnection(server.name, server.port, server.nick,
- bind(ws, ws.send), // sendFunc
- bind(ws, ws.close)); // closeFunc
- ws.onopen = bind(irc, irc.onOpened);
- ws.onclose = bind(irc, irc.onClosed);
+ ws.send.bind(ws), // sendFunc
+ ws.close.bind(ws)); // closeFunc
+ ws.onopen = irc.onOpened.bind(irc);
+ ws.onclose = irc.onClosed.bind(irc);
ws.onmessage = function(message) {
irc.onMessage(message.data);
};
diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js index 0c40e08..8106782 100644 --- a/chrome/renderer/resources/extension_process_bindings.js +++ b/chrome/renderer/resources/extension_process_bindings.js @@ -199,12 +199,6 @@ var chrome = chrome || {}; request.callback ? true : false); } - function bind(obj, func) { - return function() { - return func.apply(obj, arguments); - }; - } - // Helper function for positioning pop-up windows relative to DOM objects. // Returns the absolute position of the given element relative to the hosting // browser frame. @@ -346,7 +340,7 @@ var chrome = chrome || {}; apiFunction.name = apiDef.namespace + "." + functionDef.name; apiFunctions[apiFunction.name] = apiFunction; - module[functionDef.name] = bind(apiFunction, function() { + module[functionDef.name] = (function() { var args = arguments; if (this.updateArguments) { // Functions whose signature has changed can define an @@ -375,7 +369,7 @@ var chrome = chrome || {}; chromeHidden.validate([retval], [this.definition.returns]); } return retval; - }); + }).bind(apiFunction); }); } |