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

Function makeMemberStructWrapper

sqlite-wasm-cos/sqlite3-node.mjs:10400–10446  ·  view source on GitHub ↗
(ctor, name, si)

Source from the content-addressed store, hash-verified

10398 freed, as such.
10399 */
10400 const makeMemberStructWrapper = function callee(ctor, name, si){
10401 /**
10402 Where we store inner-struct member proxies. Keys are a
10403 combination of the parent object's pointer address and the
10404 property's name. The values are StructType instances.
10405 */
10406 const __innerStructs = (callee.innerStructs ??= new Map());
10407 const key = ctor.memberKey(name);
10408 if( undefined!==si.signature ){
10409 toss("'signature' cannot be used on an embedded struct (",
10410 ctor.structName,".",key,").");
10411 }
10412 if( memberSetterProxy(si) ){
10413 toss("'set' and 'adaptSet' are not permitted for nested struct members.");
10414 }
10415 //console.warn("si =",ctor.structName, name, JSON.stringify(si,' '));
10416 si.structName ??= ctor.structName+'::'+name;
10417 si.key = key;
10418 si.name = name;
10419 si.constructor = this.call(this, si.structName, si);
10420 //console.warn("si.constructor =",si.constructor);
10421 //console.warn("si =",si,"ctor=",ctor);
10422 const getterProxy = memberGetterProxy(si);
10423 const prop = Object.assign(Object.create(null),{
10424 configurable: false,
10425 enumerable: false,
10426 set: __propThrowOnSet(ctor/*not si.constructor*/.structName, key),
10427 get: function(){
10428 const dbg = this.debugFlags.__flags;
10429 const p = this.pointer;
10430 const k = p+'.'+key;
10431 let s = __innerStructs.get(k);
10432 if(dbg.getter){ log("debug.getter: k =",k); }
10433 if( !s ){
10434 s = new si.constructor(__ptrAdd(p, si.offset));
10435 __innerStructs.set(k, s);
10436 this.addOnDispose(()=>s.dispose());
10437 s.addOnDispose(()=>__innerStructs.delete(k));
10438 //console.warn("Created",k,"proxy");
10439 }
10440 if(getterProxy) s = getterProxy.apply(this,[s,key]);
10441 if(dbg.getter) log("debug.getter: result =",s);
10442 return s;
10443 }
10444 });
10445 Object.defineProperty(ctor.prototype, key, prop);
10446 }/*makeMemberStructWrapper()*/;
10447
10448 /**
10449 This is where most of the magic happens.

Callers

nothing calls this directly

Calls 8

setMethod · 0.80
tossFunction · 0.70
memberSetterProxyFunction · 0.70
memberGetterProxyFunction · 0.70
__propThrowOnSetFunction · 0.70
logFunction · 0.70
__ptrAddFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected