1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00

Add Array.isArray

This commit is contained in:
Robert Krimen 2013-04-17 11:05:32 -07:00
parent 7d0ac026ea
commit 0da0545485
3 changed files with 19 additions and 0 deletions

View File

@ -266,3 +266,12 @@ func TestArray_sort(t *testing.T) {
test("pqr", "-10,0.05,1,100,401,5,72,8")
test("stu", "-10,0.05,1,5,8,72,100,401")
}
func TestArray_isArray(t *testing.T) {
Terst(t)
test := runTest()
test(`
[ Array.isArray(), Array.isArray([]), Array.isArray({}) ];
`, "false,true,false")
}

View File

@ -451,3 +451,8 @@ func builtinArray_sort(call FunctionCall) Value {
}
return call.This
}
func builtinArray_isArray(call FunctionCall) Value {
object := call.Argument(0)._object()
return toValue(object != nil && object.class == "Array")
}

View File

@ -219,6 +219,11 @@ func newContext() *_runtime {
"sort", 0, builtinArray_sort,
)
self.Global.Array.write(
_propertyMode(0),
"isArray", builtinArray_isArray,
)
self.Global.String = self.newGlobalFunction(
1,
"String", builtinString,