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

Unified Diff: ui/webui/resources/js/cr.js

Issue 1228183002: cr.js: Replace usage of ES6 Map with Object. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix jsdoc. Created 5 years, 5 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/js/cr.js
diff --git a/ui/webui/resources/js/cr.js b/ui/webui/resources/js/cr.js
index ceb1eb9707474fb9d91f9bc6b12ad5b13858569f..f9b2c799b76357ac59341bf84db7ae6033c3acf6 100644
--- a/ui/webui/resources/js/cr.js
+++ b/ui/webui/resources/js/cr.js
@@ -318,9 +318,9 @@ var cr = function() {
* sent by the browser in response to the chrome.send call. The mapping is
* from ID to callback function; the ID is generated by sendWithCallback and
* is unique across all invocations of said method.
- * @type {!Map<string, Function>}
+ * @type {!Object<string, Function>}
Dan Beam 2015/07/09 22:11:15 nit: Object<string is redundant (just Object<Funct
James Hawkins 2015/07/09 22:19:50 Done.
*/
- var chromeSendCallbackMap = new Map();
+ var chromeSendCallbackMap = Object.create(null);
Dan Beam 2015/07/09 22:11:15 nit: I don't see any Object.prototype.* modificati
James Hawkins 2015/07/09 22:19:50 According to MDN, {} is equivalent to Object.creat
Dan Beam 2015/07/09 22:21:41 I get what you're saying, we just don't do that cu
/**
* The named method the WebUI handler calls directly in response to a
@@ -335,9 +335,9 @@ var cr = function() {
* response is tied to.
*/
function webUIResponse(id) {
- chromeSendCallbackMap.get(id).apply(
+ chromeSendCallbackMap[id].apply(
null, Array.prototype.slice.call(arguments, 1));
- chromeSendCallbackMap.delete(id);
+ delete chromeSendCallbackMap[id];
}
/**
@@ -353,16 +353,16 @@ var cr = function() {
*/
function sendWithCallback(methodName, args, callback) {
var id = methodName + createUid();
- chromeSendCallbackMap.set(id, callback);
+ chromeSendCallbackMap[id] = callback;
chrome.send(methodName, ['cr.webUIResponse', id].concat(args || []));
}
/**
* A registry of callbacks keyed by event name. Used by addWebUIListener to
* register listeners.
- * @type {!Map<string, Array<Function>>}
+ * @type {!Object<string, Array<Function>>}
Dan Beam 2015/07/09 22:11:15 same nit re: Object<string, -> Object<
James Hawkins 2015/07/09 22:19:50 Done.
*/
- var webUIListenerMap = new Map();
+ var webUIListenerMap = Object.create(null);
/**
* The named method the WebUI handler calls directly when an event occurs.
@@ -372,7 +372,7 @@ var cr = function() {
* @param {string} event The name of the event that has occurred.
*/
function webUIListenerCallback(event) {
- var listenerCallbacks = webUIListenerMap.get(event);
+ var listenerCallbacks = webUIListenerMap[event];
for (var i = 0; i < listenerCallbacks.length; i++) {
var callback = listenerCallbacks[i];
callback.apply(null, Array.prototype.slice.call(arguments, 1));
@@ -386,10 +386,10 @@ var cr = function() {
* @param {Function} callback The callback run when the event is fired.
*/
function addWebUIListener(event, callback) {
- if (!webUIListenerMap.has(event))
- webUIListenerMap.set(event, [callback]);
+ if (event in webUIListenerMap)
+ webUIListenerMap[event].push(callback);
else
- webUIListenerMap.get(event).push(callback);
+ webUIListenerMap[event] = [callback];
}
return {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698