bare.debug.js 285 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039
  1. /*!
  2. * @name @waca/barejs
  3. * @version 1.1.20181003
  4. * @license
  5. * Licenced Materials - Property of IBM
  6. *
  7. * (C) Copyright IBM Corp. 2016, 2018
  8. *
  9. * US Government Users Restricted Rights - Use, duplication or
  10. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  11. */
  12. module.exports =
  13. /******/ (function(modules) { // webpackBootstrap
  14. /******/ // The module cache
  15. /******/ var installedModules = {};
  16. /******/ // The require function
  17. /******/ function __webpack_require__(moduleId) {
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId])
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ // Create a new module (and put it into the cache)
  22. /******/ var module = installedModules[moduleId] = {
  23. /******/ exports: {},
  24. /******/ id: moduleId,
  25. /******/ loaded: false
  26. /******/ };
  27. /******/ // Execute the module function
  28. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  29. /******/ // Flag the module as loaded
  30. /******/ module.loaded = true;
  31. /******/ // Return the exports of the module
  32. /******/ return module.exports;
  33. /******/ }
  34. /******/ // expose the modules object (__webpack_modules__)
  35. /******/ __webpack_require__.m = modules;
  36. /******/ // expose the module cache
  37. /******/ __webpack_require__.c = installedModules;
  38. /******/ // __webpack_public_path__
  39. /******/ __webpack_require__.p = "";
  40. /******/ // Load entry module and return exports
  41. /******/ return __webpack_require__(0);
  42. /******/ })
  43. /************************************************************************/
  44. /******/ ([
  45. /* 0 */
  46. /***/ (function(module, exports, __webpack_require__) {
  47. __webpack_require__(1);
  48. __webpack_require__(13);
  49. __webpack_require__(16);
  50. module.exports = __webpack_require__(18);
  51. /***/ }),
  52. /* 1 */
  53. /***/ (function(module, exports, __webpack_require__) {
  54. // Licensed Materials - Property of IBM
  55. //
  56. // IBM Watson Analytics
  57. //
  58. // (C) Copyright IBM Corp. 2015, 2018
  59. //
  60. // US Government Users Restricted Rights - Use, duplication or
  61. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  62. ( function(
  63. Object,
  64. Array,
  65. String,
  66. Error,
  67. TypeError,
  68. ObjectPolyfill,
  69. Map,
  70. Set,
  71. Symbol,
  72. WeakMap
  73. )
  74. {
  75. "use strict";
  76. /*global console, setTimeout*/
  77. /*jshint latedef:false*/
  78. /**
  79. * Note: decl is not a constructor; call its static members.
  80. * @class module:barejs.decl
  81. * @abstract
  82. * @classdesc Module for declaring classes, interfaces, enums, and checking implementations.
  83. * decl uses the inheritance natively supported by JavaScript, instead of trying to emulate
  84. * multiple inheritance or providing "super" or "base" keyword emulation. This combined with the
  85. * fact that decl doesn't generate a constructor function (the defining code has to supply it)
  86. * leads to classes with no run-time overhead. It also means there is no "magic" performed.
  87. * Implementors using decl's inheritance are responsible for calling the base class
  88. * constructor and methods using the standard JavaScript call mechanism:
  89. *
  90. * function A( _name )
  91. * {
  92. * this.name = _name;
  93. * }
  94. *
  95. * decl.declareClass( A,
  96. * {
  97. * toString: function()
  98. * {
  99. * return this.name;
  100. * }
  101. * }
  102. *
  103. * function B( _name, _age )
  104. * {
  105. * // Invoke base class constructor on this object
  106. * A.call( this, _name );
  107. * this.age = _age;
  108. * }
  109. *
  110. * decl.declareClass( B, A,
  111. * {
  112. * toString: function()
  113. * {
  114. * // Invoke A::toString() and append our age to it.
  115. * return A.prototype.toString.call( this ) + "; age " + this.age;
  116. * }
  117. * } );
  118. *
  119. * In the debug version of barejs, decl adds a lot of metadata to provide a great debugging experience.
  120. * When defined with named constructors, objects created with decl will be highly discoverable and debuggable in browsers like Chrome.
  121. */
  122. // List of classes that are not allowed to be casted to.
  123. var uncastable_types = new Set();
  124. var uncastable_keys = new Map();
  125. // Grab slice from an array
  126. var slice = Array.prototype.slice;
  127. var hasOwnProperty = Object.prototype.hasOwnProperty;
  128. var canWriteFnName = !!( Object.defineProperties && Object.getOwnPropertyDescriptor );
  129. /*istanbul ignore else: NodeJS supports this*/
  130. if ( canWriteFnName )
  131. {
  132. canWriteFnName = Object.getOwnPropertyDescriptor( Function.prototype, "name" );
  133. canWriteFnName = !canWriteFnName || canWriteFnName.configurable;
  134. }
  135. var reSymbolProto = /^(?:@@([a-zA-Z0-9_\$]+)|\[\[([a-zA-Z0-9_\$]+)\]\])$/;
  136. var reStaticIgnore = /^(?:constructor|prototype|name|interfaces|superclass|\$private)$/;
  137. var metaData = new WeakMap();
  138. /**
  139. * Convenience property to ease defining a read only property on an Interface.
  140. * It as simply a shortcut for '{ allowGet: true, allowSet: false }':
  141. *
  142. * decl.declareInterface( function MyInterface() {},
  143. * {
  144. * // The following two definitions have exactly the same effect:
  145. * myProperty: decl.readOnlyProperty,
  146. * myProperty: { allowGet: true, allowSet: false }
  147. * } );
  148. *
  149. * @member {object}
  150. * @readonly
  151. * @memberof module:barejs.decl
  152. */
  153. var readOnlyProperty = ObjectPolyfill.freeze( { allowGet: true, allowSet: false } );
  154. var native_ctors = [ Object, Array, Function, Boolean, Number, Math, Date, String, RegExp, Symbol,
  155. Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError ];
  156. // Detect a bunch more of optional native constructors, so our native_ctor array is complete
  157. //jshint -W117
  158. /*istanbul ignore else*/
  159. if ( typeof ArrayBuffer !== "undefined" )
  160. native_ctors.push( ArrayBuffer );
  161. /*istanbul ignore else*/
  162. if ( typeof Float32Array !== "undefined" )
  163. native_ctors.push( Float32Array );
  164. /*istanbul ignore else*/
  165. if ( typeof Float64Array !== "undefined" )
  166. native_ctors.push( Float64Array );
  167. /*istanbul ignore else*/
  168. if ( typeof Promise !== "undefined" )
  169. native_ctors.push( Promise );
  170. /*istanbul ignore else*/
  171. if ( typeof Proxy !== "undefined" )
  172. native_ctors.push( Proxy );
  173. /*istanbul ignore else*/
  174. if ( typeof Uint8Array !== "undefined" )
  175. native_ctors.push( Uint8Array );
  176. /*istanbul ignore else*/
  177. if ( typeof Uint8ClampedArray !== "undefined" )
  178. native_ctors.push( Uint8ClampedArray );
  179. /*istanbul ignore else*/
  180. if ( typeof Uint16Array !== "undefined" )
  181. native_ctors.push( Uint16Array );
  182. /*istanbul ignore else*/
  183. if ( typeof Uint32Array !== "undefined" )
  184. native_ctors.push( Uint32Array );
  185. //jshint +W117
  186. /**
  187. * Convenience property to ease defining a read/write property on an Interface.
  188. * It as simply a shortcut for '{ allowGet: true, allowSet: true }':
  189. *
  190. * decl.declareInterface( function MyInterface() {},
  191. * {
  192. * // The following two definitions have exactly the same effect:
  193. * myProperty: decl.readWriteProperty,
  194. * myProperty: { allowGet: true, allowSet: true }
  195. * } );
  196. *
  197. * @member {object}
  198. * @readonly
  199. * @memberof module:barejs.decl
  200. */
  201. var readWriteProperty = ObjectPolyfill.freeze( { allowGet: true, allowSet: true } );
  202. /*
  203. * Enable validating interfaces are implemented in debug mode
  204. * Except for Rhino, since it can't handle it...
  205. */
  206. /*istanbul ignore else: We always test in DEBUG*/
  207. if ( !(false) &&
  208. // Detect Rhino so we can ignore it
  209. !( typeof load === "function" && ( typeof Packages === "function" || typeof Packages === "object" ) )
  210. )
  211. {
  212. var validateQueue = [];
  213. /**
  214. * Validate a class implements all interface members.
  215. * @param {function} _class The class to validate.
  216. * @memberof module:barejs.decl~
  217. * @private
  218. */
  219. var validateInterfacesImplemented = function( _class )
  220. {
  221. var errors = [];
  222. if ( _class && _class.interfaces )
  223. {
  224. _class.interfaces.forEach( function( _interface, _idxInterface )
  225. {
  226. var lines = [];
  227. for ( var members = InterfaceMetaData.get( _interface ).members, i = 0, len = members.length; i < len; ++i )
  228. {
  229. var member = members[i];
  230. var error = null;
  231. switch ( member.type )
  232. {
  233. case "function":
  234. var def = member.interfaces[0].prototype[member.name];
  235. var impl = _class.prototype[member.name];
  236. if ( typeof impl !== "function" )
  237. error = "Missing implementation for {def}";
  238. else if ( ( impl.length !== def.length ) && ( impl.proxy !== true ) )
  239. error = "Signature mismatch, {def} defines " + def.length + " arguments but implementation has " + impl.length;
  240. break;
  241. case "property":
  242. if ( !( member.name in _class.prototype ) )
  243. error = "Missing prototype definition for {def}";
  244. break;
  245. }
  246. if ( error !== null )
  247. lines.push( error.replace( "{def}", String( member ) ) );
  248. }
  249. if ( lines.length > 0 )
  250. {
  251. errors.push(
  252. "[" + describe( _interface ) + " @ index " + _idxInterface + "]\r\n\t\t" +
  253. lines.join( "\r\n\t\t" )
  254. );
  255. }
  256. }, this );
  257. }
  258. if ( errors.length > 0 )
  259. throw new Error( describe( _class ) + " has the following errors:\r\n\t" + errors.join( "\r\n\t" ) );
  260. };
  261. /**
  262. * Callback function to validate interfaces
  263. * @memberof module:barejs.decl~
  264. * @private
  265. */
  266. var handleValidateQueue = function()
  267. {
  268. // reset timeout id
  269. delete validateQueue.timeout;
  270. /*istanbul ignore if: sanity check, this function should not be called/queued with an empty queue*/
  271. if ( validateQueue.length < 1 )
  272. return;
  273. // The code below will report errors by throwing an exception. Ensure the validateQueue is empty
  274. var queue = validateQueue;
  275. validateQueue = [];
  276. queue.forEach( function( _class )
  277. {
  278. // For interfaces, just create the metadata; this will do basic validation
  279. if ( isInterface( _class ) )
  280. InterfaceMetaData.get( _class );
  281. else
  282. validateInterfacesImplemented( _class );
  283. } );
  284. };
  285. }
  286. /**
  287. * Generic getter method
  288. * @param {string} _name The name of the property.
  289. * @returns The value of the property
  290. * @memberof module:barejs.decl~
  291. * @private
  292. */
  293. function _get( _name )
  294. {
  295. /*jshint validthis:true*/
  296. return this[_name];
  297. }
  298. /**
  299. * Generic setter method.
  300. * @param {string} _name The name of the property.
  301. * @param _value The value to assign.
  302. * @returns The new value of the property
  303. * @memberof module:barejs.decl~
  304. * @private
  305. */
  306. function _set( _name, _value )
  307. {
  308. /*jshint validthis:true*/
  309. return ( this[_name] = _value );
  310. }
  311. /**
  312. * Used during object prototype expansion to resolve a getter definition
  313. * @memberof module:barejs.decl~
  314. * @private
  315. */
  316. function resolvePropertyAccessor( _target )
  317. {
  318. // It is possible the target is also a property definition. Resolve it
  319. if ( _target && ( typeof _target === "object" ) )
  320. {
  321. if ( hasOwnProperty.call( _target, "value" ) )
  322. return _target.value;
  323. else if ( hasOwnProperty.call( _target, "get" ) )
  324. return _target.get;
  325. }
  326. return _target;
  327. }
  328. /**
  329. * Iterator function that will modify the context to have a defineProperty
  330. * definition instead of direct properties. If the value is already a property definition, it is left
  331. * untouched. Once the object has been parsed, it can then be given to Object.create.
  332. * @memberof module:barejs.decl~
  333. * @private
  334. */
  335. function toDefineProperty( _value, _name, _object, _lookup )
  336. {
  337. var def;
  338. if ( _value && ( typeof _value === "object" ) )
  339. {
  340. if ( hasOwnProperty.call( _value, "value" ) )
  341. {
  342. def = _value;
  343. }
  344. // Guard against map values as they have
  345. else if ( hasOwnProperty.call( _value, "get" ) || hasOwnProperty.call( _value, "set" ) )
  346. {
  347. def = _value;
  348. // If there is no property support, we silently ignore properties
  349. /*istanbul ignore if: NodeJS supports properties*/
  350. if ( !ObjectPolyfill.propertyGetSetSupport )
  351. return null;
  352. // If there is a getter or setter, see if we need to resolve it
  353. if ( typeof def.get === "string" )
  354. {
  355. def.getterName = def.get;
  356. def.get = resolvePropertyAccessor( _object[def.get] || ( _lookup && _lookup[def.get] ) );
  357. }
  358. if ( typeof def.set === "string" )
  359. {
  360. def.setterName = def.set;
  361. def.set = resolvePropertyAccessor( _object[def.set] || ( _lookup && _lookup[def.set] ) );
  362. }
  363. }
  364. }
  365. if ( !def )
  366. {
  367. def =
  368. {
  369. // Make Symbols and string keys starting with "_" not enumerable by default
  370. enumerable: ObjectPolyfill.shouldBeEnumerable( _name ),
  371. writable: true,
  372. value: _value
  373. };
  374. }
  375. return def;
  376. }
  377. /**
  378. * Same purpose as toDefineProperty, but specialised for interfaces, on which we expect only
  379. * functions or objects that define get/set access. Performs validation no other properties are present.
  380. * @memberof module:barejs.decl~
  381. * @private
  382. */
  383. function toDefinePropertyInterface( _value, _name )
  384. {
  385. var ok = false;
  386. var allowGet, allowSet;
  387. switch ( _value && typeof _value )
  388. {
  389. case "function":
  390. // Functions are always OK
  391. ok = true;
  392. break;
  393. case "object":
  394. // If the decl constants where used, there is no sense in validating them
  395. ok = ( _value === readOnlyProperty ) || ( _value === readWriteProperty );
  396. // If not, validate the object given to us
  397. if ( !ok )
  398. {
  399. allowGet = ( "allowGet" in _value ) && _value.allowGet;
  400. allowSet = ( "allowSet" in _value ) && _value.allowSet;
  401. // allowGet, if defined, should be a boolean
  402. if ( typeof allowGet !== "boolean" )
  403. throw new TypeError( "allowGet value is not a boolean" );
  404. // allowSet, if defined, should be a boolean
  405. if ( typeof allowSet !== "boolean" )
  406. throw new TypeError( "allowSet value is not a boolean" );
  407. ok = allowGet || allowSet; // at least one needs to be true.
  408. }
  409. break;
  410. }
  411. if ( !ok )
  412. throw new TypeError( "Values on an interface prototype must be either a function or an object containing allowGet or allowSet boolean properties." );
  413. return { enumerable: true, value: _value };
  414. }
  415. /**
  416. * Convenience method that will add a displayName to _function if not present, by concatenating
  417. * _objectName and _propName with a '.', optionally appending _suffix after _propName.
  418. * @param {function} _function The function to add the displayName to.
  419. * @param {string} _objectName The name of the object, for example "MyClass.prototype"
  420. * @param {string} _propName The name of the property (the function is added as), for example "myMethod"
  421. * @param {string} [_suffix] Optional: part to append to the name, for example " [GET]" for a getter function
  422. * @memberof module:barejs.decl~
  423. * @private
  424. */
  425. function displayName( _function, _objectName, _propName, _suffix )
  426. {
  427. if ( canWriteFnName && !hasOwnProperty.call( _function, "name" ) )
  428. ObjectPolyfill.defineProperty( _function, "name", { configurable: true, value: _propName } );
  429. if ( !( "displayName" in _function ) )
  430. ObjectPolyfill.defineProperty( _function, "displayName", { configurable: true, value: _objectName + "." + _propName + ( _suffix || "" ) } );
  431. }
  432. /**
  433. * Utility method that returns _def expanded to a defineProperties argument.
  434. * Arguments that are a property definition are left alone, other are expanded to be a property definition
  435. * @param {object} _def The object whose properties to expand.
  436. * @param {function} _callback Function to use for the expand operation.
  437. * @param {string} [_objName] Optional: the logical name of _def, e.g. "MyClass.prototype"
  438. * @returns {object} _def made suitable for Object.defineProperties (or second argument of Object.create).
  439. * @memberof module:barejs.decl~
  440. * @private
  441. */
  442. function expandDefineProperties( _def, _lookup, _callback, _objName )
  443. {
  444. if ( _def )
  445. {
  446. // Ensure object
  447. _def = Object( _def );
  448. for ( var names = Object.keys( _def ), i = 0, len = names.length, name, prop, sym; i < len; ++i )
  449. {
  450. name = names[i];
  451. sym = reSymbolProto.exec( name );
  452. if ( sym )
  453. {
  454. //jshint -W122
  455. // The regexp matches one of two possible forms ("@@symbolName" or "[[symbolName]]"),
  456. // which means the symbol name may be in either capture group
  457. sym = Symbol[ sym[1] || sym[2] ];
  458. if ( typeof sym !== "symbol" )
  459. {
  460. delete _def[name];
  461. continue;
  462. }
  463. //jshint +W122
  464. }
  465. prop = _callback( _def[name], sym || name, _def, _lookup );
  466. if ( sym )
  467. {
  468. delete _def[name];
  469. _def[sym] = prop;
  470. }
  471. else if ( _def[name] !== prop )
  472. {
  473. // on rare occasions we may need to drop a property, e.g. when there is no getter/setter support.
  474. if ( prop === null )
  475. delete _def[name];
  476. else
  477. _def[name] = prop;
  478. }
  479. if ( prop && _objName )
  480. {
  481. if ( "value" in prop )
  482. {
  483. if ( ObjectPolyfill.isCallable( prop.value ) )
  484. displayName( prop.value, _objName, name );
  485. }
  486. else
  487. {
  488. if ( prop.get && !prop.getterName )
  489. displayName( prop.get, _objName, name, " [GET]" );
  490. if ( prop.set && !prop.setterName )
  491. displayName( prop.set, _objName, name, " [SET]" );
  492. }
  493. }
  494. }
  495. }
  496. return _def;
  497. }
  498. /**
  499. * Tells the proxy system casting to this type is not allowed. Should only be used for very low
  500. * level classes, otherwise performance will be impacted.
  501. * @param {function} _class The type to disallow casting to
  502. * @returns {Symbol} Key to cast to this type. NEVER export this key in any way.
  503. * @memberof module:barejs.decl
  504. */
  505. function preventCast( _class ){
  506. if ( typeof _class !== "function" )
  507. throw new TypeError( "_class must be a function" );
  508. if ( uncastable_types.has( _class ) )
  509. throw new Error( "Already declared uncastable" );
  510. // Register uncastable, generate key and store it at the correct index
  511. // Symbol is meant to make a "private key", so it seems suitable enough to use as a key for preventCast.
  512. var key = Symbol( _class.name );
  513. uncastable_types.add( _class );
  514. uncastable_keys.set( key, _class );
  515. return key;
  516. }
  517. // Allow decl to cast back without knowing the right type
  518. // NOTE: This value should never be exported
  519. var ObjectKey = preventCast( Object );
  520. /**
  521. * Method that sets up inheritance. Doesn't perform any validation, this should be done beforehand.
  522. * @param {function} _class Class to set up the inheritance for
  523. * @param {function} _base The class to derive from.
  524. * @returns {function} Class, now deriving from _base
  525. * @memberof module:barejs.decl~
  526. * @private
  527. */
  528. function derive( _class, _base, _proto )
  529. {
  530. // Apply prototype inheritance
  531. _class.prototype = Object.create( _base.prototype, _proto || undefined );
  532. // Reset the constructor (non enumerable, but writable, just like browsers set it).
  533. ObjectPolyfill.defineProperty( _class.prototype, "constructor", { writable : true, value : _class } );
  534. // Set superclass on constructor function
  535. // Note: decl methods should not rely too much on superclass being set, it's for convenience only
  536. return ObjectPolyfill.defineProperty( _class, "superclass", { value : _base } );
  537. }
  538. //
  539. // Helper classes for metadata
  540. //
  541. /**
  542. * @classdesc Base class to gather information about a member of an interface.
  543. * @class module:barejs.decl~InterfaceMember
  544. * @param {function[]} _interfaces The interface(s) on which the method is defined.
  545. * @param {string} _name The name of the method on the interface.
  546. * @private
  547. */
  548. function InterfaceMember( _interfaces, _name )
  549. {
  550. this.interfaces = _interfaces;
  551. this.name = _name;
  552. }
  553. derive( InterfaceMember, Object,
  554. /** @lends module:barejs.decl~InterfaceMember */
  555. {
  556. type: { value: "member" },
  557. /**
  558. * Provides a string representation of the member, for example "member myFunction on interface IMyInterface".
  559. * @returns {string} The string representation of the member
  560. */
  561. toString: { value: function toString()
  562. {
  563. return this.type + " \"" + String( this.name ) + "\" defined on " + this.interfaces.map( describe ).join( ", " );
  564. } }
  565. } );
  566. /**
  567. * @classdesc Stores information about a method on an interface.
  568. * @class module:barejs.decl~InterfaceMethod
  569. * @param {function} _interface The interface on which the method is defined.
  570. * @param {string} _name The name of the method on the interface.
  571. * @private
  572. */
  573. function InterfaceMethod( _interface, _name )
  574. {
  575. InterfaceMember.call( this, [_interface], _name );
  576. }
  577. derive( InterfaceMethod, InterfaceMember,
  578. /** @lends module:barejs.decl~InterfaceMethod */
  579. {
  580. type: { value: "function" }
  581. } );
  582. /**
  583. * @classdesc Stores information about a property on an interface
  584. * @class module:barejs.decl~InterfaceProperty
  585. * @param {function[]} _interfaces The interfaces on which the property is defined.
  586. * @param {string} _name The name of the property on the interface.
  587. * @param {boolean} _allowGet Whether getting this property is allowed.
  588. * @param {boolean} _allowSet Whether setting this property is allowed.
  589. * @private
  590. */
  591. function InterfaceProperty( _interfaces, _name, _allowGet, _allowSet )
  592. {
  593. InterfaceMember.call( this, _interfaces, _name );
  594. this.allowGet = _allowGet;
  595. this.allowSet = _allowSet;
  596. }
  597. derive( InterfaceProperty, InterfaceMember,
  598. /** @lends module:barejs.decl~InterfaceProperty */
  599. {
  600. type: { value: "property" },
  601. /**
  602. * Merge two definitions into a new InterfaceProperty. Used to resolve collisions between interfaces
  603. * @param {module:barejs.decl~InterfaceProperty} _otherProperty The property to merge with.
  604. * @returns {module:barejs.decl~InterfaceProperty} The merged InterfaceProperty. Might be the original, if the interfaces was already known.
  605. */
  606. merge: { value: function( _otherProperty )
  607. {
  608. if ( _otherProperty === this ) // sanity
  609. return this;
  610. // merge interfaces arrays
  611. for ( var interfaces = this.interfaces.slice( 0 ), i = 0, len = _otherProperty.interfaces.length, iface; i < len; ++i )
  612. {
  613. if ( interfaces.indexOf( iface = _otherProperty.interfaces[i] ) )
  614. interfaces.push( iface );
  615. }
  616. return new InterfaceProperty( interfaces, this.name, this.allowGet || _otherProperty.allowGet, this.allowSet || _otherProperty.allowSet );
  617. } }
  618. } );
  619. /**
  620. * Stores metadata about members of this interface, members of base interfaces and the combined list.
  621. * This allows methods like hasInterface and proxy to quickly iterate over the list of members.
  622. * @class module:barejs.decl~InterfaceMetaData
  623. * @memberof module:barejs.decl~
  624. * @private
  625. */
  626. function InterfaceMetaData()
  627. {
  628. this.directMembers = [];
  629. this.inheritedMembers = [];
  630. this.members = null;
  631. }
  632. /**
  633. * merge directMembers and inheritedMembers into one
  634. */
  635. InterfaceMetaData.prototype.merge = function()
  636. {
  637. var mergeMap;
  638. var i, len, member;
  639. if ( this.members )
  640. return;
  641. if ( this.inheritedMembers.length < 1 )
  642. {
  643. this.members = this.directMembers;
  644. }
  645. else if ( this.directMembers.length < 1 )
  646. {
  647. this.members = this.inheritedMembers;
  648. }
  649. else
  650. {
  651. mergeMap = Object.create( null );
  652. // Start by copying the directMembers
  653. this.members = this.directMembers.slice( 0 );
  654. // Then iterate them to initialize the merge map
  655. for ( i = 0, len = this.members.length; i < len; ++i )
  656. mergeMap[this.members[i].name] = true;
  657. // Next, iterate inherited members
  658. for ( i = 0, len = this.inheritedMembers.length; i < len; ++i )
  659. {
  660. // No point in updating the merge map, this is the last iteration of the merge
  661. // Only add the member if it wasn't redefined
  662. if ( mergeMap[(member = this.inheritedMembers[i]).name] !== true )
  663. this.members.push( member );
  664. }
  665. this.members.sort( function( _a, _b )
  666. {
  667. if ( _a.name === _b.name )
  668. return 0;
  669. var ta = typeof _a.name;
  670. return ( ta === typeof _b.name ) && ( ta === "string" ) && ( _a.name > _b.name ) ? 1 : -1;
  671. } );
  672. }
  673. };
  674. /**
  675. * Build meta data for an interface, like the list of all methods required by the interface.
  676. */
  677. InterfaceMetaData.get = function( _interface )
  678. {
  679. if ( !isInterface( _interface ) )
  680. throw new TypeError( "_interface is not an Interface" );
  681. var meta = metaData.get( _interface );
  682. if ( !meta )
  683. {
  684. metaData.set( _interface, meta = new InterfaceMetaData() );
  685. var mergeMap = Object.create( null );
  686. // Merge inherited members
  687. if ( _interface.interfaces )
  688. {
  689. _interface.interfaces.forEach( function( _extendedInterface )
  690. {
  691. var members = InterfaceMetaData.get( _extendedInterface ).members, member, existing;
  692. for ( var i = 0, len = members.length; i < len; ++i )
  693. {
  694. member = members[i];
  695. if ( ( existing = mergeMap[member.name] ) && ( existing !== member ) )
  696. {
  697. // See if we need to do property merge magic
  698. if ( ( existing.type === "property" ) && ( member.type === "property" ) )
  699. {
  700. meta.inheritedMembers[meta.inheritedMembers.indexOf( existing )] =
  701. mergeMap[member.name] = existing.merge( member );
  702. }
  703. else
  704. {
  705. // Report the conflict
  706. throw new Error( describe( _interface ) + " has a conflict in extended interfaces: The " + existing + " conflicts with " + member + "." );
  707. }
  708. }
  709. else
  710. {
  711. mergeMap[member.name] = member;
  712. meta.inheritedMembers.push( member );
  713. }
  714. }
  715. } );
  716. }
  717. // Add direct members (freeze prototype too, to protect it from modification after metadata is built).
  718. for ( var names = Object.keys( ObjectPolyfill.freeze( _interface.prototype ) ).concat( ObjectPolyfill.getOwnPropertySymbols( _interface.prototype ) ), i = 0, len = names.length; i < len; ++i )
  719. {
  720. var name = names[i], target = _interface.prototype[name];
  721. // Protect proxy features from colliding with the interface.
  722. if ( ( name === "as" ) || ( name === "is" ) )
  723. throw new Error( "The " + ( new InterfaceMember( [_interface], name ) ) + " uses the reserved name \"" + name + "\", which is not allowed." );
  724. // Explicitly ignore the constructor property for Rhino
  725. if ( name === "constructor" )
  726. continue;
  727. var member = null, existing = mergeMap[name];
  728. // First, just create the metadata (not adding it)
  729. switch ( target && typeof target )
  730. {
  731. case "function":
  732. member = new InterfaceMethod( _interface, name );
  733. break;
  734. case "object":
  735. if ( ( "allowGet" in target ) || ( "allowSet" in target ) )
  736. {
  737. member = new InterfaceProperty( [_interface], name, target.allowGet === true, target.allowSet === true );
  738. if ( !( member.allowGet || member.allowSet ) )
  739. throw new Error( "The " + member + " is invalid: it doesn't allow get or set." );
  740. }
  741. break;
  742. }
  743. if ( !member )
  744. {
  745. throw new Error(
  746. "The " + ( new InterfaceMember( [_interface], name ) ) + " is invalid: expected a function, " +
  747. "or an object with allowGet or allowSet property, but got " + ( typeof target ) + target + " instead."
  748. );
  749. }
  750. // Override or report conflict
  751. if ( existing )
  752. {
  753. // Interfaces are allowed to redefine properties with more access (i.e. readWrite over read).
  754. // They are not allowed to revoke access or redefine a property with similar access
  755. if ( ( member.type === "property" ) && ( existing.type === "property" ) )
  756. {
  757. // Test if the interface is removing access
  758. if ( existing.allowGet && !member.allowGet )
  759. throw new Error( "The " + member + " has a conflict with " + existing + ": it is removing get access." );
  760. if ( existing.allowSet && !member.allowSet )
  761. throw new Error( "The " + member + " has a conflict with " + existing + ": it is removing set access." );
  762. if ( ( existing.allowGet === member.allowGet ) && ( existing.allowSet === member.allowSet ) )
  763. throw new Error( "The " + member + " is redefining " + existing + " with equal get/set access (so it is obsolete)." );
  764. }
  765. else
  766. {
  767. throw new Error( "The " + member + " conflicts with " + existing + "." );
  768. }
  769. }
  770. meta.directMembers.push( member );
  771. }
  772. meta.merge();
  773. }
  774. return meta;
  775. };
  776. /**
  777. * Stores metadata about names and values on an enum.
  778. * This allows for quick reverse lookup
  779. * @class module:barejs.decl~EnumMetaData
  780. * @private
  781. */
  782. function EnumMetaData( _enum )
  783. {
  784. this.names = ObjectPolyfill.freeze( Object.keys( _enum ) );
  785. // Use _get to resolve the enum property value
  786. this.values = ObjectPolyfill.freeze( this.names.map( _get, _enum ) );
  787. }
  788. /**
  789. * Perform a case insensitive name lookup for an enum
  790. * @param {module:barejs.decl~Enum} _enum The enum to look up the name for
  791. * @param {string} _name The name to match
  792. * @returns {string} the found name, or null if not found.
  793. */
  794. EnumMetaData.prototype.ciName = function( _name )
  795. {
  796. var nameLower = String( _name ).toLowerCase();
  797. for ( var i = this.names.length - 1; i >= 0; --i )
  798. {
  799. if ( nameLower === this.names[i].toLowerCase() )
  800. return this.names[i];
  801. }
  802. return null;
  803. };
  804. /**
  805. * Retrieve metadata for an enum
  806. */
  807. EnumMetaData.get = function( _enum )
  808. {
  809. var meta = metaData.get( _enum.constructor );
  810. if ( !meta )
  811. metaData.set( _enum.constructor, meta = new EnumMetaData( _enum ) );
  812. return meta;
  813. };
  814. //
  815. // Helper classes
  816. //
  817. function NullObject() {}
  818. NullObject.prototype = null;
  819. /**
  820. * Internal class for decl, serving as a base class for {@link module:barejs.decl~Interface Interface} and {@link module:barejs.decl~Enum Enum}.
  821. * Does not have Object.prototype in its prototype chain, so objects deriving from SpecialType are not instanceof Object.
  822. * @class module:barejs.decl~SpecialType
  823. */
  824. function SpecialType() {}
  825. derive( SpecialType, NullObject,
  826. /** @lends module:barejs.decl~SpecialType# */
  827. {
  828. // JSHint complains hasOwnProperty is a really bad name, but we are simply "restoring" it on a special type.
  829. // jshint -W001
  830. /**
  831. * A SpecialType is not instanceof Object, but does have the Object.prototype.hasOwnProperty method.
  832. * @function
  833. * @param {string} _name The name of the property to check
  834. * @returns {boolean} True if the object has a direct property with _name, false otherwise.
  835. */
  836. hasOwnProperty: { value: hasOwnProperty }
  837. // jshint +W001
  838. } );
  839. /**
  840. * Base class for interfaces
  841. * @class module:barejs.decl~Interface
  842. * @extends module:barejs.decl~SpecialType
  843. */
  844. function Interface() {}
  845. // Make Interface a "special type" (new Interface() instanceof Object === false)
  846. derive( Interface, SpecialType,
  847. /** @lends module:barejs.decl~Interface# */
  848. {
  849. /**
  850. * toString for Interface.
  851. * @function
  852. * @returns {string} The string [interface InterfaceName], where InterfaceName is
  853. * the name of the interface constructor function, or "Interface" for anonymous interfaces.
  854. */
  855. toString: { value: function toString()
  856. {
  857. return "[interface " + ( this.constructor.name || "Interface" ) + "]";
  858. } }
  859. } );
  860. /**
  861. * Base class for Enum types declared with {@link module:barejs.decl#declareEnum decl.declareEnum}
  862. * @class module:barejs.decl~Enum
  863. * @extends module:barejs.decl~SpecialType
  864. */
  865. function Enum() {}
  866. // Make Enum a "special type" (new Enum() instanceof Object === false)
  867. derive( Enum, SpecialType,
  868. /** @lends module:barejs.decl~Enum# */
  869. {
  870. // Allow subclasses to redefine these methods (so make them writable)
  871. /**
  872. * Enum method: get the name of the specified value. If multiple names lead to the same value, the
  873. * first found name is returned
  874. * @function
  875. * @param {string} _value The value for which to get the name
  876. * @returns The name of the value, or null if not found
  877. */
  878. nameOf:
  879. {
  880. writable: true,
  881. value: function nameOf( _value )
  882. {
  883. var meta = EnumMetaData.get( this );
  884. return meta.names[meta.values.indexOf( _value )] || null;
  885. }
  886. },
  887. /**
  888. * Enum method: get the value of the specified name
  889. * @function
  890. * @param {string} _name The name of the value to get
  891. * @param {boolean} [_caseInsensitive=false] Optional, set to true to perform a case insensitive search
  892. * @returns {object} The enum value, or null if it wasn't found.
  893. */
  894. valueOf:
  895. {
  896. writable: true,
  897. value: function valueOf( _name, _caseInsensitive )
  898. {
  899. // Case sensitive or insensitive, see if the name is defined.
  900. if ( this.hasOwnProperty( _name ) )
  901. return this[_name];
  902. // If we're not case insensitive, we're not going to find the value
  903. if ( _caseInsensitive !== true )
  904. return null;
  905. // Do a case insensitive lookup
  906. _name = EnumMetaData.get( this ).ciName( _name );
  907. // ciName will return null if the name didn't match any entry
  908. return _name && this[_name];
  909. }
  910. },
  911. /**
  912. * Enum method: check if the enum has the specified name
  913. * @function
  914. * @param {string} _name The name to check
  915. * @param {boolean} [_caseInsensitive=false] Optional, set to true to perform a case insensitive search
  916. * @returns {boolean} True if the enum has the name, false otherwise.
  917. */
  918. hasName:
  919. {
  920. writable: true,
  921. value: function hasName( _name, _caseInsensitive )
  922. {
  923. // Always check hasOwnProperty first, to avoid the array lookup of case insensitive.
  924. return this.hasOwnProperty( _name ) || ( ( _caseInsensitive === true ) && ( EnumMetaData.get( this ).ciName( _name ) !== null ) );
  925. }
  926. },
  927. /**
  928. * Check if the enum has the specified value
  929. * @function
  930. * @param {object} _value The enum value to check for
  931. * @returns {boolean} True if the enum has the value, false otherwise.
  932. */
  933. hasValue:
  934. {
  935. writable: true,
  936. value: function hasValue( _value )
  937. {
  938. return EnumMetaData.get( this ).values.indexOf( _value ) >= 0;
  939. }
  940. },
  941. /**
  942. * Utility method to parse an enum value, for example from input parsed from JSON.
  943. * Takes the following steps:
  944. *
  945. * 1. if _value is an actual enum value, return _value.
  946. * 2. if _value is a name of enum, return the value of that name
  947. * 3. if _throw is true, throw a RangeError
  948. * 4. return null
  949. *
  950. * @function
  951. * @param _value The value to parse
  952. * @param {boolean} _caseInsensitive Whether name matching should be case insensitive.
  953. * Defaults to false, specify true for case insensitive.
  954. * @param {boolean} [_throw=false] Optional: set to true to perform strict validation.
  955. * @returns The parsed value, or null if the value didn't parse.
  956. */
  957. parse:
  958. {
  959. writable: true,
  960. value: function parse( _value, _caseInsensitive, _throw )
  961. {
  962. var enumMeta = EnumMetaData.get( this );
  963. if ( enumMeta.values.indexOf( _value ) >= 0 )
  964. return _value;
  965. // After this point, _value is considered to be a potential name
  966. var name = _value;
  967. // Perform case insensitive lookup if needed
  968. if ( !this.hasOwnProperty( name ) && ( _caseInsensitive === true ) )
  969. name = EnumMetaData.get( this ).ciName( name );
  970. if ( name && this.hasOwnProperty( name ) )
  971. return this[name];
  972. if ( _throw === true )
  973. throw new RangeError( "Could not parse enum value " + _value );
  974. return null;
  975. }
  976. },
  977. /**
  978. * Get the names of an enum
  979. * @function
  980. * @returns {Array} The names of an enum
  981. */
  982. names:
  983. {
  984. writable: true,
  985. value: function names()
  986. {
  987. return EnumMetaData.get( this ).names;
  988. }
  989. },
  990. /**
  991. * Get the values of an enum
  992. * @function
  993. * @returns {Array} The values of an enum
  994. */
  995. values:
  996. {
  997. writable: true,
  998. value: function values()
  999. {
  1000. return EnumMetaData.get( this ).values;
  1001. }
  1002. },
  1003. /**
  1004. * Iterate over all enum name/value pairs. Signature attempts to match Array.prototype.forEach.
  1005. * @function
  1006. * @param {function} _callback The callback, called with _value, _name, _enum
  1007. * @param {object} [_thisArg] Optional: the scope to call the callback in.
  1008. */
  1009. forEach:
  1010. {
  1011. writable: true,
  1012. value: function forEach( _callback/*, _thisArg*/ )
  1013. {
  1014. for ( var meta = EnumMetaData.get( this ), idx = 0, len = meta.names.length, thisArg = ( arguments[1] || null ) && Object( arguments[1] ); idx < len; ++idx )
  1015. _callback.call( thisArg, meta.values[idx], meta.names[idx], this );
  1016. }
  1017. },
  1018. /**
  1019. * toString for Enum.
  1020. * @function
  1021. * @returns {string} The string [enum EnumName], where EnumName is
  1022. * the name of the enum constructor function, or "Enum" for anonymous enumerations.
  1023. */
  1024. toString: { value: function toString()
  1025. {
  1026. return "[enum " + ( this.constructor.name || "Enum" ) + "]";
  1027. } }
  1028. } );
  1029. // These methods are added to a declareClass prototype
  1030. var classProtoExtension =
  1031. {
  1032. /**
  1033. * To be executed in the context of an object.
  1034. * Allow "casting" between interface proxies and the original object.
  1035. * @param {function} _class The type (constructor function) to cast to.
  1036. * @param {boolean} [_strict=false] Optional: set to true to avoid a duck-type check, and only check `decl`
  1037. * metadata for interfaces implemented.
  1038. * @returns {object} A proxy, the original object, or null if the "cast" could not be performed.
  1039. */
  1040. as: { value : function as( _class, _strict )
  1041. {
  1042. // jshint validthis:true
  1043. // Give ObjectKey special treatment, making it a "master key", allowing to cast back objects
  1044. // that are not even instanceof Object.
  1045. if ( _class === ObjectKey )
  1046. return this;
  1047. // _class is supposed to be either a constructor function or a proxy key
  1048. if ( typeof _class !== "function" )
  1049. {
  1050. // Allow casting back by key (Symbol, handed out by preventCast).
  1051. var type = uncastable_keys.get( _class );
  1052. if ( type )
  1053. return this instanceof type ? this : null;
  1054. throw new TypeError( "as requires _class to be a (constructor) function" );
  1055. }
  1056. else if ( uncastable_types.has( _class ) )
  1057. {
  1058. throw new Error( "as does not allow casting to this type, specify a more specific type" );
  1059. }
  1060. // If we get here, _class is a function
  1061. if ( isInterface( _class ) && hasInterface( this, _class, _strict ) )
  1062. return proxy( this, _class );
  1063. else if ( this instanceof _class )
  1064. return this;
  1065. // Type change failed
  1066. return null;
  1067. } },
  1068. /**
  1069. * To be executed in the context of an object.
  1070. * Allow checking if an object adheres to a specific type, or equals an instance.
  1071. * @param {function} _other (Type|Interface) to test for, OR {object} (Instance) to check equality against
  1072. * @param {boolean} [_strict=false] Optional: if _other is an Interface, set to true to avoid a duck-type
  1073. * check, and only check `decl` metadata for interfaces implemented.
  1074. * If `_other` is not an Interface, this param is ignored.
  1075. * @returns {boolean} True if this object adheres to the type, or equals the _other instance. False otherwise.
  1076. */
  1077. is: { value: function is( _other, _strict )
  1078. {
  1079. // jshint validthis:true
  1080. if ( typeof _other === "function" )
  1081. return ( this instanceof _other ) || ( ( isInterface( _other ) && hasInterface( this, _other, _strict ) ) );
  1082. else if ( isProxy( _other ) )
  1083. return this === _other.as( ObjectKey );
  1084. else
  1085. return this === _other;
  1086. } }
  1087. };
  1088. //
  1089. // Helper methods
  1090. //
  1091. /**
  1092. * Attempts to discover an object's base class.
  1093. * @param {function} _class Class constructor function
  1094. * @returns {function} The bas constructor, defaults to Object if the base cannot be determined.
  1095. * @memberof module:barejs.decl~
  1096. * @private
  1097. */
  1098. function getBase( _class )
  1099. {
  1100. var proto = null;
  1101. if ( typeof _class === "function" )
  1102. {
  1103. proto = ObjectPolyfill.getPrototypeOf( _class.prototype );
  1104. proto = proto && proto.constructor ? proto.constructor : Object;
  1105. }
  1106. return proto;
  1107. }
  1108. /**
  1109. * Get the type of _target.
  1110. * This is typeof enhanced.
  1111. * @param _target The thing to get the type of.
  1112. * @memberof module:barejs.decl~
  1113. * @private
  1114. */
  1115. function type( _target )
  1116. {
  1117. var t = _target === null ? "null" : typeof _target;
  1118. if ( t === "function" )
  1119. {
  1120. if ( _target.prototype instanceof Interface )
  1121. t = "interface";
  1122. else if ( _target.prototype instanceof Enum )
  1123. t = "enum";
  1124. else if ( !( "prototype" in _target ) )
  1125. t = "native function";
  1126. else if ( "superclass" in _target )
  1127. t = "class";
  1128. }
  1129. else if ( t === "object" )
  1130. {
  1131. if ( Array.isArray( _target ) )
  1132. return "array";
  1133. else if ( _target instanceof Enum )
  1134. t = "enum";
  1135. else if ( _target instanceof Interface )
  1136. t = "proxy";
  1137. }
  1138. return t;
  1139. }
  1140. /**
  1141. * Helper method that tries to get the name of a class.
  1142. * @param {function|Object} _target The object to get the name of
  1143. * @returns {string} The name of target, or null
  1144. * @memberof module:barejs.decl~
  1145. * @private
  1146. */
  1147. function name( _target )
  1148. {
  1149. if ( !_target )
  1150. return null;
  1151. else if ( typeof _target === "function" )
  1152. return _target.name || null;
  1153. else if ( _target.constructor )
  1154. return _target.constructor.name || null;
  1155. return null;
  1156. }
  1157. /**
  1158. * Helper method that tries to build a description of an object. It gets the right type description
  1159. * using type, and tries to append the name to it. The name is only available in environments that
  1160. * support the name property on functions, and of course the function must be named.
  1161. * Example: describe( SampleClass );
  1162. * If SampleClass is a named function this might return "class SampleClass".
  1163. * Otherwise, it will return "class (Anonymous)".
  1164. * @param {function} _fn The function to describe.
  1165. * @memberof module:barejs.decl~
  1166. * @private
  1167. */
  1168. function describe( _target )
  1169. {
  1170. var n = name( _target );
  1171. return n ? type( _target ) + " " + n : type( _target );
  1172. }
  1173. /**
  1174. * Check if the prototype object is clean (has no properties defined).
  1175. * @param {function} _class The constructor function whose prototype object to check.
  1176. * @param {string} [_requester] Optional: name of the function requesting the check
  1177. * @memberof module:barejs.decl~
  1178. * @private
  1179. */
  1180. function checkCleanPrototype( _class, _requester )
  1181. {
  1182. var props = Object.keys( _class.prototype ),
  1183. idx = props.indexOf( "constructor" );
  1184. if ( idx >= 0 )
  1185. props.splice( idx, 1 );
  1186. if ( props.length > 0 )
  1187. {
  1188. throw new Error(
  1189. ( _requester ? _requester + ": " : "" ) + describe( _class ) + " already has properties defined on the prototype: " +
  1190. props.join( ", " )
  1191. );
  1192. }
  1193. }
  1194. /**
  1195. * Port "static" functions over from the base class.
  1196. * @param {function} _class The constructor function to update with base class static functions.
  1197. * @param {function} _base The base constructor to copy static functions of.
  1198. * @memberof module:barejs.decl~
  1199. * @private
  1200. */
  1201. function applyStatic( _class, _base, _stat )
  1202. {
  1203. if ( _base && ( native_ctors.indexOf( _base ) < 0 ) )
  1204. {
  1205. var descriptors = ObjectPolyfill.getOwnPropertyDescriptors( _base );
  1206. var staticInherited;
  1207. var keys = Object.keys( descriptors );
  1208. for ( var i = 0, len = keys.length; i < len; ++i )
  1209. {
  1210. var key = keys[i];
  1211. // Ignore keys that match reStaticIgnore,
  1212. if ( ( typeof key !== "string" || !reStaticIgnore.test( key ) ) &&
  1213. // or keys that are already on _class or _stat,
  1214. ( !hasOwnProperty.call( _class, key ) && !( _stat && hasOwnProperty.call( _stat, key ) ) ) &&
  1215. // or keys that are explicitly ignored using a $private function
  1216. !( _base.$private && _base.$private( key ) ) )
  1217. {
  1218. var def = descriptors[key];
  1219. if ( "value" in def && typeof def.value !== "function" && def.writable && ObjectPolyfill.propertyGetSetSupport )
  1220. {
  1221. // Upgrade def to a get/set proxy
  1222. def =
  1223. {
  1224. configurable: def.configurable,
  1225. enumerable: def.enumerable,
  1226. "get": _get.bind( _base, key ),
  1227. "set": _set.bind( _base, key )
  1228. };
  1229. }
  1230. // Make sure the definition is always configurable, as we're "inheriting"
  1231. def.configurable = true;
  1232. if ( !staticInherited )
  1233. staticInherited = {};
  1234. staticInherited[key] = def;
  1235. }
  1236. }
  1237. if ( staticInherited )
  1238. defineObject( _class, staticInherited );
  1239. }
  1240. if ( _stat )
  1241. defineObject( _class, _stat );
  1242. }
  1243. /**
  1244. * Helper function that sets the interfaces for a class and validates they are actually interfaces.
  1245. * This method does not perform any validation on _class or its state.
  1246. * @param {function} _class The class constructor
  1247. * @param {Array} _interfaces The list of interfaces.
  1248. * @param {Array} _baseInterfaces The list of interfaces on the base class.
  1249. * @memberof module:barejs.decl~
  1250. * @private
  1251. */
  1252. function setInterfaces( _class, _interfaces, _baseInterfaces )
  1253. {
  1254. var interfaces = ( _baseInterfaces && _baseInterfaces.slice( 0 ) ) || [];
  1255. if ( _interfaces && _interfaces.length )
  1256. {
  1257. // Validate the interfaces specified are indeed interfaces.
  1258. for ( var idx = 0, len = _interfaces.length; idx < len; ++idx )
  1259. {
  1260. // An interface should derive DIRECTLY from Interface.
  1261. if ( getBase( _interfaces[idx] ) !== Interface )
  1262. throw new Error( "Interface " + idx + " is not a valid interface." );
  1263. if ( interfaces.indexOf( _interfaces[idx] ) < 0 )
  1264. interfaces.push( _interfaces[idx] );
  1265. else if ( !(false) && ( typeof console !== "undefined" ) )
  1266. console.info( describe( _class ) + " declares to implement " + describe( _interfaces[idx] ) + " also implemented by a base class." );
  1267. }
  1268. }
  1269. // Freeze the interfaces array for security
  1270. ObjectPolyfill.defineProperty( _class, "interfaces", { value : ObjectPolyfill.freeze( interfaces ) } );
  1271. }
  1272. /**
  1273. * See if _interface matches _searchInterface. This includes looking at extended interfaces.
  1274. * @param {function} _interface The interface to check
  1275. * @param {function} _searchInterface The interface to look for in _interface's tree.
  1276. * @returns {boolean} True if the interface matches, false otherwise
  1277. */
  1278. function matchInterface( _interface, _searchInterface )
  1279. {
  1280. if ( _interface === _searchInterface )
  1281. return true;
  1282. if ( _interface.interfaces )
  1283. {
  1284. for ( var idx = 0, len = _interface.interfaces.length; idx < len; ++idx )
  1285. {
  1286. if ( matchInterface( _interface.interfaces[idx], _searchInterface ) )
  1287. return true;
  1288. }
  1289. }
  1290. return false;
  1291. }
  1292. /**
  1293. * Wrapper for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is Object.is} that will "unproxy" values.
  1294. *
  1295. * // This returns false, Object.is sees two different objects:
  1296. * Object.is( instance, instance.as( MyInterface );
  1297. *
  1298. * // This returns true, decl will unproxy proxies.
  1299. * decl.is( instance, instance.as( MyInterface ) );
  1300. *
  1301. * @param _a Any value to check for equality
  1302. * @param _b Any value to check for equality
  1303. * @returns {boolean} True if the values are considered equal, false otherwise.
  1304. * @memberof module:barejs.decl
  1305. */
  1306. function is( _a, _b )
  1307. {
  1308. return Object.is(
  1309. isProxy( _a ) ? _a.as( ObjectKey ) : _a,
  1310. isProxy( _b ) ? _b.as( ObjectKey ) : _b
  1311. );
  1312. }
  1313. /**
  1314. * Check if the _target is an interface.
  1315. * Only works with class constructors, since there should be no instance of an interface.
  1316. * @param {function} _target The class constructor to test if it is an interface.
  1317. * @returns {boolean} True if _target is an interface, false otherwise.
  1318. * @memberof module:barejs.decl
  1319. */
  1320. function isInterface( _target )
  1321. {
  1322. return ( typeof _target === "function" ) && ( _target.prototype instanceof Interface );
  1323. }
  1324. /**
  1325. * Check if the _target is an enum.
  1326. * Only works with instances, since enums should not expose their class constructor directly.
  1327. * @param {object} _target The instance to test if it is an enum.
  1328. * @returns {boolean} True if _target is an enum, false otherwise.
  1329. * @memberof module:barejs.decl
  1330. */
  1331. function isEnum( _target )
  1332. {
  1333. // Enums should always be an instance
  1334. return _target instanceof Enum;
  1335. }
  1336. /**
  1337. * Check if the target is a proxy object.
  1338. * @param {object} _target The object to check.
  1339. * @returns {boolean} True if _target is a proxy object, false otherwise.
  1340. * @memberof module:barejs.decl
  1341. */
  1342. function isProxy( _target )
  1343. {
  1344. // _target must be an object, instanceof Interface, having an "as" method directly on the object (the "is" method is not tested)
  1345. return ( _target instanceof Interface ) && _target.hasOwnProperty( "as" );
  1346. }
  1347. /**
  1348. * Checks if _class has _base as a superclass. Also true if _class === _base.
  1349. * Do not use this method to check if an Object is of a specific type, use the instanceof operator
  1350. * for that instead.
  1351. * @param {function} _class The function to check.
  1352. * @param {function} _base The base class to check for.
  1353. * @returns {boolean} True if the class has the base class, false otherwise.
  1354. * @memberof module:barejs.decl
  1355. */
  1356. function hasBase( _class, _base )
  1357. {
  1358. if ( typeof _class !== "function" )
  1359. throw new TypeError( "_class is not a (constructor) function" );
  1360. if ( typeof _base !== "function" )
  1361. throw new TypeError( "_base is not a (constructor) function" );
  1362. return ( _class === _base ) || ( _class.prototype instanceof _base );
  1363. }
  1364. /**
  1365. * Create and return a proxy object for the target
  1366. * @param {object} _target The object to proxy
  1367. * @param {function} _interface The interface defining the members to proxy.
  1368. * @returns {object} The proxy object (instanceof _interface).
  1369. * @memberof module:barejs.decl
  1370. */
  1371. function proxy( _target, _interface )
  1372. {
  1373. if ( !isInterface( _interface ) )
  1374. throw new TypeError( describe( _interface ) + " is not a valid Interface" );
  1375. if ( !_target )
  1376. throw new Error( "Cannot proxy " + describe( _target ) + " as " + describe( _interface ) );
  1377. // Don't proxy a proxy, instead attempt to proxy on the source object
  1378. if ( isProxy( _target ) )
  1379. return proxy( _target.as( ObjectKey ), _interface );
  1380. // Create the proxy object
  1381. var props =
  1382. {
  1383. // Adding the constructor shows proxy objects named as the interface in the debugger
  1384. // (provided the interface function is named)
  1385. constructor: { value : _interface },
  1386. // Add the as and is methods to the proxy, read-only and not enumerated
  1387. as: { value : classProtoExtension.as.value.bind( _target ) },
  1388. is: { value : classProtoExtension.is.value.bind( _target ) }
  1389. };
  1390. for ( var members = InterfaceMetaData.get( _interface ).members, idx = 0, len = members.length, member, prop; idx < len; ++idx )
  1391. {
  1392. switch ( ( member = members[idx] ).type )
  1393. {
  1394. case "function":
  1395. prop = _target[member.name];
  1396. if ( typeof prop !== "function" )
  1397. throw new Error( "as( " + describe( _interface ) + " ) expected " + member + " to be on " + describe( _target.constructor ) + ", but it is missing." );
  1398. // Make the function proxies read-only, enumerable
  1399. props[member.name] = { value : prop.bind( _target ), enumerable : true };
  1400. break;
  1401. case "property":
  1402. if ( !( member.name in _target ) )
  1403. throw new Error( "as( " + describe( _interface ) + " ) expected " + member + " to be on " + describe( _target.constructor ) + ", but it is missing." );
  1404. if ( ObjectPolyfill.propertyGetSetSupport )
  1405. {
  1406. prop = { enumerable: true };
  1407. if ( member.allowGet )
  1408. prop.get = _get.bind( _target, member.name );
  1409. if ( member.allowSet )
  1410. prop.set = _set.bind( _target, member.name );
  1411. // No point in checking for property support: we already checked that in the if above
  1412. props[member.name] = prop;
  1413. }
  1414. else if ( typeof console !== undefined )
  1415. {
  1416. console.warn( "interface proxy skipping " + member + ", since the environment doesn't support getters and setters." );
  1417. }
  1418. break;
  1419. }
  1420. }
  1421. // Attempt to seal the proxy; we don't need to freeze since no properties are configurable
  1422. return ObjectPolyfill.seal( Object.create( _interface.prototype, props ) );
  1423. }
  1424. /**
  1425. * Duck-type check for compliance with an interface
  1426. * @param {object} _target The object to validate
  1427. * @param {function} _interface The interface to check for
  1428. * @returns {boolean} True if the object seems to implement all members
  1429. * @memberof module:barejs.decl~
  1430. * @private
  1431. */
  1432. function duckHasInterface( _target, _interface )
  1433. {
  1434. var valid = !!_target;
  1435. if ( valid )
  1436. {
  1437. // Ensure object
  1438. _target = Object( _target );
  1439. for ( var m = InterfaceMetaData.get( _interface ).members, i = m.length - 1; valid && i >= 0; --i )
  1440. {
  1441. switch( m[i].type )
  1442. {
  1443. case "function":
  1444. valid = typeof _target[m[i].name] === "function";
  1445. break;
  1446. case "property":
  1447. valid = m[i].name in _target;
  1448. break;
  1449. }
  1450. }
  1451. }
  1452. return valid;
  1453. }
  1454. /**
  1455. * Checks if _target (or a base class) implements the specified Interface.
  1456. * Works on both instances and the class constructor.
  1457. * @param {object|Function} _target The object or class constructor to check.
  1458. * @param {function} _interface The interface to check for. If interface is not a valid interface,
  1459. * this method always returns false.
  1460. * @param {boolean} [_strict=false] Optional: set to true to avoid a duck-type check, and only check decl
  1461. * metadata for interfaces implemented.
  1462. * @returns {boolean} True if _target (or a base class) implements the interface, false otherwise.
  1463. * @memberof module:barejs.decl
  1464. */
  1465. function hasInterface( _target, _interface, _strict )
  1466. {
  1467. if ( !isInterface( _interface ) )
  1468. throw new TypeError( "hasInterface: _interface must be an interface defined with decl.declareInterface, but is " + describe( _interface ) );
  1469. if ( !_target )
  1470. return false;
  1471. // Detect proxies
  1472. if ( isProxy( _target ) )
  1473. return hasInterface( _target.as( ObjectKey ), _interface, _strict );
  1474. var isFn = typeof _target === "function";
  1475. // Walk up the inheritance tree
  1476. for ( var base = isFn ? _target : _target.constructor; base && ( base !== Object ) && ( base !== Interface ) && ( base !== Enum ); base = getBase( base ) )
  1477. {
  1478. if ( base.interfaces && matchInterface( base, _interface ) )
  1479. return true;
  1480. }
  1481. // Resort to duck-type check
  1482. return ( _strict !== true ) && duckHasInterface( isFn ? _target.prototype : _target, _interface );
  1483. }
  1484. //
  1485. // Start of Declare methods
  1486. //
  1487. /**
  1488. * Helper method that unifies errors returned by declare* methods.
  1489. * @param {string} _name The name of the function from which the error is triggered
  1490. * @param {Array} _arguments or (arguments object) of arguments
  1491. * @param {string} _message The custom part of the message
  1492. * @returns {string} The error message
  1493. * @memberof module:barejs.decl~
  1494. * @private
  1495. */
  1496. function formatErrorMessage( _name, _arguments, _message )
  1497. {
  1498. return _name + "( " + Array.prototype.map.call( _arguments, describe ).join( ", " ) + " ): " + _message;
  1499. }
  1500. /**
  1501. * Helper method that will validate the _class argument passed to declare(Class|Interface|Enum).
  1502. * Ensures consistent validation across methods.
  1503. * @param {function} _class The _class argument as received by the declare method.
  1504. * @param {string} _method The name of the method requesting the validation.
  1505. * @param {Array} _arguments The arguments passed to the requesting method.
  1506. * @memberof module:barejs.decl~
  1507. * @private
  1508. */
  1509. function validateClassArg( _class, _method, _arguments )
  1510. {
  1511. // Validation
  1512. if ( !_class || ( typeof _class !== "function" ) )
  1513. throw new TypeError( formatErrorMessage( _method, _arguments, "_class is not a function." ) );
  1514. // Some special methods don't have a prototype, warn when these are passed to declareClass
  1515. if ( !( "prototype" in _class ) )
  1516. throw new Error( formatErrorMessage( _method, _arguments, "_class doesn't have a prototype property; it is probably a built-in function." ) );
  1517. if ( ( "superclass" in _class ) || ( "interfaces" in _class ) )
  1518. throw new Error( formatErrorMessage( _method, _arguments, "The " + describe( _class ) + " is already declared, cannot perform " + _method + "." ) );
  1519. if ( native_ctors.indexOf( _class ) >= 0 )
  1520. throw new Error( formatErrorMessage( _method, _arguments, "Attempt to call " + _method + " on built-in type" + ( _class.name ? " " + _class.name + "." : "" ) ) );
  1521. // Note: this check can fail if the base prototype can not be detected. We still perform it as
  1522. // a convenience for detecting errors, and hope the check for existing properties on the
  1523. // prototype will catch the other cases.
  1524. var base = getBase( _class );
  1525. if ( base && ( base !== Object ) )
  1526. throw new Error( formatErrorMessage( _method, _arguments, "_class already has a base " + describe( base ) + "." ) );
  1527. // Throw an error if anything has been defined on the original prototype
  1528. checkCleanPrototype( _class, _method );
  1529. }
  1530. /**
  1531. * Helper method that will pop the last value of an array if it's not a function.
  1532. * If the last argument is a function, or the array is empty, the _array is not modified and null is returned.
  1533. * @param {Array} _array The array to pop the non-function from.
  1534. * @memberof module:barejs.decl~
  1535. * @private
  1536. */
  1537. function popNonFunction( _array )
  1538. {
  1539. var len = _array.length;
  1540. return ( len > 0 ) && ( typeof _array[len - 1] !== "function" ) ? Object( _array.pop() ) : null;
  1541. }
  1542. /**
  1543. * Helper method that perform the actual class definition for both abstractClass and declareClass.
  1544. * @param {String} _definingName The function that is requesting a class be made, e.g. abstractClass or declareClass.
  1545. * @param {arguments} _args The arguments passed along to the declare function.
  1546. * @param {Boolean} [_validate=false] Optional: whether interfaces should be validated for implementation.
  1547. * @memberof module:barejs.decl~
  1548. * @private
  1549. */
  1550. function makeClass( _definingName, _args, _validate )
  1551. {
  1552. // normalize optional interfaces and/or prototype properties
  1553. var cls = _args[0],
  1554. base = null,
  1555. interfaces = null,
  1556. stat = null,
  1557. proto = null;
  1558. /*istanbul ignore else: We always test in DEBUG*/
  1559. if ( true )
  1560. validateClassArg( cls, _definingName, _args );
  1561. if ( _args.length > 1 )
  1562. {
  1563. interfaces = slice.call( _args, 1, _args.length );
  1564. // If the first additional argument is null or a constructor function (not an interface), it is a base class.
  1565. if ( ( interfaces[0] === null ) || ( ( typeof interfaces[0] === "function" ) && ( !isInterface( interfaces[0] ) ) ) )
  1566. base = interfaces.shift();
  1567. // If the last argument is not a function, assume it's a prototype definition.
  1568. proto = popNonFunction( interfaces );
  1569. // If the second to last argument is not a function, assume it's a static definition.
  1570. stat = popNonFunction( interfaces );
  1571. }
  1572. /*istanbul ignore else: We always test in DEBUG*/
  1573. if ( true )
  1574. {
  1575. // If a base class is passed, validate it too
  1576. if ( base )
  1577. {
  1578. if ( typeof base !== "function" )
  1579. {
  1580. throw new TypeError( formatErrorMessage( _definingName, _args, "_base is not a function.\r\n" +
  1581. "If you are passing a prototype definition, specify null as second argument." ) );
  1582. }
  1583. if ( cls === base )
  1584. throw new Error( formatErrorMessage( _definingName, _args, "A class cannot extend itself." ) );
  1585. if ( !( "prototype" in base ) )
  1586. throw new Error( formatErrorMessage( _definingName, _args, "base doesn't have a prototype property; it is probably a built-in function." ) );
  1587. if ( hasBase( base, Enum ) )
  1588. throw new Error( formatErrorMessage( _definingName, _args, "Cannot extend an enum. To create an enum, use declareEnum." ) );
  1589. if ( hasBase( base, Interface ) )
  1590. {
  1591. throw new Error( formatErrorMessage( _definingName, _args,
  1592. "Cannot extend an interface.\r\n" +
  1593. "To declare implementing interfaces, add them as arguments after _base; passing null as base class.\r\n" +
  1594. "To create an interface extending another interface, use declareInterface instead."
  1595. ) );
  1596. }
  1597. }
  1598. }
  1599. if ( base === null )
  1600. base = Object;
  1601. derive( cls, base, expandDefineProperties( proto, base && base.prototype, toDefineProperty, ( cls.name || "(Class)" ) + ".prototype" ) );
  1602. setInterfaces( cls, interfaces, base.interfaces );
  1603. // Apply static definition
  1604. if ( base !== Object || stat )
  1605. applyStatic( cls, base, stat );
  1606. // If not inherited from a base class, add certain utility methods like "is" and "as" to the class.
  1607. if ( !( "as" in cls.prototype ) )
  1608. ObjectPolyfill.defineProperties( cls.prototype, classProtoExtension );
  1609. // If we or our base have any interfaces, and if we're validating
  1610. /*istanbul ignore else: We always test in DEBUG*/
  1611. if ( !(false) && _validate && ( cls.interfaces.length > 0 ) )
  1612. {
  1613. // If we have a prototype definition ...
  1614. if ( proto )
  1615. {
  1616. // validate immediately.
  1617. validateInterfacesImplemented( cls );
  1618. }
  1619. else
  1620. {
  1621. // We can't validate immediately (since methods are expected to be added via
  1622. // MyClass.prototype.method = function() {}; calls), so we queue validation.
  1623. _validate.push( cls );
  1624. if ( !( "timeout" in _validate ) )
  1625. _validate.timeout = setTimeout( handleValidateQueue, 1 );
  1626. }
  1627. }
  1628. return cls;
  1629. }
  1630. /**
  1631. * Declare a constructor function to be an abstract class. Allows specifying an optional base class and interfaces implemented.
  1632. * When reading or writing decl.abstractClass statements, it might help to know it was designed to mimic popular languages
  1633. * in its format. Here's an example:
  1634. *
  1635. * // With common languages
  1636. * abstract class ClassName : BaseClass, Interface1, Interface2 // C#
  1637. * abstract class ClassName extends BaseClass implements Interface1, Interface2 // Java
  1638. * {
  1639. * private String _name;
  1640. *
  1641. * public ClassName( _name )
  1642. * {
  1643. * super( 42 );
  1644. * this._name = _name;
  1645. * }
  1646. *
  1647. * public String toString()
  1648. * {
  1649. * return this._name;
  1650. * }
  1651. * }
  1652. *
  1653. * // With barejs.decl:
  1654. *
  1655. * function ClassName( _name )
  1656. * {
  1657. * BaseClass.call( this, 42 );
  1658. * this._name = _name;
  1659. * }
  1660. *
  1661. * decl.abstractClass( ClassName, BaseClass, Interface1, Interface2,
  1662. * {
  1663. * // This puts the _name property as null on the prototype,
  1664. * // which is purely for clarity (e.g. stating it exists).
  1665. * _name: null,
  1666. *
  1667. * toString: function()
  1668. * {
  1669. * return this._name;
  1670. * }
  1671. * }
  1672. *
  1673. * - If a base class is provided, decl will ensure _class.prototype is instanceof _base.prototype.
  1674. * - For abstract classes, decl will not validate if interface methods are implemented.
  1675. * - If a _static argument is specified, it will be applied to the constructor function using {@link module:barejs.decl.defineObject defineObject}.
  1676. * - If a _prototype argument is specified, it will be applied to the prototype using {@link module:barejs.decl.defineObject defineObject}.
  1677. * - If only 1 object is supplied, it is always interpreted as prototype definition, never as static.
  1678. * You must specify null for the prototype object if you only want to specify static members.
  1679. *
  1680. * By default, any static members (except `name`, `prototype`, `constructor`, `superclass` and other metadata) will inherit.
  1681. * A class can make static functions "private" by defining a static `$private` function, accepting a String/Symbol as key.
  1682. * This function should return `true` for any keys that should *not* inherit. The `$private` function itself will never inherit.
  1683. *
  1684. * @param {function} _class The constructor function of the class
  1685. * @param {function} [_base] Optional: Extended base class
  1686. * @param {...function} [_interface] Optional: Any number of implemented interfaces
  1687. * @param {object} [_static] Optional: static definition; properties that will be added to the constructor function.
  1688. * @param {object} [_prototype] Optional: prototype definition: properties that will be added to the prototype
  1689. * @returns {function} The constructor function (**_class**), so it can immediately be returned
  1690. * @memberof module:barejs.decl
  1691. */
  1692. function abstractClass( _class/*[, _base] [, _interface...] [, _static] [, _prototype] */ )
  1693. {
  1694. return makeClass( "abstractClass", arguments );
  1695. }
  1696. /**
  1697. * Declare a constructor function to be a class. Allows specifying an optional base class and interfaces implemented.
  1698. * When reading or writing decl.declareClass statements, it might help to know it was designed to mimic popular languages
  1699. * in its format. Here's an example:
  1700. *
  1701. * // With common languages
  1702. * class ClassName : BaseClass, Interface1, Interface2 // C#
  1703. * class ClassName extends BaseClass implements Interface1, Interface2 // Java
  1704. * {
  1705. * private String _name;
  1706. *
  1707. * public ClassName( _name )
  1708. * {
  1709. * super( 42 );
  1710. * this._name = _name;
  1711. * }
  1712. *
  1713. * public String toString()
  1714. * {
  1715. * return this._name;
  1716. * }
  1717. * }
  1718. *
  1719. * // With barejs.decl:
  1720. *
  1721. * function ClassName( _name )
  1722. * {
  1723. * BaseClass.call( this, 42 );
  1724. * this._name = _name;
  1725. * }
  1726. *
  1727. * decl.declareClass( ClassName, BaseClass, Interface1, Interface2,
  1728. * {
  1729. * // This puts the _name property as null on the prototype,
  1730. * // which is purely for clarity (e.g. stating it exists).
  1731. * _name: null,
  1732. *
  1733. * toString: function()
  1734. * {
  1735. * return this._name;
  1736. * }
  1737. * }
  1738. *
  1739. * - If a base class is provided, decl will ensure _class.prototype is instanceof _base.prototype.
  1740. * - If interfaces are declared, decl will validate methods are implemented.
  1741. * - If a _static argument is specified, it will be applied to the constructor function using {@link module:barejs.decl.defineObject defineObject}.
  1742. * - If a _prototype argument is specified, it will be applied to the prototype using {@link module:barejs.decl.defineObject defineObject}.
  1743. * - If only 1 object is supplied, it is always interpreted as prototype definition, never as static.
  1744. * You must specify null for the prototype object if you only want to specify static members.
  1745. *
  1746. * By default, any static members (except `name`, `prototype`, `constructor`, `superclass` and other metadata) will inherit.
  1747. * A class can make static functions "private" by defining a static `$private` function, accepting a String/Symbol as key.
  1748. * This function should return `true` for any keys that should *not* inherit. The `$private` function itself will never inherit.
  1749. *
  1750. * @param {function} _class The constructor function of the class
  1751. * @param {function} [_base] Optional: Extended base class
  1752. * @param {...function} [_interface] Optional: Any number of implemented interfaces
  1753. * @param {object} [_static] Optional: static definition; properties that will be added to the constructor function.
  1754. * @param {object} [_prototype] Optional: prototype definition: properties that will be added to the prototype
  1755. * @returns {function} The constructor function (**_class**), so it can immediately be returned
  1756. * @memberof module:barejs.decl
  1757. */
  1758. function declareClass( _class/*[, _base] [, _interface...] [, _static] [, _prototype] */ )
  1759. {
  1760. return makeClass( "declareClass", arguments, validateQueue );
  1761. }
  1762. /**
  1763. * Declare an interface. An interface can extend multiple interfaces by passing them as additional parameters.
  1764. * The constructor function _class will be made to derive from the special internal {@link module:barejs.decl~Interface Interface} type.
  1765. * It is not meant to be instantiated, and decl will never call the interface's constructor.
  1766. * @param {function} _class The "constructor" function to declare as an interface.
  1767. * @param {...function} [_interface] Any number of interfaces to extend.
  1768. * @param {object} [_static] Optional: static definition; properties that will be added to the constructor function.
  1769. * @param {object} [_prototype] Optional: prototype to apply
  1770. * @returns {function} The interface definition (_class).
  1771. * @memberof module:barejs.decl
  1772. */
  1773. function declareInterface( _class /*[, _interface...] [, _static] [, _prototype] */ )
  1774. {
  1775. var interfaces = null,
  1776. stat = null,
  1777. proto = null;
  1778. // Development time validation
  1779. /*istanbul ignore else: We always test in DEBUG*/
  1780. if ( true )
  1781. validateClassArg( _class, "declareInterface", arguments );
  1782. // If the interface extends other interfaces, set up the inheritance.
  1783. if ( arguments.length > 1 )
  1784. {
  1785. interfaces = slice.call( arguments, 1, arguments.length );
  1786. // If the last argument is not a function, assume it's a prototype definition.
  1787. proto = popNonFunction( interfaces );
  1788. // If the second to last argument is not a function, assume it's a static definition.
  1789. stat = popNonFunction( interfaces );
  1790. }
  1791. // Each interface derives directly from Interface so it is easy to detect interfaces.
  1792. derive( _class, Interface, expandDefineProperties( proto, Interface.prototype, toDefinePropertyInterface, _class.name || "(Interface)" ) );
  1793. setInterfaces( _class, interfaces, null );
  1794. if ( stat )
  1795. applyStatic( _class, null, stat );
  1796. // Development time validation
  1797. /*istanbul ignore else: We always test in DEBUG*/
  1798. if ( !(false) && validateQueue )
  1799. {
  1800. // If we don't have a prototype definition ...
  1801. if ( proto === null )
  1802. {
  1803. // We can't validate immediately (since methods are expected to be added via
  1804. // MyInterface.prototype.method = function() {}; calls), so we queue validation.
  1805. // Prepend interfaces so they get validated first
  1806. validateQueue.unshift( _class );
  1807. if ( !( "timeout" in validateQueue ) )
  1808. validateQueue.timeout = setTimeout( handleValidateQueue, 1 );
  1809. }
  1810. else
  1811. {
  1812. // Otherwise just validate immediately.
  1813. // Creating the interface metadata will perform validation of the interface.
  1814. InterfaceMetaData.get( _class );
  1815. }
  1816. }
  1817. return _class;
  1818. }
  1819. /**
  1820. * Declare an enum. decl will make _class derive from the special internal {@link module:barejs.decl~Enum Enum} type,
  1821. * and return a new instance of it. Enum values should be set on 'this' in the constructor, utility methods should be
  1822. * added to the prototype.
  1823. *
  1824. * var SampleEnum = decl.declareEnum( function SampleEnum()
  1825. * {
  1826. * this.Bit1 = 1;
  1827. * this.Bit2 = 2;
  1828. * this.Bit3 = 4;
  1829. * this.Bit4 = 8;
  1830. * },
  1831. * // End of constructor, what follows is the prototype definition:
  1832. * {
  1833. * hasBit: function( _bit, _value )
  1834. * {
  1835. * // hasValue is provided by the Enum base class
  1836. * if ( !this.hasValue( _bit ) )
  1837. * throw new TypeError( "Unknown SampleEnum value: " + _bit );
  1838. * return _value & _bit === _bit
  1839. * }
  1840. * } );
  1841. *
  1842. * // SampleEnum is now instanceof the SampleEnum function passed to decl.
  1843. * SampleEnum.hasBit( SampleEnum.Bit2, 3 ); // true
  1844. * // And it inherited decl's Enum type members
  1845. * SampleEnum.names(); // ["Bit1", "Bit2", "Bit3", "Bit4"]
  1846. * SampleEnum instanceof Object; // false
  1847. *
  1848. * Note that the prototype property, if specified, is applied using {@link module:barejs.decl.defineObject defineObject}.
  1849. * @param {function} _class The "constructor" function to declare as an Enum.
  1850. * @param {object} [_prototype] Optional: things to add to the enum prototype.
  1851. * @returns {object} The enum instance (instanceof _class).
  1852. * @memberof module:barejs.decl
  1853. */
  1854. function declareEnum( _class/*[, _prototype]*/ )
  1855. {
  1856. /*istanbul ignore else: We always test in DEBUG*/
  1857. if ( true )
  1858. validateClassArg( _class, "declareEnum", arguments );
  1859. // An enum inherits directly from Enum, so they can be easily detected (and receive some helper methods).
  1860. derive( _class, Enum, expandDefineProperties( arguments[1], Enum.prototype, toDefineProperty, ( _class.name || "(Enum)" ) ) );
  1861. // jshint -W055
  1862. // Return an instance for an enum
  1863. return ObjectPolyfill.freeze( new _class() );
  1864. // jshint +W055
  1865. }
  1866. /**
  1867. * defineObject is similar to {@link module:barejs.decl.defineProperties decl.defineProperties}, but it expands the _definition's properties if needed.
  1868. * It will update values of properties that are not property assigment definitions to be proper property definitions, defaulting to:
  1869. *
  1870. * { configurable: false, writable: true, enumerable: true, value: &lt;value&gt; }
  1871. *
  1872. * (Note: enumerable will be `false` if the name starts with _ or is a Symbol).
  1873. * defineObject will iterate the _definition object and expand properties on it. Please be aware of the following:
  1874. * 1. **_destination** will be modified. If that's a problem, use {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign Object.assign} to create a copy first.
  1875. * 2. Existing properties are scanned for presence of a **value**, **get** or **set** property. If these are present on a value, you **must** use the full property syntax:
  1876. *
  1877. * decl.defineObject( MyClass,
  1878. * {
  1879. * // Since the object we want to assign to the MyClass constructor function has properties that make it look like
  1880. * // a property definition, we have to wrap it in a property definition as required by Object.defineProperties.
  1881. * staticFlags: { enumerable: true, value: { get: true, set: false } }
  1882. * } );
  1883. *
  1884. * 3. defineObject will silently ignore getter/setter properties in environments that don't support them, unlike {@link module:barejs.decl.defineProperties}.
  1885. * 4. You can reference a getter or setter by name, provided it is also on the definition object:
  1886. *
  1887. * decl.defineObject( {},
  1888. * {
  1889. * // underlying data Array, not enumerable, configurable or writable
  1890. * _values: { value: [] },
  1891. * // getSize function that returns the length of the _values
  1892. * getSize: function() { return this._values.length; },
  1893. * // Size property. Refers to the getSize function for the getter, instead of using an inline function.
  1894. * size: { enumerable: true, get: "getSize" }
  1895. * } );
  1896. *
  1897. * @param {object} _target The target object
  1898. * @param {object} _definition The definitions to assign to _target. Note that _definition will be modified to contain property definitions(!).
  1899. * @param {string} [_objectName] Optional: the name of the object. If passed, decl will generate displayName properties on methods for an enhanced debugging experience.
  1900. * For example: if "decl" is passed as name, and there's an "is" function on _definition, the displayName of the "is" function will be set to "decl.is").
  1901. * @returns _target The target object, expanded
  1902. * @memberof module:barejs.decl
  1903. */
  1904. function defineObject( _target, _definition/*, _objectName*/ )
  1905. {
  1906. if ( !_definition )
  1907. throw new Error( "Missing definition" );
  1908. return ObjectPolyfill.defineProperties( _target, expandDefineProperties( _definition, _target, toDefineProperty, arguments.length > 2 ? String( arguments[2] ) : _target.name ) );
  1909. }
  1910. /**
  1911. * Interpret `_target` as implementing a Java Functional Interface. A functional interface is an Interface with exactly
  1912. * 1 function defined. Java allows lambda expressions to be generated for arguments of this type of interface.
  1913. * This method allows normalizing a function or object to a "Functional Interface Object", so Java behavior can be
  1914. * emulated.
  1915. * This function will accept:
  1916. * - `null`/`undefined` (then `null` is returned)
  1917. * - A function (an 'instance' of _functionalInterface is returned, with this function in place).
  1918. * - An object complying with _functionalInterface
  1919. *
  1920. * Any other argument will throw a {@link TypeError}.
  1921. * @param {object|function} _target The target object or function.
  1922. * @param {function} _functionalInterface The interface to use as functional interface. May only have a single method defined.
  1923. * @param {boolean} [_strict=false] Optional: set to true to avoid a duck-type check, and only check `decl`
  1924. * metadata for interfaces implemented.
  1925. * @returns Either an object compliant with `_functionalInterface`, or `null`.
  1926. * @throws {TypeError} A TypeError may occur if `_functionalInterface` is not a valid functional interface,
  1927. * or if _target does not comply with the interface.
  1928. * @memberof module:barejs.decl
  1929. */
  1930. function asFunctional( _target, _functionalInterface, _strict )
  1931. {
  1932. if ( !isInterface( _functionalInterface ) )
  1933. throw new TypeError( _functionalInterface + " is not an interface" );
  1934. var meta = InterfaceMetaData.get( _functionalInterface );
  1935. var fn = meta.members[ 0 ];
  1936. if ( meta.members.length !== 1 || fn.type !== "function" )
  1937. throw new TypeError( _functionalInterface.prototype + " is not a functional interface, functional interfaces have a single method" );
  1938. if ( _target === null || _target === undefined )
  1939. return null;
  1940. // If this is a function, return an object that can be used instead.
  1941. if ( typeof _target === "function" )
  1942. {
  1943. var def = {};
  1944. def[fn.name] = { enumerable: true, value: _target };
  1945. return Object.create( _functionalInterface.prototype, def );
  1946. }
  1947. if ( hasInterface( _target, _functionalInterface, _strict ) )
  1948. return _target;
  1949. throw new TypeError( _target + " does not implement " + _functionalInterface.prototype );
  1950. }
  1951. defineObject( exports,
  1952. {
  1953. // Exports
  1954. isInterface: isInterface,
  1955. isEnum: isEnum,
  1956. isProxy: isProxy,
  1957. is: is,
  1958. hasBase: hasBase,
  1959. hasInterface: hasInterface,
  1960. proxy: proxy,
  1961. abstractClass: abstractClass,
  1962. declareClass: declareClass,
  1963. declareInterface: declareInterface,
  1964. declareEnum: declareEnum,
  1965. defineObject: defineObject,
  1966. asFunctional: asFunctional,
  1967. // Convenience properties to define interface properties
  1968. readOnlyProperty: readOnlyProperty,
  1969. readWriteProperty: readWriteProperty,
  1970. // Allows certain low level classes to disallow casting to them
  1971. preventCast: preventCast
  1972. }, "decl" );
  1973. // We do NOT want to add a displayName to methods from other modules, so use a separate defineObject
  1974. defineObject( exports,
  1975. /** @lends module:barejs.decl */
  1976. {
  1977. // Helper methods/flags for property definitions
  1978. /**
  1979. * This convenience property is true if the environment supports property getters and setters.
  1980. * @member {boolean}
  1981. */
  1982. hasPropertySupport: ObjectPolyfill.propertyGetSetSupport,
  1983. /**
  1984. * decl re-exports {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty Object.defineProperty}.
  1985. *
  1986. * If the native version is not available, a fall-back is used. The fallback supports the same syntax as the original, but falls back to simple assignment
  1987. * or deprecated constructs like {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__ __defineGetter__}.
  1988. * Be aware that property getters or setters may not be supported in some environments, which is indicated by {@link module:barejs.decl.hasPropertySupport hasPropertySupport} being false.
  1989. * @function
  1990. * @param {object} _target The object to define the property on
  1991. * @param {string|Symbol} _key The name or {@link module:barejs.Symbol Symbol} to set
  1992. * @param {object} _definition Object containing either a **value** property, or a **get** and/or **set** property (function).
  1993. * @param {function} [_definition.get] A getter function, taking no arguments and returning the property value.
  1994. * @param {function} [_definition.set] A setter function, taking a value as argument.
  1995. * @param {*} [_definition.value] The value to assign to the property.
  1996. * @param {boolean} [_definition.writable=false] (Only in combination with value) Whether assigning to the property is allowed.
  1997. * For properties with get/set, the writable is implicit (by absence or presence of a setter function).
  1998. * @param {boolean} [_definition.configurable=false] Whether the property may be altered via delete or a next defineProperty call.
  1999. * @param {boolean} [_definition.enumerable=false] Whether the property shows up in object property enumerations.
  2000. * @returns {object} The object the properties where defined on (_target).
  2001. */
  2002. defineProperty: ObjectPolyfill.defineProperty,
  2003. /**
  2004. * decl re-exports {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties Object.defineProperties}.
  2005. *
  2006. * If the native version is not available, a fall-back is used. The fallback supports the same syntax as the original, and uses the {@link module:barejs.decl.defineProperty defineProperty} fallback.
  2007. * @function
  2008. * @param {object} _target The object to define the property on
  2009. * @param {object} _definitions Object containing properties, each of which have a value that is a definition as passed to defineProperty.
  2010. * @returns {object} The object the properties where defined on (_target).
  2011. */
  2012. defineProperties: ObjectPolyfill.defineProperties,
  2013. // Helper methods for object strictness (seal/freeze)
  2014. /**
  2015. * decl re-exports {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal Object.seal}.
  2016. *
  2017. * If the native version is not available, a **no-operation** function is used. The object is not altered in any way and simply returned.
  2018. * @function
  2019. * @param {object} _target The object to seal.
  2020. * @returns {object} The object that was passed (_target).
  2021. */
  2022. seal: ObjectPolyfill.seal,
  2023. /**
  2024. * decl re-exports {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed Object.isSealed}.
  2025. * A sealed object may not be altered by adding or removing properties. Existing properties may be altered (provided they are writable).
  2026. *
  2027. * If the native version is not available, a **no-operation** function is used. The object is not altered by the fallback, and it always returns false (since sealing objects is not supported).
  2028. *
  2029. * @function
  2030. * @param {object} _target The object to evaluate.
  2031. * @returns {boolean} True if the object (_target) is sealed, false otherwise. The fallback always returns false.
  2032. */
  2033. isSealed: ObjectPolyfill.isSealed,
  2034. /**
  2035. * decl re-exports {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze Object.freeze}.
  2036. * A frozen object may not be altered in any way. No properties may be added or removed (like seal), and all values are made read-only.
  2037. *
  2038. * If the native version is not available, a **no-operation** function is used. The object is not altered in any way and simply returned.
  2039. *
  2040. * @function
  2041. * @param {object} _target The object to freeze.
  2042. * @returns {object} The object that was passed (_target).
  2043. */
  2044. freeze: ObjectPolyfill.freeze,
  2045. /**
  2046. * decl re-exports {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen Object.isFrozen}.
  2047. *
  2048. * If the native version is not available, a **no-operation** function is used. The object is not altered by the fallback, and it always returns false (since freezing objects is not supported).
  2049. * @function
  2050. * @param {object} _target The object to evaluate.
  2051. * @returns {boolean} True if the object (_target) is frozen, false otherwise. The fallback always returns false.
  2052. */
  2053. isFrozen: ObjectPolyfill.isFrozen
  2054. } /*DO NOT ADD NAME*/ );
  2055. exports.freeze( exports );
  2056. // End of define
  2057. }(
  2058. Object,
  2059. Array,
  2060. String,
  2061. Error,
  2062. TypeError,
  2063. __webpack_require__( 2 ),
  2064. __webpack_require__( 3 ),
  2065. __webpack_require__( 6 ),
  2066. __webpack_require__( 8 ),
  2067. __webpack_require__( 10 ),
  2068. // Unreferenced: decl depends on the Array polyfills too.
  2069. __webpack_require__( 12 )
  2070. ) );
  2071. /***/ }),
  2072. /* 2 */
  2073. /***/ (function(module, exports, __webpack_require__) {
  2074. // Licensed Materials - Property of IBM
  2075. //
  2076. // IBM Watson Analytics
  2077. //
  2078. // (C) Copyright IBM Corp. 2015, 2018
  2079. //
  2080. // US Government Users Restricted Rights - Use, duplication or
  2081. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  2082. ( function( exports, Object )
  2083. {
  2084. "use strict";
  2085. /*global Symbol*/
  2086. var hasOwnProperty = Object.prototype.hasOwnProperty;
  2087. var toString = Object.prototype.toString;
  2088. // RegExp set up to match BareJS and polyfill.io symbol strings
  2089. // polyfill uses "__\x01symbol:" and "__\x01symbol@@"
  2090. var reSymbol = /^__\d*\x01?[sS]ymbol/;
  2091. // By default, make members whose name does not start with _ or $ enumerable.
  2092. var reEnumerable = /^[^_\$]/;
  2093. var strUndef = "undefined";
  2094. var NativeSymbol = typeof Symbol !== strUndef ? Symbol : null;
  2095. //jshint -W122
  2096. var symIt = NativeSymbol && ( typeof Symbol.iterator === "symbol" ) ? Symbol.iterator : /*istanbul ignore next*/ null;
  2097. //jshint +W122
  2098. /**
  2099. * Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object Object}.
  2100. * Module that provides implementations for methods missing on Object. Methods that cannot be polyfilled close enough to
  2101. * the spec (since they rely on Native implementations) are not added to the Object global.
  2102. * @class module:barejs/polyfill.Object
  2103. */
  2104. /** @lends module:barejs/polyfill.Object */
  2105. var stat = {};
  2106. /**
  2107. * Shortcut method that only defines a property if it is not already known
  2108. * @param {object} _target The object to polyfill
  2109. * @param {object} _members The members to polyfill
  2110. * @param {object} [_copy] Optional: an object that the definitions will be copied to.
  2111. * @param {string} [_ownerName] Optional: name of the owner object
  2112. * @memberof module:barejs/polyfill.Object~
  2113. * @private
  2114. */
  2115. function polyMixin( _target, _members, _copy, _ownerName )
  2116. {
  2117. for ( var name in _members )
  2118. {
  2119. /*istanbul ignore else: we're working on clean objects, iterating prototype properties is unexpected*/
  2120. if ( _members.hasOwnProperty( name ) )
  2121. {
  2122. var member = _members[name], isFn = typeof member === "function";
  2123. if ( isFn && _ownerName )
  2124. member.displayName = _ownerName + "." + name;
  2125. if ( _copy )
  2126. _copy[name] = member;
  2127. if ( !( name in _target ) )
  2128. exports.defineProperty( _target, name, { enumerable : false, configurable: isFn, writable: isFn, value: member } );
  2129. }
  2130. }
  2131. }
  2132. /**
  2133. * Helper method that allows to easily apply static and prototype properties to a native object
  2134. * @param {function} _native The native Object constructor to polyfill
  2135. * @param {object} _static The static methods to polyfill. Can be null.
  2136. * @param {object} _proto The instance members to polyfill. Can be null.
  2137. * @param {object} [_copy] Optional: an object that the definitions will be copied to.
  2138. * @param {string} [_ownerName] Optional: the name of the owner object.
  2139. * Allows to add functions to "exports" as well, for unit testing.
  2140. * @memberof module:barejs/polyfill.Object
  2141. * @private
  2142. */
  2143. exports.polyfill = function polyfill( _native, _static, _proto, _copy, _ownerName )
  2144. {
  2145. if ( _static )
  2146. polyMixin( _native, _static, _copy, _ownerName );
  2147. if ( _proto )
  2148. polyMixin( _native.prototype, _proto, _copy, _ownerName && ( _ownerName + ".prototype" ) );
  2149. return _native;
  2150. };
  2151. exports.shouldBeEnumerable = function shouldBeEnumerable( _name )
  2152. {
  2153. return typeof _name === "string" && reEnumerable.test( _name );
  2154. };
  2155. /**
  2156. * Utility method to check if _target is an Object
  2157. * @param _arg The argument to check.
  2158. * @returns {boolean} True if the target is an object, false otherwise
  2159. */
  2160. function isObject( _arg )
  2161. {
  2162. switch ( _arg && typeof _arg )
  2163. {
  2164. case "object":
  2165. case "function":
  2166. return true;
  2167. default:
  2168. return false;
  2169. }
  2170. }
  2171. exports.isObject = isObject;
  2172. /**
  2173. * Utility method to convert target to an Object (according to Ecmascript standard)
  2174. * @param _arg The argument to check.
  2175. * @param _caller The function requesting the cast. If provided, changes the exception message.
  2176. * @returns {object} The argument, as object
  2177. * @throws {TypeError} A TypeError if _arg is null or undefined.
  2178. */
  2179. function toObject( _arg, _caller )
  2180. {
  2181. switch ( _arg === null ? strUndef : typeof _arg )
  2182. {
  2183. case "undefined":
  2184. throw new TypeError( _caller ? _caller.displayName + " called on null or undefined" : "Cannot convert undefined or null to object" );
  2185. case "object":
  2186. case "function":
  2187. return _arg;
  2188. default:
  2189. return Object( _arg );
  2190. }
  2191. }
  2192. exports.toObject = toObject;
  2193. /**
  2194. * Check if _arg is callable (i.e. a function).
  2195. * @param _arg The argument to check.
  2196. * @returns {boolean} True if _arg is a function, false otherwise.
  2197. * @memberof module:barejs/polyfill.Object
  2198. * @private
  2199. */
  2200. exports.isCallable = function isCallable( _arg )
  2201. {
  2202. // We can't check the internal [[Call]] property, so we rely on type checking.
  2203. return ( typeof _arg === "function" ) || ( toString.call( _arg ) === "[object Function]" );
  2204. };
  2205. /**
  2206. * Convenience method to check if _arg is callable (i.e. a function).
  2207. * Note: If a second argument is provided, that is returned instead of _arg.
  2208. * This allows inlining the ensureCallable method in convenient locations.
  2209. * @param _arg function to check
  2210. * @returns _arg, or second argument if present
  2211. * @throws {TypeError} if _arg is not callable.
  2212. * @memberof module:barejs/polyfill.Object
  2213. * @private
  2214. */
  2215. exports.ensureCallable = function ensureCallable( _arg )
  2216. {
  2217. if ( !exports.isCallable( _arg ) )
  2218. throw new TypeError( _arg + " is not a function" );
  2219. return arguments.length > 1 ? arguments[1] : _arg;
  2220. };
  2221. /**
  2222. * Helper function that will attempt to set the ES6 iterator Symbol for a class.
  2223. * @param {object} _target The object to define the iterator on.
  2224. * @param {function} _function The function that will result in the iterator.
  2225. * @returns {object} `_target`.
  2226. * @memberof module:barejs/polyfill.Object
  2227. * @private
  2228. */
  2229. function setIterator( _target, _function )
  2230. {
  2231. var def = { configurable: true, value: _function };
  2232. /*istanbul ignore else: always true in NodeJS*/
  2233. if ( symIt )
  2234. exports.defineProperty( _target, symIt, def );
  2235. // Set @@iterator for compliancy with polyfill libraries like core.js
  2236. exports.defineProperty( _target, "@@iterator", def );
  2237. return _target;
  2238. }
  2239. exports.setIterator = setIterator;
  2240. /**
  2241. * Helper function that will get the ES6 iterator Symbol for a class.
  2242. * @param {function} _class The constructor function to define the iterator on
  2243. * @returns {object} The iterator, or null.
  2244. * @memberof module:barejs/polyfill.Object
  2245. * @private
  2246. */
  2247. function getIterator( _target )
  2248. {
  2249. var result = null;
  2250. if ( _target )
  2251. {
  2252. var obj = Object( _target );
  2253. if ( symIt && ( symIt in obj ) )
  2254. result = obj[symIt]();
  2255. else if ( "@@iterator" in obj )
  2256. result = obj["@@iterator"]();
  2257. }
  2258. return result;
  2259. }
  2260. exports.getIterator = getIterator;
  2261. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2262. // Grab some methods that we may have to provide fallbacks for
  2263. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2264. var modernPropertySupport = !!Object.defineProperties;
  2265. var legacyPropertySupport = ( ( "__defineGetter__" in Object.prototype ) && ( "__defineSetter__" in Object.prototype ) );
  2266. /*istanbul ignore next: We know we have Object.defineProperties in NodeJS*/
  2267. exports.propertyGetSetSupport = modernPropertySupport || legacyPropertySupport;
  2268. // Take care not to grab IE8's defineProperty that only works on DOM elements.
  2269. /*istanbul ignore else: native in NodeJS*/
  2270. if ( modernPropertySupport )
  2271. {
  2272. exports.defineProperty = Object.defineProperty;
  2273. exports.defineProperties = Object.defineProperties;
  2274. exports.getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  2275. exports.getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
  2276. }
  2277. exports.getPrototypeOf = Object.getPrototypeOf;
  2278. exports.freeze = Object.freeze;
  2279. exports.isFrozen = Object.isFrozen;
  2280. exports.seal = Object.seal;
  2281. exports.isSealed = Object.isSealed;
  2282. // ES6
  2283. exports.getOwnPropertyNames = Object.getOwnPropertyNames;
  2284. exports.getOwnPropertySymbols = Object.getOwnPropertySymbols;
  2285. /*istanbul ignore else: The tests are run with __ES__ set to 3*/
  2286. if ( (6) < 5 )
  2287. {
  2288. ////////////////////////////////////////////////////////////////////////////////////////////////
  2289. // ES5 fallback functions
  2290. ////////////////////////////////////////////////////////////////////////////////////////////////
  2291. // The following methods are not actually polyfills; these methods cannot be polyfilled.
  2292. // However, if the fallback behavior provided by the methods is sufficient, these can be used.
  2293. /*istanbul ignore if: native in NodeJS*/
  2294. if ( !exports.defineProperty )
  2295. {
  2296. /*
  2297. * Object.defineProperty cannot be emulated on browsers that do not support it.
  2298. * However, if the intention is to just set a value (no getters/setters), and the loss of
  2299. * enumerable, writable and configurable flags is acceptable, this method can be used.
  2300. * Uses the native method where possible
  2301. *
  2302. * Note: check for compliance via Object.defineProperties, since IE8 has an Object.defineProperty,
  2303. * but that only works on DOM elements.
  2304. */
  2305. exports.defineProperty = function defineProperty( _object, _name, _definition )
  2306. {
  2307. if ( !isObject( _object ) )
  2308. throw new TypeError( "Object.defineProperty called on non-object" );
  2309. /*
  2310. * Fallback to simple assignment or __define[GS]etter__
  2311. */
  2312. // Only assign if it actually exists.
  2313. if ( "value" in _definition )
  2314. {
  2315. _object[_name] = _definition.value;
  2316. }
  2317. else if ( ( "get" in _definition ) || ( "set" in _definition ) )
  2318. {
  2319. if ( !exports.propertyGetSetSupport )
  2320. throw new Error( "Property getters and setters are not supported in this environment" );
  2321. if ( "get" in _definition )
  2322. _object.__defineGetter__( _name, _definition.get );
  2323. if ( "set" in _definition )
  2324. _object.__defineSetter__( _name, _definition.set );
  2325. }
  2326. return _object;
  2327. };
  2328. }
  2329. /*istanbul ignore if: native in NodeJS*/
  2330. if ( !exports.defineProperties )
  2331. {
  2332. /*
  2333. * Uses the possibly emulated defineProperty and behaves like Object.defineProperties.
  2334. * Can only be used to set values (no getters/setters) in environments that do not support getters/setters.
  2335. * Uses the native method where possible
  2336. */
  2337. exports.defineProperties = function defineProperties( _object, _properties )
  2338. {
  2339. if ( !isObject( _object ) )
  2340. throw new TypeError( "Object.defineProperties called on non-object" );
  2341. _properties = toObject( _properties );
  2342. // Assume there is no Object.keys in an environment that requires this polyfill.
  2343. for ( var i in _properties )
  2344. if ( hasOwnProperty.call( _properties, i ) && ( !reSymbol.test( i ) ) ) // Ignore Symbols
  2345. exports.defineProperty( _object, i, _properties[i] );
  2346. return _object;
  2347. };
  2348. }
  2349. /*istanbul ignore if: native in NodeJS*/
  2350. if ( !exports.getPrototypeOf )
  2351. {
  2352. /**
  2353. * Object.getPrototypeOf cannot be fully emulated on browsers that do not support it.
  2354. * We attempt to find a __proto__ or constructor.prototype.
  2355. * Attempt to get an objects prototype, returns null on failure
  2356. * @param {object} _object The object to get the prototype of
  2357. * @returns {object} The prototype of _object
  2358. * @memberof module:barejs/polyfill.Object
  2359. * @private
  2360. */
  2361. exports.getPrototypeOf = function getPrototypeOf( _object )
  2362. {
  2363. switch ( _object === null ? strUndef : typeof _object )
  2364. {
  2365. case "undefined":
  2366. throw new TypeError( "Cannot convert undefined or null to object" );
  2367. case "boolean":
  2368. return Boolean.prototype;
  2369. case "number":
  2370. return Number.prototype;
  2371. case "string":
  2372. return String.prototype;
  2373. case "function":
  2374. return Function.prototype;
  2375. // case "object", and any other host value
  2376. default:
  2377. // jshint -W103
  2378. if ( "__proto__" in _object )
  2379. return _object.__proto__;
  2380. // jshint +W103
  2381. // If the object has the constructor property, this is already a prototype
  2382. if ( !hasOwnProperty.call( _object, "constructor" ) )
  2383. return _object.constructor.prototype;
  2384. // See if a framework set a superclass property
  2385. else if ( _object.constructor.superclass )
  2386. return _object.constructor.superclass.prototype;
  2387. if ( Array.isArray( _object ) )
  2388. return Array.prototype;
  2389. return null;
  2390. }
  2391. };
  2392. }
  2393. /*istanbul ignore if: native in NodeJS*/
  2394. if ( !exports.freeze )
  2395. {
  2396. /*
  2397. * Object.freeze cannot be emulated. This method is a NOOP if Object.freeze is not supported.
  2398. */
  2399. exports.freeze = function freeze( _o ){ return _o; };
  2400. }
  2401. /*istanbul ignore if: native in NodeJS*/
  2402. if ( !exports.isFrozen )
  2403. {
  2404. /*
  2405. * Object.isFrozen cannot be emulated. This method is a NOOP if Object.isFrozen is not supported.
  2406. */
  2407. exports.isFrozen = function isFrozen( _o ){ return false; };
  2408. }
  2409. /*istanbul ignore if: native in NodeJS*/
  2410. if ( !exports.seal )
  2411. {
  2412. /*
  2413. * Object.seal cannot be emulated. This method is a NOOP if Object.seal is not supported.
  2414. */
  2415. exports.seal = function seal( _o ){ return _o; };
  2416. }
  2417. /*istanbul ignore if: native in NodeJS*/
  2418. if ( !exports.isSealed )
  2419. {
  2420. /*
  2421. * Object.isSealed cannot be emulated. This method is a NOOP if Object.isSealed is not supported.
  2422. */
  2423. exports.isSealed = function isSealed( _o ){ return false; };
  2424. }
  2425. ////////////////////////////////////////////////////////////////////////////////////////////////
  2426. // ES5 polyfills
  2427. ////////////////////////////////////////////////////////////////////////////////////////////////
  2428. //
  2429. // ES5 - Object
  2430. //
  2431. ( function()
  2432. {
  2433. /*global document, ActiveXObject*/
  2434. var createEmpty;
  2435. // While we generally prefer named constructors, avoid it here since it adds no value,
  2436. // and may even be confusing when looking at the prototype chain.
  2437. var Anonymous = function(){};
  2438. //jshint -W103
  2439. /*istanbul ignore else: NodeJS supports the __proto__ property*/
  2440. if ( ( !( { __proto__: null } instanceof Object ) ) || ( typeof document === strUndef ) )
  2441. {
  2442. // We can use the deprecated __proto__ property to create an object with no prototype
  2443. createEmpty = function()
  2444. {
  2445. return { __proto__: null };
  2446. };
  2447. }
  2448. //jshint +W103
  2449. else
  2450. {
  2451. // We grab a foreign Object.prototype so any object created from it has instanceof Object return false,
  2452. // and we can safely delete all properties from it without breaking regular objects.
  2453. createEmpty = function()
  2454. {
  2455. var shouldUseActiveX = ( function()
  2456. {
  2457. try
  2458. {
  2459. return !!( document.domain && new ActiveXObject( "htmlfile" ) );
  2460. }
  2461. catch ( ex )
  2462. {
  2463. return false;
  2464. }
  2465. }() );
  2466. function Empty() {}
  2467. if ( shouldUseActiveX )
  2468. {
  2469. Empty.prototype = ( function( _xDoc )
  2470. {
  2471. _xDoc.write( "<script><\/script>" );
  2472. _xDoc.close();
  2473. var empty = _xDoc.parentWindow.Object.prototype;
  2474. _xDoc = null;
  2475. return empty;
  2476. }( new ActiveXObject( "htmlfile" ) ));
  2477. }
  2478. else
  2479. {
  2480. Empty.prototype = ( function( _parent, _iframe )
  2481. {
  2482. _iframe.style.display = "none";
  2483. _parent.appendChild( _iframe );
  2484. // jshint -W107
  2485. _iframe.src = "javascript:";
  2486. // jshint +W107
  2487. var empty = _iframe.contentWindow.Object.prototype;
  2488. _parent.removeChild( _iframe );
  2489. _iframe = null;
  2490. return empty;
  2491. }( document.body || document.documentElement, document.createElement( "iframe" ) ) );
  2492. }
  2493. // Now delete all existing definitions on our "empty" object to make it truly empty
  2494. ( function( _e )
  2495. {
  2496. delete _e.constructor;
  2497. delete _e.hasOwnProperty;
  2498. delete _e.propertyIsEnumerable;
  2499. delete _e.isPrototypeOf;
  2500. delete _e.toLocaleString;
  2501. delete _e.toString;
  2502. delete _e.valueOf;
  2503. }( Empty.prototype ) );
  2504. // Shortcut createEmpty for future calls
  2505. createEmpty = function()
  2506. {
  2507. // This returns an object for which instanceof Object is false
  2508. return new Empty();
  2509. };
  2510. return createEmpty();
  2511. };
  2512. }
  2513. /**
  2514. * Create an instance of an object that has another object as its prototype
  2515. * @param {object} _proto The prototype of the newly created object, or null.
  2516. * @param {object} _properties
  2517. * @returns {object} A new object that has the input object as prototype.
  2518. */
  2519. stat.create = function create( _proto, _properties )
  2520. {
  2521. var result;
  2522. // _proto has 3 valid values: null or an Object (a function is an Object too)
  2523. if ( _proto === null )
  2524. {
  2525. result = createEmpty();
  2526. }
  2527. else
  2528. {
  2529. if ( !isObject( _proto ) )
  2530. throw new TypeError( "Object prototype may only be an Object or null: " + _proto );
  2531. Anonymous.prototype = _proto;
  2532. result = new Anonymous();
  2533. Anonymous.prototype = null; // Reset prototype so we don't hold a reference to _proto
  2534. }
  2535. if ( typeof _properties !== strUndef )
  2536. exports.defineProperties( result, toObject( _properties ) );
  2537. return result;
  2538. };
  2539. }() );
  2540. ( function()
  2541. {
  2542. var hasDontEnumBug = !( { toString: null } ).propertyIsEnumerable( "toString" ),
  2543. dontEnums = [
  2544. "toString",
  2545. "toLocaleString",
  2546. "valueOf",
  2547. "hasOwnProperty",
  2548. "isPrototypeOf",
  2549. "propertyIsEnumerable",
  2550. "constructor"
  2551. ],
  2552. dontEnumsLength = dontEnums.length;
  2553. /**
  2554. * Return the property names defined directly on object
  2555. * @param {object} _obj The target object.
  2556. * @returns {Array} String[] property names.
  2557. */
  2558. stat.keys = function keys( _obj )
  2559. {
  2560. // Ensure object
  2561. _obj = toObject( _obj );
  2562. var result = [];
  2563. for ( var prop in _obj )
  2564. if ( hasOwnProperty.call( _obj, prop ) && ( !reSymbol.test( prop ) ) ) // Ignore Symbols
  2565. result.push(prop);
  2566. /*istanbul ignore if: not applicable in NodeJS*/
  2567. if ( hasDontEnumBug )
  2568. {
  2569. for ( var i = 0; i < dontEnumsLength; ++i )
  2570. if ( hasOwnProperty.call( _obj, dontEnums[i] ) )
  2571. result.push( dontEnums[i] );
  2572. }
  2573. return result;
  2574. };
  2575. }() );
  2576. }
  2577. /*istanbul ignore else: The tests are run with __ES__ set to 3*/
  2578. if ( (6) < 6 )
  2579. {
  2580. // Technically most of the methods set on exports are in ES5, but BareJS relies on them so ensure there's a fallback
  2581. /*istanbul ignore if: native in NodeJS*/
  2582. if ( !exports.getOwnPropertyNames )
  2583. {
  2584. exports.getOwnPropertyNames = function( _object )
  2585. {
  2586. var result = [];
  2587. if ( _object )
  2588. {
  2589. var obj = Object( _object );
  2590. for ( var key in obj )
  2591. {
  2592. if ( hasOwnProperty.call( obj, key ) && typeof key === "string" )
  2593. result.push( key );
  2594. }
  2595. }
  2596. return result;
  2597. };
  2598. }
  2599. /*istanbul ignore if: native in NodeJS*/
  2600. if ( !exports.getOwnPropertySymbols )
  2601. {
  2602. exports.getOwnPropertySymbols = function getOwnPropertySymbols( _target )
  2603. {
  2604. // Ensure object
  2605. _target = toObject( _target );
  2606. var result = [];
  2607. for ( var prop in _target )
  2608. if ( hasOwnProperty.call( _target, prop ) && ( reSymbol.test( prop ) ) )
  2609. result.push(prop);
  2610. return result;
  2611. };
  2612. }
  2613. /*istanbul ignore if: native in NodeJS*/
  2614. if ( !exports.getOwnPropertyDescriptor )
  2615. {
  2616. exports.getOwnPropertyDescriptor = function getOwnPropertyDescriptor( _object, _key )
  2617. {
  2618. var descriptor;
  2619. if ( _object )
  2620. {
  2621. var obj = Object( _object );
  2622. if ( hasOwnProperty.call( obj, _key ) )
  2623. {
  2624. descriptor = { configurable: true, enumerable: true };
  2625. var getter;
  2626. var setter;
  2627. if ( legacyPropertySupport )
  2628. {
  2629. getter = obj.__lookupGetter__( _key );
  2630. setter = obj.__lookupSetter__( _key );
  2631. }
  2632. if ( getter || setter )
  2633. {
  2634. if ( getter )
  2635. descriptor.get = getter;
  2636. if ( setter )
  2637. descriptor.set = setter;
  2638. }
  2639. else
  2640. {
  2641. descriptor.value = obj[_key];
  2642. }
  2643. }
  2644. }
  2645. return descriptor;
  2646. };
  2647. }
  2648. /*istanbul ignore if: native in NodeJS*/
  2649. if ( !exports.getOwnPropertyDescriptors )
  2650. {
  2651. exports.getOwnPropertyDescriptors = function( _object )
  2652. {
  2653. var descriptors = {};
  2654. if ( _object )
  2655. {
  2656. var names = exports.getOwnPropertyNames( _object );
  2657. for ( var i = 0, len = names.length; i < len; ++i )
  2658. descriptors[names[i]] = exports.getOwnPropertyDescriptor( _object, names[i] );
  2659. }
  2660. return descriptors;
  2661. };
  2662. }
  2663. /**
  2664. * Object.is() determines whether two values are the same value. Two values are the same if one of the following holds:
  2665. * - both undefined
  2666. * - both null
  2667. * - both true or both false
  2668. * - both strings of the same length with the same characters
  2669. * - both the same object
  2670. * - both numbers and
  2671. * - both +0
  2672. * - both -0
  2673. * - both NaN
  2674. * - or both non-zero and both not NaN and both have the same value
  2675. * @param _v1 The first value to compare.
  2676. * @param _v2 The second value to compare.
  2677. * @returns {boolean} A new object that has the input object as prototype.
  2678. */
  2679. stat.is = function is( _v1, _v2 )
  2680. {
  2681. if ( _v1 === _v2 )
  2682. return ( _v1 !== 0 ) || ( 1 / _v1 === 1 / _v2 ); // Ensure Object.is( +0, -0 ) returns false
  2683. else
  2684. return ( _v1 !== _v1 ) && ( _v2 !== _v2 ); // Ensure Object.is( NaN, NaN ) returns true
  2685. };
  2686. /**
  2687. * The Object.assign() method only copies enumerable and own properties from a source object to a target object.
  2688. * It uses [[Get]] on the source and [[Put]] on the target, so it will invoke getters and setters.
  2689. * Therefore it assigns properties versus just copying or defining new properties.
  2690. * This may make it unsuitable for merging new properties into a prototype if the merge sources contain getters.
  2691. * For copying property definitions, including their enumerability, into prototypes Object.getOwnPropertyDescriptor() and Object.defineProperty() should be used instead.
  2692. * @param {object} _target The target to assign to.
  2693. * @param {object} _firstSource The first source object to copy from.
  2694. * @returns {object} the _target, with properties assigned.
  2695. */
  2696. stat.assign = function assign( _target, _firstSource /*assign.length should be 2*/ )
  2697. {
  2698. // Ensure object
  2699. _target = toObject( _target );
  2700. for ( var arg = 1, argLen = arguments.length, source; arg < argLen; ++arg )
  2701. {
  2702. if ( isObject( source = arguments[arg] ) )
  2703. {
  2704. for ( var key in source )
  2705. {
  2706. /*istanbul ignore else: clean prototypes assumed*/
  2707. if ( hasOwnProperty.call( source, key ) )
  2708. _target[key] = source[key];
  2709. }
  2710. }
  2711. }
  2712. return _target;
  2713. };
  2714. // End of ES6 polyfill scope
  2715. }
  2716. if ( (6) < 7 )
  2717. {
  2718. /**
  2719. * The Object.values() method returns an array of a given object's own enumerable property values,
  2720. * in the same order as that provided by a for...in loop
  2721. * (the difference being that a for-in loop enumerates properties in the prototype chain as well).
  2722. * @param {object} _target The object to enumerate.
  2723. * @returns {Array} The array of values
  2724. */
  2725. stat.values = function values( _target )
  2726. {
  2727. // Avoid using Array.map for speed (and perform in-place replacement)
  2728. for ( var t = toObject( _target ), result = Object.keys( t ), i = 0, len = result.length; i < len; ++i )
  2729. result[i] = t[result[i]];
  2730. return result;
  2731. };
  2732. /**
  2733. * The Object.entries() method returns an array of a given object's own enumerable property [key, value] pairs,
  2734. * in the same order as that provided by a for...in loop
  2735. * (the difference being that a for-in loop enumerates properties in the prototype chain as well).
  2736. * @param {object} _target The object to enumerate.
  2737. * @returns {Array} The array of values
  2738. */
  2739. stat.entries = function entries( _target )
  2740. {
  2741. // Avoid using Array.map for speed (and perform in-place replacement)
  2742. for ( var t = toObject( _target ), result = Object.keys( t ), i = 0, len = result.length; i < len; ++i )
  2743. result[i] = [ result[i], t[result[i]] ];
  2744. return result;
  2745. };
  2746. // End of ES7 polyfill scope
  2747. }
  2748. // Apply static members (not using exports.polyfill since we only have static members)
  2749. polyMixin( Object, stat, exports, "Object" );
  2750. //
  2751. // ES6 - ES5 Patching
  2752. //
  2753. /*istanbul ignore else: The tests are run with __ES__ set to 3*/
  2754. if ( (6) < 6 )
  2755. {
  2756. // It is possible Object.create exists (natively or polyfilled), but does not support the second
  2757. // argument. In this case, we replace it with a method that will call defineProperties
  2758. // We define this in the ES6 scope since we assume ES7 browsers will all support the optional second argument.
  2759. /*istanbul ignore if: NodeJS's Object.create supports the second argument*/
  2760. if ( Object.create( null, { test: { value: true } } ).test !== true )
  2761. {
  2762. Object.create = ( function( _originalCreate )
  2763. {
  2764. /**
  2765. * Object.create wrapper that adds support for an optional second argument.
  2766. */
  2767. return function create( _proto, _properties )
  2768. {
  2769. var result = _originalCreate.call( Object, _proto ); // Call native Object.create
  2770. if ( _properties )
  2771. exports.defineProperties( result, _properties );
  2772. return result;
  2773. };
  2774. }( Object.create ) );
  2775. }
  2776. }
  2777. // End of module
  2778. }( exports, Object ) );
  2779. /***/ }),
  2780. /* 3 */
  2781. /***/ (function(module, exports, __webpack_require__) {
  2782. // Licensed Materials - Property of IBM
  2783. //
  2784. // IBM Watson Analytics
  2785. //
  2786. // (C) Copyright IBM Corp. 2015
  2787. //
  2788. // US Government Users Restricted Rights - Use, duplication or
  2789. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  2790. /*global Map*/
  2791. module.exports = ( (6) >= 6 ) || ( typeof Map !== "undefined" ) ? Map : /*istanbul ignore next*/ __webpack_require__( 4 );
  2792. /***/ }),
  2793. /* 4 */
  2794. /***/ (function(module, exports, __webpack_require__) {
  2795. // Licensed Materials - Property of IBM
  2796. //
  2797. // IBM Watson Analytics
  2798. //
  2799. // (C) Copyright IBM Corp. 2015
  2800. //
  2801. // US Government Users Restricted Rights - Use, duplication or
  2802. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  2803. module.exports = ( function( ObjectPolyfill, EntryStore )
  2804. {
  2805. "use strict";
  2806. // Putting this in a var allows uglify to minify the code much more
  2807. var SET_SIZE = !( ( (6) >= 5 ) || ObjectPolyfill.propertyGetSetSupport );
  2808. /**
  2809. * @classdesc Iterator for the Map polyfill.
  2810. * @class module:barejs/polyfill.Map~MapIterator
  2811. * @extends module:barejs/polyfill.EntryStore.Iterator
  2812. */
  2813. function MapIterator( _kind, _store )
  2814. {
  2815. EntryStore.Iterator.call( this, _kind, _store );
  2816. }
  2817. MapIterator.prototype = Object.create( EntryStore.Iterator.prototype,
  2818. /** @lends module:barejs/polyfill.Map~MapIterator */
  2819. {
  2820. constructor: { writable: true, value: MapIterator }
  2821. } );
  2822. /**
  2823. * @classdesc Mimics the implementation of a native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Map}.
  2824. * Has an O(n) lookup time for non String or Number keys, so cannot compete with a native Map (Which is supposed to have an O(1) lookup time).
  2825. * @class module:barejs/polyfill.Map
  2826. */
  2827. function Map()
  2828. {
  2829. ObjectPolyfill.defineProperty( this, "_store", { value: new EntryStore( arguments[0], true ) } );
  2830. /*istanbul ignore if: NodeJS has property support*/
  2831. if ( SET_SIZE )
  2832. this.size = this._store.size;
  2833. }
  2834. ObjectPolyfill.defineProperties( Map.prototype,
  2835. /** @lends module:barejs/polyfill.Map# */
  2836. {
  2837. _store: { value: null },
  2838. /**
  2839. * The size of the Map, which represents the number of entries currently in the Map.
  2840. * @member {number}
  2841. * @readonly
  2842. */
  2843. size: ( SET_SIZE ?
  2844. /*istanbul ignore next*/ { writable: true, value: null } :
  2845. { "get": function size(){ return this._store && this._store.size; } } ),
  2846. /**
  2847. * Set a value for the specified key in the Map.
  2848. * @function
  2849. * @param _key The object to use as key.
  2850. * @param _value The value to add.
  2851. * @returns {module:barejs/polyfill.Map} The Map (for chaining)
  2852. */
  2853. "set": { value: function set( _key, _value )
  2854. {
  2855. this._store.set( _key, _value );
  2856. /*istanbul ignore if: NodeJS has property support*/
  2857. if ( SET_SIZE )
  2858. this.size = this._store.size;
  2859. return this;
  2860. } },
  2861. /**
  2862. * Get the value for the specified key
  2863. * @function
  2864. * @param {object} _key The object to use as key.
  2865. * @returns The value, or undefined if the key is not known.
  2866. */
  2867. "get": { value: function get( _key )
  2868. {
  2869. var entry = this._store.entries[this._store.indexOf( _key )];
  2870. return entry && entry[1];
  2871. } },
  2872. /**
  2873. * Check if the Map has an entry for the specified key
  2874. * @function
  2875. * @param {object} _key The object to use as key.
  2876. * @returns {boolean} True if there is an entry for the key, false otherwise
  2877. */
  2878. has: { value: function has( _key )
  2879. {
  2880. return this._store.indexOf( _key ) >= 0;
  2881. } },
  2882. /**
  2883. * Remove the value for the specified key
  2884. * @function
  2885. * @param {object} _key The object to use as key.
  2886. * @returns {boolean} True if the entry was deleted, false otherwise
  2887. */
  2888. "delete": { value: function _delete( _key )
  2889. {
  2890. var removed = this._store.remove( _key );
  2891. /*istanbul ignore if: NodeJS has property support*/
  2892. if ( SET_SIZE )
  2893. this.size = this._store.size;
  2894. return removed;
  2895. } },
  2896. clear: { value: function clear()
  2897. {
  2898. this._store.clear();
  2899. /*istanbul ignore if: NodeJS has property support*/
  2900. if ( SET_SIZE )
  2901. this.size = this._store.size;
  2902. } },
  2903. /**
  2904. * Iterate the Map
  2905. * @function
  2906. * @param {function} _callback The callback function.
  2907. * @param [_thisArg] Optional: context to call the callback in.
  2908. */
  2909. forEach: { value: function forEach( _callback/*, _thisArg*/ )
  2910. {
  2911. this._store.forEach( this, _callback, arguments[1] );
  2912. } },
  2913. /**
  2914. * Get a key iterator
  2915. * @function
  2916. * @returns {module:barejs/polyfill.Map~MapIterator} A key iterator
  2917. */
  2918. keys: { value: function keys()
  2919. {
  2920. return new MapIterator( "key", this._store );
  2921. } },
  2922. /**
  2923. * Get a value iterator
  2924. * @function
  2925. * @returns {module:barejs/polyfill.Map~MapIterator} A value iterator
  2926. */
  2927. values: { value: function values()
  2928. {
  2929. return new MapIterator( "value", this._store );
  2930. } },
  2931. /**
  2932. * Get an entry iterator
  2933. * @function
  2934. * @returns {module:barejs/polyfill.Map~MapIterator} A entry iterator
  2935. */
  2936. entries: { value: function entries()
  2937. {
  2938. return new MapIterator( "entry", this._store );
  2939. } }
  2940. } );
  2941. ObjectPolyfill.setIterator( Map.prototype, Map.prototype.entries );
  2942. return Map;
  2943. }( __webpack_require__( 2 ), __webpack_require__( 5 ) ) );
  2944. /***/ }),
  2945. /* 5 */
  2946. /***/ (function(module, exports, __webpack_require__) {
  2947. // Licensed Materials - Property of IBM
  2948. //
  2949. // IBM Watson Analytics
  2950. //
  2951. // (C) Copyright IBM Corp. 2015
  2952. //
  2953. // US Government Users Restricted Rights - Use, duplication or
  2954. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  2955. module.exports = ( function( ObjectPolyfill )
  2956. {
  2957. "use strict";
  2958. /**
  2959. * EntryStore provides the actual Map (and Set) implementation. Its implementation is shaped by two features:
  2960. * 1. Attempt to achieve the O(1) lookup time of the native Map and Set types (for String and Number values).
  2961. * 2. Support iterators according to the spec.
  2962. *
  2963. * Since we don't want to track iterators (as that would keep them alive indefinitely if iteration is aborted before end),
  2964. * the EntryStore never re-uses or changes an entry index.
  2965. * This allows iterators to keep pointing at a specific entry index, and look at the actual situation during the next call.
  2966. * @class module:barejs/polyfill.EntryStore
  2967. * @param {*} [_iterable] Optional: an iterable whose values will be added to the EntryStore.
  2968. * @param {boolean} [_pair] Optional: if the EntryStore is used for a Map, this should be true
  2969. * (iterable's values should be interpreted as key-value pairs, not as single values).
  2970. */
  2971. function EntryStore( _iterable, _pair )
  2972. {
  2973. this.entries = Object.create( null );
  2974. // Note: skip index 0 so it is safe to use the entry index in boolean expressions.
  2975. this.entries.start = this.entries.end = 1;
  2976. this.clear();
  2977. if ( _iterable )
  2978. {
  2979. // Use Array.from for iteration, as it normalizes iterables for us.
  2980. // Only downside is that we're creating an array that is thrown away
  2981. Array.from( _iterable, _pair === true ? this._setPair : this._setValue, this );
  2982. }
  2983. }
  2984. ObjectPolyfill.polyfill( EntryStore, null,
  2985. /** @lends module:barejs/polyfill.EntryStore# */
  2986. {
  2987. _setPair: function( _value )
  2988. {
  2989. if ( typeof _value !== "object" )
  2990. throw new TypeError( "Iterator value " + String( _value ) + " is not an entry object" );
  2991. this.set( _value[0], _value[1] );
  2992. },
  2993. _setValue: function( _value )
  2994. {
  2995. this.set( _value, _value );
  2996. },
  2997. /**
  2998. * Find the next valid index, starting at _start
  2999. * @param {number} _start The index to start looking at. If _start is in entries, start is returned.
  3000. * @returns {number} The next valid index, or -1 if there is no next entry.
  3001. */
  3002. _nxt: function( _start )
  3003. {
  3004. for ( var i = Math.max( _start || 0, this.entries.start ), end = this.entries.end; i < end; ++i )
  3005. if ( i in this.entries )
  3006. return i;
  3007. return -1;
  3008. },
  3009. /**
  3010. * Find the entry index for a key
  3011. * @param _key The key to get the entry index for
  3012. * @param _key The key to get the entry index for
  3013. * @returns {number} The entry index, or -1
  3014. */
  3015. indexOf: function( _key )
  3016. {
  3017. switch ( typeof _key )
  3018. {
  3019. case "string":
  3020. return this._stringKeys[ _key ] || -1;
  3021. case "number":
  3022. return this._numberKeys[ String( _key ) ] || -1;
  3023. default:
  3024. return this._otherKeyIds[ this._otherKeys.indexOf( _key ) ] || -1;
  3025. }
  3026. },
  3027. /**
  3028. * Set the entry for a key
  3029. * @param {*} _key The key for the value.
  3030. * @param {*} _value The value to set.
  3031. */
  3032. "set": function( _key, _value )
  3033. {
  3034. var idx = this.indexOf( _key );
  3035. if ( idx < 0 )
  3036. {
  3037. idx = this.entries.end++;
  3038. ++this.size;
  3039. switch ( typeof _key )
  3040. {
  3041. case "string":
  3042. this._stringKeys[ _key ] = idx;
  3043. break;
  3044. case "number":
  3045. this._numberKeys[ String( _key ) ] = idx;
  3046. break;
  3047. default:
  3048. this._otherKeys.push( _key );
  3049. this._otherKeyIds.push( idx );
  3050. break;
  3051. }
  3052. this.entries[idx] = [_key, _value];
  3053. }
  3054. else
  3055. {
  3056. this.entries[idx][1] = _value;
  3057. }
  3058. },
  3059. /**
  3060. * Remove _key from the EntryStore
  3061. * @param {*} _key The key to remove the value for
  3062. * @returns {boolean} True if the value for _key got removed, false otherwise.
  3063. */
  3064. remove: function( _key )
  3065. {
  3066. var idx;
  3067. switch ( typeof _key )
  3068. {
  3069. case "string":
  3070. if ( ( idx = this._stringKeys[ _key ] || -1 ) >= 0 )
  3071. delete this._stringKeys[ _key ];
  3072. break;
  3073. case "number":
  3074. if ( ( idx = this._numberKeys[ String( _key ) ] || -1 ) >= 0 )
  3075. delete this._numberKeys[ String( _key ) ];
  3076. break;
  3077. default:
  3078. if ( ( idx = this._otherKeys.indexOf( _key ) ) >= 0 )
  3079. {
  3080. // Remove key
  3081. this._otherKeys.splice( idx, 1 );
  3082. // Remove index mapping, and update idx to the entry index
  3083. idx = this._otherKeyIds.splice( idx, 1 )[0];
  3084. }
  3085. break;
  3086. }
  3087. var remove = idx >= 0;
  3088. if ( remove )
  3089. {
  3090. // We already moved the key mapping, but we still need to drop the entry
  3091. // (and potentially update the start value)
  3092. delete this.entries[idx];
  3093. --this.size;
  3094. if ( idx === this.entries.start )
  3095. {
  3096. // If we removed the "start" value, update it
  3097. idx = this._nxt( idx + 1 );
  3098. this.entries.start = idx < 0 ? this.entries.end : idx;
  3099. }
  3100. }
  3101. return remove;
  3102. },
  3103. /**
  3104. * Clear the EntryStore, removing all keys and associated values.
  3105. */
  3106. clear: function()
  3107. {
  3108. this._numberKeys = Object.create( null );
  3109. this._stringKeys = Object.create( null );
  3110. this._otherKeys = [];
  3111. this._otherKeyIds = [];
  3112. this.size = 0;
  3113. // drop all entries
  3114. for ( var i = this.entries.start, end = this.entries.end; i < end; ++i )
  3115. delete this.entries[i];
  3116. // Update start to end
  3117. this.entries.start = this.entries.end;
  3118. },
  3119. /**
  3120. * Iterate the EntryStore (on behalf of _iterated)
  3121. * @param {module:barejs/polyfill.EntryStore} _iterated The object to report as being iterated.
  3122. * Since the EntryStore is an internal object to be used by a Set or Map it has to report the correct object.
  3123. * @param {function} Callback: the iterator callback to call for every entry. Called with ( &lt;key&gt;, &lt;value&gt;, _iterated ).
  3124. * @param {object} [_thisArg] Optional: object to use as context for the callback function
  3125. */
  3126. forEach: function( _iterated, _callback, _thisArg )
  3127. {
  3128. // Do NOT cache end, adding entries during iteration is allowed
  3129. for ( var o = ObjectPolyfill.ensureCallable( _callback, _thisArg && Object( _thisArg ) ), i = this._nxt(), entry; i >= 0; i = this._nxt( i + 1 ) )
  3130. {
  3131. entry = this.entries[i];
  3132. _callback.call( o, entry[1], entry[0], _iterated );
  3133. }
  3134. }
  3135. }, null, "EntryStore" );
  3136. // This is NOT the native Iterator...
  3137. //jshint -W121
  3138. /**
  3139. * @class module:barejs/polyfill.EntryStore.Iterator
  3140. * @classdesc Base class Iterator for a class using the EntryStore
  3141. */
  3142. function Iterator( _kind, _store )
  3143. {
  3144. this._kind = _kind;
  3145. this._next = _store._nxt();
  3146. if ( this._next >= 0 )
  3147. this._store = _store;
  3148. }
  3149. ObjectPolyfill.polyfill( Iterator, null,
  3150. /** @lends module:barejs/polyfill.EntryStore.Iterator# */
  3151. {
  3152. /**
  3153. * Get the next value
  3154. * @returns {object} An object containing a done and value property.
  3155. */
  3156. next: function next()
  3157. {
  3158. var entry, // Note: entry is used to get an undefined value (minification optimisation)
  3159. result = { value: entry, done: this._next < 0 };
  3160. if ( !result.done )
  3161. {
  3162. var store = this._store,
  3163. // use _nxt to check if there is still an entry at _next
  3164. next = this._next = store._nxt( this._next );
  3165. // If we're done iterating, remove the reference to _store
  3166. if ( next < 0 )
  3167. {
  3168. // All entries at next (and possibly afterwards) got removed, mark the iterator done
  3169. result.done = true;
  3170. // Clear link to _store since we don't need it anymore
  3171. this._store = null;
  3172. }
  3173. else
  3174. {
  3175. entry = store.entries[next];
  3176. switch ( this._kind )
  3177. {
  3178. case "key":
  3179. result.value = entry[0];
  3180. break;
  3181. case "value":
  3182. result.value = entry[1];
  3183. break;
  3184. default:
  3185. // Don't expose our inner array, make a copy
  3186. result.value = entry.slice( 0, 2 );
  3187. break;
  3188. }
  3189. this._next = store._nxt( next + 1 );
  3190. }
  3191. }
  3192. return result;
  3193. }
  3194. }, null, "Iterator" );
  3195. ObjectPolyfill.defineProperty( EntryStore, "Iterator", { value: Iterator } );
  3196. ObjectPolyfill.setIterator( Iterator.prototype, /*istanbul ignore next*/ function()
  3197. {
  3198. //jshint validthis:true
  3199. return this;
  3200. } );
  3201. return EntryStore;
  3202. }( __webpack_require__( 2 ) ) );
  3203. /***/ }),
  3204. /* 6 */
  3205. /***/ (function(module, exports, __webpack_require__) {
  3206. // Licensed Materials - Property of IBM
  3207. //
  3208. // IBM Watson Analytics
  3209. //
  3210. // (C) Copyright IBM Corp. 2015
  3211. //
  3212. // US Government Users Restricted Rights - Use, duplication or
  3213. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  3214. /*global Set*/
  3215. module.exports = ( (6) >= 6 ) || ( typeof Set !== "undefined" ) ? Set : /*istanbul ignore next*/ __webpack_require__( 7 );
  3216. /***/ }),
  3217. /* 7 */
  3218. /***/ (function(module, exports, __webpack_require__) {
  3219. // Licensed Materials - Property of IBM
  3220. //
  3221. // IBM Watson Analytics
  3222. //
  3223. // (C) Copyright IBM Corp. 2015
  3224. //
  3225. // US Government Users Restricted Rights - Use, duplication or
  3226. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  3227. module.exports = ( function( ObjectPolyfill, EntryStore )
  3228. {
  3229. "use strict";
  3230. // Putting this in a var allows uglify to minify the code much more
  3231. var SET_SIZE = !( ( (6) >= 5 ) || ObjectPolyfill.propertyGetSetSupport );
  3232. /**
  3233. * @classdesc Iterator for the Set polyfill.
  3234. * @class module:barejs/polyfill.Set~SetIterator
  3235. * @extends module:barejs/polyfill.EntryStore.Iterator
  3236. */
  3237. function SetIterator( _kind, _store )
  3238. {
  3239. EntryStore.Iterator.call( this, _kind, _store );
  3240. }
  3241. SetIterator.prototype = Object.create( EntryStore.Iterator.prototype,
  3242. /** @lends module:barejs/polyfill.Set~SetIterator# */
  3243. {
  3244. constructor: { writable : true, value : SetIterator }
  3245. } );
  3246. /**
  3247. * @classdesc Mimics the implementation of a native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set Set}.
  3248. * Has an O(n) lookup time for non String or Number keys, so cannot compete with a native Map (Which is supposed to have an O(1) lookup time).
  3249. * @class module:barejs/polyfill.Set
  3250. */
  3251. function Set()
  3252. {
  3253. ObjectPolyfill.defineProperty( this, "_store", { value: new EntryStore( arguments[0], false ) } );
  3254. /*istanbul ignore if: NodeJS has property support*/
  3255. if ( SET_SIZE )
  3256. this.size = this._store.size;
  3257. }
  3258. ObjectPolyfill.defineProperties( Set.prototype,
  3259. /** @lends module:barejs/polyfill.Set# */
  3260. {
  3261. _store: { value: null },
  3262. /**
  3263. * The size of the Set, which represents the number of entries currently in the Map.
  3264. * @member {number}
  3265. * @readonly
  3266. */
  3267. size: ( SET_SIZE ?
  3268. /*istanbul ignore next*/ { writable: true, value: null } :
  3269. { "get": function size(){ return this._store && this._store.size; } } ),
  3270. /**
  3271. * Adds a value to a Set object.
  3272. * @function
  3273. * @param _value The value to add.
  3274. * @returns {module:barejs/polyfill.Set} The Set (for chaining)
  3275. */
  3276. add: { value: function add( _value )
  3277. {
  3278. this._store.set( _value, _value );
  3279. /*istanbul ignore if: NodeJS has property support*/
  3280. if ( SET_SIZE )
  3281. this.size = this._store.size;
  3282. return this;
  3283. } },
  3284. /**
  3285. * Check if the Set has a specified value.
  3286. * @function
  3287. * @param {object} _value The value to check for.
  3288. * @returns {boolean} True if there is an entry for the value, false otherwise
  3289. */
  3290. has: { value: function has( _value )
  3291. {
  3292. return this._store.indexOf( _value ) >= 0;
  3293. } },
  3294. /**
  3295. * Remove a value from the Set
  3296. * @function
  3297. * @param {object} _value The value to remove.
  3298. * @returns {boolean} True if the value was deleted, false otherwise.
  3299. */
  3300. "delete": { value: function _delete( _value )
  3301. {
  3302. var removed = this._store.remove( _value );
  3303. /*istanbul ignore if: NodeJS has property support*/
  3304. if ( SET_SIZE )
  3305. this.size = this._store.size;
  3306. return removed;
  3307. } },
  3308. /**
  3309. * Clear the Set.
  3310. * @function
  3311. */
  3312. clear: { value: function clear()
  3313. {
  3314. this._store.clear();
  3315. /*istanbul ignore if: NodeJS has property support*/
  3316. if ( SET_SIZE )
  3317. this.size = this._store.size;
  3318. } },
  3319. /**
  3320. * Iterate the Set
  3321. * @function
  3322. * @param {function} _callback The callback function.
  3323. * @param [_thisArg] Optional: context to call the callback in.
  3324. */
  3325. forEach: { value: function forEach( _callback/*, _thisArg*/ )
  3326. {
  3327. this._store.forEach( this, _callback, arguments[1] );
  3328. } },
  3329. /**
  3330. * Get a key iterator
  3331. * @function
  3332. * @returns {module:barejs/polyfill.Set~SetIterator} A key iterator
  3333. */
  3334. keys: { value: function keys()
  3335. {
  3336. return new SetIterator( "key", this._store );
  3337. } },
  3338. /**
  3339. * Get a value iterator
  3340. * @function
  3341. * @returns {module:barejs/polyfill.Set~SetIterator} A value iterator
  3342. */
  3343. values: { value: function values()
  3344. {
  3345. return new SetIterator( "value", this._store );
  3346. } },
  3347. /**
  3348. * Get an entry iterator
  3349. * @function
  3350. * @returns {module:barejs/polyfill.Set~SetIterator} A entry iterator
  3351. */
  3352. entries: { value: function entries()
  3353. {
  3354. return new SetIterator( "entry", this._store );
  3355. } }
  3356. } );
  3357. ObjectPolyfill.setIterator( Set.prototype, Set.prototype.values );
  3358. return Set;
  3359. }( __webpack_require__( 2 ), __webpack_require__( 5 ) ) );
  3360. /***/ }),
  3361. /* 8 */
  3362. /***/ (function(module, exports, __webpack_require__) {
  3363. // Licensed Materials - Property of IBM
  3364. //
  3365. // IBM Watson Analytics
  3366. //
  3367. // (C) Copyright IBM Corp. 2015
  3368. //
  3369. // US Government Users Restricted Rights - Use, duplication or
  3370. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  3371. /*global Symbol*/
  3372. module.exports = ( (6) >= 6 ) || ( typeof Symbol !== "undefined" ) ? Symbol : /*istanbul ignore next*/ __webpack_require__( 9 );
  3373. /***/ }),
  3374. /* 9 */
  3375. /***/ (function(module, exports) {
  3376. // Licensed Materials - Property of IBM
  3377. //
  3378. // IBM Watson Analytics
  3379. //
  3380. // (C) Copyright IBM Corp. 2015
  3381. //
  3382. // US Government Users Restricted Rights - Use, duplication or
  3383. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  3384. module.exports = ( function()
  3385. {
  3386. "use strict";
  3387. var next = 0;
  3388. /**
  3389. * Create a "{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol Symbol}" which is
  3390. * actually just a string (so it works "like" a Symbol in older environments).
  3391. * Symbol is never used with new, it is meant to be invoked as a creator function:
  3392. *
  3393. * var key = Symbol( "description" );
  3394. * var obj = {};
  3395. * obj[key] = "value";
  3396. *
  3397. * @class module:barejs/polyfill.Symbol
  3398. * @throws {TypeError} Throws a TypeError if used as a constructor (with new).
  3399. * @param {string} [_description] Optional: a description of the Symbol that will provide a hint of what the
  3400. * Symbol is for. Only for debug, does not affect the actual Symbol in any way.
  3401. */
  3402. return function Symbol( _description )
  3403. {
  3404. if ( this instanceof Symbol )
  3405. throw new TypeError( "Symbol is not a constructor" );
  3406. return "__" + ( ++next ) + "\x01Symbol(" + ( _description || "" ) + ")";
  3407. };
  3408. }() );
  3409. /***/ }),
  3410. /* 10 */
  3411. /***/ (function(module, exports, __webpack_require__) {
  3412. // Licensed Materials - Property of IBM
  3413. //
  3414. // IBM Watson Analytics
  3415. //
  3416. // (C) Copyright IBM Corp. 2015
  3417. //
  3418. // US Government Users Restricted Rights - Use, duplication or
  3419. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  3420. /*global WeakMap*/
  3421. module.exports = ( (6) >= 6 ) || ( typeof WeakMap !== "undefined" ) ? WeakMap : /*istanbul ignore next*/ __webpack_require__( 11 );
  3422. /***/ }),
  3423. /* 11 */
  3424. /***/ (function(module, exports, __webpack_require__) {
  3425. // Licensed Materials - Property of IBM
  3426. //
  3427. // IBM Watson Analytics
  3428. //
  3429. // (C) Copyright IBM Corp. 2015
  3430. //
  3431. // US Government Users Restricted Rights - Use, duplication or
  3432. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  3433. module.exports = ( function( ObjectPolyfill, Symbol )
  3434. {
  3435. "use strict";
  3436. // The property set by the first keymap that takes an object as key.
  3437. // All WeakMaps look at the same property
  3438. var KEY_PROP = Symbol( "WeakMap" );
  3439. var hOP = Object.prototype.hasOwnProperty;
  3440. var nextId = 0;
  3441. /**
  3442. * Mimics the implementation of a native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap WeakMap}.
  3443. * The only way to achieve this is by putting a property on the key object.
  3444. * @class module:barejs/polyfill.WeakMap
  3445. * @param {any} [_iterable=null] Optional: an iterable whose values will be added to the WeakSet.
  3446. */
  3447. function WeakMap( _iterable )
  3448. {
  3449. // Ensure map has no prototype chain (so we can safely use the in operator instead of hasOwnProperty)
  3450. ObjectPolyfill.defineProperty( this, "_map", { value: Object.create( null ) } );
  3451. if ( _iterable )
  3452. {
  3453. for ( var i = 0; i < _iterable.length; ++i )
  3454. this.set( _iterable[i][0], _iterable[i][1] );
  3455. }
  3456. }
  3457. return ( ObjectPolyfill.defineProperties( WeakMap.prototype,
  3458. /** @lends module:barejs/polyfill.WeakMap# */
  3459. {
  3460. _map: { value: null },
  3461. /**
  3462. * Adds a new element with a specified key and value to a WeakMap object.
  3463. * @function
  3464. * @param {object} _key The object to use as key.
  3465. * @param _value The value to add.
  3466. * @returns {module:barejs/polyfill.WeakMap} The WeakMap (for chaining)
  3467. */
  3468. "set": { value: function set( _key, _value )
  3469. {
  3470. if ( !ObjectPolyfill.isObject( _key ) )
  3471. throw new TypeError( "Invalid value used as weak map key" );
  3472. if ( !hOP.call( _key, KEY_PROP ) )
  3473. ObjectPolyfill.defineProperty( _key, KEY_PROP, { value: ++nextId } );
  3474. this._map[ _key[KEY_PROP] ] = _value;
  3475. return this;
  3476. } },
  3477. /**
  3478. * Get the value for the specified key
  3479. * @function
  3480. * @param {object} _key The object to use as key.
  3481. * @returns The value, or undefined if the key is not known.
  3482. */
  3483. "get": { value: function get( _key )
  3484. {
  3485. return this.has( _key ) ? this._map[ _key[KEY_PROP] ] : undefined;
  3486. } },
  3487. /**
  3488. * Check if the WeakMap has an entry for the specified key
  3489. * @function
  3490. * @param {object} _key The object to use as key.
  3491. * @returns {boolean} True if there is an entry for the key, false otherwise
  3492. */
  3493. has: { value: function has( _key )
  3494. {
  3495. // If there is no WeakMap key property on the object, it has never been used as key for a WeakMap
  3496. return ObjectPolyfill.isObject( _key ) && hOP.call( _key, KEY_PROP ) && ( _key[KEY_PROP] in this._map );
  3497. } },
  3498. /**
  3499. * Remove the value for the specified key
  3500. * @function
  3501. * @param {object} _key The object to use as key.
  3502. * @returns {boolean} True if the entry was deleted, false otherwise
  3503. */
  3504. "delete": { value: function _delete( _key )
  3505. {
  3506. // Remove the entry from our map (will be a NOOP if there is no property for the key value)
  3507. // Note: delete is not called if this.has( _key ) returns false. If the delete statement
  3508. // (incorrectly) returns false, we force it to return true using "|| true".
  3509. return this.has( _key ) && ( ( delete this._map[_key[KEY_PROP]] ) || true );
  3510. } }
  3511. } ), WeakMap );
  3512. }( __webpack_require__( 2 ), __webpack_require__( 8 ) ) );
  3513. /***/ }),
  3514. /* 12 */
  3515. /***/ (function(module, exports, __webpack_require__) {
  3516. // Licensed Materials - Property of IBM
  3517. //
  3518. // IBM Watson Analytics
  3519. //
  3520. // (C) Copyright IBM Corp. 2015, 2018
  3521. //
  3522. // US Government Users Restricted Rights - Use, duplication or
  3523. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  3524. ( function( Array, ObjectPolyfill, NMap, NSet )
  3525. {
  3526. "use strict";
  3527. // This module uses bitwise operators to enforce unsigned ints or perform other optimizations.
  3528. /*jshint bitwise:false*/
  3529. var toObject = ObjectPolyfill.toObject,
  3530. isCallable = ObjectPolyfill.isCallable,
  3531. ensureCallable = ObjectPolyfill.ensureCallable;
  3532. // Store reference to Object.prototype.toString for convenience and to (hopefully) grab the original before modification.
  3533. var toString = Object.prototype.toString;
  3534. /** @lends module:barejs/polyfill.Array */
  3535. var stat = {},
  3536. /** @lends module:barejs/polyfill.Array# */
  3537. proto = {};
  3538. /**
  3539. * Method that performs the actual iteration
  3540. * @memberof module:barejs/polyfill.Array~
  3541. * @private
  3542. */
  3543. function iterate( _arrayLike, _callback, _thisArg, _logic )
  3544. {
  3545. var asString = ( "charAt" in _arrayLike ) && ( "substr" in _arrayLike );
  3546. for ( var i = 0, len = _arrayLike.length >>> 0, value, result; i < len; ++i )
  3547. {
  3548. if ( asString || ( i in _arrayLike ) )
  3549. {
  3550. result = _callback.call( _thisArg, value = asString ? _arrayLike.charAt( i ) : _arrayLike[i], i, _arrayLike );
  3551. if ( _logic( value, i, result ) === true )
  3552. break;
  3553. }
  3554. }
  3555. }
  3556. /**
  3557. * Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array Array}.
  3558. * @class module:barejs/polyfill.Array
  3559. */
  3560. /*istanbul ignore else: We test with __ES__ set to 3*/
  3561. if ( (6) < 5 )
  3562. {
  3563. /**
  3564. * Enumerate all values in the array
  3565. * @this {Array}
  3566. * @param {function} _callback The callback to call for each value
  3567. * @param {object} [_thisArg] Optional: the context in which the callback should be invoked
  3568. */
  3569. proto.forEach = function forEach( _callback/*, _thisArg (method has length 1)*/ )
  3570. {
  3571. iterate( toObject( this, forEach ), ensureCallable( _callback ), arguments[1], function() {/*no logic*/} );
  3572. };
  3573. /**
  3574. * Check if callback returns true for every element
  3575. * @this {Array}
  3576. * @param {function} _callback The callback to test each value
  3577. * @param {object} [_thisArg] Optional: the context in which the callback should be invoked
  3578. * @returns {boolean} True if the callback returns true for each element, false otherwise.
  3579. */
  3580. proto.every = function every( _callback/*, _thisArg (method has length 1)*/ )
  3581. {
  3582. var result = true;
  3583. iterate( toObject( this, every ), ensureCallable( _callback ), arguments[1], function( _v, _i, _r )
  3584. {
  3585. // If the callback returned a falsey value
  3586. if ( !_r )
  3587. {
  3588. // The every statement doesn't hold true
  3589. result = false;
  3590. // Break execution
  3591. return true;
  3592. }
  3593. } );
  3594. return result;
  3595. };
  3596. /**
  3597. * Check if callback returns true for any element
  3598. * @this {Array}
  3599. * @param {function} _callback The callback to test each value
  3600. * @param {object} [_thisArg] Optional: the context in which the callback should be invoked
  3601. * @returns {boolean} True if the callback returns true for at least one element, false otherwise.
  3602. */
  3603. proto.some = function some( _callback/*, _thisArg (method has length 1)*/ )
  3604. {
  3605. var result = false;
  3606. iterate( toObject( this, some ), ensureCallable( _callback ), arguments[1], function( _v, _i, _r )
  3607. {
  3608. // If the callback returned a thruthy value, the some statement is true (shortcuted to return true for breaking)
  3609. if ( _r )
  3610. return ( result = true );
  3611. } );
  3612. return result;
  3613. };
  3614. /**
  3615. * Creates a new array with only the elements matching the provided function.
  3616. * @this {Array}
  3617. * @param {function} _callback The callback to test each value.
  3618. * @param {object} [_thisArg] Optional: the context in which the callback should be invoked
  3619. * @returns {Array} A new array containing the result of callback per element.
  3620. */
  3621. proto.filter = function filter( _callback/*, _thisArg (method has length 1)*/ )
  3622. {
  3623. var result = [];
  3624. iterate( toObject( this, filter ), ensureCallable( _callback ), arguments[1], function( _v, _i, _r )
  3625. {
  3626. // If the callback returned a thruthy value, add the value to the result
  3627. if ( _r )
  3628. result.push( _v );
  3629. } );
  3630. return result;
  3631. };
  3632. /**
  3633. * Creates a new array with the results of calling a provided function on every element in this array.
  3634. * @this {Array}
  3635. * @param {function} _callback The callback to test each value
  3636. * @param {object} [_thisArg] Optional: the context in which the callback should be invoked
  3637. * @returns {Array} A new array containing the result of callback per element.
  3638. */
  3639. proto.map = function map( _callback/*, _thisArg (method has length 1)*/ )
  3640. {
  3641. var o = toObject( this, map ), result = new Array( o.length >>> 0 );
  3642. iterate( o, ensureCallable( _callback ), arguments[1], function( _v, _i, _r )
  3643. {
  3644. result[_i] = _r;
  3645. } );
  3646. return result;
  3647. };
  3648. /**
  3649. * Returns the first index at which a given element can be found in the array, or -1 if it is not present.
  3650. * @this {Array}
  3651. * @param {object} _searchElement Element to locate in the array.
  3652. * @param {number} [_fromIndex=0] Optional: The index to start the search at. Default: 0
  3653. * If the index is greater than or equal to the array's length, -1 is returned, which means
  3654. * the array will not be searched. If the provided index value is a negative number, it is
  3655. * taken as the offset from the end of the array. Note: if the provided index is negative,
  3656. * the array is still searched from front to back. If the calculated index is less than 0,
  3657. * then the whole array will be searched.
  3658. * @returns {number} The first index at which a given element can be found in the array, or -1 if it is not present.
  3659. */
  3660. proto.indexOf = function indexOf( _searchElement/*, _fromIndex*/ )
  3661. {
  3662. var t = toObject( this, indexOf ), len = t.length >>> 0, i = 0;
  3663. if ( len < 1 )
  3664. return -1;
  3665. if ( arguments.length >= 2 )
  3666. {
  3667. if ( ( i = arguments[1] >> 0 ) < 0 )
  3668. i = Math.max( 0, len + i );
  3669. }
  3670. for ( ; i < len; ++i )
  3671. if ( ( i in t ) && ( t[i] === _searchElement ) )
  3672. return i;
  3673. return -1;
  3674. };
  3675. /**
  3676. * Returns the last index at which a given element can be found in the array, or -1 if it is not present.
  3677. * The array is searched backwards, starting at fromIndex.
  3678. * @this {Array}
  3679. * @param {object} _searchElement Element to locate in the array.
  3680. * @param {number} [_fromIndex=-1] Optional: The index at which to start searching backwards.
  3681. * Defaults to the array's length - 1, i.e. the whole array will be searched. If the index is
  3682. * greater than or equal to the length of the array, the whole array will be searched.
  3683. * If negative, it is taken as the offset from the end of the array. Note that even when
  3684. * the index is negative, the array is still searched from back to front. If the calculated
  3685. * index is less than 0, -1 is returned, i.e. the array will not be searched.
  3686. * @returns {number} The last index at which a given element can be found in the array, or -1 if it is not present.
  3687. */
  3688. proto.lastIndexOf = function lastIndexOf( _searchElement/*, _fromIndex*/ )
  3689. {
  3690. var t = toObject( this, lastIndexOf ), len = t.length >>> 0, i = len - 1;
  3691. if ( len < 1 )
  3692. return -1;
  3693. if ( arguments.length >= 2 )
  3694. {
  3695. if ( ( i = Math.min( i, arguments[1] >> 0 ) ) < 0 )
  3696. i += len;
  3697. }
  3698. for ( ; i >= 0; --i )
  3699. if ( ( i in this ) && ( this[i] === _searchElement ) )
  3700. return i;
  3701. return -1;
  3702. };
  3703. /**
  3704. * The reduce() method applies a function against an accumulator and each value of the
  3705. * array (from left-to-right) has to reduce it to a single value.
  3706. * @this {Array}
  3707. * @param {function} _callback The callback to call for each value, taking 4 arguments:
  3708. * previousValue
  3709. * The value previously returned in the last invocation of the callback, or initialValue, if supplied. (See below.)
  3710. * currentValue
  3711. * The current element being processed in the array.
  3712. * index
  3713. * The index of the current element being processed in the array.
  3714. * array
  3715. * The array reduce was called upon.
  3716. * @param {object} [_initialValue] Optional: a value to pass to the first callback.
  3717. */
  3718. proto.reduce = function reduce( _callback/*, _initialValue*/ )
  3719. {
  3720. var t = toObject( this, reduce ), len = t.length >>> 0, i = ensureCallable( _callback, 0 ), value;
  3721. if ( arguments.length >= 2 )
  3722. {
  3723. value = arguments[1];
  3724. }
  3725. else
  3726. {
  3727. while ( ( i < len ) && !( i in t ) )
  3728. ++i;
  3729. if ( i >= len )
  3730. throw new TypeError( "Reduce of empty array with no initial value" );
  3731. value = t[i++];
  3732. }
  3733. for (; i < len; ++i)
  3734. {
  3735. if ( i in t )
  3736. value = _callback( value, t[i], i, t );
  3737. }
  3738. return value;
  3739. };
  3740. /**
  3741. * The reduceRight() method applies a function against an accumulator and each value of the
  3742. * array (from right-to-left) has to reduce it to a single value.
  3743. * @this {Array}
  3744. * @param {function} _callback The callback to call for each value, taking 4 arguments:
  3745. * previousValue
  3746. * The value previously returned in the last invocation of the callback, or initialValue, if supplied. (See below.)
  3747. * currentValue
  3748. * The current element being processed in the array.
  3749. * index
  3750. * The index of the current element being processed in the array.
  3751. * array
  3752. * The array reduce was called upon.
  3753. * @param {object} [_initialValue] Optional: a value to pass to the first callback.
  3754. */
  3755. proto.reduceRight = function reduceRight( _callback/*, _initialValue*/ )
  3756. {
  3757. var t = toObject( this, reduceRight ), len = t.length >>> 0, i = ensureCallable( _callback, len - 1 ), value;
  3758. if ( arguments.length >= 2 )
  3759. {
  3760. value = arguments[1];
  3761. }
  3762. else
  3763. {
  3764. while ( ( i >= 0 ) && !( i in t ) )
  3765. --i;
  3766. if ( i < 0 )
  3767. throw new TypeError( "Reduce of empty array with no initial value" );
  3768. value = t[i--];
  3769. }
  3770. for (; i >= 0; --i)
  3771. {
  3772. if ( i in t )
  3773. value = _callback( value, t[i], i, t );
  3774. }
  3775. return value;
  3776. };
  3777. /**
  3778. * Check if an object is an array.
  3779. * @param _arg The object to check.
  3780. * @returns {boolean} true if an object is an array, false if it is not.
  3781. */
  3782. stat.isArray = function isArray( _arg )
  3783. {
  3784. return toString.call( _arg ) === "[object Array]";
  3785. };
  3786. // End of ES5 polyfill scope
  3787. }
  3788. /*istanbul ignore else: We test with __ES__ set to 3 */
  3789. if ( (6) < 6 )
  3790. {
  3791. /**
  3792. * Find a value in the array
  3793. * @param {function} _callback The callback to test each value in the array. If the value matches, it should return true.
  3794. * @param {object} [_thisArg] Optional: the context in which the callback should be invoked
  3795. * @returns the found value or undefined if not found.
  3796. */
  3797. proto.find = function find( _callback/*, _thisArg (method has length 1)*/ )
  3798. {
  3799. var result = void undefined;
  3800. iterate( toObject( this, find ), ensureCallable( _callback ), arguments[1], function( _v, _i, _r )
  3801. {
  3802. // If the callback returned a thruthy value, the result is found
  3803. if ( _r )
  3804. {
  3805. result = _v;
  3806. // Break the loop
  3807. return true;
  3808. }
  3809. } );
  3810. return result;
  3811. };
  3812. /**
  3813. * Find a value in the array
  3814. * @param {function} _callback The callback to test each value in the array. If the value matches, it should return true.
  3815. * @param {object} [_thisArg] Optional: the context in which the callback should be invoked
  3816. * @returns {number} the found index or -1 if not found.
  3817. */
  3818. proto.findIndex = function findIndex( _callback/*, _thisArg (method has length 1)*/ )
  3819. {
  3820. var result = -1;
  3821. iterate( toObject( this, findIndex ), ensureCallable( _callback ), arguments[1], function( _v, _i, _r )
  3822. {
  3823. // If the callback returned a thruthy value, the result is found
  3824. if ( _r )
  3825. {
  3826. result = _i;
  3827. // Break the loop
  3828. return true;
  3829. }
  3830. } );
  3831. return result;
  3832. };
  3833. /**
  3834. * The fill() method fills all the elements of an array from a start index to an end index with a static value.
  3835. * @param _value The value to set to each index
  3836. * @param {number} [_start=0] Optional: the index to start filling (inclusive)
  3837. * If _start is negative, it is treated as length + _start.
  3838. * @param {number} [_end] Optional: the index at which to stop filling (exclusive)
  3839. * If _end is negative, it is treated as length + _end.
  3840. */
  3841. proto.fill = function fill( _value/*, _start, _end*/ )
  3842. {
  3843. var t = toObject( this, fill ), len = t.length >>> 0, i = arguments[1] >> 0, end = arguments[2];
  3844. if ( i < 0 )
  3845. i = Math.max( 0, i + len );
  3846. if ( end === undefined )
  3847. end = len;
  3848. else if ( end < 0 )
  3849. end = Math.max( 0, end + len );
  3850. for ( ; i < end; ++i )
  3851. t[i] = _value;
  3852. return t;
  3853. };
  3854. /**
  3855. * The Array.of() method creates a new Array instance with a variable number of arguments,
  3856. * regardless of number or type of the arguments.
  3857. * @param {...any} _value Any number of values that will be the content of the array.
  3858. * @returns {Array} The created Array.
  3859. */
  3860. stat.of = function of()
  3861. {
  3862. var C = this;
  3863. var args = arguments;
  3864. var len = args.length;
  3865. var result = isCallable( C ) ? Object( new C( len ) ) : new Array( len );
  3866. for ( var i = 0; i < len; ++i )
  3867. result[i] = args[i];
  3868. return result;
  3869. };
  3870. /**
  3871. * The Array.from() method creates a new Array instance from an array-like or iterable object.
  3872. * @param {object} _arrayLike An array-like or iterable object to convert to an array.
  3873. * @param {function} [_mapFn] Optional. Map function to call on every element of the array.
  3874. * @param {object} [_thisArg] Optional. Value to use as this when executing mapFn.
  3875. * @returns {Array} The created Array.
  3876. */
  3877. stat.from = function from( _arrayLike/*, _mapFn, _thisArg*/ )
  3878. {
  3879. var C = this;
  3880. var items = toObject( _arrayLike );
  3881. var mapFn = typeof arguments[1] !== "undefined" ? ensureCallable( arguments[1] ) : null;
  3882. var thisArg = arguments[2];
  3883. // Iterators can't be emulated, but add specific logic for Map and Set so those are supported
  3884. // Note: check both for a potential global and the polyfill separately:
  3885. // NMap and Map MAY point to the same function, but don't have to in every environment (!).
  3886. var isMap = items instanceof NMap;
  3887. // Normalize to an Array, source. Chances are high we can just return this Array, or map it in place.
  3888. var source;
  3889. var i, len;
  3890. if ( mapFn )
  3891. {
  3892. if ( thisArg === undefined )
  3893. thisArg = null;
  3894. else if ( thisArg !== null )
  3895. thisArg = Object( thisArg );
  3896. }
  3897. var it = isCallable( items.next ) ? items : ObjectPolyfill.getIterator( items );
  3898. if ( it )
  3899. {
  3900. source = [];
  3901. for ( var cur = it.next(); !cur.done; cur = it.next() )
  3902. source.push( cur.value );
  3903. len = source.length;
  3904. }
  3905. // IE11's native map and set support forEach, but not iterators. Emulate using forEach.
  3906. else if ( ( isMap || ( items instanceof NSet ) ) && isCallable( items.forEach ) )
  3907. {
  3908. i = 0;
  3909. len = Math.floor( items.size ) || 0;
  3910. source = new Array( len );
  3911. items.forEach( function( _value, _key )
  3912. {
  3913. var entry;
  3914. if ( isMap )
  3915. {
  3916. entry = new Array( 2 );
  3917. entry[0] = _key;
  3918. entry[1] = _value;
  3919. }
  3920. else
  3921. {
  3922. entry = _value;
  3923. }
  3924. source[ i++ ] = entry;
  3925. } );
  3926. }
  3927. if ( !source )
  3928. {
  3929. var asString = ( "charAt" in items ) && ( "substr" in items );
  3930. len = Math.floor( items.length ) || 0;
  3931. source = new Array( len );
  3932. for ( i = 0; i < len; ++i )
  3933. source[i] = asString ? items.charAt( i ) : items[i];
  3934. }
  3935. // We already have an Array (source), only create a new Object if we have a Constructor as context
  3936. var result = isCallable( C ) && C !== Array ? Object( new C( len ) ) : source;
  3937. if ( mapFn || result !== source )
  3938. {
  3939. for ( i = 0; i < len; ++i )
  3940. result[i] = mapFn ? mapFn.call( thisArg, source[i], i ) : source[i];
  3941. }
  3942. return result;
  3943. };
  3944. // End of ES6 polyfill scope
  3945. }
  3946. /*istanbul ignore else: We test with __ES__ set to 3*/
  3947. if ( (6) < 7 )
  3948. {
  3949. /**
  3950. * The includes() method determines whether an array includes a certain element, returning true or false as appropriate.
  3951. * The array is searched forwards, starting at fromIndex (defaults to 0).
  3952. * @param {object} _searchElement Element to locate in the array.
  3953. * @param {object} [_fromIndex=0] Optional: The index to start the search at. Default: 0
  3954. * If the index is greater than or equal to the array's length, -1 is returned, which means
  3955. * the array will not be searched. If the provided index value is a negative number, it is
  3956. * taken as the offset from the end of the array. Note: if the provided index is negative,
  3957. * the array is still searched from front to back. If the calculated index is less than 0,
  3958. * then the whole array will be searched.
  3959. * @returns {boolean} True if the element was found, false otherwise.
  3960. */
  3961. proto.includes = function includes( _searchElement/*, _fromIndex*/ )
  3962. {
  3963. var t = toObject( this, includes ), len = t.length >>> 0, i = 0;
  3964. if ( len < 1 )
  3965. return false;
  3966. if ( arguments.length > 1 )
  3967. {
  3968. if ( ( i = arguments[1] >> 0 ) < 0 )
  3969. i = Math.max( 0, len + i );
  3970. }
  3971. for ( ; i < len; ++i )
  3972. if ( ( t[i] === _searchElement ) || ( _searchElement !== _searchElement && t[i] !== t[i] ) )
  3973. return true;
  3974. return false;
  3975. };
  3976. // End of ES7 polyfill scope
  3977. }
  3978. ObjectPolyfill.polyfill( Array, stat, proto, exports, "Array" );
  3979. // End of module
  3980. }( Array, __webpack_require__( 2 ), __webpack_require__( 3 ), __webpack_require__( 6 ) ) );
  3981. /***/ }),
  3982. /* 13 */
  3983. /***/ (function(module, exports, __webpack_require__) {
  3984. // Licensed Materials - Property of IBM
  3985. //
  3986. // IBM Watson Analytics
  3987. //
  3988. // (C) Copyright IBM Corp. 2015, 2018
  3989. //
  3990. // US Government Users Restricted Rights - Use, duplication or
  3991. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  3992. module.exports = ( function(
  3993. ObjectPolyfill,
  3994. decl,
  3995. WeakMap,
  3996. WeakSet
  3997. )
  3998. {
  3999. "use strict";
  4000. /*jshint latedef:false*/
  4001. var DestroyableKey = null;
  4002. // Try to use an ES6 symbol and be very protective of the destroyed flag.
  4003. var DestroyedObjects = new WeakSet();
  4004. // grab Array.prototype.map
  4005. var map = Array.prototype.map;
  4006. /**
  4007. * Takes a _target and attempts to resolve it to a Destroyable, even if it is an interface proxy.
  4008. * @memberof module:barejs.Destroyable~
  4009. * @private
  4010. */
  4011. function resolveTarget( _target )
  4012. {
  4013. return decl.isProxy( _target ) && _target.is( Destroyable ) ? _target.as( DestroyableKey ) : Object( _target );
  4014. }
  4015. /**
  4016. * Check if _target is destroyed.
  4017. * @param {module:barejs.Destroyable~Destroyable} _target The destroyable to check
  4018. * @returns {boolean} True if the target has been destroyed, false otherwise.
  4019. * @memberof module:barejs.Destroyable
  4020. */
  4021. function isDestroyed( _target )
  4022. {
  4023. return !!_target && DestroyedObjects.has( resolveTarget( _target ) );
  4024. }
  4025. /**
  4026. * @class module:barejs.Destroyable~MetaData
  4027. * @private
  4028. */
  4029. function MetaData()
  4030. {
  4031. this.listeners = [];
  4032. this.references = [];
  4033. this.referenceHandlers = [];
  4034. }
  4035. decl.declareClass( MetaData,
  4036. /** @lends module:barejs.Destroyable~MetaData */
  4037. {
  4038. listeners: null,
  4039. references: null,
  4040. referenceHandlers: null
  4041. } );
  4042. /**
  4043. * Anonymous function closure to keep the WeakMap protected. By using a WeakMap MetaData objects
  4044. * have no explicit link back to the Destroyable objects.
  4045. * @param {WeakMap} _map WeakMap to store the MetaData objects in.
  4046. * @ignore
  4047. */
  4048. ( function( _map )
  4049. {
  4050. /**
  4051. * Get MetaData for a Destroyable
  4052. * @param {module:barejs.Destroyable} _destroyable The Destroyable instance
  4053. * @param {boolean} _create Set to true to create the metadata if it doesn't exist.
  4054. * @returns {module:barejs.Destroyable~MetaData} The meta data, or null (if create is false and there is none)
  4055. */
  4056. MetaData.get = function( _destroyable, _create )
  4057. {
  4058. var meta = _map.get( _destroyable ) || null;
  4059. if ( ( !meta ) && ( _create === true ) )
  4060. _map.set( _destroyable, meta = new MetaData() );
  4061. return meta;
  4062. };
  4063. /**
  4064. * Remove MetaData for a Destroyable.
  4065. * @param {module:barejs.Destroyable} _destroyable The Destroyable instance
  4066. * @returns {module:barejs.Destroyable~MetaData} The removed meta data, or null
  4067. */
  4068. MetaData.remove = function( _destroyable )
  4069. {
  4070. var meta = _map.get( _destroyable ) || null;
  4071. if ( meta )
  4072. _map["delete"]( _destroyable );
  4073. return meta;
  4074. };
  4075. }( new WeakMap() ) );
  4076. /**
  4077. * function that can be applied to an array to remove an item
  4078. * @this {Array}
  4079. * @memberof module:barejs.Destroyable~
  4080. * @private
  4081. */
  4082. function Array_remove( _item )
  4083. {
  4084. /*jshint validthis:true*/
  4085. var idx = this.indexOf( _item );
  4086. /*istanbul ignore else: the if statement is purely a sanity check*/
  4087. if ( idx >= 0 )
  4088. this.splice( idx, 1 );
  4089. return idx >= 0;
  4090. }
  4091. /**
  4092. * Helper function that will destroy _target, if it is not null/undefined.
  4093. * @param {module:barejs.Destroyable} _target The target to destroy.
  4094. * @memberof module:barejs.Destroyable~
  4095. * @private
  4096. */
  4097. function destroyTarget( _target/*, _index*/ )
  4098. {
  4099. if ( !_target )
  4100. return;
  4101. _target = Object( _target );
  4102. if ( "destroy" in _target )
  4103. _target.destroy();
  4104. // Compatibility with dojo handles
  4105. else if ( "remove" in _target )
  4106. _target.remove();
  4107. }
  4108. /**
  4109. * @class module:barejs.Destroyable~OwnedHandle
  4110. * @private
  4111. * @classdesc Tracks an ownership and destroys links when needed
  4112. */
  4113. function OwnedHandle( _owner, _target )
  4114. {
  4115. this.owner = _owner;
  4116. this.target = _target;
  4117. _owner.addDestroyListener( this._owner_destroyed = this._owner_destroyed.bind( this ) );
  4118. if ( this.target instanceof Destroyable )
  4119. this.target.addDestroyListener( this._target_destroyed = this._target_destroyed.bind( this ) );
  4120. }
  4121. decl.declareClass( OwnedHandle,
  4122. /** @lends module:barejs.Destroyable~OwnedHandle# */
  4123. {
  4124. owner: null,
  4125. target: null,
  4126. _owner_destroyed: function()
  4127. {
  4128. /*istanbul ignore next: We actively remove listeners on destroy, so we don't expect to hit this safety guard*/
  4129. if ( !this.target )
  4130. return;
  4131. // Destroyable::ref will take care of deleting any reference to this object
  4132. // By deleting the owner before calling destroy, we are sure _target_destroyed will not
  4133. // perform any logic
  4134. delete this.owner;
  4135. // We are about to call destroy, so there's no point in getting the notification
  4136. if ( this.target instanceof Destroyable )
  4137. this.target.removeDestroyListener( this._target_destroyed );
  4138. destroyTarget( this.target );
  4139. delete this._owner_destroyed;
  4140. delete this._target_destroyed;
  4141. delete this.target;
  4142. },
  4143. _target_destroyed: function()
  4144. {
  4145. /*istanbul ignore next: We actively remove listeners on destroy, so we don't expect to hit this safety guard*/
  4146. if ( !this.owner )
  4147. return;
  4148. this.owner.removeDestroyListener( this._owner_destroyed );
  4149. delete this._owner_destroyed;
  4150. delete this._target_destroyed;
  4151. delete this.owner;
  4152. delete this.target;
  4153. }
  4154. } );
  4155. /**
  4156. * @class module:barejs.Destroyable
  4157. * @classdesc Class that adds lifetime management to JavaScript objects. Destroyable provides a few features to ensure
  4158. * the JavaScript garbage collector can recollect memory as soon as possible.
  4159. *
  4160. * A Destroyable instance can own other objects. The ownership in this case implies: if this instance is destroyed,
  4161. * the instance I own should also be destroyed. Destroyable can own any object having either a destroy or remove method.
  4162. *
  4163. * A Destroyable instance can also ref other objects. The reference is automatically cleared on destroy. If the ref-ed
  4164. * object is a Destroyable, the reference is also cleared if the target gets destroyed.
  4165. *
  4166. * Owned objects are also destroyed if this Destroyable is destroyed.
  4167. * Referenced objects are automatically unlinked if this object is destroyed, and even if the referenced
  4168. * is destroyed (in case the referenced object is Destroyable).
  4169. */
  4170. function Destroyable()
  4171. {
  4172. /*istanbul ignore else: We always test in DEBUG*/
  4173. if ( true )
  4174. Destroyable.alive.add( this );
  4175. }
  4176. DestroyableKey = decl.preventCast( Destroyable );
  4177. // Protected hidden functions of Destroyable
  4178. /**
  4179. * Code that actually ties a target to an owner
  4180. * @param {module:barejs.Destroyable} _target The target to own
  4181. * @this {module:barejs.Destroyable}
  4182. * @memberof module:barejs.Destroyable~
  4183. * @private
  4184. */
  4185. function __own( _target/*used as iterator callback*/ )
  4186. {
  4187. // jshint validthis:true
  4188. var actualTarget = resolveTarget( _target );
  4189. if ( !actualTarget || !( ( "destroy" in actualTarget ) || ( "remove" in actualTarget ) ) )
  4190. throw new TypeError( "Cannot own; invalid value" );
  4191. else if ( actualTarget === this )
  4192. throw new Error( "An object cannot own itself" );
  4193. // Note the use of the comma operator; we don't need to store a reference to the OwnedHandle instance,
  4194. // it just needs to be created. Using the comma operator avoid jshint warnings about using new for side-effects.
  4195. return new OwnedHandle( this, actualTarget ), _target;
  4196. }
  4197. // Static array to track created Destroyable objects that haven't been destroyed yet
  4198. /*istanbul ignore else: We always test in DEBUG*/
  4199. if ( true )
  4200. decl.defineProperty( Destroyable, "alive", { value: new WeakSet() } );
  4201. // All methods of Destroyable are non-enumerable and protected from modification
  4202. return decl.declareClass( Destroyable,
  4203. /** @lends module:barejs.Destroyable */
  4204. {
  4205. // Don't inherit static alive/isDestroyed values
  4206. $private:
  4207. {
  4208. value: function( _key )
  4209. {
  4210. return _key === "isDestroyed" || _key === "alive";
  4211. }
  4212. },
  4213. // Protect isDestroyed method from tampering. We're not exposing this on instance level since it's
  4214. // not a common operation.
  4215. isDestroyed: { value: isDestroyed }
  4216. },
  4217. /** @lends module:barejs.Destroyable# */
  4218. {
  4219. /**
  4220. * Destroy method that will notify registered listeners and clean up references.
  4221. * @function
  4222. */
  4223. destroy:
  4224. {
  4225. // Subclasses must be able to add custom destroy logic, so allow writing destroy
  4226. writable: true,
  4227. value: function destroy()
  4228. {
  4229. if ( isDestroyed( this ) )
  4230. return;
  4231. var meta = MetaData.remove( this ), i, len;
  4232. if ( meta )
  4233. {
  4234. // Invoke listeners before clearing references, in case listeners need to look at them
  4235. if ( meta.listeners.length > 0 )
  4236. {
  4237. for ( i = 0, len = meta.listeners.length; i < len; ++i )
  4238. meta.listeners[i]( this );
  4239. // Also explicitly clear the array to drop references to listeners
  4240. meta.listeners.length = 0;
  4241. }
  4242. // Clear references
  4243. if ( meta.references.length > 0 )
  4244. {
  4245. // Don't call unref since it will mutate the references array
  4246. for ( i = 0, len = meta.references.length; i < len; ++i )
  4247. {
  4248. if ( meta.referenceHandlers[i] )
  4249. resolveTarget( this[ meta.references[i] ] ).removeDestroyListener( meta.referenceHandlers[i] );
  4250. delete this[ meta.references[i] ];
  4251. }
  4252. // Clear the arrays
  4253. meta.references.length = 0;
  4254. meta.referenceHandlers.length = 0;
  4255. }
  4256. }
  4257. /*istanbul ignore else: We always test in DEBUG*/
  4258. if ( true )
  4259. Destroyable.alive["delete"]( this );
  4260. DestroyedObjects.add( this );
  4261. }
  4262. },
  4263. /**
  4264. * Register a destroy listener for this Destroyable object.
  4265. * @function
  4266. * @param {module:barejs.Destroyable~DestroyListener} _listener The listener function to add.
  4267. * @returns {function} the listener
  4268. */
  4269. addDestroyListener:
  4270. {
  4271. value: function addDestroyListener( _listener )
  4272. {
  4273. var meta = MetaData.get( this, true );
  4274. meta.listeners.push( ObjectPolyfill.ensureCallable( _listener ) );
  4275. return _listener;
  4276. }
  4277. },
  4278. /**
  4279. * Unregister a destroy listener for this Destroyable object.
  4280. * @function
  4281. * @param {module:barejs.Destroyable~DestroyListener} _listener The listener function to remove.
  4282. */
  4283. removeDestroyListener:
  4284. {
  4285. value: function removeDestroyListener( _listener )
  4286. {
  4287. var meta = MetaData.get( this, false );
  4288. return ( !!meta ) && Array_remove.call( meta.listeners, _listener );
  4289. }
  4290. },
  4291. /**
  4292. * Own a number of handles. Returns an array of the owned handles.
  4293. * @function
  4294. * @returns {Array} The owned handles.
  4295. */
  4296. own:
  4297. {
  4298. value: function own( /*...*/ )
  4299. {
  4300. return map.call( arguments, __own, this );
  4301. }
  4302. },
  4303. /**
  4304. * Reference a target as a member property that will be unlinked on destroy.
  4305. * If the referenced target is also Destroyable, the ref is also cleared if the target is destroyed.
  4306. * @function
  4307. * @param {string} _name The name to reference.
  4308. * @param {object} _target The object to assign to the reference.
  4309. * @returns The value of this[_name].
  4310. */
  4311. ref:
  4312. {
  4313. value: function ref( _name, _target )
  4314. {
  4315. if ( typeof _name !== "string" )
  4316. throw new TypeError( "Name must be a string" );
  4317. // typeof null === "object", but we don't want to allow it
  4318. switch ( _target === null ? "undefined" : typeof _target )
  4319. {
  4320. // Functions can create a circular reference via closures (or being bound to this).
  4321. case "function":
  4322. // Referencing objects might cause circular references
  4323. case "object":
  4324. // So we allow referencing them
  4325. break;
  4326. case "undefined":
  4327. throw new TypeError( "_target cannot be " + _target + ". Use unref to clear a reference." );
  4328. default:
  4329. throw new TypeError( "_target cannot be " + ( typeof _target ) + ". Only objects or functions can be referenced." );
  4330. }
  4331. var meta = MetaData.get( this, true ),
  4332. idx = meta.references.indexOf( _name ),
  4333. actualTarget;
  4334. if ( idx < 0 ) // Add reference
  4335. {
  4336. idx = meta.references.push( _name ) - 1;
  4337. meta.referenceHandlers.push( null );
  4338. }
  4339. else if ( meta.referenceHandlers[idx] ) // Update/change reference
  4340. {
  4341. actualTarget = resolveTarget( this[_name] );
  4342. if ( actualTarget instanceof Destroyable )
  4343. actualTarget.removeDestroyListener( meta.referenceHandlers[idx] );
  4344. meta.referenceHandlers[idx] = null;
  4345. }
  4346. decl.defineProperty( this, _name,
  4347. {
  4348. configurable: true,
  4349. enumerable: ObjectPolyfill.shouldBeEnumerable( _name ),
  4350. value: _target
  4351. } );
  4352. actualTarget = resolveTarget( _target );
  4353. // If the thing we are referencing is a Destroyable, ensure it is unref-ed if the target gets destroyed.
  4354. if ( actualTarget instanceof Destroyable )
  4355. actualTarget.addDestroyListener( meta.referenceHandlers[idx] = this.unref.bind( this, _name ) );
  4356. return _target;
  4357. }
  4358. },
  4359. /**
  4360. * Remove a reference (by name). If the name was given to ownMember, the member is NOT
  4361. * removed from the list of owned targets.
  4362. * Does NOT destroy the value currently referenced.
  4363. * @function
  4364. * @param {string} _name the name to remove the reference to
  4365. * @param {object|function} [_value] If a value is provided (and is not null), unref will only clear the reference if _value equals whatever is currently ref-ed.
  4366. */
  4367. unref:
  4368. {
  4369. value: function unref( _name )
  4370. {
  4371. if ( typeof _name !== "string" )
  4372. throw new TypeError( "_name must be a string" );
  4373. var result/* = undefined*/, value = arguments[1], meta, idx, handler;
  4374. if ( ( meta = MetaData.get( this, false ) ) && ( ( idx = meta.references.indexOf( _name ) ) >= 0 ) )
  4375. {
  4376. result = this[ meta.references[idx] ];
  4377. // If a second argument is supplied, we validate it equals the value to unref
  4378. if ( value && !decl.is( result, value ) )
  4379. {
  4380. result = undefined; // value did not match
  4381. }
  4382. else
  4383. {
  4384. delete this[ meta.references.splice( idx, 1 )[0] ];
  4385. // Since we splice the name, we need to splice the handlers too; otherwise the references and handlers will go out of sync.
  4386. // If a "target" is provided, assume we got called as a destroy listener; in that case we don't unregister since we got here from that listener.
  4387. if ( ( handler = meta.referenceHandlers.splice( idx, 1 )[0] ) && ( !value ) )
  4388. resolveTarget( result ).removeDestroyListener( handler );
  4389. }
  4390. }
  4391. return result;
  4392. }
  4393. },
  4394. /**
  4395. * The ownMember function combines ref and own into 1 call. The target is owned and then ref-ed as _name.
  4396. * @function
  4397. * @param {string} _name The name of the member.
  4398. * @param {module:barejs.Destroyable} _target The target to own.
  4399. * @returns The owned _target
  4400. */
  4401. ownMember:
  4402. {
  4403. value: function ownMember( _name, _target )
  4404. {
  4405. // use __own directly since it avoids the overhead of Array.prototype.map
  4406. // Also, call __own before ref, since it does some stricter validation.
  4407. return this.ref( _name, __own.call( this, _target ) );
  4408. }
  4409. },
  4410. /**
  4411. * Utility method that will iterate a collection and destroy all items in it.
  4412. * @function
  4413. * @param {object} _collection An object with a forEach method or length property (e.g. an Array).
  4414. */
  4415. destroyAll:
  4416. {
  4417. value: function destroyAll( _collection )
  4418. {
  4419. var c = Object( _collection );
  4420. if ( "forEach" in c )
  4421. c.forEach( destroyTarget, null );
  4422. else if ( "length" in c )
  4423. Array.prototype.forEach.call( c, destroyTarget, null );
  4424. else
  4425. throw new TypeError( "_collection must either have a forEach method or a length property." );
  4426. }
  4427. }
  4428. } );
  4429. /**
  4430. * Destroy listeners are called with one argument; the Destroyed object.
  4431. * @callback module:barejs.Destroyable~DestroyListener
  4432. * @param {module:barejs.Destroyable} _destroyed The Destroyable that got destroyed.
  4433. */
  4434. // End of module
  4435. }(
  4436. __webpack_require__( 2 ),
  4437. __webpack_require__( 1 ),
  4438. __webpack_require__( 10 ),
  4439. __webpack_require__( 14 )
  4440. ) );
  4441. /***/ }),
  4442. /* 14 */
  4443. /***/ (function(module, exports, __webpack_require__) {
  4444. // Licensed Materials - Property of IBM
  4445. //
  4446. // IBM Watson Analytics
  4447. //
  4448. // (C) Copyright IBM Corp. 2015
  4449. //
  4450. // US Government Users Restricted Rights - Use, duplication or
  4451. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  4452. /*global WeakSet*/
  4453. module.exports = ( (6) >= 6 ) || ( typeof WeakSet !== "undefined" ) ? WeakSet : /*istanbul ignore next*/ __webpack_require__( 15 );
  4454. /***/ }),
  4455. /* 15 */
  4456. /***/ (function(module, exports, __webpack_require__) {
  4457. // Licensed Materials - Property of IBM
  4458. //
  4459. // IBM Watson Analytics
  4460. //
  4461. // (C) Copyright IBM Corp. 2015
  4462. //
  4463. // US Government Users Restricted Rights - Use, duplication or
  4464. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  4465. module.exports = ( function( ObjectPolyfill, Symbol )
  4466. {
  4467. "use strict";
  4468. // The property set by the first WeakSet that takes an object as key.
  4469. // All WeakSets look at the same property
  4470. var KEY_PROP = Symbol( "WeakSet" );
  4471. var hOP = Object.prototype.hasOwnProperty;
  4472. var nextId = 0;
  4473. /**
  4474. * Mimics the implementation of a native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet WeakSet}.
  4475. * The only way to achieve this is by putting a property on the added value.
  4476. * @class module:barejs/polyfill.WeakSet
  4477. * @param {*} [_iterable]: Optional: an iterable whose values will be added to the WeakSet.
  4478. */
  4479. function WeakSet( _iterable )
  4480. {
  4481. if ( _iterable )
  4482. {
  4483. for ( var i = 0; i < _iterable.length; ++i )
  4484. this.add( _iterable[i] );
  4485. }
  4486. ObjectPolyfill.defineProperty( this, "_values", { value: [] } );
  4487. }
  4488. return ( ObjectPolyfill.defineProperties( WeakSet.prototype,
  4489. /** @lends module:barejs/polyfill.WeakSet# */
  4490. {
  4491. _values: { value: null },
  4492. /**
  4493. * Adds a value to a WeakSet.
  4494. * @function
  4495. * @param _value The value to add.
  4496. * @returns {module:barejs/polyfill.WeakSet} The WeakSet (for chaining)
  4497. */
  4498. add: { value: function add( _value )
  4499. {
  4500. if ( !ObjectPolyfill.isObject( _value ) )
  4501. throw new TypeError( "Invalid value used as WeakSet value" );
  4502. if ( !hOP.call( _value, KEY_PROP ) )
  4503. ObjectPolyfill.defineProperty( _value, KEY_PROP, { value: ++nextId } );
  4504. if ( this._values.indexOf( _value[KEY_PROP] ) < 0 )
  4505. this._values.push( _value[KEY_PROP] );
  4506. return this;
  4507. } },
  4508. /**
  4509. * Check if the WeakSet has an entry for the specified _value.
  4510. * @function
  4511. * @param {object} _value The object to check.
  4512. * @returns {boolean} True if the WeakSet contains _value, false otherwise.
  4513. */
  4514. has: { value: function has( _value )
  4515. {
  4516. // If there is no WeakSet key property on the object, it has never been used as key for a WeakSet
  4517. return ObjectPolyfill.isObject( _value ) && hOP.call( _value, KEY_PROP ) && ( this._values.indexOf( _value[KEY_PROP] ) >= 0 );
  4518. } },
  4519. /**
  4520. * Remove the value from the WeakSet
  4521. * @function
  4522. * @param {object} _value The value to remove.
  4523. * @returns {boolean} True if the value was deleted, false otherwise
  4524. */
  4525. "delete": { value: function _delete( _value )
  4526. {
  4527. var idx = -1;
  4528. if ( ObjectPolyfill.isObject( _value ) && hOP.call( _value, KEY_PROP ) )
  4529. idx = this._values.indexOf( _value[KEY_PROP] );
  4530. if ( idx < 0 )
  4531. return false;
  4532. this._values.splice( idx, 1 );
  4533. return true;
  4534. } }
  4535. } ), WeakSet );
  4536. }( __webpack_require__( 2 ), __webpack_require__( 8 ) ) );
  4537. /***/ }),
  4538. /* 16 */
  4539. /***/ (function(module, exports, __webpack_require__) {
  4540. // Licensed Materials - Property of IBM
  4541. //
  4542. // IBM Watson Analytics
  4543. //
  4544. // (C) Copyright IBM Corp. 2015
  4545. //
  4546. // US Government Users Restricted Rights - Use, duplication or
  4547. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  4548. module.exports = ( function(
  4549. Error,
  4550. ObjectPolyfill,
  4551. decl,
  4552. Destroyable,
  4553. EventArgs,
  4554. WeakMap
  4555. )
  4556. {
  4557. "use strict";
  4558. /*global console*/
  4559. var DEFAULT_ARGS = decl.freeze( new EventArgs() );
  4560. // listenersRef is used by Evented to register and unregister itself.
  4561. var g_listenersRef = new WeakMap();
  4562. // Using a WeakMap prevents circular references and hides the listeners from the object.
  4563. var g_eventHandles = new WeakMap();
  4564. var ensureCallable = ObjectPolyfill.ensureCallable;
  4565. /**
  4566. * Create a new EventedHandle.
  4567. * @class module:barejs.Evented~EventedHandle
  4568. * @classdesc EventedHandle is the handle returned by {@link module:barejs.Evented#on Evented::on} and {@link module:barejs.Evented#once Evented::once}.
  4569. */
  4570. function EventedHandle( _listeners, _eventName, _listener )
  4571. {
  4572. Destroyable.call( this );
  4573. g_listenersRef.set( this, _listeners );
  4574. decl.defineProperties( this,
  4575. {
  4576. eventName: { enumerable: true, value: _eventName },
  4577. listener: { configurable: true, enumerable: true, value: _listener },
  4578. _attached: { writable: true, value: false }
  4579. } );
  4580. this.attach();
  4581. }
  4582. decl.declareClass( EventedHandle, Destroyable,
  4583. /** @lends module:barejs.Evented~EventedHandle# */
  4584. {
  4585. eventName: null,
  4586. listener: null,
  4587. _attached: null,
  4588. /**
  4589. * Destroy the handle.
  4590. */
  4591. destroy: function destroy()
  4592. {
  4593. this.remove();
  4594. delete this.listener;
  4595. g_listenersRef["delete"]( this );
  4596. Destroyable.prototype.destroy.call( this );
  4597. },
  4598. /**
  4599. * Remove the handle. A removed handle can be re-attached using {@link module:barejs.Evented~EventedHandle#attach attach}.
  4600. * @returns {boolean} True if the handle got detached.
  4601. */
  4602. remove: function remove()
  4603. {
  4604. var listeners;
  4605. if ( this._attached && this.listener && ( listeners = g_listenersRef.get( this ) ) )
  4606. {
  4607. // Look up event listeners backwards, since destroy iterates backwards
  4608. var idx = listeners.lastIndexOf( this );
  4609. // If the last listener is removed, use pop, since it doesn't return an Array.
  4610. if ( idx >= ( listeners.length - 1 ) )
  4611. listeners.pop();
  4612. /*istanbul ignore else: this is purely a sanity check, else path should never occur*/
  4613. else if ( idx >= 0 )
  4614. listeners.splice( idx, 1 );
  4615. this._attached = false;
  4616. return true;
  4617. }
  4618. return false;
  4619. },
  4620. /**
  4621. * Attach the handle. A handle is attached by default, this method should only be used after the handle has been detached
  4622. * using {@link module:barejs.Evented~EventedHandle#remove remove}.
  4623. * @returns {boolean} True if the handle is attached.
  4624. */
  4625. attach: function attach()
  4626. {
  4627. var listeners;
  4628. if ( !this._attached && this.listener && ( listeners = g_listenersRef.get( this ) ) )
  4629. {
  4630. listeners.push( this );
  4631. this._attached = true;
  4632. }
  4633. return this._attached;
  4634. },
  4635. /**
  4636. * Check if the handle is attached.
  4637. * @returns {boolean} True if the handle is attached.
  4638. */
  4639. isAttached: function isAttached()
  4640. {
  4641. return this._attached;
  4642. }
  4643. } );
  4644. /**
  4645. * The evented constructor will invoke the Destroyable constructor to ensure the object is initialized correctly.
  4646. * @class module:barejs.Evented
  4647. * @extends module:barejs.Destroyable
  4648. * @classdesc Evented is a base class that adds Eventing to JavaScript Objects.
  4649. * Extends Destroyable to automatically remove listeners if the object is destroyed.
  4650. * If handles given to the listener are {@link module:barejs.Destroyable#own own}ed (or manually destroyed at the appropiate time),
  4651. * the event link between Evented and its listener will be removed as soon as either party is destroyed.
  4652. */
  4653. function Evented()
  4654. {
  4655. Destroyable.call( this );
  4656. }
  4657. decl.preventCast( Evented );
  4658. return decl.declareClass( Evented, Destroyable,
  4659. /** @lends module:barejs.Evented# */
  4660. {
  4661. /**
  4662. * Destroy the Evented object. This will clean up the object, removing any links to listeners.
  4663. */
  4664. destroy: function destroy()
  4665. {
  4666. var handles = g_eventHandles.get( this ) || null;
  4667. if ( handles )
  4668. {
  4669. g_eventHandles["delete"]( this );
  4670. // Note: handles remove themselves from the array, so iterate backwards.
  4671. // Do NOT use Destroyable.destroyAll for this!
  4672. for ( var i = handles.length - 1; i >= 0; --i )
  4673. handles[i].destroy();
  4674. }
  4675. Destroyable.prototype.destroy.call( this );
  4676. },
  4677. /**
  4678. * Listen to an event. To stop listening, call destroy the returned handle. Listeners should {@link module:barejs.Destroyable#own own}
  4679. * the handle returned by this method, so it is automatically disconnected when the listener is destroyed.
  4680. * @param {string} _eventName The event to listen to.
  4681. * @param {module:barejs.Evented~EventListener} _listener The callback to call if the event occurs.
  4682. * @returns {module:barejs.Evented~EventedHandle}
  4683. */
  4684. on: function on( _eventName, _listener )
  4685. {
  4686. var handlers;
  4687. // Note: inline check to see _listener is callable is performed first.
  4688. if ( Destroyable.isDestroyed( ensureCallable( _listener, this )) )
  4689. throw new Error( "The target object has been destroyed, cannot attach an event listener to it" );
  4690. if ( !( ( "on" + _eventName ) in this ) )
  4691. throw new Error( "The target object does not have a(n) " + _eventName + " event" );
  4692. if ( !( handlers = g_eventHandles.get( this ) ) )
  4693. g_eventHandles.set( this, handlers = [] );
  4694. // No need to own the handle; handles are automatically destroyed
  4695. return new EventedHandle( handlers, _eventName, _listener );
  4696. },
  4697. /**
  4698. * Listen for an event, automatically detaching after one invocation of the listener.
  4699. * @param {string} _eventName The event to listen to.
  4700. * @param {module:barejs.Evented~EventListener} _listener The callback to call (once) if the event occurs.
  4701. * @returns {module:barejs.Evented~EventedHandle}
  4702. */
  4703. once: function once( _eventName, _listener )
  4704. {
  4705. // Inline validation of _listener
  4706. var handle = ensureCallable( _listener, null );
  4707. return ( handle = this.on( _eventName, function()
  4708. {
  4709. /*istanbul ignore else: this is purely a sanity check, else path should never occur*/
  4710. if ( handle )
  4711. {
  4712. handle.destroy();
  4713. handle = null;
  4714. }
  4715. // Forward call
  4716. return _listener.apply( this, arguments );
  4717. } ) );
  4718. },
  4719. /**
  4720. * Emit the event with _eventName.
  4721. * @param {string} _eventName The name of the event to emit.
  4722. * @param {module:barejs.EventArgs} _eventArgs the event args to emit.
  4723. * @returns {module:barejs.EventArgs} _eventArgs (or null if not specified).
  4724. */
  4725. emit: function emit( _eventName, _eventArgs )
  4726. {
  4727. if ( Destroyable.isDestroyed( this ) )
  4728. throw new Error( "The target object has been destroyed, cannot emit an event from it" );
  4729. var args = _eventArgs || DEFAULT_ARGS,
  4730. evtDef = "on" + _eventName,
  4731. handles;
  4732. if ( !( evtDef in this ) )
  4733. throw new Error( "The " + _eventName + " event being emitted is not defined. Is this class missing an " + evtDef + " event definition?" );
  4734. if ( !(false) && !( args instanceof EventArgs ) && ( typeof console !== "undefined" ) )
  4735. console.warn( ( this.constructor.name || "Evented" ) + " is emitting the \"" + _eventName + "\" event with arguments that are not EventArgs" );
  4736. // First, call the local method (event definition)
  4737. this[evtDef]( args, this );
  4738. // If there are no handles, there are no listeners, so bail out
  4739. if ( ( handles = g_eventHandles.get( this ) ) && ( handles.length > 0 ) )
  4740. {
  4741. // Get the listeners for this event; using filter gives us a temporary array which is protected
  4742. // from the handles array being modified as a side effect of handler execution.
  4743. var listeners = handles.filter( function( _handle )
  4744. {
  4745. return _handle.eventName === _eventName;
  4746. } );
  4747. // Invoke the event handlers
  4748. for ( var idx = 0, len = listeners.length, handle; idx < len; idx++ )
  4749. {
  4750. // It is possible a handle got removed as a side effect of a previous handler; if so, ignore it.
  4751. if ( ( handle = listeners[idx] )._attached && handle.listener )
  4752. handle.listener( args, this );
  4753. }
  4754. }
  4755. return _eventArgs || null;
  4756. },
  4757. /**
  4758. * Check if there is at least one listener for _eventName. It is highly recommended to just
  4759. * emit an event instead of checking if there are listeners. This method is provided for edge
  4760. * cases where building the event metadata is an expensive process, which should be avoided if
  4761. * there are no listeners.
  4762. * @param {string} _eventName The name of the event to check.
  4763. * @returns {Boolean} True if there is at least one listener, false otherwise.
  4764. */
  4765. hasListener: function( _eventName )
  4766. {
  4767. var handles = g_eventHandles.get( this );
  4768. return ( !!handles ) && handles.some( function( _handle )
  4769. {
  4770. return _handle.eventName === _eventName;
  4771. } );
  4772. }
  4773. } );
  4774. /**
  4775. * Event listeners are called with two arguments; the EventArgs and the sender.
  4776. * @callback module:barejs.Evented~EventListener
  4777. * @param {module:barejs.EventArgs} _eventArgs The EventArgs to the event.
  4778. * @param {module:barejs.Evented} _sender The Evented object that emitted the event.
  4779. */
  4780. // End of module
  4781. }(
  4782. Error,
  4783. __webpack_require__( 2 ),
  4784. __webpack_require__( 1 ),
  4785. __webpack_require__( 13 ),
  4786. __webpack_require__( 17 ),
  4787. __webpack_require__( 10 )
  4788. ) );
  4789. /***/ }),
  4790. /* 17 */
  4791. /***/ (function(module, exports, __webpack_require__) {
  4792. // Licensed Materials - Property of IBM
  4793. //
  4794. // IBM Watson Analytics
  4795. //
  4796. // (C) Copyright IBM Corp. 2015
  4797. //
  4798. // US Government Users Restricted Rights - Use, duplication or
  4799. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  4800. module.exports = ( function( decl )
  4801. {
  4802. "use strict";
  4803. /**
  4804. * Create new EventArgs. Allows specifying a cancelable parameter as optional argument, which defaults to false.
  4805. * @class module:barejs.EventArgs
  4806. * @param {boolean} [_cancelable] Optional: provide a boolean to set whether this event is cancelable (default: prototype value, which is false for EventArgs).
  4807. * @classdesc Base class for event arguments. Mimics html events cancelable behavior for events that have default behavior that can be canceled.
  4808. * Subclasses can set the cancelable flag on their prototype, or use EventArgs.call( this, true ) to propagate the cancelable flag.
  4809. */
  4810. function EventArgs( /*cancelable*/ )
  4811. {
  4812. decl.defineProperties( this,
  4813. {
  4814. // Fixate the cancelable property for this object, either to argument 0 or the prototype value
  4815. cancelable: { enumerable: true, value: ( typeof arguments[0] === "boolean" ? arguments[0] : this.cancelable === true ) },
  4816. // Set defaultPrevented to false
  4817. defaultPrevented: { configurable: true, enumerable: true, value: false }
  4818. } );
  4819. }
  4820. return decl.declareClass( EventArgs,
  4821. /** @lends module:barejs.EventArgs# */
  4822. {
  4823. /**
  4824. * This value is true if the event got canceled (preventDefault was called, and cancelable is true).
  4825. * @member {boolean}
  4826. * @readonly
  4827. */
  4828. defaultPrevented: { enumerable: true, value: null },
  4829. /**
  4830. * The cancelable flag determines whether this event has behavior that can be canceled.
  4831. * @member {boolean}
  4832. * @readonly
  4833. */
  4834. cancelable: { enumerable: true, writable: true, value: false },
  4835. /**
  4836. * The preventDefault method will flag the EventArgs as defaultPrevented, if cancelable is true.
  4837. * @function
  4838. */
  4839. preventDefault:
  4840. {
  4841. enumerable: true,
  4842. value: function preventDefault()
  4843. {
  4844. if ( ( this.cancelable === true ) && !this.defaultPrevented )
  4845. decl.defineProperty( this, "defaultPrevented", { enumerable: true, value: true } );
  4846. }
  4847. }
  4848. } );
  4849. // End of define
  4850. }( __webpack_require__( 1 ) ) );
  4851. /***/ }),
  4852. /* 18 */
  4853. /***/ (function(module, exports, __webpack_require__) {
  4854. // Licensed Materials - Property of IBM
  4855. //
  4856. // IBM Watson Analytics
  4857. //
  4858. // (C) Copyright IBM Corp. 2015
  4859. //
  4860. // US Government Users Restricted Rights - Use, duplication or
  4861. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  4862. /**
  4863. * The BareJS module is the entry point for accessing BareJS's classes and polyfills.
  4864. * @module barejs
  4865. */
  4866. // Start by loading "Built-in object" polyfills, and apply them to barejs
  4867. Object.assign( exports, __webpack_require__( 19 ),
  4868. /** @lends module:barejs */
  4869. {
  4870. // Load BareJS code
  4871. decl : __webpack_require__( 1 ),
  4872. Destroyable : __webpack_require__( 13 ),
  4873. EventArgs : __webpack_require__( 17 ),
  4874. Evented : __webpack_require__( 16 ),
  4875. Exception : __webpack_require__( 35 ),
  4876. /**
  4877. * The BareJS module contains an AMD loader plugin to reference specific parts of BareJS directly.
  4878. * For example, this allows to require "{@link module:barejs.decl barejs!decl}", "{@link module:barejs.Promise barejs!Promise}",
  4879. * "{@link module:barejs.NMap barejs!NMap}" or "{@link module:barejs.Map barejs!Map}"
  4880. */
  4881. load: function( _name, _req, _load )
  4882. {
  4883. "use strict";
  4884. if ( !( _name in exports ) )
  4885. throw new Error( "invalid path: " + _name );
  4886. _load( exports[_name] );
  4887. },
  4888. /**
  4889. * While we want to provide the plugin shortcut to objects, we don't want to build this into a layer.
  4890. */
  4891. write: function()
  4892. {
  4893. "use strict";
  4894. // Don't write anything
  4895. }
  4896. } );
  4897. /***/ }),
  4898. /* 19 */
  4899. /***/ (function(module, exports, __webpack_require__) {
  4900. // Licensed Materials - Property of IBM
  4901. //
  4902. // IBM Watson Analytics
  4903. //
  4904. // (C) Copyright IBM Corp. 2016
  4905. //
  4906. // US Government Users Restricted Rights - Use, duplication or
  4907. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  4908. // Native objects available since the beginning; may contain polyfills for multiple levels of ES compliance.
  4909. // No need to expose these on "polyfill" since they are always available
  4910. __webpack_require__( 12 );
  4911. __webpack_require__( 20 );
  4912. __webpack_require__( 21 );
  4913. __webpack_require__( 22 );
  4914. __webpack_require__( 23 );
  4915. __webpack_require__( 2 );
  4916. __webpack_require__( 24 );
  4917. /**
  4918. * The polyfill module contains polyfills for objects in the ECMAScript specification.
  4919. * @module barejs/polyfill
  4920. */
  4921. Object.assign( exports,
  4922. // Note: although we define this module to be barejs/polyfill, its properties are actually added to barejs, so tell jsdoc about that.
  4923. /** @lends module:barejs */
  4924. {
  4925. /**
  4926. * NMap - Version of Map that prefers the native implementation over the polyfill, even if it doesn't have
  4927. * iterator support (like in Internet Explorer 11). If Iterator support is required, use
  4928. * {@link module:barejs.Map Map} instead.
  4929. * @member {function}
  4930. */
  4931. NMap: __webpack_require__( 3 ),
  4932. /**
  4933. * NSet - Version of Set that prefers the native implementation over the polyfill, even if it doesn't have
  4934. * iterator support (like in Internet Explorer 11). If Iterator support is required, use
  4935. * {@link module:barejs.Set Set} instead.
  4936. * @member {function}
  4937. */
  4938. NSet: __webpack_require__( 6 ),
  4939. // New built-in objects that will be polyfilled (but not globally)
  4940. /**
  4941. * This is either the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl Intl}
  4942. * or the {@link module:barejs/polyfill.Intl fallback} provided by BareJS. Note that BareJS's fallback just provides a similar API,
  4943. * it has not actual localization features. It's main purpose is to gracefully fallback to very limited formatting on
  4944. * environments that don't support Intl. For proper support, load a full Intl polyfill.
  4945. * @member {function}
  4946. */
  4947. Intl: __webpack_require__( 25 ),
  4948. /**
  4949. * This is either the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Map}
  4950. * or the {@link module:barejs/polyfill.Map polyfill} provided by BareJS. This implementation is ensured to have iterator support (using the polyfill), if no
  4951. * iterator support is required it is better to use {@link module:barejs.NMap NMap} instead.
  4952. * @member {function}
  4953. */
  4954. Map: __webpack_require__( 31 ),
  4955. /**
  4956. * This is either the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap WeakMap}
  4957. * or the {@link module:barejs/polyfill.WeakMap polyfill} provided by BareJS.
  4958. * @member {function}
  4959. */
  4960. WeakMap: __webpack_require__( 10 ),
  4961. /**
  4962. * This is either the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set Set}
  4963. * or the {@link module:barejs/polyfill.Set polyfill} provided by BareJS. This implementation is ensured to have iterator support (using the polyfill), if no
  4964. * iterator support is required it is better to use {@link module:barejs.NSet NSet} instead.
  4965. * @member {function}
  4966. */
  4967. Set: __webpack_require__( 32 ),
  4968. /**
  4969. * This is either the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet WeakSet}
  4970. * or the {@link module:barejs/polyfill.WeakSet polyfill} provided by BareJS.
  4971. * @member {function}
  4972. */
  4973. WeakSet: __webpack_require__( 14 ),
  4974. /**
  4975. * This is either the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol Symbol}
  4976. * or the {@link module:barejs/polyfill.Symbol polyfill} provided by BareJS.
  4977. * @member {function}
  4978. */
  4979. Symbol: __webpack_require__( 8 ),
  4980. /**
  4981. * This is either the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise Promise}
  4982. * or the {@link module:barejs/polyfill.Promise polyfill} provided by BareJS.
  4983. * @member {function}
  4984. */
  4985. Promise: __webpack_require__( 33 )
  4986. } );
  4987. /***/ }),
  4988. /* 20 */
  4989. /***/ (function(module, exports, __webpack_require__) {
  4990. // Licensed Materials - Property of IBM
  4991. //
  4992. // IBM Watson Analytics
  4993. //
  4994. // (C) Copyright IBM Corp. 2015
  4995. //
  4996. // US Government Users Restricted Rights - Use, duplication or
  4997. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  4998. ( function( Date, ObjectPolyfill )
  4999. {
  5000. "use strict";
  5001. /**
  5002. * Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date Date}.
  5003. * @class module:barejs/polyfill.Date
  5004. */
  5005. /** @lends module:barejs/polyfill.Date */
  5006. var stat = {};
  5007. /** @lends module:barejs/polyfill.Date# */
  5008. var proto = {};
  5009. /*istanbul ignore else: We test with __ES__ set to 3*/
  5010. if ( (6) < 5 )
  5011. {
  5012. /**
  5013. * The Date.now() method returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.
  5014. * @returns {number} The number of milliseconds.
  5015. */
  5016. stat.now = function now()
  5017. {
  5018. return new Date().getTime();
  5019. };
  5020. ( function()
  5021. {
  5022. /**
  5023. * Ensure the number is _length characters wide.
  5024. * @param {number} _value The number to pad.
  5025. * @param {number} _length The length to pad to. Note: values > 4 are not supported
  5026. * @returns {string} The number, optionally padded with leading zeros
  5027. */
  5028. function padZero( _value, _length )
  5029. {
  5030. var nr = String( _value );
  5031. if ( nr.length < _length )
  5032. nr = "0000".substr( 0, _length - nr.length ) + nr;
  5033. return nr;
  5034. }
  5035. /**
  5036. * The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which
  5037. * is always 24 characters long: YYYY-MM-DDTHH:mm:ss.sssZ. The timezone is always zero UTC
  5038. * offset, as denoted by the suffix "Z".
  5039. * @returns {string} The date formatted as (zero UTC) ISO 8601.
  5040. */
  5041. proto.toISOString = function toISOString()
  5042. {
  5043. // jshint validthis:true
  5044. return padZero( this.getUTCFullYear(), 4 ) +
  5045. "-" + padZero( this.getUTCMonth() + 1, 2 ) +
  5046. "-" + padZero( this.getUTCDate(), 2 ) +
  5047. "T" + padZero( this.getUTCHours(), 2 ) +
  5048. ":" + padZero( this.getUTCMinutes(), 2 ) +
  5049. ":" + padZero( this.getUTCSeconds(), 2 ) +
  5050. "." + ( this.getUTCMilliseconds() / 1000 ).toFixed( 3 ).slice( 2, 5 ) +
  5051. "Z";
  5052. };
  5053. }() );
  5054. // End of ES5 polyfill scope
  5055. }
  5056. ObjectPolyfill.polyfill( Date, stat, proto, exports, "Date" );
  5057. // End of module
  5058. }( Date, __webpack_require__( 2 ) ) );
  5059. /***/ }),
  5060. /* 21 */
  5061. /***/ (function(module, exports, __webpack_require__) {
  5062. // Licensed Materials - Property of IBM
  5063. //
  5064. // IBM Watson Analytics
  5065. //
  5066. // (C) Copyright IBM Corp. 2015
  5067. //
  5068. // US Government Users Restricted Rights - Use, duplication or
  5069. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  5070. ( function( Object, Function, ObjectPolyfill )
  5071. {
  5072. "use strict";
  5073. /**
  5074. * Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function Function}.
  5075. * @class module:barejs/polyfill.Function
  5076. */
  5077. /** @lends module:barejs/polyfill.Function# */
  5078. var proto = {};
  5079. var fnProto = Function.prototype;
  5080. /*istanbul ignore else: We test with __ES__ set to 3*/
  5081. if ( (6) < 5 )
  5082. {
  5083. var slice = Array.prototype.slice;
  5084. /**
  5085. * Bind a function to a specific context. Allows for additional prefix arguments to be specified.
  5086. * @param {object} _thisArg The context to bind this method to.
  5087. * @returns {function} A function that will invoke the original function in the specified context,
  5088. * optionally with additional parameters prefixed.
  5089. */
  5090. proto.bind = function bind( _thisArg /*, ... */ )
  5091. {
  5092. if ( !ObjectPolyfill.isCallable( this ) )
  5093. throw new TypeError( "Bind must be called on a function" );
  5094. var bound, fn = this, args = null, Anonymous = function(){};
  5095. if ( arguments.length > 1 )
  5096. args = slice.call( arguments, 1, arguments.length );
  5097. // Apply almost the same trick as Object.create, so if the bound method is used as a
  5098. // constructor, we do not change the context and the prototype chain is correct.
  5099. // We can't use Object.create since we need the Anonymous type for the instanceof check
  5100. // Prototype is undefined for native functions, so check it first.
  5101. Anonymous.prototype = fn.prototype /*istanbul ignore next*/|| Object.prototype;
  5102. // Only do parameter mangling if required. This optimization provides a significant speed boost
  5103. if ( args && args.length )
  5104. {
  5105. bound = function()
  5106. {
  5107. var len = arguments.length;
  5108. // Only concat the arguments if there are arguments during invocation (to avoid concat)
  5109. // If this bound method is used as a constructor, don't change the context
  5110. return fn.apply( this instanceof Anonymous ? this : _thisArg, len ? args.concat( slice.call( arguments, 0, len ) ) : args );
  5111. };
  5112. }
  5113. else
  5114. {
  5115. bound = function()
  5116. {
  5117. // If this bound method is used as a constructor, don't change the context
  5118. return fn.apply( this instanceof Anonymous ? this : _thisArg, arguments );
  5119. };
  5120. }
  5121. bound.prototype = new Anonymous();
  5122. // technically the bound function should have the same length as the function bound, but we can't emulate that
  5123. return bound;
  5124. };
  5125. }
  5126. ( function()
  5127. {
  5128. var toString = fnProto.toString;
  5129. /*istanbul ignore next: not invoked since NodeJS has a name property on Function.prototype*/
  5130. function name()
  5131. {
  5132. //jshint validthis:true
  5133. if ( this === fnProto )
  5134. return "";
  5135. var match = toString.call( this ).match( /function\s*([a-zA-Z0-9_$]*)\s*\(/ );
  5136. Object.defineProperty( this, "name", { configurable: true, value: ( match && match[1] ) || "" } );
  5137. return this.name;
  5138. }
  5139. // See if the name property isn't exposed, but we can expose it (and it works)
  5140. /*istanbul ignore next: NodeJS has a name property on functions*/
  5141. if ( !name.name && Object.defineProperties && ( name.call( name ) === "name" ) )
  5142. Object.defineProperty( fnProto, "name", { configurable: true, "get": name } );
  5143. }() );
  5144. ObjectPolyfill.polyfill( Function, null, proto, exports, "Function" );
  5145. // End of module
  5146. }( Object, Function, __webpack_require__( 2 ) ) );
  5147. /***/ }),
  5148. /* 22 */
  5149. /***/ (function(module, exports, __webpack_require__) {
  5150. // Licensed Materials - Property of IBM
  5151. //
  5152. // IBM Watson Analytics
  5153. //
  5154. // (C) Copyright IBM Corp. 2015
  5155. //
  5156. // US Government Users Restricted Rights - Use, duplication or
  5157. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  5158. ( function( Math, ObjectPolyfill )
  5159. {
  5160. "use strict";
  5161. // This module polyfills bitwise operations.
  5162. /*jshint bitwise:false*/
  5163. /**
  5164. * Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math Math}.
  5165. * @class module:barejs/polyfill.Math
  5166. */
  5167. /** @lends module:barejs/polyfill.Math */
  5168. var stat = {};
  5169. /*istanbul ignore else: We test with __ES__ set to 3*/
  5170. if ( (6) < 6 )
  5171. {
  5172. /**
  5173. * The Math.cbrt() function returns the cube root of a number.
  5174. * @param {number} _x The number to get the cube root of.
  5175. * @returns {number} The cube root of the number
  5176. */
  5177. stat.cbrt = function cbrt( _x )
  5178. {
  5179. var y = Math.pow( Math.abs( _x ), 1/3 );
  5180. return _x < 0 ? -y : y;
  5181. };
  5182. /**
  5183. * The Math.expm1() function returns e^x - 1, where x is the argument, and e the base of the natural logarithms.
  5184. * @param {number} _x The number.
  5185. * @returns {number} A number representing e^x - 1, where e is Euler's number and x is the argument.
  5186. */
  5187. stat.expm1 = function expm1( _x )
  5188. {
  5189. return Math.exp( _x ) - 1;
  5190. };
  5191. /**
  5192. * The Math.hypot() function returns the square root of the sum of squares of its arguments.
  5193. * @returns {number} The square root of the sum of squares of its arguments.
  5194. */
  5195. stat.hypot = function hypot( _a, _b/*, ...*/ )
  5196. {
  5197. for ( var i = 0, len = arguments.length, y = 0, v; i < len; ++i )
  5198. {
  5199. v = Math.abs( arguments[i] );
  5200. if ( v === Infinity )
  5201. return v;
  5202. y += v * v;
  5203. }
  5204. return Math.sqrt( y );
  5205. };
  5206. /**
  5207. * The Math.imul() function returns the result of the C-like 32-bit multiplication of the two parameters.
  5208. * @param {number} _a Operand A.
  5209. * @param {number} _b Operand B.
  5210. * @returns {number} The result of the multiplication.
  5211. */
  5212. stat.imul = function imul( _a, _b )
  5213. {
  5214. var ah = ( _a >>> 16 ) & 0xffff;
  5215. var al = _a & 0xffff;
  5216. var bh = ( _b >>> 16 ) & 0xffff;
  5217. var bl = _b & 0xffff;
  5218. // the shift by 0 fixes the sign on the high part
  5219. // the final |0 converts the unsigned value into a signed value
  5220. return ( ( al * bl ) + ( ( ( ah * bl + al * bh ) << 16 ) >>> 0 ) | 0 );
  5221. };
  5222. ( function()
  5223. {
  5224. var table = [
  5225. 32, 31, 0, 16, 0, 30, 3, 0, 15, 0, 0, 0, 29, 10, 2, 0,
  5226. 0, 0, 12, 14, 21, 0, 19, 0, 0, 28, 0, 25, 0, 9, 1, 0,
  5227. 17, 0, 4, undefined, 0, 0, 11, 0, 13, 22, 20, 0, 26, 0, 0, 18,
  5228. 5, 0, 0, 23, 0, 27, 0, 6, 0, 24, 7, 0, 8, 0, 0, 0];
  5229. /**
  5230. * The Math.clz32() function returns the number of leading zero bits in the 32-bit binary representation of a number.
  5231. * "clz32" is short for CountLeadingZeroes32.
  5232. * @param {number} _x
  5233. * @returns {number}
  5234. */
  5235. stat.clz32 = function clz32( _x )
  5236. {
  5237. var v = _x >>> 0; // convert to unsigned integer
  5238. v |= v >>> 1;
  5239. v |= v >>> 2;
  5240. v |= v >>> 4;
  5241. v |= v >>> 8;
  5242. v |= v >>> 16;
  5243. return table[ Math.imul( v, 0x06EB14F9 ) >>> 26 ];
  5244. };
  5245. }() );
  5246. /**
  5247. * The Math.log1p() function returns the natural logarithm (base e) of 1 + a number.
  5248. * @param {number} _x The value to get the logarithm of.
  5249. * @returns {number} The logarithm of 1 + _x.
  5250. */
  5251. stat.log1p = function log1p( _x )
  5252. {
  5253. return Math.log( 1 + _x );
  5254. };
  5255. /**
  5256. * The Math.log2() function returns the base 2 logarithm of a number.
  5257. * @param {number} _x The value to get the base 2 logarithm of.
  5258. * @returns {number} The base 2 logarithm of _x.
  5259. */
  5260. stat.log2 = function log2( _x )
  5261. {
  5262. return Math.log( _x ) / Math.LN2;
  5263. };
  5264. /**
  5265. * The Math.log10() function returns the base 10 logarithm of a number.
  5266. * Note that this polyfill is subject to rounding errors.
  5267. * @param {number} _x The value to get the base 10 logarithm of.
  5268. * @returns {number} The base 10 logarithm of _x.
  5269. */
  5270. stat.log10 = function log10( _x )
  5271. {
  5272. return Math.log( _x ) / Math.LN10;
  5273. };
  5274. /**
  5275. * The Math.cosh() function returns the hyperbolic cosine of a number.
  5276. * @param {number} _x The value to calculate the cosine of.
  5277. * @returns {number} The hyperbolic cosine.
  5278. */
  5279. stat.cosh = function cosh( _x )
  5280. {
  5281. var y = Math.exp( _x );
  5282. return ( y + 1 / y ) / 2;
  5283. };
  5284. /**
  5285. * The Math.acosh() function returns the hyperbolic arc-cosine of a number.
  5286. * @param {number} _x The value to calculate the arc-cosine of.
  5287. * @returns {number} The hyperbolic arc-cosine.
  5288. */
  5289. stat.acosh = function acosh( _x )
  5290. {
  5291. return Math.log( _x + Math.sqrt( _x * _x - 1 ) );
  5292. };
  5293. /**
  5294. * The Math.sinh() function returns the hyperbolic sine of a number.
  5295. * @param {number} _x The value to calculate the sine of.
  5296. * @returns {number} The hyperbolic sine.
  5297. */
  5298. stat.sinh = function sinh( _x )
  5299. {
  5300. var y = Math.exp( _x );
  5301. return ( y - 1 / y ) / 2;
  5302. };
  5303. /**
  5304. * The Math.asinh() function returns the hyperbolic arcsine of a number.
  5305. * @param {number} _x The value to calculate the arcsine of.
  5306. * @returns {number} The hyperbolic arcsine.
  5307. */
  5308. stat.asinh = function asinh( _x )
  5309. {
  5310. if ( _x === -Infinity )
  5311. return _x;
  5312. else
  5313. return Math.log( _x + Math.sqrt( _x * _x + 1 ) );
  5314. };
  5315. /**
  5316. * The Math.tanh() function returns the hyperbolic tangent of a number.
  5317. * @param {number} _x The value to calculate the tangent of.
  5318. * @returns {number} The hyperbolic tangent.
  5319. */
  5320. stat.tanh = function tanh( _x )
  5321. {
  5322. var y;
  5323. if ( _x === Infinity )
  5324. return 1;
  5325. else if ( _x === -Infinity )
  5326. return -1;
  5327. else
  5328. return ( ( y = Math.exp( 2 * _x ) ) - 1) / ( y + 1 );
  5329. };
  5330. /**
  5331. * The Math.atanh() function returns the hyperbolic arctangent of a number.
  5332. * @param {number} _x The value to calculate the arctangent of.
  5333. * @returns {number} The hyperbolic arctangent.
  5334. */
  5335. stat.atanh = function atanh( _x )
  5336. {
  5337. return Math.log( ( 1 + _x ) / ( 1 - _x ) ) / 2;
  5338. };
  5339. /**
  5340. * The Math.sign() function returns the sign of a number, indicating whether the number is positive, negative or zero.
  5341. * @param {number} _x The number to check
  5342. * @returns {number} This function has 5 kinds of return values, 1, -1, 0, -0, NaN, which represent
  5343. * "positive number", "negative number", "positive zero", "negative zero" and NaN respectively.
  5344. */
  5345. stat.sign = function sign( _x )
  5346. {
  5347. _x = +_x; // convert to a number
  5348. if ( _x === 0 || isNaN( _x ) )
  5349. return _x;
  5350. return _x > 0 ? 1 : -1;
  5351. };
  5352. /**
  5353. * Unlike other three Math methods: Math.floor(), Math.ceil() and Math.round(), the way
  5354. * Math.trunc() works is very simple and straightforward, just truncate the dot and the digits
  5355. * behind it, no matter whether the argument is a positive number or a negative number.
  5356. * @param {number} _x The number to truncate.
  5357. * @returns {number} The truncated number
  5358. */
  5359. stat.trunc = function trunc( _x )
  5360. {
  5361. return _x < 0 ? Math.ceil( _x ) : Math.floor( _x );
  5362. };
  5363. // End of ES6 polyfill scope
  5364. }
  5365. ObjectPolyfill.polyfill( Math, stat, null, exports, "Math" );
  5366. // End of module
  5367. }( Math, __webpack_require__( 2 ) ) );
  5368. /***/ }),
  5369. /* 23 */
  5370. /***/ (function(module, exports, __webpack_require__) {
  5371. // Licensed Materials - Property of IBM
  5372. //
  5373. // IBM Watson Analytics
  5374. //
  5375. // (C) Copyright IBM Corp. 2015
  5376. //
  5377. // US Government Users Restricted Rights - Use, duplication or
  5378. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  5379. ( function( Number, ObjectPolyfill )
  5380. {
  5381. "use strict";
  5382. /**
  5383. * Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number Number}.
  5384. * @class module:barejs/polyfill.Number
  5385. */
  5386. /** @lends module:barejs/polyfill.Number */
  5387. var stat = {};
  5388. /*istanbul ignore else: We test with __ES__ set to 3*/
  5389. if ( (6) < 6 )
  5390. {
  5391. stat.parseInt = parseInt; // ES6 defines this global should be on Number
  5392. stat.parseFloat = parseFloat; // ES6 defines this global should be on Number
  5393. /**
  5394. * The Number.MAX_SAFE_INTEGER constant represents the maximum safe integer in JavaScript (2<sup>53</sup> - 1).
  5395. * @member {number}
  5396. * @readonly
  5397. */
  5398. stat.MAX_SAFE_INTEGER = 9007199254740991 /*0x1fffffffffffff*/;
  5399. /**
  5400. * The Number.MIN_SAFE_INTEGER constant represents the minimum safe integer in JavaScript (-(2<sup>53</sup> - 1)).
  5401. * @member {number}
  5402. * @readonly
  5403. */
  5404. stat.MIN_SAFE_INTEGER = -stat.MAX_SAFE_INTEGER;
  5405. /**
  5406. * The Number.EPSILON property represents the difference between `1` and the smallest floating point number greater than `1`.
  5407. * @member {number}
  5408. * @readonly
  5409. */
  5410. stat.EPSILON = Math.pow( 2, -52 );
  5411. // Closure to protect the isFinite name
  5412. ( function( _isFinite )
  5413. {
  5414. /**
  5415. * Check if a number is finite. Differs from global isFinite by not coercing types.
  5416. * @param _value the value to check.
  5417. * @returns {boolean} True if _value is a finite number
  5418. */
  5419. stat.isFinite = function isFinite( _value )
  5420. {
  5421. return typeof _value === "number" && _isFinite( _value );
  5422. };
  5423. }( isFinite /* Grab the global isFinite */ ) );
  5424. /**
  5425. * The Number.isInteger() method determines whether the passed value is an integer.
  5426. * @param _value the value to check.
  5427. * @returns {boolean} True if _value is an integer.
  5428. */
  5429. stat.isInteger = function isInteger( _value )
  5430. {
  5431. return Number.isFinite( _value ) && Math.floor( _value ) === _value;
  5432. };
  5433. /**
  5434. * The Number.isSafeInteger() method determines whether the provided value is a number that is a safe integer.
  5435. * A safe integer is an integer that
  5436. * - can be exactly represented as an IEEE-754 double precision number, and
  5437. * - whose IEEE-754 representation cannot be the result of rounding any other integer to fit the IEEE-754 representation.
  5438. * For example, 2<sup>53</sup> - 1 is a safe integer: it can be exactly represented, and no other integer rounds to it under any IEEE-754 rounding mode.
  5439. * In contrast, 2<sup>53</sup> is not a safe integer: it can be exactly represented in IEEE-754, but the integer 2<sup>53</sup> + 1 can't be directly represented in IEEE-754
  5440. * but instead rounds to 2<sup>53</sup> under round-to-nearest and round-to-zero rounding.
  5441. * The safe integers consist of all integers from -(2<sup>53</sup> - 1) inclusive to 2<sup>53</sup> - 1 inclusive.
  5442. * @param {number} _value The value to test
  5443. * @returns {boolean} True if _value is a Number and a safe integer value.
  5444. */
  5445. stat.isSafeInteger = function isSafeInteger( _value )
  5446. {
  5447. return Number.isInteger( _value ) && ( _value >= Number.MIN_SAFE_INTEGER ) && ( _value <= Number.MAX_SAFE_INTEGER );
  5448. };
  5449. // Closure to protect the isNaN name
  5450. ( function( _isNaN )
  5451. {
  5452. /**
  5453. * Check if _value is the special NaN value. Differs from global isNaN by not coercing types.
  5454. * @param _value the value to check.
  5455. * @returns {boolean} True if _value is the NaN value number
  5456. */
  5457. stat.isNaN = function isNaN( _value )
  5458. {
  5459. return typeof _value === "number" && _isNaN( _value );
  5460. };
  5461. }( isNaN /* Grab the global isNaN */ ) );
  5462. // End of ES6 polyfill scope
  5463. }
  5464. ObjectPolyfill.polyfill( Number, stat, null, exports, "Number" );
  5465. // End of module
  5466. }( Number, __webpack_require__( 2 ) ) );
  5467. /***/ }),
  5468. /* 24 */
  5469. /***/ (function(module, exports, __webpack_require__) {
  5470. // Licensed Materials - Property of IBM
  5471. //
  5472. // IBM Watson Analytics
  5473. //
  5474. // (C) Copyright IBM Corp. 2015
  5475. //
  5476. // US Government Users Restricted Rights - Use, duplication or
  5477. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  5478. ( function( Math, RegExp, String, ObjectPolyfill )
  5479. {
  5480. "use strict";
  5481. var strUndef = "undefined";
  5482. /**
  5483. * Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String String}.
  5484. * @class module:barejs/polyfill.String
  5485. */
  5486. /** @lends module:barejs/polyfill.String */
  5487. var stat = {},
  5488. /** @lends module:barejs/polyfill.String# */
  5489. proto = {};
  5490. /*jshint bitwise:false*/
  5491. function stringContext( _context, _name )
  5492. {
  5493. if ( ( typeof _context === strUndef ) || ( _context === null ) )
  5494. throw new TypeError( "String.prototype." + _name + " called on null or undefined" );
  5495. return String( _context );
  5496. }
  5497. function toSearch( _search, _name )
  5498. {
  5499. if ( _search instanceof RegExp )
  5500. throw new TypeError( "First argument to String.prototype." + _name + " must not be a regular expression" );
  5501. return String( _search );
  5502. }
  5503. function toNumber( _value, _min, _default, _max )
  5504. {
  5505. if ( isNaN( _value = Math.trunc( _value ) ) )
  5506. return _default;
  5507. return _value < _min ? _min : ( _value > _max ? _max : _value );
  5508. }
  5509. /*istanbul ignore else: We test with __ES__ set to 3*/
  5510. if ( (6) < 6 )
  5511. {
  5512. /**
  5513. * Check if the string starts with the other string
  5514. * @param {string} _search The part to search for
  5515. * @param {number} [_start=0] Optional: The position in this string at which to begin searching for _search; defaults to 0.
  5516. * @returns {boolean} True if the string starts with search, false otherwise.
  5517. */
  5518. proto.startsWith = function startsWith( _search/*, _start*/ )
  5519. {
  5520. var str = stringContext( this, "startsWith" ),
  5521. pos = toNumber( arguments[1], 0, 0, str.length );
  5522. // Using lastIndexOf ensures we don't search the whole string for _search, just at the requested pos index going back.
  5523. return str.lastIndexOf( toSearch( _search, "startsWith" ), pos ) === pos;
  5524. };
  5525. /**
  5526. * Check if the string ends with the other string
  5527. * @param {string} _search The part to search for
  5528. * @param {number} [_limit] Optional: Search within this string as if this string were only this long;
  5529. * defaults to this string's actual length, clamped within the range established by this string's length.
  5530. * @returns {boolean} True if the string ends with search, false otherwise.
  5531. */
  5532. proto.endsWith = function endsWith( _search/*, _limit*/ )
  5533. {
  5534. var str = stringContext( this, "endsWith" ),
  5535. // We need to start matching at this position
  5536. pos = toNumber( arguments[1], 0, str.length, str.length ) - ( _search = toSearch( _search, "endsWith" ) ).length;
  5537. // Using indexOf ensures we don't search the whole string for _search, just at the requested end index going forward.
  5538. return ( pos >= 0 ) && str.indexOf( _search, pos ) === pos;
  5539. };
  5540. ( function( _whitespace )
  5541. {
  5542. var reTrim = /^\s+|\s+$/g;
  5543. var reTrimStart = /^\s+/;
  5544. var reTrimEnd = /\s+$/;
  5545. /*
  5546. * Attempt to sniff out regular expression engines that do not have all whitespace under the \s character class.
  5547. * If so, build the same regex as above, but with our expanded whitespace class.
  5548. */
  5549. /*istanbul ignore if: This check only fails in very old IE versions (<IE6)*/
  5550. if ( _whitespace.match( /[^\s]/ ) )
  5551. {
  5552. reTrim = new RegExp( "^[\\s" + _whitespace + "]+|[\\s" + _whitespace + "]+$", "g" );
  5553. reTrimStart = new RegExp( "^[\\s" + _whitespace + "]+" );
  5554. reTrimEnd = new RegExp( "[\\s" + _whitespace + "]+$" );
  5555. }
  5556. /**
  5557. * The trim() method removes whitespace from both ends of a string. Whitespace in this context is
  5558. * all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator
  5559. * characters (LF, CR, etc.).
  5560. * @returns {string} The trimmed string.
  5561. */
  5562. proto.trim = function trim()
  5563. {
  5564. // jshint validthis:true
  5565. return stringContext( this, "trim" ).replace( reTrim, "" );
  5566. };
  5567. /**
  5568. * The trimStart() method removes whitespace from the beginning of a string. Whitespace in this context is
  5569. * all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator
  5570. * characters (LF, CR, etc.).
  5571. * @returns {string} The trimmed string.
  5572. */
  5573. proto.trimStart = proto.trimLeft = function trimStart()
  5574. {
  5575. // jshint validthis:true
  5576. return stringContext( this, "trimStart" ).replace( reTrimStart, "" );
  5577. };
  5578. /**
  5579. * The trimEnd() method removes whitespace from the end of a string. Whitespace in this context is
  5580. * all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator
  5581. * characters (LF, CR, etc.).
  5582. * @returns {string} The trimmed string.
  5583. */
  5584. proto.trimEnd = proto.trimRight = function trimEnd()
  5585. {
  5586. // jshint validthis:true
  5587. return stringContext( this, "trimEnd" ).replace( reTrimEnd, "" );
  5588. };
  5589. }( String.fromCharCode(
  5590. // \u00A0, NO-BREAK SPACE
  5591. 160,
  5592. // \u1680, OGHAM SPACE MARK
  5593. 5760,
  5594. // \u2000..\u200A, EN QUAD..HAIR SPACE
  5595. 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202,
  5596. // \u2028, LINE SEPARATOR
  5597. 8232,
  5598. // \u2029, PARAGRAPH SEPARATOR
  5599. 8233,
  5600. // \u202F, NARROW NO-BREAK SPACE
  5601. 8239,
  5602. // \u205F, MEDIUM MATHEMATICAL SPACE
  5603. 8287,
  5604. // \u3000, IDEOGRAPHIC SPACE
  5605. 12288
  5606. ) ) );
  5607. ( function()
  5608. {
  5609. // Ensuring count is a 31-bit integer allows us to heavily optimise the main part of the method.
  5610. // Besides that, browsers that will need this polyfill can't handle strings 1 << 28 chars or longer.
  5611. var LIMIT = 1 << 28;
  5612. /**
  5613. * The repeat() method constructs and returns a new string which contains the specified number
  5614. * of copies of the string on which it was called, concatenated together.
  5615. * @param {number} _count The amount of times to repeat the number.
  5616. * @returns {string} The string, repeated.
  5617. */
  5618. proto.repeat = function repeat( _count )
  5619. {
  5620. // jshint validthis:true
  5621. var rpt = "",
  5622. str = stringContext( this, "repeat" ),
  5623. count = Math.floor( _count ) || 0;
  5624. if ( count < 0 )
  5625. throw new RangeError( "repeat count must be non-negative" );
  5626. if ( count === Infinity )
  5627. throw new RangeError( "repeat count must be less than infinity" );
  5628. // If either string.length or count is 0, we'll get length 0
  5629. var len = str.length * count;
  5630. if ( len >= LIMIT )
  5631. throw new RangeError( "repeat count must not overflow maximum string size" );
  5632. if ( len > 0 )
  5633. {
  5634. // Optimised: concatenates str instead of rpt, to perform the operation with the least
  5635. // amount of string concatenations possible.
  5636. for (;;)
  5637. {
  5638. if ( ( count & 1 ) === 1 )
  5639. rpt += str;
  5640. count >>>= 1;
  5641. if ( count === 0 )
  5642. break;
  5643. str += str;
  5644. }
  5645. }
  5646. return rpt;
  5647. };
  5648. }() );
  5649. /**
  5650. * The codePointAt() method returns a non-negative integer that is the UTF-16 encoded code point value.
  5651. * @param {number} _position The index at which the code point should be read
  5652. * @returns {number} The code point value, or undefined if _position is out of range.
  5653. */
  5654. proto.codePointAt = function codePointAt( _position )
  5655. {
  5656. var str = stringContext( this, "codePointAt" ),
  5657. len = str.length,
  5658. // `ToInteger`
  5659. i = Math.floor( _position ) || 0,
  5660. result;
  5661. // Account for out-of-bounds indices:
  5662. if ( i >= 0 && i < len )
  5663. {
  5664. // Get the first code unit; increment index afterwards
  5665. result = str.charCodeAt( i++ );
  5666. // check if it’s the start of a surrogate pair
  5667. // high surrogate && there is a next code unit
  5668. if ( ( result >= 0xD800 ) && ( result <= 0xDBFF ) && ( i < len ) )
  5669. {
  5670. var pair = str.charCodeAt( i );
  5671. if ( ( pair >= 0xDC00 ) && ( pair <= 0xDFFF ) ) // low surrogate
  5672. result = ( result - 0xD800 ) * 0x400 + pair - 0xDC00 + 0x10000;
  5673. }
  5674. }
  5675. return result;
  5676. };
  5677. /**
  5678. * Create a String from any number of codepoint values
  5679. * @returns {string} The created string
  5680. */
  5681. stat.fromCodePoint = function fromCodePoint( _firstCodePoint )
  5682. {
  5683. var codeUnits = [],
  5684. result = "";
  5685. for ( var i = 0, len = arguments.length; i < len; ++i )
  5686. {
  5687. var codePoint = +( arguments[i] );
  5688. if (
  5689. ( !isFinite( codePoint ) ) || // `NaN`, `+Infinity`, or `-Infinity`
  5690. ( codePoint < 0 ) || ( codePoint > 0x10FFFF ) || // not a valid Unicode code point
  5691. ( Math.floor( codePoint ) !== codePoint ) // not an integer
  5692. )
  5693. {
  5694. throw new RangeError( "Invalid code point: " + codePoint );
  5695. }
  5696. if ( codePoint <= 0xFFFF )
  5697. {
  5698. // BMP code point
  5699. codeUnits.push( codePoint );
  5700. }
  5701. else
  5702. {
  5703. // Astral code point; split in surrogate halves
  5704. codePoint -= 0x10000;
  5705. var highSurrogate = ( codePoint >> 10 ) + 0xD800;
  5706. var lowSurrogate = ( codePoint % 0x400 ) + 0xDC00;
  5707. codeUnits.push( highSurrogate, lowSurrogate );
  5708. }
  5709. if ( ( i + 1 === len ) || ( codeUnits.length > 0x4000 ) )
  5710. {
  5711. result += String.fromCharCode.apply( String, codeUnits );
  5712. codeUnits.length = 0;
  5713. }
  5714. }
  5715. return result;
  5716. };
  5717. /**
  5718. * Check if the string includes the other string
  5719. * @param {string} _search The part to search for
  5720. * @param {number} [_position=0] Optional: The index to start searching at. Defaults to 0.
  5721. * @returns {boolean} True if the string includes search, false otherwise.
  5722. */
  5723. proto.includes = function includes( _search/*, _position*/ )
  5724. {
  5725. var str = stringContext( this, "includes" ),
  5726. pos = toNumber( arguments[1], 0, 0, str.length );
  5727. return str.indexOf( toSearch( _search, "includes" ), pos ) >= 0;
  5728. };
  5729. // End of ES6 polyfill scope
  5730. }
  5731. /*istanbul ignore else: We test with __ES__ set to 3*/
  5732. if ( (6) < 7 )
  5733. {
  5734. /**
  5735. * The padStart() method pads the current string with a given string (eventually repeated) so that the resulting string reaches a given length.
  5736. * The pad is applied from the start (left) of the current string.
  5737. * @param {number} _targetLength The length of the resulting string once the current string has been padded.
  5738. * If this parameter is smaller than the current string's length, the current string will be returned as it is.
  5739. * @param {string} [_padString=" "] The string to pad the current string with.
  5740. * If this string is too long, it will be truncated and the left-most part will be applied.
  5741. * The default value for this parameter is " " (U+0020).
  5742. */
  5743. proto.padStart = function padStart( _targetLength/*, _padString*/ )
  5744. {
  5745. var str = stringContext( this, "padStart" ),
  5746. pad = arguments[1],
  5747. len = Math.trunc( _targetLength ) || 0,
  5748. add = len - str.length,
  5749. pLen,
  5750. pre;
  5751. pad = typeof pad === strUndef ? " " : String( pad );
  5752. pLen = pad.length;
  5753. if ( ( add > 0 ) && ( pLen > 0 ) )
  5754. {
  5755. pre = pad.repeat( Math.floor( add / pLen ) );
  5756. add %= pLen;
  5757. if ( add > 0 )
  5758. pre += pad.substr( 0, add );
  5759. str = pre + str;
  5760. }
  5761. return str;
  5762. };
  5763. /**
  5764. * The padEnd() method pads the current string with a given string (eventually repeated) so that the resulting string reaches a given length.
  5765. * The pad is applied from the end (right) of the current string.
  5766. * @param {number} _targetLength The length of the resulting string once the current string has been padded.
  5767. * If this parameter is smaller than the current string's length, the current string will be returned as it is.
  5768. * @param {string} [_padString=" "] The string to pad the current string with.
  5769. * If this string is too long, it will be truncated and the left-most part will be applied.
  5770. * The default value for this parameter is " " (U+0020).
  5771. */
  5772. proto.padEnd = function padEnd( _targetLength/*, _padString*/ )
  5773. {
  5774. var str = stringContext( this, "padEnd" ),
  5775. pad = arguments[1],
  5776. len = Math.trunc( _targetLength ) || 0,
  5777. add = len - str.length,
  5778. pLen,
  5779. post;
  5780. pad = typeof pad === strUndef ? " " : String( pad );
  5781. pLen = pad.length;
  5782. if ( ( add > 0 ) && ( pLen > 0 ) )
  5783. {
  5784. post = pad.repeat( Math.floor( add / pLen ) );
  5785. add %= pLen;
  5786. if ( add > 0 )
  5787. post += pad.substr( 0, add );
  5788. str += post;
  5789. }
  5790. return str;
  5791. };
  5792. }
  5793. ObjectPolyfill.polyfill( String, stat, proto, exports, "String" );
  5794. // End of module
  5795. }( Math, RegExp, String, __webpack_require__( 2 ) ) );
  5796. /***/ }),
  5797. /* 25 */
  5798. /***/ (function(module, exports, __webpack_require__) {
  5799. // Licensed Materials - Property of IBM
  5800. //
  5801. // IBM Watson Analytics
  5802. //
  5803. // (C) Copyright IBM Corp. 2018
  5804. //
  5805. // US Government Users Restricted Rights - Use, duplication or
  5806. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  5807. /*global Intl*/
  5808. module.exports = ( function( Intl, IntlPolyfill )
  5809. {
  5810. "use strict";
  5811. // Check if the native Intl should be merged with some polyfills on it. Only call if Intl != null.
  5812. function shouldMerge( _name )
  5813. {
  5814. return !Intl[ _name ] || IntlPolyfill[ _name ];
  5815. }
  5816. // APIs expected on the Intl object
  5817. var APIs = [ "Collator", "DateTimeformat", "NumberFormat", "PluralRules", "getCanonicalLocales" ];
  5818. var result = Intl || IntlPolyfill;
  5819. // If there is a native Intl, see if some parts should be merged
  5820. if ( Intl && APIs.some( shouldMerge ) )
  5821. {
  5822. // Create a merged Intl object taking as much from the native object as possible.
  5823. // Although prototype inheritance is used, set all expected value as local properties so hasOwnProperty behaves as expected.
  5824. result = Object.create( Intl, APIs.reduce( function( _propDef, _name )
  5825. {
  5826. var value = Intl[ _name ] || IntlPolyfill[ _name ];
  5827. if ( value )
  5828. _propDef[ _name ] = { value: value };
  5829. return _propDef;
  5830. }, {} ) );
  5831. }
  5832. return result;
  5833. }( typeof Intl !== "undefined" ? Intl : null, __webpack_require__( 26 ) ) );
  5834. /***/ }),
  5835. /* 26 */
  5836. /***/ (function(module, exports, __webpack_require__) {
  5837. // Licensed Materials - Property of IBM
  5838. //
  5839. // IBM Watson Analytics
  5840. //
  5841. // (C) Copyright IBM Corp. 2018
  5842. //
  5843. // US Government Users Restricted Rights - Use, duplication or
  5844. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  5845. module.exports = ( function( ObjectPolyfill, DateTimeFormat, NumberFormat, bcp47 )
  5846. {
  5847. "use strict";
  5848. /**
  5849. * @module barejs/polyfill/Intl
  5850. */
  5851. function Intl()
  5852. {
  5853. ObjectPolyfill.defineProperties( this,
  5854. {
  5855. DateTimeFormat: { value: DateTimeFormat },
  5856. NumberFormat: { value: NumberFormat },
  5857. getCanonicalLocales: { value: bcp47.getCanonicalLocales }
  5858. } );
  5859. }
  5860. return new Intl();
  5861. }( __webpack_require__( 2 ), __webpack_require__( 27 ), __webpack_require__( 30 ), __webpack_require__( 29 ) ) );
  5862. /***/ }),
  5863. /* 27 */
  5864. /***/ (function(module, exports, __webpack_require__) {
  5865. // Licensed Materials - Property of IBM
  5866. //
  5867. // IBM Watson Analytics
  5868. //
  5869. // (C) Copyright IBM Corp. 2018
  5870. //
  5871. // US Government Users Restricted Rights - Use, duplication or
  5872. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  5873. module.exports = ( function( ObjectPolyfill, Format )
  5874. {
  5875. "use strict";
  5876. /**
  5877. * These classes are NOT a polyfill, and are not meant to be!
  5878. * They provide a poor man's fallback for the Intl formatters, for non-compliant environments.
  5879. */
  5880. var NAME = [ "short", "long" ];
  5881. var DATE_NUMBER = [ "numeric", "2-digit" ];
  5882. var DATE_TEXT = [ "narrow" ].concat( NAME );
  5883. var DATE_BOTH = DATE_NUMBER.concat( DATE_TEXT );
  5884. var BOOLEAN = [ true, false ];
  5885. var padStart = Function.prototype.call.bind( String.prototype.padStart );
  5886. // This regex will match a sequence of possible formatter items
  5887. var reReplace = /A+|a+|D+|d+|E+|e+|F+|G+|g+|H+|h+|K+|k+|M+|m+|S+|s+|u+|W+|w+|Y+|y+|Z+|z+/g;
  5888. // This date is re-used for processing
  5889. var d1 = new Date();
  5890. /**
  5891. * Object that parses an Options object and normalizes it to options.
  5892. * @class module:barejs/polyfill/Intl.DateTimeFormat~DateTimeFormatOptions
  5893. */
  5894. function DateTimeFormatOptions( _options )
  5895. {
  5896. // Date
  5897. this._conditionalSet( _options, "year", DATE_NUMBER );
  5898. this._conditionalSet( _options, "month", DATE_BOTH );
  5899. this._conditionalSet( _options, "day", DATE_NUMBER );
  5900. this._conditionalSet( _options, "weekday", DATE_TEXT );
  5901. // Time
  5902. this._conditionalSet( _options, "hour", DATE_NUMBER );
  5903. this._conditionalSet( _options, "minute", DATE_NUMBER );
  5904. this._conditionalSet( _options, "second", DATE_NUMBER );
  5905. this._conditionalSet( _options, "weekday", DATE_TEXT );
  5906. this._conditionalSet( _options, "hour12", BOOLEAN );
  5907. this._conditionalSet( _options, "timeZoneName", NAME );
  5908. }
  5909. ObjectPolyfill.defineProperties( DateTimeFormatOptions.prototype,
  5910. /** @lends module:barejs/polyfill/Intl.DateTimeFormat~DateTimeFormatOptions# */
  5911. {
  5912. localeMatcher: { writable: true, value: null },
  5913. timeZone: { writable: true, value: null },
  5914. hour12: { writable: true, value: null },
  5915. formatMatcher: { writable: true, value: null },
  5916. weekday: { writable: true, value: null },
  5917. era: { writable: true, value: null },
  5918. year: { writable: true, value: null },
  5919. month: { writable: true, value: null },
  5920. day: { writable: true, value: null },
  5921. hour: { writable: true, value: null },
  5922. minute: { writable: true, value: null },
  5923. second: { writable: true, value: null },
  5924. timeZoneName: { writable: true, value: null },
  5925. /**
  5926. * Helper function. If _property is present on _options, will assign the value to this (with the
  5927. * same _property name), and validate the value against _validValues while doing so.
  5928. * @param _options {Object} The options to validate
  5929. * @param _property {String} The name of the property
  5930. * @param _validValues {Array} The list of valid values
  5931. */
  5932. _conditionalSet:
  5933. {
  5934. value: function( _options, _property, _validValues )
  5935. {
  5936. if ( typeof _options[ _property ] !== "undefined" )
  5937. {
  5938. if ( !_validValues.includes( this[ _property ] = _options[ _property ] ) )
  5939. throw new RangeError( "Invalid value for " + _property + ": " + _options[ _property ] );
  5940. }
  5941. }
  5942. }
  5943. } );
  5944. /**
  5945. * Supports NUMERICAL formatting of dates, according to the formatting patterns described on
  5946. * http://www.unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns
  5947. * Warning: does NOT support formats like MMMM which should be localized. This method should only
  5948. * be used to produce a fixed date format. It also doesn't support identifiers that require
  5949. * knowledge of a specific calendar system, like "day of the week" or "era".
  5950. * @param _date {Date} The date to format
  5951. * @param _formatString {String} The formatString to use.
  5952. * @param _utc {Boolean} Optional: set to true to use the UTC time zone instead of local.
  5953. * @returns {String} _date formatted as String using _pattern.
  5954. * @memberof module:barejs/polyfill/Intl.DateTimeFormat~
  5955. */
  5956. function formatDateTime( _date, _formatString, _utc )
  5957. {
  5958. // Always assign to d1 so we convert a number to a date, and can safely modify the
  5959. // date object to adjust for the time zone
  5960. d1.setTime( _date || Date.now() );
  5961. _utc = _utc === true; // ensure boolean
  5962. return String( _formatString ).replace( reReplace, function( _match )
  5963. {
  5964. var v; // value; used by most format specifiers
  5965. var c = _match.charAt( 0 ); // The first (and every) character of the matched pattern
  5966. var l = _match.length; // short alias for _match.length.
  5967. // First, grab values. Some values early out by returning immediately or throwing an error.
  5968. switch ( c )
  5969. {
  5970. //
  5971. // Values
  5972. //
  5973. case "y": // Year
  5974. v = _utc ? d1.getUTCFullYear() : d1.getFullYear();
  5975. // So two-digit years are a stupid idea (where's the cut-off point?!).
  5976. // As a formatter, we just take the last two digits and don't care about a cut-off.
  5977. // This does mean that 1894 and 1994 will both produce 94, which can't be distinguished.
  5978. // The alternative would be a configurable cut-off year, but the best alternative
  5979. // would be for people to stop chopping away significant digits.
  5980. if ( l === 2 )
  5981. v %= 100;
  5982. break;
  5983. case "M": // Month
  5984. v = ( _utc ? d1.getUTCMonth() : d1.getMonth() ) + 1; // compensate for 0 based
  5985. break;
  5986. case "d": // Day in month
  5987. v = _utc ? d1.getUTCDate() : d1.getDate();
  5988. break;
  5989. case "D": // Day of year
  5990. // Start by making v a new UTC date on January 1st of the same year.
  5991. // Using UTC will avoid DST differences.
  5992. v = new Date( Date.UTC( d1.getUTCFullYear(), 0, 1, d1.getUTCHours(), d1.getUTCMinutes(), d1.getUTCSeconds(), d1.getUTCMilliseconds() ) );
  5993. // Calculate the number of days and make the value 1 based.
  5994. // Although we expect an integer result (due to the usage of UTC), round the result
  5995. // in case the browser included leap seconds, or some other unforeseen difference.
  5996. v = Math.round( ( d1.getTime() - v.getTime() ) / 86400000 ) + 1;
  5997. break;
  5998. case "E": // Day of week - Sunday is always day 1
  5999. v = ( _utc ? d1.getUTCDay() : d1.getDay() ) + 1;
  6000. break;
  6001. case "H": // Hour [0-23]
  6002. case "h": // Hour [1-12]
  6003. case "K": // Hour [0-11]
  6004. case "k": // Hour [1-24]
  6005. v = _utc ? d1.getUTCHours() : d1.getHours();
  6006. // v is now [0-23]
  6007. switch ( c )
  6008. {
  6009. case 'h':
  6010. v = ( v % 12 ) || 12; // translate to [1-12]
  6011. break;
  6012. case 'K':
  6013. v = ( v % 12 ); // translate to [0-11]
  6014. break;
  6015. case 'k':
  6016. v = v || 24; // translate to [1-24]
  6017. break;
  6018. }
  6019. break;
  6020. case "m": // Minute
  6021. v = _utc ? d1.getUTCMinutes() : d1.getMinutes();
  6022. break;
  6023. case "s": // Second
  6024. v = _utc ? d1.getUTCSeconds() : d1.getSeconds();
  6025. break;
  6026. case "S": // Fractional Second - rounds to the count of letters
  6027. v = Math.round( ( _utc ? d1.getUTCMilliseconds() : d1.getMilliseconds() ) * Math.pow( 10, l - 3 ) );
  6028. break;
  6029. //
  6030. // Instant return
  6031. //
  6032. case "a": // AM or PM
  6033. if ( l > 1 )
  6034. throw new RangeError( "Invalid pattern: " + _match + ", a maximum of 1 character is allowed" );
  6035. // Note: am/pm this should actually be localised. However, we're allowing this
  6036. // since the 12 hour format would be useless otherwise.
  6037. v = _utc ? d1.getUTCHours() : d1.getHours();
  6038. return v < 12 ? "am" : "pm";
  6039. case "Z": // Time zone. 1: GMT format, 2: RFC 822
  6040. if ( l > 2 )
  6041. throw new RangeError( "Invalid pattern: " + _match + ", a maximum of 2 characters is allowed" );
  6042. if ( _utc && ( l === 2 ) )
  6043. return "Z";
  6044. v = _utc ? 0 : -d1.getTimezoneOffset();
  6045. // Translate v to +-00:00 syntax
  6046. v = ( v < 0 ? "-" : "+" ) +
  6047. padStart( Math.floor( v / 60 ), 2, "0" ) +
  6048. ":" + padStart( v % 60, 2, "0" );
  6049. // And immediately return
  6050. return ( l === 1 ? "GMT" + v : v );
  6051. //
  6052. // Unsupported
  6053. //
  6054. /*
  6055. case "A": // Milliseconds in day
  6056. case "e": // Day of week - Local (calendar based)
  6057. case "F": // Day of Week in Month.
  6058. case "G": // Era
  6059. case "g": // Modified Julian day.
  6060. case "u": // Extended year
  6061. case "W": // Week of month
  6062. case "w": // Week of year
  6063. case "Y": // Year (of "Week of Year"), used in ISO year-week calendar. May differ from calendar year.
  6064. case "z": // Timezone. 1: short wall (generic), 2: long wall, 3: short time zone (i.e. PST) 4: full name (Pacific Standard Time).
  6065. */
  6066. default:
  6067. throw new Error( "format identifier " + _match.charAt( 0 ) + "is not supported by this method" );
  6068. }
  6069. // Process values
  6070. switch ( c )
  6071. {
  6072. // Two digit maximum, more is invalid
  6073. case "H": // Hour [0-23]
  6074. case "h": // Hour [1-12]
  6075. case "K": // Hour [0-11]
  6076. case "k": // Hour [1-24]
  6077. case "m": // Minute
  6078. case "s": // Second
  6079. if ( l > 2 )
  6080. throw new RangeError( "Invalid pattern: " + _match + ", a maximum of 2 characters is allowed" );
  6081. break;
  6082. // Three digit maximum, more is invalid
  6083. case "D": // Day of year
  6084. if ( l > 3 )
  6085. throw new RangeError( "Invalid pattern: " + _match + ", a maximum of 3 characters is allowed" );
  6086. break;
  6087. // Five digit maximum, but only two digits are not localised.
  6088. case "M": // Month
  6089. case "d": // Day in month
  6090. case "E": // Day of week - Sunday is always day 1
  6091. if ( l > 5 )
  6092. throw new RangeError( "Invalid pattern: " + _match + ", a maximum of 5 characters is allowed" );
  6093. if ( l > 2 )
  6094. throw new RangeError( "Pattern: " + _match + ", requires localisation, which is not supported by format" );
  6095. break;
  6096. // Unlimited repeat allowed (no validation needed)
  6097. /*
  6098. case "y": // Year
  6099. case "S": // Fractional Second
  6100. break;
  6101. */
  6102. }
  6103. /*
  6104. if ( ( maxLen > 0 ) && ( l > maxLen ) )
  6105. throw new RangeError( "Invalid pattern: " + _match + ", a maximum of " + maxLen + " characters is allowed" );
  6106. */
  6107. // If we get here, we can just return value (possibly padding it to length).
  6108. return l > 1 ? padStart( v, l, "0" ) : v;
  6109. } );
  6110. }
  6111. /**
  6112. * Provides Date/Time formatting
  6113. * @class module:barejs/polyfill/Intl.DateTimeFormat
  6114. * @extends module:barejs/polyfill/Intl~Format
  6115. */
  6116. function DateTimeFormat( _locales, _options )
  6117. {
  6118. Format.call( this, _locales, new DateTimeFormatOptions( Object( _options ) ) );
  6119. }
  6120. DateTimeFormat.prototype = Object.create( Format.prototype,
  6121. /** @lends module:barejs/polyfill/Intl.DateTimeFormat# */
  6122. {
  6123. format:
  6124. {
  6125. enumerable: true,
  6126. value: function format( _value )
  6127. {
  6128. var parts = []; // used to build the date and/or time part
  6129. var fmt = []; // used to build the end format
  6130. switch ( this._options.year )
  6131. {
  6132. case "2-digit":
  6133. parts.push( "yy" );
  6134. break;
  6135. case "numeric":
  6136. parts.push( "yyyy" );
  6137. break;
  6138. }
  6139. switch ( this._options.month )
  6140. {
  6141. case "narrow":
  6142. case "short":
  6143. case "long":
  6144. // No actual implementation, default to 2-digit
  6145. case "2-digit":
  6146. parts.push( "MM" );
  6147. break;
  6148. case "numeric":
  6149. parts.push( "M" );
  6150. break;
  6151. }
  6152. switch ( this._options.day )
  6153. {
  6154. case "2-digit":
  6155. parts.push( "dd" );
  6156. break;
  6157. case "numeric":
  6158. parts.push( "d" );
  6159. break;
  6160. }
  6161. if ( parts.length > 0 )
  6162. {
  6163. fmt.push( parts.join( "-" ) );
  6164. parts.length = 0; // reset for time part
  6165. }
  6166. switch ( this._options.hour )
  6167. {
  6168. case "2-digit":
  6169. parts.push( "HH" );
  6170. break;
  6171. case "numeric":
  6172. parts.push( "H" );
  6173. break;
  6174. }
  6175. switch ( this._options.minute )
  6176. {
  6177. case "2-digit":
  6178. parts.push( "mm" );
  6179. break;
  6180. case "numeric":
  6181. parts.push( "m" );
  6182. break;
  6183. }
  6184. switch ( this._options.second )
  6185. {
  6186. case "2-digit":
  6187. parts.push( "ss" );
  6188. break;
  6189. case "numeric":
  6190. parts.push( "s" );
  6191. break;
  6192. }
  6193. if ( parts.length > 0 )
  6194. fmt.push( parts.join( ":" ) );
  6195. // DateTimeFormat defaults to formatting year/month/day if no options where specified.
  6196. if ( fmt.length < 1 )
  6197. fmt.push( "yyyy-MM-dd" );
  6198. return formatDateTime( _value, fmt.join( " " ) );
  6199. }
  6200. }
  6201. } );
  6202. return DateTimeFormat;
  6203. }( __webpack_require__( 2 ), __webpack_require__( 28 ) ) );
  6204. /***/ }),
  6205. /* 28 */
  6206. /***/ (function(module, exports, __webpack_require__) {
  6207. // Licensed Materials - Property of IBM
  6208. //
  6209. // IBM Watson Analytics
  6210. //
  6211. // (C) Copyright IBM Corp. 2018
  6212. //
  6213. // US Government Users Restricted Rights - Use, duplication or
  6214. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6215. module.exports = ( function( ObjectPolyfill, bcp47 )
  6216. {
  6217. "use strict";
  6218. /*global navigator*/
  6219. /**
  6220. * These classes are NOT a polyfill, and are not meant to be!
  6221. * They provide a poor man's fallback for the Intl formatters, for non-compliant environments.
  6222. */
  6223. var LOCALE = ( function( navigator )
  6224. {
  6225. try
  6226. {
  6227. return bcp47.getCanonicalLocales( ( navigator && ( navigator.language || navigator.userLanguage ) ) || "en-US" )[ 0 ];
  6228. }
  6229. catch ( ex )
  6230. {
  6231. return "en-US";
  6232. }
  6233. }( typeof navigator !== "undefined" ? navigator : null ) );
  6234. /**
  6235. * Base class for objects that perform formatting based on locale and options
  6236. * @class module:barejs/polyfill/Intl~Format
  6237. * @param _locales
  6238. * @param _options
  6239. */
  6240. function Format( _locales, _options )
  6241. {
  6242. // We can't accept custom locales since we don't polyfill any culture data.
  6243. // Always format using the environment locale(!)
  6244. ObjectPolyfill.defineProperties( this,
  6245. {
  6246. _locale: { value: LOCALE },
  6247. _options: { value: _options }
  6248. } );
  6249. }
  6250. ObjectPolyfill.defineProperties( Format.prototype,
  6251. /** @lends module:barejs/polyfill/Intl~Format# */
  6252. {
  6253. _locale: { value: null },
  6254. _options: { value: null },
  6255. /**
  6256. * Get the resolvedOptions
  6257. * @function
  6258. * @return {Object} The options
  6259. */
  6260. resolvedOptions:
  6261. {
  6262. value: function resolvedOptions()
  6263. {
  6264. // Create a new object with a locale on it, and copy the options to it.
  6265. return Object.assign( { locale: this._locale }, this._options );
  6266. }
  6267. },
  6268. /**
  6269. * Format a value
  6270. * @param {any} _value
  6271. * @return {String} The formatted value.
  6272. */
  6273. format:
  6274. {
  6275. enumerable: true,
  6276. value: function( _value )
  6277. {
  6278. return _value ? _value.toLocaleString() : "";
  6279. }
  6280. }
  6281. } );
  6282. return ObjectPolyfill.defineProperty( Format, "envLocale", { value: LOCALE } );
  6283. }( __webpack_require__( 2 ), __webpack_require__( 29 ) ) );
  6284. /***/ }),
  6285. /* 29 */
  6286. /***/ (function(module, exports, __webpack_require__) {
  6287. // Licensed Materials - Property of IBM
  6288. //
  6289. // IBM Watson Analytics
  6290. //
  6291. // (C) Copyright IBM Corp. 2018
  6292. //
  6293. // US Government Users Restricted Rights - Use, duplication or
  6294. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6295. ( function( exports, ObjectPolyfill )
  6296. {
  6297. "use strict";
  6298. // Instead of fully validating the tag, we match any string that starts with two or three [a-z] characters,
  6299. // followed by any number of -[a-z0-9] suffixes.
  6300. var reTag = /^(i|[a-zA-Z]{2,3})((?:\-[a-zA-Z0-9]+)*)$/;
  6301. var reFormat = /^[a-zA-Z]+|\-\w+/g;
  6302. function bcp47Replace( _match, _offset )
  6303. {
  6304. /*
  6305. * Formatting follows simple rules:
  6306. * > if NOT the first entry
  6307. * > Length 2: UPPER case
  6308. * > Length 4: Title case
  6309. * > lower case
  6310. * For any match that is not the first (_offset is 0), take into account '-' is in the match
  6311. */
  6312. var len = _offset ? _match.length : 0;
  6313. return len === 3 ? // +1 for '-'
  6314. _match.toUpperCase() :
  6315. len === 5 ? // +1 for '-'
  6316. _match.substr( 0, 2 ).toUpperCase() + _match.substr( 2 ).toLowerCase() :
  6317. _match.toLowerCase();
  6318. }
  6319. function isStructurallyValidLanguageTag( _tag )
  6320. {
  6321. // With the current implementation, the type check for string is unnecessary.
  6322. return /*typeof _tag === "string" &&*/ reTag.test( _tag );
  6323. }
  6324. function canonicalizeLanguageTag( _tag )
  6325. {
  6326. // Officially this validation should be performed before calling this function,
  6327. // but with this limited implementation it's more convenient to perform it here.
  6328. var tag = String( _tag );
  6329. if ( !isStructurallyValidLanguageTag( tag ) )
  6330. throw new RangeError( "Invalid language tag: " + tag );
  6331. return tag.replace( reFormat, bcp47Replace );
  6332. }
  6333. /**
  6334. * @memberof module:barejs/polyfill/Intl
  6335. * @param {String|Array} _locales
  6336. * @return {String[]} List of canonical locale tags.
  6337. */
  6338. exports.getCanonicalLocales = function getCanonicalLocales( _locales )
  6339. {
  6340. var seen;
  6341. if ( _locales === undefined )
  6342. {
  6343. seen = new Array( 0 );
  6344. }
  6345. else if ( typeof _locales === "string" )
  6346. {
  6347. seen = new Array( 1 );
  6348. seen[ 0 ] = canonicalizeLanguageTag( _locales );
  6349. }
  6350. else
  6351. {
  6352. seen = [];
  6353. var locales = ObjectPolyfill.toObject( _locales );
  6354. var len = locales.length || 0;
  6355. for ( var i = 0; i < len; ++i )
  6356. {
  6357. var tag = canonicalizeLanguageTag( locales[ i ] );
  6358. if ( seen.indexOf( tag ) < 0 )
  6359. seen.push( tag );
  6360. }
  6361. }
  6362. return seen;
  6363. };
  6364. }( module.exports, __webpack_require__( 2 ) ) );
  6365. /***/ }),
  6366. /* 30 */
  6367. /***/ (function(module, exports, __webpack_require__) {
  6368. // Licensed Materials - Property of IBM
  6369. //
  6370. // IBM Watson Analytics
  6371. //
  6372. // (C) Copyright IBM Corp. 2018
  6373. //
  6374. // US Government Users Restricted Rights - Use, duplication or
  6375. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6376. module.exports = ( function( Format )
  6377. {
  6378. "use strict";
  6379. /**
  6380. * These classes are NOT a polyfill, and are not meant to be!
  6381. * They provide a poor man's fallback for the Intl formatters, for non-compliant environments.
  6382. */
  6383. var reCurrencyCode = /^[A-Z]{3}$/;
  6384. var nbsp = String.fromCharCode( 160 );
  6385. /**
  6386. * Object that parses an Options object and normalizes it to options.
  6387. * @class module:barejs/polyfill/Intl.NumberFormat~NumberFormatOptions
  6388. */
  6389. function NumberFormatOptions( _options )
  6390. {
  6391. // MinimumFractionDigits is usually 0
  6392. this.minimumFractionDigits = 0;
  6393. this.maximumFractionDigits = 3;
  6394. this.minimumIntegerDigits = 1;
  6395. this.numberingSystem = "latn";
  6396. this.useGrouping = true;
  6397. switch ( "style" in _options ? _options.style : "decimal" )
  6398. {
  6399. case "percent":
  6400. this.style = "percent";
  6401. this.maximumFractionDigits = Math.max( 0, this.minimumFractionDigits );
  6402. break;
  6403. case "currency":
  6404. this.style = "currency";
  6405. if ( !_options.currency )
  6406. throw new TypeError( "Currency code is required with currency style." );
  6407. if ( ( typeof _options.currency !== "string" ) || !reCurrencyCode.test( _options.currency ) )
  6408. throw new TypeError( "Invalid currency code:" + _options.currency );
  6409. this.currency = _options.currency;
  6410. this.currencyDisplay = "code"; // This is all the fallback supports!
  6411. this.maximumFractionDigits = Math.max( 2, this.minimumFractionDigits );
  6412. break;
  6413. case "decimal":
  6414. this.style = "decimal";
  6415. break;
  6416. default:
  6417. throw new RangeError( "Value " + _options.style + " out of range for numberformat options property style" );
  6418. }
  6419. }
  6420. /**
  6421. * Provides number formatting
  6422. * @class module:barejs/polyfill/Intl.NumberFormat
  6423. * @extends module:barejs/polyfill/Intl~Format
  6424. */
  6425. function NumberFormat( _locales, _options )
  6426. {
  6427. Format.call( this, _locales, new NumberFormatOptions( Object( _options ) ) );
  6428. }
  6429. NumberFormat.prototype = Object.create( Format.prototype,
  6430. /** @lends module:barejs/polyfill/Intl.NumberFormat# */
  6431. {
  6432. constructor: { writable: true, value: NumberFormat },
  6433. format:
  6434. {
  6435. enumerable: true,
  6436. value: function format( _value )
  6437. {
  6438. if ( _value === null || typeof _value === "undefined" )
  6439. return "";
  6440. var value = +_value;
  6441. var prefix = "";
  6442. var suffix = "";
  6443. if ( isNaN( value ) )
  6444. return "NaN";
  6445. switch( this._options.style )
  6446. {
  6447. case "percent":
  6448. value *= 100;
  6449. suffix = "%";
  6450. break;
  6451. case "currency":
  6452. prefix = this._options.currency + nbsp;
  6453. break;
  6454. }
  6455. // We're currently ignoring min/max decimal places (which is bad).
  6456. return prefix + value.toLocaleString() + suffix;
  6457. }
  6458. }
  6459. } );
  6460. return NumberFormat;
  6461. }( __webpack_require__( 28 ) ) );
  6462. /***/ }),
  6463. /* 31 */
  6464. /***/ (function(module, exports, __webpack_require__) {
  6465. // Licensed Materials - Property of IBM
  6466. //
  6467. // IBM Watson Analytics
  6468. //
  6469. // (C) Copyright IBM Corp. 2015
  6470. //
  6471. // US Government Users Restricted Rights - Use, duplication or
  6472. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6473. var NMap = __webpack_require__( 3 );
  6474. // Check for iterator support
  6475. module.exports = ( (6) >= 6 ) || ( "entries" in NMap.prototype ) ? NMap : /*istanbul ignore next*/ __webpack_require__( 4 );
  6476. /***/ }),
  6477. /* 32 */
  6478. /***/ (function(module, exports, __webpack_require__) {
  6479. // Licensed Materials - Property of IBM
  6480. //
  6481. // IBM Watson Analytics
  6482. //
  6483. // (C) Copyright IBM Corp. 2015
  6484. //
  6485. // US Government Users Restricted Rights - Use, duplication or
  6486. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6487. var NSet = __webpack_require__( 6 );
  6488. // Check for iterator support
  6489. module.exports = ( (6) >= 6 ) || ( "entries" in NSet.prototype ) ? NSet : /*istanbul ignore next*/ __webpack_require__( 7 );
  6490. /***/ }),
  6491. /* 33 */
  6492. /***/ (function(module, exports, __webpack_require__) {
  6493. // Licensed Materials - Property of IBM
  6494. //
  6495. // IBM Watson Analytics
  6496. //
  6497. // (C) Copyright IBM Corp. 2015
  6498. //
  6499. // US Government Users Restricted Rights - Use, duplication or
  6500. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6501. /*global Promise*/
  6502. module.exports = ( (6) >= 6 ) || ( typeof Promise !== "undefined" ) ? Promise : /*istanbul ignore next*/ __webpack_require__( 34 );
  6503. /***/ }),
  6504. /* 34 */
  6505. /***/ (function(module, exports, __webpack_require__) {
  6506. // Licensed Materials - Property of IBM
  6507. //
  6508. // IBM Watson Analytics
  6509. //
  6510. // (C) Copyright IBM Corp. 2015
  6511. //
  6512. // US Government Users Restricted Rights - Use, duplication or
  6513. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6514. module.exports = ( function(
  6515. ObjectPolyfill,
  6516. setImmediate
  6517. )
  6518. {
  6519. "use strict";
  6520. /*jshint latedef:false*/
  6521. /**
  6522. * Helper method that turns an _iterable into an array of promises
  6523. * @memberof module:barejs/polyfill.Promise~
  6524. * @private
  6525. */
  6526. function iterableToPromiseArray( _iterable )
  6527. {
  6528. var promises;
  6529. var it;
  6530. var value;
  6531. if ( _iterable.length || _iterable.length === 0 )
  6532. {
  6533. promises = new Array( _iterable.length );
  6534. for ( var i = 0, len = _iterable.length; i < len; ++i )
  6535. {
  6536. value = _iterable[i];
  6537. if ( ( !value ) || ( typeof value.then !== "function" ) )
  6538. value = Promise.resolve( value );
  6539. promises[i] = value;
  6540. }
  6541. }
  6542. else if ( ( it = ObjectPolyfill.getIterator( _iterable ) ) )
  6543. {
  6544. promises = [];
  6545. for( value = it.next(); !value.done; value = it.next() )
  6546. {
  6547. if ( ( !value.value ) || ( typeof value.value.then !== "function" ) )
  6548. promises.push( Promise.resolve( value.value ) );
  6549. else
  6550. promises.push( value.value );
  6551. }
  6552. }
  6553. else
  6554. {
  6555. throw new Error( "Invalid iterable" );
  6556. }
  6557. return promises;
  6558. }
  6559. /**
  6560. * Handler for a promise
  6561. * @class module:barejs/polyfill.Promise~Handler
  6562. * @private
  6563. */
  6564. function Handler( _onFulfilled, _onRejected, _promise )
  6565. {
  6566. this.onFulfilled = typeof _onFulfilled === "function" ? _onFulfilled : null;
  6567. this.onRejected = typeof _onRejected === "function" ? _onRejected : null;
  6568. this.promise = _promise;
  6569. }
  6570. /**
  6571. * No-operation function
  6572. */
  6573. function noop() {}
  6574. // States:
  6575. //
  6576. // 0 - pending
  6577. // 1 - fulfilled with _value
  6578. // 2 - rejected with _value
  6579. // 3 - adopted the state of another promise, _value
  6580. //
  6581. // once the state is no longer pending (0) it is immutable
  6582. // All `_` prefixed properties will be reduced to `_{random number}`
  6583. // at build time to obfuscate them and discourage their use.
  6584. // We don't use symbols or Object.defineProperty to fully hide them
  6585. // because the performance isn't good enough.
  6586. // to avoid using try/catch inside critical functions, we
  6587. // extract them to here.
  6588. var LAST_ERROR = null;
  6589. var IS_ERROR = {};
  6590. /**
  6591. * Safely request the then function from an object
  6592. */
  6593. function getThen( _obj )
  6594. {
  6595. try
  6596. {
  6597. return _obj.then;
  6598. }
  6599. catch ( ex )
  6600. {
  6601. LAST_ERROR = ex;
  6602. return IS_ERROR;
  6603. }
  6604. }
  6605. function tryCallOne( _fn, _a )
  6606. {
  6607. try
  6608. {
  6609. return _fn( _a );
  6610. }
  6611. catch ( ex )
  6612. {
  6613. LAST_ERROR = ex;
  6614. return IS_ERROR;
  6615. }
  6616. }
  6617. function tryCallTwo( _fn, _a, _b )
  6618. {
  6619. try
  6620. {
  6621. _fn( _a, _b );
  6622. }
  6623. catch ( ex )
  6624. {
  6625. LAST_ERROR = ex;
  6626. return IS_ERROR;
  6627. }
  6628. }
  6629. /**
  6630. * Create a new Promise
  6631. * @class module:barejs/polyfill.Promise
  6632. * @param {function} _resolver The resolver function that will be called with two callbacks:
  6633. * _resolve (call on succes) and _reject (call on failure).
  6634. */
  6635. function Promise( _resolver )
  6636. {
  6637. if ( typeof this !== "object" )
  6638. throw new TypeError( "Promises must be constructed via new" );
  6639. this._state = 0;
  6640. this._value = null;
  6641. this._deferreds = [];
  6642. if ( ObjectPolyfill.ensureCallable( _resolver ) === noop )
  6643. return;
  6644. doResolve( _resolver, this );
  6645. }
  6646. function safeThen( _self, _onFulfilled, _onRejected )
  6647. {
  6648. return new _self.constructor( function( resolve, reject )
  6649. {
  6650. var res = new Promise( noop );
  6651. res.then( resolve, reject );
  6652. handle( _self, new Handler( _onFulfilled, _onRejected, res ) );
  6653. } );
  6654. }
  6655. function handle( _self, _deferred )
  6656. {
  6657. while ( _self._state === 3 )
  6658. {
  6659. _self = _self._value;
  6660. }
  6661. if ( _self._state === 0 )
  6662. {
  6663. _self._deferreds.push( _deferred );
  6664. return;
  6665. }
  6666. setImmediate( function()
  6667. {
  6668. var cb = _self._state === 1 ? _deferred.onFulfilled : _deferred.onRejected;
  6669. if ( cb === null )
  6670. {
  6671. if ( _self._state === 1 )
  6672. {
  6673. resolve( _deferred.promise, _self._value );
  6674. }
  6675. else
  6676. {
  6677. reject( _deferred.promise, _self._value );
  6678. }
  6679. return;
  6680. }
  6681. var ret = tryCallOne( cb, _self._value );
  6682. if ( ret === IS_ERROR )
  6683. {
  6684. reject( _deferred.promise, LAST_ERROR );
  6685. }
  6686. else
  6687. {
  6688. resolve( _deferred.promise, ret );
  6689. }
  6690. } );
  6691. }
  6692. function resolve( _self, _newValue )
  6693. {
  6694. // Promise Resolution Procedure:
  6695. // https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
  6696. if ( _newValue === _self )
  6697. {
  6698. return reject( _self, new TypeError( 'A promise cannot be resolved with itself.' ) );
  6699. }
  6700. if ( _newValue && (typeof _newValue === "object" || typeof _newValue === "function") )
  6701. {
  6702. var then = getThen( _newValue );
  6703. if ( then === IS_ERROR )
  6704. {
  6705. return reject( _self, LAST_ERROR );
  6706. }
  6707. if ( then === _self.then && ( _newValue instanceof Promise ) )
  6708. {
  6709. _self._state = 3;
  6710. _self._value = _newValue;
  6711. finale( _self );
  6712. return;
  6713. }
  6714. else if ( typeof then === "function" )
  6715. {
  6716. doResolve( then.bind( _newValue ), _self );
  6717. return;
  6718. }
  6719. }
  6720. _self._state = 1;
  6721. _self._value = _newValue;
  6722. finale( _self );
  6723. }
  6724. function reject( _self, _newValue )
  6725. {
  6726. _self._state = 2;
  6727. _self._value = _newValue;
  6728. finale( _self );
  6729. }
  6730. function finale( _self )
  6731. {
  6732. for ( var i = 0; i < _self._deferreds.length; ++i )
  6733. handle( _self, _self._deferreds[ i ] );
  6734. _self._deferreds = null;
  6735. }
  6736. /**
  6737. * Take a potentially misbehaving resolver function and make sure onFulfilled and onRejected
  6738. * are only called once.
  6739. *
  6740. * Makes no guarantees about asynchrony.
  6741. * @memberof module:barejs/polyfill.Promise~
  6742. * @private
  6743. */
  6744. function doResolve( _resolver, _promise )
  6745. {
  6746. var done = false;
  6747. var res = tryCallTwo( _resolver, function( value )
  6748. {
  6749. if ( done )
  6750. return;
  6751. done = true;
  6752. resolve( _promise, value );
  6753. }, function( reason )
  6754. {
  6755. if ( done )
  6756. return;
  6757. done = true;
  6758. reject( _promise, reason );
  6759. } );
  6760. if ( !done && res === IS_ERROR )
  6761. {
  6762. done = true;
  6763. reject( _promise, LAST_ERROR );
  6764. }
  6765. }
  6766. return ObjectPolyfill.polyfill( Promise,
  6767. /** @lends module:barejs/polyfill.Promise */
  6768. {
  6769. _noop: noop,
  6770. /**
  6771. * The Promise.resolve( _value ) method returns a Promise object that is resolved with the given value.
  6772. * If the value is a thenable (i.e. has a then method), the returned promise will "follow" that thenable,
  6773. * adopting its eventual state; otherwise the returned promise will be fulfilled with the value.
  6774. * @param {*} _value The value to resolve with.
  6775. * @returns {module:barejs/polyfill.Promise} A Promise that is resolved with _value.
  6776. */
  6777. resolve: function resolve( _value )
  6778. {
  6779. return new Promise( function( _resolve, _reject )
  6780. {
  6781. _resolve( _value );
  6782. } );
  6783. },
  6784. /**
  6785. * The Promise.reject( _reason ) method returns a Promise object that is rejected with the given reason.
  6786. * @param {*} _reason The rejection reason (passed as rejection argument).
  6787. * @returns {module:barejs/polyfill.Promise} A Promise that is rejected with _reason.
  6788. */
  6789. reject: function reject( _reason )
  6790. {
  6791. return new Promise( function( _resolve, _reject )
  6792. {
  6793. _reject( _reason );
  6794. } );
  6795. },
  6796. /**
  6797. * The Promise.all( _iterable ) method returns a promise that resolves when all of the promises
  6798. * in the iterable argument have resolved. If any of the passed in promises rejects, the all
  6799. * Promise immediately rejects with the value of the promise that rejected, discarding all the
  6800. * other promises whether or not they have resolved.
  6801. * @param _iterable {Object} Array that can be iterated.
  6802. * @returns {module:barejs/polyfill.Promise} A promise that will resolve with an array of values corresponding to all Promises in _iterable, after every Promise is resolved.
  6803. */
  6804. all: function all( _iterable )
  6805. {
  6806. var promises = iterableToPromiseArray( _iterable );
  6807. if ( promises.length < 1 )
  6808. return Promise.resolve( promises );
  6809. return new Promise( function( _resolve, _reject )
  6810. {
  6811. var values = new Array( promises.length );
  6812. var resolveCount = 0;
  6813. function rejected( _reason )
  6814. {
  6815. if ( values )
  6816. {
  6817. _reject( _reason );
  6818. values = null;
  6819. }
  6820. }
  6821. function resolved( _index, _value )
  6822. {
  6823. if ( values )
  6824. {
  6825. // Promises should never resolve twice, so we don't perform any sanity checking
  6826. // to see if values.hasOwnProperty( _index )...
  6827. values[_index] = _value;
  6828. if ( ++resolveCount >= values.length )
  6829. {
  6830. _resolve( values );
  6831. values = null;
  6832. }
  6833. }
  6834. }
  6835. for ( var i = 0, len = promises.length; i < len; ++i )
  6836. promises[i].then( resolved.bind( null, i ), rejected );
  6837. } );
  6838. },
  6839. /**
  6840. * The Promise.race( _iterable ) method returns a promise that resolves or rejects as soon as one
  6841. * of the promises in the iterable resolves or rejects, with the value or reason from that promise.
  6842. * @returns {module:barejs/polyfill.Promise} A promise that will resolve with the value of the first Promise to resolve.
  6843. */
  6844. race: function race( _iterable )
  6845. {
  6846. var promises = iterableToPromiseArray( _iterable );
  6847. return new Promise( function( _resolve, _reject )
  6848. {
  6849. var isResolved = false;
  6850. function rejected( _reason )
  6851. {
  6852. if ( !isResolved )
  6853. {
  6854. _reject( _reason );
  6855. isResolved = true;
  6856. }
  6857. }
  6858. function resolved( _value )
  6859. {
  6860. if ( !isResolved )
  6861. {
  6862. _resolve( _value );
  6863. isResolved = true;
  6864. }
  6865. }
  6866. for ( var i = 0, len = promises.length; i < len; ++i )
  6867. promises[i].then( resolved, rejected );
  6868. } );
  6869. }
  6870. },
  6871. /** @lends module:barejs/polyfill.Promise# */
  6872. {
  6873. /**
  6874. * Register either a resolve or reject callback, or both.
  6875. * @returns {module:barejs/polyfill.Promise} A promise that will resolve or reject with the value returned by (or thrown from) _onFulfilled or _onRejected.
  6876. */
  6877. then: function( _onFulfilled, _onRejected )
  6878. {
  6879. if ( this.constructor !== Promise )
  6880. return safeThen( this, _onFulfilled, _onRejected );
  6881. var res = new Promise( noop );
  6882. handle( this, new Handler( _onFulfilled, _onRejected, res ) );
  6883. return res;
  6884. },
  6885. /**
  6886. * Register a rejection callback (shortcut for then( null, _onRejected ) ).
  6887. * @returns {module:barejs/polyfill.Promise} A promise that will resolve or reject with the value returned by (or thrown from) _onRejected.
  6888. */
  6889. "catch": function( _onRejected )
  6890. {
  6891. return this.then( null, _onRejected );
  6892. }
  6893. }, null, "Promise" );
  6894. }(
  6895. __webpack_require__( 2 ),
  6896. /* global setImmediate, setTimeout */
  6897. typeof setImmediate !== "undefined" ? setImmediate : setTimeout
  6898. ) );
  6899. /***/ }),
  6900. /* 35 */
  6901. /***/ (function(module, exports, __webpack_require__) {
  6902. // Licensed Materials - Property of IBM
  6903. //
  6904. // IBM Watson Analytics
  6905. //
  6906. // (C) Copyright IBM Corp. 2015
  6907. //
  6908. // US Government Users Restricted Rights - Use, duplication or
  6909. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6910. module.exports = ( function( Error, decl )
  6911. {
  6912. "use strict";
  6913. /**
  6914. * Interprets a line of a stack trace and tries to extract information from it.
  6915. * @param {string} _line The line to interpret
  6916. * @memberof module:barejs.Exception~
  6917. * @private
  6918. */
  6919. /*istanbul ignore next: NodeJS has the Error.captureStackTrace method natively so this function will not be hit*/
  6920. function splitStackLine( _line )
  6921. {
  6922. /*
  6923. Expected input looks like:
  6924. myFunction@http://my.domain.com:8080/my/site/script.js:120:8 (Firefox, Safari)
  6925. @http://my.domain.com:8080/my/site/script.js:120:8 (Firefox)
  6926. http://my.domain.com:8080/my/site/script.js:120:8 (Safari)
  6927. */
  6928. if ( !_line )
  6929. return null;
  6930. var line = String( _line );
  6931. var result = new Array( 4 );
  6932. // Try to find a name (can be empty string)
  6933. var match = line.match( /^([^@]*)@/ );
  6934. result[0] = null;
  6935. if ( match )
  6936. {
  6937. result[0] = match[1] || null;
  6938. // Chop off the <functionName>@ part
  6939. line = line.substr( match[0].length );
  6940. }
  6941. // Try to find line and column number
  6942. match = line.match( /(:[0-9]+)?:([0-9]+)$/ );
  6943. if ( match )
  6944. {
  6945. if ( match[1] )
  6946. {
  6947. result[2] = parseInt( match[1].substr( 1 ), 10 );
  6948. result[3] = parseInt( match[2], 10 ) - 1;
  6949. }
  6950. else
  6951. {
  6952. result[2] = parseInt( match[2], 10 );
  6953. result[3] = null;
  6954. }
  6955. // Chop off the :LineNumber:ColumnNumber part
  6956. line = line.substr( 0, line.length - match[0].length );
  6957. }
  6958. // The result should be the filename
  6959. result[1] = line;
  6960. return result;
  6961. }
  6962. /*istanbul ignore next: NodeJS has the Error.captureStackTrace method natively so this function will not be hit*/
  6963. function processStack( _obj, _ctor, _err )
  6964. {
  6965. var fileName, lineNumber, columnNumber; // Additional metadata
  6966. var line, match; // used to parse the stack entries
  6967. var stack = _err.stack.split( "\n" ); // Split version of _err.stack
  6968. // Initialize fileName etc. to null
  6969. fileName = lineNumber = columnNumber = null;
  6970. if ( _ctor.name )
  6971. {
  6972. for ( line = 0; line < stack.length; ++line )
  6973. {
  6974. if ( stack[line].startsWith( _ctor.name + "@" ) )
  6975. break;
  6976. }
  6977. // Never remove the last entry
  6978. if ( line >= ( stack.length - 1 ) )
  6979. line = -1;
  6980. }
  6981. else
  6982. {
  6983. // We know for a fact the lowest entry can be ignored, unless it's the only entry
  6984. line = ( stack.length === 1 ) ? -1 : 0;
  6985. }
  6986. // If we get here and line >= 0, we can remove those entries
  6987. if ( line >= 0 )
  6988. {
  6989. stack = stack.slice( line + 1 );
  6990. match = splitStackLine( stack[0] );
  6991. if ( match )
  6992. {
  6993. fileName = match[1];
  6994. lineNumber = match[2];
  6995. columnNumber = match[3];
  6996. }
  6997. }
  6998. decl.defineProperty( _obj, "stack", { configurable: true, value: stack.join( "\n" ) } );
  6999. if ( fileName )
  7000. {
  7001. decl.defineProperties( _obj,
  7002. {
  7003. fileName: { configurable: true, value: fileName },
  7004. lineNumber: { configurable: true, value: lineNumber },
  7005. columnNumber: { configurable: true, value: columnNumber }
  7006. } );
  7007. }
  7008. }
  7009. /*istanbul ignore next: NodeJS has the Error.captureStackTrace method natively so this function will not be hit*/
  7010. function captureStackTrace( _obj, _ctor, _err )
  7011. {
  7012. if ( "stack" in _err )
  7013. processStack( _obj, _ctor, _err );
  7014. // if ( "opera#sourceLoc" in _err ) // Opera support?
  7015. }
  7016. /**
  7017. * The Exception constructor will set up the exception with a name and stack property. You can pass the "creator function"
  7018. * as second argument, this is the topmost function that will be ignored from the stack. It defaults to the constructed
  7019. * object's constructor, which ensures the "Exception" and parent constructors never show up in the stack.
  7020. * @class module:barejs.Exception
  7021. * @param {string} _message The message that describes the exception.
  7022. * @param {function} [_creatorFn] Optional: function to exclude from the call stack.
  7023. * Defaults to the this.constructor function.
  7024. *
  7025. * @classdesc Exception creates a normalized base class for creating custom Error (Exception) classes to throw.
  7026. * It handles determining the stack trace for the created exception in a cross browser way.
  7027. * This class relies on the constructor property being set correctly, otherwise sub-class constructors
  7028. * may show up in the stack trace. Using {@link module:barejs.decl#declareClass decl.declareClass}
  7029. * to define base classes ensures the constructor property is set correctly.
  7030. *
  7031. * Sub classes should also set the name property on the prototype to the name of the exception, for example:
  7032. *
  7033. * function MyCustomError( _message, _myAdditionalData )
  7034. * {
  7035. * Exception.call( this, _message );
  7036. *
  7037. * this.myAdditionalData = _myAdditionalData;
  7038. * }
  7039. *
  7040. * decl.declareClass( MyCustomError, Exception,
  7041. * {
  7042. * // Setting the name ensures our custom error looks and behaves as expected
  7043. * // Avoid using MyCustomError.name (named function name) as the name may get
  7044. * // mangled by a minifier/uglifier.
  7045. * name: "MyCustomError",
  7046. *
  7047. * myAdditionalData: null
  7048. * } );
  7049. *
  7050. */
  7051. function Exception( _message/*, _creatorFn*/ )
  7052. {
  7053. if ( !this || !( this instanceof Exception ) )
  7054. throw new TypeError( "Invalid context for Exception. Did you forget the new keyword?" );
  7055. var fn = arguments[1] || this.constructor;
  7056. if ( typeof fn !== "function" )
  7057. throw new TypeError( "_creatorFn must be omitted, null or a function." );
  7058. /*istanbul ignore else: NodeJS has the Error.captureStackTrace method natively*/
  7059. if ( Error.captureStackTrace )
  7060. Error.captureStackTrace( this, fn );
  7061. else
  7062. captureStackTrace( this, fn, new Error() );
  7063. decl.defineProperty( this, "message", { configurable: true, writable: true, value: _message } );
  7064. }
  7065. return decl.declareClass( Exception, Error,
  7066. /** @lends module:barejs.Exception# */
  7067. {
  7068. /**
  7069. * The name of the Exception type. Base classes are supposed to set the correct name on the prototype too.
  7070. * It is recommended not to use the constructor function's name for this, as that might get obfuscated by
  7071. * a minifier, or the name property may not be supported at all.
  7072. * @member {string}
  7073. */
  7074. name: { configurable: true, writable: true, value: "Exception" }
  7075. } );
  7076. // End of module
  7077. }( Error, __webpack_require__( 1 ) ) );
  7078. /***/ })
  7079. /******/ ]);