]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/ObjectConstructor.cpp
JavaScriptCore-525.tar.gz
[apple/javascriptcore.git] / runtime / ObjectConstructor.cpp
CommitLineData
9dae56ea
A
1/*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21#include "config.h"
22#include "ObjectConstructor.h"
23
24#include "JSGlobalObject.h"
25#include "ObjectPrototype.h"
26
27namespace JSC {
28
29ASSERT_CLASS_FITS_IN_CELL(ObjectConstructor);
30
31ObjectConstructor::ObjectConstructor(ExecState* exec, PassRefPtr<Structure> structure, ObjectPrototype* objectPrototype)
32 : InternalFunction(&exec->globalData(), structure, Identifier(exec, "Object"))
33{
34 // ECMA 15.2.3.1
35 putDirectWithoutTransition(exec->propertyNames().prototype, objectPrototype, DontEnum | DontDelete | ReadOnly);
36
37 // no. of arguments for constructor
38 putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
39}
40
41// ECMA 15.2.2
42static ALWAYS_INLINE JSObject* constructObject(ExecState* exec, const ArgList& args)
43{
44 JSValuePtr arg = args.at(exec, 0);
45 if (arg.isUndefinedOrNull())
46 return new (exec) JSObject(exec->lexicalGlobalObject()->emptyObjectStructure());
47 return arg.toObject(exec);
48}
49
50static JSObject* constructWithObjectConstructor(ExecState* exec, JSObject*, const ArgList& args)
51{
52 return constructObject(exec, args);
53}
54
55ConstructType ObjectConstructor::getConstructData(ConstructData& constructData)
56{
57 constructData.native.function = constructWithObjectConstructor;
58 return ConstructTypeHost;
59}
60
61static JSValuePtr callObjectConstructor(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
62{
63 return constructObject(exec, args);
64}
65
66CallType ObjectConstructor::getCallData(CallData& callData)
67{
68 callData.native.function = callObjectConstructor;
69 return CallTypeHost;
70}
71
72} // namespace JSC