]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | /* |
2 | * Copyright (C) 2013 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 "JSPromiseDeferred.h" | |
28 | ||
29 | #if ENABLE(PROMISES) | |
30 | ||
ed1e77d3 | 31 | #include "BuiltinNames.h" |
81345200 | 32 | #include "Error.h" |
ed1e77d3 | 33 | #include "Exception.h" |
81345200 A |
34 | #include "JSCJSValueInlines.h" |
35 | #include "JSCellInlines.h" | |
36 | #include "JSPromise.h" | |
37 | #include "JSPromiseConstructor.h" | |
81345200 A |
38 | #include "SlotVisitorInlines.h" |
39 | #include "StructureInlines.h" | |
40 | ||
41 | namespace JSC { | |
42 | ||
ed1e77d3 | 43 | const ClassInfo JSPromiseDeferred::s_info = { "JSPromiseDeferred", 0, 0, CREATE_METHOD_TABLE(JSPromiseDeferred) }; |
81345200 A |
44 | |
45 | JSPromiseDeferred* JSPromiseDeferred::create(ExecState* exec, JSGlobalObject* globalObject) | |
46 | { | |
47 | VM& vm = exec->vm(); | |
81345200 | 48 | |
ed1e77d3 A |
49 | JSFunction* newPromiseDeferredFunction = globalObject->newPromiseDeferredFunction(); |
50 | CallData callData; | |
51 | CallType callType = JSC::getCallData(newPromiseDeferredFunction, callData); | |
52 | ASSERT(callType != CallTypeNone); | |
81345200 | 53 | |
ed1e77d3 A |
54 | MarkedArgumentBuffer arguments; |
55 | JSValue deferred = call(exec, newPromiseDeferredFunction, callType, callData, jsUndefined(), arguments); | |
56 | ||
57 | JSValue promise = deferred.get(exec, vm.propertyNames->promisePrivateName); | |
58 | ASSERT(promise.inherits(JSPromise::info())); | |
59 | JSValue resolve = deferred.get(exec, vm.propertyNames->builtinNames().resolvePrivateName()); | |
60 | JSValue reject = deferred.get(exec, vm.propertyNames->builtinNames().rejectPrivateName()); | |
61 | ||
62 | return JSPromiseDeferred::create(vm, jsCast<JSPromise*>(promise), resolve, reject); | |
81345200 A |
63 | } |
64 | ||
65 | JSPromiseDeferred* JSPromiseDeferred::create(VM& vm, JSObject* promise, JSValue resolve, JSValue reject) | |
66 | { | |
67 | JSPromiseDeferred* deferred = new (NotNull, allocateCell<JSPromiseDeferred>(vm.heap)) JSPromiseDeferred(vm); | |
68 | deferred->finishCreation(vm, promise, resolve, reject); | |
69 | return deferred; | |
70 | } | |
71 | ||
72 | JSPromiseDeferred::JSPromiseDeferred(VM& vm) | |
73 | : Base(vm, vm.promiseDeferredStructure.get()) | |
74 | { | |
75 | } | |
76 | ||
77 | void JSPromiseDeferred::finishCreation(VM& vm, JSObject* promise, JSValue resolve, JSValue reject) | |
78 | { | |
79 | Base::finishCreation(vm); | |
80 | m_promise.set(vm, this, promise); | |
81 | m_resolve.set(vm, this, resolve); | |
82 | m_reject.set(vm, this, reject); | |
83 | } | |
84 | ||
85 | void JSPromiseDeferred::visitChildren(JSCell* cell, SlotVisitor& visitor) | |
86 | { | |
87 | JSPromiseDeferred* thisObject = jsCast<JSPromiseDeferred*>(cell); | |
88 | ASSERT_GC_OBJECT_INHERITS(thisObject, info()); | |
81345200 A |
89 | |
90 | Base::visitChildren(thisObject, visitor); | |
91 | ||
92 | visitor.append(&thisObject->m_promise); | |
93 | visitor.append(&thisObject->m_resolve); | |
94 | visitor.append(&thisObject->m_reject); | |
95 | } | |
96 | ||
81345200 A |
97 | } // namespace JSC |
98 | ||
99 | #endif // ENABLE(PROMISES) |