| 165 | } |
| 166 | |
| 167 | void JSPromise::doOnComplete(const Ref<PromiseCallback>& callback, const JavaScriptEntryParameters& jsEntry) { |
| 168 | auto jsValue = _jsValue.getJsValue(jsEntry.jsContext, jsEntry.exceptionTracker); |
| 169 | if (!jsEntry.exceptionTracker) { |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | if (!jsEntry.jsContext.isValueObject(jsValue)) { |
| 174 | // Our JS value is not a promise |
| 175 | doOnCompleteWithValue(callback, jsValue, jsEntry); |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | auto thenCallback = jsEntry.jsContext.getObjectProperty( |
| 180 | jsValue, jsEntry.jsContext.getPropertyNameCached(thenPropertyKey()), jsEntry.exceptionTracker); |
| 181 | |
| 182 | if (jsEntry.jsContext.isValueUndefined(thenCallback.get())) { |
| 183 | // Not a promise |
| 184 | doOnCompleteWithValue(callback, jsValue, jsEntry); |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | std::array<JSValueRef, 2> parameters; |
| 189 | |
| 190 | parameters[0] = jsEntry.jsContext.newFunction(makeShared<JSPromiseOnFulfilled>(callback, _valueMarshaller), |
| 191 | jsEntry.exceptionTracker); |
| 192 | if (!jsEntry.exceptionTracker) { |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | parameters[1] = jsEntry.jsContext.newFunction(makeShared<JSPromiseOnRejected>(callback), jsEntry.exceptionTracker); |
| 197 | if (!jsEntry.exceptionTracker) { |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | JSFunctionCallContext callContext( |
| 202 | jsEntry.jsContext, parameters.data(), parameters.size(), jsEntry.exceptionTracker); |
| 203 | callContext.setThisValue(jsValue); |
| 204 | |
| 205 | jsEntry.jsContext.callObjectAsFunction(thenCallback.get(), callContext); |
| 206 | } |
| 207 | |
| 208 | void JSPromise::doCancel(const JavaScriptEntryParameters& jsEntry) { |
| 209 | auto jsValue = _jsValue.getJsValue(jsEntry.jsContext, jsEntry.exceptionTracker); |
no test coverage detected