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#include "JSCInlines.h"
30
31namespace JSC {
32
33static EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState*);
34static EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState*);
35
36}
37
38#include "BooleanPrototype.lut.h"
39
40namespace JSC {
41
42const ClassInfo BooleanPrototype::s_info = { "Boolean", &BooleanObject::s_info, 0, ExecState::booleanPrototypeTable, CREATE_METHOD_TABLE(BooleanPrototype) };
43
44/* Source for BooleanPrototype.lut.h
45@begin booleanPrototypeTable
46  toString  booleanProtoFuncToString    DontEnum|Function 0
47  valueOf   booleanProtoFuncValueOf     DontEnum|Function 0
48@end
49*/
50
51STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanPrototype);
52
53BooleanPrototype::BooleanPrototype(VM& vm, Structure* structure)
54    : BooleanObject(vm, structure)
55{
56}
57
58void BooleanPrototype::finishCreation(VM& vm, JSGlobalObject*)
59{
60    Base::finishCreation(vm);
61    setInternalValue(vm, jsBoolean(false));
62
63    ASSERT(inherits(info()));
64}
65
66bool BooleanPrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot &slot)
67{
68    return getStaticFunctionSlot<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec->vm()), jsCast<BooleanPrototype*>(object), propertyName, slot);
69}
70
71// ------------------------------ Functions ---------------------------
72
73EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState* exec)
74{
75    VM* vm = &exec->vm();
76    JSValue thisValue = exec->thisValue();
77    if (thisValue == jsBoolean(false))
78        return JSValue::encode(vm->smallStrings.falseString());
79
80    if (thisValue == jsBoolean(true))
81        return JSValue::encode(vm->smallStrings.trueString());
82
83    if (!thisValue.inherits(BooleanObject::info()))
84        return throwVMTypeError(exec);
85
86    if (asBooleanObject(thisValue)->internalValue() == jsBoolean(false))
87        return JSValue::encode(vm->smallStrings.falseString());
88
89    ASSERT(asBooleanObject(thisValue)->internalValue() == jsBoolean(true));
90    return JSValue::encode(vm->smallStrings.trueString());
91}
92
93EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec)
94{
95    JSValue thisValue = exec->thisValue();
96    if (thisValue.isBoolean())
97        return JSValue::encode(thisValue);
98
99    if (!thisValue.inherits(BooleanObject::info()))
100        return throwVMTypeError(exec);
101
102    return JSValue::encode(asBooleanObject(thisValue)->internalValue());
103}
104
105} // namespace JSC
106