Commit 86a4bc73 authored by oliver@apple.com's avatar oliver@apple.com

[ES5] Implement Array.isArray

https://bugs.webkit.org/show_bug.cgi?id=28296

Reviewed by Maciej Stachowiak

Add support for Array.isArray to the Array constructor


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@47271 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 99168e75
......@@ -7,6 +7,25 @@
* runtime/JSArray.h:
(JSC::MarkStack::drain):
2009-08-13 Oliver Hunt <oliver@apple.com>
Reviewed by Maciej Stachowiak.
[ES5] Implement Array.isArray
https://bugs.webkit.org/show_bug.cgi?id=28296
Add support for Array.isArray to the Array constructor
* runtime/ArrayConstructor.cpp:
(JSC::ArrayConstructor::ArrayConstructor):
(JSC::arrayConstructorIsArray):
* runtime/ArrayConstructor.h:
* runtime/CommonIdentifiers.h:
* runtime/JSArray.h:
(JSC::MarkStack::drain):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::reset):
2009-08-13 Oliver Hunt <oliver@apple.com>
Reviewed by NOBODY (Buildfix).
......
......@@ -33,8 +33,10 @@
namespace JSC {
ASSERT_CLASS_FITS_IN_CELL(ArrayConstructor);
static JSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState*, JSObject*, JSValue, const ArgList&);
ArrayConstructor::ArrayConstructor(ExecState* exec, PassRefPtr<Structure> structure, ArrayPrototype* arrayPrototype)
ArrayConstructor::ArrayConstructor(ExecState* exec, PassRefPtr<Structure> structure, ArrayPrototype* arrayPrototype, Structure* prototypeFunctionStructure)
: InternalFunction(&exec->globalData(), structure, Identifier(exec, arrayPrototype->classInfo()->className))
{
// ECMA 15.4.3.1 Array.prototype
......@@ -42,6 +44,9 @@ ArrayConstructor::ArrayConstructor(ExecState* exec, PassRefPtr<Structure> struct
// no. of arguments for constructor
putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
// ES5
putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 1, exec->propertyNames().isArray, arrayConstructorIsArray), DontEnum);
}
static JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgList& args)
......@@ -83,4 +88,11 @@ CallType ArrayConstructor::getCallData(CallData& callData)
return CallTypeHost;
}
JSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState*, JSObject*, JSValue, const ArgList& args)
{
if (!args.at(0).isObject())
return jsBoolean(false);
return jsBoolean(asObject(args.at(0))->isObject(&JSArray::info));
}
} // namespace JSC
......@@ -29,7 +29,7 @@ namespace JSC {
class ArrayConstructor : public InternalFunction {
public:
ArrayConstructor(ExecState*, PassRefPtr<Structure>, ArrayPrototype*);
ArrayConstructor(ExecState*, PassRefPtr<Structure>, ArrayPrototype*, Structure*);
virtual ConstructType getConstructData(ConstructData&);
virtual CallType getCallData(CallData&);
......
......@@ -47,6 +47,7 @@
macro(ignoreCase) \
macro(index) \
macro(input) \
macro(isArray) \
macro(isPrototypeOf) \
macro(length) \
macro(message) \
......
......@@ -258,7 +258,7 @@ void JSGlobalObject::reset(JSValue prototype)
JSCell* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype, d()->prototypeFunctionStructure.get());
JSCell* functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructure(d()->functionPrototype), d()->functionPrototype);
JSCell* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype);
JSCell* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype, d()->prototypeFunctionStructure.get());
JSCell* stringConstructor = new (exec) StringConstructor(exec, StringConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype);
JSCell* booleanConstructor = new (exec) BooleanConstructor(exec, BooleanConstructor::createStructure(d()->functionPrototype), d()->booleanPrototype);
JSCell* numberConstructor = new (exec) NumberConstructor(exec, NumberConstructor::createStructure(d()->functionPrototype), d()->numberPrototype);
......
2009-08-13 Oliver Hunt <oliver@apple.com>
Reviewed by Maciej Stachowiak.
[ES5] Implement Array.isArray
https://bugs.webkit.org/show_bug.cgi?id=28296
Add tests for Array.isArray
* fast/js/Array-isArray-expected.txt: Added.
* fast/js/Array-isArray.html: Added.
* fast/js/resources/Array-isArray.js: Added.
2009-08-13 Simon Fraser <simon.fraser@apple.com>
Reviewed by Dan Bernstein.
......
Test to ensure correct behaviour of Array.array
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS Array.isArray([]) is true
PASS Array.isArray(new Array) is true
PASS Array.isArray(Array()) is true
PASS Array.isArray('abc'.match(/(a)*/g)) is true
PASS (function(){ return Array.isArray(arguments); })() is false
PASS Array.isArray() is false
PASS Array.isArray(null) is false
PASS Array.isArray(undefined) is false
PASS Array.isArray(true) is false
PASS Array.isArray(false) is false
PASS Array.isArray('a string') is false
PASS Array.isArray({}) is false
PASS Array.isArray({length: 5}) is false
PASS Array.isArray({__proto__: Array.prototype, length:1, 0:1, 1:2}) is false
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="resources/js-test-style.css">
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="resources/Array-isArray.js"></script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
description("Test to ensure correct behaviour of Array.array");
shouldBeTrue("Array.isArray([])");
shouldBeTrue("Array.isArray(new Array)");
shouldBeTrue("Array.isArray(Array())");
shouldBeTrue("Array.isArray('abc'.match(/(a)*/g))");
shouldBeFalse("(function(){ return Array.isArray(arguments); })()");
shouldBeFalse("Array.isArray()");
shouldBeFalse("Array.isArray(null)");
shouldBeFalse("Array.isArray(undefined)");
shouldBeFalse("Array.isArray(true)");
shouldBeFalse("Array.isArray(false)");
shouldBeFalse("Array.isArray('a string')");
shouldBeFalse("Array.isArray({})");
shouldBeFalse("Array.isArray({length: 5})");
shouldBeFalse("Array.isArray({__proto__: Array.prototype, length:1, 0:1, 1:2})");
successfullyParsed = true;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment