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_CLASS_FITS_IN_CELL(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, const Identifier& propertyName, PropertySlot &slot)
67 return getStaticFunctionSlot<BooleanObject>(exec, ExecState::booleanPrototypeTable(exec), jsCast<BooleanPrototype*>(cell), propertyName, slot);
70 bool BooleanPrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& 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 JSValue thisValue = exec->hostThisValue();
80 if (thisValue == jsBoolean(false))
81 return JSValue::encode(jsNontrivialString(exec, "false"));
83 if (thisValue == jsBoolean(true))
84 return JSValue::encode(jsNontrivialString(exec, "true"));
86 if (!thisValue.inherits(&BooleanObject::s_info))
87 return throwVMTypeError(exec);
89 if (asBooleanObject(thisValue)->internalValue() == jsBoolean(false))
90 return JSValue::encode(jsNontrivialString(exec, "false"));
92 ASSERT(asBooleanObject(thisValue)->internalValue() == jsBoolean(true));
93 return JSValue::encode(jsNontrivialString(exec, "true"));
96 EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec)
98 JSValue thisValue = exec->hostThisValue();
99 if (thisValue.isBoolean())
100 return JSValue::encode(thisValue);
102 if (!thisValue.inherits(&BooleanObject::s_info))
103 return throwVMTypeError(exec);
105 return JSValue::encode(asBooleanObject(thisValue)->internalValue());