BooleanPrototype.cpp 3.61 KB
Newer Older
1 2
/*
 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3
 *  Copyright (C) 2003, 2008, 2011 Apple Inc. All rights reserved.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include "config.h"
#include "BooleanPrototype.h"

24
#include "Error.h"
25
#include "ExceptionHelpers.h"
oliver@apple.com's avatar
oliver@apple.com committed
26
#include "JSFunction.h"
27
#include "JSString.h"
28
#include "ObjectPrototype.h"
29

30
namespace JSC {
31

32 33
static EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState*);
static EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState*);
34

35 36 37 38 39 40
}

#include "BooleanPrototype.lut.h"

namespace JSC {

41
const ClassInfo BooleanPrototype::s_info = { "Boolean", &BooleanObject::s_info, 0, ExecState::booleanPrototypeTable, CREATE_METHOD_TABLE(BooleanPrototype) };
42

43 44 45 46 47 48 49 50 51
/* Source for BooleanPrototype.lut.h
@begin booleanPrototypeTable
  toString  booleanProtoFuncToString    DontEnum|Function 0
  valueOf   booleanProtoFuncValueOf     DontEnum|Function 0
@end
*/

ASSERT_CLASS_FITS_IN_CELL(BooleanPrototype);

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 66 67 68
bool BooleanPrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
{
    return getStaticFunctionSlot<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec), this, propertyName, slot);
}
69

70 71 72 73
bool BooleanPrototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
    return getStaticFunctionDescriptor<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec), this, propertyName, descriptor);
}
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

darin@apple.com's avatar
darin@apple.com committed
89
    if (asBooleanObject(thisValue)->internalValue() == jsBoolean(false))
90
        return JSValue::encode(jsNontrivialString(exec, "false"));
91

darin@apple.com's avatar
darin@apple.com committed
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();
weinig@apple.com's avatar
weinig@apple.com committed
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