BooleanPrototype.cpp 3.37 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
#include "Operations.h"
30

31
namespace JSC {
32

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

36 37 38 39 40 41
}

#include "BooleanPrototype.lut.h"

namespace JSC {

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

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

51
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanPrototype);
52

53 54
BooleanPrototype::BooleanPrototype(VM& vm, Structure* structure)
    : BooleanObject(vm, structure)
55
{
56 57
}

58
void BooleanPrototype::finishCreation(VM& vm, JSGlobalObject*)
59
{
60 61
    Base::finishCreation(vm);
    setInternalValue(vm, jsBoolean(false));
62

63
    ASSERT(inherits(info()));
64 65
}

66
bool BooleanPrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot &slot)
67
{
68
    return getStaticFunctionSlot<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec), jsCast<BooleanPrototype*>(object), propertyName, slot);
69
}
70

71
// ------------------------------ Functions ---------------------------
72

73
EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState* exec)
74
{
75
    VM* vm = &exec->vm();
76
    JSValue thisValue = exec->hostThisValue();
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

darin@apple.com's avatar
darin@apple.com committed
86
    if (asBooleanObject(thisValue)->internalValue() == jsBoolean(false))
87
        return JSValue::encode(vm->smallStrings.falseString());
88

darin@apple.com's avatar
darin@apple.com committed
89
    ASSERT(asBooleanObject(thisValue)->internalValue() == jsBoolean(true));
90
    return JSValue::encode(vm->smallStrings.trueString());
91 92
}

93
EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec)
94
{
95
    JSValue thisValue = exec->hostThisValue();
weinig@apple.com's avatar
weinig@apple.com committed
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