1 | /* |
2 | * Copyright (C) 2013, 2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "JSPromiseConstructor.h" |
28 | |
29 | #include "BuiltinNames.h" |
30 | #include "Error.h" |
31 | #include "Exception.h" |
32 | #include "GetterSetter.h" |
33 | #include "JSCBuiltins.h" |
34 | #include "JSCInlines.h" |
35 | #include "JSFunction.h" |
36 | #include "JSPromise.h" |
37 | #include "JSPromisePrototype.h" |
38 | #include "Lookup.h" |
39 | #include "NumberObject.h" |
40 | |
41 | namespace JSC { |
42 | |
43 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSPromiseConstructor); |
44 | |
45 | } |
46 | |
47 | #include "JSPromiseConstructor.lut.h" |
48 | |
49 | namespace JSC { |
50 | |
51 | const ClassInfo JSPromiseConstructor::s_info = { "Function" , &Base::s_info, &promiseConstructorTable, nullptr, CREATE_METHOD_TABLE(JSPromiseConstructor) }; |
52 | |
53 | /* Source for JSPromiseConstructor.lut.h |
54 | @begin promiseConstructorTable |
55 | resolve JSBuiltin DontEnum|Function 1 |
56 | reject JSBuiltin DontEnum|Function 1 |
57 | race JSBuiltin DontEnum|Function 1 |
58 | all JSBuiltin DontEnum|Function 1 |
59 | allSettled JSBuiltin DontEnum|Function 1 |
60 | @end |
61 | */ |
62 | |
63 | JSPromiseConstructor* JSPromiseConstructor::create(VM& vm, Structure* structure, JSPromisePrototype* promisePrototype, GetterSetter* speciesSymbol) |
64 | { |
65 | JSGlobalObject* globalObject = structure->globalObject(); |
66 | FunctionExecutable* executable = promiseConstructorPromiseConstructorCodeGenerator(vm); |
67 | JSPromiseConstructor* constructor = new (NotNull, allocateCell<JSPromiseConstructor>(vm.heap)) JSPromiseConstructor(vm, executable, globalObject, structure); |
68 | constructor->finishCreation(vm, promisePrototype, speciesSymbol); |
69 | constructor->addOwnInternalSlots(vm, globalObject); |
70 | return constructor; |
71 | } |
72 | |
73 | Structure* JSPromiseConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) |
74 | { |
75 | return Structure::create(vm, globalObject, prototype, TypeInfo(JSFunctionType, StructureFlags), info()); |
76 | } |
77 | |
78 | JSPromiseConstructor::JSPromiseConstructor(VM& vm, FunctionExecutable* executable, JSGlobalObject* globalObject, Structure* structure) |
79 | : Base(vm, executable, globalObject, structure) |
80 | { |
81 | } |
82 | |
83 | void JSPromiseConstructor::finishCreation(VM& vm, JSPromisePrototype* promisePrototype, GetterSetter* speciesSymbol) |
84 | { |
85 | Base::finishCreation(vm); |
86 | putDirectWithoutTransition(vm, vm.propertyNames->prototype, promisePrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); |
87 | putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly); |
88 | putDirectNonIndexAccessorWithoutTransition(vm, vm.propertyNames->speciesSymbol, speciesSymbol, PropertyAttribute::Accessor | PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum); |
89 | } |
90 | |
91 | void JSPromiseConstructor::addOwnInternalSlots(VM& vm, JSGlobalObject* globalObject) |
92 | { |
93 | JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().resolvePrivateName(), promiseConstructorResolveCodeGenerator, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); |
94 | JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().rejectPrivateName(), promiseConstructorRejectCodeGenerator, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); |
95 | } |
96 | |
97 | } // namespace JSC |
98 | |