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}
166
167void 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
208void JSPromise::doCancel(const JavaScriptEntryParameters& jsEntry) {
209 auto jsValue = _jsValue.getJsValue(jsEntry.jsContext, jsEntry.exceptionTracker);

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