diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/NativeArray.java b/mozilla/js/rhino/src/org/mozilla/javascript/NativeArray.java index e50cb920a8a..a03d6aa945d 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/NativeArray.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/NativeArray.java @@ -194,6 +194,8 @@ public class NativeArray extends IdScriptableObject "reduce", 2); addIdFunctionProperty(ctor, ARRAY_TAG, ConstructorId_reduceRight, "reduceRight", 2); + addIdFunctionProperty(ctor, ARRAY_TAG, ConstructorId_isArray, + "isArray", 1); super.fillConstructorProperties(ctor); } @@ -271,6 +273,9 @@ public class NativeArray extends IdScriptableObject id = -id; continue again; } + + case ConstructorId_isArray: + return args.length > 0 && (args[0] instanceof NativeArray); case Id_constructor: { boolean inNewExpr = (thisObj == null); @@ -1722,7 +1727,8 @@ public class NativeArray extends IdScriptableObject ConstructorId_map = -Id_map, ConstructorId_some = -Id_some, ConstructorId_reduce = -Id_reduce, - ConstructorId_reduceRight = -Id_reduceRight; + ConstructorId_reduceRight = -Id_reduceRight, + ConstructorId_isArray = -24; /** * Internal representation of the JavaScript array's length property. diff --git a/mozilla/js/rhino/testsrc/doctests/array.isarray.doctest b/mozilla/js/rhino/testsrc/doctests/array.isarray.doctest new file mode 100644 index 00000000000..d26a206d339 --- /dev/null +++ b/mozilla/js/rhino/testsrc/doctests/array.isarray.doctest @@ -0,0 +1,26 @@ +js> Array.isArray; +function isArray() { [native code for Array.isArray, arity=1] } + +js> Array.isArray() +false +js> Array.isArray(undefined); +false +js> Array.isArray(null); +false +js> Array.isArray(true); +false +js> Array.isArray(1); +false +js> Array.isArray('hello'); +false +js> Array.isArray({}); +false +js> Array.isArray(function(){}) +false +js> (function() { print(Array.isArray(arguments)) })() +false + +js> Array.isArray([]) +true +js> Array.isArray(new Array()) +true