MCPcopy Create free account
hub / github.com/GoogleChrome/samples / installMethod

Function installMethod

sqlite-wasm-cos/sqlite3-node.mjs:12584–12652  ·  view source on GitHub ↗
(
    tgt, name, func, applyArgcCheck = callee.installMethodArgcCheck
  )

Source from the content-addressed store, hash-verified

12582 environment in an undefined state.
12583 */
12584 const installMethod = function callee(
12585 tgt, name, func, applyArgcCheck = callee.installMethodArgcCheck
12586 ){
12587 if(!(tgt instanceof StructBinder.StructType)){
12588 toss("Usage error: target object is-not-a StructType.");
12589 }else if(!(func instanceof Function) && !wasm.isPtr(func)){
12590 toss("Usage error: expecting a Function or WASM pointer to one.");
12591 }
12592 if(1===arguments.length){
12593 return (n,f)=>callee(tgt, n, f, applyArgcCheck);
12594 }
12595 if(!callee.argcProxy){
12596 callee.argcProxy = function(tgt, funcName, func,sig){
12597 return function(...args){
12598 if(func.length!==arguments.length){
12599 toss("Argument mismatch for",
12600 tgt.structInfo.name+"::"+funcName
12601 +": Native signature is:",sig);
12602 }
12603 return func.apply(this, args);
12604 }
12605 };
12606 /* An ondispose() callback for use with
12607 StructBinder-created types. */
12608 callee.removeFuncList = function(){
12609 if(this.ondispose.__removeFuncList){
12610 this.ondispose.__removeFuncList.forEach(
12611 (v,ndx)=>{
12612 if(wasm.isPtr(v)){
12613 try{wasm.uninstallFunction(v)}
12614 catch(e){/*ignore*/}
12615 }
12616 /* else it's a descriptive label for the next number in
12617 the list. */
12618 }
12619 );
12620 delete this.ondispose.__removeFuncList;
12621 }
12622 };
12623 }/*static init*/
12624 const sigN = tgt.memberSignature(name);
12625 if(sigN.length<2){
12626 toss("Member",name,"does not have a function pointer signature:",sigN);
12627 }
12628 const memKey = tgt.memberKey(name);
12629 const fProxy = (applyArgcCheck && !wasm.isPtr(func))
12630 /** This middle-man proxy is only for use during development, to
12631 confirm that we always pass the proper number of
12632 arguments. We know that the C-level code will always use the
12633 correct argument count. */
12634 ? callee.argcProxy(tgt, memKey, func, sigN)
12635 : func;
12636 if(wasm.isPtr(fProxy)){
12637 if(fProxy && !wasm.functionEntry(fProxy)){
12638 toss("Pointer",fProxy,"is not a WASM function table entry.");
12639 }
12640 tgt[memKey] = fProxy;
12641 }else{

Callers 2

installMethodsFunction · 0.70
sqlite3InitModuleFunction · 0.70

Calls 1

tossFunction · 0.70

Tested by

no test coverage detected