1 | /* |
2 | * Copyright (C) 1999-2000 Harri Porten ([email protected]) |
3 | * Copyright (C) 2003, 2008, 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 "BooleanConstructor.h" |
23 | |
24 | #include "BooleanPrototype.h" |
25 | #include "JSGlobalObject.h" |
26 | #include "JSCInlines.h" |
27 | |
28 | namespace JSC { |
29 | |
30 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanConstructor); |
31 | |
32 | const ClassInfo BooleanConstructor::s_info = { "Function" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(BooleanConstructor) }; |
33 | |
34 | // ECMA 15.6.1 |
35 | static EncodedJSValue JSC_HOST_CALL callBooleanConstructor(ExecState* exec) |
36 | { |
37 | return JSValue::encode(jsBoolean(exec->argument(0).toBoolean(exec))); |
38 | } |
39 | |
40 | // ECMA 15.6.2 |
41 | static EncodedJSValue JSC_HOST_CALL constructWithBooleanConstructor(ExecState* exec) |
42 | { |
43 | VM& vm = exec->vm(); |
44 | auto scope = DECLARE_THROW_SCOPE(vm); |
45 | JSValue boolean = jsBoolean(exec->argument(0).toBoolean(exec)); |
46 | Structure* booleanStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), jsCast<InternalFunction*>(exec->jsCallee())->globalObject(vm)->booleanObjectStructure()); |
47 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
48 | BooleanObject* obj = BooleanObject::create(vm, booleanStructure); |
49 | obj->setInternalValue(vm, boolean); |
50 | return JSValue::encode(obj); |
51 | } |
52 | |
53 | BooleanConstructor::BooleanConstructor(VM& vm, Structure* structure) |
54 | : InternalFunction(vm, structure, callBooleanConstructor, constructWithBooleanConstructor) |
55 | { |
56 | } |
57 | |
58 | void BooleanConstructor::finishCreation(VM& vm, BooleanPrototype* booleanPrototype) |
59 | { |
60 | Base::finishCreation(vm, vm.propertyNames->Boolean.string(), NameVisibility::Visible, NameAdditionMode::WithoutStructureTransition); |
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); |
63 | } |
64 | |
65 | JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSGlobalObject* globalObject, JSValue immediateBooleanValue) |
66 | { |
67 | VM& vm = exec->vm(); |
68 | BooleanObject* obj = BooleanObject::create(vm, globalObject->booleanObjectStructure()); |
69 | obj->setInternalValue(vm, immediateBooleanValue); |
70 | return obj; |
71 | } |
72 | |
73 | } // namespace JSC |
74 | |