1/*
2 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 *  Copyright (C) 2003, 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 "BooleanConstructor.h"
23
24#include "BooleanPrototype.h"
25#include "JSGlobalObject.h"
26#include "JSCInlines.h"
27
28namespace JSC {
29
30STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanConstructor);
31
32const ClassInfo BooleanConstructor::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(BooleanConstructor) };
33
34BooleanConstructor::BooleanConstructor(VM& vm, Structure* structure)
35    : InternalFunction(vm, structure)
36{
37}
38
39void BooleanConstructor::finishCreation(VM& vm, BooleanPrototype* booleanPrototype)
40{
41    Base::finishCreation(vm, booleanPrototype->classInfo()->className);
42    putDirectWithoutTransition(vm, vm.propertyNames->prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly);
43
44    // no. of arguments for constructor
45    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontDelete | DontEnum);
46}
47
48// ECMA 15.6.2
49JSObject* constructBoolean(ExecState* exec, const ArgList& args)
50{
51    BooleanObject* obj = BooleanObject::create(exec->vm(), asInternalFunction(exec->callee())->globalObject()->booleanObjectStructure());
52    obj->setInternalValue(exec->vm(), jsBoolean(args.at(0).toBoolean(exec)));
53    return obj;
54}
55
56static EncodedJSValue JSC_HOST_CALL constructWithBooleanConstructor(ExecState* exec)
57{
58    ArgList args(exec);
59    return JSValue::encode(constructBoolean(exec, args));
60}
61
62ConstructType BooleanConstructor::getConstructData(JSCell*, ConstructData& constructData)
63{
64    constructData.native.function = constructWithBooleanConstructor;
65    return ConstructTypeHost;
66}
67
68// ECMA 15.6.1
69static EncodedJSValue JSC_HOST_CALL callBooleanConstructor(ExecState* exec)
70{
71    return JSValue::encode(jsBoolean(exec->argument(0).toBoolean(exec)));
72}
73
74CallType BooleanConstructor::getCallData(JSCell*, CallData& callData)
75{
76    callData.native.function = callBooleanConstructor;
77    return CallTypeHost;
78}
79
80JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSGlobalObject* globalObject, JSValue immediateBooleanValue)
81{
82    BooleanObject* obj = BooleanObject::create(exec->vm(), globalObject->booleanObjectStructure());
83    obj->setInternalValue(exec->vm(), immediateBooleanValue);
84    return obj;
85}
86
87} // namespace JSC
88