bare.debug.js 285 KB

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