fix bad rpc finding for class member for real this time

This commit is contained in:
2020-02-01 11:45:35 +01:00
parent fff118d9d2
commit a2268526af
4 changed files with 57 additions and 4 deletions
+8 -2
View File
@@ -53,15 +53,21 @@ export class RPCServer<
if(conf.connectionHandler) conf.connectionHandler(socket)
}
exporters.forEach(U.fixNames)
let badRPC = exporters.flatMap(ex => ex.exportRPCs()).find(rpc => !rpc.name)
if(badRPC)
throw new Error(`
if(badRPC){
console.log(badRPC);
throw new Error(`
RPC did not provide a name.
\nUse 'funtion name(..){ .. }' syntax instead.
\n
\n<------------OFFENDING RPC:
\n`+badRPC.toString()+`
\n>------------OFFENDING RPC`)
}
this.startWebsocket()
}
+16
View File
@@ -172,4 +172,20 @@ export function makeSesameFunction (sesame : T.SesameFunction | string) : T.Sesa
export function appendComma(s?:string):string{
return s?`'${s}',`:""
}
/**
* Typescript incorrectly omits the function.name attribute for MethodDeclaration.
* This was supposedly fixed (https://github.com/microsoft/TypeScript/issues/5611) but it still is the case.
* This function sets the name value for all object members that are functions.
*/
export function fixNames(o:Object):void{
Object.keys(o).forEach(key => {
if(typeof o[key] === 'function' && !o[key].name){
Object.defineProperty(o[key], 'name', {
value: key
})
}
})
}