1 /* 2 * Copyright (C) 1999-2000 Harri Porten (porten (at) kde.org) 3 * Copyright (C) 2003, 2008 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 "JSFunction.h" 26 #include "JSString.h" 27 #include "ObjectPrototype.h" 28 #include "PrototypeFunction.h" 29 30 namespace JSC { 31 32 ASSERT_CLASS_FITS_IN_CELL(BooleanPrototype); 33 34 // Functions 35 static JSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState*, JSObject*, JSValue, const ArgList&); 36 static JSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState*, JSObject*, JSValue, const ArgList&); 37 38 // ECMA 15.6.4 39 40 BooleanPrototype::BooleanPrototype(ExecState* exec, NonNullPassRefPtr<Structure> structure, Structure* prototypeFunctionStructure) 41 : BooleanObject(structure) 42 { 43 setInternalValue(jsBoolean(false)); 44 45 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 0, exec->propertyNames().toString, booleanProtoFuncToString), DontEnum); 46 putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 0, exec->propertyNames().valueOf, booleanProtoFuncValueOf), DontEnum); 47 } 48 49 50 // ------------------------------ Functions -------------------------- 51 52 // ECMA 15.6.4.2 + 15.6.4.3 53 54 JSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) 55 { 56 if (thisValue == jsBoolean(false)) 57 return jsNontrivialString(exec, "false"); 58 59 if (thisValue == jsBoolean(true)) 60 return jsNontrivialString(exec, "true"); 61 62 if (!thisValue.inherits(&BooleanObject::info)) 63 return throwError(exec, TypeError); 64 65 if (asBooleanObject(thisValue)->internalValue() == jsBoolean(false)) 66 return jsNontrivialString(exec, "false"); 67 68 ASSERT(asBooleanObject(thisValue)->internalValue() == jsBoolean(true)); 69 return jsNontrivialString(exec, "true"); 70 } 71 72 JSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) 73 { 74 if (thisValue.isBoolean()) 75 return thisValue; 76 77 if (!thisValue.inherits(&BooleanObject::info)) 78 return throwError(exec, TypeError); 79 80 return asBooleanObject(thisValue)->internalValue(); 81 } 82 83 } // namespace JSC 84