Fix Bug 505862 - Implement Array.isArray

Patch from Raphael Speyer


git-svn-id: svn://10.0.0.236/trunk@257784 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
nboyd%atg.com 2009-07-24 01:26:14 +00:00
parent e0b96c5c54
commit cdfa99a296
2 changed files with 33 additions and 1 deletions

View File

@ -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.

View File

@ -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