function()

in knative-build/runtimes/javascript/runner.js [112:146]


            function (resolve, reject) {
                callback.completed = undefined;
                callback.next = resolve;

                try {
                    DEBUG.dumpObject(args, "Calling: thisRunner.userScriptMain(args): args", "run");
                    var result = thisRunner.userScriptMain(args);
                    DEBUG.dumpObject(result,"Returned: thisRunner.userScriptMain(args): result", "run");
                } catch (e) {
                    DEBUG.functionEndError("ERROR: Promise.reject(): " + e.message);
                    reject(e);
                }

                // Non-promises/undefined instantly resolve.
                Promise.resolve(result).then(function (resolvedResult) {
                    // This happens, e.g. if you just have "return;"
                    if (typeof resolvedResult === "undefined") {
                        resolvedResult = {};
                    }
                    DEBUG.functionEndSuccess("Promise.Resolve(): result=" + resolvedResult, "run");
                    resolve(resolvedResult);
                }).catch(function (error) {
                    // A rejected Promise from the user code maps into a
                    // successful promise wrapping a whisk-encoded error.

                    // Special case if the user just called `reject()`.
                    if (!error) {
                        DEBUG.functionEndError("ERROR: reject()", "run");
                        resolve({ error: {}});
                    } else {
                        DEBUG.functionEndError("ERROR: " + error.message, "run");
                        resolve({ error: serializeError(error) });
                    }
                });
            }