From c4f07a2cbb7f9ff472e17fc65d2670361bc20081 Mon Sep 17 00:00:00 2001 From: John Foerch Date: Fri, 16 Sep 2011 13:40:21 -0400 Subject: [PATCH] use array_p wherever appropriate There is no simple reliable way to detecting whether an object is an array that works across all XULRunner versions. Therefore we head off possible sources of error by using one predicate function that we can test and fix as needed. --- modules/input.js | 2 +- modules/interactive.js | 2 +- modules/keymap.js | 4 ++-- modules/opensearch.js | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/input.js b/modules/input.js index 0fe3f6a..6adbec1 100644 --- a/modules/input.js +++ b/modules/input.js @@ -224,7 +224,7 @@ sequence: if (binding) { if (binding.browser_object !== undefined) I.binding_browser_object = binding.browser_object; - if (binding.constructor == Array) { + if (array_p(binding)) { keymaps = binding; input_show_partial_sequence(window, I); } else if (binding.command) { diff --git a/modules/interactive.js b/modules/interactive.js index 1e9f87a..8eec0b0 100644 --- a/modules/interactive.js +++ b/modules/interactive.js @@ -126,7 +126,7 @@ function alternates () { let alts = Array.prototype.slice.call(arguments, 0); return function (I) { var index = 0; - if (I.prefix_argument instanceof Array) { + if (array_p(I.prefix_argument)) { let num = I.prefix_argument = I.prefix_argument[0]; while (num >= 4 && index + 1 < alts.length) { num = num / 4; diff --git a/modules/keymap.js b/modules/keymap.js index 2f9f653..ee02f22 100644 --- a/modules/keymap.js +++ b/modules/keymap.js @@ -486,7 +486,7 @@ function define_key (kmap, seq, cmd) { if (typeof seq == "string" && seq.length > 1) seq = seq.split(" "); - if (!(typeof seq == "object") || !(seq instanceof Array)) + if (! array_p(seq)) seq = [seq]; // normalize the order of modifiers in key combos @@ -592,7 +592,7 @@ function read_key_binding_key (window, state, event) { return; } - if (binding.constructor == Array) { //keymaps stack + if (array_p(binding)) { //keymaps stack window.minibuffer._restore_normal_state(); window.minibuffer._input_text = state.key_sequence.join(" ") + " "; state.target_keymap = binding; diff --git a/modules/opensearch.js b/modules/opensearch.js index 09cafe0..d90ec7b 100644 --- a/modules/opensearch.js +++ b/modules/opensearch.js @@ -158,13 +158,13 @@ opensearch_description.prototype = { delete result; delete lspec; - if (!(data instanceof Array && + if (!(array_p(data) && data.length >= 2 && typeof(data[0]) == "string" && data[0] == str && - data[1] instanceof Array)) + array_p(data[1]))) yield co_return(null); - if (data[2] && data[2] instanceof Array && + if (data[2] && array_p(data[2]) && data[2].length == data[1].length) { var descriptions = data[2]; -- 2.11.4.GIT