| 1 | /* |
| 2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) |
| 3 | * Copyright (C) 2003, 2008, 2011, 2016 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 "ExceptionHelpers.h" |
| 26 | #include "JSFunction.h" |
| 27 | #include "JSString.h" |
| 28 | #include "ObjectPrototype.h" |
| 29 | #include "JSCInlines.h" |
| 30 | |
| 31 | namespace JSC { |
| 32 | |
| 33 | static EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState*); |
| 34 | static EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState*); |
| 35 | |
| 36 | } |
| 37 | |
| 38 | #include "BooleanPrototype.lut.h" |
| 39 | |
| 40 | namespace JSC { |
| 41 | |
| 42 | const ClassInfo BooleanPrototype::s_info = { "Boolean" , &BooleanObject::s_info, &booleanPrototypeTable, nullptr, CREATE_METHOD_TABLE(BooleanPrototype) }; |
| 43 | |
| 44 | /* Source for BooleanPrototype.lut.h |
| 45 | @begin booleanPrototypeTable |
| 46 | toString booleanProtoFuncToString DontEnum|Function 0 |
| 47 | valueOf booleanProtoFuncValueOf DontEnum|Function 0 |
| 48 | @end |
| 49 | */ |
| 50 | |
| 51 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanPrototype); |
| 52 | |
| 53 | BooleanPrototype::BooleanPrototype(VM& vm, Structure* structure) |
| 54 | : BooleanObject(vm, structure) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | void BooleanPrototype::finishCreation(VM& vm, JSGlobalObject*) |
| 59 | { |
| 60 | Base::finishCreation(vm); |
| 61 | setInternalValue(vm, jsBoolean(false)); |
| 62 | |
| 63 | ASSERT(inherits(vm, info())); |
| 64 | } |
| 65 | |
| 66 | // ------------------------------ Functions --------------------------- |
| 67 | |
| 68 | EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState* exec) |
| 69 | { |
| 70 | VM& vm = exec->vm(); |
| 71 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 72 | JSValue thisValue = exec->thisValue(); |
| 73 | if (thisValue == jsBoolean(false)) |
| 74 | return JSValue::encode(vm.smallStrings.falseString()); |
| 75 | |
| 76 | if (thisValue == jsBoolean(true)) |
| 77 | return JSValue::encode(vm.smallStrings.trueString()); |
| 78 | |
| 79 | auto* thisObject = jsDynamicCast<BooleanObject*>(vm, thisValue); |
| 80 | if (UNLIKELY(!thisObject)) |
| 81 | return throwVMTypeError(exec, scope); |
| 82 | |
| 83 | if (thisObject->internalValue() == jsBoolean(false)) |
| 84 | return JSValue::encode(vm.smallStrings.falseString()); |
| 85 | |
| 86 | ASSERT(thisObject->internalValue() == jsBoolean(true)); |
| 87 | return JSValue::encode(vm.smallStrings.trueString()); |
| 88 | } |
| 89 | |
| 90 | EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec) |
| 91 | { |
| 92 | VM& vm = exec->vm(); |
| 93 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 94 | JSValue thisValue = exec->thisValue(); |
| 95 | if (thisValue.isBoolean()) |
| 96 | return JSValue::encode(thisValue); |
| 97 | |
| 98 | auto* thisObject = jsDynamicCast<BooleanObject*>(vm, thisValue); |
| 99 | if (UNLIKELY(!thisObject)) |
| 100 | return throwVMTypeError(exec, scope); |
| 101 | |
| 102 | return JSValue::encode(thisObject->internalValue()); |
| 103 | } |
| 104 | |
| 105 | } // namespace JSC |
| 106 | |