tizen beta release
[framework/web/webkit-efl.git] / Source / JavaScriptCore / runtime / BooleanConstructor.cpp
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
27 namespace JSC {
28
29 ASSERT_CLASS_FITS_IN_CELL(BooleanConstructor);
30
31 const ClassInfo BooleanConstructor::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(BooleanConstructor) };
32
33 BooleanConstructor::BooleanConstructor(JSGlobalObject* globalObject, Structure* structure)
34     : InternalFunction(globalObject, structure)
35 {
36 }
37
38 void BooleanConstructor::finishCreation(ExecState* exec, BooleanPrototype* booleanPrototype)
39 {
40     Base::finishCreation(exec->globalData(), Identifier(exec, booleanPrototype->classInfo()->className));
41     putDirectWithoutTransition(exec->globalData(), exec->propertyNames().prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly);
42
43     // no. of arguments for constructor
44     putDirectWithoutTransition(exec->globalData(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontDelete | DontEnum);
45 }
46
47 // ECMA 15.6.2
48 JSObject* constructBoolean(ExecState* exec, const ArgList& args)
49 {
50     BooleanObject* obj = BooleanObject::create(exec->globalData(), asInternalFunction(exec->callee())->globalObject()->booleanObjectStructure());
51     obj->setInternalValue(exec->globalData(), jsBoolean(args.at(0).toBoolean(exec)));
52     return obj;
53 }
54
55 static EncodedJSValue JSC_HOST_CALL constructWithBooleanConstructor(ExecState* exec)
56 {
57     ArgList args(exec);
58     return JSValue::encode(constructBoolean(exec, args));
59 }
60
61 ConstructType BooleanConstructor::getConstructData(JSCell*, ConstructData& constructData)
62 {
63     constructData.native.function = constructWithBooleanConstructor;
64     return ConstructTypeHost;
65 }
66
67 // ECMA 15.6.1
68 static EncodedJSValue JSC_HOST_CALL callBooleanConstructor(ExecState* exec)
69 {
70     return JSValue::encode(jsBoolean(exec->argument(0).toBoolean(exec)));
71 }
72
73 CallType BooleanConstructor::getCallData(JSCell*, CallData& callData)
74 {
75     callData.native.function = callBooleanConstructor;
76     return CallTypeHost;
77 }
78
79 JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSGlobalObject* globalObject, JSValue immediateBooleanValue)
80 {
81     BooleanObject* obj = BooleanObject::create(exec->globalData(), globalObject->booleanObjectStructure());
82     obj->setInternalValue(exec->globalData(), immediateBooleanValue);
83     return obj;
84 }
85
86 } // namespace JSC