| 165 | taskScheduler->dispatchOnJsThreadAsync( |
| 166 | _jsValue.getContext(), |
| 167 | [self = strongSmallRef(this)](const JavaScriptEntryParameters& jsEntry) { self->doCancel(jsEntry); }); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | bool JSPromise::isCancelable() const { |
| 172 | return _cancelable; |
| 173 | } |
| 174 | |
| 175 | void JSPromise::doOnCompleteWithValue(const Ref<PromiseCallback>& callback, |
| 176 | const JSValue& value, |
| 177 | const StringBox& anrAttribution, |
| 178 | const JavaScriptEntryParameters& jsEntry) { |
| 179 | ScopedNativeCallActivity activity(getAttributingRuntime(jsEntry.jsContext, anrAttribution), anrAttribution); |
| 180 | JSPromiseOnFulfilled::callCompletionWithValue( |
| 181 | jsEntry.jsContext, value, _valueMarshaller, callback, jsEntry.exceptionTracker); |
| 182 | } |
| 183 | |
| 184 | StringBox JSPromise::getCompletionAttribution(const JavaScriptEntryParameters& jsEntry) const { |
| 185 | auto* taskScheduler = jsEntry.jsContext.getTaskScheduler(); |
| 186 | if (taskScheduler == nullptr) { |
| 187 | return StringBox(); |
| 188 | } |
| 189 | return JavaScriptANRAttribution::referenceLabel(_jsValue.getReferenceInfo()); |
| 190 | } |
| 191 | |
| 192 | void JSPromise::doOnComplete(const Ref<PromiseCallback>& callback, const JavaScriptEntryParameters& jsEntry) { |
| 193 | auto jsValue = _jsValue.getJsValue(jsEntry.jsContext, jsEntry.exceptionTracker); |
| 194 | if (!jsEntry.exceptionTracker) { |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | auto anrAttribution = getCompletionAttribution(jsEntry); |
| 199 | |
| 200 | if (!jsEntry.jsContext.isValueObject(jsValue)) { |
| 201 | // Our JS value is not a promise |
| 202 | doOnCompleteWithValue(callback, jsValue, anrAttribution, jsEntry); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | auto thenCallback = jsEntry.jsContext.getObjectProperty( |
| 207 | jsValue, jsEntry.jsContext.getPropertyNameCached(thenPropertyKey()), jsEntry.exceptionTracker); |
| 208 | |
| 209 | if (jsEntry.jsContext.isValueUndefined(thenCallback.get())) { |
no test coverage detected