weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) |
keith_miller@apple.com | 8dc2c35 | 2016-01-06 18:25:01 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003, 2008, 2016 Apple Inc. All rights reserved. |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 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 "BooleanConstructor.h" |
| 23 | |
| 24 | #include "BooleanPrototype.h" |
| 25 | #include "JSGlobalObject.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 26 | #include "JSCInlines.h" |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 27 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 28 | namespace JSC { |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 29 | |
andersca@apple.com | 7de5aae | 2013-09-05 20:12:23 +0000 | [diff] [blame] | 30 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanConstructor); |
ggaren@apple.com | fea4353 | 2008-08-17 20:23:49 +0000 | [diff] [blame] | 31 | |
utatane.tea@gmail.com | a5544f1 | 2017-05-19 09:23:20 +0000 | [diff] [blame] | 32 | const ClassInfo BooleanConstructor::s_info = { "Function", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(BooleanConstructor) }; |
mhahnenberg@apple.com | 77d198e | 2011-10-05 02:47:42 +0000 | [diff] [blame] | 33 | |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 34 | // ECMA 15.6.1 |
| 35 | static EncodedJSValue JSC_HOST_CALL callBooleanConstructor(ExecState* exec) |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 36 | { |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 37 | return JSValue::encode(jsBoolean(exec->argument(0).toBoolean(exec))); |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // ECMA 15.6.2 |
barraclough@apple.com | 11d351a | 2010-06-04 21:38:38 +0000 | [diff] [blame] | 41 | static EncodedJSValue JSC_HOST_CALL constructWithBooleanConstructor(ExecState* exec) |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 42 | { |
mark.lam@apple.com | 451de99 | 2016-09-07 22:10:50 +0000 | [diff] [blame] | 43 | VM& vm = exec->vm(); |
| 44 | auto scope = DECLARE_THROW_SCOPE(vm); |
keith_miller@apple.com | 8dc2c35 | 2016-01-06 18:25:01 +0000 | [diff] [blame] | 45 | JSValue boolean = jsBoolean(exec->argument(0).toBoolean(exec)); |
utatane.tea@gmail.com | b860d69 | 2018-05-31 06:19:33 +0000 | [diff] [blame] | 46 | Structure* booleanStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), jsCast<InternalFunction*>(exec->jsCallee())->globalObject(vm)->booleanObjectStructure()); |
mark.lam@apple.com | e1ab17c | 2016-09-26 19:11:17 +0000 | [diff] [blame] | 47 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
mark.lam@apple.com | 451de99 | 2016-09-07 22:10:50 +0000 | [diff] [blame] | 48 | BooleanObject* obj = BooleanObject::create(vm, booleanStructure); |
| 49 | obj->setInternalValue(vm, boolean); |
keith_miller@apple.com | 8dc2c35 | 2016-01-06 18:25:01 +0000 | [diff] [blame] | 50 | return JSValue::encode(obj); |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 51 | } |
| 52 | |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 53 | BooleanConstructor::BooleanConstructor(VM& vm, Structure* structure) |
| 54 | : InternalFunction(vm, structure, callBooleanConstructor, constructWithBooleanConstructor) |
mhahnenberg@apple.com | 79c8e6e | 2011-10-08 23:26:41 +0000 | [diff] [blame] | 55 | { |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 56 | } |
| 57 | |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 58 | void BooleanConstructor::finishCreation(VM& vm, BooleanPrototype* booleanPrototype) |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 59 | { |
ysuzuki@apple.com | 5f05b1e | 2019-03-08 19:33:51 +0000 | [diff] [blame] | 60 | Base::finishCreation(vm, vm.propertyNames->Boolean.string(), NameVisibility::Visible, NameAdditionMode::WithoutStructureTransition); |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 61 | putDirectWithoutTransition(vm, vm.propertyNames->prototype, booleanPrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); |
| 62 | putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum); |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 63 | } |
| 64 | |
oliver@apple.com | 3b6dc57 | 2011-03-28 23:39:16 +0000 | [diff] [blame] | 65 | JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSGlobalObject* globalObject, JSValue immediateBooleanValue) |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 66 | { |
mark.lam@apple.com | 23e9624 | 2017-09-09 16:21:45 +0000 | [diff] [blame] | 67 | VM& vm = exec->vm(); |
| 68 | BooleanObject* obj = BooleanObject::create(vm, globalObject->booleanObjectStructure()); |
| 69 | obj->setInternalValue(vm, immediateBooleanValue); |
weinig@apple.com | 282b0a4 | 2008-06-28 04:29:48 +0000 | [diff] [blame] | 70 | return obj; |
| 71 | } |
| 72 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 73 | } // namespace JSC |