(target, source, funcArgs, runtime)
| 32 | } |
| 33 | |
| 34 | install(target, source, funcArgs, runtime) { |
| 35 | const args = this.args; |
| 36 | const start = this.start; |
| 37 | const errorHandler = this.errorHandler; |
| 38 | const errorSymbol = this.errorSymbol; |
| 39 | const finallyHandler = this.finallyHandler; |
| 40 | const nameVal = this.nameVal; |
| 41 | const nameSpace = this.nameSpace; |
| 42 | const funcName = this.name; |
| 43 | const functionFeature = this; |
| 44 | |
| 45 | var func = function () { |
| 46 | // null, worker |
| 47 | var ctx = runtime.makeContext(source, functionFeature, target, null); |
| 48 | |
| 49 | // install error handler if any |
| 50 | ctx.meta.errorHandler = errorHandler; |
| 51 | ctx.meta.errorSymbol = errorSymbol; |
| 52 | ctx.meta.finallyHandler = finallyHandler; |
| 53 | |
| 54 | for (var i = 0; i < args.length; i++) { |
| 55 | var name = args[i]; |
| 56 | var argumentVal = arguments[i]; |
| 57 | if (name) { |
| 58 | ctx.locals[name.value] = argumentVal; |
| 59 | } |
| 60 | } |
| 61 | ctx.meta.caller = arguments[args.length]; |
| 62 | if (ctx.meta.caller) { |
| 63 | ctx.meta.callingCommand = ctx.meta.caller.meta.command; |
| 64 | } |
| 65 | var resolve, reject; |
| 66 | var promise = new Promise(function (theResolve, theReject) { |
| 67 | resolve = theResolve; |
| 68 | reject = theReject; |
| 69 | }); |
| 70 | start.execute(ctx); |
| 71 | if (ctx.meta.returned) { |
| 72 | return ctx.meta.returnValue; |
| 73 | } else { |
| 74 | ctx.meta.resolve = resolve; |
| 75 | ctx.meta.reject = reject; |
| 76 | return promise; |
| 77 | } |
| 78 | }; |
| 79 | func.hyperfunc = true; |
| 80 | func.hypername = nameVal; |
| 81 | runtime.assignToNamespace(target, nameSpace, funcName, func); |
| 82 | } |
| 83 | |
| 84 | static parse(parser) { |
| 85 | if (!parser.matchToken("def")) return; |
nothing calls this directly
no test coverage detected