MCPcopy Create free account
hub / github.com/Snapchat/Valdi / doOnComplete

Method doOnComplete

valdi/src/valdi/runtime/JavaScript/JSPromise.cpp:167–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165 taskScheduler->dispatchOnJsThreadAsync(
166 _jsValue.getContext(),
167 [self = strongSmallRef(this)](const JavaScriptEntryParameters& jsEntry) { self->doCancel(jsEntry); });
168 }
169}
170
171bool JSPromise::isCancelable() const {
172 return _cancelable;
173}
174
175void 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
184StringBox 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
192void 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())) {

Callers 1

onCompleteMethod · 0.95

Calls 11

getJsValueMethod · 0.80
getPropertyNameCachedMethod · 0.80
setThisValueMethod · 0.80
getMethod · 0.65
isValueObjectMethod · 0.45
getObjectPropertyMethod · 0.45
isValueUndefinedMethod · 0.45
newFunctionMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
callObjectAsFunctionMethod · 0.45

Tested by

no test coverage detected