blob: 4eb9600770c64c422f11e415bed8d88f9885f982 [file] [log] [blame]
weinig@apple.com282b0a42008-06-28 04:29:48 +00001/*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
keith_miller@apple.com8dc2c352016-01-06 18:25:01 +00003 * Copyright (C) 2003, 2008, 2016 Apple Inc. All rights reserved.
weinig@apple.com282b0a42008-06-28 04:29:48 +00004 *
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.comfb7eff22014-02-11 01:45:50 +000026#include "JSCInlines.h"
weinig@apple.com282b0a42008-06-28 04:29:48 +000027
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000028namespace JSC {
weinig@apple.com282b0a42008-06-28 04:29:48 +000029
andersca@apple.com7de5aae2013-09-05 20:12:23 +000030STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanConstructor);
ggaren@apple.comfea43532008-08-17 20:23:49 +000031
utatane.tea@gmail.coma5544f12017-05-19 09:23:20 +000032const ClassInfo BooleanConstructor::s_info = { "Function", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(BooleanConstructor) };
mhahnenberg@apple.com77d198e2011-10-05 02:47:42 +000033
utatane.tea@gmail.com7ab015d2017-11-06 14:40:08 +000034// ECMA 15.6.1
35static EncodedJSValue JSC_HOST_CALL callBooleanConstructor(ExecState* exec)
weinig@apple.com282b0a42008-06-28 04:29:48 +000036{
utatane.tea@gmail.com7ab015d2017-11-06 14:40:08 +000037 return JSValue::encode(jsBoolean(exec->argument(0).toBoolean(exec)));
weinig@apple.com282b0a42008-06-28 04:29:48 +000038}
39
40// ECMA 15.6.2
barraclough@apple.com11d351a2010-06-04 21:38:38 +000041static EncodedJSValue JSC_HOST_CALL constructWithBooleanConstructor(ExecState* exec)
weinig@apple.com282b0a42008-06-28 04:29:48 +000042{
mark.lam@apple.com451de992016-09-07 22:10:50 +000043 VM& vm = exec->vm();
44 auto scope = DECLARE_THROW_SCOPE(vm);
keith_miller@apple.com8dc2c352016-01-06 18:25:01 +000045 JSValue boolean = jsBoolean(exec->argument(0).toBoolean(exec));
utatane.tea@gmail.comb860d692018-05-31 06:19:33 +000046 Structure* booleanStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), jsCast<InternalFunction*>(exec->jsCallee())->globalObject(vm)->booleanObjectStructure());
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +000047 RETURN_IF_EXCEPTION(scope, encodedJSValue());
mark.lam@apple.com451de992016-09-07 22:10:50 +000048 BooleanObject* obj = BooleanObject::create(vm, booleanStructure);
49 obj->setInternalValue(vm, boolean);
keith_miller@apple.com8dc2c352016-01-06 18:25:01 +000050 return JSValue::encode(obj);
weinig@apple.com282b0a42008-06-28 04:29:48 +000051}
52
utatane.tea@gmail.com7ab015d2017-11-06 14:40:08 +000053BooleanConstructor::BooleanConstructor(VM& vm, Structure* structure)
54 : InternalFunction(vm, structure, callBooleanConstructor, constructWithBooleanConstructor)
mhahnenberg@apple.com79c8e6e2011-10-08 23:26:41 +000055{
weinig@apple.com282b0a42008-06-28 04:29:48 +000056}
57
utatane.tea@gmail.com7ab015d2017-11-06 14:40:08 +000058void BooleanConstructor::finishCreation(VM& vm, BooleanPrototype* booleanPrototype)
weinig@apple.com282b0a42008-06-28 04:29:48 +000059{
ysuzuki@apple.com5f05b1e2019-03-08 19:33:51 +000060 Base::finishCreation(vm, vm.propertyNames->Boolean.string(), NameVisibility::Visible, NameAdditionMode::WithoutStructureTransition);
utatane.tea@gmail.com7ab015d2017-11-06 14:40:08 +000061 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.com282b0a42008-06-28 04:29:48 +000063}
64
oliver@apple.com3b6dc572011-03-28 23:39:16 +000065JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSGlobalObject* globalObject, JSValue immediateBooleanValue)
weinig@apple.com282b0a42008-06-28 04:29:48 +000066{
mark.lam@apple.com23e96242017-09-09 16:21:45 +000067 VM& vm = exec->vm();
68 BooleanObject* obj = BooleanObject::create(vm, globalObject->booleanObjectStructure());
69 obj->setInternalValue(vm, immediateBooleanValue);
weinig@apple.com282b0a42008-06-28 04:29:48 +000070 return obj;
71}
72
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000073} // namespace JSC