2
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3
* Copyright (C) 2003, 2008, 2011 Apple Inc. All rights reserved.
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.
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.
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
22
#include "BooleanPrototype.h"
25
#include "ExceptionHelpers.h"
26
#include "JSFunction.h"
28
#include "ObjectPrototype.h"
32
static EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState*);
33
static EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState*);
37
#include "BooleanPrototype.lut.h"
41
const ClassInfo BooleanPrototype::s_info = { "Boolean", &BooleanObject::s_info, 0, ExecState::booleanPrototypeTable, CREATE_METHOD_TABLE(BooleanPrototype) };
43
/* Source for BooleanPrototype.lut.h
44
@begin booleanPrototypeTable
45
toString booleanProtoFuncToString DontEnum|Function 0
46
valueOf booleanProtoFuncValueOf DontEnum|Function 0
50
ASSERT_HAS_TRIVIAL_DESTRUCTOR(BooleanPrototype);
52
BooleanPrototype::BooleanPrototype(ExecState* exec, Structure* structure)
53
: BooleanObject(exec->globalData(), structure)
57
void BooleanPrototype::finishCreation(ExecState* exec, JSGlobalObject*)
59
Base::finishCreation(exec->globalData());
60
setInternalValue(exec->globalData(), jsBoolean(false));
62
ASSERT(inherits(&s_info));
65
bool BooleanPrototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot &slot)
67
return getStaticFunctionSlot<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec), jsCast<BooleanPrototype*>(cell), propertyName, slot);
70
bool BooleanPrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
72
return getStaticFunctionDescriptor<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec), jsCast<BooleanPrototype*>(object), propertyName, descriptor);
75
// ------------------------------ Functions ---------------------------
77
EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState* exec)
79
JSGlobalData* globalData = &exec->globalData();
80
JSValue thisValue = exec->hostThisValue();
81
if (thisValue == jsBoolean(false))
82
return JSValue::encode(globalData->smallStrings.falseString(globalData));
84
if (thisValue == jsBoolean(true))
85
return JSValue::encode(globalData->smallStrings.trueString(globalData));
87
if (!thisValue.inherits(&BooleanObject::s_info))
88
return throwVMTypeError(exec);
90
if (asBooleanObject(thisValue)->internalValue() == jsBoolean(false))
91
return JSValue::encode(globalData->smallStrings.falseString(globalData));
93
ASSERT(asBooleanObject(thisValue)->internalValue() == jsBoolean(true));
94
return JSValue::encode(globalData->smallStrings.trueString(globalData));
97
EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec)
99
JSValue thisValue = exec->hostThisValue();
100
if (thisValue.isBoolean())
101
return JSValue::encode(thisValue);
103
if (!thisValue.inherits(&BooleanObject::s_info))
104
return throwVMTypeError(exec);
106
return JSValue::encode(asBooleanObject(thisValue)->internalValue());