From b06ec5482320c2f40332e54f6728e3cbfdf47a0d Mon Sep 17 00:00:00 2001 From: Scott Jaderholm Date: Fri, 29 Jan 2016 23:24:57 -0800 Subject: [PATCH] Use var for some non-top-level functions These functions were causing SyntaxErrors in strict mode because "functions may be declared only at top level or immediately within another function" --- modules/buffer.js | 44 +++++++++++++++++---------------- modules/compat/Map.js | 2 +- modules/download-manager.js | 6 ++--- modules/env.js | 6 ++--- modules/favicon.js | 2 +- modules/mime-type-override.js | 48 +++++++++++++++++++----------------- modules/session.js | 57 +++++++++++++++++++++++-------------------- modules/spawn-process.js | 4 +-- modules/theme.js | 12 ++++----- modules/window.js | 2 +- 10 files changed, 96 insertions(+), 87 deletions(-) diff --git a/modules/buffer.js b/modules/buffer.js index 667aef2..7f15a6f 100644 --- a/modules/buffer.js +++ b/modules/buffer.js @@ -759,30 +759,32 @@ function create_buffer (window, creator, target) { { let queued_buffer_creators = null; - function create_buffer_in_current_window (creator, target, focus_existing) { - function process_queued_buffer_creators (window) { - for (var i = 0; i < queued_buffer_creators.length; ++i) { - var x = queued_buffer_creators[i]; - create_buffer(window, x[0], x[1]); + var create_buffer_in_current_window = + function create_buffer_in_current_window (creator, target, focus_existing) { + function process_queued_buffer_creators (window) { + for (var i = 0; i < queued_buffer_creators.length; ++i) { + var x = queued_buffer_creators[i]; + create_buffer(window, x[0], x[1]); + } + queued_buffer_creators = null; } - queued_buffer_creators = null; - } - if (target == OPEN_NEW_WINDOW) - throw new Error("invalid target"); - var window = get_recent_conkeror_window(); - if (window) { - if (focus_existing) - window.focus(); - create_buffer(window, creator, target); - } else if (queued_buffer_creators != null) { - queued_buffer_creators.push([creator,target]); - } else { - queued_buffer_creators = []; - window = make_window(creator); - add_hook.call(window, "window_initialize_late_hook", process_queued_buffer_creators); + if (target == OPEN_NEW_WINDOW) + throw new Error("invalid target"); + var window = get_recent_conkeror_window(); + if (window) { + if (focus_existing) + window.focus(); + create_buffer(window, creator, target); + } else if (queued_buffer_creators != null) { + queued_buffer_creators.push([creator,target]); + } else { + queued_buffer_creators = []; + window = make_window(creator); + add_hook.call(window, "window_initialize_late_hook", + process_queued_buffer_creators); + } } - } }; diff --git a/modules/compat/Map.js b/modules/compat/Map.js index 4dd0152..26ae68e 100644 --- a/modules/compat/Map.js +++ b/modules/compat/Map.js @@ -12,7 +12,7 @@ **/ if (typeof(Map) == "undefined") { - function Map() { + var Map = function Map() { this.data = {} this.size = 0; } diff --git a/modules/download-manager.js b/modules/download-manager.js index 490904f..f5a7737 100644 --- a/modules/download-manager.js +++ b/modules/download-manager.js @@ -24,13 +24,13 @@ try { throw "bad Downloads.jsm version"; var use_downloads_jsm = true; - function lookup_download(download) { + var lookup_download = function lookup_download(download) { return id_to_download_info.get(download); } } catch (e) { var use_downloads_jsm = false; - function lookup_download(download) { + var lookup_download = function lookup_download(download) { return id_to_download_info.get(download.id); } } @@ -1126,7 +1126,7 @@ function open_download_buffer_automatically (info) { download_show(buf ? buf.window : null, target, info.mozilla_info); } else { var timer = null; - function finish () { + var finish = function finish () { timer.cancel(); } add_hook.call(info, "download_finished_hook", finish); diff --git a/modules/env.js b/modules/env.js index 270d6f7..42cf63a 100644 --- a/modules/env.js +++ b/modules/env.js @@ -14,7 +14,7 @@ { let xul_runtime = Cc['@mozilla.org/xre/app-info;1'] .getService(Ci.nsIXULRuntime); - function get_os () { + var get_os = function get_os () { return xul_runtime.OS; } } @@ -41,7 +41,7 @@ function get_mozilla_version () { { let env = Cc['@mozilla.org/process/environment;1'] .getService(Ci.nsIEnvironment); - function getenv (variable) { + var getenv = function getenv (variable) { if (env.exists(variable)) return env.get(variable); return null; @@ -79,7 +79,7 @@ function get_home_directory () { */ { let profile_name = null; - function get_current_profile () { + var get_current_profile = function get_current_profile () { if (profile_name) return profile_name; if ("@mozilla.org/profile/manager;1" in Cc) { diff --git a/modules/favicon.js b/modules/favicon.js index 0f7230d..d1f0d92 100644 --- a/modules/favicon.js +++ b/modules/favicon.js @@ -31,7 +31,7 @@ define_variable("favicon_image_max_size", 1024, buffer.current_uri, icon_url, false); }; } - function favicon_set (buffer, icon_url) { + var favicon_set = function favicon_set (buffer, icon_url) { favicon_set_internal(buffer, icon_url); buffer.icon = icon_url.spec; } diff --git a/modules/mime-type-override.js b/modules/mime-type-override.js index 4bd9a30..140ede3 100644 --- a/modules/mime-type-override.js +++ b/modules/mime-type-override.js @@ -34,9 +34,10 @@ let table_size = 0; // uri must be an instance of nsIURI - function can_override_mime_type_for_uri(uri) { - return uri.schemeIs("http") || uri.schemeIs("https"); - } + var can_override_mime_type_for_uri = + function can_override_mime_type_for_uri (uri) { + return uri.schemeIs("http") || uri.schemeIs("https"); + } let clear_override = function(uri_string) { delete table[uri_string]; @@ -77,26 +78,27 @@ // return true for the passed uri. // mime_type must be a string - function override_mime_type_for_next_load(uri, mime_type) { - yield cache_entry_clear(CACHE_SESSION_HTTP, uri); - - var obj = table[uri.spec]; - if (obj) - obj.timer.cancel(); - else - table_size++; - - obj = { mime_type: mime_type }; - - obj.timer = call_after_timeout(function () { - clear_override(uri.spec); - }, timeout); - - if (table_size == 1) { - observer_service.addObserver(observer, EXAMINE_TOPIC, false); - observer_service.addObserver(observer, EXAMINE_MERGED_TOPIC, false); + var override_mime_type_for_next_load = + function override_mime_type_for_next_load(uri, mime_type) { + yield cache_entry_clear(CACHE_SESSION_HTTP, uri); + + var obj = table[uri.spec]; + if (obj) + obj.timer.cancel(); + else + table_size++; + + obj = { mime_type: mime_type }; + + obj.timer = call_after_timeout(function () { + clear_override(uri.spec); + }, timeout); + + if (table_size == 1) { + observer_service.addObserver(observer, EXAMINE_TOPIC, false); + observer_service.addObserver(observer, EXAMINE_MERGED_TOPIC, false); + } + table[uri.spec] = obj; } - table[uri.spec] = obj; - } } provide("mime-type-override"); diff --git a/modules/session.js b/modules/session.js index 54e21b3..806f260 100644 --- a/modules/session.js +++ b/modules/session.js @@ -54,7 +54,7 @@ * during buffer init, whether the buffer was created by a session or * by other means. */ - function session_token () {} + var session_token = function session_token () {} session_token.prototype = { constructor: session_token }; @@ -63,7 +63,7 @@ * session_get generates and returns a structure containing session * data for the current group of open windows. */ - function session_get () { + var session_get = function session_get () { let windows = {}; let x = 0; for_each_window(function (w) { @@ -94,7 +94,7 @@ * with optional buffer_idx as the buffer index at which to begin * overwriting existing buffers. */ - function session_load (session, window, buffer_idx) { + var session_load = function session_load (session, window, buffer_idx) { if (! (session[0] && session[0][0])) throw new Error("Invalid 'session' argument."); let s = 0; @@ -209,7 +209,7 @@ /** * session_load_window_new loads the given session into new windows. */ - function session_load_window_new (session) { + var session_load_window_new = function session_load_window_new (session) { session_load(session); } @@ -218,25 +218,27 @@ * session's first window being appended to window. No existing * buffers will be overwritten. */ - function session_load_window_current (session, window) { - let w = window ? window : get_recent_conkeror_window(); - session_load(session, w); - } + var session_load_window_current = + function session_load_window_current (session, window) { + let w = window ? window : get_recent_conkeror_window(); + session_load(session, w); + } /** * session_load_window_current loads the given session, with the * session's first window replacing the given window. All buffers in * the given window will be overwritten. */ - function session_load_window_current_replace (session, window) { - let w = window ? window : get_recent_conkeror_window(); - session_load(session, w, 0); - } + var session_load_window_current_replace = + function session_load_window_current_replace (session, window) { + let w = window ? window : get_recent_conkeror_window(); + session_load(session, w, 0); + } /** * session_write writes the given session to the file given by path. */ - function session_write (path, session) { + var session_write = function session_write (path, session) { if (! (path instanceof Ci.nsIFile)) path = make_file(path); if (! session) @@ -248,7 +250,7 @@ * session_read reads session data from the given file path, * and returns a decoded session structure. */ - function session_read (path) { + var session_read = function session_read (path) { if (! (path instanceof Ci.nsIFile)) path = make_file(path); var rv = JSON.parse(read_text_file(path)); @@ -264,7 +266,7 @@ /** * session_remove deletes the given session file. */ - function session_remove (path) { + var session_remove = function session_remove (path) { if (! (path instanceof Ci.nsIFile)) path = make_file(path); path.remove(false); @@ -347,17 +349,20 @@ 'Whether to load the auto-saved session when the browser is started. '+ 'May be true, false, or "prompt".'); - function session_auto_save_load_window_new () { - session_load_window_new(_session_auto_save_cached); - } + var session_auto_save_load_window_new = + function session_auto_save_load_window_new () { + session_load_window_new(_session_auto_save_cached); + } - function session_auto_save_load_window_current (window) { - session_load_window_current(_session_auto_save_cached, window); - } + var session_auto_save_load_window_current = + function session_auto_save_load_window_current (window) { + session_load_window_current(_session_auto_save_cached, window); + } - function session_auto_save_load_window_current_replace (window) { - session_load_window_current_replace(_session_auto_save_cached, window); - } + var session_auto_save_load_window_current_replace = + function session_auto_save_load_window_current_replace (window) { + session_load_window_current_replace(_session_auto_save_cached, window); + } define_variable("session_auto_save_auto_load_fn", null, @@ -381,7 +386,7 @@ return f; }; - function session_auto_save_save () { + var session_auto_save_save = function session_auto_save_save () { let f = _session_auto_save_file_get(); let s = session_get(); if (s[0]) @@ -390,7 +395,7 @@ f.remove(false); } - function session_auto_save_remove () { + var session_auto_save_remove = function session_auto_save_remove () { let f = _session_auto_save_file_get(); if (f.exists()) f.remove(false); diff --git a/modules/spawn-process.js b/modules/spawn-process.js index c42b24e..7bf5d7d 100644 --- a/modules/spawn-process.js +++ b/modules/spawn-process.js @@ -311,7 +311,7 @@ function spawn_process (program_name, args, working_dir, fail("setup timeout"); }, spawn_process_helper_setup_timeout); - function wait_for_fd_sockets () { + var wait_for_fd_sockets = function wait_for_fd_sockets () { var remaining_streams = total_fds * 2; var timer = null; function handler () { @@ -338,7 +338,7 @@ function spawn_process (program_name, args, working_dir, var control_data = ""; - function handle_control_input () { + var handle_control_input = function handle_control_input () { if (terminate_pending) return; try { diff --git a/modules/theme.js b/modules/theme.js index 3a07611..99c3456 100644 --- a/modules/theme.js +++ b/modules/theme.js @@ -15,7 +15,7 @@ "nsIURI's, or nsIFile's. Chrome urls must be given as "+ "strings."); - function theme_cssfile_module (cssfile) { + var theme_cssfile_module = function theme_cssfile_module (cssfile) { cssfile = cssfile.substring(0, cssfile.indexOf('.')); var sep = cssfile.indexOf('--'); if (sep == -1) @@ -24,7 +24,7 @@ return cssfile.substring(0, sep); } - function theme (location, sheets) { + var theme = function theme (location, sheets) { this.location = location; this.sheets = sheets; } @@ -41,7 +41,7 @@ } }; - function theme_find (name) { + var theme_find = function theme_find (name) { if (loaded_themes[name]) return loaded_themes[name]; for each (var path in theme_load_paths) { @@ -69,7 +69,7 @@ return null; } - function theme_load (name) { + var theme_load = function theme_load (name) { var th = theme_find(name); if (! th) throw new Error("theme "+name+" not found."); for each (var cssfile in th.sheets) { @@ -90,7 +90,7 @@ } } - function theme_unload (name) { + var theme_unload = function theme_unload (name) { var th = theme_find(name); for each (var cssfile in th.sheets) { let module = theme_cssfile_module(cssfile); @@ -105,7 +105,7 @@ delete loaded_themes[name]; } - function theme_module (module) { + var theme_module = function theme_module (module) { for (var cssfile in themes[module]) { if (themes[module][cssfile].length > 0) themes[module][cssfile][0].register(cssfile); diff --git a/modules/window.js b/modules/window.js index 6c9544e..181aeb4 100644 --- a/modules/window.js +++ b/modules/window.js @@ -326,7 +326,7 @@ function call_builtin_command (window, command, clear_mark) { if (clear_mark) m.current_state.mark_active = false; } else { - function attempt_command (element) { + var attempt_command = function attempt_command (element) { var c; if (element.controllers && (c = element.controllers.getControllerForCommand(command)) != null -- 2.11.4.GIT