tizen beta release
[framework/web/webkit-efl.git] / Source / JavaScriptCore / runtime / BooleanPrototype.cpp
1 /*
2  *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3  *  Copyright (C) 2003, 2008, 2011 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 "BooleanPrototype.h"
23
24 #include "Error.h"
25 #include "ExceptionHelpers.h"
26 #include "JSFunction.h"
27 #include "JSString.h"
28 #include "ObjectPrototype.h"
29
30 namespace JSC {
31
32 static EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState*);
33 static EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState*);
34
35 }
36
37 #include "BooleanPrototype.lut.h"
38
39 namespace JSC {
40
41 const ClassInfo BooleanPrototype::s_info = { "Boolean", &BooleanObject::s_info, 0, ExecState::booleanPrototypeTable, CREATE_METHOD_TABLE(BooleanPrototype) };
42
43 /* Source for BooleanPrototype.lut.h
44 @begin booleanPrototypeTable
45   toString  booleanProtoFuncToString    DontEnum|Function 0
46   valueOf   booleanProtoFuncValueOf     DontEnum|Function 0
47 @end
48 */
49
50 ASSERT_CLASS_FITS_IN_CELL(BooleanPrototype);
51
52 BooleanPrototype::BooleanPrototype(ExecState* exec, Structure* structure)
53     : BooleanObject(exec->globalData(), structure)
54 {
55 }
56
57 void BooleanPrototype::finishCreation(ExecState* exec, JSGlobalObject*)
58 {
59     Base::finishCreation(exec->globalData());
60     setInternalValue(exec->globalData(), jsBoolean(false));
61
62     ASSERT(inherits(&s_info));
63 }
64
65 bool BooleanPrototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
66 {
67     return getStaticFunctionSlot<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec), jsCast<BooleanPrototype*>(cell), propertyName, slot);
68 }
69
70 bool BooleanPrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
71 {
72     return getStaticFunctionDescriptor<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec), jsCast<BooleanPrototype*>(object), propertyName, descriptor);
73 }
74
75 // ------------------------------ Functions ---------------------------
76
77 EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState* exec)
78 {
79     JSValue thisValue = exec->hostThisValue();
80     if (thisValue == jsBoolean(false))
81         return JSValue::encode(jsNontrivialString(exec, "false"));
82
83     if (thisValue == jsBoolean(true))
84         return JSValue::encode(jsNontrivialString(exec, "true"));
85
86     if (!thisValue.inherits(&BooleanObject::s_info))
87         return throwVMTypeError(exec);
88
89     if (asBooleanObject(thisValue)->internalValue() == jsBoolean(false))
90         return JSValue::encode(jsNontrivialString(exec, "false"));
91
92     ASSERT(asBooleanObject(thisValue)->internalValue() == jsBoolean(true));
93     return JSValue::encode(jsNontrivialString(exec, "true"));
94 }
95
96 EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec)
97 {
98     JSValue thisValue = exec->hostThisValue();
99     if (thisValue.isBoolean())
100         return JSValue::encode(thisValue);
101
102     if (!thisValue.inherits(&BooleanObject::s_info))
103         return throwVMTypeError(exec);
104
105     return JSValue::encode(asBooleanObject(thisValue)->internalValue());
106 }
107
108 } // namespace JSC