]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) | |
14957cd0 | 3 | * Copyright (C) 2003, 2007, 2008, 2011 Apple Inc. All rights reserved. |
9dae56ea A |
4 | * Copyright (C) 2003 Peter Kelly (pmk@post.com) |
5 | * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) | |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this library; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
20 | * USA | |
21 | * | |
22 | */ | |
23 | ||
24 | #include "config.h" | |
25 | #include "ArrayConstructor.h" | |
26 | ||
27 | #include "ArrayPrototype.h" | |
f9bf01c6 | 28 | #include "Error.h" |
14957cd0 | 29 | #include "ExceptionHelpers.h" |
9dae56ea | 30 | #include "JSArray.h" |
ba379fdc | 31 | #include "JSFunction.h" |
9dae56ea A |
32 | #include "Lookup.h" |
33 | ||
34 | namespace JSC { | |
35 | ||
14957cd0 A |
36 | static EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState*); |
37 | ||
38 | } | |
39 | ||
40 | #include "ArrayConstructor.lut.h" | |
41 | ||
42 | namespace JSC { | |
43 | ||
6fe7ccc8 A |
44 | ASSERT_HAS_TRIVIAL_DESTRUCTOR(ArrayConstructor); |
45 | ||
46 | const ClassInfo ArrayConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::arrayConstructorTable, CREATE_METHOD_TABLE(ArrayConstructor) }; | |
14957cd0 A |
47 | |
48 | /* Source for ArrayConstructor.lut.h | |
49 | @begin arrayConstructorTable | |
50 | isArray arrayConstructorIsArray DontEnum|Function 1 | |
51 | @end | |
52 | */ | |
53 | ||
9dae56ea A |
54 | ASSERT_CLASS_FITS_IN_CELL(ArrayConstructor); |
55 | ||
6fe7ccc8 A |
56 | ArrayConstructor::ArrayConstructor(JSGlobalObject* globalObject, Structure* structure) |
57 | : InternalFunction(globalObject, structure) | |
58 | { | |
59 | } | |
60 | ||
61 | void ArrayConstructor::finishCreation(ExecState* exec, ArrayPrototype* arrayPrototype) | |
9dae56ea | 62 | { |
6fe7ccc8 | 63 | Base::finishCreation(exec->globalData(), Identifier(exec, arrayPrototype->classInfo()->className)); |
14957cd0 A |
64 | putDirectWithoutTransition(exec->globalData(), exec->propertyNames().prototype, arrayPrototype, DontEnum | DontDelete | ReadOnly); |
65 | putDirectWithoutTransition(exec->globalData(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontEnum | DontDelete); | |
66 | } | |
9dae56ea | 67 | |
6fe7ccc8 | 68 | bool ArrayConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot &slot) |
14957cd0 | 69 | { |
6fe7ccc8 | 70 | return getStaticFunctionSlot<InternalFunction>(exec, ExecState::arrayConstructorTable(exec), jsCast<ArrayConstructor*>(cell), propertyName, slot); |
14957cd0 | 71 | } |
f9bf01c6 | 72 | |
6fe7ccc8 | 73 | bool ArrayConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) |
14957cd0 | 74 | { |
6fe7ccc8 | 75 | return getStaticFunctionDescriptor<InternalFunction>(exec, ExecState::arrayConstructorTable(exec), jsCast<ArrayConstructor*>(object), propertyName, descriptor); |
9dae56ea A |
76 | } |
77 | ||
14957cd0 A |
78 | // ------------------------------ Functions --------------------------- |
79 | ||
f9bf01c6 | 80 | static inline JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgList& args) |
9dae56ea | 81 | { |
14957cd0 A |
82 | JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject(); |
83 | ||
9dae56ea | 84 | // a single numeric argument denotes the array size (!) |
ba379fdc A |
85 | if (args.size() == 1 && args.at(0).isNumber()) { |
86 | uint32_t n = args.at(0).toUInt32(exec); | |
87 | if (n != args.at(0).toNumber(exec)) | |
14957cd0 | 88 | return throwError(exec, createRangeError(exec, "Array size is not a small enough positive integer.")); |
6fe7ccc8 | 89 | return constructEmptyArray(exec, globalObject, n); |
9dae56ea A |
90 | } |
91 | ||
92 | // otherwise the array is constructed with the arguments in it | |
6fe7ccc8 | 93 | return constructArray(exec, globalObject, args); |
9dae56ea A |
94 | } |
95 | ||
14957cd0 | 96 | static EncodedJSValue JSC_HOST_CALL constructWithArrayConstructor(ExecState* exec) |
9dae56ea | 97 | { |
14957cd0 A |
98 | ArgList args(exec); |
99 | return JSValue::encode(constructArrayWithSizeQuirk(exec, args)); | |
9dae56ea A |
100 | } |
101 | ||
6fe7ccc8 | 102 | ConstructType ArrayConstructor::getConstructData(JSCell*, ConstructData& constructData) |
9dae56ea A |
103 | { |
104 | constructData.native.function = constructWithArrayConstructor; | |
105 | return ConstructTypeHost; | |
106 | } | |
107 | ||
14957cd0 | 108 | static EncodedJSValue JSC_HOST_CALL callArrayConstructor(ExecState* exec) |
9dae56ea | 109 | { |
14957cd0 A |
110 | ArgList args(exec); |
111 | return JSValue::encode(constructArrayWithSizeQuirk(exec, args)); | |
9dae56ea A |
112 | } |
113 | ||
6fe7ccc8 | 114 | CallType ArrayConstructor::getCallData(JSCell*, CallData& callData) |
9dae56ea A |
115 | { |
116 | // equivalent to 'new Array(....)' | |
117 | callData.native.function = callArrayConstructor; | |
118 | return CallTypeHost; | |
119 | } | |
120 | ||
14957cd0 | 121 | EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState* exec) |
f9bf01c6 | 122 | { |
14957cd0 | 123 | return JSValue::encode(jsBoolean(exec->argument(0).inherits(&JSArray::s_info))); |
f9bf01c6 A |
124 | } |
125 | ||
9dae56ea | 126 | } // namespace JSC |