use array_p wherever appropriate
authorJohn Foerch <jjfoerch@earthlink.net>
Fri, 16 Sep 2011 17:40:21 +0000 (16 13:40 -0400)
committerJohn Foerch <jjfoerch@earthlink.net>
Thu, 29 Nov 2012 02:23:51 +0000 (28 21:23 -0500)
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
modules/interactive.js
modules/keymap.js
modules/opensearch.js

index 0fe3f6a..6adbec1 100644 (file)
@@ -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) {
index 1e9f87a..8eec0b0 100644 (file)
@@ -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;
index 2f9f653..ee02f22 100644 (file)
@@ -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;
index 09cafe0..d90ec7b 100644 (file)
@@ -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];