by
15
7
3,719
0
Top 1% !
Popular
Famous
Nice
Easy-to-find
Specified
MultiPlatform
Popularity: 2873rd place
Languageactionscript
Languagejavascript
LicenseMIT_X11

weaklings.js...  a good try at creating "WeakSet" and "WeakMap" data-structures.

go ahead, slap the map and set...
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/250855/weaklings-js-----a-good-try-at-creating-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// weak set / map var wkMap=global.WeakMap, wkSet=global.WeakSet; function wkmCreate(a) { if(!isCallConstruct()) { throw MakeTypeError('constructor_not_function',['WkMap']); } var b,c; if(!(a==null)){ b=getEnum(a); c=this.set; if(!(ClassIs(c)==='Function')) { throw MakeTypeError('property_not_function',['set',this]); } } cofigureGroup(this); if ((b===(void 0))) { return; } var d,g,h; while(!(d=b.next()).done) { if(!(isSpecial(d))) { throw MakeTypeError('iterator_result_not_an_object',[d]); } h=d.value; if(!(isSpecial(h))) { throw MakeTypeError('iterator_value_not_an_object',[h]); } makeCall(this,h[0],h[1],c); } } function wkmGet(a) { if((ClassIs(this)!=='WkMap')) { throw MakeTypeError('incompatible_method_receiver', ['WkMap.prototype.get', this]); } if(!isSpecial(a)||(typeof(a)==='symbol')) { throw MakeTypeError('invalid_weakmap_key', [this,a]); } return wkmGet(this,a); } function wkmSet(a,b) { if((ClassIs(this)!=='WkMap')) { throw MakeTypeError('incompatible_method_receiver', ['WkMap.prototype.set', this]); } if(!((isSpecial(a))||(typeof(a)=='symbol'))) { throw MakeTypeError('invalid_weakmap_key', [this,a]); } return wkmCollection(this,a,b); } function wkmContains(a) { if((ClassIs(this)!=='WkMap')) { throw MakeTypeError('incompatible_method_receiver', ['WkMap.prototype.contins', this]); } if(!((isSpecial(a))||(typeof(a)==='symbol'))) { throw MakeTypeError('invalid_weakmap_key', [this,a]); } return wsContains(this,a); } function WkmDelete(a) { if((ClassIs(this)!=='WkMap')) { throw MakeTypeError('incompatible_method_receiver', ['WkMap.prototype.delete', this]); } if(!((isSpecial(a))||(typeof(a)==='symbol'))) { throw MakeTypeError('invalid_weakmap_key', [this, a]); } return emptyCollection(this, a); } function wkmClear() { if((ClassIs(this)!=='WkMap')) { throw MakeTypeError('incompatible_method_receiver', ['WkMap.prototype.clear', this]); } cofigureGroup(this); } function wkmConfigure() { isStrapped(); setCode(wkMap, wkmCreate); setProto(wkMap, new genObj()); addName(wkMap.prototype, "constructor", wkMap, 2); pinMethods(wkMap.prototype, 2, genAry( "get", wkmGet, "set", wkmSet, "contains", wkmContains, "delete", wkmDelete, "clear", wkmClear )); } wkmConfigure(); function wsConstructor(a) { if(!isConstructCall()) { throw MakeTypeError('constructor_not_function',['WeakSet']); } var b,c; if(a!==null) { b=getEnum(a); c=this.add; if(ClassIs(c)!=='Function') { throw MakeTypeError('property_not_function', ['add', this]); } } cofigureGroup(this); if ((b===(void 0))) { return; } var d,g; while(!(d=b.next()).done) { if(!(isSpecial(d))) { throw MakeTypeError('iterator_result_not_an_object', [d]); } makeCall(this, d.value, c); } } function addItem(a) { if(ClassIs(this)!=='WkSet') { throw MakeTypeError('incompatible_method_receiver', ['WkSet.prototype.addItem', this]); } if(!isSpecial(a)||typeof(a)==='symbol') { throw MakeTypeError('invalid_weakset_value', [this,a]); } return wsCollection(this, a, true); } function wsContains(a) { if(ClassIs(this)!=='WkSet') { throw MakeTypeError('incompatible_method_receiver', ['WkSet.prototype.contains',this]); } if(!isSpecial(a)||typeof(a)==='symbol') { throw MakeTypeError('invalid_weakset_value', [this, a]); } return wsContains(this, a); } function wsDelete(a) { if(ClassIs(this)!=='WkSet') { throw MakeTypeError('incompatible_method_receiver', ['WkSet.prototype.delete',this]); } if(!(isSpecial(a)||typeof(a)==='symbol')) { throw MakeTypeError('invalid_weakset_value', [this, a]); } return emptyCollection(this, a); } function wsClear(){ if(ClassIs(this)!=='WkSet') { throw MakeTypeError('incompatible_method_receiver', ['WkSet.prototype.clear', this]); } cofigureGroup(this); } function setConfigure() { isStrapped(); setCode(wkSet, wsConstructor); setPrototype(wkSet, new genObj()); addName(wkSet.prototype,"constructor", wkSet, 2); pinMethods(wkSet.prototype, 2, genAry( "add", addItem, "has", wsContains, "delete",wsDelete, "clear",wsClear )); } return setConfigure();
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus