2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "JSPromiseDeferred.h"
31 #include "BuiltinNames.h"
33 #include "Exception.h"
34 #include "JSCJSValueInlines.h"
35 #include "JSCellInlines.h"
36 #include "JSPromise.h"
37 #include "JSPromiseConstructor.h"
38 #include "SlotVisitorInlines.h"
39 #include "StructureInlines.h"
43 const ClassInfo
JSPromiseDeferred::s_info
= { "JSPromiseDeferred", 0, 0, CREATE_METHOD_TABLE(JSPromiseDeferred
) };
45 JSPromiseDeferred
* JSPromiseDeferred::create(ExecState
* exec
, JSGlobalObject
* globalObject
)
49 JSFunction
* newPromiseDeferredFunction
= globalObject
->newPromiseDeferredFunction();
51 CallType callType
= JSC::getCallData(newPromiseDeferredFunction
, callData
);
52 ASSERT(callType
!= CallTypeNone
);
54 MarkedArgumentBuffer arguments
;
55 JSValue deferred
= call(exec
, newPromiseDeferredFunction
, callType
, callData
, jsUndefined(), arguments
);
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());
62 return JSPromiseDeferred::create(vm
, jsCast
<JSPromise
*>(promise
), resolve
, reject
);
65 JSPromiseDeferred
* JSPromiseDeferred::create(VM
& vm
, JSObject
* promise
, JSValue resolve
, JSValue reject
)
67 JSPromiseDeferred
* deferred
= new (NotNull
, allocateCell
<JSPromiseDeferred
>(vm
.heap
)) JSPromiseDeferred(vm
);
68 deferred
->finishCreation(vm
, promise
, resolve
, reject
);
72 JSPromiseDeferred::JSPromiseDeferred(VM
& vm
)
73 : Base(vm
, vm
.promiseDeferredStructure
.get())
77 void JSPromiseDeferred::finishCreation(VM
& vm
, JSObject
* promise
, JSValue resolve
, JSValue reject
)
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
);
85 void JSPromiseDeferred::visitChildren(JSCell
* cell
, SlotVisitor
& visitor
)
87 JSPromiseDeferred
* thisObject
= jsCast
<JSPromiseDeferred
*>(cell
);
88 ASSERT_GC_OBJECT_INHERITS(thisObject
, info());
90 Base::visitChildren(thisObject
, visitor
);
92 visitor
.append(&thisObject
->m_promise
);
93 visitor
.append(&thisObject
->m_resolve
);
94 visitor
.append(&thisObject
->m_reject
);
99 #endif // ENABLE(PROMISES)