JavascriptLibrary.cpp 490 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "RuntimeLibraryPch.h"
  6. #include "Library/JSON.h"
  7. #include "Types/MissingPropertyTypeHandler.h"
  8. #include "Types/NullTypeHandler.h"
  9. #include "Types/SimpleTypeHandler.h"
  10. #include "Types/DeferredTypeHandler.h"
  11. #include "Types/PathTypeHandler.h"
  12. #include "Types/PropertyIndexRanges.h"
  13. #include "Types/SimpleDictionaryPropertyDescriptor.h"
  14. #include "Types/SimpleDictionaryTypeHandler.h"
  15. #include "Library/ForInObjectEnumerator.h"
  16. #include "Library/EngineInterfaceObject.h"
  17. #include "Library/IntlEngineInterfaceExtensionObject.h"
  18. #ifdef ENABLE_JS_BUILTINS
  19. #include "Library/JsBuiltInEngineInterfaceExtensionObject.h"
  20. #endif
  21. #include "Library/ThrowErrorObject.h"
  22. #include "Library/StackScriptFunction.h"
  23. namespace Js
  24. {
  25. SimplePropertyDescriptor const JavascriptLibrary::SharedFunctionPropertyDescriptors[2] =
  26. {
  27. SimplePropertyDescriptor(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::prototype), PropertyWritable),
  28. SimplePropertyDescriptor(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::name), PropertyConfigurable)
  29. };
  30. SimplePropertyDescriptor const JavascriptLibrary::FunctionWithLengthAndNameTypeDescriptors[2] =
  31. {
  32. SimplePropertyDescriptor(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::length), PropertyConfigurable),
  33. SimplePropertyDescriptor(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::name), PropertyConfigurable)
  34. };
  35. SimplePropertyDescriptor const JavascriptLibrary::ModuleNamespaceTypeDescriptors[1] =
  36. {
  37. SimplePropertyDescriptor(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::_symbolToStringTag), PropertyConfigurable)
  38. };
  39. SimpleTypeHandler<1> JavascriptLibrary::SharedPrototypeTypeHandler(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::constructor), PropertyWritable | PropertyConfigurable, PropertyTypesWritableDataOnly, 4, sizeof(DynamicObject));
  40. SimpleTypeHandler<1> JavascriptLibrary::SharedFunctionWithoutPrototypeTypeHandler(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::name), PropertyConfigurable);
  41. SimpleTypeHandler<1> JavascriptLibrary::SharedFunctionWithPrototypeTypeHandlerV11(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::prototype), PropertyWritable);
  42. SimpleTypeHandler<2> JavascriptLibrary::SharedFunctionWithPrototypeTypeHandler(NO_WRITE_BARRIER_TAG(SharedFunctionPropertyDescriptors));
  43. SimpleTypeHandler<1> JavascriptLibrary::SharedIdMappedFunctionWithPrototypeTypeHandler(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::prototype));
  44. SimpleTypeHandler<1> JavascriptLibrary::SharedFunctionWithLengthTypeHandler(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::length));
  45. SimpleTypeHandler<2> JavascriptLibrary::SharedFunctionWithLengthAndNameTypeHandler(NO_WRITE_BARRIER_TAG(FunctionWithLengthAndNameTypeDescriptors));
  46. SimpleTypeHandler<1> JavascriptLibrary::SharedNamespaceSymbolTypeHandler(NO_WRITE_BARRIER_TAG(ModuleNamespaceTypeDescriptors));
  47. MissingPropertyTypeHandler JavascriptLibrary::MissingPropertyHolderTypeHandler;
  48. SimplePropertyDescriptor const JavascriptLibrary::HeapArgumentsPropertyDescriptors[3] =
  49. {
  50. SimplePropertyDescriptor(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::length), PropertyConfigurable | PropertyWritable),
  51. SimplePropertyDescriptor(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::callee), PropertyConfigurable | PropertyWritable),
  52. SimplePropertyDescriptor(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::_symbolIterator), PropertyConfigurable | PropertyWritable)
  53. };
  54. SimplePropertyDescriptor const JavascriptLibrary::FunctionWithLengthAndPrototypeTypeDescriptors[2] =
  55. {
  56. SimplePropertyDescriptor(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::prototype), PropertyNone),
  57. SimplePropertyDescriptor(NO_WRITE_BARRIER_TAG(BuiltInPropertyRecords::length), PropertyConfigurable)
  58. };
  59. void JavascriptLibrary::Initialize(ScriptContext* scriptContext, GlobalObject * globalObject)
  60. {
  61. PROBE_STACK(scriptContext, Js::Constants::MinStackDefault);
  62. #ifdef PROFILE_EXEC
  63. scriptContext->ProfileBegin(Js::LibInitPhase);
  64. #endif
  65. this->scriptContext = scriptContext;
  66. this->recycler = scriptContext->GetRecycler();
  67. this->undeclBlockVarSentinel = RecyclerNew(recycler, UndeclaredBlockVariable, StaticType::New(scriptContext, TypeIds_Null, nullptr, nullptr));
  68. typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain = RecyclerNew(recycler, JsUtil::List<Type *>, recycler);
  69. // Library is not zero-initialized. memset the memory occupied by builtinFunctions array to 0.
  70. ClearArray(builtinFunctions, BuiltinFunction::Count);
  71. // Note: InitializePrototypes and InitializeTypes must be called first.
  72. InitializePrototypes();
  73. InitializeTypes();
  74. InitializeGlobal(globalObject);
  75. InitializeComplexThings();
  76. InitializeStaticValues();
  77. PrecalculateArrayAllocationBuckets();
  78. this->cache.toStringTagCache = ScriptContextPolymorphicInlineCache::New(32, this);
  79. #if ENABLE_COPYONACCESS_ARRAY
  80. if (!PHASE_OFF1(CopyOnAccessArrayPhase))
  81. {
  82. this->cacheForCopyOnAccessArraySegments = RecyclerNewZ(this->recycler, CacheForCopyOnAccessArraySegments);
  83. }
  84. #endif
  85. #ifdef PROFILE_EXEC
  86. scriptContext->ProfileEnd(Js::LibInitPhase);
  87. #endif
  88. }
  89. void JavascriptLibrary::Uninitialize()
  90. {
  91. this->globalObject = nullptr;
  92. }
  93. void JavascriptLibrary::InitializePrototypes()
  94. {
  95. Recycler* recycler = this->GetRecycler();
  96. // Recycler macros below expect that their arguments will not throw when they're evaluated.
  97. // We allocate a lot of types for the built-in prototype objects which we need to store temporarily.
  98. DynamicType* tempDynamicType = nullptr;
  99. Type* tempType = StaticType::New(scriptContext, TypeIds_Null, nullptr, nullptr);
  100. nullValue = RecyclerNew(recycler, RecyclableObject, tempType);
  101. nullValue->GetType()->SetHasSpecialPrototype(true);
  102. this->rootPath = TypePath::New(recycler);
  103. // The prototype property of the object prototype is null.
  104. objectPrototype = ObjectPrototypeObject::New(recycler,
  105. DynamicType::New(scriptContext, TypeIds_Object, nullValue, nullptr,
  106. DeferredTypeHandler<InitializeObjectPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  107. constructorPrototypeObjectType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  108. &SharedPrototypeTypeHandler, true, true);
  109. constructorPrototypeObjectType->SetHasNoEnumerableProperties(true);
  110. arrayBufferPrototype = DynamicObject::New(recycler,
  111. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  112. DeferredTypeHandler<InitializeArrayBufferPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  113. if (scriptContext->GetConfig()->IsESSharedArrayBufferEnabled())
  114. {
  115. sharedArrayBufferPrototype = DynamicObject::New(recycler,
  116. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  117. DeferredTypeHandler<InitializeSharedArrayBufferPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  118. }
  119. else
  120. {
  121. sharedArrayBufferPrototype = nullptr;
  122. }
  123. dataViewPrototype = DynamicObject::New(recycler,
  124. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  125. DeferredTypeHandler<InitializeDataViewPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  126. typedArrayPrototype = DynamicObject::New(recycler,
  127. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  128. DeferredTypeHandler<InitializeTypedArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  129. Int8ArrayPrototype = DynamicObject::New(recycler,
  130. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  131. DeferredTypeHandler<InitializeInt8ArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  132. Uint8ArrayPrototype = DynamicObject::New(recycler,
  133. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  134. DeferredTypeHandler<InitializeUint8ArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  135. // If ES6 TypedArrays are enabled, we have Khronos Interop mode enabled
  136. Uint8ClampedArrayPrototype = DynamicObject::New(recycler,
  137. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  138. DeferredTypeHandler<InitializeUint8ClampedArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  139. Int16ArrayPrototype = DynamicObject::New(recycler,
  140. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  141. DeferredTypeHandler<InitializeInt16ArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  142. Uint16ArrayPrototype = DynamicObject::New(recycler,
  143. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  144. DeferredTypeHandler<InitializeUint16ArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  145. Int32ArrayPrototype = DynamicObject::New(recycler,
  146. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  147. DeferredTypeHandler<InitializeInt32ArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  148. Uint32ArrayPrototype = DynamicObject::New(recycler,
  149. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  150. DeferredTypeHandler<InitializeUint32ArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  151. Float32ArrayPrototype = DynamicObject::New(recycler,
  152. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  153. DeferredTypeHandler<InitializeFloat32ArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  154. Float64ArrayPrototype = DynamicObject::New(recycler,
  155. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  156. DeferredTypeHandler<InitializeFloat64ArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  157. Int64ArrayPrototype = DynamicObject::New(recycler,
  158. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  159. DeferredTypeHandler<InitializeInt64ArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  160. Uint64ArrayPrototype = DynamicObject::New(recycler,
  161. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  162. DeferredTypeHandler<InitializeUint64ArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  163. BoolArrayPrototype = DynamicObject::New(recycler,
  164. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  165. DeferredTypeHandler<InitializeBoolArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  166. CharArrayPrototype = DynamicObject::New(recycler,
  167. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  168. DeferredTypeHandler<InitializeCharArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  169. arrayPrototype = JavascriptArray::New<Var, JavascriptArray, 0>(0,
  170. DynamicType::New(scriptContext, TypeIds_Array, objectPrototype, nullptr,
  171. DeferredTypeHandler<InitializeArrayPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()), recycler);
  172. tempDynamicType = DynamicType::New(scriptContext, TypeIds_BooleanObject, objectPrototype, nullptr,
  173. DeferredTypeHandler<InitializeBooleanPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  174. booleanPrototype = RecyclerNew(recycler, JavascriptBooleanObject, nullptr, tempDynamicType);
  175. tempDynamicType = DynamicType::New(scriptContext, TypeIds_NumberObject, objectPrototype, nullptr,
  176. DeferredTypeHandler<InitializeNumberPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  177. numberPrototype = RecyclerNew(recycler, JavascriptNumberObject, TaggedInt::ToVarUnchecked(0), tempDynamicType);
  178. tempDynamicType = DynamicType::New(scriptContext, TypeIds_StringObject, objectPrototype, nullptr,
  179. DeferredTypeHandler<InitializeStringPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  180. stringPrototype = RecyclerNew(recycler, JavascriptStringObject, nullptr, tempDynamicType);
  181. #ifdef ENABLE_SIMDJS
  182. /* Initialize SIMD prototypes*/
  183. if (GetScriptContext()->GetConfig()->IsSimdjsEnabled())
  184. {
  185. tempDynamicType = DynamicType::New(scriptContext, TypeIds_SIMDObject, objectPrototype, nullptr,
  186. DeferredTypeHandler<InitializeSIMDBool8x16Prototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  187. simdBool8x16Prototype = RecyclerNew(recycler, JavascriptSIMDObject, nullptr, tempDynamicType);
  188. tempDynamicType = DynamicType::New(scriptContext, TypeIds_SIMDObject, objectPrototype, nullptr,
  189. DeferredTypeHandler<InitializeSIMDBool16x8Prototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  190. simdBool16x8Prototype = RecyclerNew(recycler, JavascriptSIMDObject, nullptr, tempDynamicType);
  191. tempDynamicType = DynamicType::New(scriptContext, TypeIds_SIMDObject, objectPrototype, nullptr,
  192. DeferredTypeHandler<InitializeSIMDBool32x4Prototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  193. simdBool32x4Prototype = RecyclerNew(recycler, JavascriptSIMDObject, nullptr, tempDynamicType);
  194. tempDynamicType = DynamicType::New(scriptContext, TypeIds_SIMDObject, objectPrototype, nullptr,
  195. DeferredTypeHandler<InitializeSIMDInt8x16Prototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  196. simdInt8x16Prototype = RecyclerNew(recycler, JavascriptSIMDObject, nullptr, tempDynamicType);
  197. tempDynamicType = DynamicType::New(scriptContext, TypeIds_SIMDObject, objectPrototype, nullptr,
  198. DeferredTypeHandler<InitializeSIMDInt16x8Prototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  199. simdInt16x8Prototype = RecyclerNew(recycler, JavascriptSIMDObject, nullptr, tempDynamicType);
  200. tempDynamicType = DynamicType::New(scriptContext, TypeIds_SIMDObject, objectPrototype, nullptr,
  201. DeferredTypeHandler<InitializeSIMDInt32x4Prototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  202. simdInt32x4Prototype = RecyclerNew(recycler, JavascriptSIMDObject, nullptr, tempDynamicType);
  203. tempDynamicType = DynamicType::New(scriptContext, TypeIds_SIMDObject, objectPrototype, nullptr,
  204. DeferredTypeHandler<InitializeSIMDUint8x16Prototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  205. simdUint8x16Prototype = RecyclerNew(recycler, JavascriptSIMDObject, nullptr, tempDynamicType);
  206. tempDynamicType = DynamicType::New(scriptContext, TypeIds_SIMDObject, objectPrototype, nullptr,
  207. DeferredTypeHandler<InitializeSIMDUint16x8Prototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  208. simdUint16x8Prototype = RecyclerNew(recycler, JavascriptSIMDObject, nullptr, tempDynamicType);
  209. tempDynamicType = DynamicType::New(scriptContext, TypeIds_SIMDObject, objectPrototype, nullptr,
  210. DeferredTypeHandler<InitializeSIMDUint32x4Prototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  211. simdUint32x4Prototype = RecyclerNew(recycler, JavascriptSIMDObject, nullptr, tempDynamicType);
  212. tempDynamicType = DynamicType::New(scriptContext, TypeIds_SIMDObject, objectPrototype, nullptr,
  213. DeferredTypeHandler<InitializeSIMDFloat32x4Prototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  214. simdFloat32x4Prototype = RecyclerNew(recycler, JavascriptSIMDObject, nullptr, tempDynamicType);
  215. }
  216. #endif
  217. if (scriptContext->GetConfig()->IsES6PrototypeChain())
  218. {
  219. datePrototype = DynamicObject::New(recycler,
  220. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  221. DeferredTypeHandler<InitializeDatePrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  222. regexPrototype = DynamicObject::New(recycler,
  223. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  224. DeferredTypeHandler<InitializeRegexPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  225. errorPrototype = DynamicObject::New(recycler,
  226. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  227. DeferredTypeHandler<InitializeErrorPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  228. }
  229. else
  230. {
  231. double initDateValue = JavascriptNumber::NaN;
  232. tempDynamicType = DynamicType::New(scriptContext, TypeIds_Date, objectPrototype, nullptr,
  233. DeferredTypeHandler<InitializeDatePrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  234. datePrototype = RecyclerNewZ(recycler, JavascriptDate, initDateValue, tempDynamicType);
  235. tempDynamicType = DynamicType::New(scriptContext, TypeIds_Error, objectPrototype, nullptr,
  236. DeferredTypeHandler<InitializeErrorPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  237. errorPrototype = RecyclerNew(this->GetRecycler(), JavascriptError, tempDynamicType, /*isExternalError*/FALSE, /*isPrototype*/TRUE);
  238. }
  239. #define INIT_ERROR_PROTO(field, initFunc) \
  240. if (scriptContext->GetConfig()->IsES6PrototypeChain()) \
  241. { \
  242. field = DynamicObject::New(recycler, \
  243. DynamicType::New(scriptContext, TypeIds_Object, errorPrototype, nullptr, \
  244. DeferredTypeHandler<initFunc, DefaultDeferredTypeFilter, true>::GetDefaultInstance())); \
  245. } \
  246. else \
  247. { \
  248. tempDynamicType = DynamicType::New(scriptContext, TypeIds_Error, errorPrototype, nullptr, \
  249. DeferredTypeHandler<initFunc, DefaultDeferredTypeFilter, true>::GetDefaultInstance()); \
  250. field = RecyclerNew(this->GetRecycler(), JavascriptError, tempDynamicType, /*isExternalError*/FALSE, /*isPrototype*/TRUE); \
  251. }
  252. INIT_ERROR_PROTO(evalErrorPrototype, InitializeEvalErrorPrototype);
  253. INIT_ERROR_PROTO(rangeErrorPrototype, InitializeRangeErrorPrototype);
  254. INIT_ERROR_PROTO(referenceErrorPrototype, InitializeReferenceErrorPrototype);
  255. INIT_ERROR_PROTO(syntaxErrorPrototype, InitializeSyntaxErrorPrototype);
  256. INIT_ERROR_PROTO(typeErrorPrototype, InitializeTypeErrorPrototype);
  257. INIT_ERROR_PROTO(uriErrorPrototype, InitializeURIErrorPrototype);
  258. #ifdef ENABLE_WASM
  259. if (CONFIG_FLAG(Wasm) && !PHASE_OFF1(Js::WasmPhase))
  260. {
  261. INIT_ERROR_PROTO(webAssemblyCompileErrorPrototype, InitializeWebAssemblyCompileErrorPrototype);
  262. INIT_ERROR_PROTO(webAssemblyRuntimeErrorPrototype, InitializeWebAssemblyRuntimeErrorPrototype);
  263. INIT_ERROR_PROTO(webAssemblyLinkErrorPrototype, InitializeWebAssemblyLinkErrorPrototype);
  264. }
  265. #endif
  266. #undef INIT_ERROR_PROTO
  267. tempDynamicType = DynamicType::New(scriptContext, TypeIds_Function, objectPrototype, JavascriptFunction::PrototypeEntryPoint,
  268. DeferredTypeHandler<InitializeFunctionPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  269. functionPrototype = RecyclerNew(recycler, JavascriptFunction, tempDynamicType, &JavascriptFunction::EntryInfo::PrototypeEntryPoint);
  270. promisePrototype = nullptr;
  271. generatorFunctionPrototype = nullptr;
  272. generatorPrototype = nullptr;
  273. asyncFunctionPrototype = nullptr;
  274. symbolPrototype = DynamicObject::New(recycler,
  275. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  276. DeferredTypeHandler<InitializeSymbolPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  277. mapPrototype = DynamicObject::New(recycler,
  278. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  279. DeferredTypeHandler<InitializeMapPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  280. setPrototype = DynamicObject::New(recycler,
  281. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  282. DeferredTypeHandler<InitializeSetPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  283. weakMapPrototype = DynamicObject::New(recycler,
  284. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  285. DeferredTypeHandler<InitializeWeakMapPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  286. weakSetPrototype = DynamicObject::New(recycler,
  287. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  288. DeferredTypeHandler<InitializeWeakSetPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  289. iteratorPrototype = DynamicObject::New(recycler,
  290. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  291. DeferredTypeHandler<InitializeIteratorPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  292. if (!scriptContext->IsJsBuiltInEnabled())
  293. {
  294. arrayIteratorPrototype = DynamicObject::New(recycler,
  295. DynamicType::New(scriptContext, TypeIds_Object, iteratorPrototype, nullptr,
  296. DeferredTypeHandler<InitializeArrayIteratorPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  297. }
  298. mapIteratorPrototype = DynamicObject::New(recycler,
  299. DynamicType::New(scriptContext, TypeIds_Object, iteratorPrototype, nullptr,
  300. DeferredTypeHandler<InitializeMapIteratorPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  301. setIteratorPrototype = DynamicObject::New(recycler,
  302. DynamicType::New(scriptContext, TypeIds_Object, iteratorPrototype, nullptr,
  303. DeferredTypeHandler<InitializeSetIteratorPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  304. stringIteratorPrototype = DynamicObject::New(recycler,
  305. DynamicType::New(scriptContext, TypeIds_Object, iteratorPrototype, nullptr,
  306. DeferredTypeHandler<InitializeStringIteratorPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  307. #ifdef ENABLE_WASM
  308. if (CONFIG_FLAG(Wasm) && !PHASE_OFF1(Js::WasmPhase))
  309. {
  310. webAssemblyMemoryPrototype = DynamicObject::New(recycler,
  311. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  312. DeferredTypeHandler<InitializeWebAssemblyMemoryPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  313. webAssemblyModulePrototype = DynamicObject::New(recycler,
  314. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  315. DeferredTypeHandler<InitializeWebAssemblyModulePrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  316. webAssemblyInstancePrototype = DynamicObject::New(recycler,
  317. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  318. DeferredTypeHandler<InitializeWebAssemblyInstancePrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  319. webAssemblyTablePrototype = DynamicObject::New(recycler,
  320. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  321. DeferredTypeHandler<InitializeWebAssemblyTablePrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  322. }
  323. #endif
  324. if(scriptContext->GetConfig()->IsES6PromiseEnabled())
  325. {
  326. promisePrototype = DynamicObject::New(recycler,
  327. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  328. DeferredTypeHandler<InitializePromisePrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  329. }
  330. if(scriptContext->GetConfig()->IsES6GeneratorsEnabled())
  331. {
  332. generatorFunctionPrototype = DynamicObject::New(recycler,
  333. DynamicType::New(scriptContext, TypeIds_Object, functionPrototype, nullptr,
  334. DeferredTypeHandler<InitializeGeneratorFunctionPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  335. generatorPrototype = DynamicObject::New(recycler,
  336. DynamicType::New(scriptContext, TypeIds_Object, iteratorPrototype, nullptr,
  337. DeferredTypeHandler<InitializeGeneratorPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  338. }
  339. if(scriptContext->GetConfig()->IsES7AsyncAndAwaitEnabled())
  340. {
  341. asyncFunctionPrototype = DynamicObject::New(recycler,
  342. DynamicType::New(scriptContext, TypeIds_Object, functionPrototype, nullptr,
  343. DeferredTypeHandler<InitializeAsyncFunctionPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  344. }
  345. }
  346. void JavascriptLibrary::InitializeTypes()
  347. {
  348. Recycler* recycler = this->GetRecycler();
  349. ScriptConfiguration const *config = scriptContext->GetConfig();
  350. enumeratorType = StaticType::New(scriptContext, TypeIds_Enumerator, objectPrototype, nullptr);
  351. // Initialize Array/Argument types
  352. heapArgumentsType = DynamicType::New(scriptContext, TypeIds_Arguments, objectPrototype, nullptr,
  353. SimpleDictionaryTypeHandler::New(scriptContext, HeapArgumentsPropertyDescriptors, _countof(HeapArgumentsPropertyDescriptors), 0, 0, true, true), true, true);
  354. #define INIT_SIMPLE_TYPE(field, typeId, prototype) \
  355. field = DynamicType::New(scriptContext, typeId, prototype, nullptr, \
  356. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true)
  357. INIT_SIMPLE_TYPE(activationObjectType, TypeIds_ActivationObject, nullValue);
  358. INIT_SIMPLE_TYPE(arrayType, TypeIds_Array, arrayPrototype);
  359. INIT_SIMPLE_TYPE(nativeIntArrayType, TypeIds_NativeIntArray, arrayPrototype);
  360. INIT_SIMPLE_TYPE(nativeFloatArrayType, TypeIds_NativeFloatArray, arrayPrototype);
  361. INIT_SIMPLE_TYPE(arrayBufferType, TypeIds_ArrayBuffer, arrayBufferPrototype);
  362. #if ENABLE_COPYONACCESS_ARRAY
  363. INIT_SIMPLE_TYPE(copyOnAccessNativeIntArrayType, TypeIds_CopyOnAccessNativeIntArray, arrayPrototype);
  364. #endif
  365. if (scriptContext->GetConfig()->IsESSharedArrayBufferEnabled())
  366. {
  367. INIT_SIMPLE_TYPE(sharedArrayBufferType, TypeIds_SharedArrayBuffer, sharedArrayBufferPrototype);
  368. }
  369. else
  370. {
  371. sharedArrayBufferType = nullptr;
  372. }
  373. INIT_SIMPLE_TYPE(dataViewType, TypeIds_DataView, dataViewPrototype);
  374. INIT_SIMPLE_TYPE(int8ArrayType, TypeIds_Int8Array, Int8ArrayPrototype);
  375. INIT_SIMPLE_TYPE(uint8ArrayType, TypeIds_Uint8Array, Uint8ArrayPrototype);
  376. INIT_SIMPLE_TYPE(uint8ClampedArrayType, TypeIds_Uint8ClampedArray, Uint8ClampedArrayPrototype);
  377. INIT_SIMPLE_TYPE(int16ArrayType, TypeIds_Int16Array, Int16ArrayPrototype);
  378. INIT_SIMPLE_TYPE(uint16ArrayType, TypeIds_Uint16Array, Uint16ArrayPrototype);
  379. INIT_SIMPLE_TYPE(int32ArrayType, TypeIds_Int32Array, Int32ArrayPrototype);
  380. INIT_SIMPLE_TYPE(uint32ArrayType, TypeIds_Uint32Array, Uint32ArrayPrototype);
  381. INIT_SIMPLE_TYPE(float32ArrayType, TypeIds_Float32Array, Float32ArrayPrototype);
  382. INIT_SIMPLE_TYPE(float64ArrayType, TypeIds_Float64Array, Float64ArrayPrototype);
  383. INIT_SIMPLE_TYPE(int64ArrayType, TypeIds_Int64Array, Int64ArrayPrototype);
  384. INIT_SIMPLE_TYPE(uint64ArrayType, TypeIds_Uint64Array, Uint64ArrayPrototype);
  385. INIT_SIMPLE_TYPE(boolArrayType, TypeIds_BoolArray, BoolArrayPrototype);
  386. INIT_SIMPLE_TYPE(charArrayType, TypeIds_CharArray, CharArrayPrototype);
  387. INIT_SIMPLE_TYPE(errorType, TypeIds_Error, errorPrototype);
  388. INIT_SIMPLE_TYPE(evalErrorType, TypeIds_Error, evalErrorPrototype);
  389. INIT_SIMPLE_TYPE(rangeErrorType, TypeIds_Error, rangeErrorPrototype);
  390. INIT_SIMPLE_TYPE(referenceErrorType, TypeIds_Error, referenceErrorPrototype);
  391. INIT_SIMPLE_TYPE(syntaxErrorType, TypeIds_Error, syntaxErrorPrototype);
  392. INIT_SIMPLE_TYPE(typeErrorType, TypeIds_Error, typeErrorPrototype);
  393. INIT_SIMPLE_TYPE(uriErrorType, TypeIds_Error, uriErrorPrototype);
  394. #ifdef ENABLE_WASM
  395. if (CONFIG_FLAG(Wasm) && !PHASE_OFF1(Js::WasmPhase))
  396. {
  397. INIT_SIMPLE_TYPE(webAssemblyCompileErrorType, TypeIds_Error, webAssemblyCompileErrorPrototype);
  398. INIT_SIMPLE_TYPE(webAssemblyRuntimeErrorType, TypeIds_Error, webAssemblyRuntimeErrorPrototype);
  399. INIT_SIMPLE_TYPE(webAssemblyLinkErrorType, TypeIds_Error, webAssemblyLinkErrorPrototype);
  400. }
  401. #endif
  402. #undef INIT_SIMPLE_TYPE
  403. withType = nullptr;
  404. proxyType = nullptr;
  405. promiseType = nullptr;
  406. moduleNamespaceType = nullptr;
  407. // Initialize boolean types
  408. booleanTypeStatic = StaticType::New(scriptContext, TypeIds_Boolean, booleanPrototype, nullptr);
  409. booleanTypeDynamic = DynamicType::New(scriptContext, TypeIds_BooleanObject, booleanPrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  410. // Initialize symbol types
  411. symbolTypeStatic = StaticType::New(scriptContext, TypeIds_Symbol, symbolPrototype, nullptr);
  412. symbolTypeDynamic = DynamicType::New(scriptContext, TypeIds_SymbolObject, symbolPrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  413. if (config->IsES6UnscopablesEnabled())
  414. {
  415. withType = StaticType::New(scriptContext, TypeIds_WithScopeObject, GetNull(), nullptr);
  416. }
  417. if (config->IsES6SpreadEnabled())
  418. {
  419. SpreadArgumentType = DynamicType::New(scriptContext, TypeIds_SpreadArgument, GetNull(), nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  420. }
  421. if (config->IsES6ProxyEnabled())
  422. {
  423. // proxy's prototype is not actually used. once a proxy is used, the GetType()->GetPrototype() is not used in instanceOf style usage as they are trapped.
  424. // We can use GetType()->GetPrototype() in [[get]], [[set]], and [[hasProperty]] to force the prototype walk to stop at prototype so we don't need to
  425. // continue prototype chain walk after proxy.
  426. proxyType = DynamicType::New(scriptContext, TypeIds_Proxy, GetNull(), nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  427. }
  428. if (config->IsES6PromiseEnabled())
  429. {
  430. promiseType = DynamicType::New(scriptContext, TypeIds_Promise, promisePrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  431. }
  432. if (config->IsES6ModuleEnabled())
  433. {
  434. moduleNamespaceType = DynamicType::New(scriptContext, TypeIds_ModuleNamespace, nullValue, nullptr, &SharedNamespaceSymbolTypeHandler);
  435. moduleNamespaceType->ShareType();
  436. }
  437. // Initialize Date types
  438. dateType = DynamicType::New(scriptContext, TypeIds_Date, datePrototype, nullptr,
  439. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  440. variantDateType = StaticType::New(scriptContext, TypeIds_VariantDate, nullValue, nullptr);
  441. anonymousFunctionTypeHandler = NullTypeHandler<false>::GetDefaultInstance();
  442. anonymousFunctionWithPrototypeTypeHandler = &SharedFunctionWithPrototypeTypeHandlerV11;
  443. // Initialize function types
  444. if (config->IsES6FunctionNameEnabled())
  445. {
  446. functionTypeHandler = &SharedFunctionWithoutPrototypeTypeHandler;
  447. }
  448. else
  449. {
  450. functionTypeHandler = anonymousFunctionTypeHandler;
  451. }
  452. if (config->IsES6FunctionNameEnabled())
  453. {
  454. functionWithPrototypeTypeHandler = &SharedFunctionWithPrototypeTypeHandler;
  455. }
  456. else
  457. {
  458. functionWithPrototypeTypeHandler = anonymousFunctionWithPrototypeTypeHandler;
  459. }
  460. functionWithPrototypeTypeHandler->SetHasKnownSlot0();
  461. externalFunctionWithDeferredPrototypeType = CreateDeferredPrototypeFunctionTypeNoProfileThunk(JavascriptExternalFunction::ExternalFunctionThunk, true /*isShared*/);
  462. externalFunctionWithLengthAndDeferredPrototypeType = CreateDeferredPrototypeFunctionTypeNoProfileThunk(JavascriptExternalFunction::ExternalFunctionThunk, true /*isShared*/, /* isLengthAvailable */ true);
  463. wrappedFunctionWithDeferredPrototypeType = CreateDeferredPrototypeFunctionTypeNoProfileThunk(JavascriptExternalFunction::WrappedFunctionThunk, true /*isShared*/);
  464. stdCallFunctionWithDeferredPrototypeType = CreateDeferredPrototypeFunctionTypeNoProfileThunk(JavascriptExternalFunction::StdCallExternalFunctionThunk, true /*isShared*/);
  465. idMappedFunctionWithPrototypeType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, JavascriptExternalFunction::ExternalFunctionThunk,
  466. &SharedIdMappedFunctionWithPrototypeTypeHandler, true, true);
  467. externalConstructorFunctionWithDeferredPrototypeType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, JavascriptExternalFunction::ExternalFunctionThunk,
  468. Js::DeferredTypeHandler<Js::JavascriptExternalFunction::DeferredConstructorInitializer>::GetDefaultInstance(), true, true);
  469. defaultExternalConstructorFunctionWithDeferredPrototypeType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, JavascriptExternalFunction::DefaultExternalFunctionThunk,
  470. Js::DeferredTypeHandler<Js::JavascriptExternalFunction::DeferredConstructorInitializer>::GetDefaultInstance(), true, true);
  471. if (config->IsES6FunctionNameEnabled())
  472. {
  473. boundFunctionType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, BoundFunction::NewInstance,
  474. GetDeferredFunctionTypeHandler(), true, true);
  475. }
  476. else
  477. {
  478. boundFunctionType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, BoundFunction::NewInstance,
  479. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  480. }
  481. crossSiteDeferredPrototypeFunctionType = CreateDeferredPrototypeFunctionTypeNoProfileThunk(
  482. scriptContext->CurrentCrossSiteThunk, true /*isShared*/);
  483. crossSiteIdMappedFunctionWithPrototypeType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, scriptContext->CurrentCrossSiteThunk,
  484. &SharedIdMappedFunctionWithPrototypeTypeHandler, true, true);
  485. crossSiteExternalConstructFunctionWithPrototypeType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, scriptContext->CurrentCrossSiteThunk,
  486. Js::DeferredTypeHandler<Js::JavascriptExternalFunction::DeferredConstructorInitializer>::GetDefaultInstance(), true, true);
  487. // Initialize Number types
  488. numberTypeStatic = StaticType::New(scriptContext, TypeIds_Number, numberPrototype, nullptr);
  489. int64NumberTypeStatic = StaticType::New(scriptContext, TypeIds_Int64Number, numberPrototype, nullptr);
  490. uint64NumberTypeStatic = StaticType::New(scriptContext, TypeIds_UInt64Number, numberPrototype, nullptr);
  491. numberTypeDynamic = DynamicType::New(scriptContext, TypeIds_NumberObject, numberPrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  492. // SIMD_JS
  493. // Initialize types
  494. #ifdef ENABLE_SIMDJS
  495. if (GetScriptContext()->GetConfig()->IsSimdjsEnabled())
  496. {
  497. simdBool8x16TypeDynamic = DynamicType::New(scriptContext, TypeIds_SIMDObject, simdBool8x16Prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  498. simdBool16x8TypeDynamic = DynamicType::New(scriptContext, TypeIds_SIMDObject, simdBool16x8Prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  499. simdBool32x4TypeDynamic = DynamicType::New(scriptContext, TypeIds_SIMDObject, simdBool32x4Prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  500. simdInt8x16TypeDynamic = DynamicType::New(scriptContext, TypeIds_SIMDObject, simdInt8x16Prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  501. simdInt16x8TypeDynamic = DynamicType::New(scriptContext, TypeIds_SIMDObject, simdInt16x8Prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  502. simdInt32x4TypeDynamic = DynamicType::New(scriptContext, TypeIds_SIMDObject, simdInt32x4Prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  503. simdUint8x16TypeDynamic = DynamicType::New(scriptContext, TypeIds_SIMDObject, simdUint8x16Prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  504. simdUint16x8TypeDynamic = DynamicType::New(scriptContext, TypeIds_SIMDObject, simdUint16x8Prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  505. simdUint32x4TypeDynamic = DynamicType::New(scriptContext, TypeIds_SIMDObject, simdUint32x4Prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  506. simdFloat32x4TypeDynamic = DynamicType::New(scriptContext, TypeIds_SIMDObject, simdFloat32x4Prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  507. simdFloat32x4TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDFloat32x4, simdFloat32x4Prototype , nullptr);
  508. //simdFloat64x2TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDFloat64x2, simdFloat64x2Prototype, nullptr);
  509. simdInt32x4TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDInt32x4, simdInt32x4Prototype, nullptr);
  510. simdInt16x8TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDInt16x8, simdInt16x8Prototype, nullptr);
  511. simdInt8x16TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDInt8x16, simdInt8x16Prototype, nullptr);
  512. simdBool32x4TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDBool32x4, simdBool32x4Prototype, nullptr);
  513. simdBool16x8TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDBool16x8, simdBool16x8Prototype, nullptr);
  514. simdBool8x16TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDBool8x16, simdBool8x16Prototype, nullptr);
  515. simdUint32x4TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDUint32x4, simdUint32x4Prototype, nullptr);
  516. simdUint16x8TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDUint16x8, simdUint16x8Prototype, nullptr);
  517. simdUint8x16TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDUint8x16, simdUint8x16Prototype, nullptr);
  518. }
  519. #endif
  520. #ifdef ENABLE_WASM
  521. if (CONFIG_FLAG(Wasm) && !PHASE_OFF1(Js::WasmPhase))
  522. {
  523. webAssemblyModuleType = DynamicType::New(scriptContext, TypeIds_WebAssemblyModule, webAssemblyModulePrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  524. webAssemblyInstanceType = DynamicType::New(scriptContext, TypeIds_WebAssemblyInstance, webAssemblyInstancePrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  525. webAssemblyMemoryType = DynamicType::New(scriptContext, TypeIds_WebAssemblyMemory, webAssemblyMemoryPrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  526. webAssemblyTableType = DynamicType::New(scriptContext, TypeIds_WebAssemblyTable, webAssemblyTablePrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  527. }
  528. #endif
  529. // Initialize Object types
  530. for (int16 i = 0; i < PreInitializedObjectTypeCount; i++)
  531. {
  532. SimplePathTypeHandlerNoAttr * typeHandler =
  533. SimplePathTypeHandlerNoAttr::New(
  534. scriptContext,
  535. this->GetRootPath(),
  536. 0,
  537. i * InlineSlotCountIncrement,
  538. sizeof(DynamicObject),
  539. true,
  540. true);
  541. typeHandler->SetIsInlineSlotCapacityLocked();
  542. objectTypes[i] = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr, typeHandler, true, true);
  543. }
  544. for (int16 i = 0; i < PreInitializedObjectTypeCount; i++)
  545. {
  546. SimplePathTypeHandlerNoAttr * typeHandler =
  547. SimplePathTypeHandlerNoAttr::New(
  548. scriptContext,
  549. this->GetRootPath(),
  550. 0,
  551. DynamicTypeHandler::GetObjectHeaderInlinableSlotCapacity() + i * InlineSlotCountIncrement,
  552. DynamicTypeHandler::GetOffsetOfObjectHeaderInlineSlots(),
  553. true,
  554. true);
  555. typeHandler->SetIsInlineSlotCapacityLocked();
  556. objectHeaderInlinedTypes[i] =
  557. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr, typeHandler, true, true);
  558. }
  559. SimplePathTypeHandlerNoAttr * typeHandler = SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true);
  560. nullPrototypeObjectType = DynamicType::New(scriptContext, TypeIds_Object, nullValue, nullptr, typeHandler, true, true);
  561. // Initialize regex types
  562. TypePath *const regexResultPath = TypePath::New(recycler);
  563. regexResultPath->Add(BuiltInPropertyRecords::input);
  564. regexResultPath->Add(BuiltInPropertyRecords::index);
  565. regexResultType = DynamicType::New(scriptContext, TypeIds_Array, arrayPrototype, nullptr,
  566. SimplePathTypeHandlerNoAttr::New(scriptContext, regexResultPath, regexResultPath->GetPathLength(), JavascriptRegularExpressionResult::InlineSlotCount, sizeof(JavascriptArray), true, true), true, true);
  567. // Initialize string types
  568. // static type is handled under StringCache.h
  569. stringTypeDynamic = DynamicType::New(scriptContext, TypeIds_StringObject, stringPrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  570. // Initialize Throw error object type
  571. throwErrorObjectType = StaticType::New(scriptContext, TypeIds_Undefined, nullValue, ThrowErrorObject::DefaultEntryPoint);
  572. mapType = DynamicType::New(scriptContext, TypeIds_Map, mapPrototype, nullptr,
  573. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  574. setType = DynamicType::New(scriptContext, TypeIds_Set, setPrototype, nullptr,
  575. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  576. weakMapType = DynamicType::New(scriptContext, TypeIds_WeakMap, weakMapPrototype, nullptr,
  577. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  578. weakSetType = DynamicType::New(scriptContext, TypeIds_WeakSet, weakSetPrototype, nullptr,
  579. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  580. TypePath *const iteratorResultPath = TypePath::New(recycler);
  581. iteratorResultPath->Add(BuiltInPropertyRecords::value);
  582. iteratorResultPath->Add(BuiltInPropertyRecords::done);
  583. iteratorResultType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  584. SimplePathTypeHandlerNoAttr::New(scriptContext, iteratorResultPath, iteratorResultPath->GetPathLength(), 2, sizeof(DynamicObject), true, true), true, true);
  585. arrayIteratorType = DynamicType::New(scriptContext, TypeIds_ArrayIterator, arrayIteratorPrototype, nullptr,
  586. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  587. mapIteratorType = DynamicType::New(scriptContext, TypeIds_MapIterator, mapIteratorPrototype, nullptr,
  588. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  589. setIteratorType = DynamicType::New(scriptContext, TypeIds_SetIterator, setIteratorPrototype, nullptr,
  590. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  591. stringIteratorType = DynamicType::New(scriptContext, TypeIds_StringIterator, stringIteratorPrototype, nullptr,
  592. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  593. listIteratorType = DynamicType::New(scriptContext, TypeIds_ListIterator, iteratorPrototype, nullptr,
  594. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  595. if (config->IsES6GeneratorsEnabled())
  596. {
  597. generatorConstructorPrototypeObjectType = DynamicType::New(scriptContext, TypeIds_Object, generatorPrototype, nullptr,
  598. NullTypeHandler<false>::GetDefaultInstance(), true, true);
  599. generatorConstructorPrototypeObjectType->SetHasNoEnumerableProperties(true);
  600. }
  601. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  602. debugDisposableObjectType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  603. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  604. debugFuncExecutorInDisposeObjectType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  605. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  606. #endif
  607. }
  608. bool JavascriptLibrary::InitializeGeneratorFunction(DynamicObject *function, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  609. {
  610. bool isAnonymousFunction = JavascriptGeneratorFunction::FromVar(function)->IsAnonymousFunction();
  611. JavascriptLibrary* javascriptLibrary = function->GetType()->GetLibrary();
  612. typeHandler->Convert(function, isAnonymousFunction ? javascriptLibrary->anonymousFunctionWithPrototypeTypeHandler : javascriptLibrary->functionWithPrototypeTypeHandler);
  613. function->SetPropertyWithAttributes(PropertyIds::prototype, javascriptLibrary->CreateGeneratorConstructorPrototypeObject(), PropertyWritable, nullptr);
  614. if (function->GetScriptContext()->GetConfig()->IsES6FunctionNameEnabled() && !isAnonymousFunction)
  615. {
  616. JavascriptString * functionName = nullptr;
  617. DebugOnly(bool status = ) ((Js::JavascriptFunction*)function)->GetFunctionName(&functionName);
  618. Assert(status);
  619. function->SetPropertyWithAttributes(PropertyIds::name,functionName, PropertyConfigurable, nullptr);
  620. }
  621. return true;
  622. }
  623. bool JavascriptLibrary::InitializeAsyncFunction(DynamicObject *function, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  624. {
  625. // Async function instances do not have a prototype property as they are not constructable
  626. typeHandler->Convert(function, mode, 1);
  627. if (function->GetScriptContext()->GetConfig()->IsES6FunctionNameEnabled() && !JavascriptAsyncFunction::FromVar(function)->IsAnonymousFunction())
  628. {
  629. JavascriptString * functionName = nullptr;
  630. DebugOnly(bool status = ) ((Js::JavascriptFunction*)function)->GetFunctionName(&functionName);
  631. Assert(status);
  632. function->SetPropertyWithAttributes(PropertyIds::name, functionName, PropertyConfigurable, nullptr);
  633. }
  634. return true;
  635. }
  636. /* static */
  637. void JavascriptLibrary::PrecalculateArrayAllocationBuckets()
  638. {
  639. JavascriptArray::EnsureCalculationOfAllocationBuckets<Js::JavascriptNativeIntArray>();
  640. JavascriptArray::EnsureCalculationOfAllocationBuckets<Js::JavascriptNativeFloatArray>();
  641. JavascriptArray::EnsureCalculationOfAllocationBuckets<Js::JavascriptArray>();
  642. }
  643. template<bool addPrototype>
  644. bool JavascriptLibrary::InitializeFunction(DynamicObject *function, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  645. {
  646. JavascriptLibrary* javascriptLibrary = function->GetType()->GetLibrary();
  647. ScriptFunction *scriptFunction = nullptr;
  648. bool useAnonymous = false;
  649. if (ScriptFunction::Is(function))
  650. {
  651. scriptFunction = Js::ScriptFunction::FromVar(function);
  652. useAnonymous = scriptFunction->IsAnonymousFunction();
  653. }
  654. if (!addPrototype)
  655. {
  656. Assert(!useAnonymous);
  657. typeHandler->Convert(function, javascriptLibrary->functionTypeHandler);
  658. }
  659. else
  660. {
  661. typeHandler->Convert(function, useAnonymous ? javascriptLibrary->anonymousFunctionWithPrototypeTypeHandler : javascriptLibrary->functionWithPrototypeTypeHandler);
  662. function->SetProperty(PropertyIds::prototype, javascriptLibrary->CreateConstructorPrototypeObject((Js::JavascriptFunction *)function), PropertyOperation_None, nullptr);
  663. }
  664. if (scriptFunction)
  665. {
  666. if (scriptFunction->GetFunctionInfo()->IsClassConstructor())
  667. {
  668. scriptFunction->SetWritable(Js::PropertyIds::prototype, FALSE);
  669. }
  670. }
  671. ScriptContext *scriptContext = function->GetScriptContext();
  672. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  673. {
  674. if(scriptFunction && (useAnonymous || scriptFunction->GetFunctionProxy()->EnsureDeserialized()->GetIsStaticNameFunction()))
  675. {
  676. return true;
  677. }
  678. JavascriptString * functionName = nullptr;
  679. if (((Js::JavascriptFunction*)function)->GetFunctionName(&functionName))
  680. {
  681. function->SetPropertyWithAttributes(PropertyIds::name, functionName, PropertyConfigurable, nullptr);
  682. }
  683. }
  684. return true;
  685. }
  686. DynamicType* JavascriptLibrary::GetErrorType(ErrorTypeEnum typeToFind) const
  687. {
  688. switch (typeToFind)
  689. {
  690. case kjstError:
  691. return GetErrorType();
  692. case kjstEvalError:
  693. return GetEvalErrorType();
  694. case kjstRangeError:
  695. return GetRangeErrorType();
  696. case kjstReferenceError:
  697. return GetReferenceErrorType();
  698. case kjstSyntaxError:
  699. return GetSyntaxErrorType();
  700. case kjstTypeError:
  701. return GetTypeErrorType();
  702. case kjstURIError:
  703. return GetURIErrorType();
  704. case kjstWebAssemblyCompileError:
  705. return GetWebAssemblyCompileErrorType();
  706. case kjstWebAssemblyRuntimeError:
  707. return GetWebAssemblyRuntimeErrorType();
  708. case kjstWebAssemblyLinkError:
  709. return GetWebAssemblyLinkErrorType();
  710. }
  711. return nullptr;
  712. }
  713. template<bool isNameAvailable, bool isPrototypeAvailable, bool isLengthAvailable = false>
  714. class InitializeFunctionDeferredTypeHandlerFilter
  715. {
  716. public:
  717. static bool HasFilter() { return true; }
  718. static bool HasProperty(PropertyId propertyId)
  719. {
  720. switch (propertyId)
  721. {
  722. case PropertyIds::prototype:
  723. return isPrototypeAvailable;
  724. case PropertyIds::name:
  725. return isNameAvailable;
  726. case PropertyIds::length:
  727. return isLengthAvailable;
  728. }
  729. return false;
  730. }
  731. };
  732. template<bool isNameAvailable, bool isPrototypeAvailable, bool isLengthAvailable>
  733. DynamicTypeHandler * JavascriptLibrary::GetDeferredFunctionTypeHandlerBase()
  734. {
  735. return DeferredTypeHandler<InitializeFunction<isPrototypeAvailable>, InitializeFunctionDeferredTypeHandlerFilter<isNameAvailable, isPrototypeAvailable, isLengthAvailable>>::GetDefaultInstance();
  736. }
  737. template<bool isNameAvailable, bool isPrototypeAvailable>
  738. DynamicTypeHandler * JavascriptLibrary::GetDeferredGeneratorFunctionTypeHandlerBase()
  739. {
  740. return DeferredTypeHandler<InitializeGeneratorFunction, InitializeFunctionDeferredTypeHandlerFilter<isNameAvailable, isPrototypeAvailable>>::GetDefaultInstance();
  741. }
  742. template<bool isNameAvailable>
  743. DynamicTypeHandler * JavascriptLibrary::GetDeferredAsyncFunctionTypeHandlerBase()
  744. {
  745. // Async functions do not have the prototype property
  746. return DeferredTypeHandler<InitializeAsyncFunction, InitializeFunctionDeferredTypeHandlerFilter<isNameAvailable, /* isPrototypeAvailable */ false>>::GetDefaultInstance();
  747. }
  748. DynamicTypeHandler * JavascriptLibrary::GetDeferredAnonymousPrototypeGeneratorFunctionTypeHandler()
  749. {
  750. return JavascriptLibrary::GetDeferredGeneratorFunctionTypeHandlerBase</*isNameAvailable*/ false>();
  751. }
  752. DynamicTypeHandler * JavascriptLibrary::GetDeferredAnonymousPrototypeAsyncFunctionTypeHandler()
  753. {
  754. return JavascriptLibrary::GetDeferredAsyncFunctionTypeHandlerBase</*isNameAvailable*/ false>();
  755. }
  756. DynamicTypeHandler * JavascriptLibrary::GetDeferredPrototypeGeneratorFunctionTypeHandler(ScriptContext* scriptContext)
  757. {
  758. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  759. {
  760. return JavascriptLibrary::GetDeferredGeneratorFunctionTypeHandlerBase</*isNameAvailable*/ true>();
  761. }
  762. else
  763. {
  764. return JavascriptLibrary::GetDeferredGeneratorFunctionTypeHandlerBase</*isNameAvailable*/ false>();
  765. }
  766. }
  767. DynamicTypeHandler * JavascriptLibrary::GetDeferredPrototypeAsyncFunctionTypeHandler(ScriptContext* scriptContext)
  768. {
  769. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  770. {
  771. return JavascriptLibrary::GetDeferredAsyncFunctionTypeHandlerBase</*isNameAvailable*/ true>();
  772. }
  773. else
  774. {
  775. return JavascriptLibrary::GetDeferredAsyncFunctionTypeHandlerBase</*isNameAvailable*/ false>();
  776. }
  777. }
  778. DynamicTypeHandler * JavascriptLibrary::GetDeferredAnonymousPrototypeFunctionTypeHandler()
  779. {
  780. return JavascriptLibrary::GetDeferredFunctionTypeHandlerBase</*isNameAvailable*/ false>();
  781. }
  782. DynamicTypeHandler * JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler(ScriptContext* scriptContext)
  783. {
  784. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  785. {
  786. return JavascriptLibrary::GetDeferredFunctionTypeHandlerBase</* isNameAvailable */ true>();
  787. }
  788. else
  789. {
  790. return JavascriptLibrary::GetDeferredFunctionTypeHandlerBase</* isNameAvailable */ false>();
  791. }
  792. }
  793. DynamicTypeHandler * JavascriptLibrary::GetDeferredPrototypeFunctionWithLengthTypeHandler(ScriptContext* scriptContext)
  794. {
  795. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  796. {
  797. return DeferredTypeHandler<Js::JavascriptExternalFunction::DeferredLengthInitializer, InitializeFunctionDeferredTypeHandlerFilter</* isNameAvailable */ true, /* isPrototypeAvailable */ true, /* isLengthAvailable */ true>>::GetDefaultInstance();
  798. }
  799. else
  800. {
  801. return DeferredTypeHandler<Js::JavascriptExternalFunction::DeferredLengthInitializer, InitializeFunctionDeferredTypeHandlerFilter</* isNameAvailable */ false, /* isPrototypeAvailable */ true, /* isLengthAvailable */ true>>::GetDefaultInstance();
  802. }
  803. }
  804. DynamicTypeHandler * JavascriptLibrary::GetDeferredAnonymousFunctionTypeHandler()
  805. {
  806. return anonymousFunctionTypeHandler;
  807. }
  808. DynamicTypeHandler * JavascriptLibrary::GetDeferredFunctionTypeHandler()
  809. {
  810. if (this->GetScriptContext()->GetConfig()->IsES6FunctionNameEnabled())
  811. {
  812. return GetDeferredFunctionTypeHandlerBase</*isNameAvailable*/ true, /*isPrototypeAvailable*/ false>();
  813. }
  814. return functionTypeHandler;
  815. }
  816. DynamicTypeHandler * JavascriptLibrary::ScriptFunctionTypeHandler(bool noPrototypeProperty, bool isAnonymousFunction)
  817. {
  818. DynamicTypeHandler * scriptFunctionTypeHandler = nullptr;
  819. if (noPrototypeProperty)
  820. {
  821. scriptFunctionTypeHandler = isAnonymousFunction ?
  822. this->GetDeferredAnonymousFunctionTypeHandler() :
  823. this->GetDeferredFunctionTypeHandler();
  824. }
  825. else
  826. {
  827. scriptFunctionTypeHandler = isAnonymousFunction ?
  828. JavascriptLibrary::GetDeferredAnonymousPrototypeFunctionTypeHandler() :
  829. JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler(scriptContext);
  830. }
  831. return scriptFunctionTypeHandler;
  832. }
  833. DynamicType * JavascriptLibrary::CreateDeferredPrototypeGeneratorFunctionType(JavascriptMethod entrypoint, bool isAnonymousFunction, bool isShared)
  834. {
  835. return DynamicType::New(scriptContext, TypeIds_Function, generatorFunctionPrototype, entrypoint,
  836. isAnonymousFunction ? GetDeferredAnonymousPrototypeGeneratorFunctionTypeHandler() : GetDeferredPrototypeGeneratorFunctionTypeHandler(scriptContext), isShared, isShared);
  837. }
  838. DynamicType * JavascriptLibrary::CreateDeferredPrototypeAsyncFunctionType(JavascriptMethod entrypoint, bool isAnonymousFunction, bool isShared)
  839. {
  840. return DynamicType::New(scriptContext, TypeIds_Function, asyncFunctionPrototype, entrypoint,
  841. isAnonymousFunction ? GetDeferredAnonymousPrototypeAsyncFunctionTypeHandler() : GetDeferredPrototypeAsyncFunctionTypeHandler(scriptContext), isShared, isShared);
  842. }
  843. DynamicType * JavascriptLibrary::CreateDeferredPrototypeFunctionType(JavascriptMethod entrypoint)
  844. {
  845. return CreateDeferredPrototypeFunctionTypeNoProfileThunk(this->inDispatchProfileMode ? ProfileEntryThunk : entrypoint);
  846. }
  847. DynamicType * JavascriptLibrary::CreateDeferredPrototypeFunctionTypeNoProfileThunk(JavascriptMethod entrypoint, bool isShared, bool isLengthAvailable)
  848. {
  849. // Note: the lack of TypeHandler switching here based on the isAnonymousFunction flag is intentional.
  850. // We can't switch shared typeHandlers and RuntimeFunctions do not produce script code for us to know if a function is Anonymous.
  851. // As a result we may have an issue where hasProperty would say you have a name property but getProperty returns undefined
  852. return DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, entrypoint,
  853. isLengthAvailable ? GetDeferredPrototypeFunctionWithLengthTypeHandler(scriptContext) : GetDeferredPrototypeFunctionTypeHandler(scriptContext),
  854. isShared, isShared);
  855. }
  856. DynamicType * JavascriptLibrary::CreateFunctionType(JavascriptMethod entrypoint, RecyclableObject* prototype)
  857. {
  858. if (prototype == nullptr)
  859. {
  860. prototype = functionPrototype;
  861. }
  862. return DynamicType::New(scriptContext, TypeIds_Function, prototype, entrypoint,
  863. GetDeferredFunctionTypeHandler(), false, false);
  864. }
  865. DynamicType * JavascriptLibrary::CreateFunctionWithLengthType(FunctionInfo * functionInfo)
  866. {
  867. return CreateFunctionWithLengthType(this->GetFunctionPrototype(), functionInfo);
  868. }
  869. DynamicType * JavascriptLibrary::CreateFunctionWithLengthAndNameType(FunctionInfo * functionInfo)
  870. {
  871. return CreateFunctionWithLengthAndNameType(this->GetFunctionPrototype(), functionInfo);
  872. }
  873. DynamicType * JavascriptLibrary::CreateFunctionWithLengthAndPrototypeType(FunctionInfo * functionInfo)
  874. {
  875. return CreateFunctionWithLengthAndPrototypeType(this->GetFunctionPrototype(), functionInfo);
  876. }
  877. DynamicType * JavascriptLibrary::CreateFunctionWithLengthType(DynamicObject * prototype, FunctionInfo * functionInfo)
  878. {
  879. Assert(!functionInfo->HasBody());
  880. return DynamicType::New(scriptContext, TypeIds_Function, prototype,
  881. this->inProfileMode? ProfileEntryThunk : functionInfo->GetOriginalEntryPoint(),
  882. &SharedFunctionWithLengthTypeHandler);
  883. }
  884. DynamicType * JavascriptLibrary::CreateFunctionWithLengthAndNameType(DynamicObject * prototype, FunctionInfo * functionInfo)
  885. {
  886. Assert(!functionInfo->HasBody());
  887. return DynamicType::New(scriptContext, TypeIds_Function, prototype,
  888. this->inProfileMode ? ProfileEntryThunk : functionInfo->GetOriginalEntryPoint(),
  889. &SharedFunctionWithLengthAndNameTypeHandler);
  890. }
  891. DynamicType * JavascriptLibrary::CreateFunctionWithLengthAndPrototypeType(DynamicObject * prototype, FunctionInfo * functionInfo)
  892. {
  893. Assert(!functionInfo->HasBody());
  894. return DynamicType::New(scriptContext, TypeIds_Function, prototype,
  895. this->inProfileMode? ProfileEntryThunk : functionInfo->GetOriginalEntryPoint(),
  896. SimpleDictionaryTypeHandler::New(scriptContext, FunctionWithLengthAndPrototypeTypeDescriptors, _countof(FunctionWithLengthAndPrototypeTypeDescriptors), 0, 0));
  897. }
  898. void JavascriptLibrary::InitializeProperties(ThreadContext * threadContext)
  899. {
  900. if ( threadContext->GetMaxPropertyId() < PropertyIds::_countJSOnlyProperty )
  901. {
  902. threadContext->UncheckedAddBuiltInPropertyId();
  903. }
  904. }
  905. DynamicObject * JavascriptLibraryBase::GetObjectPrototype()
  906. {
  907. return GetObjectPrototypeObject();
  908. }
  909. void JavascriptLibraryBase::Finalize(bool isShutdown)
  910. {
  911. if (scriptContext)
  912. {
  913. // Clear the weak reference dictionary so we don't need to clean them
  914. // during PostCollectCallBack before Dispose deleting the script context.
  915. scriptContext->ResetWeakReferenceDictionaryList();
  916. scriptContext->SetIsFinalized();
  917. scriptContext->MarkForClose();
  918. if (scriptContext->IsRegistered())
  919. {
  920. scriptContext->GetThreadContext()->UnregisterScriptContext(scriptContext);
  921. }
  922. }
  923. }
  924. void JavascriptLibraryBase::Dispose(bool isShutdown)
  925. {
  926. if (scriptContext)
  927. {
  928. HeapDelete(scriptContext);
  929. scriptContext = nullptr;
  930. }
  931. }
  932. void JavascriptLibrary::Finalize(bool isShutdown)
  933. {
  934. __super::Finalize(isShutdown);
  935. this->SetFakeGlobalFuncForUndefer(nullptr);
  936. if (this->referencedPropertyRecords != nullptr)
  937. {
  938. RECYCLER_PERF_COUNTER_SUB(PropertyRecordBindReference, this->referencedPropertyRecords->Count());
  939. }
  940. }
  941. void JavascriptLibrary::InitializeGlobal(GlobalObject * globalObject)
  942. {
  943. RecyclableObject* globalObjectPrototype = GetObjectPrototype();
  944. globalObject->SetPrototype(globalObjectPrototype);
  945. Recycler* recycler = this->GetRecycler();
  946. StaticType* staticString = StaticType::New(scriptContext, TypeIds_String, stringPrototype, nullptr);
  947. stringCache.Initialize(scriptContext, staticString);
  948. pi = JavascriptNumber::New(Math::PI, scriptContext);
  949. nan = JavascriptNumber::New(JavascriptNumber::NaN, scriptContext);
  950. negativeInfinite = JavascriptNumber::New(JavascriptNumber::NEGATIVE_INFINITY, scriptContext);
  951. positiveInfinite = JavascriptNumber::New(JavascriptNumber::POSITIVE_INFINITY, scriptContext);
  952. minValue = JavascriptNumber::New(JavascriptNumber::MIN_VALUE, scriptContext);
  953. maxValue = JavascriptNumber::New(JavascriptNumber::MAX_VALUE, scriptContext);
  954. negativeZero = JavascriptNumber::New(JavascriptNumber::NEG_ZERO, scriptContext);
  955. Type* type = StaticType::New(scriptContext, TypeIds_Undefined, nullValue, nullptr);
  956. undefinedValue = RecyclerNew(recycler, RecyclableObject, type);
  957. DynamicType* dynamicType = DynamicType::New(scriptContext, TypeIds_Object, nullValue, nullptr, &MissingPropertyHolderTypeHandler);
  958. missingPropertyHolder = RecyclerNewPlus(recycler, sizeof(Var), DynamicObject, dynamicType);
  959. MissingPropertyTypeHandler::SetUndefinedPropertySlot(missingPropertyHolder);
  960. emptyString = CreateEmptyString(); // Must be created before other calls to CreateString
  961. nullString = CreateEmptyString(); // Must be distinct from emptyString (for the DOM)
  962. promiseResolveFunction = nullptr;
  963. promiseThenFunction = nullptr;
  964. generatorNextFunction = nullptr;
  965. generatorThrowFunction = nullptr;
  966. jsonStringifyFunction = nullptr;
  967. objectFreezeFunction = nullptr;
  968. symbolHasInstance = CreateSymbol(BuiltInPropertyRecords::_symbolHasInstance);
  969. symbolIsConcatSpreadable = CreateSymbol(BuiltInPropertyRecords::_symbolIsConcatSpreadable);
  970. symbolIterator = CreateSymbol(BuiltInPropertyRecords::_symbolIterator);
  971. symbolSpecies = CreateSymbol(BuiltInPropertyRecords::_symbolSpecies);
  972. symbolToPrimitive = CreateSymbol(BuiltInPropertyRecords::_symbolToPrimitive);
  973. symbolToStringTag = CreateSymbol(BuiltInPropertyRecords::_symbolToStringTag);
  974. symbolUnscopables = CreateSymbol(BuiltInPropertyRecords::_symbolUnscopables);
  975. if (scriptContext->GetConfig()->IsES6RegExSymbolsEnabled())
  976. {
  977. symbolMatch = CreateSymbol(BuiltInPropertyRecords::_symbolMatch);
  978. symbolReplace = CreateSymbol(BuiltInPropertyRecords::_symbolReplace);
  979. symbolSearch = CreateSymbol(BuiltInPropertyRecords::_symbolSearch);
  980. symbolSplit = CreateSymbol(BuiltInPropertyRecords::_symbolSplit);
  981. }
  982. else
  983. {
  984. symbolMatch = nullptr;
  985. symbolReplace = nullptr;
  986. symbolSearch = nullptr;
  987. symbolSplit = nullptr;
  988. }
  989. debuggerDeadZoneBlockVariableString = CreateStringFromCppLiteral(_u("[Uninitialized block variable]"));
  990. defaultAccessorFunction = CreateNonProfiledFunction(&JavascriptOperators::EntryInfo::DefaultAccessor);
  991. if (scriptContext->GetConfig()->IsErrorStackTraceEnabled())
  992. {
  993. stackTraceAccessorFunction = CreateNonProfiledFunction(&JavascriptExceptionOperators::EntryInfo::StackTraceAccessor);
  994. stackTraceAccessorFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable, nullptr);
  995. }
  996. throwTypeErrorRestrictedPropertyAccessorFunction = CreateNonProfiledFunction(&JavascriptExceptionOperators::EntryInfo::ThrowTypeErrorRestrictedPropertyAccessor);
  997. throwTypeErrorRestrictedPropertyAccessorFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable, nullptr);
  998. __proto__getterFunction = CreateNonProfiledFunction(&ObjectPrototypeObject::EntryInfo::__proto__getter);
  999. __proto__getterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable, nullptr);
  1000. __proto__setterFunction = CreateNonProfiledFunction(&ObjectPrototypeObject::EntryInfo::__proto__setter);
  1001. __proto__setterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
  1002. if (scriptContext->GetConfig()->IsES6PromiseEnabled())
  1003. {
  1004. identityFunction = CreateNonProfiledFunction(&JavascriptPromise::EntryInfo::Identity);
  1005. identityFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
  1006. throwerFunction = CreateNonProfiledFunction(&JavascriptPromise::EntryInfo::Thrower);
  1007. throwerFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
  1008. }
  1009. booleanTrue = RecyclerNew(recycler, JavascriptBoolean, true, booleanTypeStatic);
  1010. booleanFalse = RecyclerNew(recycler, JavascriptBoolean, false, booleanTypeStatic);
  1011. isPRNGSeeded = false;
  1012. randSeed0 = 0;
  1013. randSeed1 = 0;
  1014. AddMember(globalObject, PropertyIds::NaN, nan, PropertyNone);
  1015. AddMember(globalObject, PropertyIds::Infinity, positiveInfinite, PropertyNone);
  1016. AddMember(globalObject, PropertyIds::undefined, undefinedValue, PropertyNone);
  1017. // Note: Any global function added/removed/changed here should also be updated in JavascriptLibrary::ProfilerRegisterBuiltinFunctions
  1018. // so that the new functions show up in the profiler too.
  1019. Field(JavascriptFunction*)* builtinFuncs = this->GetBuiltinFunctions();
  1020. evalFunctionObject = AddFunctionToLibraryObject(globalObject, PropertyIds::eval, &GlobalObject::EntryInfo::Eval, 1);
  1021. parseIntFunctionObject = AddFunctionToLibraryObject(globalObject, PropertyIds::parseInt, &GlobalObject::EntryInfo::ParseInt, 2);
  1022. builtinFuncs[BuiltinFunction::GlobalObject_ParseInt] = parseIntFunctionObject;
  1023. parseFloatFunctionObject = AddFunctionToLibraryObject(globalObject, PropertyIds::parseFloat, &GlobalObject::EntryInfo::ParseFloat, 1);
  1024. AddFunctionToLibraryObject(globalObject, PropertyIds::isNaN, &GlobalObject::EntryInfo::IsNaN, 1);
  1025. AddFunctionToLibraryObject(globalObject, PropertyIds::isFinite, &GlobalObject::EntryInfo::IsFinite, 1);
  1026. AddFunctionToLibraryObject(globalObject, PropertyIds::decodeURI, &GlobalObject::EntryInfo::DecodeURI, 1);
  1027. AddFunctionToLibraryObject(globalObject, PropertyIds::decodeURIComponent, &GlobalObject::EntryInfo::DecodeURIComponent, 1);
  1028. AddFunctionToLibraryObject(globalObject, PropertyIds::encodeURI, &GlobalObject::EntryInfo::EncodeURI, 1);
  1029. AddFunctionToLibraryObject(globalObject, PropertyIds::encodeURIComponent, &GlobalObject::EntryInfo::EncodeURIComponent, 1);
  1030. AddFunctionToLibraryObject(globalObject, PropertyIds::escape, &GlobalObject::EntryInfo::Escape, 1);
  1031. AddFunctionToLibraryObject(globalObject, PropertyIds::unescape, &GlobalObject::EntryInfo::UnEscape, 1);
  1032. if (scriptContext->GetConfig()->SupportsCollectGarbage()
  1033. #ifdef ENABLE_PROJECTION
  1034. || scriptContext->GetConfig()->GetHostType() == HostType::HostTypeApplication
  1035. || scriptContext->GetConfig()->GetHostType() == HostType::HostTypeWebview
  1036. #endif
  1037. )
  1038. {
  1039. AddFunctionToLibraryObject(globalObject, PropertyIds::CollectGarbage, &GlobalObject::EntryInfo::CollectGarbage, 0);
  1040. }
  1041. #if ENABLE_TTD
  1042. if(scriptContext->GetThreadContext()->IsRuntimeInTTDMode())
  1043. {
  1044. //
  1045. //TODO: when we formalize our telemetry library in JS land we will want to move these to a seperate Debug or Telemetry object instead of cluttering the global object
  1046. //
  1047. AddFunctionToLibraryObjectWithPropertyName(globalObject, _u("telemetryLog"), &GlobalObject::EntryInfo::TelemetryLog, 3);
  1048. AddFunctionToLibraryObjectWithPropertyName(globalObject, _u("enabledDiagnosticsTrace"), &GlobalObject::EntryInfo::EnabledDiagnosticsTrace, 1);
  1049. AddFunctionToLibraryObjectWithPropertyName(globalObject, _u("emitTTDLog"), &GlobalObject::EntryInfo::EmitTTDLog, 2);
  1050. }
  1051. #endif
  1052. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  1053. AddFunctionToLibraryObjectWithPropertyName(globalObject, _u("chWriteTraceEvent"), &GlobalObject::EntryInfo::ChWriteTraceEvent, 1);
  1054. #endif
  1055. #ifdef IR_VIEWER
  1056. if (Js::Configuration::Global.flags.IsEnabled(Js::IRViewerFlag))
  1057. {
  1058. AddFunctionToLibraryObjectWithPropertyName(globalObject, _u("parseIR"), &GlobalObject::EntryInfo::ParseIR, 1);
  1059. AddFunctionToLibraryObjectWithPropertyName(globalObject, _u("functionList"), &GlobalObject::EntryInfo::FunctionList, 1);
  1060. AddFunctionToLibraryObjectWithPropertyName(globalObject, _u("rejitFunction"), &GlobalObject::EntryInfo::RejitFunction, 2);
  1061. }
  1062. #endif /* IR_VIEWER */
  1063. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  1064. builtInConstructorCache = RecyclerNew(this->GetRecycler(), ConstructorCache);
  1065. builtInConstructorCache->PopulateForSkipDefaultNewObject(this->GetScriptContext());
  1066. objectConstructor = CreateBuiltinConstructor(&JavascriptObject::EntryInfo::NewInstance,
  1067. DeferredTypeHandler<InitializeObjectConstructor>::GetDefaultInstance());
  1068. AddFunction(globalObject, PropertyIds::Object, objectConstructor);
  1069. arrayConstructor = CreateBuiltinConstructor(&JavascriptArray::EntryInfo::NewInstance,
  1070. DeferredTypeHandler<InitializeArrayConstructor>::GetDefaultInstance());
  1071. SetArrayObjectHasUserDefinedSpecies(false);
  1072. AddFunction(globalObject, PropertyIds::Array, arrayConstructor);
  1073. booleanConstructor = CreateBuiltinConstructor(&JavascriptBoolean::EntryInfo::NewInstance,
  1074. DeferredTypeHandler<InitializeBooleanConstructor>::GetDefaultInstance());
  1075. AddFunction(globalObject, PropertyIds::Boolean, booleanConstructor);
  1076. symbolConstructor = nullptr;
  1077. proxyConstructor = nullptr;
  1078. promiseConstructor = nullptr;
  1079. reflectObject = nullptr;
  1080. debugEval = nullptr;
  1081. getStackTrace = nullptr;
  1082. #ifdef EDIT_AND_CONTINUE
  1083. editSource = nullptr;
  1084. #endif
  1085. symbolConstructor = CreateBuiltinConstructor(&JavascriptSymbol::EntryInfo::NewInstance,
  1086. DeferredTypeHandler<InitializeSymbolConstructor>::GetDefaultInstance());
  1087. AddFunction(globalObject, PropertyIds::Symbol, symbolConstructor);
  1088. if (scriptContext->GetConfig()->IsES6ProxyEnabled())
  1089. {
  1090. proxyConstructor = CreateBuiltinConstructor(&JavascriptProxy::EntryInfo::NewInstance,
  1091. DeferredTypeHandler<InitializeProxyConstructor>::GetDefaultInstance());
  1092. AddFunction(globalObject, PropertyIds::Proxy, proxyConstructor);
  1093. reflectObject = DynamicObject::New(recycler,
  1094. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1095. DeferredTypeHandler<InitializeReflectObject>::GetDefaultInstance()));
  1096. AddMember(globalObject, PropertyIds::Reflect, reflectObject);
  1097. }
  1098. if (scriptContext->GetConfig()->IsES6PromiseEnabled())
  1099. {
  1100. promiseConstructor = CreateBuiltinConstructor(&JavascriptPromise::EntryInfo::NewInstance,
  1101. DeferredTypeHandler<InitializePromiseConstructor>::GetDefaultInstance());
  1102. AddFunction(globalObject, PropertyIds::Promise, promiseConstructor);
  1103. }
  1104. dateConstructor = CreateBuiltinConstructor(&JavascriptDate::EntryInfo::NewInstance,
  1105. DeferredTypeHandler<InitializeDateConstructor>::GetDefaultInstance());
  1106. AddFunction(globalObject, PropertyIds::Date, dateConstructor);
  1107. functionConstructor = CreateBuiltinConstructor(&JavascriptFunction::EntryInfo::NewInstance,
  1108. DeferredTypeHandler<InitializeFunctionConstructor, DefaultDeferredTypeFilter, true>::GetDefaultInstance());
  1109. AddFunction(globalObject, PropertyIds::Function, functionConstructor);
  1110. mathObject = DynamicObject::New(recycler,
  1111. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1112. DeferredTypeHandler<InitializeMathObject>::GetDefaultInstance()));
  1113. AddMember(globalObject, PropertyIds::Math, mathObject);
  1114. // SIMD_JS
  1115. // we declare global objects and lib functions only if SSE2 is available. Else, we use the polyfill.
  1116. #ifdef ENABLE_SIMDJS
  1117. if (GetScriptContext()->GetConfig()->IsSimdjsEnabled())
  1118. {
  1119. simdObject = DynamicObject::New(recycler,
  1120. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1121. DeferredTypeHandler<InitializeSIMDObject>::GetDefaultInstance()));
  1122. AddMember(globalObject, PropertyIds::SIMD, simdObject);
  1123. }
  1124. #endif
  1125. debugObject = nullptr;
  1126. numberConstructor = CreateBuiltinConstructor(&JavascriptNumber::EntryInfo::NewInstance,
  1127. DeferredTypeHandler<InitializeNumberConstructor>::GetDefaultInstance());
  1128. AddFunction(globalObject, PropertyIds::Number, numberConstructor);
  1129. stringConstructor = CreateBuiltinConstructor(&JavascriptString::EntryInfo::NewInstance,
  1130. DeferredTypeHandler<InitializeStringConstructor>::GetDefaultInstance());
  1131. AddFunction(globalObject, PropertyIds::String, stringConstructor);
  1132. regexConstructorType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, JavascriptRegExp::NewInstance,
  1133. DeferredTypeHandler<InitializeRegexConstructor>::GetDefaultInstance());
  1134. regexConstructor = RecyclerNewEnumClass(recycler, EnumFunctionClass, JavascriptRegExpConstructor, regexConstructorType);
  1135. AddFunction(globalObject, PropertyIds::RegExp, regexConstructor);
  1136. arrayBufferConstructor = CreateBuiltinConstructor(&ArrayBuffer::EntryInfo::NewInstance,
  1137. DeferredTypeHandler<InitializeArrayBufferConstructor>::GetDefaultInstance());
  1138. AddFunction(globalObject, PropertyIds::ArrayBuffer, arrayBufferConstructor);
  1139. dataViewConstructor = CreateBuiltinConstructor(&DataView::EntryInfo::NewInstance,
  1140. DeferredTypeHandler<InitializeDataViewConstructor>::GetDefaultInstance());
  1141. AddFunction(globalObject, PropertyIds::DataView, dataViewConstructor);
  1142. typedArrayConstructor = CreateBuiltinConstructor(&TypedArrayBase::EntryInfo::NewInstance,
  1143. DeferredTypeHandler<InitializeTypedArrayConstructor, DefaultDeferredTypeFilter, true>::GetDefaultInstance(),
  1144. functionPrototype);
  1145. Int8ArrayConstructor = CreateBuiltinConstructor(&Int8Array::EntryInfo::NewInstance,
  1146. DeferredTypeHandler<InitializeInt8ArrayConstructor>::GetDefaultInstance(),
  1147. typedArrayConstructor);
  1148. AddFunction(globalObject, PropertyIds::Int8Array, Int8ArrayConstructor);
  1149. Uint8ArrayConstructor = CreateBuiltinConstructor(&Uint8Array::EntryInfo::NewInstance,
  1150. DeferredTypeHandler<InitializeUint8ArrayConstructor>::GetDefaultInstance(),
  1151. typedArrayConstructor);
  1152. AddFunction(globalObject, PropertyIds::Uint8Array, Uint8ArrayConstructor);
  1153. Uint8ClampedArrayConstructor = CreateBuiltinConstructor(&Uint8ClampedArray::EntryInfo::NewInstance,
  1154. DeferredTypeHandler<InitializeUint8ClampedArrayConstructor>::GetDefaultInstance(),
  1155. typedArrayConstructor);
  1156. AddFunction(globalObject, PropertyIds::Uint8ClampedArray, Uint8ClampedArrayConstructor);
  1157. Int16ArrayConstructor = CreateBuiltinConstructor(&Int16Array::EntryInfo::NewInstance,
  1158. DeferredTypeHandler<InitializeInt16ArrayConstructor>::GetDefaultInstance(),
  1159. typedArrayConstructor);
  1160. AddFunction(globalObject, PropertyIds::Int16Array, Int16ArrayConstructor);
  1161. Uint16ArrayConstructor = CreateBuiltinConstructor(&Uint16Array::EntryInfo::NewInstance,
  1162. DeferredTypeHandler<InitializeUint16ArrayConstructor>::GetDefaultInstance(),
  1163. typedArrayConstructor);
  1164. AddFunction(globalObject, PropertyIds::Uint16Array, Uint16ArrayConstructor);
  1165. Int32ArrayConstructor = CreateBuiltinConstructor(&Int32Array::EntryInfo::NewInstance,
  1166. DeferredTypeHandler<InitializeInt32ArrayConstructor>::GetDefaultInstance(),
  1167. typedArrayConstructor);
  1168. AddFunction(globalObject, PropertyIds::Int32Array, Int32ArrayConstructor);
  1169. Uint32ArrayConstructor = CreateBuiltinConstructor(&Uint32Array::EntryInfo::NewInstance,
  1170. DeferredTypeHandler<InitializeUint32ArrayConstructor>::GetDefaultInstance(),
  1171. typedArrayConstructor);
  1172. AddFunction(globalObject, PropertyIds::Uint32Array, Uint32ArrayConstructor);
  1173. Float32ArrayConstructor = CreateBuiltinConstructor(&Float32Array::EntryInfo::NewInstance,
  1174. DeferredTypeHandler<InitializeFloat32ArrayConstructor>::GetDefaultInstance(),
  1175. typedArrayConstructor);
  1176. AddFunction(globalObject, PropertyIds::Float32Array, Float32ArrayConstructor);
  1177. Float64ArrayConstructor = CreateBuiltinConstructor(&Float64Array::EntryInfo::NewInstance,
  1178. DeferredTypeHandler<InitializeFloat64ArrayConstructor>::GetDefaultInstance(),
  1179. typedArrayConstructor);
  1180. AddFunction(globalObject, PropertyIds::Float64Array, Float64ArrayConstructor);
  1181. if (scriptContext->GetConfig()->IsESSharedArrayBufferEnabled())
  1182. {
  1183. sharedArrayBufferConstructor = CreateBuiltinConstructor(&SharedArrayBuffer::EntryInfo::NewInstance,
  1184. DeferredTypeHandler<InitializeSharedArrayBufferConstructor>::GetDefaultInstance());
  1185. AddFunction(globalObject, PropertyIds::SharedArrayBuffer, sharedArrayBufferConstructor);
  1186. atomicsObject = DynamicObject::New(recycler,
  1187. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1188. DeferredTypeHandler<InitializeAtomicsObject>::GetDefaultInstance()));
  1189. AddMember(globalObject, PropertyIds::Atomics, atomicsObject);
  1190. }
  1191. else
  1192. {
  1193. sharedArrayBufferConstructor = nullptr;
  1194. atomicsObject = nullptr;
  1195. }
  1196. JSONObject = DynamicObject::New(recycler,
  1197. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1198. DeferredTypeHandler<InitializeJSONObject>::GetDefaultInstance()));
  1199. AddMember(globalObject, PropertyIds::JSON, JSONObject);
  1200. #ifdef ENABLE_INTL_OBJECT
  1201. if (scriptContext->IsIntlEnabled())
  1202. {
  1203. IntlObject = DynamicObject::New(recycler,
  1204. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1205. DeferredTypeHandler<InitializeIntlObject>::GetDefaultInstance()));
  1206. AddMember(globalObject, PropertyIds::Intl, IntlObject);
  1207. }
  1208. else
  1209. {
  1210. IntlObject = nullptr;
  1211. }
  1212. #endif
  1213. #if defined(ENABLE_INTL_OBJECT) || defined(ENABLE_JS_BUILTINS) || defined(ENABLE_PROJECTION)
  1214. engineInterfaceObject = EngineInterfaceObject::New(recycler,
  1215. DynamicType::New(scriptContext, TypeIds_EngineInterfaceObject, objectPrototype, nullptr,
  1216. DeferredTypeHandler<InitializeEngineInterfaceObject>::GetDefaultInstance()));
  1217. #ifdef ENABLE_INTL_OBJECT
  1218. IntlEngineInterfaceExtensionObject* intlExtension = RecyclerNew(recycler, IntlEngineInterfaceExtensionObject, scriptContext);
  1219. engineInterfaceObject->SetEngineExtension(EngineInterfaceExtensionKind_Intl, intlExtension);
  1220. #endif
  1221. #ifdef ENABLE_JS_BUILTINS
  1222. chakraLibraryObject = DynamicObject::New(recycler,
  1223. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1224. DeferredTypeHandler<InitializeChakraLibraryObject>::GetDefaultInstance()));
  1225. if (CONFIG_FLAG(LdChakraLib)) {
  1226. AddMember(globalObject, PropertyIds::__chakraLibrary, chakraLibraryObject);
  1227. }
  1228. JsBuiltInEngineInterfaceExtensionObject* builtInExtension = RecyclerNew(recycler, JsBuiltInEngineInterfaceExtensionObject, scriptContext);
  1229. engineInterfaceObject->SetEngineExtension(EngineInterfaceExtensionKind_JsBuiltIn, builtInExtension);
  1230. this->isArrayFunction = this->DefaultCreateFunction(&JavascriptArray::EntryInfo::IsArray, 1, nullptr, nullptr, PropertyIds::isArray);
  1231. #endif
  1232. #endif
  1233. mapConstructor = CreateBuiltinConstructor(&JavascriptMap::EntryInfo::NewInstance,
  1234. DeferredTypeHandler<InitializeMapConstructor>::GetDefaultInstance());
  1235. AddFunction(globalObject, PropertyIds::Map, mapConstructor);
  1236. setConstructor = CreateBuiltinConstructor(&JavascriptSet::EntryInfo::NewInstance,
  1237. DeferredTypeHandler<InitializeSetConstructor>::GetDefaultInstance());
  1238. AddFunction(globalObject, PropertyIds::Set, setConstructor);
  1239. weakMapConstructor = CreateBuiltinConstructor(&JavascriptWeakMap::EntryInfo::NewInstance,
  1240. DeferredTypeHandler<InitializeWeakMapConstructor>::GetDefaultInstance());
  1241. AddFunction(globalObject, PropertyIds::WeakMap, weakMapConstructor);
  1242. weakSetConstructor = CreateBuiltinConstructor(&JavascriptWeakSet::EntryInfo::NewInstance,
  1243. DeferredTypeHandler<InitializeWeakSetConstructor>::GetDefaultInstance());
  1244. AddFunction(globalObject, PropertyIds::WeakSet, weakSetConstructor);
  1245. generatorFunctionConstructor = nullptr;
  1246. if (scriptContext->GetConfig()->IsES6GeneratorsEnabled())
  1247. {
  1248. generatorFunctionConstructor = CreateBuiltinConstructor(&JavascriptGeneratorFunction::EntryInfo::NewInstance,
  1249. DeferredTypeHandler<InitializeGeneratorFunctionConstructor>::GetDefaultInstance(),
  1250. functionConstructor);
  1251. // GeneratorFunction is not a global property by ES6 spec so don't add it to the global object
  1252. }
  1253. asyncFunctionConstructor = nullptr;
  1254. if (scriptContext->GetConfig()->IsES7AsyncAndAwaitEnabled())
  1255. {
  1256. asyncFunctionConstructor = CreateBuiltinConstructor(&JavascriptFunction::EntryInfo::NewAsyncFunctionInstance,
  1257. DeferredTypeHandler<InitializeAsyncFunctionConstructor>::GetDefaultInstance(),
  1258. functionConstructor);
  1259. // AsyncFunction is not a global property by ES7 spec so don't add it to the global object
  1260. }
  1261. errorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewErrorInstance,
  1262. DeferredTypeHandler<InitializeErrorConstructor>::GetDefaultInstance());
  1263. AddFunction(globalObject, PropertyIds::Error, errorConstructor);
  1264. RuntimeFunction* nativeErrorPrototype = nullptr;
  1265. if (scriptContext->GetConfig()->IsES6PrototypeChain())
  1266. {
  1267. nativeErrorPrototype = errorConstructor;
  1268. }
  1269. evalErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewEvalErrorInstance,
  1270. DeferredTypeHandler<InitializeEvalErrorConstructor>::GetDefaultInstance(),
  1271. nativeErrorPrototype);
  1272. AddFunction(globalObject, PropertyIds::EvalError, evalErrorConstructor);
  1273. rangeErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewRangeErrorInstance,
  1274. DeferredTypeHandler<InitializeRangeErrorConstructor>::GetDefaultInstance(),
  1275. nativeErrorPrototype);
  1276. AddFunction(globalObject, PropertyIds::RangeError, rangeErrorConstructor);
  1277. referenceErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewReferenceErrorInstance,
  1278. DeferredTypeHandler<InitializeReferenceErrorConstructor>::GetDefaultInstance(),
  1279. nativeErrorPrototype);
  1280. AddFunction(globalObject, PropertyIds::ReferenceError, referenceErrorConstructor);
  1281. syntaxErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewSyntaxErrorInstance,
  1282. DeferredTypeHandler<InitializeSyntaxErrorConstructor>::GetDefaultInstance(),
  1283. nativeErrorPrototype);
  1284. AddFunction(globalObject, PropertyIds::SyntaxError, syntaxErrorConstructor);
  1285. typeErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewTypeErrorInstance,
  1286. DeferredTypeHandler<InitializeTypeErrorConstructor>::GetDefaultInstance(),
  1287. nativeErrorPrototype);
  1288. AddFunction(globalObject, PropertyIds::TypeError, typeErrorConstructor);
  1289. uriErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewURIErrorInstance,
  1290. DeferredTypeHandler<InitializeURIErrorConstructor>::GetDefaultInstance(),
  1291. nativeErrorPrototype);
  1292. AddFunction(globalObject, PropertyIds::URIError, uriErrorConstructor);
  1293. #ifdef ENABLE_WASM
  1294. if (CONFIG_FLAG(Wasm) && !PHASE_OFF1(Js::WasmPhase))
  1295. {
  1296. webAssemblyCompileFunction = nullptr;
  1297. // new WebAssembly object
  1298. webAssemblyObject = DynamicObject::New(recycler,
  1299. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1300. DeferredTypeHandler<InitializeWebAssemblyObject>::GetDefaultInstance()));
  1301. AddMember(globalObject, PropertyIds::WebAssembly, webAssemblyObject);
  1302. webAssemblyCompileErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewWebAssemblyCompileErrorInstance,
  1303. DeferredTypeHandler<InitializeWebAssemblyCompileErrorConstructor>::GetDefaultInstance(),
  1304. nativeErrorPrototype);
  1305. webAssemblyRuntimeErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewWebAssemblyRuntimeErrorInstance,
  1306. DeferredTypeHandler<InitializeWebAssemblyRuntimeErrorConstructor>::GetDefaultInstance(),
  1307. nativeErrorPrototype);
  1308. webAssemblyLinkErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewWebAssemblyLinkErrorInstance,
  1309. DeferredTypeHandler<InitializeWebAssemblyLinkErrorConstructor>::GetDefaultInstance(),
  1310. nativeErrorPrototype);
  1311. webAssemblyInstanceConstructor = CreateBuiltinConstructor(&WebAssemblyInstance::EntryInfo::NewInstance,
  1312. DeferredTypeHandler<InitializeWebAssemblyInstanceConstructor>::GetDefaultInstance(), webAssemblyInstancePrototype);
  1313. webAssemblyModuleConstructor = CreateBuiltinConstructor(&WebAssemblyModule::EntryInfo::NewInstance,
  1314. DeferredTypeHandler<InitializeWebAssemblyModuleConstructor>::GetDefaultInstance(), webAssemblyModulePrototype);
  1315. webAssemblyMemoryConstructor = CreateBuiltinConstructor(&WebAssemblyMemory::EntryInfo::NewInstance,
  1316. DeferredTypeHandler<InitializeWebAssemblyMemoryConstructor>::GetDefaultInstance(), webAssemblyMemoryConstructor);
  1317. webAssemblyTableConstructor = CreateBuiltinConstructor(&WebAssemblyTable::EntryInfo::NewInstance,
  1318. DeferredTypeHandler<InitializeWebAssemblyTableConstructor>::GetDefaultInstance(), webAssemblyTableConstructor);
  1319. }
  1320. #endif
  1321. }
  1322. void JavascriptLibrary::EnsureDebugObject(DynamicObject* newDebugObject)
  1323. {
  1324. Assert(!debugObject);
  1325. if (!debugObject)
  1326. {
  1327. this->debugObject = newDebugObject;
  1328. AddMember(globalObject, PropertyIds::Debug, debugObject);
  1329. }
  1330. }
  1331. void JavascriptLibrary::SetDebugObjectNonUserAccessor(FunctionInfo *funcGetter, FunctionInfo *funcSetter)
  1332. {
  1333. Assert(funcGetter);
  1334. Assert(funcSetter);
  1335. debugObjectNonUserGetterFunction = CreateNonProfiledFunction(funcGetter);
  1336. debugObjectNonUserGetterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable, nullptr);
  1337. debugObjectNonUserSetterFunction = CreateNonProfiledFunction(funcSetter);
  1338. debugObjectNonUserSetterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
  1339. }
  1340. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  1341. void JavascriptLibrary::SetDebugObjectFaultInjectionCookieGetterAccessor(FunctionInfo *funcGetter, FunctionInfo *funcSetter)
  1342. {
  1343. Assert(funcGetter);
  1344. Assert(funcSetter);
  1345. debugObjectFaultInjectionCookieGetterFunction = CreateNonProfiledFunction(funcGetter);
  1346. debugObjectFaultInjectionCookieGetterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable, nullptr);
  1347. debugObjectFaultInjectionCookieSetterFunction = CreateNonProfiledFunction(funcSetter);
  1348. debugObjectFaultInjectionCookieSetterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
  1349. }
  1350. #endif
  1351. void JavascriptLibrary::SetDebugObjectDebugModeAccessor(FunctionInfo *funcGetter)
  1352. {
  1353. Assert(funcGetter);
  1354. debugObjectDebugModeGetterFunction = CreateNonProfiledFunction(funcGetter);
  1355. debugObjectDebugModeGetterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable, nullptr);
  1356. }
  1357. bool JavascriptLibrary::InitializeArrayConstructor(DynamicObject* arrayConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1358. {
  1359. typeHandler->Convert(arrayConstructor, mode, 6);
  1360. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterArray
  1361. // so that the update is in sync with profiler
  1362. ScriptContext* scriptContext = arrayConstructor->GetScriptContext();
  1363. JavascriptLibrary* library = arrayConstructor->GetLibrary();
  1364. Field(JavascriptFunction*)* builtinFuncs = library->GetBuiltinFunctions();
  1365. library->AddMember(arrayConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  1366. library->AddMember(arrayConstructor, PropertyIds::prototype, scriptContext->GetLibrary()->arrayPrototype, PropertyNone);
  1367. library->AddSpeciesAccessorsToLibraryObject(arrayConstructor, &JavascriptArray::EntryInfo::GetterSymbolSpecies);
  1368. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1369. {
  1370. library->AddMember(arrayConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Array), PropertyConfigurable);
  1371. }
  1372. #ifdef ENABLE_JS_BUILTINS
  1373. builtinFuncs[BuiltinFunction::JavascriptArray_IsArray] = library->isArrayFunction;
  1374. library->AddMember(arrayConstructor, PropertyIds::isArray, library->isArrayFunction);
  1375. #else
  1376. library->AddFunctionToLibraryObject(arrayConstructor, PropertyIds::isArray, &JavascriptArray::EntryInfo::IsArray, 1);
  1377. #endif
  1378. library->AddFunctionToLibraryObject(arrayConstructor, PropertyIds::from, &JavascriptArray::EntryInfo::From, 1);
  1379. library->AddFunctionToLibraryObject(arrayConstructor, PropertyIds::of, &JavascriptArray::EntryInfo::Of, 0);
  1380. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  1381. arrayConstructor->SetHasNoEnumerableProperties(true);
  1382. return true;
  1383. }
  1384. bool JavascriptLibrary::IsDefaultArrayValuesFunction(RecyclableObject * function, ScriptContext *scriptContext)
  1385. {
  1386. #ifdef ENABLE_JS_BUILTINS
  1387. if (scriptContext->IsJsBuiltInEnabled())
  1388. {
  1389. scriptContext->GetLibrary()->EnsureBuiltInEngineIsReady();
  1390. return JavascriptFunction::Is(function) && JavascriptFunction::FromVar(function)->IsJsBuiltIn();
  1391. }
  1392. #endif
  1393. JavascriptMethod method = function->GetEntryPoint();
  1394. return method == JavascriptArray::EntryInfo::Values.GetOriginalEntryPoint();
  1395. }
  1396. JavascriptFunction* JavascriptLibrary::EnsureArrayPrototypeForEachFunction()
  1397. {
  1398. if (arrayPrototypeForEachFunction == nullptr)
  1399. {
  1400. arrayPrototypeForEachFunction = DefaultCreateFunction(&JavascriptArray::EntryInfo::ForEach, 1, nullptr, nullptr, PropertyIds::forEach);
  1401. }
  1402. return arrayPrototypeForEachFunction;
  1403. }
  1404. JavascriptFunction* JavascriptLibrary::EnsureArrayPrototypeKeysFunction()
  1405. {
  1406. if (arrayPrototypeKeysFunction == nullptr)
  1407. {
  1408. #ifndef ENABLE_JS_BUILTINS
  1409. arrayPrototypeKeysFunction = DefaultCreateFunction(&JavascriptArray::EntryInfo::Keys, 0, nullptr, nullptr, PropertyIds::keys);
  1410. #else
  1411. if (!scriptContext->IsJsBuiltInEnabled())
  1412. {
  1413. arrayPrototypeKeysFunction = DefaultCreateFunction(&JavascriptArray::EntryInfo::Keys, 0, nullptr, nullptr, PropertyIds::keys);
  1414. }
  1415. else
  1416. {
  1417. this->EnsureBuiltInEngineIsReady();
  1418. }
  1419. #endif
  1420. }
  1421. return arrayPrototypeKeysFunction;
  1422. }
  1423. JavascriptFunction* JavascriptLibrary::EnsureArrayPrototypeValuesFunction()
  1424. {
  1425. if (arrayPrototypeValuesFunction == nullptr)
  1426. {
  1427. #ifndef ENABLE_JS_BUILTINS
  1428. arrayPrototypeValuesFunction = DefaultCreateFunction(&JavascriptArray::EntryInfo::Values, 0, nullptr, nullptr, PropertyIds::values);
  1429. #else
  1430. if (!scriptContext->IsJsBuiltInEnabled())
  1431. {
  1432. arrayPrototypeValuesFunction = DefaultCreateFunction(&JavascriptArray::EntryInfo::Values, 0, nullptr, nullptr, PropertyIds::values);
  1433. }
  1434. else
  1435. {
  1436. this->EnsureBuiltInEngineIsReady();
  1437. }
  1438. #endif
  1439. }
  1440. return arrayPrototypeValuesFunction;
  1441. }
  1442. JavascriptFunction* JavascriptLibrary::EnsureArrayPrototypeEntriesFunction()
  1443. {
  1444. if (arrayPrototypeEntriesFunction == nullptr)
  1445. {
  1446. #ifndef ENABLE_JS_BUILTINS
  1447. arrayPrototypeEntriesFunction = DefaultCreateFunction(&JavascriptArray::EntryInfo::Entries, 0, nullptr, nullptr, PropertyIds::entries);
  1448. #else
  1449. if (!scriptContext->IsJsBuiltInEnabled())
  1450. {
  1451. arrayPrototypeEntriesFunction = DefaultCreateFunction(&JavascriptArray::EntryInfo::Entries, 0, nullptr, nullptr, PropertyIds::entries);
  1452. }
  1453. else
  1454. {
  1455. this->EnsureBuiltInEngineIsReady();
  1456. }
  1457. #endif
  1458. }
  1459. return arrayPrototypeEntriesFunction;
  1460. }
  1461. bool JavascriptLibrary::InitializeArrayPrototype(DynamicObject* arrayPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1462. {
  1463. typeHandler->Convert(arrayPrototype, mode, 24);
  1464. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterArray
  1465. // so that the update is in sync with profiler
  1466. ScriptContext* scriptContext = arrayPrototype->GetScriptContext();
  1467. JavascriptLibrary* library = arrayPrototype->GetLibrary();
  1468. library->AddMember(arrayPrototype, PropertyIds::constructor, library->arrayConstructor);
  1469. Field(JavascriptFunction*)* builtinFuncs = library->GetBuiltinFunctions();
  1470. builtinFuncs[BuiltinFunction::JavascriptArray_Push] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::push, &JavascriptArray::EntryInfo::Push, 1);
  1471. builtinFuncs[BuiltinFunction::JavascriptArray_Concat] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::concat, &JavascriptArray::EntryInfo::Concat, 1);
  1472. builtinFuncs[BuiltinFunction::JavascriptArray_Join] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::join, &JavascriptArray::EntryInfo::Join, 1);
  1473. builtinFuncs[BuiltinFunction::JavascriptArray_Pop] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::pop, &JavascriptArray::EntryInfo::Pop, 0);
  1474. builtinFuncs[BuiltinFunction::JavascriptArray_Reverse] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reverse, &JavascriptArray::EntryInfo::Reverse, 0);
  1475. builtinFuncs[BuiltinFunction::JavascriptArray_Shift] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::shift, &JavascriptArray::EntryInfo::Shift, 0);
  1476. builtinFuncs[BuiltinFunction::JavascriptArray_Slice] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::slice, &JavascriptArray::EntryInfo::Slice, 2);
  1477. /* No inlining Array_Sort */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::sort, &JavascriptArray::EntryInfo::Sort, 1);
  1478. builtinFuncs[BuiltinFunction::JavascriptArray_Splice] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::splice, &JavascriptArray::EntryInfo::Splice, 2);
  1479. // The toString and toLocaleString properties are shared between Array.prototype and %TypedArray%.prototype.
  1480. // Whichever prototype is initialized first will create the functions, the other should just load the existing function objects.
  1481. if (library->arrayPrototypeToStringFunction == nullptr)
  1482. {
  1483. Assert(library->arrayPrototypeToLocaleStringFunction == nullptr);
  1484. library->arrayPrototypeToLocaleStringFunction = /* No inlining Array_ToLocaleString */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::toLocaleString, &JavascriptArray::EntryInfo::ToLocaleString, 0);
  1485. library->arrayPrototypeToStringFunction = /* No inlining Array_ToString */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::toString, &JavascriptArray::EntryInfo::ToString, 0);
  1486. }
  1487. else
  1488. {
  1489. Assert(library->arrayPrototypeToLocaleStringFunction);
  1490. library->AddMember(arrayPrototype, PropertyIds::toLocaleString, library->arrayPrototypeToLocaleStringFunction);
  1491. library->AddMember(arrayPrototype, PropertyIds::toString, library->arrayPrototypeToStringFunction);
  1492. }
  1493. builtinFuncs[BuiltinFunction::JavascriptArray_Unshift] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::unshift, &JavascriptArray::EntryInfo::Unshift, 1);
  1494. builtinFuncs[BuiltinFunction::JavascriptArray_IndexOf] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::indexOf, &JavascriptArray::EntryInfo::IndexOf, 1);
  1495. /* No inlining Array_Every */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::every, &JavascriptArray::EntryInfo::Every, 1);
  1496. /* No inlining Array_Filter */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::filter, &JavascriptArray::EntryInfo::Filter, 1);
  1497. /* No inlining Array_ForEach */
  1498. library->AddMember(arrayPrototype, PropertyIds::forEach, library->EnsureArrayPrototypeForEachFunction());
  1499. builtinFuncs[BuiltinFunction::JavascriptArray_LastIndexOf] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::lastIndexOf, &JavascriptArray::EntryInfo::LastIndexOf, 1);
  1500. /* No inlining Array_Map */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::map, &JavascriptArray::EntryInfo::Map, 1);
  1501. /* No inlining Array_Reduce */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reduce, &JavascriptArray::EntryInfo::Reduce, 1);
  1502. /* No inlining Array_ReduceRight */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reduceRight, &JavascriptArray::EntryInfo::ReduceRight, 1);
  1503. /* No inlining Array_Some */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::some, &JavascriptArray::EntryInfo::Some, 1);
  1504. if (scriptContext->GetConfig()->IsES6StringExtensionsEnabled()) // This is not a typo, Array.prototype.find and .findIndex are part of the ES6 Improved String APIs feature
  1505. {
  1506. /* No inlining Array_Find */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::find, &JavascriptArray::EntryInfo::Find, 1);
  1507. /* No inlining Array_FindIndex */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::findIndex, &JavascriptArray::EntryInfo::FindIndex, 1);
  1508. }
  1509. #ifndef ENABLE_JS_BUILTINS
  1510. /* No inlining Array_Entries */
  1511. library->AddMember(arrayPrototype, PropertyIds::entries, library->EnsureArrayPrototypeEntriesFunction());
  1512. /* No inlining Array_Keys */
  1513. library->AddMember(arrayPrototype, PropertyIds::keys, library->EnsureArrayPrototypeKeysFunction());
  1514. JavascriptFunction *values = library->EnsureArrayPrototypeValuesFunction();
  1515. /* No inlining Array_Values */ library->AddMember(arrayPrototype, PropertyIds::values, values);
  1516. /* No inlining Array_SymbolIterator */ library->AddMember(arrayPrototype, PropertyIds::_symbolIterator, values);
  1517. #else
  1518. if (!scriptContext->IsJsBuiltInEnabled())
  1519. {
  1520. /* No inlining Array_Entries */
  1521. library->AddMember(arrayPrototype, PropertyIds::entries, library->EnsureArrayPrototypeEntriesFunction());
  1522. /* No inlining Array_Keys */
  1523. library->AddMember(arrayPrototype, PropertyIds::keys, library->EnsureArrayPrototypeKeysFunction());
  1524. JavascriptFunction *values = library->EnsureArrayPrototypeValuesFunction();
  1525. /* No inlining Array_Values */ library->AddMember(arrayPrototype, PropertyIds::values, values);
  1526. /* No inlining Array_SymbolIterator */ library->AddMember(arrayPrototype, PropertyIds::_symbolIterator, values);
  1527. }
  1528. else
  1529. {
  1530. library->EnsureBuiltInEngineIsReady();
  1531. }
  1532. #endif
  1533. if (scriptContext->GetConfig()->IsES6UnscopablesEnabled())
  1534. {
  1535. DynamicType* dynamicType = DynamicType::New(scriptContext, TypeIds_Object, library->nullValue, nullptr, NullTypeHandler<false>::GetDefaultInstance(), false);
  1536. DynamicObject* unscopablesList = DynamicObject::New(library->GetRecycler(), dynamicType);
  1537. unscopablesList->SetProperty(PropertyIds::find, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1538. unscopablesList->SetProperty(PropertyIds::findIndex, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1539. unscopablesList->SetProperty(PropertyIds::fill, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1540. unscopablesList->SetProperty(PropertyIds::copyWithin, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1541. unscopablesList->SetProperty(PropertyIds::entries, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1542. unscopablesList->SetProperty(PropertyIds::includes, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1543. unscopablesList->SetProperty(PropertyIds::keys, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1544. unscopablesList->SetProperty(PropertyIds::values, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1545. library->AddMember(arrayPrototype, PropertyIds::_symbolUnscopables, unscopablesList, PropertyConfigurable);
  1546. }
  1547. /* No inlining Array_Fill */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::fill, &JavascriptArray::EntryInfo::Fill, 1);
  1548. /* No inlining Array_CopyWithin */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::copyWithin, &JavascriptArray::EntryInfo::CopyWithin, 2);
  1549. builtinFuncs[BuiltinFunction::JavascriptArray_Includes] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::includes, &JavascriptArray::EntryInfo::Includes, 1);
  1550. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  1551. arrayPrototype->SetHasNoEnumerableProperties(true);
  1552. return true;
  1553. }
  1554. bool JavascriptLibrary::InitializeSharedArrayBufferConstructor(DynamicObject* sharedArrayBufferConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1555. {
  1556. typeHandler->Convert(sharedArrayBufferConstructor, mode, 4);
  1557. ScriptContext* scriptContext = sharedArrayBufferConstructor->GetScriptContext();
  1558. JavascriptLibrary* library = sharedArrayBufferConstructor->GetLibrary();
  1559. library->AddMember(sharedArrayBufferConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  1560. library->AddMember(sharedArrayBufferConstructor, PropertyIds::prototype, scriptContext->GetLibrary()->sharedArrayBufferPrototype, PropertyNone);
  1561. library->AddSpeciesAccessorsToLibraryObject(sharedArrayBufferConstructor, &SharedArrayBuffer::EntryInfo::GetterSymbolSpecies);
  1562. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1563. {
  1564. library->AddMember(sharedArrayBufferConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::SharedArrayBuffer), PropertyConfigurable);
  1565. }
  1566. sharedArrayBufferConstructor->SetHasNoEnumerableProperties(true);
  1567. return true;
  1568. }
  1569. bool JavascriptLibrary::InitializeSharedArrayBufferPrototype(DynamicObject* sharedArrayBufferPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1570. {
  1571. typeHandler->Convert(sharedArrayBufferPrototype, mode, 4);
  1572. ScriptContext* scriptContext = sharedArrayBufferPrototype->GetScriptContext();
  1573. JavascriptLibrary* library = sharedArrayBufferPrototype->GetLibrary();
  1574. library->AddMember(sharedArrayBufferPrototype, PropertyIds::constructor, library->sharedArrayBufferConstructor);
  1575. library->AddFunctionToLibraryObject(sharedArrayBufferPrototype, PropertyIds::slice, &SharedArrayBuffer::EntryInfo::Slice, 2);
  1576. library->AddAccessorsToLibraryObject(sharedArrayBufferPrototype, PropertyIds::byteLength, &SharedArrayBuffer::EntryInfo::GetterByteLength, nullptr);
  1577. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1578. {
  1579. library->AddMember(sharedArrayBufferPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("SharedArrayBuffer")), PropertyConfigurable);
  1580. }
  1581. sharedArrayBufferPrototype->SetHasNoEnumerableProperties(true);
  1582. return true;
  1583. }
  1584. bool JavascriptLibrary::InitializeAtomicsObject(DynamicObject* atomicsObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1585. {
  1586. typeHandler->Convert(atomicsObject, mode, 12);
  1587. JavascriptLibrary* library = atomicsObject->GetLibrary();
  1588. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::add, &AtomicsObject::EntryInfo::Add, 3);
  1589. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::and_, &AtomicsObject::EntryInfo::And, 3);
  1590. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::compareExchange, &AtomicsObject::EntryInfo::CompareExchange, 4);
  1591. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::exchange, &AtomicsObject::EntryInfo::Exchange, 3);
  1592. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::isLockFree, &AtomicsObject::EntryInfo::IsLockFree, 1);
  1593. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::load, &AtomicsObject::EntryInfo::Load, 2);
  1594. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::or_, &AtomicsObject::EntryInfo::Or, 3);
  1595. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::store, &AtomicsObject::EntryInfo::Store, 3);
  1596. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::sub, &AtomicsObject::EntryInfo::Sub, 3);
  1597. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::wait, &AtomicsObject::EntryInfo::Wait, 4);
  1598. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::wake, &AtomicsObject::EntryInfo::Wake, 3);
  1599. library->AddFunctionToLibraryObject(atomicsObject, PropertyIds::xor_, &AtomicsObject::EntryInfo::Xor, 3);
  1600. if (atomicsObject->GetScriptContext()->GetConfig()->IsES6ToStringTagEnabled())
  1601. {
  1602. library->AddMember(atomicsObject, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("Atomics")), PropertyConfigurable);
  1603. }
  1604. atomicsObject->SetHasNoEnumerableProperties(true);
  1605. return true;
  1606. }
  1607. bool JavascriptLibrary::InitializeArrayBufferConstructor(DynamicObject* arrayBufferConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1608. {
  1609. typeHandler->Convert(arrayBufferConstructor, mode, 4);
  1610. ScriptContext* scriptContext = arrayBufferConstructor->GetScriptContext();
  1611. JavascriptLibrary* library = arrayBufferConstructor->GetLibrary();
  1612. library->AddMember(arrayBufferConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  1613. library->AddMember(arrayBufferConstructor, PropertyIds::prototype, scriptContext->GetLibrary()->arrayBufferPrototype, PropertyNone);
  1614. library->AddSpeciesAccessorsToLibraryObject(arrayBufferConstructor, &ArrayBuffer::EntryInfo::GetterSymbolSpecies);
  1615. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1616. {
  1617. library->AddMember(arrayBufferConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::ArrayBuffer), PropertyConfigurable);
  1618. }
  1619. library->AddFunctionToLibraryObject(arrayBufferConstructor, PropertyIds::isView, &ArrayBuffer::EntryInfo::IsView, 1);
  1620. #if ENABLE_DEBUG_CONFIG_OPTIONS
  1621. library->AddFunctionToLibraryObject(arrayBufferConstructor, PropertyIds::detach, &ArrayBuffer::EntryInfo::Detach, 1);
  1622. #endif
  1623. arrayBufferConstructor->SetHasNoEnumerableProperties(true);
  1624. return true;
  1625. }
  1626. bool JavascriptLibrary::InitializeArrayBufferPrototype(DynamicObject* arrayBufferPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1627. {
  1628. typeHandler->Convert(arrayBufferPrototype, mode, 2);
  1629. ScriptContext* scriptContext = arrayBufferPrototype->GetScriptContext();
  1630. JavascriptLibrary* library = arrayBufferPrototype->GetLibrary();
  1631. library->AddMember(arrayBufferPrototype, PropertyIds::constructor, library->arrayBufferConstructor);
  1632. library->AddFunctionToLibraryObject(arrayBufferPrototype, PropertyIds::slice, &ArrayBuffer::EntryInfo::Slice, 2);
  1633. library->AddAccessorsToLibraryObject(arrayBufferPrototype, PropertyIds::byteLength, &ArrayBuffer::EntryInfo::GetterByteLength, nullptr);
  1634. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1635. {
  1636. library->AddMember(arrayBufferPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("ArrayBuffer")), PropertyConfigurable);
  1637. }
  1638. arrayBufferPrototype->SetHasNoEnumerableProperties(true);
  1639. return true;
  1640. }
  1641. bool JavascriptLibrary::InitializeDataViewConstructor(DynamicObject* dataViewConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1642. {
  1643. typeHandler->Convert(dataViewConstructor, mode, 3);
  1644. ScriptContext* scriptContext = dataViewConstructor->GetScriptContext();
  1645. JavascriptLibrary* library = dataViewConstructor->GetLibrary();
  1646. library->AddMember(dataViewConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(3), PropertyConfigurable);
  1647. library->AddMember(dataViewConstructor, PropertyIds::prototype, scriptContext->GetLibrary()->dataViewPrototype, PropertyNone);
  1648. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1649. {
  1650. library->AddMember(dataViewConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::DataView), PropertyConfigurable);
  1651. }
  1652. dataViewConstructor->SetHasNoEnumerableProperties(true);
  1653. return true;
  1654. }
  1655. bool JavascriptLibrary::InitializeDataViewPrototype(DynamicObject* dataViewPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1656. {
  1657. typeHandler->Convert(dataViewPrototype, mode, 2);
  1658. ScriptContext* scriptContext = dataViewPrototype->GetScriptContext();
  1659. JavascriptLibrary* library = dataViewPrototype->GetLibrary();
  1660. library->AddMember(dataViewPrototype, PropertyIds::constructor, library->dataViewConstructor);
  1661. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setInt8, &DataView::EntryInfo::SetInt8, 2);
  1662. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setUint8, &DataView::EntryInfo::SetUint8, 2);
  1663. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setInt16, &DataView::EntryInfo::SetInt16, 2);
  1664. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setUint16, &DataView::EntryInfo::SetUint16, 2);
  1665. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setInt32, &DataView::EntryInfo::SetInt32, 2);
  1666. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setUint32, &DataView::EntryInfo::SetUint32, 2);
  1667. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setFloat32, &DataView::EntryInfo::SetFloat32, 2);
  1668. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setFloat64, &DataView::EntryInfo::SetFloat64, 2);
  1669. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getInt8, &DataView::EntryInfo::GetInt8, 1);
  1670. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getUint8, &DataView::EntryInfo::GetUint8, 1);
  1671. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getInt16, &DataView::EntryInfo::GetInt16, 1);
  1672. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getUint16, &DataView::EntryInfo::GetUint16, 1);
  1673. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getInt32, &DataView::EntryInfo::GetInt32, 1);
  1674. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getUint32, &DataView::EntryInfo::GetUint32, 1);
  1675. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getFloat32, &DataView::EntryInfo::GetFloat32, 1);
  1676. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getFloat64, &DataView::EntryInfo::GetFloat64, 1);
  1677. library->AddAccessorsToLibraryObject(dataViewPrototype, PropertyIds::buffer, &DataView::EntryInfo::GetterBuffer, nullptr);
  1678. library->AddAccessorsToLibraryObject(dataViewPrototype, PropertyIds::byteLength, &DataView::EntryInfo::GetterByteLength, nullptr);
  1679. library->AddAccessorsToLibraryObject(dataViewPrototype, PropertyIds::byteOffset, &DataView::EntryInfo::GetterByteOffset, nullptr);
  1680. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1681. {
  1682. library->AddMember(dataViewPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("DataView")), PropertyConfigurable);
  1683. }
  1684. dataViewPrototype->SetHasNoEnumerableProperties(true);
  1685. return true;
  1686. }
  1687. bool JavascriptLibrary::InitializeTypedArrayConstructor(DynamicObject* typedArrayConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1688. {
  1689. typeHandler->Convert(typedArrayConstructor, mode, 5);
  1690. ScriptContext* scriptContext = typedArrayConstructor->GetScriptContext();
  1691. JavascriptLibrary* library = typedArrayConstructor->GetLibrary();
  1692. library->AddMember(typedArrayConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(3), PropertyConfigurable);
  1693. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1694. {
  1695. library->AddMember(typedArrayConstructor, PropertyIds::name, library->CreateStringFromCppLiteral(_u("TypedArray")), PropertyConfigurable);
  1696. }
  1697. library->AddMember(typedArrayConstructor, PropertyIds::prototype, library->typedArrayPrototype, PropertyNone);
  1698. library->AddFunctionToLibraryObject(typedArrayConstructor, PropertyIds::from, &TypedArrayBase::EntryInfo::From, 1);
  1699. library->AddFunctionToLibraryObject(typedArrayConstructor, PropertyIds::of, &TypedArrayBase::EntryInfo::Of, 0);
  1700. library->AddSpeciesAccessorsToLibraryObject(typedArrayConstructor, &TypedArrayBase::EntryInfo::GetterSymbolSpecies);
  1701. typedArrayConstructor->SetHasNoEnumerableProperties(true);
  1702. return true;
  1703. }
  1704. bool JavascriptLibrary::InitializeTypedArrayPrototype(DynamicObject* typedarrayPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1705. {
  1706. typeHandler->Convert(typedarrayPrototype, mode, 31);
  1707. ScriptContext* scriptContext = typedarrayPrototype->GetScriptContext();
  1708. JavascriptLibrary* library = typedarrayPrototype->GetLibrary();
  1709. #ifdef ENABLE_JS_BUILTINS
  1710. if (scriptContext->IsJsBuiltInEnabled())
  1711. {
  1712. library->EnsureBuiltInEngineIsReady();
  1713. }
  1714. #endif
  1715. library->AddMember(typedarrayPrototype, PropertyIds::constructor, library->typedArrayConstructor);
  1716. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::set, &TypedArrayBase::EntryInfo::Set, 2);
  1717. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::subarray, &TypedArrayBase::EntryInfo::Subarray, 2);
  1718. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::copyWithin, &TypedArrayBase::EntryInfo::CopyWithin, 2);
  1719. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::every, &TypedArrayBase::EntryInfo::Every, 1);
  1720. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::fill, &TypedArrayBase::EntryInfo::Fill, 1);
  1721. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::filter, &TypedArrayBase::EntryInfo::Filter, 1);
  1722. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::find, &TypedArrayBase::EntryInfo::Find, 1);
  1723. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::findIndex, &TypedArrayBase::EntryInfo::FindIndex, 1);
  1724. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::forEach, &TypedArrayBase::EntryInfo::ForEach, 1);
  1725. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::indexOf, &TypedArrayBase::EntryInfo::IndexOf, 1);
  1726. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::join, &TypedArrayBase::EntryInfo::Join, 1);
  1727. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::lastIndexOf, &TypedArrayBase::EntryInfo::LastIndexOf, 1);
  1728. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::map, &TypedArrayBase::EntryInfo::Map, 1);
  1729. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::reduce, &TypedArrayBase::EntryInfo::Reduce, 1);
  1730. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::reduceRight, &TypedArrayBase::EntryInfo::ReduceRight, 1);
  1731. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::reverse, &TypedArrayBase::EntryInfo::Reverse, 0);
  1732. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::slice, &TypedArrayBase::EntryInfo::Slice, 2);
  1733. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::some, &TypedArrayBase::EntryInfo::Some, 1);
  1734. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::sort, &TypedArrayBase::EntryInfo::Sort, 1);
  1735. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::entries, &TypedArrayBase::EntryInfo::Entries, 0);
  1736. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::keys, &TypedArrayBase::EntryInfo::Keys, 0);
  1737. JavascriptFunction* valuesFunc = library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::values, &TypedArrayBase::EntryInfo::Values, 0);
  1738. library->AddMember(typedarrayPrototype, PropertyIds::_symbolIterator, valuesFunc);
  1739. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::includes, &TypedArrayBase::EntryInfo::Includes, 1);
  1740. library->AddAccessorsToLibraryObject(typedarrayPrototype, PropertyIds::buffer, &TypedArrayBase::EntryInfo::GetterBuffer, nullptr);
  1741. library->AddAccessorsToLibraryObject(typedarrayPrototype, PropertyIds::byteLength, &TypedArrayBase::EntryInfo::GetterByteLength, nullptr);
  1742. library->AddAccessorsToLibraryObject(typedarrayPrototype, PropertyIds::byteOffset, &TypedArrayBase::EntryInfo::GetterByteOffset, nullptr);
  1743. library->AddAccessorsToLibraryObject(typedarrayPrototype, PropertyIds::length, &TypedArrayBase::EntryInfo::GetterLength, nullptr);
  1744. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1745. {
  1746. // ES2017 22.2.3.32 get %TypedArray%.prototype[@@toStringTag]
  1747. // %TypedArray%.prototype[@@toStringTag] is an accessor property whose set accessor function is undefined.
  1748. // This property has the attributes { [[Enumerable]]: false, [[Configurable]]: true }.
  1749. // The initial value of the name property of this function is "get [Symbol.toStringTag]".
  1750. library->AddAccessorsToLibraryObjectWithName(typedarrayPrototype, PropertyIds::_symbolToStringTag,
  1751. PropertyIds::_RuntimeFunctionNameId_toStringTag, &TypedArrayBase::EntryInfo::GetterSymbolToStringTag, nullptr);
  1752. }
  1753. // The toString and toLocaleString properties are shared between Array.prototype and %TypedArray%.prototype.
  1754. // Whichever prototype is initialized first will create the functions, the other should just load the existing function objects.
  1755. if (library->arrayPrototypeToStringFunction == nullptr)
  1756. {
  1757. Assert(library->arrayPrototypeToLocaleStringFunction == nullptr);
  1758. library->arrayPrototypeToLocaleStringFunction = library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::toLocaleString, &JavascriptArray::EntryInfo::ToLocaleString, 0);
  1759. library->arrayPrototypeToStringFunction = library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::toString, &JavascriptArray::EntryInfo::ToString, 0);
  1760. }
  1761. else
  1762. {
  1763. Assert(library->arrayPrototypeToLocaleStringFunction);
  1764. library->AddMember(typedarrayPrototype, PropertyIds::toLocaleString, library->arrayPrototypeToLocaleStringFunction);
  1765. library->AddMember(typedarrayPrototype, PropertyIds::toString, library->arrayPrototypeToStringFunction);
  1766. }
  1767. typedarrayPrototype->SetHasNoEnumerableProperties(true);
  1768. return true;
  1769. }
  1770. #define INIT_TYPEDARRAY_CONSTRUCTOR(typedArray, typedarrayPrototype, TypeName) \
  1771. bool JavascriptLibrary::Initialize##typedArray##Constructor(DynamicObject* typedArrayConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode) \
  1772. { \
  1773. typeHandler->Convert(typedArrayConstructor, mode, 4); \
  1774. ScriptContext* scriptContext = typedArrayConstructor->GetScriptContext(); \
  1775. JavascriptLibrary* library = typedArrayConstructor->GetLibrary(); \
  1776. library->AddMember(typedArrayConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(3), PropertyConfigurable); \
  1777. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled()) \
  1778. { \
  1779. library->AddMember(typedArrayConstructor, PropertyIds::name, library->CreateStringFromCppLiteral(_u(#typedArray)), PropertyConfigurable); \
  1780. } \
  1781. library->AddMember(typedArrayConstructor, PropertyIds::BYTES_PER_ELEMENT, TaggedInt::ToVarUnchecked(sizeof(TypeName)), PropertyNone); \
  1782. library->AddMember(typedArrayConstructor, PropertyIds::prototype, scriptContext->GetLibrary()->##typedarrayPrototype##, PropertyNone); \
  1783. typedArrayConstructor->SetHasNoEnumerableProperties(true); \
  1784. return true; \
  1785. } \
  1786. INIT_TYPEDARRAY_CONSTRUCTOR(Int8Array, Int8ArrayPrototype, int8);
  1787. INIT_TYPEDARRAY_CONSTRUCTOR(Uint8Array, Uint8ArrayPrototype, uint8);
  1788. INIT_TYPEDARRAY_CONSTRUCTOR(Uint8ClampedArray, Uint8ClampedArrayPrototype, uint8);
  1789. INIT_TYPEDARRAY_CONSTRUCTOR(Int16Array, Int16ArrayPrototype, int16);
  1790. INIT_TYPEDARRAY_CONSTRUCTOR(Uint16Array, Uint16ArrayPrototype, uint16);
  1791. INIT_TYPEDARRAY_CONSTRUCTOR(Int32Array, Int32ArrayPrototype, int32);
  1792. INIT_TYPEDARRAY_CONSTRUCTOR(Uint32Array, Uint32ArrayPrototype, uint32);
  1793. INIT_TYPEDARRAY_CONSTRUCTOR(Float32Array, Float32ArrayPrototype, float);
  1794. INIT_TYPEDARRAY_CONSTRUCTOR(Float64Array, Float64ArrayPrototype, double);
  1795. #define INIT_TYPEDARRAY_PROTOTYPE(typedArray, typedarrayPrototype, TypeName) \
  1796. bool JavascriptLibrary::Initialize##typedarrayPrototype##(DynamicObject* typedarrayPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode) \
  1797. { \
  1798. typeHandler->Convert(typedarrayPrototype, mode, 2); \
  1799. JavascriptLibrary* library = typedarrayPrototype->GetLibrary(); \
  1800. library->AddMember(typedarrayPrototype, PropertyIds::constructor, library->##typedArray##Constructor); \
  1801. library->AddMember(typedarrayPrototype, PropertyIds::BYTES_PER_ELEMENT, TaggedInt::ToVarUnchecked(sizeof(TypeName)), PropertyNone); \
  1802. typedarrayPrototype->SetHasNoEnumerableProperties(true); \
  1803. return true; \
  1804. } \
  1805. INIT_TYPEDARRAY_PROTOTYPE(Int8Array, Int8ArrayPrototype, int8);
  1806. INIT_TYPEDARRAY_PROTOTYPE(Uint8Array, Uint8ArrayPrototype, uint8);
  1807. INIT_TYPEDARRAY_PROTOTYPE(Uint8ClampedArray, Uint8ClampedArrayPrototype, uint8);
  1808. INIT_TYPEDARRAY_PROTOTYPE(Int16Array, Int16ArrayPrototype, int16);
  1809. INIT_TYPEDARRAY_PROTOTYPE(Uint16Array, Uint16ArrayPrototype, uint16);
  1810. INIT_TYPEDARRAY_PROTOTYPE(Int32Array, Int32ArrayPrototype, int32);
  1811. INIT_TYPEDARRAY_PROTOTYPE(Uint32Array, Uint32ArrayPrototype, uint32);
  1812. INIT_TYPEDARRAY_PROTOTYPE(Float32Array, Float32ArrayPrototype, float);
  1813. INIT_TYPEDARRAY_PROTOTYPE(Float64Array, Float64ArrayPrototype, double);
  1814. // For Microsoft extension typed array, like Int64Array, BoolArray, we don't have constructor as they can only be created from the projection arguments.
  1815. // there is no subarray method either as that's another way to create typed array.
  1816. #define INIT_MSINTERNAL_TYPEDARRAY_PROTOTYPE(typedArray, typedarrayPrototype) \
  1817. bool JavascriptLibrary::Initialize##typedarrayPrototype##(DynamicObject* typedarrayPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode) \
  1818. { \
  1819. typeHandler->Convert(typedarrayPrototype, mode, 1); \
  1820. JavascriptLibrary* library = typedarrayPrototype->GetLibrary(); \
  1821. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::set, &##typedArray##::EntryInfo::Set, 2); \
  1822. typedarrayPrototype->SetHasNoEnumerableProperties(true); \
  1823. return true; \
  1824. } \
  1825. INIT_MSINTERNAL_TYPEDARRAY_PROTOTYPE(Int64Array, Int64ArrayPrototype);
  1826. INIT_MSINTERNAL_TYPEDARRAY_PROTOTYPE(Uint64Array, Uint64ArrayPrototype);
  1827. INIT_MSINTERNAL_TYPEDARRAY_PROTOTYPE(BoolArray, BoolArrayPrototype);
  1828. INIT_MSINTERNAL_TYPEDARRAY_PROTOTYPE(CharArray, CharArrayPrototype);
  1829. bool JavascriptLibrary::InitializeErrorConstructor(DynamicObject* constructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1830. {
  1831. typeHandler->Convert(constructor, mode, 4);
  1832. ScriptContext* scriptContext = constructor->GetScriptContext();
  1833. JavascriptLibrary* library = constructor->GetLibrary();
  1834. library->AddMember(constructor, PropertyIds::prototype, library->errorPrototype, PropertyNone);
  1835. library->AddMember(constructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  1836. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1837. {
  1838. library->AddMember(constructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Error), PropertyConfigurable);
  1839. }
  1840. if (scriptContext->GetConfig()->IsErrorStackTraceEnabled())
  1841. {
  1842. library->AddMember(constructor, PropertyIds::stackTraceLimit, JavascriptNumber::ToVar(JavascriptExceptionOperators::DefaultStackTraceLimit, scriptContext), PropertyConfigurable | PropertyWritable | PropertyEnumerable);
  1843. }
  1844. constructor->SetHasNoEnumerableProperties(true);
  1845. return true;
  1846. }
  1847. bool JavascriptLibrary::InitializeErrorPrototype(DynamicObject* prototype, DeferredTypeHandlerBase* typeHandler, DeferredInitializeMode mode)
  1848. {
  1849. typeHandler->Convert(prototype, mode, 4);
  1850. JavascriptLibrary* library = prototype->GetLibrary();
  1851. library->AddMember(prototype, PropertyIds::constructor, library->errorConstructor);
  1852. bool hasNoEnumerableProperties = true;
  1853. PropertyAttributes prototypeNameMessageAttributes = PropertyConfigurable | PropertyWritable;
  1854. library->AddMember(prototype, PropertyIds::name, library->CreateStringFromCppLiteral(_u("Error")), prototypeNameMessageAttributes);
  1855. library->AddMember(prototype, PropertyIds::message, library->GetEmptyString(), prototypeNameMessageAttributes);
  1856. library->AddFunctionToLibraryObject(prototype, PropertyIds::toString, &JavascriptError::EntryInfo::ToString, 0);
  1857. prototype->SetHasNoEnumerableProperties(hasNoEnumerableProperties);
  1858. return true;
  1859. }
  1860. #define INIT_ERROR_IMPL(error, errorName) \
  1861. bool JavascriptLibrary::Initialize##error##Constructor(DynamicObject* constructor, DeferredTypeHandlerBase* typeHandler, DeferredInitializeMode mode) \
  1862. { \
  1863. typeHandler->Convert(constructor, mode, 3); \
  1864. ScriptContext* scriptContext = constructor->GetScriptContext(); \
  1865. JavascriptLibrary* library = constructor->GetLibrary(); \
  1866. library->AddMember(constructor, PropertyIds::prototype, library->Get##error##Prototype(), PropertyNone); \
  1867. library->AddMember(constructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable); \
  1868. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled()) \
  1869. { \
  1870. PropertyAttributes prototypeNameMessageAttributes = PropertyConfigurable; \
  1871. library->AddMember(constructor, PropertyIds::name, library->CreateStringFromCppLiteral(_u(#errorName)), prototypeNameMessageAttributes); \
  1872. } \
  1873. constructor->SetHasNoEnumerableProperties(true); \
  1874. return true; \
  1875. } \
  1876. bool JavascriptLibrary::Initialize##error##Prototype(DynamicObject* prototype, DeferredTypeHandlerBase* typeHandler, DeferredInitializeMode mode) \
  1877. { \
  1878. typeHandler->Convert(prototype, mode, 4); \
  1879. JavascriptLibrary* library = prototype->GetLibrary(); \
  1880. library->AddMember(prototype, PropertyIds::constructor, library->Get##error##Constructor()); \
  1881. bool hasNoEnumerableProperties = true; \
  1882. PropertyAttributes prototypeNameMessageAttributes = PropertyConfigurable | PropertyWritable; \
  1883. library->AddMember(prototype, PropertyIds::name, library->CreateStringFromCppLiteral(_u(#errorName)), prototypeNameMessageAttributes); \
  1884. library->AddMember(prototype, PropertyIds::message, library->GetEmptyString(), prototypeNameMessageAttributes); \
  1885. library->AddFunctionToLibraryObject(prototype, PropertyIds::toString, &JavascriptError::EntryInfo::ToString, 0); \
  1886. prototype->SetHasNoEnumerableProperties(hasNoEnumerableProperties); \
  1887. return true; \
  1888. }
  1889. #define INIT_ERROR(error) INIT_ERROR_IMPL(error, error)
  1890. INIT_ERROR(EvalError);
  1891. INIT_ERROR(RangeError);
  1892. INIT_ERROR(ReferenceError);
  1893. INIT_ERROR(SyntaxError);
  1894. INIT_ERROR(TypeError);
  1895. INIT_ERROR(URIError);
  1896. INIT_ERROR_IMPL(WebAssemblyCompileError, CompileError);
  1897. INIT_ERROR_IMPL(WebAssemblyRuntimeError, RuntimeError);
  1898. INIT_ERROR_IMPL(WebAssemblyLinkError, LinkError);
  1899. #undef INIT_ERROR
  1900. bool JavascriptLibrary::InitializeBooleanConstructor(DynamicObject* booleanConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1901. {
  1902. typeHandler->Convert(booleanConstructor, mode, 3);
  1903. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterBoolean
  1904. // so that the update is in sync with profiler
  1905. ScriptContext* scriptContext = booleanConstructor->GetScriptContext();
  1906. JavascriptLibrary* library = booleanConstructor->GetLibrary();
  1907. library->AddMember(booleanConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  1908. library->AddMember(booleanConstructor, PropertyIds::prototype, library->booleanPrototype, PropertyNone);
  1909. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1910. {
  1911. library->AddMember(booleanConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Boolean), PropertyConfigurable);
  1912. }
  1913. booleanConstructor->SetHasNoEnumerableProperties(true);
  1914. return true;
  1915. }
  1916. bool JavascriptLibrary::InitializeBooleanPrototype(DynamicObject* booleanPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1917. {
  1918. typeHandler->Convert(booleanPrototype, mode, 3);
  1919. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterBoolean
  1920. // so that the update is in sync with profiler
  1921. JavascriptLibrary* library = booleanPrototype->GetLibrary();
  1922. ScriptContext* scriptContext = booleanPrototype->GetScriptContext();
  1923. library->AddMember(booleanPrototype, PropertyIds::constructor, library->booleanConstructor);
  1924. scriptContext->SetBuiltInLibraryFunction(JavascriptBoolean::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  1925. library->AddFunctionToLibraryObject(booleanPrototype, PropertyIds::valueOf, &JavascriptBoolean::EntryInfo::ValueOf, 0));
  1926. scriptContext->SetBuiltInLibraryFunction(JavascriptBoolean::EntryInfo::ToString.GetOriginalEntryPoint(),
  1927. library->AddFunctionToLibraryObject(booleanPrototype, PropertyIds::toString, &JavascriptBoolean::EntryInfo::ToString, 0));
  1928. booleanPrototype->SetHasNoEnumerableProperties(true);
  1929. return true;
  1930. }
  1931. bool JavascriptLibrary::InitializeSymbolConstructor(DynamicObject* symbolConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1932. {
  1933. typeHandler->Convert(symbolConstructor, mode, 16);
  1934. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSymbol
  1935. // so that the update is in sync with profiler
  1936. JavascriptLibrary* library = symbolConstructor->GetLibrary();
  1937. ScriptContext* scriptContext = symbolConstructor->GetScriptContext();
  1938. library->AddMember(symbolConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable);
  1939. library->AddMember(symbolConstructor, PropertyIds::prototype, library->symbolPrototype, PropertyNone);
  1940. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1941. {
  1942. library->AddMember(symbolConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Symbol), PropertyConfigurable);
  1943. }
  1944. if (scriptContext->GetConfig()->IsES6HasInstanceEnabled())
  1945. {
  1946. library->AddMember(symbolConstructor, PropertyIds::hasInstance, library->GetSymbolHasInstance(), PropertyNone);
  1947. }
  1948. if (scriptContext->GetConfig()->IsES6IsConcatSpreadableEnabled())
  1949. {
  1950. library->AddMember(symbolConstructor, PropertyIds::isConcatSpreadable, library->GetSymbolIsConcatSpreadable(), PropertyNone);
  1951. }
  1952. library->AddMember(symbolConstructor, PropertyIds::iterator, library->GetSymbolIterator(), PropertyNone);
  1953. if (scriptContext->GetConfig()->IsES6SpeciesEnabled())
  1954. {
  1955. library->AddMember(symbolConstructor, PropertyIds::species, library->GetSymbolSpecies(), PropertyNone);
  1956. }
  1957. if (scriptContext->GetConfig()->IsES6ToPrimitiveEnabled())
  1958. {
  1959. library->AddMember(symbolConstructor, PropertyIds::toPrimitive, library->GetSymbolToPrimitive(), PropertyNone);
  1960. }
  1961. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1962. {
  1963. library->AddMember(symbolConstructor, PropertyIds::toStringTag, library->GetSymbolToStringTag(), PropertyNone);
  1964. }
  1965. library->AddMember(symbolConstructor, PropertyIds::unscopables, library->GetSymbolUnscopables(), PropertyNone);
  1966. if (scriptContext->GetConfig()->IsES6RegExSymbolsEnabled())
  1967. {
  1968. library->AddMember(symbolConstructor, PropertyIds::match, library->GetSymbolMatch(), PropertyNone);
  1969. library->AddMember(symbolConstructor, PropertyIds::replace, library->GetSymbolReplace(), PropertyNone);
  1970. library->AddMember(symbolConstructor, PropertyIds::search, library->GetSymbolSearch(), PropertyNone);
  1971. library->AddMember(symbolConstructor, PropertyIds::split, library->GetSymbolSplit(), PropertyNone);
  1972. }
  1973. library->AddFunctionToLibraryObject(symbolConstructor, PropertyIds::for_, &JavascriptSymbol::EntryInfo::For, 1);
  1974. library->AddFunctionToLibraryObject(symbolConstructor, PropertyIds::keyFor, &JavascriptSymbol::EntryInfo::KeyFor, 1);
  1975. symbolConstructor->SetHasNoEnumerableProperties(true);
  1976. return true;
  1977. }
  1978. bool JavascriptLibrary::InitializeSymbolPrototype(DynamicObject* symbolPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1979. {
  1980. typeHandler->Convert(symbolPrototype, mode, 5);
  1981. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSymbol
  1982. // so that the update is in sync with profiler
  1983. JavascriptLibrary* library = symbolPrototype->GetLibrary();
  1984. ScriptContext* scriptContext = symbolPrototype->GetScriptContext();
  1985. library->AddMember(symbolPrototype, PropertyIds::constructor, library->symbolConstructor);
  1986. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1987. {
  1988. library->AddMember(symbolPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("Symbol")), PropertyConfigurable);
  1989. }
  1990. scriptContext->SetBuiltInLibraryFunction(JavascriptSymbol::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  1991. library->AddFunctionToLibraryObject(symbolPrototype, PropertyIds::valueOf, &JavascriptSymbol::EntryInfo::ValueOf, 0));
  1992. scriptContext->SetBuiltInLibraryFunction(JavascriptSymbol::EntryInfo::ToString.GetOriginalEntryPoint(),
  1993. library->AddFunctionToLibraryObject(symbolPrototype, PropertyIds::toString, &JavascriptSymbol::EntryInfo::ToString, 0));
  1994. if (scriptContext->GetConfig()->IsES6ToPrimitiveEnabled())
  1995. {
  1996. scriptContext->SetBuiltInLibraryFunction(JavascriptSymbol::EntryInfo::SymbolToPrimitive.GetOriginalEntryPoint(),
  1997. library->AddFunctionToLibraryObjectWithName(symbolPrototype, PropertyIds::_symbolToPrimitive, PropertyIds::_RuntimeFunctionNameId_toPrimitive,
  1998. &JavascriptSymbol::EntryInfo::SymbolToPrimitive, 1));
  1999. symbolPrototype->SetWritable(PropertyIds::_symbolToPrimitive, false);
  2000. }
  2001. symbolPrototype->SetHasNoEnumerableProperties(true);
  2002. return true;
  2003. }
  2004. bool JavascriptLibrary::InitializePromiseConstructor(DynamicObject* promiseConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2005. {
  2006. typeHandler->Convert(promiseConstructor, mode, 8);
  2007. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterPromise
  2008. // so that the update is in sync with profiler
  2009. JavascriptLibrary* library = promiseConstructor->GetLibrary();
  2010. ScriptContext* scriptContext = promiseConstructor->GetScriptContext();
  2011. library->AddMember(promiseConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  2012. library->AddMember(promiseConstructor, PropertyIds::prototype, library->promisePrototype, PropertyNone);
  2013. library->AddSpeciesAccessorsToLibraryObject(promiseConstructor, &JavascriptPromise::EntryInfo::GetterSymbolSpecies);
  2014. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2015. {
  2016. library->AddMember(promiseConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Promise), PropertyConfigurable);
  2017. }
  2018. library->AddFunctionToLibraryObject(promiseConstructor, PropertyIds::all, &JavascriptPromise::EntryInfo::All, 1);
  2019. library->AddFunctionToLibraryObject(promiseConstructor, PropertyIds::race, &JavascriptPromise::EntryInfo::Race, 1);
  2020. library->AddFunctionToLibraryObject(promiseConstructor, PropertyIds::reject, &JavascriptPromise::EntryInfo::Reject, 1);
  2021. library->AddMember(promiseConstructor, PropertyIds::resolve, library->EnsurePromiseResolveFunction(), PropertyBuiltInMethodDefaults);
  2022. promiseConstructor->SetHasNoEnumerableProperties(true);
  2023. return true;
  2024. }
  2025. JavascriptFunction* JavascriptLibrary::EnsurePromiseResolveFunction()
  2026. {
  2027. if (promiseResolveFunction == nullptr)
  2028. {
  2029. promiseResolveFunction = DefaultCreateFunction(&JavascriptPromise::EntryInfo::Resolve, 1, nullptr, nullptr, PropertyIds::resolve);
  2030. }
  2031. return promiseResolveFunction;
  2032. }
  2033. bool JavascriptLibrary::InitializePromisePrototype(DynamicObject* promisePrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2034. {
  2035. typeHandler->Convert(promisePrototype, mode, 4);
  2036. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterPromise
  2037. // so that the update is in sync with profiler
  2038. JavascriptLibrary* library = promisePrototype->GetLibrary();
  2039. ScriptContext* scriptContext = promisePrototype->GetScriptContext();
  2040. library->AddMember(promisePrototype, PropertyIds::constructor, library->promiseConstructor);
  2041. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  2042. {
  2043. library->AddMember(promisePrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("Promise")), PropertyConfigurable);
  2044. }
  2045. scriptContext->SetBuiltInLibraryFunction(JavascriptPromise::EntryInfo::Catch.GetOriginalEntryPoint(),
  2046. library->AddFunctionToLibraryObject(promisePrototype, PropertyIds::catch_, &JavascriptPromise::EntryInfo::Catch, 1));
  2047. library->AddMember(promisePrototype, PropertyIds::then, library->EnsurePromiseThenFunction(), PropertyBuiltInMethodDefaults);
  2048. scriptContext->SetBuiltInLibraryFunction(JavascriptPromise::EntryInfo::Then.GetOriginalEntryPoint(), library->EnsurePromiseThenFunction());
  2049. promisePrototype->SetHasNoEnumerableProperties(true);
  2050. return true;
  2051. }
  2052. JavascriptFunction* JavascriptLibrary::EnsurePromiseThenFunction()
  2053. {
  2054. if (promiseThenFunction == nullptr)
  2055. {
  2056. promiseThenFunction = DefaultCreateFunction(&JavascriptPromise::EntryInfo::Then, 2, nullptr, nullptr, PropertyIds::then);
  2057. }
  2058. return promiseThenFunction;
  2059. }
  2060. bool JavascriptLibrary::InitializeGeneratorFunctionConstructor(DynamicObject* generatorFunctionConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2061. {
  2062. typeHandler->Convert(generatorFunctionConstructor, mode, 3);
  2063. JavascriptLibrary* library = generatorFunctionConstructor->GetLibrary();
  2064. ScriptContext* scriptContext = generatorFunctionConstructor->GetScriptContext();
  2065. library->AddMember(generatorFunctionConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  2066. library->AddMember(generatorFunctionConstructor, PropertyIds::prototype, library->generatorFunctionPrototype, PropertyNone);
  2067. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2068. {
  2069. library->AddMember(generatorFunctionConstructor, PropertyIds::name, library->CreateStringFromCppLiteral(_u("GeneratorFunction")), PropertyConfigurable);
  2070. }
  2071. generatorFunctionConstructor->SetHasNoEnumerableProperties(true);
  2072. return true;
  2073. }
  2074. bool JavascriptLibrary::InitializeGeneratorFunctionPrototype(DynamicObject* generatorFunctionPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2075. {
  2076. typeHandler->Convert(generatorFunctionPrototype, mode, 3);
  2077. JavascriptLibrary* library = generatorFunctionPrototype->GetLibrary();
  2078. ScriptContext* scriptContext = library->GetScriptContext();
  2079. library->AddMember(generatorFunctionPrototype, PropertyIds::constructor, library->generatorFunctionConstructor, PropertyConfigurable);
  2080. library->AddMember(generatorFunctionPrototype, PropertyIds::prototype, library->generatorPrototype, PropertyConfigurable);
  2081. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  2082. {
  2083. library->AddMember(generatorFunctionPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("GeneratorFunction")), PropertyConfigurable);
  2084. }
  2085. generatorFunctionPrototype->SetHasNoEnumerableProperties(true);
  2086. return true;
  2087. }
  2088. bool JavascriptLibrary::InitializeGeneratorPrototype(DynamicObject* generatorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2089. {
  2090. typeHandler->Convert(generatorPrototype, mode, 5);
  2091. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterGenerator
  2092. // so that the update is in sync with profiler
  2093. JavascriptLibrary* library = generatorPrototype->GetLibrary();
  2094. ScriptContext* scriptContext = library->GetScriptContext();
  2095. library->AddMember(generatorPrototype, PropertyIds::constructor, library->generatorFunctionPrototype, PropertyConfigurable);
  2096. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  2097. {
  2098. library->AddMember(generatorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("Generator")), PropertyConfigurable);
  2099. }
  2100. library->AddFunctionToLibraryObject(generatorPrototype, PropertyIds::return_, &JavascriptGenerator::EntryInfo::Return, 1);
  2101. library->AddMember(generatorPrototype, PropertyIds::next, library->EnsureGeneratorNextFunction(), PropertyBuiltInMethodDefaults);
  2102. library->AddMember(generatorPrototype, PropertyIds::throw_, library->EnsureGeneratorThrowFunction(), PropertyBuiltInMethodDefaults);
  2103. generatorPrototype->SetHasNoEnumerableProperties(true);
  2104. return true;
  2105. }
  2106. JavascriptFunction* JavascriptLibrary::EnsureGeneratorNextFunction()
  2107. {
  2108. if (generatorNextFunction == nullptr)
  2109. {
  2110. generatorNextFunction = DefaultCreateFunction(&JavascriptGenerator::EntryInfo::Next, 1, nullptr, nullptr, PropertyIds::next);
  2111. }
  2112. return generatorNextFunction;
  2113. }
  2114. JavascriptFunction* JavascriptLibrary::EnsureGeneratorThrowFunction()
  2115. {
  2116. if (generatorThrowFunction == nullptr)
  2117. {
  2118. generatorThrowFunction = DefaultCreateFunction(&JavascriptGenerator::EntryInfo::Throw, 1, nullptr, nullptr, PropertyIds::throw_);
  2119. }
  2120. return generatorThrowFunction;
  2121. }
  2122. bool JavascriptLibrary::InitializeAsyncFunctionConstructor(DynamicObject* asyncFunctionConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2123. {
  2124. typeHandler->Convert(asyncFunctionConstructor, mode, 3);
  2125. JavascriptLibrary* library = asyncFunctionConstructor->GetLibrary();
  2126. ScriptContext* scriptContext = asyncFunctionConstructor->GetScriptContext();
  2127. library->AddMember(asyncFunctionConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  2128. library->AddMember(asyncFunctionConstructor, PropertyIds::prototype, library->asyncFunctionPrototype, PropertyNone);
  2129. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2130. {
  2131. library->AddMember(asyncFunctionConstructor, PropertyIds::name, library->CreateStringFromCppLiteral(_u("AsyncFunction")), PropertyConfigurable);
  2132. }
  2133. asyncFunctionConstructor->SetHasNoEnumerableProperties(true);
  2134. return true;
  2135. }
  2136. bool JavascriptLibrary::InitializeAsyncFunctionPrototype(DynamicObject* asyncFunctionPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2137. {
  2138. typeHandler->Convert(asyncFunctionPrototype, mode, 2);
  2139. JavascriptLibrary* library = asyncFunctionPrototype->GetLibrary();
  2140. ScriptContext* scriptContext = library->GetScriptContext();
  2141. library->AddMember(asyncFunctionPrototype, PropertyIds::constructor, library->asyncFunctionConstructor, PropertyConfigurable);
  2142. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  2143. {
  2144. library->AddMember(asyncFunctionPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("AsyncFunction")), PropertyConfigurable);
  2145. }
  2146. asyncFunctionPrototype->SetHasNoEnumerableProperties(true);
  2147. return true;
  2148. }
  2149. bool JavascriptLibrary::InitializeProxyConstructor(DynamicObject* proxyConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2150. {
  2151. typeHandler->Convert(proxyConstructor, mode, 4);
  2152. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSymbol
  2153. // so that the update is in sync with profiler
  2154. JavascriptLibrary* library = proxyConstructor->GetLibrary();
  2155. ScriptContext* scriptContext = proxyConstructor->GetScriptContext();
  2156. library->AddMember(proxyConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(2), PropertyConfigurable);
  2157. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2158. {
  2159. library->AddMember(proxyConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Proxy), PropertyConfigurable);
  2160. }
  2161. library->AddFunctionToLibraryObject(proxyConstructor, PropertyIds::revocable, &JavascriptProxy::EntryInfo::Revocable, 2, PropertyConfigurable);
  2162. proxyConstructor->SetHasNoEnumerableProperties(true);
  2163. return true;
  2164. }
  2165. bool JavascriptLibrary::InitializeProxyPrototype(DynamicObject* proxyPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2166. {
  2167. typeHandler->Convert(proxyPrototype, mode, 1);
  2168. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSymbol
  2169. // so that the update is in sync with profiler
  2170. JavascriptLibrary* library = proxyPrototype->GetLibrary();
  2171. library->AddMember(proxyPrototype, PropertyIds::constructor, library->proxyConstructor);
  2172. proxyPrototype->SetHasNoEnumerableProperties(true);
  2173. return true;
  2174. }
  2175. bool JavascriptLibrary::InitializeDateConstructor(DynamicObject* dateConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2176. {
  2177. typeHandler->Convert(dateConstructor, mode, 6);
  2178. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterDate
  2179. // so that the update is in sync with profiler
  2180. JavascriptLibrary* library = dateConstructor->GetLibrary();
  2181. ScriptContext* scriptContext = dateConstructor->GetScriptContext();
  2182. library->AddMember(dateConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(7), PropertyConfigurable);
  2183. library->AddMember(dateConstructor, PropertyIds::prototype, library->datePrototype, PropertyNone);
  2184. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2185. {
  2186. library->AddMember(dateConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Date), PropertyConfigurable);
  2187. }
  2188. library->AddFunctionToLibraryObject(dateConstructor, PropertyIds::parse, &JavascriptDate::EntryInfo::Parse, 1); // should be static
  2189. library->AddFunctionToLibraryObject(dateConstructor, PropertyIds::now, &JavascriptDate::EntryInfo::Now, 0); // should be static
  2190. library->AddFunctionToLibraryObject(dateConstructor, PropertyIds::UTC, &JavascriptDate::EntryInfo::UTC, 7); // should be static
  2191. dateConstructor->SetHasNoEnumerableProperties(true);
  2192. return true;
  2193. }
  2194. bool JavascriptLibrary::InitializeDatePrototype(DynamicObject* datePrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2195. {
  2196. typeHandler->Convert(datePrototype, mode, 51);
  2197. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterDate
  2198. // so that the update is in sync with profiler
  2199. ScriptContext* scriptContext = datePrototype->GetScriptContext();
  2200. JavascriptLibrary* library = datePrototype->GetLibrary();
  2201. library->AddMember(datePrototype, PropertyIds::constructor, library->dateConstructor);
  2202. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetDate.GetOriginalEntryPoint(),
  2203. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getDate, &JavascriptDate::EntryInfo::GetDate, 0));
  2204. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetDay.GetOriginalEntryPoint(),
  2205. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getDay, &JavascriptDate::EntryInfo::GetDay, 0));
  2206. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetFullYear.GetOriginalEntryPoint(),
  2207. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getFullYear, &JavascriptDate::EntryInfo::GetFullYear, 0));
  2208. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetHours.GetOriginalEntryPoint(),
  2209. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getHours, &JavascriptDate::EntryInfo::GetHours, 0));
  2210. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetMilliseconds.GetOriginalEntryPoint(),
  2211. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getMilliseconds, &JavascriptDate::EntryInfo::GetMilliseconds, 0));
  2212. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetMinutes.GetOriginalEntryPoint(),
  2213. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getMinutes, &JavascriptDate::EntryInfo::GetMinutes, 0));
  2214. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetMonth.GetOriginalEntryPoint(),
  2215. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getMonth, &JavascriptDate::EntryInfo::GetMonth, 0));
  2216. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetSeconds.GetOriginalEntryPoint(),
  2217. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getSeconds, &JavascriptDate::EntryInfo::GetSeconds, 0));
  2218. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetTime.GetOriginalEntryPoint(),
  2219. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getTime, &JavascriptDate::EntryInfo::GetTime, 0));
  2220. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetTimezoneOffset.GetOriginalEntryPoint(),
  2221. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getTimezoneOffset, &JavascriptDate::EntryInfo::GetTimezoneOffset, 0));
  2222. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCDate.GetOriginalEntryPoint(),
  2223. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCDate, &JavascriptDate::EntryInfo::GetUTCDate, 0));
  2224. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCDay.GetOriginalEntryPoint(),
  2225. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCDay, &JavascriptDate::EntryInfo::GetUTCDay, 0));
  2226. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCFullYear.GetOriginalEntryPoint(),
  2227. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCFullYear, &JavascriptDate::EntryInfo::GetUTCFullYear, 0));
  2228. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCHours.GetOriginalEntryPoint(),
  2229. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCHours, &JavascriptDate::EntryInfo::GetUTCHours, 0));
  2230. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCMilliseconds.GetOriginalEntryPoint(),
  2231. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCMilliseconds, &JavascriptDate::EntryInfo::GetUTCMilliseconds, 0));
  2232. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCMinutes.GetOriginalEntryPoint(),
  2233. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCMinutes, &JavascriptDate::EntryInfo::GetUTCMinutes, 0));
  2234. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCMonth.GetOriginalEntryPoint(),
  2235. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCMonth, &JavascriptDate::EntryInfo::GetUTCMonth, 0));
  2236. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCSeconds.GetOriginalEntryPoint(),
  2237. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCSeconds, &JavascriptDate::EntryInfo::GetUTCSeconds, 0));
  2238. if (scriptContext->GetConfig()->SupportsES3Extensions())
  2239. {
  2240. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetVarDate.GetOriginalEntryPoint(),
  2241. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getVarDate, &JavascriptDate::EntryInfo::GetVarDate, 0));
  2242. }
  2243. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetYear.GetOriginalEntryPoint(),
  2244. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getYear, &JavascriptDate::EntryInfo::GetYear, 0));
  2245. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetDate.GetOriginalEntryPoint(),
  2246. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setDate, &JavascriptDate::EntryInfo::SetDate, 1));
  2247. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetFullYear.GetOriginalEntryPoint(),
  2248. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setFullYear, &JavascriptDate::EntryInfo::SetFullYear, 3));
  2249. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetHours.GetOriginalEntryPoint(),
  2250. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setHours, &JavascriptDate::EntryInfo::SetHours, 4));
  2251. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetMilliseconds.GetOriginalEntryPoint(),
  2252. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setMilliseconds, &JavascriptDate::EntryInfo::SetMilliseconds, 1));
  2253. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetMinutes.GetOriginalEntryPoint(),
  2254. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setMinutes, &JavascriptDate::EntryInfo::SetMinutes, 3));
  2255. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetMonth.GetOriginalEntryPoint(),
  2256. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setMonth, &JavascriptDate::EntryInfo::SetMonth, 2));
  2257. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetSeconds.GetOriginalEntryPoint(),
  2258. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setSeconds, &JavascriptDate::EntryInfo::SetSeconds, 2));
  2259. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetTime.GetOriginalEntryPoint(),
  2260. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setTime, &JavascriptDate::EntryInfo::SetTime, 1));
  2261. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCDate.GetOriginalEntryPoint(),
  2262. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCDate, &JavascriptDate::EntryInfo::SetUTCDate, 1));
  2263. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCFullYear.GetOriginalEntryPoint(),
  2264. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCFullYear, &JavascriptDate::EntryInfo::SetUTCFullYear, 3));
  2265. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCHours.GetOriginalEntryPoint(),
  2266. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCHours, &JavascriptDate::EntryInfo::SetUTCHours, 4));
  2267. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCMilliseconds.GetOriginalEntryPoint(),
  2268. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCMilliseconds, &JavascriptDate::EntryInfo::SetUTCMilliseconds, 1));
  2269. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCMinutes.GetOriginalEntryPoint(),
  2270. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCMinutes, &JavascriptDate::EntryInfo::SetUTCMinutes, 3));
  2271. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCMonth.GetOriginalEntryPoint(),
  2272. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCMonth, &JavascriptDate::EntryInfo::SetUTCMonth, 2));
  2273. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCSeconds.GetOriginalEntryPoint(),
  2274. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCSeconds, &JavascriptDate::EntryInfo::SetUTCSeconds, 2));
  2275. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetYear.GetOriginalEntryPoint(),
  2276. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setYear, &JavascriptDate::EntryInfo::SetYear, 1));
  2277. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToDateString.GetOriginalEntryPoint(),
  2278. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toDateString, &JavascriptDate::EntryInfo::ToDateString, 0));
  2279. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToISOString.GetOriginalEntryPoint(),
  2280. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toISOString, &JavascriptDate::EntryInfo::ToISOString, 0));
  2281. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToJSON.GetOriginalEntryPoint(),
  2282. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toJSON, &JavascriptDate::EntryInfo::ToJSON, 1));
  2283. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToLocaleDateString.GetOriginalEntryPoint(),
  2284. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toLocaleDateString, &JavascriptDate::EntryInfo::ToLocaleDateString, 0));
  2285. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToLocaleString.GetOriginalEntryPoint(),
  2286. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toLocaleString, &JavascriptDate::EntryInfo::ToLocaleString, 0));
  2287. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToLocaleTimeString.GetOriginalEntryPoint(),
  2288. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toLocaleTimeString, &JavascriptDate::EntryInfo::ToLocaleTimeString, 0));
  2289. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToString.GetOriginalEntryPoint(),
  2290. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toString, &JavascriptDate::EntryInfo::ToString, 0));
  2291. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToTimeString.GetOriginalEntryPoint(),
  2292. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toTimeString, &JavascriptDate::EntryInfo::ToTimeString, 0));
  2293. // Spec stipulates toGMTString must be the same function object as toUTCString
  2294. JavascriptFunction *toUTCStringFunc = library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toUTCString, &JavascriptDate::EntryInfo::ToUTCString, 0);
  2295. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToUTCString.GetOriginalEntryPoint(), toUTCStringFunc);
  2296. library->AddMember(datePrototype, PropertyIds::toGMTString, toUTCStringFunc, PropertyBuiltInMethodDefaults);
  2297. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  2298. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::valueOf, &JavascriptDate::EntryInfo::ValueOf, 0));
  2299. if (scriptContext->GetConfig()->IsES6ToPrimitiveEnabled())
  2300. {
  2301. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SymbolToPrimitive.GetOriginalEntryPoint(),
  2302. library->AddFunctionToLibraryObjectWithName(datePrototype, PropertyIds::_symbolToPrimitive, PropertyIds::_RuntimeFunctionNameId_toPrimitive,
  2303. &JavascriptDate::EntryInfo::SymbolToPrimitive, 1));
  2304. datePrototype->SetWritable(PropertyIds::_symbolToPrimitive, false);
  2305. }
  2306. datePrototype->SetHasNoEnumerableProperties(true);
  2307. return true;
  2308. }
  2309. bool JavascriptLibrary::InitializeFunctionConstructor(DynamicObject* functionConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2310. {
  2311. typeHandler->Convert(functionConstructor, mode, 3);
  2312. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterFunction
  2313. // so that the update is in sync with profiler
  2314. ScriptContext* scriptContext = functionConstructor->GetScriptContext();
  2315. JavascriptLibrary* library = functionConstructor->GetLibrary();
  2316. library->AddMember(functionConstructor, PropertyIds::prototype, library->functionPrototype, PropertyNone);
  2317. library->AddMember(functionConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  2318. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2319. {
  2320. library->AddMember(functionConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Function), PropertyConfigurable);
  2321. }
  2322. functionConstructor->SetHasNoEnumerableProperties(true);
  2323. #ifdef ALLOW_JIT_REPRO
  2324. if (CONFIG_FLAG(JitRepro))
  2325. {
  2326. library->AddFunctionToLibraryObject(functionConstructor, PropertyIds::invokeJit, &JavascriptFunction::EntryInfo::InvokeJit, 1);
  2327. }
  2328. #endif
  2329. return true;
  2330. }
  2331. bool JavascriptLibrary::InitializeFunctionPrototype(DynamicObject* functionPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2332. {
  2333. typeHandler->Convert(functionPrototype, mode, 7);
  2334. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterFunction
  2335. // so that the update is in sync with profiler
  2336. ScriptContext* scriptContext = functionPrototype->GetScriptContext();
  2337. JavascriptLibrary* library = functionPrototype->GetLibrary();
  2338. Field(JavascriptFunction*)* builtinFuncs = library->GetBuiltinFunctions();
  2339. library->AddMember(functionPrototype, PropertyIds::constructor, library->functionConstructor);
  2340. library->AddMember(functionPrototype, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable);
  2341. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2342. {
  2343. library->AddMember(functionPrototype, PropertyIds::name, LiteralString::CreateEmptyString(scriptContext->GetLibrary()->GetStringTypeStatic()), PropertyConfigurable);
  2344. }
  2345. JavascriptFunction *func = library->AddFunctionToLibraryObject(functionPrototype, PropertyIds::apply, &JavascriptFunction::EntryInfo::Apply, 2);
  2346. builtinFuncs[BuiltinFunction::JavascriptFunction_Apply] = func;
  2347. library->AddFunctionToLibraryObject(functionPrototype, PropertyIds::bind, &JavascriptFunction::EntryInfo::Bind, 1);
  2348. func = library->AddFunctionToLibraryObject(functionPrototype, PropertyIds::call, &JavascriptFunction::EntryInfo::Call, 1);
  2349. builtinFuncs[BuiltinFunction::JavascriptFunction_Call] = func;
  2350. library->AddFunctionToLibraryObject(functionPrototype, PropertyIds::toString, &JavascriptFunction::EntryInfo::ToString, 0);
  2351. if (scriptContext->GetConfig()->IsES6HasInstanceEnabled())
  2352. {
  2353. scriptContext->SetBuiltInLibraryFunction(JavascriptFunction::EntryInfo::SymbolHasInstance.GetOriginalEntryPoint(),
  2354. library->AddFunctionToLibraryObjectWithName(functionPrototype, PropertyIds::_symbolHasInstance, PropertyIds::_RuntimeFunctionNameId_hasInstance,
  2355. &JavascriptFunction::EntryInfo::SymbolHasInstance, 1));
  2356. functionPrototype->SetWritable(PropertyIds::_symbolHasInstance, false);
  2357. functionPrototype->SetConfigurable(PropertyIds::_symbolHasInstance, false);
  2358. }
  2359. functionPrototype->DynamicObject::SetAccessors(PropertyIds::caller, library->throwTypeErrorRestrictedPropertyAccessorFunction, library->throwTypeErrorRestrictedPropertyAccessorFunction);
  2360. functionPrototype->SetEnumerable(PropertyIds::caller, false);
  2361. functionPrototype->DynamicObject::SetAccessors(PropertyIds::arguments, library->throwTypeErrorRestrictedPropertyAccessorFunction, library->throwTypeErrorRestrictedPropertyAccessorFunction);
  2362. functionPrototype->SetEnumerable(PropertyIds::arguments, false);
  2363. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  2364. functionPrototype->SetHasNoEnumerableProperties(true);
  2365. return true;
  2366. }
  2367. void JavascriptLibrary::InitializeComplexThings()
  2368. {
  2369. emptyRegexPattern = RegexHelper::CompileDynamic(scriptContext, _u(""), 0, _u(""), 0, false);
  2370. Recycler *const recycler = GetRecycler();
  2371. const ScriptConfiguration *scriptConfig = scriptContext->GetConfig();
  2372. // Creating the regex prototype object requires compiling an empty regex, which may require error types to be
  2373. // initialized first (such as when a stack probe fails). So, the regex prototype and other things that depend on it are
  2374. // initialized here, which will be after the dependency types are initialized.
  2375. //
  2376. // In ES6, RegExp.prototype is not a RegExp object itself so we do not need to wait and create an empty RegExp.
  2377. // Instead, we just create an ordinary object prototype for RegExp.prototype in InitializePrototypes.
  2378. if (!scriptConfig->IsES6PrototypeChain() && regexPrototype == nullptr)
  2379. {
  2380. regexPrototype = RecyclerNew(recycler, JavascriptRegExp, emptyRegexPattern,
  2381. DynamicType::New(scriptContext, TypeIds_RegEx, objectPrototype, nullptr,
  2382. DeferredTypeHandler<InitializeRegexPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
  2383. }
  2384. SimplePathTypeHandlerNoAttr *typeHandler =
  2385. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true);
  2386. // See JavascriptRegExp::IsWritable for property writability
  2387. if (!scriptConfig->IsES6RegExPrototypePropertiesEnabled())
  2388. {
  2389. typeHandler->ClearHasOnlyWritableDataProperties();
  2390. }
  2391. regexType = DynamicType::New(scriptContext, TypeIds_RegEx, regexPrototype, nullptr, typeHandler, true, true);
  2392. }
  2393. bool JavascriptLibrary::InitializeMathObject(DynamicObject* mathObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2394. {
  2395. typeHandler->Convert(mathObject, mode, 42);
  2396. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterMath
  2397. // so that the update is in sync with profiler
  2398. ScriptContext* scriptContext = mathObject->GetScriptContext();
  2399. JavascriptLibrary* library = mathObject->GetLibrary();
  2400. library->AddMember(mathObject, PropertyIds::E, JavascriptNumber::New(Math::E, scriptContext), PropertyNone);
  2401. library->AddMember(mathObject, PropertyIds::LN10, JavascriptNumber::New(Math::LN10, scriptContext), PropertyNone);
  2402. library->AddMember(mathObject, PropertyIds::LN2, JavascriptNumber::New(Math::LN2, scriptContext), PropertyNone);
  2403. library->AddMember(mathObject, PropertyIds::LOG2E, JavascriptNumber::New(Math::LOG2E, scriptContext), PropertyNone);
  2404. library->AddMember(mathObject, PropertyIds::LOG10E, JavascriptNumber::New(Math::LOG10E, scriptContext), PropertyNone);
  2405. library->AddMember(mathObject, PropertyIds::PI, library->pi, PropertyNone);
  2406. library->AddMember(mathObject, PropertyIds::SQRT1_2, JavascriptNumber::New(Math::SQRT1_2, scriptContext), PropertyNone);
  2407. library->AddMember(mathObject, PropertyIds::SQRT2, JavascriptNumber::New(Math::SQRT2, scriptContext), PropertyNone);
  2408. Field(JavascriptFunction*)* builtinFuncs = library->GetBuiltinFunctions();
  2409. builtinFuncs[BuiltinFunction::Math_Abs] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::abs, &Math::EntryInfo::Abs, 1);
  2410. builtinFuncs[BuiltinFunction::Math_Acos] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::acos, &Math::EntryInfo::Acos, 1);
  2411. builtinFuncs[BuiltinFunction::Math_Asin] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::asin, &Math::EntryInfo::Asin, 1);
  2412. builtinFuncs[BuiltinFunction::Math_Atan] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::atan, &Math::EntryInfo::Atan, 1);
  2413. builtinFuncs[BuiltinFunction::Math_Atan2] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::atan2, &Math::EntryInfo::Atan2, 2);
  2414. builtinFuncs[BuiltinFunction::Math_Cos] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::cos, &Math::EntryInfo::Cos, 1);
  2415. builtinFuncs[BuiltinFunction::Math_Ceil] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::ceil, &Math::EntryInfo::Ceil, 1);
  2416. builtinFuncs[BuiltinFunction::Math_Exp] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::exp, &Math::EntryInfo::Exp, 1);
  2417. builtinFuncs[BuiltinFunction::Math_Floor] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::floor, &Math::EntryInfo::Floor, 1);
  2418. builtinFuncs[BuiltinFunction::Math_Log] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::log, &Math::EntryInfo::Log, 1);
  2419. builtinFuncs[BuiltinFunction::Math_Max] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::max, &Math::EntryInfo::Max, 2);
  2420. builtinFuncs[BuiltinFunction::Math_Min] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::min, &Math::EntryInfo::Min, 2);
  2421. builtinFuncs[BuiltinFunction::Math_Pow] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::pow, &Math::EntryInfo::Pow, 2);
  2422. builtinFuncs[BuiltinFunction::Math_Random] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::random, &Math::EntryInfo::Random, 0);
  2423. builtinFuncs[BuiltinFunction::Math_Round] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::round, &Math::EntryInfo::Round, 1);
  2424. builtinFuncs[BuiltinFunction::Math_Sin] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::sin, &Math::EntryInfo::Sin, 1);
  2425. builtinFuncs[BuiltinFunction::Math_Sqrt] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::sqrt, &Math::EntryInfo::Sqrt, 1);
  2426. builtinFuncs[BuiltinFunction::Math_Tan] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::tan, &Math::EntryInfo::Tan, 1);
  2427. if (scriptContext->GetConfig()->IsES6MathExtensionsEnabled())
  2428. {
  2429. builtinFuncs[BuiltinFunction::Math_Imul] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::imul, &Math::EntryInfo::Imul, 2);
  2430. builtinFuncs[BuiltinFunction::Math_Fround] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::fround, &Math::EntryInfo::Fround, 1);
  2431. /*builtinFuncs[BuiltinFunction::Math_Log10] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::log10, &Math::EntryInfo::Log10, 1);
  2432. /*builtinFuncs[BuiltinFunction::Math_Log2] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::log2, &Math::EntryInfo::Log2, 1);
  2433. /*builtinFuncs[BuiltinFunction::Math_Log1p] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::log1p, &Math::EntryInfo::Log1p, 1);
  2434. /*builtinFuncs[BuiltinFunction::Math_Expm1] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::expm1, &Math::EntryInfo::Expm1, 1);
  2435. /*builtinFuncs[BuiltinFunction::Math_Cosh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::cosh, &Math::EntryInfo::Cosh, 1);
  2436. /*builtinFuncs[BuiltinFunction::Math_Sinh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::sinh, &Math::EntryInfo::Sinh, 1);
  2437. /*builtinFuncs[BuiltinFunction::Math_Tanh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::tanh, &Math::EntryInfo::Tanh, 1);
  2438. /*builtinFuncs[BuiltinFunction::Math_Acosh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::acosh, &Math::EntryInfo::Acosh, 1);
  2439. /*builtinFuncs[BuiltinFunction::Math_Asinh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::asinh, &Math::EntryInfo::Asinh, 1);
  2440. /*builtinFuncs[BuiltinFunction::Math_Atanh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::atanh, &Math::EntryInfo::Atanh, 1);
  2441. /*builtinFuncs[BuiltinFunction::Math_Hypot] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::hypot, &Math::EntryInfo::Hypot, 2);
  2442. /*builtinFuncs[BuiltinFunction::Math_Trunc] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::trunc, &Math::EntryInfo::Trunc, 1);
  2443. /*builtinFuncs[BuiltinFunction::Math_Sign] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::sign, &Math::EntryInfo::Sign, 1);
  2444. /*builtinFuncs[BuiltinFunction::Math_Cbrt] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::cbrt, &Math::EntryInfo::Cbrt, 1);
  2445. /*builtinFuncs[BuiltinFunction::Math_Clz32] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::clz32, &Math::EntryInfo::Clz32, 1);
  2446. }
  2447. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  2448. {
  2449. library->AddMember(mathObject, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("Math")), PropertyConfigurable);
  2450. }
  2451. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  2452. mathObject->SetHasNoEnumerableProperties(true);
  2453. return true;
  2454. }
  2455. #ifdef ENABLE_WASM
  2456. bool JavascriptLibrary::InitializeWebAssemblyTablePrototype(DynamicObject* prototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2457. {
  2458. typeHandler->Convert(prototype, mode, 6);
  2459. JavascriptLibrary* library = prototype->GetLibrary();
  2460. ScriptContext* scriptContext = prototype->GetScriptContext();
  2461. library->AddMember(prototype, PropertyIds::constructor, library->webAssemblyTableConstructor);
  2462. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  2463. {
  2464. library->AddMember(prototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("WebAssembly.Table")), PropertyConfigurable);
  2465. }
  2466. scriptContext->SetBuiltInLibraryFunction(WebAssemblyTable::EntryInfo::Grow.GetOriginalEntryPoint(),
  2467. library->AddFunctionToLibraryObject(prototype, PropertyIds::grow, &WebAssemblyTable::EntryInfo::Grow, 1));
  2468. scriptContext->SetBuiltInLibraryFunction(WebAssemblyTable::EntryInfo::Get.GetOriginalEntryPoint(),
  2469. library->AddFunctionToLibraryObject(prototype, PropertyIds::get, &WebAssemblyTable::EntryInfo::Get, 1));
  2470. scriptContext->SetBuiltInLibraryFunction(WebAssemblyTable::EntryInfo::Set.GetOriginalEntryPoint(),
  2471. library->AddFunctionToLibraryObject(prototype, PropertyIds::set, &WebAssemblyTable::EntryInfo::Set, 2));
  2472. library->AddAccessorsToLibraryObject(prototype, PropertyIds::length, &WebAssemblyTable::EntryInfo::GetterLength, nullptr);
  2473. prototype->SetHasNoEnumerableProperties(true);
  2474. return true;
  2475. }
  2476. bool JavascriptLibrary::InitializeWebAssemblyTableConstructor(DynamicObject* constructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2477. {
  2478. typeHandler->Convert(constructor, mode, 3);
  2479. JavascriptLibrary* library = constructor->GetLibrary();
  2480. ScriptContext* scriptContext = constructor->GetScriptContext();
  2481. library->AddMember(constructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  2482. library->AddMember(constructor, PropertyIds::prototype, library->webAssemblyTablePrototype, PropertyNone);
  2483. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2484. {
  2485. library->AddMember(constructor, PropertyIds::name, library->CreateStringFromCppLiteral(_u("Table")), PropertyConfigurable);
  2486. }
  2487. constructor->SetHasNoEnumerableProperties(true);
  2488. return true;
  2489. }
  2490. bool JavascriptLibrary::InitializeWebAssemblyMemoryPrototype(DynamicObject* prototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2491. {
  2492. typeHandler->Convert(prototype, mode, 4);
  2493. JavascriptLibrary* library = prototype->GetLibrary();
  2494. ScriptContext* scriptContext = prototype->GetScriptContext();
  2495. library->AddMember(prototype, PropertyIds::constructor, library->webAssemblyMemoryConstructor);
  2496. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  2497. {
  2498. library->AddMember(prototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("WebAssembly.Memory")), PropertyConfigurable);
  2499. }
  2500. scriptContext->SetBuiltInLibraryFunction(WebAssemblyMemory::EntryInfo::Grow.GetOriginalEntryPoint(),
  2501. library->AddFunctionToLibraryObject(prototype, PropertyIds::grow, &WebAssemblyMemory::EntryInfo::Grow, 1));
  2502. library->AddAccessorsToLibraryObject(prototype, PropertyIds::buffer, &WebAssemblyMemory::EntryInfo::GetterBuffer, nullptr);
  2503. prototype->SetHasNoEnumerableProperties(true);
  2504. return true;
  2505. }
  2506. bool JavascriptLibrary::InitializeWebAssemblyMemoryConstructor(DynamicObject* constructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2507. {
  2508. typeHandler->Convert(constructor, mode, 3);
  2509. JavascriptLibrary* library = constructor->GetLibrary();
  2510. ScriptContext* scriptContext = constructor->GetScriptContext();
  2511. library->AddMember(constructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  2512. library->AddMember(constructor, PropertyIds::prototype, library->webAssemblyMemoryPrototype, PropertyNone);
  2513. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2514. {
  2515. library->AddMember(constructor, PropertyIds::name, library->CreateStringFromCppLiteral(_u("Memory")), PropertyConfigurable);
  2516. }
  2517. constructor->SetHasNoEnumerableProperties(true);
  2518. return true;
  2519. }
  2520. bool JavascriptLibrary::InitializeWebAssemblyInstancePrototype(DynamicObject* prototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2521. {
  2522. typeHandler->Convert(prototype, mode, 3);
  2523. JavascriptLibrary* library = prototype->GetLibrary();
  2524. ScriptContext* scriptContext = prototype->GetScriptContext();
  2525. library->AddMember(prototype, PropertyIds::constructor, library->webAssemblyInstanceConstructor);
  2526. library->AddAccessorsToLibraryObject(prototype, PropertyIds::exports, &WebAssemblyInstance::EntryInfo::GetterExports, nullptr);
  2527. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  2528. {
  2529. library->AddMember(prototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("WebAssembly.Instance")), PropertyConfigurable);
  2530. }
  2531. prototype->SetHasNoEnumerableProperties(true);
  2532. return true;
  2533. }
  2534. bool JavascriptLibrary::InitializeWebAssemblyInstanceConstructor(DynamicObject* constructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2535. {
  2536. typeHandler->Convert(constructor, mode, 3);
  2537. JavascriptLibrary* library = constructor->GetLibrary();
  2538. ScriptContext* scriptContext = constructor->GetScriptContext();
  2539. library->AddMember(constructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  2540. library->AddMember(constructor, PropertyIds::prototype, library->webAssemblyInstancePrototype, PropertyNone);
  2541. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2542. {
  2543. library->AddMember(constructor, PropertyIds::name, library->CreateStringFromCppLiteral(_u("Instance")), PropertyConfigurable);
  2544. }
  2545. constructor->SetHasNoEnumerableProperties(true);
  2546. return true;
  2547. }
  2548. bool JavascriptLibrary::InitializeWebAssemblyModulePrototype(DynamicObject* prototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2549. {
  2550. typeHandler->Convert(prototype, mode, 2);
  2551. JavascriptLibrary* library = prototype->GetLibrary();
  2552. ScriptContext* scriptContext = prototype->GetScriptContext();
  2553. library->AddMember(prototype, PropertyIds::constructor, library->webAssemblyModuleConstructor);
  2554. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  2555. {
  2556. library->AddMember(prototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("WebAssembly.Module")), PropertyConfigurable);
  2557. }
  2558. prototype->SetHasNoEnumerableProperties(true);
  2559. return true;
  2560. }
  2561. bool JavascriptLibrary::InitializeWebAssemblyModuleConstructor(DynamicObject* constructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2562. {
  2563. typeHandler->Convert(constructor, mode, 5);
  2564. JavascriptLibrary* library = constructor->GetLibrary();
  2565. ScriptContext* scriptContext = constructor->GetScriptContext();
  2566. library->AddMember(constructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  2567. library->AddMember(constructor, PropertyIds::prototype, library->webAssemblyModulePrototype, PropertyNone);
  2568. library->AddFunctionToLibraryObject(constructor, PropertyIds::exports, &WebAssemblyModule::EntryInfo::Exports, 1);
  2569. library->AddFunctionToLibraryObject(constructor, PropertyIds::imports, &WebAssemblyModule::EntryInfo::Imports, 1);
  2570. library->AddFunctionToLibraryObject(constructor, PropertyIds::customSections, &WebAssemblyModule::EntryInfo::CustomSections, 2);
  2571. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2572. {
  2573. library->AddMember(constructor, PropertyIds::name, library->CreateStringFromCppLiteral(_u("Module")), PropertyConfigurable);
  2574. }
  2575. constructor->SetHasNoEnumerableProperties(true);
  2576. return true;
  2577. }
  2578. bool JavascriptLibrary::InitializeWebAssemblyObject(DynamicObject* webAssemblyObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2579. {
  2580. JavascriptLibrary* library = webAssemblyObject->GetLibrary();
  2581. int slots = 9;
  2582. #ifdef ENABLE_WABT
  2583. // Attaching wabt for testing
  2584. ++slots;
  2585. #endif
  2586. typeHandler->Convert(webAssemblyObject, mode, slots);
  2587. #ifdef ENABLE_WABT
  2588. // Build wabt object
  2589. Js::DynamicObject* wabtObject = library->CreateObject(true);
  2590. library->AddFunctionToLibraryObject(wabtObject, PropertyIds::convertWast2Wasm, &WabtInterface::EntryInfo::ConvertWast2Wasm, 1);
  2591. library->AddMember(webAssemblyObject, PropertyIds::wabt, wabtObject, PropertyNone);
  2592. #endif
  2593. library->webAssemblyCompileFunction =
  2594. library->AddFunctionToLibraryObject(webAssemblyObject, PropertyIds::compile, &WebAssembly::EntryInfo::Compile, 1);
  2595. library->AddFunctionToLibraryObject(webAssemblyObject, PropertyIds::compileStreaming, &WebAssembly::EntryInfo::CompileStreaming, 1);
  2596. library->AddFunctionToLibraryObject(webAssemblyObject, PropertyIds::validate, &WebAssembly::EntryInfo::Validate, 1);
  2597. library->AddFunctionToLibraryObject(webAssemblyObject, PropertyIds::instantiate, &WebAssembly::EntryInfo::Instantiate, 1);
  2598. library->AddFunctionToLibraryObject(webAssemblyObject, PropertyIds::instantiateStreaming, &WebAssembly::EntryInfo::InstantiateStreaming, 1);
  2599. library->webAssemblyQueryResponseFunction = library->DefaultCreateFunction(&WebAssembly::EntryInfo::QueryResponse, 1, nullptr, nullptr, PropertyIds::undefined);
  2600. library->webAssemblyInstantiateBoundFunction = library->DefaultCreateFunction(&WebAssembly::EntryInfo::InstantiateBound, 1, nullptr, nullptr, PropertyIds::undefined);
  2601. library->AddFunction(webAssemblyObject, PropertyIds::Module, library->webAssemblyModuleConstructor);
  2602. library->AddFunction(webAssemblyObject, PropertyIds::Instance, library->webAssemblyInstanceConstructor);
  2603. library->AddFunction(webAssemblyObject, PropertyIds::CompileError, library->webAssemblyCompileErrorConstructor);
  2604. library->AddFunction(webAssemblyObject, PropertyIds::RuntimeError, library->webAssemblyRuntimeErrorConstructor);
  2605. library->AddFunction(webAssemblyObject, PropertyIds::LinkError, library->webAssemblyLinkErrorConstructor);
  2606. library->AddFunction(webAssemblyObject, PropertyIds::Memory, library->webAssemblyMemoryConstructor);
  2607. library->AddFunction(webAssemblyObject, PropertyIds::Table, library->webAssemblyTableConstructor);
  2608. ScriptContext* scriptContext = webAssemblyObject->GetScriptContext();
  2609. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2610. {
  2611. library->AddMember(webAssemblyObject, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("WebAssembly")), PropertyConfigurable);
  2612. }
  2613. return true;
  2614. }
  2615. #endif
  2616. // SIMD_JS
  2617. #ifdef ENABLE_SIMDJS
  2618. bool JavascriptLibrary::InitializeSIMDObject(DynamicObject* simdObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2619. {
  2620. // Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSIMD so that the update is in sync with profiler
  2621. typeHandler->Convert(simdObject, mode, 2);
  2622. JavascriptLibrary* library = simdObject->GetLibrary();
  2623. // only functions to be inlined to be added to builtinFuncs
  2624. Field(JavascriptFunction*)* builtinFuncs = library->GetBuiltinFunctions();
  2625. /*** Float32x4 ***/
  2626. JavascriptFunction* float32x4Function = library->AddFunctionToLibraryObjectWithPrototype(simdObject, PropertyIds::Float32x4, &SIMDFloat32x4Lib::EntryInfo::Float32x4, 5, library->simdFloat32x4Prototype, nullptr);
  2627. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Float32x4] = float32x4Function;
  2628. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Check] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::check, &SIMDFloat32x4Lib::EntryInfo::Check, 2);
  2629. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Splat] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::splat, &SIMDFloat32x4Lib::EntryInfo::Splat, 2);
  2630. // Lane Access
  2631. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_ExtractLane] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::extractLane, &SIMDFloat32x4Lib::EntryInfo::ExtractLane, 3);
  2632. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_ReplaceLane] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::replaceLane, &SIMDFloat32x4Lib::EntryInfo::ReplaceLane, 4);
  2633. // type conversions
  2634. #if 0
  2635. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromFloat64x2, &SIMDFloat32x4Lib::EntryInfo::FromFloat64x2, 2);
  2636. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromFloat64x2Bits, &SIMDFloat32x4Lib::EntryInfo::FromFloat64x2Bits, 2);
  2637. #endif
  2638. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_FromInt32x4] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromInt32x4, &SIMDFloat32x4Lib::EntryInfo::FromInt32x4, 2);
  2639. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromUint32x4, &SIMDFloat32x4Lib::EntryInfo::FromUint32x4, 2);
  2640. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromInt16x8Bits, &SIMDFloat32x4Lib::EntryInfo::FromInt16x8Bits, 2);
  2641. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromInt8x16Bits, &SIMDFloat32x4Lib::EntryInfo::FromInt8x16Bits, 2);
  2642. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_FromInt32x4Bits] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromInt32x4Bits, &SIMDFloat32x4Lib::EntryInfo::FromInt32x4Bits, 2);
  2643. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromUint32x4Bits, &SIMDFloat32x4Lib::EntryInfo::FromUint32x4Bits, 2);
  2644. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromUint16x8Bits, &SIMDFloat32x4Lib::EntryInfo::FromUint16x8Bits, 2);
  2645. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromUint8x16Bits, &SIMDFloat32x4Lib::EntryInfo::FromUint8x16Bits, 2);
  2646. // binary ops
  2647. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Add] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::add, &SIMDFloat32x4Lib::EntryInfo::Add, 3);
  2648. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Sub] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::sub, &SIMDFloat32x4Lib::EntryInfo::Sub, 3);
  2649. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Mul] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::mul, &SIMDFloat32x4Lib::EntryInfo::Mul, 3);
  2650. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Div] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::div, &SIMDFloat32x4Lib::EntryInfo::Div, 3);
  2651. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Min] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::min, &SIMDFloat32x4Lib::EntryInfo::Min, 3);
  2652. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Max] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::max, &SIMDFloat32x4Lib::EntryInfo::Max, 3);
  2653. // unary ops
  2654. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Abs] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::abs, &SIMDFloat32x4Lib::EntryInfo::Abs, 2);
  2655. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Neg] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::neg, &SIMDFloat32x4Lib::EntryInfo::Neg, 2);
  2656. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Sqrt] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::sqrt, &SIMDFloat32x4Lib::EntryInfo::Sqrt, 2);
  2657. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Reciprocal] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::reciprocalApproximation, &SIMDFloat32x4Lib::EntryInfo::Reciprocal, 2);
  2658. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_ReciprocalSqrt] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::reciprocalSqrtApproximation, &SIMDFloat32x4Lib::EntryInfo::ReciprocalSqrt, 2);
  2659. // compare ops
  2660. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::lessThan, &SIMDFloat32x4Lib::EntryInfo::LessThan, 3);
  2661. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::lessThanOrEqual, &SIMDFloat32x4Lib::EntryInfo::LessThanOrEqual, 3);
  2662. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::equal, &SIMDFloat32x4Lib::EntryInfo::Equal, 3);
  2663. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::notEqual, &SIMDFloat32x4Lib::EntryInfo::NotEqual, 3);
  2664. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::greaterThan, &SIMDFloat32x4Lib::EntryInfo::GreaterThan, 3);
  2665. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::greaterThanOrEqual, &SIMDFloat32x4Lib::EntryInfo::GreaterThanOrEqual,3);
  2666. // others
  2667. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Swizzle] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::swizzle, &SIMDFloat32x4Lib::EntryInfo::Swizzle, 6);
  2668. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Shuffle] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::shuffle, &SIMDFloat32x4Lib::EntryInfo::Shuffle, 7);
  2669. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::select, &SIMDFloat32x4Lib::EntryInfo::Select, 4);
  2670. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Load] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::load, &SIMDFloat32x4Lib::EntryInfo::Load, 3);
  2671. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Load1] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::load1, &SIMDFloat32x4Lib::EntryInfo::Load1, 3);
  2672. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Load2] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::load2, &SIMDFloat32x4Lib::EntryInfo::Load2, 3);
  2673. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Load3] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::load3, &SIMDFloat32x4Lib::EntryInfo::Load3, 3);
  2674. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Store] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::store, &SIMDFloat32x4Lib::EntryInfo::Store, 4);
  2675. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Store1] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::store1, &SIMDFloat32x4Lib::EntryInfo::Store1, 4);
  2676. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Store2] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::store2, &SIMDFloat32x4Lib::EntryInfo::Store2, 4);
  2677. builtinFuncs[BuiltinFunction::SIMDFloat32x4Lib_Store3] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::store3, &SIMDFloat32x4Lib::EntryInfo::Store3, 4);
  2678. /*** End Float32x4 ***/
  2679. /*** Float64x2 ***/
  2680. #if 0
  2681. JavascriptFunction* float64x2Function = library->AddFunctionToLibraryObject(simdObject, PropertyIds::Float64x2, &SIMDFloat64x2Lib::EntryInfo::Float64x2, 3);
  2682. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::check, &SIMDFloat64x2Lib::EntryInfo::Check, 2);
  2683. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::splat, &SIMDFloat64x2Lib::EntryInfo::Splat, 2);
  2684. // type conversions
  2685. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::fromFloat32x4, &SIMDFloat64x2Lib::EntryInfo::FromFloat32x4, 2);
  2686. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::fromFloat32x4Bits, &SIMDFloat64x2Lib::EntryInfo::FromFloat32x4Bits, 2);
  2687. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::fromInt32x4, &SIMDFloat64x2Lib::EntryInfo::FromInt32x4, 2);
  2688. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::fromInt32x4Bits, &SIMDFloat64x2Lib::EntryInfo::FromInt32x4Bits, 2);
  2689. // binary ops
  2690. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::add, &SIMDFloat64x2Lib::EntryInfo::Add, 3);
  2691. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::sub, &SIMDFloat64x2Lib::EntryInfo::Sub, 3);
  2692. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::mul, &SIMDFloat64x2Lib::EntryInfo::Mul, 3);
  2693. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::div, &SIMDFloat64x2Lib::EntryInfo::Div, 3);
  2694. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::min, &SIMDFloat64x2Lib::EntryInfo::Min, 3);
  2695. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::max, &SIMDFloat64x2Lib::EntryInfo::Max, 3);
  2696. // unary ops
  2697. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::abs, &SIMDFloat64x2Lib::EntryInfo::Abs, 2);
  2698. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::neg, &SIMDFloat64x2Lib::EntryInfo::Neg, 2);
  2699. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::sqrt, &SIMDFloat64x2Lib::EntryInfo::Sqrt, 2);
  2700. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::reciprocalApproximation, &SIMDFloat64x2Lib::EntryInfo::Reciprocal, 2);
  2701. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::reciprocalSqrtApproximation, &SIMDFloat64x2Lib::EntryInfo::ReciprocalSqrt, 2);
  2702. // compare ops
  2703. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::lessThan, &SIMDFloat64x2Lib::EntryInfo::LessThan, 3);
  2704. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::lessThanOrEqual, &SIMDFloat64x2Lib::EntryInfo::LessThanOrEqual, 3);
  2705. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::equal, &SIMDFloat64x2Lib::EntryInfo::Equal, 3);
  2706. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::notEqual, &SIMDFloat64x2Lib::EntryInfo::NotEqual, 3);
  2707. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::greaterThan, &SIMDFloat64x2Lib::EntryInfo::GreaterThan, 3);
  2708. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::greaterThanOrEqual, &SIMDFloat64x2Lib::EntryInfo::GreaterThanOrEqual, 3);
  2709. // others
  2710. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::swizzle, &SIMDFloat64x2Lib::EntryInfo::Swizzle, 4);
  2711. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::shuffle, &SIMDFloat64x2Lib::EntryInfo::Shuffle, 5);
  2712. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::select, &SIMDFloat64x2Lib::EntryInfo::Select, 4);
  2713. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::load, &SIMDFloat64x2Lib::EntryInfo::Load, 3);
  2714. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::load1, &SIMDFloat64x2Lib::EntryInfo::Load1, 3);
  2715. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::store, &SIMDFloat64x2Lib::EntryInfo::Store, 4);
  2716. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::store1, &SIMDFloat64x2Lib::EntryInfo::Store1, 4);
  2717. #endif
  2718. /*** End Float64x2 ***/
  2719. /*** Int32x4 ***/
  2720. JavascriptFunction* int32x4Function = library->AddFunctionToLibraryObjectWithPrototype(simdObject, PropertyIds::Int32x4, &SIMDInt32x4Lib::EntryInfo::Int32x4, 5, library->simdInt32x4Prototype, nullptr);
  2721. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Int32x4] = int32x4Function;
  2722. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Check] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::check, &SIMDInt32x4Lib::EntryInfo::Check, 2);
  2723. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Splat] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::splat, &SIMDInt32x4Lib::EntryInfo::Splat, 2);
  2724. // Lane Access
  2725. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_ExtractLane] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::extractLane, &SIMDInt32x4Lib::EntryInfo::ExtractLane, 3);
  2726. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_ReplaceLane] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::replaceLane, &SIMDInt32x4Lib::EntryInfo::ReplaceLane, 4);
  2727. // type conversions
  2728. //library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromFloat64x2, &SIMDInt32x4Lib::EntryInfo::FromFloat64x2, 2);
  2729. //library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromFloat64x2Bits, &SIMDInt32x4Lib::EntryInfo::FromFloat64x2Bits, 2);
  2730. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_FromFloat32x4] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromFloat32x4, &SIMDInt32x4Lib::EntryInfo::FromFloat32x4, 2);
  2731. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_FromFloat32x4Bits] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromFloat32x4Bits, &SIMDInt32x4Lib::EntryInfo::FromFloat32x4Bits, 2);
  2732. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromUint32x4Bits, &SIMDInt32x4Lib::EntryInfo::FromUint32x4Bits, 2);
  2733. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromUint8x16Bits, &SIMDInt32x4Lib::EntryInfo::FromUint8x16Bits, 2);
  2734. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromUint16x8Bits, &SIMDInt32x4Lib::EntryInfo::FromUint16x8Bits, 2);
  2735. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromInt8x16Bits, &SIMDInt32x4Lib::EntryInfo::FromInt8x16Bits, 2);
  2736. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromInt16x8Bits, &SIMDInt32x4Lib::EntryInfo::FromInt16x8Bits, 2);
  2737. // binary ops
  2738. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Add] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::add, &SIMDInt32x4Lib::EntryInfo::Add, 3);
  2739. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Sub] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::sub, &SIMDInt32x4Lib::EntryInfo::Sub, 3);
  2740. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Mul] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::mul, &SIMDInt32x4Lib::EntryInfo::Mul, 3);
  2741. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_And] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::and_, &SIMDInt32x4Lib::EntryInfo::And, 3);
  2742. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Or] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::or_, &SIMDInt32x4Lib::EntryInfo::Or, 3);
  2743. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Xor] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::xor_, &SIMDInt32x4Lib::EntryInfo::Xor, 3);
  2744. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Neg] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::neg, &SIMDInt32x4Lib::EntryInfo::Neg, 2);
  2745. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Not] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::not_, &SIMDInt32x4Lib::EntryInfo::Not, 2);
  2746. // compare ops
  2747. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::lessThan, &SIMDInt32x4Lib::EntryInfo::LessThan, 3);
  2748. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::lessThanOrEqual, &SIMDInt32x4Lib::EntryInfo::LessThanOrEqual, 3);
  2749. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::equal, &SIMDInt32x4Lib::EntryInfo::Equal, 3);
  2750. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::notEqual, &SIMDInt32x4Lib::EntryInfo::NotEqual, 3);
  2751. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::greaterThan, &SIMDInt32x4Lib::EntryInfo::GreaterThan, 3);
  2752. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::greaterThanOrEqual, &SIMDInt32x4Lib::EntryInfo::GreaterThanOrEqual, 3);
  2753. // shuffle
  2754. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Swizzle] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::swizzle, &SIMDInt32x4Lib::EntryInfo::Swizzle, 6);
  2755. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Shuffle] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::shuffle, &SIMDInt32x4Lib::EntryInfo::Shuffle, 7);
  2756. // shift
  2757. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::shiftLeftByScalar, &SIMDInt32x4Lib::EntryInfo::ShiftLeftByScalar, 3);
  2758. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::shiftRightByScalar, &SIMDInt32x4Lib::EntryInfo::ShiftRightByScalar, 3);
  2759. // select
  2760. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::select, &SIMDInt32x4Lib::EntryInfo::Select, 4);
  2761. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Load] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::load, &SIMDInt32x4Lib::EntryInfo::Load, 3);
  2762. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Load1] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::load1, &SIMDInt32x4Lib::EntryInfo::Load1, 3);
  2763. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Load2] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::load2, &SIMDInt32x4Lib::EntryInfo::Load2, 3);
  2764. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Load3] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::load3, &SIMDInt32x4Lib::EntryInfo::Load3, 3);
  2765. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Store] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::store, &SIMDInt32x4Lib::EntryInfo::Store, 4);
  2766. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Store1] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::store1, &SIMDInt32x4Lib::EntryInfo::Store1, 4);
  2767. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Store2] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::store2, &SIMDInt32x4Lib::EntryInfo::Store2, 4);
  2768. builtinFuncs[BuiltinFunction::SIMDInt32x4Lib_Store3] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::store3, &SIMDInt32x4Lib::EntryInfo::Store3, 4);
  2769. /*** End Int32x4 ***/
  2770. /*** Int16x8 ***/
  2771. JavascriptFunction* int16x8Function = library->AddFunctionToLibraryObjectWithPrototype(simdObject, PropertyIds::Int16x8,
  2772. &SIMDInt16x8Lib::EntryInfo::Int16x8, 9, library->simdInt16x8Prototype, nullptr);
  2773. builtinFuncs[BuiltinFunction::SIMDInt16x8Lib_Int16x8] = int16x8Function;
  2774. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::splat, &SIMDInt16x8Lib::EntryInfo::Splat, 2);
  2775. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::check, &SIMDInt16x8Lib::EntryInfo::Check, 2);
  2776. // type conversions
  2777. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::fromFloat32x4Bits, &SIMDInt16x8Lib::EntryInfo::FromFloat32x4Bits, 2);
  2778. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::fromInt32x4Bits, &SIMDInt16x8Lib::EntryInfo::FromInt32x4Bits, 2);
  2779. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::fromInt8x16Bits, &SIMDInt16x8Lib::EntryInfo::FromInt8x16Bits, 2);
  2780. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::fromUint32x4Bits, &SIMDInt16x8Lib::EntryInfo::FromUint32x4Bits, 2);
  2781. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::fromUint16x8Bits, &SIMDInt16x8Lib::EntryInfo::FromUint16x8Bits, 2);
  2782. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::fromUint8x16Bits, &SIMDInt16x8Lib::EntryInfo::FromUint8x16Bits, 2);
  2783. // UnaryOps
  2784. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::neg, &SIMDInt16x8Lib::EntryInfo::Neg, 2);
  2785. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::not_, &SIMDInt16x8Lib::EntryInfo::Not, 2);
  2786. // binary ops
  2787. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::add, &SIMDInt16x8Lib::EntryInfo::Add, 3);
  2788. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::sub, &SIMDInt16x8Lib::EntryInfo::Sub, 3);
  2789. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::mul, &SIMDInt16x8Lib::EntryInfo::Mul, 3);
  2790. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::and_, &SIMDInt16x8Lib::EntryInfo::And, 3);
  2791. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::or_, &SIMDInt16x8Lib::EntryInfo::Or, 3);
  2792. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::xor_, &SIMDInt16x8Lib::EntryInfo::Xor, 3);
  2793. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::addSaturate, &SIMDInt16x8Lib::EntryInfo::AddSaturate, 3);
  2794. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::subSaturate, &SIMDInt16x8Lib::EntryInfo::SubSaturate, 3);
  2795. // compare ops
  2796. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::lessThan, &SIMDInt16x8Lib::EntryInfo::LessThan, 3);
  2797. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::lessThanOrEqual, &SIMDInt16x8Lib::EntryInfo::LessThanOrEqual, 3);
  2798. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::equal, &SIMDInt16x8Lib::EntryInfo::Equal, 3);
  2799. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::notEqual, &SIMDInt16x8Lib::EntryInfo::NotEqual, 3);
  2800. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::greaterThan, &SIMDInt16x8Lib::EntryInfo::GreaterThan, 3);
  2801. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::greaterThanOrEqual, &SIMDInt16x8Lib::EntryInfo::GreaterThanOrEqual, 3);
  2802. // Lane Access
  2803. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::extractLane, &SIMDInt16x8Lib::EntryInfo::ExtractLane, 3);
  2804. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::replaceLane, &SIMDInt16x8Lib::EntryInfo::ReplaceLane, 3);
  2805. // shift
  2806. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::shiftLeftByScalar, &SIMDInt16x8Lib::EntryInfo::ShiftLeftByScalar, 3);
  2807. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::shiftRightByScalar, &SIMDInt16x8Lib::EntryInfo::ShiftRightByScalar, 3);
  2808. // load/store
  2809. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::load, &SIMDInt16x8Lib::EntryInfo::Load, 3);
  2810. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::store, &SIMDInt16x8Lib::EntryInfo::Store, 4);
  2811. // others
  2812. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::swizzle, &SIMDInt16x8Lib::EntryInfo::Swizzle, 10);
  2813. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::shuffle, &SIMDInt16x8Lib::EntryInfo::Shuffle, 11);
  2814. library->AddFunctionToLibraryObject(int16x8Function, PropertyIds::select, &SIMDInt16x8Lib::EntryInfo::Select, 4);
  2815. /*** End Int16x8 ***/
  2816. /*** Int8x16 ***/
  2817. JavascriptFunction* int8x16Function = library->AddFunctionToLibraryObjectWithPrototype(simdObject, PropertyIds::Int8x16,
  2818. &SIMDInt8x16Lib::EntryInfo::Int8x16, 17, library->simdInt8x16Prototype, nullptr);
  2819. builtinFuncs[BuiltinFunction::SIMDInt8x16Lib_Int8x16] = int8x16Function;
  2820. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::check, &SIMDInt8x16Lib::EntryInfo::Check, 2);
  2821. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::splat, &SIMDInt8x16Lib::EntryInfo::Splat, 2);
  2822. // type conversions
  2823. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::fromFloat32x4Bits, &SIMDInt8x16Lib::EntryInfo::FromFloat32x4Bits, 2);
  2824. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::fromInt32x4Bits, &SIMDInt8x16Lib::EntryInfo::FromInt32x4Bits, 2);
  2825. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::fromInt16x8Bits, &SIMDInt8x16Lib::EntryInfo::FromInt16x8Bits, 2);
  2826. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::fromUint32x4Bits, &SIMDInt8x16Lib::EntryInfo::FromUint32x4Bits, 2);
  2827. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::fromUint16x8Bits, &SIMDInt8x16Lib::EntryInfo::FromUint16x8Bits, 2);
  2828. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::fromUint8x16Bits, &SIMDInt8x16Lib::EntryInfo::FromUint8x16Bits, 2);
  2829. // binary ops
  2830. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::add, &SIMDInt8x16Lib::EntryInfo::Add, 3);
  2831. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::sub, &SIMDInt8x16Lib::EntryInfo::Sub, 3);
  2832. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::mul, &SIMDInt8x16Lib::EntryInfo::Mul, 3);
  2833. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::and_, &SIMDInt8x16Lib::EntryInfo::And, 3);
  2834. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::or_ , &SIMDInt8x16Lib::EntryInfo::Or , 3);
  2835. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::xor_, &SIMDInt8x16Lib::EntryInfo::Xor, 3);
  2836. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::addSaturate, &SIMDInt8x16Lib::EntryInfo::AddSaturate, 3);
  2837. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::subSaturate, &SIMDInt8x16Lib::EntryInfo::SubSaturate, 3);
  2838. // unary ops
  2839. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::neg, &SIMDInt8x16Lib::EntryInfo::Neg, 2);
  2840. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::not_, &SIMDInt8x16Lib::EntryInfo::Not, 2);
  2841. // compare ops
  2842. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::lessThan, &SIMDInt8x16Lib::EntryInfo::LessThan, 3);
  2843. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::lessThanOrEqual, &SIMDInt8x16Lib::EntryInfo::LessThanOrEqual, 3);
  2844. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::equal , &SIMDInt8x16Lib::EntryInfo::Equal , 3);
  2845. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::notEqual , &SIMDInt8x16Lib::EntryInfo::NotEqual , 3);
  2846. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::greaterThan, &SIMDInt8x16Lib::EntryInfo::GreaterThan, 3);
  2847. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::greaterThanOrEqual, &SIMDInt8x16Lib::EntryInfo::GreaterThanOrEqual , 3);
  2848. // shuffle
  2849. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::swizzle, &SIMDInt8x16Lib::EntryInfo::Swizzle, 18);
  2850. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::shuffle, &SIMDInt8x16Lib::EntryInfo::Shuffle, 19);
  2851. // shift
  2852. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::shiftLeftByScalar, &SIMDInt8x16Lib::EntryInfo::ShiftLeftByScalar, 3);
  2853. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::shiftRightByScalar, &SIMDInt8x16Lib::EntryInfo::ShiftRightByScalar, 3);
  2854. // load/store
  2855. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::load, &SIMDInt8x16Lib::EntryInfo::Load, 3);
  2856. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::store, &SIMDInt8x16Lib::EntryInfo::Store, 4);
  2857. // Lane Access
  2858. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::extractLane, &SIMDInt8x16Lib::EntryInfo::ExtractLane, 3);
  2859. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::replaceLane, &SIMDInt8x16Lib::EntryInfo::ReplaceLane, 4);
  2860. // select
  2861. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::select, &SIMDInt8x16Lib::EntryInfo::Select, 4);
  2862. /*** End Int8x16 ***/
  2863. /*** Bool32x4 ***/
  2864. JavascriptFunction* bool32x4Function = library->AddFunctionToLibraryObjectWithPrototype(simdObject, PropertyIds::Bool32x4,
  2865. &SIMDBool32x4Lib::EntryInfo::Bool32x4, 5, library->simdBool32x4Prototype, nullptr);
  2866. builtinFuncs[BuiltinFunction::SIMDBool32x4Lib_Bool32x4] = bool32x4Function;
  2867. library->AddFunctionToLibraryObject(bool32x4Function, PropertyIds::check, &SIMDBool32x4Lib::EntryInfo::Check, 2);
  2868. library->AddFunctionToLibraryObject(bool32x4Function, PropertyIds::splat, &SIMDBool32x4Lib::EntryInfo::Splat, 2);
  2869. // UnaryOps
  2870. library->AddFunctionToLibraryObject(bool32x4Function, PropertyIds::not_, &SIMDBool32x4Lib::EntryInfo::Not, 2);
  2871. library->AddFunctionToLibraryObject(bool32x4Function, PropertyIds::allTrue, &SIMDBool32x4Lib::EntryInfo::AllTrue, 2);
  2872. library->AddFunctionToLibraryObject(bool32x4Function, PropertyIds::anyTrue, &SIMDBool32x4Lib::EntryInfo::AnyTrue, 2);
  2873. // BinaryOps
  2874. library->AddFunctionToLibraryObject(bool32x4Function, PropertyIds::and_, &SIMDBool32x4Lib::EntryInfo::And, 2);
  2875. library->AddFunctionToLibraryObject(bool32x4Function, PropertyIds::or_, &SIMDBool32x4Lib::EntryInfo::Or, 2);
  2876. library->AddFunctionToLibraryObject(bool32x4Function, PropertyIds::xor_, &SIMDBool32x4Lib::EntryInfo::Xor, 2);
  2877. // Lane Access
  2878. library->AddFunctionToLibraryObject(bool32x4Function, PropertyIds::extractLane, &SIMDBool32x4Lib::EntryInfo::ExtractLane, 3);
  2879. library->AddFunctionToLibraryObject(bool32x4Function, PropertyIds::replaceLane, &SIMDBool32x4Lib::EntryInfo::ReplaceLane, 4);
  2880. /*** End Bool32x4 ***/
  2881. /*** Bool16x8 ***/
  2882. JavascriptFunction* bool16x8Function = library->AddFunctionToLibraryObjectWithPrototype(simdObject, PropertyIds::Bool16x8,
  2883. &SIMDBool16x8Lib::EntryInfo::Bool16x8, 9, library->simdBool16x8Prototype, nullptr);
  2884. builtinFuncs[BuiltinFunction::SIMDBool16x8Lib_Bool16x8] = bool16x8Function;
  2885. library->AddFunctionToLibraryObject(bool16x8Function, PropertyIds::check, &SIMDBool16x8Lib::EntryInfo::Check, 2);
  2886. library->AddFunctionToLibraryObject(bool16x8Function, PropertyIds::splat, &SIMDBool16x8Lib::EntryInfo::Splat, 2);
  2887. // UnaryOps
  2888. library->AddFunctionToLibraryObject(bool16x8Function, PropertyIds::not_, &SIMDBool16x8Lib::EntryInfo::Not, 2);
  2889. library->AddFunctionToLibraryObject(bool16x8Function, PropertyIds::allTrue, &SIMDBool16x8Lib::EntryInfo::AllTrue, 2);
  2890. library->AddFunctionToLibraryObject(bool16x8Function, PropertyIds::anyTrue, &SIMDBool16x8Lib::EntryInfo::AnyTrue, 2);
  2891. // BinaryOps
  2892. library->AddFunctionToLibraryObject(bool16x8Function, PropertyIds::and_, &SIMDBool16x8Lib::EntryInfo::And, 2);
  2893. library->AddFunctionToLibraryObject(bool16x8Function, PropertyIds::or_, &SIMDBool16x8Lib::EntryInfo::Or, 2);
  2894. library->AddFunctionToLibraryObject(bool16x8Function, PropertyIds::xor_, &SIMDBool16x8Lib::EntryInfo::Xor, 2);
  2895. // Lane Access
  2896. library->AddFunctionToLibraryObject(bool16x8Function, PropertyIds::extractLane, &SIMDBool16x8Lib::EntryInfo::ExtractLane, 3);
  2897. library->AddFunctionToLibraryObject(bool16x8Function, PropertyIds::replaceLane, &SIMDBool16x8Lib::EntryInfo::ReplaceLane, 4);
  2898. /*** End Bool16x8 ***/
  2899. /*** Bool8x16 ***/
  2900. JavascriptFunction* bool8x16Function = library->AddFunctionToLibraryObjectWithPrototype(simdObject, PropertyIds::Bool8x16,
  2901. &SIMDBool8x16Lib::EntryInfo::Bool8x16, 17, library->simdBool8x16Prototype, nullptr);
  2902. builtinFuncs[BuiltinFunction::SIMDBool8x16Lib_Bool8x16] = bool8x16Function;
  2903. library->AddFunctionToLibraryObject(bool8x16Function, PropertyIds::check, &SIMDBool8x16Lib::EntryInfo::Check, 2);
  2904. library->AddFunctionToLibraryObject(bool8x16Function, PropertyIds::splat, &SIMDBool8x16Lib::EntryInfo::Splat, 2);
  2905. // UnaryOps
  2906. library->AddFunctionToLibraryObject(bool8x16Function, PropertyIds::not_, &SIMDBool8x16Lib::EntryInfo::Not, 2);
  2907. library->AddFunctionToLibraryObject(bool8x16Function, PropertyIds::allTrue, &SIMDBool8x16Lib::EntryInfo::AllTrue, 2);
  2908. library->AddFunctionToLibraryObject(bool8x16Function, PropertyIds::anyTrue, &SIMDBool8x16Lib::EntryInfo::AnyTrue, 2);
  2909. // BinaryOps
  2910. library->AddFunctionToLibraryObject(bool8x16Function, PropertyIds::and_, &SIMDBool8x16Lib::EntryInfo::And, 2);
  2911. library->AddFunctionToLibraryObject(bool8x16Function, PropertyIds::or_, &SIMDBool8x16Lib::EntryInfo::Or, 2);
  2912. library->AddFunctionToLibraryObject(bool8x16Function, PropertyIds::xor_, &SIMDBool8x16Lib::EntryInfo::Xor, 2);
  2913. // Lane Access
  2914. library->AddFunctionToLibraryObject(bool8x16Function, PropertyIds::extractLane, &SIMDBool8x16Lib::EntryInfo::ExtractLane, 3);
  2915. library->AddFunctionToLibraryObject(bool8x16Function, PropertyIds::replaceLane, &SIMDBool8x16Lib::EntryInfo::ReplaceLane, 4);
  2916. /*** End Bool8x16 ***/
  2917. /*** Uint32x4 ***/
  2918. JavascriptFunction* uint32x4Function = library->AddFunctionToLibraryObjectWithPrototype(simdObject, PropertyIds::Uint32x4,
  2919. &SIMDUint32x4Lib::EntryInfo::Uint32x4, 5, library->simdUint32x4Prototype, nullptr);
  2920. builtinFuncs[BuiltinFunction::SIMDUint32x4Lib_Uint32x4] = uint32x4Function;
  2921. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::check, &SIMDUint32x4Lib::EntryInfo::Check, 2);
  2922. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::splat, &SIMDUint32x4Lib::EntryInfo::Splat, 2);
  2923. // Lane Access
  2924. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::extractLane, &SIMDUint32x4Lib::EntryInfo::ExtractLane, 3);
  2925. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::replaceLane, &SIMDUint32x4Lib::EntryInfo::ReplaceLane, 4);
  2926. // type conversions
  2927. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::fromFloat32x4, &SIMDUint32x4Lib::EntryInfo::FromFloat32x4, 2);
  2928. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::fromFloat32x4Bits, &SIMDUint32x4Lib::EntryInfo::FromFloat32x4Bits, 2);
  2929. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::fromInt32x4Bits, &SIMDUint32x4Lib::EntryInfo::FromInt32x4Bits, 2);
  2930. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::fromInt16x8Bits, &SIMDUint32x4Lib::EntryInfo::FromInt16x8Bits, 2);
  2931. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::fromInt8x16Bits, &SIMDUint32x4Lib::EntryInfo::FromInt8x16Bits, 2);
  2932. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::fromUint16x8Bits, &SIMDUint32x4Lib::EntryInfo::FromUint16x8Bits, 2);
  2933. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::fromUint8x16Bits, &SIMDUint32x4Lib::EntryInfo::FromUint8x16Bits, 2);
  2934. // unary ops
  2935. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::not_, &SIMDUint32x4Lib::EntryInfo::Not, 2);
  2936. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::neg, &SIMDUint32x4Lib::EntryInfo::Neg, 2);
  2937. // binary ops
  2938. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::add, &SIMDUint32x4Lib::EntryInfo::Add, 3);
  2939. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::sub, &SIMDUint32x4Lib::EntryInfo::Sub, 3);
  2940. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::mul, &SIMDUint32x4Lib::EntryInfo::Mul, 3);
  2941. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::and_, &SIMDUint32x4Lib::EntryInfo::And, 3);
  2942. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::or_, &SIMDUint32x4Lib::EntryInfo::Or, 3);
  2943. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::xor_, &SIMDUint32x4Lib::EntryInfo::Xor, 3);
  2944. // compare ops
  2945. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::lessThan, &SIMDUint32x4Lib::EntryInfo::LessThan, 3);
  2946. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::lessThanOrEqual, &SIMDUint32x4Lib::EntryInfo::LessThanOrEqual, 3);
  2947. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::equal, &SIMDUint32x4Lib::EntryInfo::Equal, 3);
  2948. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::notEqual, &SIMDUint32x4Lib::EntryInfo::NotEqual, 3);
  2949. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::greaterThan, &SIMDUint32x4Lib::EntryInfo::GreaterThan, 3);
  2950. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::greaterThanOrEqual, &SIMDUint32x4Lib::EntryInfo::GreaterThanOrEqual, 3);
  2951. // others
  2952. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::swizzle, &SIMDUint32x4Lib::EntryInfo::Swizzle, 6);
  2953. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::shuffle, &SIMDUint32x4Lib::EntryInfo::Shuffle, 7);
  2954. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::select, &SIMDUint32x4Lib::EntryInfo::Select, 4);
  2955. // shift
  2956. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::shiftLeftByScalar, &SIMDUint32x4Lib::EntryInfo::ShiftLeftByScalar, 3);
  2957. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::shiftRightByScalar, &SIMDUint32x4Lib::EntryInfo::ShiftRightByScalar, 3);
  2958. // load/store
  2959. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::load, &SIMDUint32x4Lib::EntryInfo::Load, 3);
  2960. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::load1, &SIMDUint32x4Lib::EntryInfo::Load1, 3);
  2961. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::load2, &SIMDUint32x4Lib::EntryInfo::Load2, 3);
  2962. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::load3, &SIMDUint32x4Lib::EntryInfo::Load3, 3);
  2963. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::store, &SIMDUint32x4Lib::EntryInfo::Store, 4);
  2964. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::store1, &SIMDUint32x4Lib::EntryInfo::Store1, 4);
  2965. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::store2, &SIMDUint32x4Lib::EntryInfo::Store2, 4);
  2966. library->AddFunctionToLibraryObject(uint32x4Function, PropertyIds::store3, &SIMDUint32x4Lib::EntryInfo::Store3, 4);
  2967. /*** End Uint32x4 ***/
  2968. /** Uint16x8 **/
  2969. JavascriptFunction* uint16x8Function = library->AddFunctionToLibraryObjectWithPrototype(simdObject, PropertyIds::Uint16x8,
  2970. &SIMDUint16x8Lib::EntryInfo::Uint16x8, 9, library->simdUint16x8Prototype, nullptr);
  2971. builtinFuncs[BuiltinFunction::SIMDUint16x8Lib_Uint16x8] = uint16x8Function;
  2972. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::splat, &SIMDUint16x8Lib::EntryInfo::Splat, 2);
  2973. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::check, &SIMDUint16x8Lib::EntryInfo::Check, 2);
  2974. //// type conversions
  2975. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::fromFloat32x4Bits, &SIMDUint16x8Lib::EntryInfo::FromFloat32x4Bits, 2);
  2976. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::fromInt32x4Bits, &SIMDUint16x8Lib::EntryInfo::FromInt32x4Bits, 2);
  2977. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::fromInt16x8Bits, &SIMDUint16x8Lib::EntryInfo::FromInt16x8Bits, 2);
  2978. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::fromInt8x16Bits, &SIMDUint16x8Lib::EntryInfo::FromInt8x16Bits, 2);
  2979. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::fromUint32x4Bits, &SIMDUint16x8Lib::EntryInfo::FromUint32x4Bits, 2);
  2980. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::fromUint8x16Bits, &SIMDUint16x8Lib::EntryInfo::FromUint8x16Bits, 2);
  2981. //// UnaryOps
  2982. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::not_, &SIMDUint16x8Lib::EntryInfo::Not, 2);
  2983. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::neg, &SIMDUint16x8Lib::EntryInfo::Neg, 2);
  2984. //// binary ops
  2985. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::add, &SIMDUint16x8Lib::EntryInfo::Add, 3);
  2986. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::sub, &SIMDUint16x8Lib::EntryInfo::Sub, 3);
  2987. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::mul, &SIMDUint16x8Lib::EntryInfo::Mul, 3);
  2988. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::and_, &SIMDUint16x8Lib::EntryInfo::And, 3);
  2989. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::or_, &SIMDUint16x8Lib::EntryInfo::Or, 3);
  2990. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::xor_, &SIMDUint16x8Lib::EntryInfo::Xor, 3);
  2991. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::addSaturate, &SIMDUint16x8Lib::EntryInfo::AddSaturate, 3);
  2992. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::subSaturate, &SIMDUint16x8Lib::EntryInfo::SubSaturate, 3);
  2993. //// compare ops
  2994. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::lessThan, &SIMDUint16x8Lib::EntryInfo::LessThan, 3);
  2995. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::lessThanOrEqual, &SIMDUint16x8Lib::EntryInfo::LessThanOrEqual, 3);
  2996. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::equal, &SIMDUint16x8Lib::EntryInfo::Equal, 3);
  2997. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::notEqual, &SIMDUint16x8Lib::EntryInfo::NotEqual, 3);
  2998. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::greaterThan, &SIMDUint16x8Lib::EntryInfo::GreaterThan, 3);
  2999. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::greaterThanOrEqual, &SIMDUint16x8Lib::EntryInfo::GreaterThanOrEqual, 3);
  3000. //// Lane Access
  3001. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::extractLane, &SIMDUint16x8Lib::EntryInfo::ExtractLane, 3);
  3002. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::replaceLane, &SIMDUint16x8Lib::EntryInfo::ReplaceLane, 3);
  3003. //// shift
  3004. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::shiftLeftByScalar, &SIMDUint16x8Lib::EntryInfo::ShiftLeftByScalar, 3);
  3005. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::shiftRightByScalar, &SIMDUint16x8Lib::EntryInfo::ShiftRightByScalar, 3);
  3006. //// load/store
  3007. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::load, &SIMDUint16x8Lib::EntryInfo::Load, 3);
  3008. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::store, &SIMDUint16x8Lib::EntryInfo::Store, 3);
  3009. //// others
  3010. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::swizzle, &SIMDUint16x8Lib::EntryInfo::Swizzle, 10);
  3011. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::shuffle, &SIMDUint16x8Lib::EntryInfo::Shuffle, 11);
  3012. library->AddFunctionToLibraryObject(uint16x8Function, PropertyIds::select, &SIMDUint16x8Lib::EntryInfo::Select, 4);
  3013. /** end Uint16x8 **/
  3014. /** Uint8x16**/
  3015. JavascriptFunction* uint8x16Function = library->AddFunctionToLibraryObjectWithPrototype(simdObject, PropertyIds::Uint8x16,
  3016. &SIMDUint8x16Lib::EntryInfo::Uint8x16, 17, library->simdUint8x16Prototype, nullptr);
  3017. builtinFuncs[BuiltinFunction::SIMDUint8x16Lib_Uint8x16] = uint8x16Function;
  3018. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::splat, &SIMDUint8x16Lib::EntryInfo::Splat, 2);
  3019. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::check, &SIMDUint8x16Lib::EntryInfo::Check, 2);
  3020. //// type conversions
  3021. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::fromInt32x4Bits, &SIMDUint8x16Lib::EntryInfo::FromInt32x4Bits, 2);
  3022. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::fromInt16x8Bits, &SIMDUint8x16Lib::EntryInfo::FromInt16x8Bits, 2);
  3023. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::fromInt8x16Bits, &SIMDUint8x16Lib::EntryInfo::FromInt8x16Bits, 2);
  3024. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::fromUint32x4Bits, &SIMDUint8x16Lib::EntryInfo::FromUint32x4Bits, 2);
  3025. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::fromUint16x8Bits, &SIMDUint8x16Lib::EntryInfo::FromUint16x8Bits, 2);
  3026. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::fromFloat32x4Bits, &SIMDUint8x16Lib::EntryInfo::FromFloat32x4Bits, 2);
  3027. //// UnaryOps
  3028. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::not_, &SIMDUint8x16Lib::EntryInfo::Not, 2);
  3029. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::neg, &SIMDUint8x16Lib::EntryInfo::Neg, 2);
  3030. //// binary ops
  3031. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::add, &SIMDUint8x16Lib::EntryInfo::Add, 3);
  3032. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::sub, &SIMDUint8x16Lib::EntryInfo::Sub, 3);
  3033. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::mul, &SIMDUint8x16Lib::EntryInfo::Mul, 3);
  3034. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::and_, &SIMDUint8x16Lib::EntryInfo::And, 3);
  3035. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::or_, &SIMDUint8x16Lib::EntryInfo::Or, 3);
  3036. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::xor_, &SIMDUint8x16Lib::EntryInfo::Xor, 3);
  3037. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::addSaturate, &SIMDUint8x16Lib::EntryInfo::AddSaturate, 3);
  3038. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::subSaturate, &SIMDUint8x16Lib::EntryInfo::SubSaturate, 3);
  3039. //// compare ops
  3040. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::lessThan, &SIMDUint8x16Lib::EntryInfo::LessThan, 3);
  3041. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::lessThanOrEqual, &SIMDUint8x16Lib::EntryInfo::LessThanOrEqual, 3);
  3042. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::equal, &SIMDUint8x16Lib::EntryInfo::Equal, 3);
  3043. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::notEqual, &SIMDUint8x16Lib::EntryInfo::NotEqual, 3);
  3044. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::greaterThan, &SIMDUint8x16Lib::EntryInfo::GreaterThan, 3);
  3045. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::greaterThanOrEqual, &SIMDUint8x16Lib::EntryInfo::GreaterThanOrEqual, 3);
  3046. //// Lane Access
  3047. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::extractLane, &SIMDUint8x16Lib::EntryInfo::ExtractLane, 3);
  3048. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::replaceLane, &SIMDUint8x16Lib::EntryInfo::ReplaceLane, 3);
  3049. //// shift
  3050. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::shiftLeftByScalar, &SIMDUint8x16Lib::EntryInfo::ShiftLeftByScalar, 3);
  3051. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::shiftRightByScalar, &SIMDUint8x16Lib::EntryInfo::ShiftRightByScalar, 3);
  3052. //// load/store
  3053. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::load, &SIMDUint8x16Lib::EntryInfo::Load, 3);
  3054. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::store, &SIMDUint8x16Lib::EntryInfo::Store, 3);
  3055. //// others
  3056. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::swizzle, &SIMDUint8x16Lib::EntryInfo::Swizzle, 18);
  3057. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::shuffle, &SIMDUint8x16Lib::EntryInfo::Shuffle, 19);
  3058. library->AddFunctionToLibraryObject(uint8x16Function, PropertyIds::select, &SIMDUint8x16Lib::EntryInfo::Select, 4);
  3059. /** end Uint8x16 **/
  3060. return true;
  3061. }
  3062. #endif
  3063. bool JavascriptLibrary::InitializeReflectObject(DynamicObject* reflectObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3064. {
  3065. typeHandler->Convert(reflectObject, mode, 12);
  3066. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterReflect
  3067. // so that the update is in sync with profiler
  3068. ScriptContext* scriptContext = reflectObject->GetScriptContext();
  3069. JavascriptLibrary* library = reflectObject->GetLibrary();
  3070. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::DefineProperty.GetOriginalEntryPoint(),
  3071. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::defineProperty, &JavascriptReflect::EntryInfo::DefineProperty, 3));
  3072. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::DeleteProperty.GetOriginalEntryPoint(),
  3073. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::deleteProperty, &JavascriptReflect::EntryInfo::DeleteProperty, 2));
  3074. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Get.GetOriginalEntryPoint(),
  3075. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::get, &JavascriptReflect::EntryInfo::Get, 2));
  3076. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::GetOwnPropertyDescriptor.GetOriginalEntryPoint(),
  3077. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::getOwnPropertyDescriptor, &JavascriptReflect::EntryInfo::GetOwnPropertyDescriptor, 2));
  3078. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::GetPrototypeOf.GetOriginalEntryPoint(),
  3079. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::getPrototypeOf, &JavascriptReflect::EntryInfo::GetPrototypeOf, 1));
  3080. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Has.GetOriginalEntryPoint(),
  3081. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::has, &JavascriptReflect::EntryInfo::Has, 2));
  3082. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::IsExtensible.GetOriginalEntryPoint(),
  3083. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::isExtensible, &JavascriptReflect::EntryInfo::IsExtensible, 1));
  3084. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::OwnKeys.GetOriginalEntryPoint(),
  3085. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::ownKeys, &JavascriptReflect::EntryInfo::OwnKeys, 1));
  3086. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::PreventExtensions.GetOriginalEntryPoint(),
  3087. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::preventExtensions, &JavascriptReflect::EntryInfo::PreventExtensions, 1));
  3088. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Set.GetOriginalEntryPoint(),
  3089. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::set, &JavascriptReflect::EntryInfo::Set, 3));
  3090. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::SetPrototypeOf.GetOriginalEntryPoint(),
  3091. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::setPrototypeOf, &JavascriptReflect::EntryInfo::SetPrototypeOf, 2));
  3092. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Apply.GetOriginalEntryPoint(),
  3093. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::apply, &JavascriptReflect::EntryInfo::Apply, 3));
  3094. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Construct.GetOriginalEntryPoint(),
  3095. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::construct, &JavascriptReflect::EntryInfo::Construct, 2));
  3096. return true;
  3097. }
  3098. void JavascriptLibrary::InitializeStaticValues()
  3099. {
  3100. constructorCacheDefaultInstance = &Js::ConstructorCache::DefaultInstance;
  3101. absDoubleCst = Js::JavascriptNumber::AbsDoubleCst;
  3102. uintConvertConst = Js::JavascriptNumber::UIntConvertConst;
  3103. defaultPropertyDescriptor.SetValue(undefinedValue);
  3104. defaultPropertyDescriptor.SetWritable(false);
  3105. defaultPropertyDescriptor.SetGetter(defaultAccessorFunction);
  3106. defaultPropertyDescriptor.SetSetter(defaultAccessorFunction);
  3107. defaultPropertyDescriptor.SetEnumerable(false);
  3108. defaultPropertyDescriptor.SetConfigurable(false);
  3109. #if !defined(TARGET_64)
  3110. VirtualTableRecorder<Js::JavascriptNumber>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableJavascriptNumber);
  3111. #else
  3112. vtableAddresses[VTableValue::VtableJavascriptNumber] = 0;
  3113. #endif
  3114. VirtualTableRecorder<Js::DynamicObject>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableDynamicObject);
  3115. vtableAddresses[VTableValue::VtableInvalid] = Js::ScriptContextOptimizationOverrideInfo::InvalidVtable;
  3116. VirtualTableRecorder<Js::PropertyString>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtablePropertyString);
  3117. VirtualTableRecorder<Js::LazyJSONString>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableLazyJSONString);
  3118. VirtualTableRecorder<Js::JavascriptBoolean>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableJavascriptBoolean);
  3119. VirtualTableRecorder<Js::JavascriptArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableJavascriptArray);
  3120. VirtualTableRecorder<Js::Int8Array>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableInt8Array);
  3121. VirtualTableRecorder<Js::Uint8Array>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableUint8Array);
  3122. VirtualTableRecorder<Js::Uint8ClampedArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableUint8ClampedArray);
  3123. VirtualTableRecorder<Js::Int16Array>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableInt16Array);
  3124. VirtualTableRecorder<Js::Uint16Array>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableUint16Array);
  3125. VirtualTableRecorder<Js::Int32Array>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableInt32Array);
  3126. VirtualTableRecorder<Js::Uint32Array>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableUint32Array);
  3127. VirtualTableRecorder<Js::Float32Array>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableFloat32Array);
  3128. VirtualTableRecorder<Js::Float64Array>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableFloat64Array);
  3129. VirtualTableRecorder<Js::Int64Array>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableInt64Array);
  3130. VirtualTableRecorder<Js::Uint64Array>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableUint64Array);
  3131. VirtualTableRecorder<Js::Int8VirtualArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableInt8VirtualArray);
  3132. VirtualTableRecorder<Js::Uint8VirtualArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableUint8VirtualArray);
  3133. VirtualTableRecorder<Js::Uint8ClampedVirtualArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableUint8ClampedVirtualArray);
  3134. VirtualTableRecorder<Js::Int16VirtualArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableInt16VirtualArray);
  3135. VirtualTableRecorder<Js::Uint16VirtualArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableUint16VirtualArray);
  3136. VirtualTableRecorder<Js::Int32VirtualArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableInt32VirtualArray);
  3137. VirtualTableRecorder<Js::Uint32VirtualArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableUint32VirtualArray);
  3138. VirtualTableRecorder<Js::Float32VirtualArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableFloat32VirtualArray);
  3139. VirtualTableRecorder<Js::Float64VirtualArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableFloat64VirtualArray);
  3140. VirtualTableRecorder<Js::BoolArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableBoolArray);
  3141. VirtualTableRecorder<Js::CharArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableCharArray);
  3142. VirtualTableRecorder<Js::JavascriptNativeIntArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableNativeIntArray);
  3143. #if ENABLE_COPYONACCESS_ARRAY
  3144. VirtualTableRecorder<Js::JavascriptCopyOnAccessNativeIntArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableCopyOnAccessNativeIntArray);
  3145. #endif
  3146. VirtualTableRecorder<Js::JavascriptNativeFloatArray>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableNativeFloatArray);
  3147. // don't validate vtable for VtableJavascriptNativeIntArray because its vtable is used for VtableNativeIntArray
  3148. vtableAddresses[VTableValue::VtableJavascriptNativeIntArray] = VirtualTableInfo<Js::JavascriptNativeIntArray>::Address;
  3149. VirtualTableRecorder<Js::JavascriptRegExp>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableJavascriptRegExp);
  3150. VirtualTableRecorder<Js::StackScriptFunction>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableStackScriptFunction);
  3151. VirtualTableRecorder<Js::ScriptFunction>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableScriptFunction);
  3152. VirtualTableRecorder<Js::JavascriptGeneratorFunction>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableJavascriptGeneratorFunction);
  3153. VirtualTableRecorder<Js::JavascriptAsyncFunction>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableJavascriptAsyncFunction);
  3154. VirtualTableRecorder<Js::ConcatStringMulti>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableConcatStringMulti);
  3155. VirtualTableRecorder<Js::CompoundString>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableCompoundString);
  3156. // SIMD_JS
  3157. #ifdef ENABLE_SIMDJS
  3158. VirtualTableRecorder<Js::JavascriptSIMDFloat32x4>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableSimd128F4);
  3159. VirtualTableRecorder<Js::JavascriptSIMDInt32x4>::RecordVirtualTableAddress(vtableAddresses, VTableValue::VtableSimd128I4);
  3160. #endif
  3161. for (TypeId typeId = static_cast<TypeId>(0); typeId < TypeIds_Limit; typeId = static_cast<TypeId>(typeId + 1))
  3162. {
  3163. switch (typeId)
  3164. {
  3165. case TypeIds_Undefined:
  3166. typeDisplayStrings[typeId] = GetUndefinedDisplayString();
  3167. break;
  3168. case TypeIds_Function:
  3169. typeDisplayStrings[typeId] = stringCache.GetFunctionTypeDisplayString();
  3170. break;
  3171. case TypeIds_Boolean:
  3172. typeDisplayStrings[typeId] = stringCache.GetBooleanTypeDisplayString();
  3173. break;
  3174. case TypeIds_String:
  3175. typeDisplayStrings[typeId] = stringCache.GetStringTypeDisplayString();
  3176. break;
  3177. case TypeIds_Symbol:
  3178. typeDisplayStrings[typeId] = stringCache.GetSymbolTypeDisplayString();
  3179. break;
  3180. case TypeIds_VariantDate:
  3181. typeDisplayStrings[typeId] = stringCache.GetVariantDateTypeDisplayString();
  3182. break;
  3183. case TypeIds_Integer:
  3184. case TypeIds_Number:
  3185. case TypeIds_Int64Number:
  3186. case TypeIds_UInt64Number:
  3187. typeDisplayStrings[typeId] = stringCache.GetNumberTypeDisplayString();
  3188. break;
  3189. #ifdef ENABLE_SIMDJS
  3190. case TypeIds_SIMDFloat32x4:
  3191. typeDisplayStrings[typeId] = stringCache.GetSIMDFloat32x4DisplayString();
  3192. break;
  3193. //case TypeIds_SIMDFloat64x2: //Type under review by the spec.
  3194. // typeDisplayStrings[typeId] = simdFloat64x2DisplayString;
  3195. // break;
  3196. case TypeIds_SIMDInt32x4:
  3197. typeDisplayStrings[typeId] = stringCache.GetSIMDInt32x4DisplayString();
  3198. break;
  3199. case TypeIds_SIMDInt16x8:
  3200. typeDisplayStrings[typeId] = stringCache.GetSIMDInt16x8DisplayString();
  3201. break;
  3202. case TypeIds_SIMDInt8x16:
  3203. typeDisplayStrings[typeId] = stringCache.GetSIMDInt8x16DisplayString();
  3204. break;
  3205. case TypeIds_SIMDUint32x4:
  3206. typeDisplayStrings[typeId] = stringCache.GetSIMDUint32x4DisplayString();
  3207. break;
  3208. case TypeIds_SIMDUint16x8:
  3209. typeDisplayStrings[typeId] = stringCache.GetSIMDUint16x8DisplayString();
  3210. break;
  3211. case TypeIds_SIMDUint8x16:
  3212. typeDisplayStrings[typeId] = stringCache.GetSIMDUint8x16DisplayString();
  3213. break;
  3214. case TypeIds_SIMDBool32x4:
  3215. typeDisplayStrings[typeId] = stringCache.GetSIMDBool32x4DisplayString();
  3216. break;
  3217. case TypeIds_SIMDBool16x8:
  3218. typeDisplayStrings[typeId] = stringCache.GetSIMDBool16x8DisplayString();
  3219. break;
  3220. case TypeIds_SIMDBool8x16:
  3221. typeDisplayStrings[typeId] = stringCache.GetSIMDBool8x16DisplayString();
  3222. break;
  3223. #endif
  3224. case TypeIds_Enumerator:
  3225. case TypeIds_HostDispatch:
  3226. case TypeIds_WithScopeObject:
  3227. case TypeIds_UndeclBlockVar:
  3228. case TypeIds_Proxy:
  3229. case TypeIds_SpreadArgument:
  3230. typeDisplayStrings[typeId] = nullptr;
  3231. break;
  3232. default:
  3233. typeDisplayStrings[typeId] = stringCache.GetObjectTypeDisplayString();
  3234. break;
  3235. }
  3236. }
  3237. }
  3238. // Note: This function is only used in float preferencing scenarios. Should remove it once we do away with float preferencing.
  3239. // Cases like,
  3240. // case PropertyIds::concat:
  3241. // case PropertyIds::indexOf:
  3242. // case PropertyIds::lastIndexOf:
  3243. // case PropertyIds::slice:
  3244. // which have same names for Array and String cannot be resolved just by the property id
  3245. BuiltinFunction JavascriptLibrary::GetBuiltinFunctionForPropId(PropertyId id)
  3246. {
  3247. switch (id)
  3248. {
  3249. case PropertyIds::abs:
  3250. return BuiltinFunction::Math_Abs;
  3251. // For now, avoid mapping Math.atan2 to a direct CRT call, as the
  3252. // fast CRT helper doesn't handle denormals correctly.
  3253. // case PropertyIds::atan2:
  3254. // return BuiltinFunction::Atan2;
  3255. case PropertyIds::acos:
  3256. return BuiltinFunction::Math_Acos;
  3257. case PropertyIds::asin:
  3258. return BuiltinFunction::Math_Asin;
  3259. case PropertyIds::atan:
  3260. return BuiltinFunction::Math_Atan;
  3261. case PropertyIds::cos:
  3262. return BuiltinFunction::Math_Cos;
  3263. case PropertyIds::exp:
  3264. return BuiltinFunction::Math_Exp;
  3265. case PropertyIds::log:
  3266. return BuiltinFunction::Math_Log;
  3267. case PropertyIds::pow:
  3268. return BuiltinFunction::Math_Pow;
  3269. case PropertyIds::random:
  3270. return BuiltinFunction::Math_Random;
  3271. case PropertyIds::sin:
  3272. return BuiltinFunction::Math_Sin;
  3273. case PropertyIds::sqrt:
  3274. return BuiltinFunction::Math_Sqrt;
  3275. case PropertyIds::tan:
  3276. return BuiltinFunction::Math_Tan;
  3277. case PropertyIds::floor:
  3278. return BuiltinFunction::Math_Floor;
  3279. case PropertyIds::ceil:
  3280. return BuiltinFunction::Math_Ceil;
  3281. case PropertyIds::round:
  3282. return BuiltinFunction::Math_Round;
  3283. case PropertyIds::max:
  3284. return BuiltinFunction::Math_Max;
  3285. case PropertyIds::min:
  3286. return BuiltinFunction::Math_Min;
  3287. case PropertyIds::imul:
  3288. return BuiltinFunction::Math_Imul;
  3289. case PropertyIds::fround:
  3290. return BuiltinFunction::Math_Fround;
  3291. case PropertyIds::codePointAt:
  3292. return BuiltinFunction::JavascriptString_CodePointAt;
  3293. case PropertyIds::push:
  3294. return BuiltinFunction::JavascriptArray_Push;
  3295. case PropertyIds::concat:
  3296. return BuiltinFunction::JavascriptArray_Concat;
  3297. case PropertyIds::indexOf:
  3298. return BuiltinFunction::JavascriptArray_IndexOf;
  3299. case PropertyIds::includes:
  3300. return BuiltinFunction::JavascriptArray_Includes;
  3301. case PropertyIds::isArray:
  3302. return BuiltinFunction::JavascriptArray_IsArray;
  3303. case PropertyIds::join:
  3304. return BuiltinFunction::JavascriptArray_Join;
  3305. case PropertyIds::lastIndexOf:
  3306. return BuiltinFunction::JavascriptArray_LastIndexOf;
  3307. case PropertyIds::reverse:
  3308. return BuiltinFunction::JavascriptArray_Reverse;
  3309. case PropertyIds::shift:
  3310. return BuiltinFunction::JavascriptArray_Shift;
  3311. case PropertyIds::slice:
  3312. return BuiltinFunction::JavascriptArray_Slice;
  3313. case PropertyIds::splice:
  3314. return BuiltinFunction::JavascriptArray_Splice;
  3315. case PropertyIds::unshift:
  3316. return BuiltinFunction::JavascriptArray_Unshift;
  3317. case PropertyIds::apply:
  3318. return BuiltinFunction::JavascriptFunction_Apply;
  3319. case PropertyIds::charAt:
  3320. return BuiltinFunction::JavascriptString_CharAt;
  3321. case PropertyIds::charCodeAt:
  3322. return BuiltinFunction::JavascriptString_CharCodeAt;
  3323. case PropertyIds::fromCharCode:
  3324. return BuiltinFunction::JavascriptString_FromCharCode;
  3325. case PropertyIds::fromCodePoint:
  3326. return BuiltinFunction::JavascriptString_FromCodePoint;
  3327. case PropertyIds::link:
  3328. return BuiltinFunction::JavascriptString_Link;
  3329. case PropertyIds::localeCompare:
  3330. return BuiltinFunction::JavascriptString_LocaleCompare;
  3331. case PropertyIds::match:
  3332. return BuiltinFunction::JavascriptString_Match;
  3333. case PropertyIds::replace:
  3334. return BuiltinFunction::JavascriptString_Replace;
  3335. case PropertyIds::search:
  3336. return BuiltinFunction::JavascriptString_Search;
  3337. case PropertyIds::_symbolSearch:
  3338. return BuiltinFunction::JavascriptRegExp_SymbolSearch;
  3339. case PropertyIds::split:
  3340. return BuiltinFunction::JavascriptString_Split;
  3341. case PropertyIds::substr:
  3342. return BuiltinFunction::JavascriptString_Substr;
  3343. case PropertyIds::substring:
  3344. return BuiltinFunction::JavascriptString_Substring;
  3345. case PropertyIds::toLocaleLowerCase:
  3346. return BuiltinFunction::JavascriptString_ToLocaleLowerCase;
  3347. case PropertyIds::toLocaleUpperCase:
  3348. return BuiltinFunction::JavascriptString_ToLocaleUpperCase;
  3349. case PropertyIds::toLowerCase:
  3350. return BuiltinFunction::JavascriptString_ToLowerCase;
  3351. case PropertyIds::toUpperCase:
  3352. return BuiltinFunction::JavascriptString_ToUpperCase;
  3353. case PropertyIds::trim:
  3354. return BuiltinFunction::JavascriptString_Trim;
  3355. case PropertyIds::trimLeft:
  3356. return BuiltinFunction::JavascriptString_TrimLeft;
  3357. case PropertyIds::trimRight:
  3358. return BuiltinFunction::JavascriptString_TrimRight;
  3359. case PropertyIds::padStart:
  3360. return BuiltinFunction::JavascriptString_PadStart;
  3361. case PropertyIds::padEnd:
  3362. return BuiltinFunction::JavascriptString_PadEnd;
  3363. case PropertyIds::exec:
  3364. return BuiltinFunction::JavascriptRegExp_Exec;
  3365. case PropertyIds::hasOwnProperty:
  3366. return BuiltinFunction::JavascriptObject_HasOwnProperty;
  3367. default:
  3368. return BuiltinFunction::None;
  3369. }
  3370. }
  3371. #if DBG
  3372. /*static*/
  3373. void JavascriptLibrary::CheckRegisteredBuiltIns(
  3374. Field(JavascriptFunction*)* builtInFuncs, ScriptContext *scriptContext)
  3375. {
  3376. byte count = BuiltinFunction::Count;
  3377. for (byte index = 0; index < count; index++)
  3378. {
  3379. Assert(!builtInFuncs[index] || (index == GetBuiltInForFuncInfo((intptr_t)builtInFuncs[index]->GetFunctionInfo(), scriptContext->GetThreadContext())));
  3380. }
  3381. }
  3382. #endif
  3383. // Returns built-in enum value for given funcInfo. Ultimately this will work for all built-ins (not only Math.*).
  3384. // Used by inliner.
  3385. BuiltinFunction JavascriptLibrary::GetBuiltInForFuncInfo(intptr_t funcInfoAddr, ThreadContextInfo * context)
  3386. {
  3387. #define LIBRARY_FUNCTION(target, name, argc, flags, EntryInfo) \
  3388. if(funcInfoAddr == (intptr_t)ShiftAddr(context, &EntryInfo)) \
  3389. { \
  3390. return BuiltinFunction::##target##_##name; \
  3391. }
  3392. #include "LibraryFunction.h"
  3393. #undef LIBRARY_FUNCTION
  3394. return BuiltinFunction::None;
  3395. }
  3396. // Returns true if the function's return type is always float.
  3397. BOOL JavascriptLibrary::IsFltFunc(BuiltinFunction index)
  3398. {
  3399. // Note: MathFunction is one of built-ins.
  3400. if (!JavascriptLibrary::CanFloatPreferenceFunc(index))
  3401. {
  3402. return FALSE;
  3403. }
  3404. Js::BuiltInFlags builtInFlags = JavascriptLibrary::GetFlagsForBuiltIn(index);
  3405. Js::BuiltInArgSpecializationType dstType = Js::JavascriptLibrary::GetBuiltInArgType(builtInFlags, Js::BuiltInArgShift::BIAS_Dst);
  3406. bool isFloatFunc = dstType == Js::BuiltInArgSpecializationType::BIAST_Float;
  3407. return isFloatFunc;
  3408. }
  3409. size_t const JavascriptLibrary::LibraryFunctionArgC[] = {
  3410. #define LIBRARY_FUNCTION(obj, name, argc, flags, entry) argc,
  3411. #include "LibraryFunction.h"
  3412. #undef LIBRARY_FUNCTION
  3413. 0
  3414. };
  3415. #if ENABLE_DEBUG_CONFIG_OPTIONS
  3416. char16 const * const JavascriptLibrary::LibraryFunctionName[] = {
  3417. #define LIBRARY_FUNCTION(obj, name, argc, flags, entry) _u(#obj) _u(".") _u(#name),
  3418. #include "LibraryFunction.h"
  3419. #undef LIBRARY_FUNCTION
  3420. 0
  3421. };
  3422. #endif
  3423. int const JavascriptLibrary::LibraryFunctionFlags[] = {
  3424. #define LIBRARY_FUNCTION(obj, name, argc, flags, entry) flags,
  3425. #include "LibraryFunction.h"
  3426. #undef LIBRARY_FUNCTION
  3427. BIF_None
  3428. };
  3429. bool JavascriptLibrary::IsFloatFunctionCallsite(BuiltinFunction index, size_t argc)
  3430. {
  3431. if (IsFltFunc(index))
  3432. {
  3433. Assert(index < BuiltinFunction::Count);
  3434. if (argc)
  3435. {
  3436. return JavascriptLibrary::LibraryFunctionArgC[index] <= (argc - 1 /* this */);
  3437. }
  3438. }
  3439. return false;
  3440. }
  3441. // For abs, min, max -- return can be int or float, but still return true from here.
  3442. BOOL JavascriptLibrary::CanFloatPreferenceFunc(BuiltinFunction index)
  3443. {
  3444. // Shortcut the common case:
  3445. if (index == BuiltinFunction::None)
  3446. {
  3447. return FALSE;
  3448. }
  3449. switch (index)
  3450. {
  3451. case BuiltinFunction::Math_Abs:
  3452. case BuiltinFunction::Math_Acos:
  3453. case BuiltinFunction::Math_Asin:
  3454. case BuiltinFunction::Math_Atan:
  3455. case BuiltinFunction::Math_Cos:
  3456. case BuiltinFunction::Math_Exp:
  3457. case BuiltinFunction::Math_Log:
  3458. case BuiltinFunction::Math_Min:
  3459. case BuiltinFunction::Math_Max:
  3460. case BuiltinFunction::Math_Pow:
  3461. case BuiltinFunction::Math_Random:
  3462. case BuiltinFunction::Math_Sin:
  3463. case BuiltinFunction::Math_Sqrt:
  3464. case BuiltinFunction::Math_Tan:
  3465. case BuiltinFunction::Math_Fround:
  3466. return TRUE;
  3467. }
  3468. return FALSE;
  3469. }
  3470. bool JavascriptLibrary::IsFltBuiltInConst(PropertyId propertyId)
  3471. {
  3472. switch (propertyId)
  3473. {
  3474. case Js::PropertyIds::E:
  3475. case Js::PropertyIds::LN10:
  3476. case Js::PropertyIds::LN2:
  3477. case Js::PropertyIds::LOG2E:
  3478. case Js::PropertyIds::LOG10E:
  3479. case Js::PropertyIds::PI:
  3480. case Js::PropertyIds::SQRT1_2:
  3481. case Js::PropertyIds::SQRT2:
  3482. return true;
  3483. }
  3484. return false;
  3485. }
  3486. void JavascriptLibrary::TypeAndPrototypesAreEnsuredToHaveOnlyWritableDataProperties(Type *const type)
  3487. {
  3488. Assert(type);
  3489. Assert(type->GetScriptContext() == scriptContext);
  3490. Assert(type->AreThisAndPrototypesEnsuredToHaveOnlyWritableDataProperties());
  3491. Assert(!scriptContext->IsClosed());
  3492. if(typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain->Count() == 0)
  3493. {
  3494. scriptContext->RegisterPrototypeChainEnsuredToHaveOnlyWritableDataPropertiesScriptContext();
  3495. }
  3496. typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain->Add(type);
  3497. }
  3498. void JavascriptLibrary::NoPrototypeChainsAreEnsuredToHaveOnlyWritableDataProperties()
  3499. {
  3500. for(int i = 0; i < typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain->Count(); ++i)
  3501. {
  3502. typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain
  3503. ->Item(i)
  3504. ->SetAreThisAndPrototypesEnsuredToHaveOnlyWritableDataProperties(false);
  3505. }
  3506. typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain->ClearAndZero();
  3507. }
  3508. bool JavascriptLibrary::ArrayIteratorPrototypeHasUserDefinedNext(ScriptContext *scriptContext)
  3509. {
  3510. Var arrayIteratorPrototypeNext = nullptr;
  3511. ImplicitCallFlags flags = scriptContext->GetThreadContext()->TryWithDisabledImplicitCall(
  3512. [&]() { arrayIteratorPrototypeNext = JavascriptOperators::GetPropertyNoCache(scriptContext->GetLibrary()->GetArrayIteratorPrototype(), PropertyIds::next, scriptContext); });
  3513. return (flags != ImplicitCall_None) || arrayIteratorPrototypeNext != scriptContext->GetLibrary()->GetArrayIteratorPrototypeBuiltinNextFunction();
  3514. }
  3515. bool JavascriptLibrary::InitializeNumberConstructor(DynamicObject* numberConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3516. {
  3517. typeHandler->Convert(numberConstructor, mode, 17);
  3518. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterNumber
  3519. // so that the update is in sync with profiler
  3520. ScriptContext* scriptContext = numberConstructor->GetScriptContext();
  3521. JavascriptLibrary* library = numberConstructor->GetLibrary();
  3522. library->AddMember(numberConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  3523. library->AddMember(numberConstructor, PropertyIds::prototype, library->numberPrototype, PropertyNone);
  3524. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3525. {
  3526. library->AddMember(numberConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Number), PropertyConfigurable);
  3527. }
  3528. library->AddMember(numberConstructor, PropertyIds::MAX_VALUE, library->maxValue, PropertyNone);
  3529. library->AddMember(numberConstructor, PropertyIds::MIN_VALUE, library->minValue, PropertyNone);
  3530. library->AddMember(numberConstructor, PropertyIds::NaN, library->nan, PropertyNone);
  3531. library->AddMember(numberConstructor, PropertyIds::NEGATIVE_INFINITY, library->negativeInfinite, PropertyNone);
  3532. library->AddMember(numberConstructor, PropertyIds::POSITIVE_INFINITY, library->positiveInfinite, PropertyNone);
  3533. if (scriptContext->GetConfig()->IsES6NumberExtensionsEnabled())
  3534. {
  3535. #ifdef DBG
  3536. double epsilon = 0.0;
  3537. for (double next = 1.0; next + 1.0 != 1.0; next = next / 2.0)
  3538. {
  3539. epsilon = next;
  3540. }
  3541. Assert(epsilon == Math::EPSILON);
  3542. #endif
  3543. library->AddMember(numberConstructor, PropertyIds::EPSILON, JavascriptNumber::New(Math::EPSILON, scriptContext), PropertyNone);
  3544. library->AddMember(numberConstructor, PropertyIds::MAX_SAFE_INTEGER, JavascriptNumber::New(Math::MAX_SAFE_INTEGER, scriptContext), PropertyNone);
  3545. library->AddMember(numberConstructor, PropertyIds::MIN_SAFE_INTEGER, JavascriptNumber::New(Math::MIN_SAFE_INTEGER, scriptContext), PropertyNone);
  3546. AssertMsg(library->parseIntFunctionObject != nullptr, "Where is parseIntFunctionObject? Should have been initialized with Global object initialization");
  3547. AssertMsg(library->parseFloatFunctionObject != nullptr, "Where is parseIntFunctionObject? Should have been initialized with Global object initialization");
  3548. library->AddMember(numberConstructor, PropertyIds::parseInt, library->parseIntFunctionObject);
  3549. library->AddMember(numberConstructor, PropertyIds::parseFloat, library->parseFloatFunctionObject);
  3550. library->AddFunctionToLibraryObject(numberConstructor, PropertyIds::isNaN, &JavascriptNumber::EntryInfo::IsNaN, 1);
  3551. library->AddFunctionToLibraryObject(numberConstructor, PropertyIds::isFinite, &JavascriptNumber::EntryInfo::IsFinite, 1);
  3552. library->AddFunctionToLibraryObject(numberConstructor, PropertyIds::isInteger, &JavascriptNumber::EntryInfo::IsInteger, 1);
  3553. library->AddFunctionToLibraryObject(numberConstructor, PropertyIds::isSafeInteger, &JavascriptNumber::EntryInfo::IsSafeInteger, 1);
  3554. }
  3555. numberConstructor->SetHasNoEnumerableProperties(true);
  3556. return true;
  3557. }
  3558. bool JavascriptLibrary::InitializeNumberPrototype(DynamicObject* numberPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3559. {
  3560. typeHandler->Convert(numberPrototype, mode, 8);
  3561. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterNumber
  3562. // so that the update is in sync with profiler
  3563. ScriptContext* scriptContext = numberPrototype->GetScriptContext();
  3564. JavascriptLibrary* library = numberPrototype->GetLibrary();
  3565. library->AddMember(numberPrototype, PropertyIds::constructor, library->numberConstructor);
  3566. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ToExponential.GetOriginalEntryPoint(),
  3567. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::toExponential, &JavascriptNumber::EntryInfo::ToExponential, 1));
  3568. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ToFixed.GetOriginalEntryPoint(),
  3569. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::toFixed, &JavascriptNumber::EntryInfo::ToFixed, 1));
  3570. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ToPrecision.GetOriginalEntryPoint(),
  3571. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::toPrecision, &JavascriptNumber::EntryInfo::ToPrecision, 1));
  3572. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ToLocaleString.GetOriginalEntryPoint(),
  3573. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::toLocaleString, &JavascriptNumber::EntryInfo::ToLocaleString, 0));
  3574. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ToString.GetOriginalEntryPoint(),
  3575. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::toString, &JavascriptNumber::EntryInfo::ToString, 1));
  3576. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  3577. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::valueOf, &JavascriptNumber::EntryInfo::ValueOf, 0));
  3578. numberPrototype->SetHasNoEnumerableProperties(true);
  3579. return true;
  3580. }
  3581. #ifdef ENABLE_SIMDJS
  3582. template<typename SIMDTypeName>
  3583. void JavascriptLibrary::SIMDPrototypeInitHelper(DynamicObject* simdPrototype, JavascriptLibrary* library, JavascriptFunction* constructorFn, JavascriptString* strLiteral)
  3584. {
  3585. ScriptContext* scriptContext = simdPrototype->GetScriptContext();
  3586. //The initial value of SIMDConstructor.prototype.constructor is the intrinsic object %SIMDConstructor%
  3587. library->AddMember(simdPrototype, PropertyIds::constructor, constructorFn);
  3588. scriptContext->SetBuiltInLibraryFunction(SIMDTypeName::EntryInfo::ToLocaleString.GetOriginalEntryPoint(),
  3589. library->AddFunctionToLibraryObject(simdPrototype, PropertyIds::toLocaleString, &SIMDTypeName::EntryInfo::ToLocaleString, 0));
  3590. scriptContext->SetBuiltInLibraryFunction(SIMDTypeName::EntryInfo::ToString.GetOriginalEntryPoint(),
  3591. library->AddFunctionToLibraryObject(simdPrototype, PropertyIds::toString, &SIMDTypeName::EntryInfo::ToString, 1));
  3592. scriptContext->SetBuiltInLibraryFunction(SIMDTypeName::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  3593. library->AddFunctionToLibraryObject(simdPrototype, PropertyIds::valueOf, &SIMDTypeName::EntryInfo::ValueOf, 0));
  3594. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  3595. {
  3596. library->AddMember(simdPrototype, PropertyIds::_symbolToStringTag, strLiteral, PropertyConfigurable);
  3597. }
  3598. if (scriptContext->GetConfig()->IsES6ToPrimitiveEnabled())
  3599. {
  3600. scriptContext->SetBuiltInLibraryFunction(SIMDTypeName::EntryInfo::SymbolToPrimitive.GetOriginalEntryPoint(),
  3601. library->AddFunctionToLibraryObjectWithName(simdPrototype, PropertyIds::_symbolToPrimitive, PropertyIds::_RuntimeFunctionNameId_toPrimitive,
  3602. &SIMDTypeName::EntryInfo::SymbolToPrimitive, 1));
  3603. simdPrototype->SetWritable(PropertyIds::_symbolToPrimitive, false);
  3604. }
  3605. simdPrototype->SetHasNoEnumerableProperties(true);
  3606. }
  3607. bool JavascriptLibrary::InitializeSIMDBool8x16Prototype(DynamicObject* simdPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3608. {
  3609. typeHandler->Convert(simdPrototype, mode, 6);
  3610. JavascriptLibrary* library = simdPrototype->GetLibrary();
  3611. SIMDPrototypeInitHelper<JavascriptSIMDBool8x16>(simdPrototype, library, library->GetBuiltinFunctions()[BuiltinFunction::SIMDBool8x16Lib_Bool8x16],
  3612. library->CreateStringFromCppLiteral(_u("SIMD.Bool8x16")));
  3613. return true;
  3614. }
  3615. bool JavascriptLibrary::InitializeSIMDBool16x8Prototype(DynamicObject* simdPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3616. {
  3617. typeHandler->Convert(simdPrototype, mode, 6);
  3618. JavascriptLibrary* library = simdPrototype->GetLibrary();
  3619. SIMDPrototypeInitHelper<JavascriptSIMDBool16x8>(simdPrototype, library, library->GetBuiltinFunctions()[BuiltinFunction::SIMDBool16x8Lib_Bool16x8],
  3620. library->CreateStringFromCppLiteral(_u("SIMD.Bool16x8")));
  3621. return true;
  3622. }
  3623. bool JavascriptLibrary::InitializeSIMDBool32x4Prototype(DynamicObject* simdPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3624. {
  3625. typeHandler->Convert(simdPrototype, mode, 6);
  3626. JavascriptLibrary* library = simdPrototype->GetLibrary();
  3627. SIMDPrototypeInitHelper<JavascriptSIMDBool32x4>(simdPrototype, library, library->GetBuiltinFunctions()[BuiltinFunction::SIMDBool32x4Lib_Bool32x4],
  3628. library->CreateStringFromCppLiteral(_u("SIMD.Bool32x4")));
  3629. return true;
  3630. }
  3631. bool JavascriptLibrary::InitializeSIMDInt8x16Prototype(DynamicObject* simdPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3632. {
  3633. typeHandler->Convert(simdPrototype, mode, 6);
  3634. JavascriptLibrary* library = simdPrototype->GetLibrary();
  3635. SIMDPrototypeInitHelper<JavascriptSIMDInt8x16>(simdPrototype, library, library->GetBuiltinFunctions()[BuiltinFunction::SIMDInt8x16Lib_Int8x16],
  3636. library->CreateStringFromCppLiteral(_u("SIMD.Int8x16")));
  3637. return true;
  3638. }
  3639. bool JavascriptLibrary::InitializeSIMDInt16x8Prototype(DynamicObject* simdPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3640. {
  3641. typeHandler->Convert(simdPrototype, mode, 6);
  3642. JavascriptLibrary* library = simdPrototype->GetLibrary();
  3643. SIMDPrototypeInitHelper<JavascriptSIMDInt16x8>(simdPrototype, library, library->GetBuiltinFunctions()[BuiltinFunction::SIMDInt16x8Lib_Int16x8],
  3644. library->CreateStringFromCppLiteral(_u("SIMD.Int16x8")));
  3645. return true;
  3646. }
  3647. bool JavascriptLibrary::InitializeSIMDInt32x4Prototype(DynamicObject* simdPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3648. {
  3649. typeHandler->Convert(simdPrototype, mode, 6);
  3650. JavascriptLibrary* library = simdPrototype->GetLibrary();
  3651. SIMDPrototypeInitHelper<JavascriptSIMDInt32x4>(simdPrototype, library, library->GetBuiltinFunctions()[BuiltinFunction::SIMDInt32x4Lib_Int32x4],
  3652. library->CreateStringFromCppLiteral(_u("SIMD.Int32x4")));
  3653. return true;
  3654. }
  3655. bool JavascriptLibrary::InitializeSIMDUint8x16Prototype(DynamicObject* simdPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3656. {
  3657. typeHandler->Convert(simdPrototype, mode, 6);
  3658. JavascriptLibrary* library = simdPrototype->GetLibrary();
  3659. SIMDPrototypeInitHelper<JavascriptSIMDUint8x16>(simdPrototype, library, library->GetBuiltinFunctions()[BuiltinFunction::SIMDUint8x16Lib_Uint8x16],
  3660. library->CreateStringFromCppLiteral(_u("SIMD.Uint8x16")));
  3661. return true;
  3662. }
  3663. bool JavascriptLibrary::InitializeSIMDUint16x8Prototype(DynamicObject* simdPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3664. {
  3665. typeHandler->Convert(simdPrototype, mode, 6);
  3666. JavascriptLibrary* library = simdPrototype->GetLibrary();
  3667. SIMDPrototypeInitHelper<JavascriptSIMDUint16x8>(simdPrototype, library, library->GetBuiltinFunctions()[BuiltinFunction::SIMDUint16x8Lib_Uint16x8],
  3668. library->CreateStringFromCppLiteral(_u("SIMD.Uint16x8")));
  3669. return true;
  3670. }
  3671. bool JavascriptLibrary::InitializeSIMDUint32x4Prototype(DynamicObject* simdPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3672. {
  3673. typeHandler->Convert(simdPrototype, mode, 6);
  3674. JavascriptLibrary* library = simdPrototype->GetLibrary();
  3675. SIMDPrototypeInitHelper<JavascriptSIMDUint32x4>(simdPrototype, library, library->GetBuiltinFunctions()[BuiltinFunction::SIMDUint32x4Lib_Uint32x4],
  3676. library->CreateStringFromCppLiteral(_u("SIMD.Uint32x4")));
  3677. return true;
  3678. }
  3679. bool JavascriptLibrary::InitializeSIMDFloat32x4Prototype(DynamicObject* simdPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3680. {
  3681. typeHandler->Convert(simdPrototype, mode, 6);
  3682. JavascriptLibrary* library = simdPrototype->GetLibrary();
  3683. SIMDPrototypeInitHelper<JavascriptSIMDFloat32x4>(simdPrototype, library, library->GetBuiltinFunctions()[BuiltinFunction::SIMDFloat32x4Lib_Float32x4],
  3684. library->CreateStringFromCppLiteral(_u("SIMD.Float32x4")));
  3685. return true;
  3686. }
  3687. #endif
  3688. bool JavascriptLibrary::InitializeObjectConstructor(DynamicObject* objectConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3689. {
  3690. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterObject
  3691. // so that the update is in sync with profiler
  3692. JavascriptLibrary* library = objectConstructor->GetLibrary();
  3693. ScriptContext* scriptContext = objectConstructor->GetScriptContext();
  3694. int propertyCount = 18;
  3695. if (scriptContext->GetConfig()->IsES6ObjectExtensionsEnabled())
  3696. {
  3697. propertyCount += 2;
  3698. }
  3699. if (scriptContext->GetConfig()->IsESObjectGetOwnPropertyDescriptorsEnabled())
  3700. {
  3701. propertyCount++;
  3702. }
  3703. typeHandler->Convert(objectConstructor, mode, propertyCount);
  3704. library->AddMember(objectConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  3705. library->AddMember(objectConstructor, PropertyIds::prototype, library->objectPrototype, PropertyNone);
  3706. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3707. {
  3708. library->AddMember(objectConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Object), PropertyConfigurable);
  3709. }
  3710. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::DefineProperty.GetOriginalEntryPoint(),
  3711. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::defineProperty, &JavascriptObject::EntryInfo::DefineProperty, 3));
  3712. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::GetOwnPropertyDescriptor.GetOriginalEntryPoint(),
  3713. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::getOwnPropertyDescriptor, &JavascriptObject::EntryInfo::GetOwnPropertyDescriptor, 2));
  3714. if (scriptContext->GetConfig()->IsESObjectGetOwnPropertyDescriptorsEnabled())
  3715. {
  3716. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::GetOwnPropertyDescriptors.GetOriginalEntryPoint(),
  3717. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::getOwnPropertyDescriptors, &JavascriptObject::EntryInfo::GetOwnPropertyDescriptors, 1));
  3718. }
  3719. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::DefineProperties.GetOriginalEntryPoint(),
  3720. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::defineProperties, &JavascriptObject::EntryInfo::DefineProperties, 2));
  3721. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::create, &JavascriptObject::EntryInfo::Create, 2);
  3722. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Seal.GetOriginalEntryPoint(),
  3723. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::seal, &JavascriptObject::EntryInfo::Seal, 1));
  3724. library->AddMember(objectConstructor, PropertyIds::freeze, library->EnsureObjectFreezeFunction(), PropertyBuiltInMethodDefaults);
  3725. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Freeze.GetOriginalEntryPoint(), library->EnsureObjectFreezeFunction());
  3726. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::PreventExtensions.GetOriginalEntryPoint(),
  3727. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::preventExtensions, &JavascriptObject::EntryInfo::PreventExtensions, 1));
  3728. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::IsSealed.GetOriginalEntryPoint(),
  3729. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::isSealed, &JavascriptObject::EntryInfo::IsSealed, 1));
  3730. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::IsFrozen.GetOriginalEntryPoint(),
  3731. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::isFrozen, &JavascriptObject::EntryInfo::IsFrozen, 1));
  3732. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::IsExtensible.GetOriginalEntryPoint(),
  3733. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::isExtensible, &JavascriptObject::EntryInfo::IsExtensible, 1));
  3734. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::GetPrototypeOf.GetOriginalEntryPoint(),
  3735. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::getPrototypeOf, &JavascriptObject::EntryInfo::GetPrototypeOf, 1));
  3736. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Keys.GetOriginalEntryPoint(),
  3737. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::keys, &JavascriptObject::EntryInfo::Keys, 1));
  3738. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::GetOwnPropertyNames.GetOriginalEntryPoint(),
  3739. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::getOwnPropertyNames, &JavascriptObject::EntryInfo::GetOwnPropertyNames, 1));
  3740. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::SetPrototypeOf.GetOriginalEntryPoint(),
  3741. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::setPrototypeOf, &JavascriptObject::EntryInfo::SetPrototypeOf, 2));
  3742. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::GetOwnPropertySymbols.GetOriginalEntryPoint(),
  3743. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::getOwnPropertySymbols, &JavascriptObject::EntryInfo::GetOwnPropertySymbols, 1));
  3744. if (scriptContext->GetConfig()->IsES6ObjectExtensionsEnabled())
  3745. {
  3746. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Is.GetOriginalEntryPoint(),
  3747. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::is, &JavascriptObject::EntryInfo::Is, 2));
  3748. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Assign.GetOriginalEntryPoint(),
  3749. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::assign, &JavascriptObject::EntryInfo::Assign, 2));
  3750. }
  3751. if (scriptContext->GetConfig()->IsES7ValuesEntriesEnabled())
  3752. {
  3753. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Values.GetOriginalEntryPoint(),
  3754. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::values, &JavascriptObject::EntryInfo::Values, 1));
  3755. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Entries.GetOriginalEntryPoint(),
  3756. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::entries, &JavascriptObject::EntryInfo::Entries, 1));
  3757. }
  3758. objectConstructor->SetHasNoEnumerableProperties(true);
  3759. return true;
  3760. }
  3761. JavascriptFunction* JavascriptLibrary::EnsureObjectFreezeFunction()
  3762. {
  3763. if (objectFreezeFunction == nullptr)
  3764. {
  3765. objectFreezeFunction = DefaultCreateFunction(&JavascriptObject::EntryInfo::Freeze, 1, nullptr, nullptr, PropertyIds::freeze);
  3766. }
  3767. return objectFreezeFunction;
  3768. }
  3769. bool JavascriptLibrary::InitializeObjectPrototype(DynamicObject* objectPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3770. {
  3771. JavascriptLibrary* library = objectPrototype->GetLibrary();
  3772. ScriptContext* scriptContext = objectPrototype->GetScriptContext();
  3773. Field(JavascriptFunction*)* builtinFuncs = library->GetBuiltinFunctions();
  3774. typeHandler->Convert(objectPrototype, mode, 11, true);
  3775. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterObject
  3776. // so that the update is in sync with profiler
  3777. library->AddMember(objectPrototype, PropertyIds::constructor, library->objectConstructor);
  3778. builtinFuncs[BuiltinFunction::JavascriptObject_HasOwnProperty] = library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::hasOwnProperty, &JavascriptObject::EntryInfo::HasOwnProperty, 1);
  3779. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::propertyIsEnumerable, &JavascriptObject::EntryInfo::PropertyIsEnumerable, 1);
  3780. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::isPrototypeOf, &JavascriptObject::EntryInfo::IsPrototypeOf, 1);
  3781. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::toLocaleString, &JavascriptObject::EntryInfo::ToLocaleString, 0);
  3782. library->objectToStringFunction = library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::toString, &JavascriptObject::EntryInfo::ToString, 0);
  3783. library->objectValueOfFunction = library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::valueOf, &JavascriptObject::EntryInfo::ValueOf, 0);
  3784. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::ToString.GetOriginalEntryPoint(), library->objectToStringFunction);
  3785. bool hadOnlyWritableDataProperties = objectPrototype->GetDynamicType()->GetTypeHandler()->GetHasOnlyWritableDataProperties();
  3786. objectPrototype->SetAccessors(PropertyIds::__proto__, library->Get__proto__getterFunction(), library->Get__proto__setterFunction(), PropertyOperation_NonFixedValue);
  3787. objectPrototype->SetEnumerable(PropertyIds::__proto__, FALSE);
  3788. // Let's pretend __proto__ is actually writable. We'll make sure we always go through a special code path when writing to it.
  3789. if (hadOnlyWritableDataProperties)
  3790. {
  3791. objectPrototype->GetDynamicType()->GetTypeHandler()->SetHasOnlyWritableDataProperties();
  3792. }
  3793. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::__defineGetter__, &JavascriptObject::EntryInfo::DefineGetter, 2);
  3794. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::__defineSetter__, &JavascriptObject::EntryInfo::DefineSetter, 2);
  3795. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::__lookupGetter__, &JavascriptObject::EntryInfo::LookupGetter, 1);
  3796. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::__lookupSetter__, &JavascriptObject::EntryInfo::LookupSetter, 1);
  3797. objectPrototype->SetHasNoEnumerableProperties(true);
  3798. return true;
  3799. }
  3800. bool JavascriptLibrary::InitializeRegexConstructor(DynamicObject* regexConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3801. {
  3802. JavascriptLibrary* library = regexConstructor->GetLibrary();
  3803. ScriptContext* scriptContext = regexConstructor->GetScriptContext();
  3804. typeHandler->Convert(regexConstructor, mode, 3);
  3805. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterRegExp
  3806. // so that the update is in sync with profiler
  3807. library->AddMember(regexConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(2), PropertyConfigurable);
  3808. library->AddMember(regexConstructor, PropertyIds::prototype, library->regexPrototype, PropertyNone);
  3809. library->AddSpeciesAccessorsToLibraryObject(regexConstructor, &JavascriptRegExp::EntryInfo::GetterSymbolSpecies);
  3810. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3811. {
  3812. library->AddMember(regexConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::RegExp), PropertyConfigurable);
  3813. }
  3814. regexConstructor->SetHasNoEnumerableProperties(true);
  3815. return true;
  3816. }
  3817. bool JavascriptLibrary::InitializeRegexPrototype(DynamicObject* regexPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3818. {
  3819. typeHandler->Convert(regexPrototype, mode, 24);
  3820. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterRegExp
  3821. // so that the update is in sync with profiler
  3822. JavascriptFunction * func;
  3823. JavascriptLibrary* library = regexPrototype->GetLibrary();
  3824. Field(JavascriptFunction*)* builtinFuncs = library->GetBuiltinFunctions();
  3825. library->AddMember(regexPrototype, PropertyIds::constructor, library->regexConstructor);
  3826. library->regexConstructorSlotIndex = 0;
  3827. Assert(regexPrototype->GetSlot(library->regexConstructorSlotIndex) == library->regexConstructor);
  3828. func = library->AddFunctionToLibraryObject(regexPrototype, PropertyIds::exec, &JavascriptRegExp::EntryInfo::Exec, 1);
  3829. builtinFuncs[BuiltinFunction::JavascriptRegExp_Exec] = func;
  3830. library->regexExecFunction = func;
  3831. library->regexExecSlotIndex = 1;
  3832. Assert(regexPrototype->GetSlot(library->regexExecSlotIndex) == library->regexExecFunction);
  3833. library->AddFunctionToLibraryObject(regexPrototype, PropertyIds::test, &JavascriptRegExp::EntryInfo::Test, 1);
  3834. library->AddFunctionToLibraryObject(regexPrototype, PropertyIds::toString, &JavascriptRegExp::EntryInfo::ToString, 0);
  3835. // This is deprecated. Should be guarded with appropriate version flag.
  3836. library->AddFunctionToLibraryObject(regexPrototype, PropertyIds::compile, &JavascriptRegExp::EntryInfo::Compile, 2);
  3837. const ScriptConfiguration* scriptConfig = regexPrototype->GetScriptContext()->GetConfig();
  3838. if (scriptConfig->IsES6RegExPrototypePropertiesEnabled())
  3839. {
  3840. library->regexGlobalGetterFunction =
  3841. library->AddGetterToLibraryObject(regexPrototype, PropertyIds::global, &JavascriptRegExp::EntryInfo::GetterGlobal);
  3842. library->regexGlobalGetterSlotIndex = 5;
  3843. Assert(regexPrototype->GetSlot(library->regexGlobalGetterSlotIndex) == library->regexGlobalGetterFunction);
  3844. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::ignoreCase, &JavascriptRegExp::EntryInfo::GetterIgnoreCase, nullptr);
  3845. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::multiline, &JavascriptRegExp::EntryInfo::GetterMultiline, nullptr);
  3846. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::options, &JavascriptRegExp::EntryInfo::GetterOptions, nullptr);
  3847. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::source, &JavascriptRegExp::EntryInfo::GetterSource, nullptr);
  3848. library->regexFlagsGetterFunction =
  3849. library->AddGetterToLibraryObject(regexPrototype, PropertyIds::flags, &JavascriptRegExp::EntryInfo::GetterFlags);
  3850. library->regexFlagsGetterSlotIndex = 15;
  3851. Assert(regexPrototype->GetSlot(library->regexFlagsGetterSlotIndex) == library->regexFlagsGetterFunction);
  3852. if (scriptConfig->IsES6RegExStickyEnabled())
  3853. {
  3854. library->regexStickyGetterFunction =
  3855. library->AddGetterToLibraryObject(regexPrototype, PropertyIds::sticky, &JavascriptRegExp::EntryInfo::GetterSticky);
  3856. library->regexStickyGetterSlotIndex = 17;
  3857. Assert(regexPrototype->GetSlot(library->regexStickyGetterSlotIndex) == library->regexStickyGetterFunction);
  3858. }
  3859. if (scriptConfig->IsES6UnicodeExtensionsEnabled())
  3860. {
  3861. library->regexUnicodeGetterFunction =
  3862. library->AddGetterToLibraryObject(regexPrototype, PropertyIds::unicode, &JavascriptRegExp::EntryInfo::GetterUnicode);
  3863. library->regexUnicodeGetterSlotIndex = 19;
  3864. Assert(regexPrototype->GetSlot(library->regexUnicodeGetterSlotIndex) == library->regexUnicodeGetterFunction);
  3865. }
  3866. }
  3867. if (scriptConfig->IsES6RegExSymbolsEnabled())
  3868. {
  3869. library->AddFunctionToLibraryObjectWithName(
  3870. regexPrototype,
  3871. PropertyIds::_symbolMatch,
  3872. PropertyIds::_RuntimeFunctionNameId_match,
  3873. &JavascriptRegExp::EntryInfo::SymbolMatch,
  3874. 1);
  3875. library->AddFunctionToLibraryObjectWithName(
  3876. regexPrototype,
  3877. PropertyIds::_symbolReplace,
  3878. PropertyIds::_RuntimeFunctionNameId_replace,
  3879. &JavascriptRegExp::EntryInfo::SymbolReplace,
  3880. 2);
  3881. builtinFuncs[BuiltinFunction::JavascriptRegExp_SymbolSearch] = library->AddFunctionToLibraryObjectWithName(
  3882. regexPrototype,
  3883. PropertyIds::_symbolSearch,
  3884. PropertyIds::_RuntimeFunctionNameId_search,
  3885. &JavascriptRegExp::EntryInfo::SymbolSearch,
  3886. 1);
  3887. library->AddFunctionToLibraryObjectWithName(
  3888. regexPrototype,
  3889. PropertyIds::_symbolSplit,
  3890. PropertyIds::_RuntimeFunctionNameId_split,
  3891. &JavascriptRegExp::EntryInfo::SymbolSplit,
  3892. 2);
  3893. }
  3894. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, library->GetScriptContext()));
  3895. regexPrototype->SetHasNoEnumerableProperties(true);
  3896. library->regexPrototypeType = regexPrototype->GetDynamicType();
  3897. return true;
  3898. }
  3899. bool JavascriptLibrary::InitializeStringConstructor(DynamicObject* stringConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3900. {
  3901. typeHandler->Convert(stringConstructor, mode, 6);
  3902. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterString
  3903. // so that the update is in sync with profiler
  3904. JavascriptLibrary* library = stringConstructor->GetLibrary();
  3905. ScriptContext* scriptContext = stringConstructor->GetScriptContext();
  3906. Field(JavascriptFunction*)* builtinFuncs = library->GetBuiltinFunctions();
  3907. library->AddMember(stringConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  3908. library->AddMember(stringConstructor, PropertyIds::prototype, library->stringPrototype, PropertyNone);
  3909. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3910. {
  3911. library->AddMember(stringConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::String), PropertyConfigurable);
  3912. }
  3913. builtinFuncs[BuiltinFunction::JavascriptString_FromCharCode] = library->AddFunctionToLibraryObject(stringConstructor, PropertyIds::fromCharCode, &JavascriptString::EntryInfo::FromCharCode, 1);
  3914. if(scriptContext->GetConfig()->IsES6UnicodeExtensionsEnabled())
  3915. {
  3916. builtinFuncs[BuiltinFunction::JavascriptString_FromCodePoint] = library->AddFunctionToLibraryObject(stringConstructor, PropertyIds::fromCodePoint, &JavascriptString::EntryInfo::FromCodePoint, 1);
  3917. }
  3918. /* No inlining String_Raw */ library->AddFunctionToLibraryObject(stringConstructor, PropertyIds::raw, &JavascriptString::EntryInfo::Raw, 1);
  3919. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  3920. stringConstructor->SetHasNoEnumerableProperties(true);
  3921. return true;
  3922. }
  3923. bool JavascriptLibrary::InitializeStringPrototype(DynamicObject* stringPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3924. {
  3925. typeHandler->Convert(stringPrototype, mode, 38);
  3926. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterString
  3927. // so that the update is in sync with profiler
  3928. ScriptContext* scriptContext = stringPrototype->GetScriptContext();
  3929. JavascriptLibrary* library = stringPrototype->GetLibrary();
  3930. Field(JavascriptFunction*)* builtinFuncs = library->GetBuiltinFunctions();
  3931. library->AddMember(stringPrototype, PropertyIds::constructor, library->stringConstructor);
  3932. builtinFuncs[BuiltinFunction::JavascriptString_IndexOf] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::indexOf, &JavascriptString::EntryInfo::IndexOf, 1);
  3933. builtinFuncs[BuiltinFunction::JavascriptString_LastIndexOf] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::lastIndexOf, &JavascriptString::EntryInfo::LastIndexOf, 1);
  3934. builtinFuncs[BuiltinFunction::JavascriptString_Replace] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::replace, &JavascriptString::EntryInfo::Replace, 2);
  3935. builtinFuncs[BuiltinFunction::JavascriptString_Search] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::search, &JavascriptString::EntryInfo::Search, 1);
  3936. builtinFuncs[BuiltinFunction::JavascriptString_Slice] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::slice, &JavascriptString::EntryInfo::Slice, 2);
  3937. if (CONFIG_FLAG(ES6Unicode))
  3938. {
  3939. builtinFuncs[BuiltinFunction::JavascriptString_CodePointAt] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::codePointAt, &JavascriptString::EntryInfo::CodePointAt, 1);
  3940. /* builtinFuncs[BuiltinFunction::String_Normalize] =*/library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::normalize, &JavascriptString::EntryInfo::Normalize, 0);
  3941. }
  3942. builtinFuncs[BuiltinFunction::JavascriptString_CharAt] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::charAt, &JavascriptString::EntryInfo::CharAt, 1);
  3943. builtinFuncs[BuiltinFunction::JavascriptString_CharCodeAt] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::charCodeAt, &JavascriptString::EntryInfo::CharCodeAt, 1);
  3944. builtinFuncs[BuiltinFunction::JavascriptString_Concat] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::concat, &JavascriptString::EntryInfo::Concat, 1);
  3945. builtinFuncs[BuiltinFunction::JavascriptString_LocaleCompare] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::localeCompare, &JavascriptString::EntryInfo::LocaleCompare, 1);
  3946. builtinFuncs[BuiltinFunction::JavascriptString_Match] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::match, &JavascriptString::EntryInfo::Match, 1);
  3947. builtinFuncs[BuiltinFunction::JavascriptString_Split] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::split, &JavascriptString::EntryInfo::Split, 2);
  3948. builtinFuncs[BuiltinFunction::JavascriptString_Substring] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::substring, &JavascriptString::EntryInfo::Substring, 2);
  3949. builtinFuncs[BuiltinFunction::JavascriptString_Substr] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::substr, &JavascriptString::EntryInfo::Substr, 2);
  3950. builtinFuncs[BuiltinFunction::JavascriptString_ToLocaleLowerCase] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::toLocaleLowerCase, &JavascriptString::EntryInfo::ToLocaleLowerCase, 0);
  3951. builtinFuncs[BuiltinFunction::JavascriptString_ToLocaleUpperCase] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::toLocaleUpperCase, &JavascriptString::EntryInfo::ToLocaleUpperCase, 0);
  3952. builtinFuncs[BuiltinFunction::JavascriptString_ToLowerCase] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::toLowerCase, &JavascriptString::EntryInfo::ToLowerCase, 0);
  3953. scriptContext->SetBuiltInLibraryFunction(JavascriptString::EntryInfo::ToString.GetOriginalEntryPoint(),
  3954. library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::toString, &JavascriptString::EntryInfo::ToString, 0));
  3955. builtinFuncs[BuiltinFunction::JavascriptString_ToUpperCase] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::toUpperCase, &JavascriptString::EntryInfo::ToUpperCase, 0);
  3956. builtinFuncs[BuiltinFunction::JavascriptString_Trim] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::trim, &JavascriptString::EntryInfo::Trim, 0);
  3957. scriptContext->SetBuiltInLibraryFunction(JavascriptString::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  3958. library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::valueOf, &JavascriptString::EntryInfo::ValueOf, 0));
  3959. /* No inlining String_Anchor */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::anchor, &JavascriptString::EntryInfo::Anchor, 1);
  3960. /* No inlining String_Big */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::big, &JavascriptString::EntryInfo::Big, 0);
  3961. /* No inlining String_Blink */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::blink, &JavascriptString::EntryInfo::Blink, 0);
  3962. /* No inlining String_Bold */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::bold, &JavascriptString::EntryInfo::Bold, 0);
  3963. /* No inlining String_Fixed */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::fixed, &JavascriptString::EntryInfo::Fixed, 0);
  3964. /* No inlining String_FontColor */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::fontcolor, &JavascriptString::EntryInfo::FontColor, 1);
  3965. /* No inlining String_FontSize */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::fontsize, &JavascriptString::EntryInfo::FontSize, 1);
  3966. /* No inlining String_Italics */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::italics, &JavascriptString::EntryInfo::Italics, 0);
  3967. builtinFuncs[BuiltinFunction::JavascriptString_Link] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::link, &JavascriptString::EntryInfo::Link, 1);
  3968. /* No inlining String_Small */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::Small, &JavascriptString::EntryInfo::Small, 0);
  3969. /* No inlining String_Strike */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::strike, &JavascriptString::EntryInfo::Strike, 0);
  3970. /* No inlining String_Sub */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::sub, &JavascriptString::EntryInfo::Sub, 0);
  3971. /* No inlining String_Sup */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::sup, &JavascriptString::EntryInfo::Sup, 0);
  3972. if (scriptContext->GetConfig()->IsES6StringExtensionsEnabled())
  3973. {
  3974. /* No inlining String_Repeat */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::repeat, &JavascriptString::EntryInfo::Repeat, 1);
  3975. /* No inlining String_StartsWith */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::startsWith, &JavascriptString::EntryInfo::StartsWith, 1);
  3976. /* No inlining String_EndsWith */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::endsWith, &JavascriptString::EntryInfo::EndsWith, 1);
  3977. /* No inlining String_Includes */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::includes, &JavascriptString::EntryInfo::Includes, 1);
  3978. builtinFuncs[BuiltinFunction::JavascriptString_TrimLeft] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::trimLeft, &JavascriptString::EntryInfo::TrimLeft, 0);
  3979. builtinFuncs[BuiltinFunction::JavascriptString_TrimRight] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::trimRight, &JavascriptString::EntryInfo::TrimRight, 0);
  3980. }
  3981. library->AddFunctionToLibraryObjectWithName(stringPrototype, PropertyIds::_symbolIterator, PropertyIds::_RuntimeFunctionNameId_iterator, &JavascriptString::EntryInfo::SymbolIterator, 0);
  3982. builtinFuncs[BuiltinFunction::JavascriptString_PadStart] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::padStart, &JavascriptString::EntryInfo::PadStart, 1);
  3983. builtinFuncs[BuiltinFunction::JavascriptString_PadEnd] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::padEnd, &JavascriptString::EntryInfo::PadEnd, 1);
  3984. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  3985. stringPrototype->SetHasNoEnumerableProperties(true);
  3986. return true;
  3987. }
  3988. bool JavascriptLibrary::InitializeMapConstructor(DynamicObject* mapConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3989. {
  3990. typeHandler->Convert(mapConstructor, mode, 3);
  3991. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterMap
  3992. // so that the update is in sync with profiler
  3993. JavascriptLibrary* library = mapConstructor->GetLibrary();
  3994. ScriptContext* scriptContext = mapConstructor->GetScriptContext();
  3995. library->AddMember(mapConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable);
  3996. library->AddMember(mapConstructor, PropertyIds::prototype, library->mapPrototype, PropertyNone);
  3997. library->AddSpeciesAccessorsToLibraryObject(mapConstructor, &JavascriptMap::EntryInfo::GetterSymbolSpecies);
  3998. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3999. {
  4000. library->AddMember(mapConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Map), PropertyConfigurable);
  4001. }
  4002. mapConstructor->SetHasNoEnumerableProperties(true);
  4003. return true;
  4004. }
  4005. bool JavascriptLibrary::InitializeMapPrototype(DynamicObject* mapPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4006. {
  4007. typeHandler->Convert(mapPrototype, mode, 13, true);
  4008. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterMap
  4009. // so that the update is in sync with profiler
  4010. ScriptContext* scriptContext = mapPrototype->GetScriptContext();
  4011. JavascriptLibrary* library = mapPrototype->GetLibrary();
  4012. library->AddMember(mapPrototype, PropertyIds::constructor, library->mapConstructor);
  4013. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::clear, &JavascriptMap::EntryInfo::Clear, 0);
  4014. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::delete_, &JavascriptMap::EntryInfo::Delete, 1);
  4015. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::forEach, &JavascriptMap::EntryInfo::ForEach, 1);
  4016. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::get, &JavascriptMap::EntryInfo::Get, 1);
  4017. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::has, &JavascriptMap::EntryInfo::Has, 1);
  4018. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::set, &JavascriptMap::EntryInfo::Set, 2);
  4019. library->AddAccessorsToLibraryObject(mapPrototype, PropertyIds::size, &JavascriptMap::EntryInfo::SizeGetter, nullptr);
  4020. JavascriptFunction* entriesFunc;
  4021. entriesFunc = library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::entries, &JavascriptMap::EntryInfo::Entries, 0);
  4022. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::keys, &JavascriptMap::EntryInfo::Keys, 0);
  4023. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::values, &JavascriptMap::EntryInfo::Values, 0);
  4024. library->AddMember(mapPrototype, PropertyIds::_symbolIterator, entriesFunc);
  4025. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  4026. {
  4027. library->AddMember(mapPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("Map")), PropertyConfigurable);
  4028. }
  4029. mapPrototype->SetHasNoEnumerableProperties(true);
  4030. return true;
  4031. }
  4032. bool JavascriptLibrary::InitializeSetConstructor(DynamicObject* setConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4033. {
  4034. typeHandler->Convert(setConstructor, mode, 3);
  4035. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSet
  4036. // so that the update is in sync with profiler
  4037. JavascriptLibrary* library = setConstructor->GetLibrary();
  4038. ScriptContext* scriptContext = setConstructor->GetScriptContext();
  4039. library->AddMember(setConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable);
  4040. library->AddMember(setConstructor, PropertyIds::prototype, library->setPrototype, PropertyNone);
  4041. library->AddSpeciesAccessorsToLibraryObject(setConstructor, &JavascriptSet::EntryInfo::GetterSymbolSpecies);
  4042. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  4043. {
  4044. library->AddMember(setConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Set), PropertyConfigurable);
  4045. }
  4046. setConstructor->SetHasNoEnumerableProperties(true);
  4047. return true;
  4048. }
  4049. bool JavascriptLibrary::InitializeSetPrototype(DynamicObject* setPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4050. {
  4051. typeHandler->Convert(setPrototype, mode, 12, true);
  4052. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSet
  4053. // so that the update is in sync with profiler
  4054. ScriptContext* scriptContext = setPrototype->GetScriptContext();
  4055. JavascriptLibrary* library = setPrototype->GetLibrary();
  4056. library->AddMember(setPrototype, PropertyIds::constructor, library->setConstructor);
  4057. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::add, &JavascriptSet::EntryInfo::Add, 1);
  4058. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::clear, &JavascriptSet::EntryInfo::Clear, 0);
  4059. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::delete_, &JavascriptSet::EntryInfo::Delete, 1);
  4060. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::forEach, &JavascriptSet::EntryInfo::ForEach, 1);
  4061. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::has, &JavascriptSet::EntryInfo::Has, 1);
  4062. library->AddAccessorsToLibraryObject(setPrototype, PropertyIds::size, &JavascriptSet::EntryInfo::SizeGetter, nullptr);
  4063. JavascriptFunction* valuesFunc;
  4064. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::entries, &JavascriptSet::EntryInfo::Entries, 0);
  4065. valuesFunc = library->AddFunctionToLibraryObject(setPrototype, PropertyIds::values, &JavascriptSet::EntryInfo::Values, 0);
  4066. library->AddMember(setPrototype, PropertyIds::keys, valuesFunc);
  4067. library->AddMember(setPrototype, PropertyIds::_symbolIterator, valuesFunc);
  4068. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  4069. {
  4070. library->AddMember(setPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("Set")), PropertyConfigurable);
  4071. }
  4072. setPrototype->SetHasNoEnumerableProperties(true);
  4073. return true;
  4074. }
  4075. bool JavascriptLibrary::InitializeWeakMapConstructor(DynamicObject* weakMapConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4076. {
  4077. typeHandler->Convert(weakMapConstructor, mode, 3);
  4078. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterWeakMap
  4079. // so that the update is in sync with profiler
  4080. JavascriptLibrary* library = weakMapConstructor->GetLibrary();
  4081. ScriptContext* scriptContext = weakMapConstructor->GetScriptContext();
  4082. library->AddMember(weakMapConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable);
  4083. library->AddMember(weakMapConstructor, PropertyIds::prototype, library->weakMapPrototype, PropertyNone);
  4084. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  4085. {
  4086. library->AddMember(weakMapConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::WeakMap), PropertyConfigurable);
  4087. }
  4088. weakMapConstructor->SetHasNoEnumerableProperties(true);
  4089. return true;
  4090. }
  4091. bool JavascriptLibrary::InitializeWeakMapPrototype(DynamicObject* weakMapPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4092. {
  4093. typeHandler->Convert(weakMapPrototype, mode, 6);
  4094. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterWeakMap
  4095. // so that the update is in sync with profiler
  4096. ScriptContext* scriptContext = weakMapPrototype->GetScriptContext();
  4097. JavascriptLibrary* library = weakMapPrototype->GetLibrary();
  4098. library->AddMember(weakMapPrototype, PropertyIds::constructor, library->weakMapConstructor);
  4099. library->AddFunctionToLibraryObject(weakMapPrototype, PropertyIds::delete_, &JavascriptWeakMap::EntryInfo::Delete, 1);
  4100. library->AddFunctionToLibraryObject(weakMapPrototype, PropertyIds::get, &JavascriptWeakMap::EntryInfo::Get, 1);
  4101. library->AddFunctionToLibraryObject(weakMapPrototype, PropertyIds::has, &JavascriptWeakMap::EntryInfo::Has, 1);
  4102. library->AddFunctionToLibraryObject(weakMapPrototype, PropertyIds::set, &JavascriptWeakMap::EntryInfo::Set, 2);
  4103. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  4104. {
  4105. library->AddMember(weakMapPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("WeakMap")), PropertyConfigurable);
  4106. }
  4107. weakMapPrototype->SetHasNoEnumerableProperties(true);
  4108. return true;
  4109. }
  4110. bool JavascriptLibrary::InitializeWeakSetConstructor(DynamicObject* weakSetConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4111. {
  4112. typeHandler->Convert(weakSetConstructor, mode, 3);
  4113. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterWeakSet
  4114. // so that the update is in sync with profiler
  4115. JavascriptLibrary* library = weakSetConstructor->GetLibrary();
  4116. ScriptContext* scriptContext = weakSetConstructor->GetScriptContext();
  4117. library->AddMember(weakSetConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable);
  4118. library->AddMember(weakSetConstructor, PropertyIds::prototype, library->weakSetPrototype, PropertyNone);
  4119. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  4120. {
  4121. library->AddMember(weakSetConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::WeakSet), PropertyConfigurable);
  4122. }
  4123. weakSetConstructor->SetHasNoEnumerableProperties(true);
  4124. return true;
  4125. }
  4126. bool JavascriptLibrary::InitializeWeakSetPrototype(DynamicObject* weakSetPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4127. {
  4128. typeHandler->Convert(weakSetPrototype, mode, 5);
  4129. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterWeakSet
  4130. // so that the update is in sync with profiler
  4131. ScriptContext* scriptContext = weakSetPrototype->GetScriptContext();
  4132. JavascriptLibrary* library = weakSetPrototype->GetLibrary();
  4133. library->AddMember(weakSetPrototype, PropertyIds::constructor, library->weakSetConstructor);
  4134. library->AddFunctionToLibraryObject(weakSetPrototype, PropertyIds::add, &JavascriptWeakSet::EntryInfo::Add, 1);
  4135. library->AddFunctionToLibraryObject(weakSetPrototype, PropertyIds::delete_, &JavascriptWeakSet::EntryInfo::Delete, 1);
  4136. library->AddFunctionToLibraryObject(weakSetPrototype, PropertyIds::has, &JavascriptWeakSet::EntryInfo::Has, 1);
  4137. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  4138. {
  4139. library->AddMember(weakSetPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("WeakSet")), PropertyConfigurable);
  4140. }
  4141. weakSetPrototype->SetHasNoEnumerableProperties(true);
  4142. return true;
  4143. }
  4144. bool JavascriptLibrary::InitializeIteratorPrototype(DynamicObject* iteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4145. {
  4146. typeHandler->Convert(iteratorPrototype, mode, 1);
  4147. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterIterator
  4148. // so that the update is in sync with profiler
  4149. JavascriptLibrary* library = iteratorPrototype->GetLibrary();
  4150. library->AddFunctionToLibraryObjectWithName(iteratorPrototype, PropertyIds::_symbolIterator, PropertyIds::_RuntimeFunctionNameId_iterator,
  4151. &JavascriptIterator::EntryInfo::SymbolIterator, 0);
  4152. return true;
  4153. }
  4154. bool JavascriptLibrary::InitializeArrayIteratorPrototype(DynamicObject* arrayIteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4155. {
  4156. typeHandler->Convert(arrayIteratorPrototype, mode, 2);
  4157. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterArrayIterator
  4158. // so that the update is in sync with profiler
  4159. JavascriptLibrary* library = arrayIteratorPrototype->GetLibrary();
  4160. ScriptContext* scriptContext = library->GetScriptContext();
  4161. #ifdef ENABLE_JS_BUILTINS
  4162. Assert(!scriptContext->IsJsBuiltInEnabled());
  4163. #endif
  4164. library->arrayIteratorPrototypeBuiltinNextFunction = library->AddFunctionToLibraryObject(arrayIteratorPrototype, PropertyIds::next, &JavascriptArrayIterator::EntryInfo::Next, 0);
  4165. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  4166. {
  4167. library->AddMember(arrayIteratorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("Array Iterator")), PropertyConfigurable);
  4168. }
  4169. return true;
  4170. }
  4171. bool JavascriptLibrary::InitializeMapIteratorPrototype(DynamicObject* mapIteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4172. {
  4173. typeHandler->Convert(mapIteratorPrototype, mode, 2);
  4174. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterMapIterator
  4175. // so that the update is in sync with profiler
  4176. JavascriptLibrary* library = mapIteratorPrototype->GetLibrary();
  4177. ScriptContext* scriptContext = library->GetScriptContext();
  4178. library->AddFunctionToLibraryObject(mapIteratorPrototype, PropertyIds::next, &JavascriptMapIterator::EntryInfo::Next, 0);
  4179. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  4180. {
  4181. library->AddMember(mapIteratorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("Map Iterator")), PropertyConfigurable);
  4182. }
  4183. return true;
  4184. }
  4185. bool JavascriptLibrary::InitializeSetIteratorPrototype(DynamicObject* setIteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4186. {
  4187. typeHandler->Convert(setIteratorPrototype, mode, 2);
  4188. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSetIterator
  4189. // so that the update is in sync with profiler
  4190. JavascriptLibrary* library = setIteratorPrototype->GetLibrary();
  4191. ScriptContext* scriptContext = library->GetScriptContext();
  4192. library->AddFunctionToLibraryObject(setIteratorPrototype, PropertyIds::next, &JavascriptSetIterator::EntryInfo::Next, 0);
  4193. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  4194. {
  4195. library->AddMember(setIteratorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("Set Iterator")), PropertyConfigurable);
  4196. }
  4197. return true;
  4198. }
  4199. bool JavascriptLibrary::InitializeStringIteratorPrototype(DynamicObject* stringIteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4200. {
  4201. typeHandler->Convert(stringIteratorPrototype, mode, 2);
  4202. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterStringIterator
  4203. // so that the update is in sync with profiler
  4204. JavascriptLibrary* library = stringIteratorPrototype->GetLibrary();
  4205. ScriptContext* scriptContext = library->GetScriptContext();
  4206. library->AddFunctionToLibraryObject(stringIteratorPrototype, PropertyIds::next, &JavascriptStringIterator::EntryInfo::Next, 0);
  4207. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  4208. {
  4209. library->AddMember(stringIteratorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(_u("String Iterator")), PropertyConfigurable);
  4210. }
  4211. return true;
  4212. }
  4213. RuntimeFunction* JavascriptLibrary::CreateBuiltinConstructor(FunctionInfo * functionInfo, DynamicTypeHandler * typeHandler, DynamicObject* prototype)
  4214. {
  4215. Assert((functionInfo->GetAttributes() & FunctionInfo::Attributes::ErrorOnNew) == 0);
  4216. if (prototype == nullptr)
  4217. {
  4218. prototype = functionPrototype;
  4219. }
  4220. ConstructorCache* ctorCache = ((functionInfo->GetAttributes() & FunctionInfo::Attributes::SkipDefaultNewObject) != 0) ?
  4221. static_cast<ConstructorCache*>(this->builtInConstructorCache) : &ConstructorCache::DefaultInstance;
  4222. DynamicType* type = DynamicType::New(scriptContext, TypeIds_Function, prototype, functionInfo->GetOriginalEntryPoint(), typeHandler);
  4223. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, RuntimeFunction, type, functionInfo, ctorCache);
  4224. }
  4225. JavascriptExternalFunction* JavascriptLibrary::CreateExternalConstructor(Js::ExternalMethod entryPoint, PropertyId nameId, RecyclableObject * prototype)
  4226. {
  4227. Assert(nameId >= Js::InternalPropertyIds::Count && scriptContext->IsTrackedPropertyId(nameId));
  4228. JavascriptExternalFunction* function = this->CreateIdMappedExternalFunction(entryPoint, idMappedFunctionWithPrototypeType);
  4229. function->SetFunctionNameId(TaggedInt::ToVarUnchecked(nameId));
  4230. Js::RecyclableObject* objPrototype;
  4231. if (prototype == nullptr)
  4232. {
  4233. objPrototype = CreateConstructorPrototypeObject(function);
  4234. Assert(!objPrototype->IsEnumerable(Js::PropertyIds::constructor));
  4235. }
  4236. else
  4237. {
  4238. objPrototype = Js::RecyclableObject::FromVar(prototype);
  4239. Js::JavascriptOperators::InitProperty(objPrototype, Js::PropertyIds::constructor, function);
  4240. objPrototype->SetEnumerable(Js::PropertyIds::constructor, false);
  4241. }
  4242. Assert(!function->IsEnumerable(Js::PropertyIds::prototype));
  4243. Assert(!function->IsConfigurable(Js::PropertyIds::prototype));
  4244. Assert(!function->IsWritable(Js::PropertyIds::prototype));
  4245. function->SetPropertyWithAttributes(Js::PropertyIds::prototype, objPrototype, PropertyNone, nullptr);
  4246. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  4247. {
  4248. JavascriptString * functionName = nullptr;
  4249. DebugOnly(bool status =) function->GetFunctionName(&functionName);
  4250. AssertMsg(status,"CreateExternalConstructor sets the functionNameId, status should always be true");
  4251. function->SetPropertyWithAttributes(PropertyIds::name, functionName, PropertyConfigurable, nullptr);
  4252. }
  4253. return function;
  4254. }
  4255. JavascriptExternalFunction* JavascriptLibrary::CreateExternalConstructor(Js::ExternalMethod entryPoint, PropertyId nameId, InitializeMethod method, unsigned short deferredTypeSlots, bool hasAccessors)
  4256. {
  4257. Assert(nameId >= Js::InternalPropertyIds::Count && scriptContext->IsTrackedPropertyId(nameId));
  4258. JavascriptExternalFunction* function = nullptr;
  4259. if (entryPoint != nullptr)
  4260. {
  4261. function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptExternalFunction, entryPoint,
  4262. externalConstructorFunctionWithDeferredPrototypeType, method, deferredTypeSlots, hasAccessors);
  4263. }
  4264. else
  4265. {
  4266. function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptExternalFunction,
  4267. defaultExternalConstructorFunctionWithDeferredPrototypeType, method, deferredTypeSlots, hasAccessors);
  4268. }
  4269. function->SetFunctionNameId(TaggedInt::ToVarUnchecked(nameId));
  4270. return function;
  4271. }
  4272. DynamicType* JavascriptLibrary::GetCachedJsrtExternalType(uintptr_t finalizeCallback)
  4273. {
  4274. RecyclerWeakReference<DynamicType>* dynamicTypeWeakRef = nullptr;
  4275. DynamicType* dynamicType = nullptr;
  4276. if (jsrtExternalTypesCache == nullptr)
  4277. {
  4278. jsrtExternalTypesCache = RecyclerNew(recycler, JsrtExternalTypesCache, recycler, 3);
  4279. // Register for periodic cleanup
  4280. scriptContext->RegisterWeakReferenceDictionary(jsrtExternalTypesCache);
  4281. }
  4282. if (jsrtExternalTypesCache->TryGetValue(finalizeCallback, &dynamicTypeWeakRef))
  4283. {
  4284. dynamicType = dynamicTypeWeakRef->Get();
  4285. }
  4286. return dynamicType;
  4287. }
  4288. void JavascriptLibrary::CacheJsrtExternalType(uintptr_t finalizeCallback, DynamicType* dynamicTypeToCache)
  4289. {
  4290. jsrtExternalTypesCache->Item(finalizeCallback, recycler->CreateWeakReferenceHandle<DynamicType>(dynamicTypeToCache));
  4291. }
  4292. void JavascriptLibrary::DefaultCreateFunction(ParseableFunctionInfo * functionInfo, int length, DynamicObject * prototype, PropertyId nameId)
  4293. {
  4294. Assert(nameId >= Js::InternalPropertyIds::Count && scriptContext->IsTrackedPropertyId(nameId));
  4295. ScriptFunction* function = scriptContext->GetLibrary()->CreateScriptFunction(functionInfo);
  4296. function->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(length), PropertyConfigurable, nullptr);
  4297. AddMember(prototype, nameId, function);
  4298. }
  4299. RuntimeFunction* JavascriptLibrary::DefaultCreateFunction(FunctionInfo * functionInfo, int length, DynamicObject * prototype, DynamicType * functionType, PropertyId nameId)
  4300. {
  4301. Assert(nameId >= Js::InternalPropertyIds::Count && scriptContext->IsTrackedPropertyId(nameId));
  4302. return DefaultCreateFunction(functionInfo, length, prototype, functionType, TaggedInt::ToVarUnchecked((int)nameId));
  4303. }
  4304. RuntimeFunction* JavascriptLibrary::DefaultCreateFunction(FunctionInfo * functionInfo, int length, DynamicObject * prototype, DynamicType * functionType, Var nameId)
  4305. {
  4306. Assert(nameId != nullptr);
  4307. RuntimeFunction * function;
  4308. if (nullptr == functionType)
  4309. {
  4310. functionType = (nullptr == prototype) ?
  4311. scriptContext->GetConfig()->IsES6FunctionNameEnabled() ?
  4312. CreateFunctionWithLengthAndNameType(functionInfo) :
  4313. CreateFunctionWithLengthType(functionInfo) :
  4314. CreateFunctionWithLengthAndPrototypeType(functionInfo);
  4315. }
  4316. function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, RuntimeFunction, functionType, functionInfo);
  4317. if (prototype != nullptr)
  4318. {
  4319. // NOTE: Assume all built in function prototype doesn't contain valueOf or toString that has side effects
  4320. function->SetPropertyWithAttributes(PropertyIds::prototype, prototype, PropertyNone, nullptr, PropertyOperation_None, SideEffects_None);
  4321. }
  4322. function->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(length), PropertyConfigurable, nullptr);
  4323. function->SetFunctionNameId(nameId);
  4324. if (function->GetScriptContext()->GetConfig()->IsES6FunctionNameEnabled())
  4325. {
  4326. JavascriptString * functionName = nullptr;
  4327. DebugOnly(bool status = ) function->GetFunctionName(&functionName);
  4328. AssertMsg(status, "DefaultCreateFunction sets the functionNameId, status should always be true");
  4329. function->SetPropertyWithAttributes(PropertyIds::name, functionName, PropertyConfigurable, nullptr);
  4330. }
  4331. #ifdef HEAP_ENUMERATION_VALIDATION
  4332. if (prototype) prototype->SetHeapEnumValidationCookie(HEAP_ENUMERATION_LIBRARY_OBJECT_COOKIE);
  4333. function->SetHeapEnumValidationCookie(HEAP_ENUMERATION_LIBRARY_OBJECT_COOKIE);
  4334. #endif
  4335. return function;
  4336. }
  4337. JavascriptFunction* JavascriptLibrary::AddFunction(DynamicObject* object, PropertyId propertyId, RuntimeFunction* function)
  4338. {
  4339. AddMember(object, propertyId, function);
  4340. function->SetFunctionNameId(TaggedInt::ToVarUnchecked((int)propertyId));
  4341. return function;
  4342. }
  4343. JavascriptFunction * JavascriptLibrary::AddFunctionToLibraryObject(DynamicObject* object, PropertyId propertyId, FunctionInfo * functionInfo, int length, PropertyAttributes attributes)
  4344. {
  4345. RuntimeFunction* function = DefaultCreateFunction(functionInfo, length, nullptr, nullptr, propertyId);
  4346. AddMember(object, propertyId, function, attributes);
  4347. return function;
  4348. }
  4349. JavascriptFunction * JavascriptLibrary::AddFunctionToLibraryObjectWithPrototype(DynamicObject * object, PropertyId propertyId, FunctionInfo * functionInfo, int length, DynamicObject * prototype, DynamicType * functionType)
  4350. {
  4351. RuntimeFunction* function = DefaultCreateFunction(functionInfo, length, prototype, functionType, propertyId);
  4352. AddMember(object, propertyId, function);
  4353. return function;
  4354. }
  4355. JavascriptFunction * JavascriptLibrary::AddFunctionToLibraryObjectWithName(DynamicObject* object, PropertyId propertyId, PropertyId name, FunctionInfo * functionInfo, int length)
  4356. {
  4357. RuntimeFunction* function = DefaultCreateFunction(functionInfo, length, nullptr, nullptr, name);
  4358. AddMember(object, propertyId, function);
  4359. return function;
  4360. }
  4361. RuntimeFunction* JavascriptLibrary::AddGetterToLibraryObject(DynamicObject* object, PropertyId propertyId, FunctionInfo* functionInfo)
  4362. {
  4363. RuntimeFunction* getter = CreateGetterFunction(propertyId, functionInfo);
  4364. AddAccessorsToLibraryObject(object, propertyId, getter, nullptr);
  4365. return getter;
  4366. }
  4367. void JavascriptLibrary::AddAccessorsToLibraryObject(DynamicObject* object, PropertyId propertyId, FunctionInfo * getterFunctionInfo, FunctionInfo * setterFunctionInfo)
  4368. {
  4369. AddAccessorsToLibraryObjectWithName(object, propertyId, propertyId, getterFunctionInfo, setterFunctionInfo);
  4370. }
  4371. void JavascriptLibrary::AddAccessorsToLibraryObject(DynamicObject* object, PropertyId propertyId, RecyclableObject* getterFunction, RecyclableObject* setterFunction)
  4372. {
  4373. if (getterFunction == nullptr)
  4374. {
  4375. getterFunction = GetUndefined();
  4376. }
  4377. if (setterFunction == nullptr)
  4378. {
  4379. setterFunction = GetUndefined();
  4380. }
  4381. object->SetAccessors(propertyId, getterFunction, setterFunction);
  4382. object->SetAttributes(propertyId, PropertyConfigurable | PropertyWritable);
  4383. }
  4384. void JavascriptLibrary::AddAccessorsToLibraryObjectWithName(DynamicObject* object, PropertyId propertyId, PropertyId nameId, FunctionInfo * getterFunctionInfo, FunctionInfo * setterFunctionInfo)
  4385. {
  4386. Js::RuntimeFunction* getterFunction = (getterFunctionInfo != nullptr)
  4387. ? CreateGetterFunction(nameId, getterFunctionInfo)
  4388. : nullptr;
  4389. Js::RuntimeFunction* setterFunction = (setterFunctionInfo != nullptr)
  4390. ? CreateSetterFunction(nameId, setterFunctionInfo)
  4391. : nullptr;
  4392. AddAccessorsToLibraryObject(object, propertyId, getterFunction, setterFunction);
  4393. }
  4394. void JavascriptLibrary::AddSpeciesAccessorsToLibraryObject(DynamicObject* object, FunctionInfo * getterFunctionInfo)
  4395. {
  4396. if (scriptContext->GetConfig()->IsES6SpeciesEnabled())
  4397. {
  4398. AddAccessorsToLibraryObjectWithName(object, PropertyIds::_symbolSpecies, PropertyIds::_RuntimeFunctionNameId_species, getterFunctionInfo, nullptr);
  4399. }
  4400. }
  4401. RuntimeFunction* JavascriptLibrary::CreateGetterFunction(PropertyId nameId, FunctionInfo* functionInfo)
  4402. {
  4403. Var name_withGetPrefix = LiteralString::Concat(LiteralString::NewCopySz(_u("get "), scriptContext), scriptContext->GetPropertyString(nameId));
  4404. RuntimeFunction* getterFunction = DefaultCreateFunction(functionInfo, 0, nullptr, nullptr, name_withGetPrefix);
  4405. getterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable, nullptr);
  4406. return getterFunction;
  4407. }
  4408. RuntimeFunction* JavascriptLibrary::CreateSetterFunction(PropertyId nameId, FunctionInfo* functionInfo)
  4409. {
  4410. Var name_withSetPrefix = LiteralString::Concat(LiteralString::NewCopySz(_u("set "), scriptContext), scriptContext->GetPropertyString(nameId));
  4411. RuntimeFunction* setterFunction = DefaultCreateFunction(functionInfo, 0, nullptr, nullptr, name_withSetPrefix);
  4412. setterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
  4413. return setterFunction;
  4414. }
  4415. void JavascriptLibrary::AddMember(DynamicObject* object, PropertyId propertyId, Var value)
  4416. {
  4417. AddMember(object, propertyId, value, PropertyBuiltInMethodDefaults);
  4418. }
  4419. void JavascriptLibrary::AddMember(DynamicObject* object, PropertyId propertyId, Var value, PropertyAttributes attributes)
  4420. {
  4421. // NOTE: Assume all built in member doesn't have side effect
  4422. object->SetPropertyWithAttributes(propertyId, value, attributes, nullptr, PropertyOperation_None, SideEffects_None);
  4423. }
  4424. bool JavascriptLibrary::InitializeJSONObject(DynamicObject* JSONObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4425. {
  4426. typeHandler->Convert(JSONObject, mode, 3);
  4427. JavascriptLibrary* library = JSONObject->GetLibrary();
  4428. library->AddMember(JSONObject, PropertyIds::stringify, library->EnsureJSONStringifyFunction());
  4429. JSONObject->GetScriptContext()->SetBuiltInLibraryFunction(JSON::EntryInfo::Stringify.GetOriginalEntryPoint(), library->EnsureJSONStringifyFunction());
  4430. library->AddFunctionToLibraryObject(JSONObject, PropertyIds::parse, &JSON::EntryInfo::Parse, 2);
  4431. if (JSONObject->GetScriptContext()->GetConfig()->IsES6ToStringTagEnabled())
  4432. {
  4433. library->AddMember(JSONObject, PropertyIds::_symbolToStringTag, JSONObject->GetLibrary()->CreateStringFromCppLiteral(_u("JSON")), PropertyConfigurable);
  4434. }
  4435. JSONObject->SetHasNoEnumerableProperties(true);
  4436. return true;
  4437. }
  4438. JavascriptFunction* JavascriptLibrary::EnsureJSONStringifyFunction()
  4439. {
  4440. if (jsonStringifyFunction == nullptr)
  4441. {
  4442. jsonStringifyFunction = DefaultCreateFunction(&JSON::EntryInfo::Stringify, 3, nullptr, nullptr, PropertyIds::stringify);
  4443. }
  4444. return jsonStringifyFunction;
  4445. }
  4446. #if defined(ENABLE_INTL_OBJECT) || defined(ENABLE_JS_BUILTINS) || defined(ENABLE_PROJECTION)
  4447. bool JavascriptLibrary::InitializeEngineInterfaceObject(DynamicObject* engineInterface, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4448. {
  4449. typeHandler->Convert(engineInterface, mode, 3);
  4450. EngineInterfaceObject::FromVar(engineInterface)->Initialize();
  4451. engineInterface->SetHasNoEnumerableProperties(true);
  4452. return true;
  4453. }
  4454. #endif
  4455. void JavascriptLibrary::SetNativeHostPromiseContinuationFunction(PromiseContinuationCallback function, void *state)
  4456. {
  4457. this->nativeHostPromiseContinuationFunction = function;
  4458. this->nativeHostPromiseContinuationFunctionState = state;
  4459. }
  4460. void JavascriptLibrary::SetJsrtContext(FinalizableObject* jsrtContext)
  4461. {
  4462. // With JsrtContext supporting cross context, ensure that it doesn't get GCed
  4463. // prematurely. So pin the instance to javascriptLibrary so it will stay alive
  4464. // until any object of it are alive.
  4465. Assert(this->jsrtContextObject == nullptr);
  4466. this->jsrtContextObject = jsrtContext;
  4467. }
  4468. FinalizableObject* JavascriptLibrary::GetJsrtContext()
  4469. {
  4470. return this->jsrtContextObject;
  4471. }
  4472. void JavascriptLibrary::EnqueueTask(Var taskVar)
  4473. {
  4474. Assert(JavascriptFunction::Is(taskVar));
  4475. if(this->nativeHostPromiseContinuationFunction)
  4476. {
  4477. #if ENABLE_TTD
  4478. TTDAssert(this->scriptContext != nullptr, "We shouldn't be adding tasks if this is the case???");
  4479. if(this->scriptContext->ShouldPerformReplayAction())
  4480. {
  4481. this->scriptContext->GetThreadContext()->TTDRootNestingCount++;
  4482. this->scriptContext->GetThreadContext()->TTDLog->ReplayEnqueueTaskEvent(scriptContext, taskVar);
  4483. this->scriptContext->GetThreadContext()->TTDRootNestingCount--;
  4484. }
  4485. else if(this->scriptContext->ShouldPerformRecordAction())
  4486. {
  4487. this->scriptContext->GetThreadContext()->TTDRootNestingCount++;
  4488. TTD::NSLogEvents::EventLogEntry* evt = this->scriptContext->GetThreadContext()->TTDLog->RecordEnqueueTaskEvent(taskVar);
  4489. BEGIN_LEAVE_SCRIPT(this->scriptContext);
  4490. try
  4491. {
  4492. this->nativeHostPromiseContinuationFunction(taskVar, this->nativeHostPromiseContinuationFunctionState);
  4493. }
  4494. catch(...)
  4495. {
  4496. // Hosts are required not to pass exceptions back across the callback boundary. If
  4497. // this happens, it is a bug in the host, not something that we are expected to
  4498. // handle gracefully.
  4499. Js::Throw::FatalInternalError();
  4500. }
  4501. END_LEAVE_SCRIPT(this->scriptContext);
  4502. this->scriptContext->GetThreadContext()->TTDLog->RecordEnqueueTaskEvent_Complete(evt);
  4503. this->scriptContext->GetThreadContext()->TTDRootNestingCount--;
  4504. }
  4505. else
  4506. {
  4507. BEGIN_LEAVE_SCRIPT(scriptContext);
  4508. try
  4509. {
  4510. this->nativeHostPromiseContinuationFunction(taskVar, this->nativeHostPromiseContinuationFunctionState);
  4511. }
  4512. catch(...)
  4513. {
  4514. // Hosts are required not to pass exceptions back across the callback boundary. If
  4515. // this happens, it is a bug in the host, not something that we are expected to
  4516. // handle gracefully.
  4517. Js::Throw::FatalInternalError();
  4518. }
  4519. END_LEAVE_SCRIPT(scriptContext);
  4520. }
  4521. #else
  4522. BEGIN_LEAVE_SCRIPT(scriptContext);
  4523. try
  4524. {
  4525. this->nativeHostPromiseContinuationFunction(taskVar, this->nativeHostPromiseContinuationFunctionState);
  4526. }
  4527. catch (...)
  4528. {
  4529. // Hosts are required not to pass exceptions back across the callback boundary. If
  4530. // this happens, it is a bug in the host, not something that we are expected to
  4531. // handle gracefully.
  4532. Js::Throw::FatalInternalError();
  4533. }
  4534. END_LEAVE_SCRIPT(scriptContext);
  4535. #endif
  4536. }
  4537. else
  4538. {
  4539. #if ENABLE_TTD
  4540. if(this->scriptContext->ShouldPerformRecordOrReplayAction())
  4541. {
  4542. //
  4543. //TODO: need to implement support for this path
  4544. //
  4545. TTDAssert(false, "Path not implemented in TTD!!!");
  4546. }
  4547. #endif
  4548. HRESULT hr = scriptContext->GetHostScriptContext()->EnqueuePromiseTask(taskVar);
  4549. if (hr != S_OK)
  4550. {
  4551. Js::JavascriptError::MapAndThrowError(scriptContext, JSERR_HostMaybeMissingPromiseContinuationCallback);
  4552. }
  4553. }
  4554. }
  4555. #ifdef ENABLE_JS_BUILTINS
  4556. bool JavascriptLibrary::InitializeBuiltInObject(DynamicObject* builtInObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4557. {
  4558. typeHandler->Convert(builtInObject, mode, /*initSlotCapacity*/ 2);
  4559. if (builtInObject->GetScriptContext()->IsJsBuiltInEnabled())
  4560. {
  4561. auto builtInInitializer = [&](JsBuiltInEngineInterfaceExtensionObject* builtInExtension, ScriptContext * scriptContext) -> void
  4562. {
  4563. builtInExtension->InjectJsBuiltInLibraryCode(scriptContext);
  4564. };
  4565. builtInObject->GetLibrary()->InitializeBuiltInForPrototypes(builtInInitializer);
  4566. }
  4567. return true;
  4568. }
  4569. void JavascriptLibrary::EnsureBuiltInEngineIsReady()
  4570. {
  4571. if (scriptContext->IsJsBuiltInEnabled())
  4572. {
  4573. auto builtInInitializer = [&](JsBuiltInEngineInterfaceExtensionObject* builtInExtension, ScriptContext * scriptContext) -> void
  4574. {
  4575. builtInExtension->InjectJsBuiltInLibraryCode(scriptContext);
  4576. };
  4577. scriptContext->GetLibrary()->InitializeBuiltInForPrototypes(builtInInitializer);
  4578. }
  4579. }
  4580. template <class Fn>
  4581. void JavascriptLibrary::InitializeBuiltInForPrototypes(Fn fn)
  4582. {
  4583. if (scriptContext->VerifyAlive()) // Can't initialize if scriptContext closed, will need to run script
  4584. {
  4585. Assert(engineInterfaceObject != nullptr);
  4586. JsBuiltInEngineInterfaceExtensionObject* builtInExtension = static_cast<JsBuiltInEngineInterfaceExtensionObject*>(GetEngineInterfaceObject()->GetEngineExtension(EngineInterfaceExtensionKind_JsBuiltIn));
  4587. fn(builtInExtension, scriptContext);
  4588. }
  4589. }
  4590. bool JavascriptLibrary::InitializeChakraLibraryObject(DynamicObject * chakraLibraryObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4591. {
  4592. JavascriptLibrary* library = chakraLibraryObject->GetLibrary();
  4593. typeHandler->Convert(chakraLibraryObject, mode, 4);
  4594. library->AddFunctionToLibraryObject(chakraLibraryObject, PropertyIds::GetLength, &JsBuiltInEngineInterfaceExtensionObject::EntryInfo::JsBuiltIn_Internal_GetLength, 1);
  4595. library->AddFunctionToLibraryObject(chakraLibraryObject, PropertyIds::InitInternalProperties, &JsBuiltInEngineInterfaceExtensionObject::EntryInfo::JsBuiltIn_Internal_InitInternalProperties, 1);
  4596. library->AddMember(chakraLibraryObject, PropertyIds::isArray, library->isArrayFunction);
  4597. library->AddMember(chakraLibraryObject, PropertyIds::Object, library->objectConstructor);
  4598. return true;
  4599. }
  4600. #endif // ENABLE_JS_BUILTINS
  4601. #ifdef ENABLE_INTL_OBJECT
  4602. void JavascriptLibrary::ResetIntlObject()
  4603. {
  4604. IntlObject = DynamicObject::New(
  4605. recycler,
  4606. DynamicType::New(scriptContext,
  4607. TypeIds_Object, objectPrototype, nullptr,
  4608. DeferredTypeHandler<InitializeIntlObject>::GetDefaultInstance()));
  4609. }
  4610. void JavascriptLibrary::EnsureIntlObjectReady()
  4611. {
  4612. Assert(this->IntlObject != nullptr);
  4613. // For Intl builtins, we need to make sure the Intl object has been initialized before fetching the
  4614. // builtins from the EngineInterfaceObject. This is because the builtins are actually created via
  4615. // Intl.js and are registered into the EngineInterfaceObject as part of Intl object initialization.
  4616. JavascriptExceptionObject * caughtExceptionObject = nullptr;
  4617. try
  4618. {
  4619. this->IntlObject->GetTypeHandler()->EnsureObjectReady(this->IntlObject);
  4620. }
  4621. catch (const JavascriptException& err)
  4622. {
  4623. caughtExceptionObject = err.GetAndClear();
  4624. }
  4625. // Propagate the OOM and SOE exceptions only
  4626. if (caughtExceptionObject != nullptr &&
  4627. (caughtExceptionObject == ThreadContext::GetContextForCurrentThread()->GetPendingOOMErrorObject() ||
  4628. caughtExceptionObject == ThreadContext::GetContextForCurrentThread()->GetPendingSOErrorObject()))
  4629. {
  4630. caughtExceptionObject = caughtExceptionObject->CloneIfStaticExceptionObject(scriptContext);
  4631. JavascriptExceptionOperators::DoThrow(caughtExceptionObject, scriptContext);
  4632. }
  4633. }
  4634. bool JavascriptLibrary::InitializeIntlObject(DynamicObject* IntlObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  4635. {
  4636. typeHandler->Convert(IntlObject, mode, /*initSlotCapacity*/ 2);
  4637. auto intlInitializer = [&](IntlEngineInterfaceExtensionObject* intlExtension, ScriptContext * scriptContext, DynamicObject* intlObject) ->void
  4638. {
  4639. intlExtension->InjectIntlLibraryCode(scriptContext, intlObject, IntlInitializationType::Intl);
  4640. };
  4641. IntlObject->GetLibrary()->InitializeIntlForPrototypes(intlInitializer);
  4642. return true;
  4643. }
  4644. void JavascriptLibrary::InitializeIntlForStringPrototype()
  4645. {
  4646. auto stringPrototypeInitializer = [&](IntlEngineInterfaceExtensionObject* intlExtension, ScriptContext * scriptContext, DynamicObject* intlObject) ->void
  4647. {
  4648. intlExtension->InjectIntlLibraryCode(scriptContext, intlObject, IntlInitializationType::StringPrototype);
  4649. };
  4650. InitializeIntlForPrototypes(stringPrototypeInitializer);
  4651. }
  4652. void JavascriptLibrary::InitializeIntlForDatePrototype()
  4653. {
  4654. auto datePrototypeInitializer = [&](IntlEngineInterfaceExtensionObject* intlExtension, ScriptContext * scriptContext, DynamicObject* intlObject) ->void
  4655. {
  4656. intlExtension->InjectIntlLibraryCode(scriptContext, intlObject, IntlInitializationType::DatePrototype);
  4657. };
  4658. InitializeIntlForPrototypes(datePrototypeInitializer);
  4659. }
  4660. void JavascriptLibrary::InitializeIntlForNumberPrototype()
  4661. {
  4662. auto numberPrototypeInitializer = [&](IntlEngineInterfaceExtensionObject* intlExtension, ScriptContext * scriptContext, DynamicObject* intlObject) ->void
  4663. {
  4664. intlExtension->InjectIntlLibraryCode(scriptContext, intlObject, IntlInitializationType::NumberPrototype);
  4665. };
  4666. InitializeIntlForPrototypes(numberPrototypeInitializer);
  4667. }
  4668. template <class Fn>
  4669. void JavascriptLibrary::InitializeIntlForPrototypes(Fn fn)
  4670. {
  4671. ScriptContext* scriptContext = this->IntlObject->GetScriptContext();
  4672. if (scriptContext->VerifyAlive()) // Can't initialize if scriptContext closed, will need to run script
  4673. {
  4674. JavascriptLibrary* library = this->IntlObject->GetLibrary();
  4675. Assert(library->engineInterfaceObject != nullptr);
  4676. IntlEngineInterfaceExtensionObject* intlExtension = static_cast<IntlEngineInterfaceExtensionObject*>(library->GetEngineInterfaceObject()->GetEngineExtension(EngineInterfaceExtensionKind_Intl));
  4677. fn(intlExtension, scriptContext, IntlObject);
  4678. }
  4679. }
  4680. #endif
  4681. void JavascriptLibrary::SetProfileMode(bool fSet)
  4682. {
  4683. inProfileMode = fSet;
  4684. }
  4685. void JavascriptLibrary::SetDispatchProfile(bool fSet, JavascriptMethod dispatchInvoke)
  4686. {
  4687. if (!fSet)
  4688. {
  4689. this->inDispatchProfileMode = false;
  4690. if (dispatchInvoke != nullptr)
  4691. {
  4692. this->GetScriptContext()->GetHostScriptContext()->SetDispatchInvoke(dispatchInvoke);
  4693. }
  4694. idMappedFunctionWithPrototypeType->SetEntryPoint(JavascriptExternalFunction::ExternalFunctionThunk);
  4695. externalFunctionWithDeferredPrototypeType->SetEntryPoint(JavascriptExternalFunction::ExternalFunctionThunk);
  4696. stdCallFunctionWithDeferredPrototypeType->SetEntryPoint(JavascriptExternalFunction::StdCallExternalFunctionThunk);
  4697. }
  4698. else
  4699. {
  4700. this->inDispatchProfileMode = true;
  4701. if (dispatchInvoke != nullptr)
  4702. {
  4703. this->GetScriptContext()->GetHostScriptContext()->SetDispatchInvoke(dispatchInvoke);
  4704. }
  4705. idMappedFunctionWithPrototypeType->SetEntryPoint(ProfileEntryThunk);
  4706. externalFunctionWithDeferredPrototypeType->SetEntryPoint(ProfileEntryThunk);
  4707. stdCallFunctionWithDeferredPrototypeType->SetEntryPoint(ProfileEntryThunk);
  4708. }
  4709. }
  4710. JavascriptString* JavascriptLibrary::CreateEmptyString()
  4711. {
  4712. return LiteralStringWithPropertyStringPtr::CreateEmptyString(this);
  4713. }
  4714. JavascriptRegExp* JavascriptLibrary::CreateEmptyRegExp()
  4715. {
  4716. return RecyclerNew(scriptContext->GetRecycler(), JavascriptRegExp, emptyRegexPattern,
  4717. this->GetRegexType());
  4718. }
  4719. #if ENABLE_TTD
  4720. Js::PropertyId JavascriptLibrary::ExtractPrimitveSymbolId_TTD(Var value)
  4721. {
  4722. return Js::JavascriptSymbol::FromVar(value)->GetValue()->GetPropertyId();
  4723. }
  4724. Js::RecyclableObject* JavascriptLibrary::CreatePrimitveSymbol_TTD(Js::PropertyId pid)
  4725. {
  4726. return this->CreateSymbol(this->scriptContext->GetPropertyName(pid));
  4727. }
  4728. Js::RecyclableObject* JavascriptLibrary::CreatePrimitveSymbol_TTD(Js::JavascriptString* str)
  4729. {
  4730. return this->CreateSymbol(str);
  4731. }
  4732. Js::RecyclableObject* JavascriptLibrary::CreateDefaultBoxedObject_TTD(Js::TypeId kind)
  4733. {
  4734. switch(kind)
  4735. {
  4736. case Js::TypeIds_BooleanObject:
  4737. return this->CreateBooleanObject();
  4738. case Js::TypeIds_NumberObject:
  4739. return this->CreateNumberObject(Js::TaggedInt::ToVarUnchecked(0));
  4740. case Js::TypeIds_StringObject:
  4741. return this->CreateStringObject(nullptr);
  4742. case Js::TypeIds_SymbolObject:
  4743. return this->CreateSymbolObject(nullptr);
  4744. default:
  4745. TTDAssert(false, "Unsupported nullptr value boxed object.");
  4746. return nullptr;
  4747. }
  4748. }
  4749. void JavascriptLibrary::SetBoxedObjectValue_TTD(Js::RecyclableObject* obj, Js::Var value)
  4750. {
  4751. switch(obj->GetTypeId())
  4752. {
  4753. case Js::TypeIds_BooleanObject:
  4754. Js::JavascriptBooleanObject::FromVar(obj)->SetValue_TTD(value);
  4755. break;
  4756. case Js::TypeIds_NumberObject:
  4757. Js::JavascriptNumberObject::FromVar(obj)->SetValue_TTD(value);
  4758. break;
  4759. case Js::TypeIds_StringObject:
  4760. Js::JavascriptStringObject::FromVar(obj)->SetValue_TTD(value);
  4761. break;
  4762. case Js::TypeIds_SymbolObject:
  4763. Js::JavascriptSymbolObject::FromVar(obj)->SetValue_TTD(value);
  4764. break;
  4765. default:
  4766. TTDAssert(false, "Unsupported nullptr value boxed object.");
  4767. break;
  4768. }
  4769. }
  4770. Js::RecyclableObject* JavascriptLibrary::CreateDate_TTD(double value)
  4771. {
  4772. return this->CreateDate(value);
  4773. }
  4774. Js::RecyclableObject* JavascriptLibrary::CreateRegex_TTD(const char16* patternSource, uint32 patternLength, UnifiedRegex::RegexFlags flags, CharCount lastIndex, Js::Var lastVar)
  4775. {
  4776. Js::JavascriptRegExp* re = Js::JavascriptRegExp::CreateRegEx(patternSource, patternLength, flags, this->scriptContext);
  4777. re->SetLastIndexInfo_TTD(lastIndex, lastVar);
  4778. return re;
  4779. }
  4780. Js::RecyclableObject* JavascriptLibrary::CreateError_TTD()
  4781. {
  4782. return this->CreateError();
  4783. }
  4784. Js::RecyclableObject* JavascriptLibrary::CreateES5Array_TTD()
  4785. {
  4786. Js::JavascriptArray* arrayObj = this->CreateArray();
  4787. arrayObj->GetTypeHandler()->ConvertToTypeWithItemAttributes(arrayObj);
  4788. return arrayObj;
  4789. }
  4790. void JavascriptLibrary::SetLengthWritableES5Array_TTD(Js::RecyclableObject* es5Array, bool isLengthWritable)
  4791. {
  4792. Js::ES5Array* es5a = Js::ES5Array::FromVar(es5Array);
  4793. if(es5a->IsLengthWritable() != isLengthWritable)
  4794. {
  4795. es5a->SetWritable(Js::PropertyIds::length, isLengthWritable ? TRUE : FALSE);
  4796. }
  4797. }
  4798. Js::RecyclableObject* JavascriptLibrary::CreateSet_TTD()
  4799. {
  4800. return JavascriptSet::CreateForSnapshotRestore(this->scriptContext);
  4801. }
  4802. Js::RecyclableObject* JavascriptLibrary::CreateWeakSet_TTD()
  4803. {
  4804. return this->CreateWeakSet();
  4805. }
  4806. void JavascriptLibrary::AddSetElementInflate_TTD(Js::JavascriptSet* set, Var value)
  4807. {
  4808. set->Add(value);
  4809. }
  4810. void JavascriptLibrary::AddWeakSetElementInflate_TTD(Js::JavascriptWeakSet* set, Var value)
  4811. {
  4812. set->GetScriptContext()->TTDContextInfo->TTDWeakReferencePinSet->Add(Js::DynamicObject::FromVar(value));
  4813. set->Add(Js::DynamicObject::FromVar(value));
  4814. }
  4815. Js::RecyclableObject* JavascriptLibrary::CreateMap_TTD()
  4816. {
  4817. return JavascriptMap::CreateForSnapshotRestore(this->scriptContext);
  4818. }
  4819. Js::RecyclableObject* JavascriptLibrary::CreateWeakMap_TTD()
  4820. {
  4821. return this->CreateWeakMap();
  4822. }
  4823. void JavascriptLibrary::AddMapElementInflate_TTD(Js::JavascriptMap* map, Var key, Var value)
  4824. {
  4825. map->Set(key, value);
  4826. }
  4827. void JavascriptLibrary::AddWeakMapElementInflate_TTD(Js::JavascriptWeakMap* map, Var key, Var value)
  4828. {
  4829. map->GetScriptContext()->TTDContextInfo->TTDWeakReferencePinSet->Add(Js::DynamicObject::FromVar(key));
  4830. map->Set(Js::DynamicObject::FromVar(key), value);
  4831. }
  4832. Js::RecyclableObject* JavascriptLibrary::CreateExternalFunction_TTD(Js::Var fname)
  4833. {
  4834. if(TaggedInt::Is(fname))
  4835. {
  4836. PropertyId pid = TaggedInt::ToInt32(fname);
  4837. if(!scriptContext->IsTrackedPropertyId(pid))
  4838. {
  4839. scriptContext->TrackPid(pid);
  4840. }
  4841. }
  4842. JavascriptExternalFunction* function = this->CreateIdMappedExternalFunction(&JavascriptExternalFunction::TTDReplayDummyExternalMethod, stdCallFunctionWithDeferredPrototypeType);
  4843. function->SetFunctionNameId(fname);
  4844. function->SetCallbackState(nullptr);
  4845. return function;
  4846. }
  4847. Js::RecyclableObject* JavascriptLibrary::CreateBoundFunction_TTD(
  4848. RecyclableObject* function, Var bThis, uint32 ct, Field(Var)* args)
  4849. {
  4850. return BoundFunction::InflateBoundFunction(this->scriptContext, function, bThis, ct, args);
  4851. }
  4852. Js::RecyclableObject* JavascriptLibrary::CreateProxy_TTD(RecyclableObject* handler, RecyclableObject* target)
  4853. {
  4854. JavascriptProxy* newProxy = RecyclerNew(this->scriptContext->GetRecycler(), JavascriptProxy, this->GetProxyType(), this->scriptContext, target, handler);
  4855. if(target != nullptr && JavascriptConversion::IsCallable(target))
  4856. {
  4857. newProxy->ChangeType();
  4858. newProxy->GetDynamicType()->SetEntryPoint(JavascriptProxy::FunctionCallTrap);
  4859. }
  4860. return newProxy;
  4861. }
  4862. Js::RecyclableObject* JavascriptLibrary::CreateRevokeFunction_TTD(RecyclableObject* proxy)
  4863. {
  4864. RuntimeFunction* revoker = RecyclerNewEnumClass(this->scriptContext->GetRecycler(), JavascriptLibrary::EnumFunctionClass, RuntimeFunction, this->CreateFunctionWithLengthType(&JavascriptProxy::EntryInfo::Revoke), &JavascriptProxy::EntryInfo::Revoke);
  4865. revoker->SetPropertyWithAttributes(Js::PropertyIds::length, Js::TaggedInt::ToVarUnchecked(0), PropertyNone, NULL);
  4866. revoker->SetInternalProperty(Js::InternalPropertyIds::RevocableProxy, proxy, PropertyOperationFlags::PropertyOperation_Force, nullptr);
  4867. return revoker;
  4868. }
  4869. Js::RecyclableObject* JavascriptLibrary::CreateHeapArguments_TTD(uint32 numOfArguments, uint32 formalCount, ActivationObject* frameObject, byte* deletedArray)
  4870. {
  4871. Js::HeapArgumentsObject* argsObj = this->CreateHeapArguments(frameObject, formalCount);
  4872. argsObj->SetNumberOfArguments(numOfArguments);
  4873. for(uint32 i = 0; i < formalCount; ++i)
  4874. {
  4875. if(deletedArray[i])
  4876. {
  4877. argsObj->DeleteItemAt(i);
  4878. }
  4879. }
  4880. return argsObj;
  4881. }
  4882. Js::RecyclableObject* JavascriptLibrary::CreateES5HeapArguments_TTD(uint32 numOfArguments, uint32 formalCount, ActivationObject* frameObject, byte* deletedArray)
  4883. {
  4884. Js::HeapArgumentsObject* argsObj = this->CreateHeapArguments(frameObject, formalCount);
  4885. argsObj->SetNumberOfArguments(numOfArguments);
  4886. for(uint32 i = 0; i < formalCount; ++i)
  4887. {
  4888. if(deletedArray[i])
  4889. {
  4890. argsObj->DeleteItemAt(i);
  4891. }
  4892. }
  4893. return argsObj->ConvertToES5HeapArgumentsObject_TTD();
  4894. }
  4895. Js::JavascriptPromiseCapability* JavascriptLibrary::CreatePromiseCapability_TTD(Var promise, Var resolve, Var reject)
  4896. {
  4897. return JavascriptPromiseCapability::New(promise, resolve, reject, this->scriptContext);
  4898. }
  4899. Js::JavascriptPromiseReaction* JavascriptLibrary::CreatePromiseReaction_TTD(RecyclableObject* handler, JavascriptPromiseCapability* capabilities)
  4900. {
  4901. return JavascriptPromiseReaction::New(capabilities, handler, this->scriptContext);
  4902. }
  4903. Js::RecyclableObject* JavascriptLibrary::CreatePromise_TTD(uint32 status, Var result, JsUtil::List<Js::JavascriptPromiseReaction*, HeapAllocator>& resolveReactions, JsUtil::List<Js::JavascriptPromiseReaction*, HeapAllocator>& rejectReactions)
  4904. {
  4905. return JavascriptPromise::InitializePromise_TTD(this->scriptContext, status, result, resolveReactions, rejectReactions);
  4906. }
  4907. JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* JavascriptLibrary::CreateAlreadyDefinedWrapper_TTD(bool alreadyDefined)
  4908. {
  4909. JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* alreadyResolvedRecord = RecyclerNewStructZ(scriptContext->GetRecycler(), JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper);
  4910. alreadyResolvedRecord->alreadyResolved = alreadyDefined;
  4911. return alreadyResolvedRecord;
  4912. }
  4913. Js::RecyclableObject* JavascriptLibrary::CreatePromiseResolveOrRejectFunction_TTD(RecyclableObject* promise, bool isReject, JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* alreadyResolved)
  4914. {
  4915. TTDAssert(JavascriptPromise::Is(promise), "Not a promise!");
  4916. return this->CreatePromiseResolveOrRejectFunction(JavascriptPromise::EntryResolveOrRejectFunction, static_cast<JavascriptPromise*>(promise), isReject, alreadyResolved);
  4917. }
  4918. Js::RecyclableObject* JavascriptLibrary::CreatePromiseReactionTaskFunction_TTD(JavascriptPromiseReaction* reaction, Var argument)
  4919. {
  4920. return this->CreatePromiseReactionTaskFunction(JavascriptPromise::EntryReactionTaskFunction, reaction, argument);
  4921. }
  4922. JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* JavascriptLibrary::CreateRemainingElementsWrapper_TTD(Js::ScriptContext* ctx, uint32 value)
  4923. {
  4924. JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* remainingElementsWrapper = RecyclerNewStructZ(ctx->GetRecycler(), JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper);
  4925. remainingElementsWrapper->remainingElements = value;
  4926. return remainingElementsWrapper;
  4927. }
  4928. Js::RecyclableObject* JavascriptLibrary::CreatePromiseAllResolveElementFunction_TTD(Js::JavascriptPromiseCapability* capabilities, uint32 index, Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* wrapper, Js::RecyclableObject* values, bool alreadyCalled)
  4929. {
  4930. Js::JavascriptPromiseAllResolveElementFunction* res = this->CreatePromiseAllResolveElementFunction(JavascriptPromise::EntryAllResolveElementFunction, index, Js::JavascriptArray::FromVar(values), capabilities, wrapper);
  4931. res->SetAlreadyCalled(alreadyCalled);
  4932. return res;
  4933. }
  4934. #endif
  4935. void JavascriptLibrary::SetCrossSiteForSharedFunctionType(JavascriptFunction * function)
  4936. {
  4937. Assert(function->GetDynamicType()->GetIsShared());
  4938. if (ScriptFunction::Is(function))
  4939. {
  4940. #if DEBUG
  4941. if (!function->GetFunctionProxy()->GetIsAnonymousFunction())
  4942. {
  4943. Assert(function->GetFunctionInfo()->IsConstructor() ?
  4944. (function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler(this->GetScriptContext())
  4945. || function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredPrototypeFunctionWithLengthTypeHandler(this->GetScriptContext()))
  4946. : function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredFunctionTypeHandler());
  4947. }
  4948. else
  4949. {
  4950. Assert(function->GetFunctionInfo()->IsConstructor() ?
  4951. function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredAnonymousPrototypeFunctionTypeHandler() :
  4952. function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredAnonymousFunctionTypeHandler());
  4953. }
  4954. #endif
  4955. function->ChangeType();
  4956. function->SetEntryPoint(scriptContext->CurrentCrossSiteThunk);
  4957. }
  4958. else if (BoundFunction::Is(function))
  4959. {
  4960. function->ChangeType();
  4961. function->SetEntryPoint(scriptContext->CurrentCrossSiteThunk);
  4962. }
  4963. else
  4964. {
  4965. DynamicTypeHandler * typeHandler = function->GetDynamicType()->GetTypeHandler();
  4966. if (typeHandler == JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler(this->GetScriptContext())
  4967. || typeHandler == JavascriptLibrary::GetDeferredPrototypeFunctionWithLengthTypeHandler(this->GetScriptContext()))
  4968. {
  4969. function->ReplaceType(crossSiteDeferredPrototypeFunctionType);
  4970. }
  4971. else if (typeHandler == Js::DeferredTypeHandler<Js::JavascriptExternalFunction::DeferredConstructorInitializer>::GetDefaultInstance())
  4972. {
  4973. function->ReplaceType(crossSiteExternalConstructFunctionWithPrototypeType);
  4974. }
  4975. else
  4976. {
  4977. Assert(typeHandler == &SharedIdMappedFunctionWithPrototypeTypeHandler);
  4978. function->ReplaceType(crossSiteIdMappedFunctionWithPrototypeType);
  4979. }
  4980. }
  4981. }
  4982. JavascriptExternalFunction*
  4983. JavascriptLibrary::CreateExternalFunction(ExternalMethod entryPoint, PropertyId nameId, Var signature, UINT64 flags, bool isLengthAvailable)
  4984. {
  4985. Assert(nameId == 0 || scriptContext->IsTrackedPropertyId(nameId));
  4986. return CreateExternalFunction(entryPoint, TaggedInt::ToVarUnchecked(nameId), signature, flags, isLengthAvailable);
  4987. }
  4988. JavascriptExternalFunction*
  4989. JavascriptLibrary::CreateExternalFunction(ExternalMethod entryPoint, Var nameId, Var signature, UINT64 flags, bool isLengthAvailable)
  4990. {
  4991. JavascriptExternalFunction* function = this->CreateIdMappedExternalFunction(entryPoint, isLengthAvailable ? externalFunctionWithLengthAndDeferredPrototypeType : externalFunctionWithDeferredPrototypeType);
  4992. function->SetExternalFlags(flags);
  4993. function->SetFunctionNameId(nameId);
  4994. function->SetSignature(signature);
  4995. #ifdef HEAP_ENUMERATION_VALIDATION
  4996. function->SetHeapEnumValidationCookie(HEAP_ENUMERATION_LIBRARY_OBJECT_COOKIE);
  4997. #endif
  4998. JS_ETW_INTERNAL(EventWriteJSCRIPT_BUILD_DIRECT_FUNCTION(scriptContext, function, TaggedInt::Is(nameId) ? scriptContext->GetThreadContext()->GetPropertyName(TaggedInt::ToInt32(nameId))->GetBuffer() : ((JavascriptString *)nameId)->GetString()));
  4999. #if DBG_DUMP
  5000. if (Js::Configuration::Global.flags.Trace.IsEnabled(Js::HostPhase))
  5001. {
  5002. Output::Print(_u("Create new external function: methodAddr= %p, propertyRecord= %p, propertyName= %s\n"),
  5003. this, nameId,
  5004. TaggedInt::Is(nameId) ? scriptContext->GetThreadContext()->GetPropertyName(TaggedInt::ToInt32(nameId))->GetBuffer() : ((JavascriptString *)nameId)->GetString());
  5005. }
  5006. #endif
  5007. return function;
  5008. }
  5009. void JavascriptLibrary::EnsureStringTemplateCallsiteObjectList()
  5010. {
  5011. if (this->stringTemplateCallsiteObjectList == nullptr)
  5012. {
  5013. this->stringTemplateCallsiteObjectList = RecyclerNew(GetRecycler(), StringTemplateCallsiteObjectList, GetRecycler());
  5014. }
  5015. }
  5016. void JavascriptLibrary::AddStringTemplateCallsiteObject(RecyclableObject* callsite)
  5017. {
  5018. this->EnsureStringTemplateCallsiteObjectList();
  5019. RecyclerWeakReference<RecyclableObject>* callsiteRef = this->GetRecycler()->CreateWeakReferenceHandle<RecyclableObject>(callsite);
  5020. this->stringTemplateCallsiteObjectList->Item(callsiteRef);
  5021. }
  5022. RecyclableObject* JavascriptLibrary::TryGetStringTemplateCallsiteObject(ParseNodePtr pnode)
  5023. {
  5024. this->EnsureStringTemplateCallsiteObjectList();
  5025. RecyclerWeakReference<RecyclableObject>* callsiteRef = this->stringTemplateCallsiteObjectList->LookupWithKey(pnode);
  5026. if (callsiteRef)
  5027. {
  5028. RecyclableObject* callsite = callsiteRef->Get();
  5029. if (callsite)
  5030. {
  5031. return callsite;
  5032. }
  5033. }
  5034. return nullptr;
  5035. }
  5036. RecyclableObject* JavascriptLibrary::TryGetStringTemplateCallsiteObject(RecyclableObject* callsite)
  5037. {
  5038. this->EnsureStringTemplateCallsiteObjectList();
  5039. RecyclerWeakReference<RecyclableObject>* callsiteRef = this->GetRecycler()->CreateWeakReferenceHandle<RecyclableObject>(callsite);
  5040. RecyclerWeakReference<RecyclableObject>* existingCallsiteRef = this->stringTemplateCallsiteObjectList->LookupWithKey(callsiteRef);
  5041. if (existingCallsiteRef)
  5042. {
  5043. RecyclableObject* existingCallsite = existingCallsiteRef->Get();
  5044. if (existingCallsite)
  5045. {
  5046. return existingCallsite;
  5047. }
  5048. }
  5049. return nullptr;
  5050. }
  5051. #if DBG_DUMP
  5052. const char16* JavascriptLibrary::GetStringTemplateCallsiteObjectKey(Var callsite)
  5053. {
  5054. // Calculate the key for the string template callsite object.
  5055. // Key is combination of the raw string literals delimited by '${}' since string template literals cannot include that symbol.
  5056. // `str1${expr1}str2${expr2}str3` => "str1${}str2${}str3"
  5057. ES5Array* callsiteObj = ES5Array::FromVar(callsite);
  5058. ScriptContext* scriptContext = callsiteObj->GetScriptContext();
  5059. Var var = JavascriptOperators::OP_GetProperty(callsiteObj, Js::PropertyIds::raw, scriptContext);
  5060. ES5Array* rawArray = ES5Array::FromVar(var);
  5061. uint32 arrayLength = rawArray->GetLength();
  5062. uint32 totalStringLength = 0;
  5063. JavascriptString* str;
  5064. Assert(arrayLength != 0);
  5065. // Count the size in characters of the raw strings
  5066. for (uint32 i = 0; i < arrayLength; i++)
  5067. {
  5068. rawArray->DirectGetItemAt(i, &var);
  5069. str = JavascriptString::FromVar(var);
  5070. totalStringLength += str->GetLength();
  5071. }
  5072. uint32 keyLength = totalStringLength + (arrayLength - 1) * 3 + 1;
  5073. char16* key = RecyclerNewArray(scriptContext->GetRecycler(), char16, keyLength);
  5074. char16* ptr = key;
  5075. charcount_t remainingSpace = keyLength;
  5076. // Get first item before loop - there always must be at least one item
  5077. rawArray->DirectGetItemAt(0, &var);
  5078. str = JavascriptString::FromVar(var);
  5079. charcount_t len = str->GetLength();
  5080. js_wmemcpy_s(ptr, remainingSpace, str->GetSz(), len);
  5081. ptr += len;
  5082. remainingSpace -= len;
  5083. // Append a delimiter and the rest of the items
  5084. for (uint32 i = 1; i < arrayLength; i++)
  5085. {
  5086. len = 3; // strlen(_u("${}"));
  5087. js_wmemcpy_s(ptr, remainingSpace, _u("${}"), len);
  5088. ptr += len;
  5089. remainingSpace -= len;
  5090. rawArray->DirectGetItemAt(i, &var);
  5091. str = JavascriptString::FromVar(var);
  5092. len = str->GetLength();
  5093. js_wmemcpy_s(ptr, remainingSpace, str->GetSz(), len);
  5094. ptr += len;
  5095. remainingSpace -= len;
  5096. }
  5097. // Ensure string is terminated
  5098. key[keyLength - 1] = _u('\0');
  5099. return key;
  5100. }
  5101. #endif
  5102. bool StringTemplateCallsiteObjectComparer<ParseNodePtr>::Equals(ParseNodePtr x, RecyclerWeakReference<Js::RecyclableObject>* y)
  5103. {
  5104. Assert(x != nullptr);
  5105. Assert(x->nop == knopStrTemplate);
  5106. Js::RecyclableObject* obj = y->Get();
  5107. // If the weak reference is dead, we can't be equal.
  5108. if (obj == nullptr)
  5109. {
  5110. return false;
  5111. }
  5112. Js::ES5Array* callsite = Js::ES5Array::FromVar(obj);
  5113. uint32 length = callsite->GetLength();
  5114. Js::Var element;
  5115. Js::JavascriptString* str;
  5116. IdentPtr pid;
  5117. // If the length of string literals is different, these callsite objects are not equal.
  5118. if (x->sxStrTemplate.countStringLiterals != length)
  5119. {
  5120. return false;
  5121. }
  5122. JS_REENTRANCY_LOCK(reentrancyLock, callsite->GetScriptContext()->GetThreadContext());
  5123. Unused(reentrancyLock);
  5124. element = Js::JavascriptOperators::OP_GetProperty(callsite, Js::PropertyIds::raw, callsite->GetScriptContext());
  5125. Js::ES5Array* rawArray = Js::ES5Array::FromVar(element);
  5126. // Length of the raw strings should be the same as the cooked string literals.
  5127. AssertOrFailFast(length != 0 && length == rawArray->GetLength());
  5128. x = x->sxStrTemplate.pnodeStringRawLiterals;
  5129. for (uint32 i = 0; i < length - 1; i++)
  5130. {
  5131. BOOL hasElem = rawArray->DirectGetItemAt(i, &element);
  5132. AssertOrFailFast(hasElem);
  5133. str = Js::JavascriptString::FromVar(element);
  5134. Assert(x->nop == knopList);
  5135. Assert(x->sxBin.pnode1->nop == knopStr);
  5136. pid = x->sxBin.pnode1->sxPid.pid;
  5137. // If strings have different length, they aren't equal
  5138. if (pid->Cch() != str->GetLength())
  5139. {
  5140. return false;
  5141. }
  5142. // If the strings at this index are not equal, the callsite objects are not equal.
  5143. if (!JsUtil::CharacterBuffer<char16>::StaticEquals(pid->Psz(), str->GetSz(), str->GetLength()))
  5144. {
  5145. return false;
  5146. }
  5147. x = x->sxBin.pnode2;
  5148. }
  5149. // There should be one more string in the callsite array - and the final string in the ParseNode
  5150. BOOL hasLastElem = rawArray->DirectGetItemAt(length - 1, &element);
  5151. AssertOrFailFast(hasLastElem);
  5152. str = Js::JavascriptString::FromVar(element);
  5153. Assert(x->nop == knopStr);
  5154. pid = x->sxPid.pid;
  5155. // If strings have different length, they aren't equal
  5156. if (pid->Cch() != str->GetLength())
  5157. {
  5158. return false;
  5159. }
  5160. // If the strings at this index are not equal, the callsite objects are not equal.
  5161. if (!JsUtil::CharacterBuffer<char16>::StaticEquals(pid->Psz(), str->GetSz(), str->GetLength()))
  5162. {
  5163. return false;
  5164. }
  5165. return true;
  5166. }
  5167. bool StringTemplateCallsiteObjectComparer<ParseNodePtr>::Equals(ParseNodePtr x, ParseNodePtr y)
  5168. {
  5169. Assert(x != nullptr && y != nullptr);
  5170. Assert(x->nop == knopStrTemplate && y->nop == knopStrTemplate);
  5171. // If the ParseNode is the same, they are equal.
  5172. if (x == y)
  5173. {
  5174. return true;
  5175. }
  5176. x = x->sxStrTemplate.pnodeStringRawLiterals;
  5177. y = y->sxStrTemplate.pnodeStringRawLiterals;
  5178. // If one of the templates only includes one string value, the raw literals ParseNode will
  5179. // be a knopStr instead of knopList.
  5180. if (x->nop != y->nop)
  5181. {
  5182. return false;
  5183. }
  5184. const char16* pid_x;
  5185. const char16* pid_y;
  5186. while (x->nop == knopList)
  5187. {
  5188. // If y is knopStr here, that means x has more strings in the list than y does.
  5189. if (y->nop != knopList)
  5190. {
  5191. return false;
  5192. }
  5193. Assert(x->sxBin.pnode1->nop == knopStr);
  5194. Assert(y->sxBin.pnode1->nop == knopStr);
  5195. pid_x = x->sxBin.pnode1->sxPid.pid->Psz();
  5196. pid_y = y->sxBin.pnode1->sxPid.pid->Psz();
  5197. // If the pid values of each raw string don't match each other, these are different.
  5198. if (!DefaultComparer<const char16*>::Equals(pid_x, pid_y))
  5199. {
  5200. return false;
  5201. }
  5202. x = x->sxBin.pnode2;
  5203. y = y->sxBin.pnode2;
  5204. }
  5205. // If y is still knopList here, that means y has more strings in the list than x does.
  5206. if (y->nop != knopStr)
  5207. {
  5208. return false;
  5209. }
  5210. Assert(x->nop == knopStr);
  5211. pid_x = x->sxPid.pid->Psz();
  5212. pid_y = y->sxPid.pid->Psz();
  5213. // This is the final string in the raw literals list. Return true if they are equal.
  5214. return DefaultComparer<const char16*>::Equals(pid_x, pid_y);
  5215. }
  5216. hash_t StringTemplateCallsiteObjectComparer<ParseNodePtr>::GetHashCode(ParseNodePtr i)
  5217. {
  5218. hash_t hash = 0;
  5219. Assert(i != nullptr);
  5220. Assert(i->nop == knopStrTemplate);
  5221. i = i->sxStrTemplate.pnodeStringRawLiterals;
  5222. const char16* pid;
  5223. while (i->nop == knopList)
  5224. {
  5225. Assert(i->sxBin.pnode1->nop == knopStr);
  5226. pid = i->sxBin.pnode1->sxPid.pid->Psz();
  5227. hash ^= DefaultComparer<const char16*>::GetHashCode(pid);
  5228. hash ^= DefaultComparer<const char16*>::GetHashCode(_u("${}"));
  5229. i = i->sxBin.pnode2;
  5230. }
  5231. Assert(i->nop == knopStr);
  5232. pid = i->sxPid.pid->Psz();
  5233. hash ^= DefaultComparer<const char16*>::GetHashCode(pid);
  5234. return hash;
  5235. }
  5236. bool StringTemplateCallsiteObjectComparer<RecyclerWeakReference<Js::RecyclableObject>*>::Equals(RecyclerWeakReference<Js::RecyclableObject>* x, ParseNodePtr y)
  5237. {
  5238. return StringTemplateCallsiteObjectComparer<ParseNodePtr>::Equals(y, x);
  5239. }
  5240. bool StringTemplateCallsiteObjectComparer<RecyclerWeakReference<Js::RecyclableObject>*>::Equals(RecyclerWeakReference<Js::RecyclableObject>* x, RecyclerWeakReference<Js::RecyclableObject>* y)
  5241. {
  5242. Js::RecyclableObject* objLeft = x->Get();
  5243. Js::RecyclableObject* objRight = y->Get();
  5244. // If either WeakReference is dead, we can't be equal to anything.
  5245. if (objLeft == nullptr || objRight == nullptr)
  5246. {
  5247. return false;
  5248. }
  5249. // If the Var pointers are the same, they are equal.
  5250. if (objLeft == objRight)
  5251. {
  5252. return true;
  5253. }
  5254. Js::ES5Array* arrayLeft = Js::ES5Array::FromVar(objLeft);
  5255. Js::ES5Array* arrayRight = Js::ES5Array::FromVar(objRight);
  5256. uint32 lengthLeft = arrayLeft->GetLength();
  5257. uint32 lengthRight = arrayRight->GetLength();
  5258. Js::Var varLeft;
  5259. Js::Var varRight;
  5260. // If the length of string literals is different, these callsite objects are not equal.
  5261. if (lengthLeft != lengthRight)
  5262. {
  5263. return false;
  5264. }
  5265. AssertOrFailFast(lengthLeft != 0 && lengthRight != 0);
  5266. JS_REENTRANCY_LOCK(reentrancyLock, arrayLeft->GetScriptContext()->GetThreadContext());
  5267. Unused(reentrancyLock);
  5268. // Change to the set of raw strings.
  5269. varLeft = Js::JavascriptOperators::OP_GetProperty(arrayLeft, Js::PropertyIds::raw, arrayLeft->GetScriptContext());
  5270. arrayLeft = Js::ES5Array::FromVar(varLeft);
  5271. varRight = Js::JavascriptOperators::OP_GetProperty(arrayRight, Js::PropertyIds::raw, arrayRight->GetScriptContext());
  5272. arrayRight = Js::ES5Array::FromVar(varRight);
  5273. // Length of the raw strings should be the same as the cooked string literals.
  5274. AssertOrFailFast(lengthLeft == arrayLeft->GetLength());
  5275. AssertOrFailFast(lengthRight == arrayRight->GetLength());
  5276. for (uint32 i = 0; i < lengthLeft; i++)
  5277. {
  5278. BOOL hasLeft = arrayLeft->DirectGetItemAt(i, &varLeft);
  5279. AssertOrFailFast(hasLeft);
  5280. BOOL hasRight = arrayRight->DirectGetItemAt(i, &varRight);
  5281. AssertOrFailFast(hasRight);
  5282. // If the strings at this index are not equal, the callsite objects are not equal.
  5283. if (!Js::JavascriptString::Equals(varLeft, varRight))
  5284. {
  5285. return false;
  5286. }
  5287. }
  5288. return true;
  5289. }
  5290. hash_t StringTemplateCallsiteObjectComparer<RecyclerWeakReference<Js::RecyclableObject>*>::GetHashCode(RecyclerWeakReference<Js::RecyclableObject>* o)
  5291. {
  5292. hash_t hash = 0;
  5293. Js::RecyclableObject* obj = o->Get();
  5294. if (obj == nullptr)
  5295. {
  5296. return hash;
  5297. }
  5298. JS_REENTRANCY_LOCK(reentrancyLock, obj->GetScriptContext()->GetThreadContext());
  5299. Unused(reentrancyLock);
  5300. Js::ES5Array* callsite = Js::ES5Array::FromVar(obj);
  5301. Js::Var var = Js::JavascriptOperators::OP_GetProperty(callsite, Js::PropertyIds::raw, callsite->GetScriptContext());
  5302. Js::ES5Array* rawArray = Js::ES5Array::FromVar(var);
  5303. AssertOrFailFast(rawArray->GetLength() > 0);
  5304. rawArray->DirectGetItemAt(0, &var);
  5305. Js::JavascriptString* str = Js::JavascriptString::FromVar(var);
  5306. hash ^= DefaultComparer<const char16*>::GetHashCode(str->GetSz());
  5307. for (uint32 i = 1; i < rawArray->GetLength(); i++)
  5308. {
  5309. hash ^= DefaultComparer<const char16*>::GetHashCode(_u("${}"));
  5310. BOOL hasItem = rawArray->DirectGetItemAt(i, &var);
  5311. AssertOrFailFast(hasItem);
  5312. str = Js::JavascriptString::FromVar(var);
  5313. hash ^= DefaultComparer<const char16*>::GetHashCode(str->GetSz());
  5314. }
  5315. return hash;
  5316. }
  5317. DynamicType * JavascriptLibrary::GetObjectLiteralType(uint16 requestedInlineSlotCapacity)
  5318. {
  5319. if (requestedInlineSlotCapacity <= MaxPreInitializedObjectTypeInlineSlotCount)
  5320. {
  5321. return objectTypes[DynamicTypeHandler::RoundUpInlineSlotCapacity(requestedInlineSlotCapacity) / InlineSlotCountIncrement];
  5322. }
  5323. else
  5324. {
  5325. return objectTypes[PreInitializedObjectTypeCount - 1];
  5326. }
  5327. }
  5328. DynamicType * JavascriptLibrary::GetObjectHeaderInlinedLiteralType(uint16 requestedInlineSlotCapacity)
  5329. {
  5330. Assert(requestedInlineSlotCapacity <= MaxPreInitializedObjectHeaderInlinedTypeInlineSlotCount);
  5331. return
  5332. objectHeaderInlinedTypes[
  5333. (
  5334. DynamicTypeHandler::RoundUpObjectHeaderInlinedInlineSlotCapacity(requestedInlineSlotCapacity) -
  5335. DynamicTypeHandler::GetObjectHeaderInlinableSlotCapacity()
  5336. ) / InlineSlotCountIncrement];
  5337. }
  5338. HeapArgumentsObject* JavascriptLibrary::CreateHeapArguments(Var frameObj, uint32 formalCount, bool isStrictMode)
  5339. {
  5340. AssertMsg(heapArgumentsType, "Where's heapArgumentsType?");
  5341. Recycler *recycler = this->GetRecycler();
  5342. EnsureArrayPrototypeValuesFunction(); //InitializeArrayPrototype can be delay loaded, which could prevent us from access to array.prototype.values
  5343. DynamicType * argumentsType = nullptr;
  5344. if (isStrictMode)
  5345. {
  5346. //TODO: Make DictionaryTypeHandler shareable - So that Arguments' type can be cached on the javascriptLibrary.
  5347. DictionaryTypeHandler * dictTypeHandlerForArgumentsInStrictMode = DictionaryTypeHandler::CreateTypeHandlerForArgumentsInStrictMode(recycler, scriptContext);
  5348. argumentsType = DynamicType::New(scriptContext, TypeIds_Arguments, objectPrototype, nullptr,
  5349. dictTypeHandlerForArgumentsInStrictMode, false, false);
  5350. }
  5351. else
  5352. {
  5353. argumentsType = heapArgumentsType;
  5354. }
  5355. return RecyclerNew(recycler, HeapArgumentsObject, recycler,
  5356. frameObj != GetNull() ? static_cast<ActivationObject*>(frameObj) : nullptr,
  5357. formalCount, argumentsType);
  5358. }
  5359. JavascriptArray* JavascriptLibrary::CreateArray()
  5360. {
  5361. AssertMsg(arrayType, "Where's arrayType?");
  5362. return JavascriptArray::New<Var, JavascriptArray>(this->GetRecycler(), arrayType);
  5363. }
  5364. JavascriptArray* JavascriptLibrary::CreateArray(uint32 length)
  5365. {
  5366. AssertMsg(arrayType, "Where's arrayType?");
  5367. JavascriptArray* arr = JavascriptArray::New<Var, JavascriptArray, 0>(length, arrayType, this->GetRecycler());
  5368. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  5369. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  5370. arr->CheckForceES5Array();
  5371. #endif
  5372. return arr;
  5373. }
  5374. JavascriptArray *JavascriptLibrary::CreateArrayOnStack(void *const stackAllocationPointer)
  5375. {
  5376. return JavascriptArray::New<JavascriptArray, 0>(stackAllocationPointer, 0, arrayType);
  5377. }
  5378. JavascriptNativeIntArray* JavascriptLibrary::CreateNativeIntArray()
  5379. {
  5380. AssertMsg(nativeIntArrayType, "Where's nativeIntArrayType?");
  5381. return JavascriptArray::New<int32, JavascriptNativeIntArray>(this->GetRecycler(), nativeIntArrayType);
  5382. }
  5383. JavascriptNativeIntArray* JavascriptLibrary::CreateNativeIntArray(uint32 length)
  5384. {
  5385. AssertMsg(nativeIntArrayType, "Where's nativeIntArrayType?");
  5386. JavascriptNativeIntArray* arr = JavascriptArray::New<int32, JavascriptNativeIntArray, 0>(length, nativeIntArrayType, this->GetRecycler());
  5387. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  5388. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  5389. arr->CheckForceES5Array();
  5390. #endif
  5391. return arr;
  5392. }
  5393. JavascriptNativeFloatArray* JavascriptLibrary::CreateNativeFloatArray()
  5394. {
  5395. AssertMsg(nativeFloatArrayType, "Where's nativeFloatArrayType?");
  5396. return JavascriptArray::New<double, JavascriptNativeFloatArray>(this->GetRecycler(), nativeFloatArrayType);
  5397. }
  5398. JavascriptNativeFloatArray* JavascriptLibrary::CreateNativeFloatArray(uint32 length)
  5399. {
  5400. AssertMsg(nativeFloatArrayType, "Where's nativeIntArrayType?");
  5401. JavascriptNativeFloatArray* arr = JavascriptArray::New<double, JavascriptNativeFloatArray, 0>(length, nativeFloatArrayType, this->GetRecycler());
  5402. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  5403. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  5404. arr->CheckForceES5Array();
  5405. #endif
  5406. return arr;
  5407. }
  5408. JavascriptArray* JavascriptLibrary::CreateArrayLiteral(uint32 length)
  5409. {
  5410. AssertMsg(arrayType, "Where's arrayType?");
  5411. JavascriptArray* arr = JavascriptArray::NewLiteral<Var, JavascriptArray, 0>(length, arrayType, this->GetRecycler());
  5412. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  5413. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  5414. arr->CheckForceES5Array();
  5415. #endif
  5416. return arr;
  5417. }
  5418. JavascriptNativeIntArray* JavascriptLibrary::CreateNativeIntArrayLiteral(uint32 length)
  5419. {
  5420. AssertMsg(nativeIntArrayType, "Where's arrayType?");
  5421. JavascriptNativeIntArray* arr = JavascriptArray::NewLiteral<int32, JavascriptNativeIntArray, 0>(length, nativeIntArrayType, this->GetRecycler());
  5422. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  5423. return arr;
  5424. }
  5425. #if ENABLE_COPYONACCESS_ARRAY
  5426. JavascriptNativeIntArray* JavascriptLibrary::CreateCopyOnAccessNativeIntArrayLiteral(ArrayCallSiteInfo *arrayInfo, FunctionBody *functionBody, const Js::AuxArray<int32> *ints)
  5427. {
  5428. AssertMsg(copyOnAccessNativeIntArrayType, "Where's arrayType?");
  5429. JavascriptNativeIntArray* arr = JavascriptArray::NewCopyOnAccessLiteral<int32, JavascriptCopyOnAccessNativeIntArray, 0>(copyOnAccessNativeIntArrayType, arrayInfo, functionBody, ints, this->GetRecycler());
  5430. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  5431. return arr;
  5432. }
  5433. #endif
  5434. JavascriptNativeFloatArray* JavascriptLibrary::CreateNativeFloatArrayLiteral(uint32 length)
  5435. {
  5436. AssertMsg(nativeFloatArrayType, "Where's arrayType?");
  5437. JavascriptNativeFloatArray* arr = JavascriptArray::NewLiteral<double, JavascriptNativeFloatArray, 0>(length, nativeFloatArrayType, this->GetRecycler());
  5438. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  5439. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  5440. arr->CheckForceES5Array();
  5441. #endif
  5442. return arr;
  5443. }
  5444. JavascriptArray* JavascriptLibrary::CreateArray(uint32 length, uint32 size)
  5445. {
  5446. AssertMsg(arrayType, "Where's arrayType?");
  5447. JavascriptArray* arr = RecyclerNew(this->GetRecycler(), JavascriptArray, length, size, arrayType);
  5448. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  5449. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  5450. arr->CheckForceES5Array();
  5451. #endif
  5452. return arr;
  5453. }
  5454. ArrayBuffer* JavascriptLibrary::CreateArrayBuffer(uint32 length)
  5455. {
  5456. ArrayBuffer* arr = JavascriptArrayBuffer::Create(length, arrayBufferType);
  5457. return arr;
  5458. }
  5459. ArrayBuffer* JavascriptLibrary::CreateArrayBuffer(byte* buffer, uint32 length)
  5460. {
  5461. ArrayBuffer* arr = JavascriptArrayBuffer::Create(buffer, length, arrayBufferType);
  5462. return arr;
  5463. }
  5464. Js::WebAssemblyArrayBuffer* JavascriptLibrary::CreateWebAssemblyArrayBuffer(uint32 length)
  5465. {
  5466. return WebAssemblyArrayBuffer::Create(nullptr, length, arrayBufferType);
  5467. }
  5468. Js::WebAssemblyArrayBuffer* JavascriptLibrary::CreateWebAssemblyArrayBuffer(byte* buffer, uint32 length)
  5469. {
  5470. return WebAssemblyArrayBuffer::Create(buffer, length, arrayBufferType);
  5471. }
  5472. SharedArrayBuffer* JavascriptLibrary::CreateSharedArrayBuffer(uint32 length)
  5473. {
  5474. return JavascriptSharedArrayBuffer::Create(length, sharedArrayBufferType);
  5475. }
  5476. SharedArrayBuffer* JavascriptLibrary::CreateSharedArrayBuffer(SharedContents *contents)
  5477. {
  5478. return JavascriptSharedArrayBuffer::Create(contents, sharedArrayBufferType);
  5479. }
  5480. ArrayBuffer* JavascriptLibrary::CreateProjectionArraybuffer(uint32 length)
  5481. {
  5482. ArrayBuffer* arr = ProjectionArrayBuffer::Create(length, arrayBufferType);
  5483. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_OBJECT(arr));
  5484. return arr;
  5485. }
  5486. ArrayBuffer* JavascriptLibrary::CreateProjectionArraybuffer(byte* buffer, uint32 length)
  5487. {
  5488. ArrayBuffer* arr = ProjectionArrayBuffer::Create(buffer, length, arrayBufferType);
  5489. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_OBJECT(arr));
  5490. return arr;
  5491. }
  5492. DataView* JavascriptLibrary::CreateDataView(ArrayBufferBase* arrayBuffer, uint32 offset, uint32 length)
  5493. {
  5494. DataView* dataView = RecyclerNew(this->GetRecycler(), DataView, arrayBuffer, offset, length, dataViewType);
  5495. return dataView;
  5496. }
  5497. JavascriptBoolean* JavascriptLibrary::CreateBoolean(BOOL value)
  5498. {
  5499. AssertMsg(booleanTrue, "Where's booleanTrue?");
  5500. AssertMsg(booleanFalse, "Where's booleanFalse?");
  5501. return value ? booleanTrue : booleanFalse;
  5502. }
  5503. JavascriptDate* JavascriptLibrary::CreateDate()
  5504. {
  5505. AssertMsg(dateType, "Where's dateType?");
  5506. return RecyclerNew(this->GetRecycler(), JavascriptDate, 0, dateType);
  5507. }
  5508. JavascriptDate* JavascriptLibrary::CreateDate(double value)
  5509. {
  5510. AssertMsg(dateType, "Where's dateType?");
  5511. return RecyclerNew(this->GetRecycler(), JavascriptDate, value, dateType);
  5512. }
  5513. JavascriptDate* JavascriptLibrary::CreateDate(SYSTEMTIME* pst)
  5514. {
  5515. AssertMsg(dateType, "Where's dateType?");
  5516. double value = DateImplementation::TimeFromSt(pst);
  5517. return CreateDate(value);
  5518. }
  5519. JavascriptMap* JavascriptLibrary::CreateMap()
  5520. {
  5521. AssertMsg(mapType, "Where's mapType?");
  5522. return RecyclerNew(this->GetRecycler(), JavascriptMap, mapType);
  5523. }
  5524. JavascriptSet* JavascriptLibrary::CreateSet()
  5525. {
  5526. AssertMsg(setType, "Where's setType?");
  5527. return RecyclerNew(this->GetRecycler(), JavascriptSet, setType);
  5528. }
  5529. JavascriptWeakMap* JavascriptLibrary::CreateWeakMap()
  5530. {
  5531. AssertMsg(weakMapType, "Where's weakMapType?");
  5532. return RecyclerNewFinalized(this->GetRecycler(), JavascriptWeakMap, weakMapType);
  5533. }
  5534. JavascriptWeakSet* JavascriptLibrary::CreateWeakSet()
  5535. {
  5536. AssertMsg(weakSetType, "Where's weakSetType?");
  5537. return RecyclerNewFinalized(this->GetRecycler(), JavascriptWeakSet, weakSetType);
  5538. }
  5539. JavascriptPromise* JavascriptLibrary::CreatePromise()
  5540. {
  5541. AssertMsg(promiseType, "Where's promiseType?");
  5542. return RecyclerNew(this->GetRecycler(), JavascriptPromise, promiseType);
  5543. }
  5544. JavascriptPromiseAsyncSpawnExecutorFunction* JavascriptLibrary::CreatePromiseAsyncSpawnExecutorFunction(JavascriptMethod entryPoint, JavascriptGenerator* generator, Var target)
  5545. {
  5546. FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
  5547. DynamicType* type = CreateDeferredPrototypeFunctionType(this->inDispatchProfileMode ? ProfileEntryThunk : entryPoint);
  5548. JavascriptPromiseAsyncSpawnExecutorFunction* function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseAsyncSpawnExecutorFunction, type, functionInfo, generator, target);
  5549. return function;
  5550. }
  5551. JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* JavascriptLibrary::CreatePromiseAsyncSpawnStepArgumentExecutorFunction(JavascriptMethod entryPoint, JavascriptGenerator* generator, Var argument, Var resolve, Var reject, bool isReject)
  5552. {
  5553. FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
  5554. DynamicType* type = CreateDeferredPrototypeFunctionType(this->inDispatchProfileMode ? ProfileEntryThunk : entryPoint);
  5555. JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction, type, functionInfo, generator, argument, resolve, reject, isReject);
  5556. return function;
  5557. }
  5558. JavascriptGenerator* JavascriptLibrary::CreateGenerator(Arguments& args, ScriptFunction* scriptFunction, RecyclableObject* prototype)
  5559. {
  5560. Assert(scriptContext->GetConfig()->IsES6GeneratorsEnabled());
  5561. DynamicType* generatorType = CreateGeneratorType(prototype);
  5562. return JavascriptGenerator::New(this->GetRecycler(), generatorType, args, scriptFunction);
  5563. }
  5564. JavascriptError* JavascriptLibrary::CreateError()
  5565. {
  5566. AssertMsg(errorType, "Where's errorType?");
  5567. JavascriptError *pError = RecyclerNew(this->GetRecycler(), JavascriptError, errorType);
  5568. JavascriptError::SetErrorType(pError, kjstError);
  5569. return pError;
  5570. }
  5571. JavascriptSymbol* JavascriptLibrary::CreateSymbol(JavascriptString* description)
  5572. {
  5573. return this->CreateSymbol(description->GetString(), (int)description->GetLength());
  5574. }
  5575. JavascriptSymbol* JavascriptLibrary::CreateSymbol(const char16* description, int descriptionLength)
  5576. {
  5577. ENTER_PINNED_SCOPE(const Js::PropertyRecord, propertyRecord);
  5578. propertyRecord = this->scriptContext->GetThreadContext()->UncheckedAddPropertyId(description, descriptionLength, /*bind*/false, /*isSymbol*/true);
  5579. LEAVE_PINNED_SCOPE();
  5580. return this->CreateSymbol(propertyRecord);
  5581. }
  5582. JavascriptSymbol* JavascriptLibrary::CreateSymbol(const PropertyRecord* propertyRecord)
  5583. {
  5584. AssertMsg(symbolTypeStatic, "Where's symbolTypeStatic?");
  5585. return RecyclerNew(this->GetRecycler(), JavascriptSymbol, propertyRecord, symbolTypeStatic);
  5586. }
  5587. JavascriptError* JavascriptLibrary::CreateExternalError(ErrorTypeEnum errorTypeEnum)
  5588. {
  5589. DynamicType* baseErrorType = NULL;
  5590. switch (errorTypeEnum)
  5591. {
  5592. case kjstError:
  5593. default:
  5594. baseErrorType = errorType;
  5595. break;
  5596. case kjstEvalError:
  5597. baseErrorType = evalErrorType;
  5598. break;
  5599. case kjstRangeError:
  5600. baseErrorType = rangeErrorType;
  5601. break;
  5602. case kjstReferenceError:
  5603. baseErrorType = referenceErrorType;
  5604. break;
  5605. case kjstSyntaxError:
  5606. baseErrorType = syntaxErrorType;
  5607. break;
  5608. case kjstTypeError:
  5609. baseErrorType = typeErrorType;
  5610. break;
  5611. case kjstURIError:
  5612. baseErrorType = uriErrorType;
  5613. break;
  5614. case kjstWebAssemblyCompileError:
  5615. baseErrorType = webAssemblyCompileErrorType;
  5616. break;
  5617. case kjstWebAssemblyRuntimeError:
  5618. baseErrorType = webAssemblyRuntimeErrorType;
  5619. break;
  5620. case kjstWebAssemblyLinkError:
  5621. baseErrorType = webAssemblyLinkErrorType;
  5622. break;
  5623. }
  5624. JavascriptError *pError = RecyclerNew(recycler, JavascriptError, baseErrorType, TRUE);
  5625. JavascriptError::SetErrorType(pError, errorTypeEnum);
  5626. return pError;
  5627. }
  5628. #define CREATE_ERROR(name, field, id) \
  5629. JavascriptError* JavascriptLibrary::Create##name() \
  5630. { \
  5631. AssertMsg(field, "Where's field?"); \
  5632. JavascriptError *pError = RecyclerNew(this->GetRecycler(), JavascriptError, field); \
  5633. JavascriptError::SetErrorType(pError, id); \
  5634. return pError; \
  5635. }
  5636. CREATE_ERROR(EvalError, evalErrorType, kjstEvalError);
  5637. CREATE_ERROR(RangeError, rangeErrorType, kjstRangeError);
  5638. CREATE_ERROR(ReferenceError, referenceErrorType, kjstReferenceError);
  5639. CREATE_ERROR(SyntaxError, syntaxErrorType, kjstSyntaxError);
  5640. CREATE_ERROR(TypeError, typeErrorType, kjstTypeError);
  5641. CREATE_ERROR(URIError, uriErrorType, kjstURIError);
  5642. CREATE_ERROR(WebAssemblyCompileError, webAssemblyCompileErrorType, kjstWebAssemblyCompileError);
  5643. CREATE_ERROR(WebAssemblyRuntimeError, webAssemblyRuntimeErrorType, kjstWebAssemblyRuntimeError);
  5644. CREATE_ERROR(WebAssemblyLinkError, webAssemblyLinkErrorType, kjstWebAssemblyLinkError);
  5645. #undef CREATE_ERROR
  5646. JavascriptError* JavascriptLibrary::CreateStackOverflowError()
  5647. {
  5648. #if DBG
  5649. // If we are doing a heap enum, we need to be able to allocate the error object.
  5650. Recycler::AutoAllowAllocationDuringHeapEnum autoAllowAllocationDuringHeapEnum(this->GetRecycler());
  5651. #endif
  5652. JavascriptError* stackOverflowError = scriptContext->GetLibrary()->CreateError();
  5653. JavascriptError::SetErrorMessage(stackOverflowError, VBSERR_OutOfStack, NULL, scriptContext);
  5654. return stackOverflowError;
  5655. }
  5656. JavascriptError* JavascriptLibrary::CreateOutOfMemoryError()
  5657. {
  5658. JavascriptError* outOfMemoryError = scriptContext->GetLibrary()->CreateError();
  5659. JavascriptError::SetErrorMessage(outOfMemoryError, VBSERR_OutOfMemory, NULL, scriptContext);
  5660. return outOfMemoryError;
  5661. }
  5662. JavascriptFunction* JavascriptLibrary::CreateNonProfiledFunction(FunctionInfo * functionInfo)
  5663. {
  5664. Assert(functionInfo->GetAttributes() & FunctionInfo::DoNotProfile);
  5665. return RecyclerNew(this->GetRecycler(), RuntimeFunction,
  5666. CreateDeferredPrototypeFunctionTypeNoProfileThunk(functionInfo->GetOriginalEntryPoint()),
  5667. functionInfo);
  5668. }
  5669. ScriptFunction* JavascriptLibrary::CreateScriptFunction(FunctionProxy * proxy)
  5670. {
  5671. ScriptFunctionType* deferredPrototypeType = proxy->EnsureDeferredPrototypeType();
  5672. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, ScriptFunction, proxy, deferredPrototypeType);
  5673. }
  5674. AsmJsScriptFunction* JavascriptLibrary::CreateAsmJsScriptFunction(FunctionProxy * proxy)
  5675. {
  5676. ScriptFunctionType* deferredPrototypeType = proxy->EnsureDeferredPrototypeType();
  5677. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, AsmJsScriptFunction, proxy, deferredPrototypeType);
  5678. }
  5679. #ifdef ENABLE_WASM
  5680. WasmScriptFunction * JavascriptLibrary::CreateWasmScriptFunction(FunctionProxy* proxy)
  5681. {
  5682. ScriptFunctionType* deferredPrototypeType = proxy->EnsureDeferredPrototypeType();
  5683. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, WasmScriptFunction, proxy, deferredPrototypeType);
  5684. }
  5685. #endif
  5686. ScriptFunctionWithInlineCache* JavascriptLibrary::CreateScriptFunctionWithInlineCache(FunctionProxy * proxy)
  5687. {
  5688. ScriptFunctionType* deferredPrototypeType = proxy->EnsureDeferredPrototypeType();
  5689. return RecyclerNewWithInfoBits(this->GetRecycler(), (Memory::ObjectInfoBits)(EnumFunctionClass | Memory::FinalizableObjectBits), ScriptFunctionWithInlineCache, proxy, deferredPrototypeType);
  5690. }
  5691. GeneratorVirtualScriptFunction* JavascriptLibrary::CreateGeneratorVirtualScriptFunction(FunctionProxy * proxy)
  5692. {
  5693. ScriptFunctionType* deferredPrototypeType = proxy->EnsureDeferredPrototypeType();
  5694. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, GeneratorVirtualScriptFunction, proxy, deferredPrototypeType);
  5695. }
  5696. DynamicType * JavascriptLibrary::CreateGeneratorType(RecyclableObject* prototype)
  5697. {
  5698. return DynamicType::New(scriptContext, TypeIds_Generator, prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance());
  5699. }
  5700. template <class MethodType>
  5701. JavascriptExternalFunction* JavascriptLibrary::CreateIdMappedExternalFunction(MethodType entryPoint, DynamicType *pPrototypeType)
  5702. {
  5703. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptExternalFunction, entryPoint, pPrototypeType);
  5704. }
  5705. JavascriptGeneratorFunction* JavascriptLibrary::CreateGeneratorFunction(JavascriptMethod entryPoint, GeneratorVirtualScriptFunction* scriptFunction)
  5706. {
  5707. Assert(scriptContext->GetConfig()->IsES6GeneratorsEnabled());
  5708. DynamicType* type = CreateDeferredPrototypeGeneratorFunctionType(entryPoint, scriptFunction->IsAnonymousFunction());
  5709. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptGeneratorFunction, type, scriptFunction);
  5710. }
  5711. JavascriptAsyncFunction* JavascriptLibrary::CreateAsyncFunction(JavascriptMethod entryPoint, GeneratorVirtualScriptFunction* scriptFunction)
  5712. {
  5713. DynamicType* type = CreateDeferredPrototypeAsyncFunctionType(entryPoint, scriptFunction->IsAnonymousFunction());
  5714. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptAsyncFunction, type, scriptFunction);
  5715. }
  5716. JavascriptExternalFunction* JavascriptLibrary::CreateStdCallExternalFunction(StdCallJavascriptMethod entryPoint, PropertyId nameId, void *callbackState)
  5717. {
  5718. Assert(nameId == 0 || scriptContext->IsTrackedPropertyId(nameId));
  5719. return CreateStdCallExternalFunction(entryPoint, TaggedInt::ToVarUnchecked(nameId), callbackState);
  5720. }
  5721. JavascriptExternalFunction* JavascriptLibrary::CreateStdCallExternalFunction(StdCallJavascriptMethod entryPoint, Var name, void *callbackState)
  5722. {
  5723. Var functionNameOrId = name;
  5724. if (JavascriptString::Is(name))
  5725. {
  5726. JavascriptString * functionName = JavascriptString::FromVar(name);
  5727. const char16 * functionNameBuffer = functionName->GetString();
  5728. int functionNameBufferLength = functionName->GetLengthAsSignedInt();
  5729. PropertyId functionNamePropertyId = scriptContext->GetOrAddPropertyIdTracked(functionNameBuffer, functionNameBufferLength);
  5730. functionNameOrId = TaggedInt::ToVarUnchecked(functionNamePropertyId);
  5731. }
  5732. AssertOrFailFast(TaggedInt::Is(functionNameOrId));
  5733. JavascriptExternalFunction* function = this->CreateIdMappedExternalFunction(entryPoint, stdCallFunctionWithDeferredPrototypeType);
  5734. function->SetFunctionNameId(functionNameOrId);
  5735. function->SetCallbackState(callbackState);
  5736. return function;
  5737. }
  5738. JavascriptPromiseCapabilitiesExecutorFunction* JavascriptLibrary::CreatePromiseCapabilitiesExecutorFunction(JavascriptMethod entryPoint, JavascriptPromiseCapability* capability)
  5739. {
  5740. Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());
  5741. FunctionInfo* functionInfo = &Js::JavascriptPromise::EntryInfo::CapabilitiesExecutorFunction;
  5742. DynamicType* type = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, entryPoint, GetDeferredAnonymousFunctionTypeHandler());
  5743. JavascriptPromiseCapabilitiesExecutorFunction* function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseCapabilitiesExecutorFunction, type, functionInfo, capability);
  5744. function->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(2), PropertyConfigurable, nullptr);
  5745. return function;
  5746. }
  5747. JavascriptPromiseResolveOrRejectFunction* JavascriptLibrary::CreatePromiseResolveOrRejectFunction(JavascriptMethod entryPoint, JavascriptPromise* promise, bool isReject, JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* alreadyResolvedRecord)
  5748. {
  5749. Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());
  5750. FunctionInfo* functionInfo = &Js::JavascriptPromise::EntryInfo::ResolveOrRejectFunction;
  5751. DynamicType* type = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, entryPoint, GetDeferredAnonymousFunctionTypeHandler());
  5752. JavascriptPromiseResolveOrRejectFunction* function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseResolveOrRejectFunction, type, functionInfo, promise, isReject, alreadyResolvedRecord);
  5753. function->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
  5754. return function;
  5755. }
  5756. JavascriptPromiseReactionTaskFunction* JavascriptLibrary::CreatePromiseReactionTaskFunction(JavascriptMethod entryPoint, JavascriptPromiseReaction* reaction, Var argument)
  5757. {
  5758. Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());
  5759. FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
  5760. DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);
  5761. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseReactionTaskFunction, type, functionInfo, reaction, argument);
  5762. }
  5763. JavascriptPromiseResolveThenableTaskFunction* JavascriptLibrary::CreatePromiseResolveThenableTaskFunction(JavascriptMethod entryPoint, JavascriptPromise* promise, RecyclableObject* thenable, RecyclableObject* thenFunction)
  5764. {
  5765. Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());
  5766. FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
  5767. DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);
  5768. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseResolveThenableTaskFunction, type, functionInfo, promise, thenable, thenFunction);
  5769. }
  5770. JavascriptPromiseAllResolveElementFunction* JavascriptLibrary::CreatePromiseAllResolveElementFunction(JavascriptMethod entryPoint, uint32 index, JavascriptArray* values, JavascriptPromiseCapability* capabilities, JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* remainingElements)
  5771. {
  5772. Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());
  5773. FunctionInfo* functionInfo = &Js::JavascriptPromise::EntryInfo::AllResolveElementFunction;
  5774. DynamicType* type = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, entryPoint, GetDeferredAnonymousFunctionTypeHandler());
  5775. JavascriptPromiseAllResolveElementFunction* function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseAllResolveElementFunction, type, functionInfo, index, values, capabilities, remainingElements);
  5776. function->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
  5777. return function;
  5778. }
  5779. JavascriptExternalFunction* JavascriptLibrary::CreateWrappedExternalFunction(JavascriptExternalFunction* wrappedFunction)
  5780. {
  5781. // The wrapped function will have profiling, so the wrapper function does not need it.
  5782. JavascriptExternalFunction* function = RecyclerNew(this->GetRecycler(), JavascriptExternalFunction, wrappedFunction, wrappedFunctionWithDeferredPrototypeType);
  5783. function->SetFunctionNameId(wrappedFunction->GetSourceString());
  5784. return function;
  5785. }
  5786. #if !FLOATVAR
  5787. JavascriptNumber * JavascriptLibrary::CreateNumber(double value, RecyclerJavascriptNumberAllocator * numberAllocator)
  5788. {
  5789. AssertMsg(numberTypeStatic, "Where's numberTypeStatic?");
  5790. return AllocatorNew(RecyclerJavascriptNumberAllocator, numberAllocator, JavascriptNumber, value, numberTypeStatic);
  5791. }
  5792. #if ENABLE_NATIVE_CODEGEN
  5793. JavascriptNumber* JavascriptLibrary::CreateCodeGenNumber(CodeGenNumberAllocator * alloc, double value)
  5794. {
  5795. AssertMsg(numberTypeStatic, "Where's numberTypeStatic?");
  5796. return new (alloc->Alloc()) JavascriptNumber(value, numberTypeStatic);
  5797. }
  5798. #endif
  5799. #endif
  5800. DynamicObject* JavascriptLibrary::CreateGeneratorConstructorPrototypeObject()
  5801. {
  5802. AssertMsg(generatorConstructorPrototypeObjectType, "Where's generatorConstructorPrototypeObjectType?");
  5803. DynamicObject * prototype = DynamicObject::New(this->GetRecycler(), generatorConstructorPrototypeObjectType);
  5804. // Generator functions' prototype objects are not created with a .constructor property
  5805. return prototype;
  5806. }
  5807. DynamicObject* JavascriptLibrary::CreateConstructorPrototypeObject(JavascriptFunction * constructor)
  5808. {
  5809. AssertMsg(constructorPrototypeObjectType, "Where's constructorPrototypeObjectType?");
  5810. DynamicObject * prototype = DynamicObject::New(this->GetRecycler(), constructorPrototypeObjectType);
  5811. AddMember(prototype, PropertyIds::constructor, constructor);
  5812. return prototype;
  5813. }
  5814. DynamicObject* JavascriptLibrary::CreateObject(
  5815. const bool allowObjectHeaderInlining,
  5816. const PropertyIndex requestedInlineSlotCapacity)
  5817. {
  5818. Assert(GetObjectType());
  5819. Assert(GetObjectHeaderInlinedType());
  5820. const bool useObjectHeaderInlining =
  5821. allowObjectHeaderInlining && FunctionBody::DoObjectHeaderInliningForObjectLiteral(requestedInlineSlotCapacity);
  5822. DynamicType *const type =
  5823. useObjectHeaderInlining
  5824. ? GetObjectHeaderInlinedLiteralType(requestedInlineSlotCapacity)
  5825. : GetObjectLiteralType(requestedInlineSlotCapacity);
  5826. return DynamicObject::New(GetRecycler(), type);
  5827. }
  5828. DynamicObject* JavascriptLibrary::CreateObject(DynamicTypeHandler * typeHandler)
  5829. {
  5830. return DynamicObject::New(this->GetRecycler(),
  5831. Js::DynamicType::New(scriptContext, Js::TypeIds_Object, this->GetObjectPrototype(),
  5832. RecyclableObject::DefaultEntryPoint, typeHandler, false, false));
  5833. }
  5834. DynamicType* JavascriptLibrary::CreateObjectType(RecyclableObject* prototype, Js::TypeId typeId, uint16 requestedInlineSlotCapacity)
  5835. {
  5836. const bool useObjectHeaderInlining = FunctionBody::DoObjectHeaderInliningForConstructor(requestedInlineSlotCapacity);
  5837. const uint16 offsetOfInlineSlots =
  5838. useObjectHeaderInlining
  5839. ? DynamicTypeHandler::GetOffsetOfObjectHeaderInlineSlots()
  5840. : sizeof(DynamicObject);
  5841. DynamicType* dynamicType = nullptr;
  5842. const bool useCache = prototype->GetScriptContext() == this->scriptContext;
  5843. #if DBG
  5844. DynamicType* oldCachedType = nullptr;
  5845. char16 reason[1024];
  5846. swprintf_s(reason, 1024, _u("Cache not populated."));
  5847. #endif
  5848. // Always use `TypeOfPrototypeObjectInlined` because we are creating DynamicType of TypeIds_Object
  5849. AssertMsg(typeId == TypeIds_Object, "CreateObjectType() is used to create other objects. Please update cacheSlot for protoObjectCache first.");
  5850. if (useCache &&
  5851. prototype->GetInternalProperty(prototype, Js::InternalPropertyIds::TypeOfPrototypeObjectInlined, (Js::Var*) &dynamicType, nullptr, this->scriptContext))
  5852. {
  5853. //If the prototype is externalObject, then ExternalObject::Reinitialize can set all the properties to undefined in navigation scenario.
  5854. //Check to make sure dynamicType which is stored as a Js::Var is not undefined.
  5855. //See Blue 419324
  5856. if (dynamicType != nullptr && (Js::Var)dynamicType != this->GetUndefined())
  5857. {
  5858. DynamicTypeHandler *const dynamicTypeHandler = dynamicType->GetTypeHandler();
  5859. if (dynamicTypeHandler->IsObjectHeaderInlinedTypeHandler() == useObjectHeaderInlining &&
  5860. (
  5861. dynamicTypeHandler->GetInlineSlotCapacity() ==
  5862. (
  5863. useObjectHeaderInlining
  5864. ? DynamicTypeHandler::RoundUpObjectHeaderInlinedInlineSlotCapacity(requestedInlineSlotCapacity)
  5865. : DynamicTypeHandler::RoundUpInlineSlotCapacity(requestedInlineSlotCapacity)
  5866. )
  5867. ))
  5868. {
  5869. Assert(dynamicType->GetIsShared());
  5870. if (PHASE_TRACE1(TypeShareForChangePrototypePhase))
  5871. {
  5872. #if DBG
  5873. if (PHASE_VERBOSE_TRACE1(TypeShareForChangePrototypePhase))
  5874. {
  5875. Output::Print(_u("TypeSharing: Reusing prototype [0x%p] object's InlineSlot cache 0x%p in CreateObject.\n"), prototype, dynamicType);
  5876. }
  5877. else
  5878. {
  5879. #endif
  5880. Output::Print(_u("TypeSharing: Reusing prototype object's InlineSlot cache in __proto__.\n"));
  5881. #if DBG
  5882. }
  5883. #endif
  5884. Output::Flush();
  5885. }
  5886. return dynamicType;
  5887. }
  5888. #if DBG
  5889. if (PHASE_VERBOSE_TRACE1(TypeShareForChangePrototypePhase))
  5890. {
  5891. if (dynamicTypeHandler->IsObjectHeaderInlinedTypeHandler() != useObjectHeaderInlining)
  5892. {
  5893. swprintf_s(reason, 1024, _u("useObjectHeaderInlining mismatch."));
  5894. }
  5895. else
  5896. {
  5897. uint16 cachedCapacity = dynamicTypeHandler->GetInlineSlotCapacity();
  5898. uint16 requiredCapacity = useObjectHeaderInlining
  5899. ? DynamicTypeHandler::RoundUpObjectHeaderInlinedInlineSlotCapacity(requestedInlineSlotCapacity)
  5900. : DynamicTypeHandler::RoundUpInlineSlotCapacity(requestedInlineSlotCapacity);
  5901. swprintf_s(reason, 1024, _u("inlineSlotCapacity mismatch. Required = %d, Cached = %d"), requiredCapacity, cachedCapacity);
  5902. }
  5903. }
  5904. #endif
  5905. }
  5906. }
  5907. #if DBG
  5908. if (PHASE_VERBOSE_TRACE1(TypeShareForChangePrototypePhase))
  5909. {
  5910. if (dynamicType == nullptr)
  5911. {
  5912. swprintf_s(reason, 1024, _u("cached type was null"));
  5913. }
  5914. else if ((Js::Var)dynamicType == this->GetUndefined())
  5915. {
  5916. swprintf_s(reason, 1024, _u("cached type was undefined"));
  5917. }
  5918. }
  5919. oldCachedType = dynamicType;
  5920. #endif
  5921. SimplePathTypeHandlerNoAttr* typeHandler = SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, requestedInlineSlotCapacity, offsetOfInlineSlots, true, true);
  5922. dynamicType = DynamicType::New(scriptContext, typeId, prototype, RecyclableObject::DefaultEntryPoint, typeHandler, true, true);
  5923. if (useCache)
  5924. {
  5925. prototype->SetInternalProperty(Js::InternalPropertyIds::TypeOfPrototypeObjectInlined, (Var)dynamicType, PropertyOperationFlags::PropertyOperation_Force, nullptr);
  5926. if (PHASE_TRACE1(TypeShareForChangePrototypePhase))
  5927. {
  5928. #if DBG
  5929. if (PHASE_VERBOSE_TRACE1(TypeShareForChangePrototypePhase))
  5930. {
  5931. Output::Print(_u("TypeSharing: Updating prototype [0x%p] object's InlineSlot cache from 0x%p to 0x%p in CreateObject. Reason = %s\n"), prototype, oldCachedType, dynamicType, reason);
  5932. }
  5933. else
  5934. {
  5935. #endif
  5936. Output::Print(_u("TypeSharing: Updating prototype object's InlineSlot cache in CreateObject.\n"));
  5937. #if DBG
  5938. }
  5939. #endif
  5940. Output::Flush();
  5941. }
  5942. }
  5943. return dynamicType;
  5944. }
  5945. DynamicType* JavascriptLibrary::CreateObjectTypeNoCache(RecyclableObject* prototype, Js::TypeId typeId)
  5946. {
  5947. return DynamicType::New(scriptContext, typeId, prototype, RecyclableObject::DefaultEntryPoint,
  5948. SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
  5949. }
  5950. DynamicType* JavascriptLibrary::CreateObjectType(RecyclableObject* prototype, uint16 requestedInlineSlotCapacity)
  5951. {
  5952. // We can't reuse the type in objectType even if the prototype is the object prototype, because those has inline slot capacity fixed
  5953. return CreateObjectType(prototype, TypeIds_Object, requestedInlineSlotCapacity);
  5954. }
  5955. DynamicObject* JavascriptLibrary::CreateObject(RecyclableObject* prototype, uint16 requestedInlineSlotCapacity)
  5956. {
  5957. Assert(JavascriptOperators::IsObjectOrNull(prototype));
  5958. DynamicType* type = nullptr;
  5959. // If requested capacity is 0, we can't shrink, so it is already fixed and we can reuse the cached types
  5960. // For other inline slot capacities, we might want to shrink so we can't use the cached types (whose slot capacities are fixed)
  5961. //
  5962. // REVIEW: Do we really need non-fixed inline slot capacity? The obvious downside is it prevents type sharing with the cached types
  5963. if (requestedInlineSlotCapacity == 0 && JavascriptOperators::IsNull(prototype))
  5964. {
  5965. type = GetNullPrototypeObjectType();
  5966. }
  5967. else if(requestedInlineSlotCapacity == 0 && prototype == GetObjectPrototype())
  5968. {
  5969. type = GetObjectType();
  5970. }
  5971. else
  5972. {
  5973. type = CreateObjectType(prototype, requestedInlineSlotCapacity);
  5974. }
  5975. return DynamicObject::New(this->GetRecycler(), type);
  5976. }
  5977. PropertyStringCacheMap* JavascriptLibrary::EnsurePropertyStringMap()
  5978. {
  5979. if (this->propertyStringMap == nullptr)
  5980. {
  5981. this->propertyStringMap = RecyclerNew(this->recycler, PropertyStringCacheMap, this->GetRecycler(), 71);
  5982. this->scriptContext->RegisterWeakReferenceDictionary((JsUtil::IWeakReferenceDictionary*) this->propertyStringMap);
  5983. }
  5984. return this->propertyStringMap;
  5985. }
  5986. DynamicObject* JavascriptLibrary::CreateActivationObject()
  5987. {
  5988. AssertMsg(activationObjectType, "Where's activationObjectType?");
  5989. return RecyclerNew(this->GetRecycler(), ActivationObject, activationObjectType);
  5990. }
  5991. DynamicObject* JavascriptLibrary::CreatePseudoActivationObject()
  5992. {
  5993. AssertMsg(activationObjectType, "Where's activationObjectType?");
  5994. return RecyclerNew(this->GetRecycler(), PseudoActivationObject, activationObjectType);
  5995. }
  5996. DynamicObject* JavascriptLibrary::CreateBlockActivationObject()
  5997. {
  5998. AssertMsg(activationObjectType, "Where's activationObjectType?");
  5999. return RecyclerNew(this->GetRecycler(), BlockActivationObject, activationObjectType);
  6000. }
  6001. DynamicObject* JavascriptLibrary::CreateConsoleScopeActivationObject()
  6002. {
  6003. AssertMsg(activationObjectType, "Where's activationObjectType?");
  6004. return RecyclerNew(this->GetRecycler(), ConsoleScopeActivationObject, activationObjectType);
  6005. }
  6006. JavascriptString* JavascriptLibrary::GetEmptyString() const
  6007. {
  6008. AssertMsg(emptyString, "Where's emptyString?");
  6009. #ifdef PROFILE_STRINGS
  6010. StringProfiler::RecordEmptyStringRequest(scriptContext);
  6011. #endif
  6012. return emptyString;
  6013. }
  6014. PropertyString* JavascriptLibrary::CreatePropertyString(const Js::PropertyRecord* propertyRecord)
  6015. {
  6016. return PropertyString::New(GetStringTypeStatic(), propertyRecord, this->GetRecycler());
  6017. }
  6018. JavascriptVariantDate* JavascriptLibrary::CreateVariantDate(const double value)
  6019. {
  6020. AssertMsg(variantDateType, "Where's variantDateType?");
  6021. return RecyclerNewLeafZ(this->GetRecycler(), JavascriptVariantDate, value, variantDateType);
  6022. }
  6023. JavascriptBooleanObject* JavascriptLibrary::CreateBooleanObject()
  6024. {
  6025. AssertMsg(booleanTypeDynamic, "Where's booleanTypeDynamic?");
  6026. return RecyclerNew(this->GetRecycler(), JavascriptBooleanObject, nullptr, booleanTypeDynamic);
  6027. }
  6028. JavascriptBooleanObject* JavascriptLibrary::CreateBooleanObject(BOOL value)
  6029. {
  6030. AssertMsg(booleanTypeDynamic, "Where's booleanTypeDynamic?");
  6031. return RecyclerNew(this->GetRecycler(), JavascriptBooleanObject, CreateBoolean(value), booleanTypeDynamic);
  6032. }
  6033. JavascriptSymbolObject* JavascriptLibrary::CreateSymbolObject(JavascriptSymbol* value)
  6034. {
  6035. AssertMsg(symbolTypeDynamic, "Where's symbolTypeDynamic?");
  6036. return RecyclerNew(this->GetRecycler(), JavascriptSymbolObject, value, symbolTypeDynamic);
  6037. }
  6038. #ifdef ENABLE_SIMDJS
  6039. JavascriptSIMDObject* JavascriptLibrary::CreateSIMDObject(Var simdValue, TypeId typeDescriptor)
  6040. {
  6041. switch (typeDescriptor)
  6042. {
  6043. case TypeIds_SIMDBool8x16:
  6044. AssertMsg(simdBool8x16TypeDynamic, "Where's simdTypeDynamic?");
  6045. return RecyclerNew(this->GetRecycler(), JavascriptSIMDObject, simdValue, simdBool8x16TypeDynamic, typeDescriptor);
  6046. case TypeIds_SIMDBool16x8:
  6047. AssertMsg(simdBool16x8TypeDynamic, "Where's simdTypeDynamic?");
  6048. return RecyclerNew(this->GetRecycler(), JavascriptSIMDObject, simdValue, simdBool16x8TypeDynamic, typeDescriptor);
  6049. case TypeIds_SIMDBool32x4:
  6050. AssertMsg(simdBool32x4TypeDynamic, "Where's simdTypeDynamic?");
  6051. return RecyclerNew(this->GetRecycler(), JavascriptSIMDObject, simdValue, simdBool32x4TypeDynamic, typeDescriptor);
  6052. case TypeIds_SIMDInt8x16:
  6053. AssertMsg(simdInt8x16TypeDynamic, "Where's simdTypeDynamic?");
  6054. return RecyclerNew(this->GetRecycler(), JavascriptSIMDObject, simdValue, simdInt8x16TypeDynamic, typeDescriptor);
  6055. case TypeIds_SIMDInt16x8:
  6056. AssertMsg(simdInt16x8TypeDynamic, "Where's simdTypeDynamic?");
  6057. return RecyclerNew(this->GetRecycler(), JavascriptSIMDObject, simdValue, simdInt16x8TypeDynamic, typeDescriptor);
  6058. case TypeIds_SIMDInt32x4:
  6059. AssertMsg(simdInt32x4TypeDynamic, "Where's simdTypeDynamic?");
  6060. return RecyclerNew(this->GetRecycler(), JavascriptSIMDObject, simdValue, simdInt32x4TypeDynamic, typeDescriptor);
  6061. case TypeIds_SIMDUint8x16:
  6062. AssertMsg(simdUint8x16TypeDynamic, "Where's simdTypeDynamic?");
  6063. return RecyclerNew(this->GetRecycler(), JavascriptSIMDObject, simdValue, simdUint8x16TypeDynamic, typeDescriptor);
  6064. case TypeIds_SIMDUint16x8:
  6065. AssertMsg(simdUint16x8TypeDynamic, "Where's simdTypeDynamic?");
  6066. return RecyclerNew(this->GetRecycler(), JavascriptSIMDObject, simdValue, simdUint16x8TypeDynamic, typeDescriptor);
  6067. case TypeIds_SIMDUint32x4:
  6068. AssertMsg(simdUint32x4TypeDynamic, "Where's simdTypeDynamic?");
  6069. return RecyclerNew(this->GetRecycler(), JavascriptSIMDObject, simdValue, simdUint32x4TypeDynamic, typeDescriptor);
  6070. case TypeIds_SIMDFloat32x4:
  6071. AssertMsg(simdFloat32x4TypeDynamic, "Where's simdTypeDynamic?");
  6072. return RecyclerNew(this->GetRecycler(), JavascriptSIMDObject, simdValue, simdFloat32x4TypeDynamic, typeDescriptor);
  6073. default:
  6074. Assert(UNREACHED);
  6075. }
  6076. return nullptr;
  6077. }
  6078. #endif
  6079. JavascriptNumberObject* JavascriptLibrary::CreateNumberObject(Var number)
  6080. {
  6081. AssertMsg(numberTypeDynamic, "Where's numberTypeDynamic?");
  6082. return RecyclerNew(this->GetRecycler(), JavascriptNumberObject, number, numberTypeDynamic);
  6083. }
  6084. JavascriptNumberObject* JavascriptLibrary::CreateNumberObjectWithCheck(double value)
  6085. {
  6086. return CreateNumberObject(JavascriptNumber::ToVarWithCheck(value, scriptContext));
  6087. }
  6088. JavascriptStringObject* JavascriptLibrary::CreateStringObject(JavascriptString* value)
  6089. {
  6090. AssertMsg(stringTypeDynamic, "Where's stringTypeDynamic?");
  6091. return RecyclerNew(this->GetRecycler(), JavascriptStringObject, value, stringTypeDynamic);
  6092. }
  6093. JavascriptStringObject* JavascriptLibrary::CreateStringObject(const char16* value, charcount_t length)
  6094. {
  6095. AssertMsg(stringTypeDynamic, "Where's stringTypeDynamic?");
  6096. return RecyclerNew(this->GetRecycler(), JavascriptStringObject,
  6097. Js::JavascriptString::NewWithBuffer(value, length, scriptContext), stringTypeDynamic);
  6098. }
  6099. JavascriptRegExp* JavascriptLibrary::CreateRegExp(UnifiedRegex::RegexPattern* pattern)
  6100. {
  6101. AssertMsg(regexType, "Where's regexType?");
  6102. return RecyclerNew(this->GetRecycler(), JavascriptRegExp, pattern, regexType);
  6103. }
  6104. JavascriptArrayIterator* JavascriptLibrary::CreateArrayIterator(Var iterable, JavascriptArrayIteratorKind kind)
  6105. {
  6106. AssertMsg(arrayIteratorType, "Where's arrayIteratorType");
  6107. return RecyclerNew(this->GetRecycler(), JavascriptArrayIterator, arrayIteratorType, iterable, kind);
  6108. }
  6109. JavascriptMapIterator* JavascriptLibrary::CreateMapIterator(JavascriptMap* map, JavascriptMapIteratorKind kind)
  6110. {
  6111. AssertMsg(mapIteratorType, "Where's mapIteratorType");
  6112. return RecyclerNew(this->GetRecycler(), JavascriptMapIterator, mapIteratorType, map, kind);
  6113. }
  6114. JavascriptSetIterator* JavascriptLibrary::CreateSetIterator(JavascriptSet* set, JavascriptSetIteratorKind kind)
  6115. {
  6116. AssertMsg(setIteratorType, "Where's setIteratorType");
  6117. return RecyclerNew(this->GetRecycler(), JavascriptSetIterator, setIteratorType, set, kind);
  6118. }
  6119. JavascriptStringIterator* JavascriptLibrary::CreateStringIterator(JavascriptString* string)
  6120. {
  6121. AssertMsg(stringIteratorType, "Where's stringIteratorType");
  6122. return RecyclerNew(this->GetRecycler(), JavascriptStringIterator, stringIteratorType, string);
  6123. }
  6124. DynamicObject* JavascriptLibrary::CreateIteratorResultObject(Var value, Var done)
  6125. {
  6126. DynamicObject* iteratorResult = DynamicObject::New(this->GetRecycler(), iteratorResultType);
  6127. iteratorResult->SetSlot(SetSlotArguments(Js::PropertyIds::value, 0, value));
  6128. iteratorResult->SetSlot(SetSlotArguments(Js::PropertyIds::done, 1, done));
  6129. return iteratorResult;
  6130. }
  6131. JavascriptListIterator* JavascriptLibrary::CreateListIterator(ListForListIterator* list)
  6132. {
  6133. JavascriptListIterator* iterator = RecyclerNew(this->GetRecycler(), JavascriptListIterator, listIteratorType, list);
  6134. RuntimeFunction* nextFunction = DefaultCreateFunction(&JavascriptListIterator::EntryInfo::Next, 0, nullptr, nullptr, PropertyIds::next);
  6135. JavascriptOperators::SetProperty(iterator, iterator, PropertyIds::next, RuntimeFunction::FromVar(nextFunction), GetScriptContext(), PropertyOperation_None);
  6136. return iterator;
  6137. }
  6138. DynamicObject* JavascriptLibrary::CreateIteratorResultObjectValueFalse(Var value)
  6139. {
  6140. return CreateIteratorResultObject(value, GetFalse());
  6141. }
  6142. DynamicObject* JavascriptLibrary::CreateIteratorResultObjectUndefinedTrue()
  6143. {
  6144. return CreateIteratorResultObject(GetUndefined(), GetTrue());
  6145. }
  6146. RecyclableObject* JavascriptLibrary::CreateThrowErrorObject(JavascriptError* error)
  6147. {
  6148. return ThrowErrorObject::New(this->throwErrorObjectType, error, this->GetRecycler());
  6149. }
  6150. #if ENABLE_COPYONACCESS_ARRAY
  6151. bool JavascriptLibrary::IsCopyOnAccessArrayCallSite(JavascriptLibrary *lib, ArrayCallSiteInfo *arrayInfo, uint32 length)
  6152. {
  6153. return
  6154. lib->cacheForCopyOnAccessArraySegments
  6155. && lib->cacheForCopyOnAccessArraySegments->IsNotOverHardLimit()
  6156. && (
  6157. PHASE_FORCE1(CopyOnAccessArrayPhase) // -force:copyonaccessarray is only restricted by hard limit of the segment cache
  6158. || (
  6159. !arrayInfo->isNotCopyOnAccessArray // from profile
  6160. && !PHASE_OFF1(CopyOnAccessArrayPhase)
  6161. && lib->cacheForCopyOnAccessArraySegments->IsNotFull() // cache size soft limit through -copyonaccessarraysegmentcachesize:<number>
  6162. && length <= (uint32)CONFIG_FLAG(MaxCopyOnAccessArrayLength) // -maxcopyonaccessarraylength:<number>
  6163. && length >= (uint32)CONFIG_FLAG(MinCopyOnAccessArrayLength) // -mincopyonaccessarraylength:<number>
  6164. )
  6165. )
  6166. #if ENABLE_TTD
  6167. && !lib->GetScriptContext()->GetThreadContext()->IsRuntimeInTTDMode()
  6168. #endif
  6169. ;
  6170. }
  6171. bool JavascriptLibrary::IsCachedCopyOnAccessArrayCallSite(const JavascriptLibrary *lib, ArrayCallSiteInfo *arrayInfo)
  6172. {
  6173. return lib->cacheForCopyOnAccessArraySegments
  6174. && lib->cacheForCopyOnAccessArraySegments->IsValidIndex(arrayInfo->copyOnAccessArrayCacheIndex);
  6175. }
  6176. #endif
  6177. // static
  6178. bool JavascriptLibrary::IsTypedArrayConstructor(Var constructor, ScriptContext* scriptContext)
  6179. {
  6180. JavascriptLibrary* library = scriptContext->GetLibrary();
  6181. return constructor == library->GetInt8ArrayConstructor()
  6182. || constructor == library->GetUint8ArrayConstructor()
  6183. || constructor == library->GetUint8ClampedArrayConstructor()
  6184. || constructor == library->GetInt16ArrayConstructor()
  6185. || constructor == library->GetUint16ArrayConstructor()
  6186. || constructor == library->GetInt32ArrayConstructor()
  6187. || constructor == library->GetUint32ArrayConstructor()
  6188. || constructor == library->GetFloat32ArrayConstructor()
  6189. || constructor == library->GetFloat64ArrayConstructor();
  6190. }
  6191. Field(JavascriptFunction*)* JavascriptLibrary::GetBuiltinFunctions()
  6192. {
  6193. AssertMsg(this->builtinFunctions, "builtinFunctions table must've been initialized as part of library initialization!");
  6194. return this->builtinFunctions;
  6195. }
  6196. void JavascriptLibrary::SetIsPRNGSeeded(bool val)
  6197. {
  6198. this->isPRNGSeeded = val;
  6199. #if ENABLE_NATIVE_CODEGEN
  6200. if (JITManager::GetJITManager()->IsOOPJITEnabled() && JITManager::GetJITManager()->IsConnected())
  6201. {
  6202. PSCRIPTCONTEXT_HANDLE remoteScriptContext = this->scriptContext->GetRemoteScriptAddr();
  6203. if (remoteScriptContext)
  6204. {
  6205. HRESULT hr = JITManager::GetJITManager()->SetIsPRNGSeeded(remoteScriptContext, val);
  6206. JITManager::HandleServerCallResult(hr, RemoteCallType::StateUpdate);
  6207. }
  6208. }
  6209. #endif
  6210. }
  6211. INT_PTR* JavascriptLibrary::GetVTableAddresses()
  6212. {
  6213. AssertMsg(this->vtableAddresses, "vtableAddresses table must've been initialized as part of library initialization!");
  6214. return this->vtableAddresses;
  6215. }
  6216. #if ENABLE_NATIVE_CODEGEN
  6217. //static
  6218. BuiltinFunction JavascriptLibrary::GetBuiltInInlineCandidateId(OpCode opCode)
  6219. {
  6220. switch (opCode)
  6221. {
  6222. case OpCode::InlineMathAcos:
  6223. return BuiltinFunction::Math_Acos;
  6224. case OpCode::InlineMathAsin:
  6225. return BuiltinFunction::Math_Asin;
  6226. case OpCode::InlineMathAtan:
  6227. return BuiltinFunction::Math_Atan;
  6228. case OpCode::InlineMathAtan2:
  6229. return BuiltinFunction::Math_Atan2;
  6230. case OpCode::InlineMathCos:
  6231. return BuiltinFunction::Math_Cos;
  6232. case OpCode::InlineMathExp:
  6233. return BuiltinFunction::Math_Exp;
  6234. case OpCode::InlineMathLog:
  6235. return BuiltinFunction::Math_Log;
  6236. case OpCode::InlineMathPow:
  6237. return BuiltinFunction::Math_Pow;
  6238. case OpCode::InlineMathSin:
  6239. return BuiltinFunction::Math_Sin;
  6240. case OpCode::InlineMathSqrt:
  6241. return BuiltinFunction::Math_Sqrt;
  6242. case OpCode::InlineMathTan:
  6243. return BuiltinFunction::Math_Tan;
  6244. case OpCode::InlineMathAbs:
  6245. return BuiltinFunction::Math_Abs;
  6246. case OpCode::InlineMathClz:
  6247. return BuiltinFunction::Math_Clz32;
  6248. case OpCode::InlineMathCeil:
  6249. return BuiltinFunction::Math_Ceil;
  6250. case OpCode::InlineMathFloor:
  6251. return BuiltinFunction::Math_Floor;
  6252. case OpCode::InlineMathMax:
  6253. return BuiltinFunction::Math_Max;
  6254. case OpCode::InlineMathMin:
  6255. return BuiltinFunction::Math_Min;
  6256. case OpCode::InlineMathImul:
  6257. return BuiltinFunction::Math_Imul;
  6258. case OpCode::InlineMathRandom:
  6259. return BuiltinFunction::Math_Random;
  6260. case OpCode::InlineMathRound:
  6261. return BuiltinFunction::Math_Round;
  6262. case OpCode::InlineMathFround:
  6263. return BuiltinFunction::Math_Fround;
  6264. case OpCode::InlineStringCharAt:
  6265. return BuiltinFunction::JavascriptString_CharAt;
  6266. case OpCode::InlineStringCharCodeAt:
  6267. return BuiltinFunction::JavascriptString_CharCodeAt;
  6268. case OpCode::InlineStringCodePointAt:
  6269. return BuiltinFunction::JavascriptString_CodePointAt;
  6270. case OpCode::InlineArrayPop:
  6271. return BuiltinFunction::JavascriptArray_Pop;
  6272. case OpCode::InlineArrayPush:
  6273. return BuiltinFunction::JavascriptArray_Push;
  6274. case OpCode::InlineFunctionApply:
  6275. return BuiltinFunction::JavascriptFunction_Apply;
  6276. case OpCode::InlineFunctionCall:
  6277. return BuiltinFunction::JavascriptFunction_Call;
  6278. case OpCode::InlineRegExpExec:
  6279. return BuiltinFunction::JavascriptRegExp_Exec;
  6280. }
  6281. return BuiltinFunction::None;
  6282. }
  6283. #endif
  6284. // Parses given flags and arg kind (dst or src1, or src2) returns the type the arg must be type-specialized to.
  6285. // static
  6286. BuiltInArgSpecializationType JavascriptLibrary::GetBuiltInArgType(BuiltInFlags flags, BuiltInArgShift argKind)
  6287. {
  6288. Assert(argKind == BuiltInArgShift::BIAS_Dst || BuiltInArgShift::BIAS_Src1 || BuiltInArgShift::BIAS_Src2);
  6289. BuiltInArgSpecializationType type = static_cast<BuiltInArgSpecializationType>(
  6290. (flags >> argKind) & // Shift-out everything to the right of start of interesting area.
  6291. ((1 << Js::BIAS_ArgSize) - 1)); // Mask-out everything to the left of interesting area.
  6292. return type;
  6293. }
  6294. ModuleRecordList* JavascriptLibrary::EnsureModuleRecordList()
  6295. {
  6296. if (moduleRecordList == nullptr)
  6297. {
  6298. moduleRecordList = RecyclerNew(recycler, ModuleRecordList, recycler);
  6299. }
  6300. return moduleRecordList;
  6301. }
  6302. SourceTextModuleRecord* JavascriptLibrary::GetModuleRecord(uint moduleId)
  6303. {
  6304. Assert((moduleRecordList->Count() >= 0) && (moduleId < (uint)moduleRecordList->Count()));
  6305. if (moduleId >= (uint)moduleRecordList->Count())
  6306. {
  6307. Js::Throw::FatalInternalError();
  6308. }
  6309. return moduleRecordList->Item(moduleId);
  6310. }
  6311. void JavascriptLibrary::BindReference(void * addr)
  6312. {
  6313. // The last void* is the linklist connecting to next block.
  6314. if (bindRefChunkCurrent == bindRefChunkEnd)
  6315. {
  6316. Field(void*)* tmpBindRefChunk = RecyclerNewArrayZ(recycler,
  6317. Field(void*), HeapConstants::ObjectGranularity / sizeof(void *));
  6318. // reserve the last void* as the linklist node.
  6319. bindRefChunkEnd = tmpBindRefChunk + (HeapConstants::ObjectGranularity / sizeof(void *) -1 );
  6320. if (bindRefChunkBegin == nullptr)
  6321. {
  6322. bindRefChunkCurrent = tmpBindRefChunk;
  6323. bindRefChunkBegin = bindRefChunkCurrent;
  6324. }
  6325. else
  6326. {
  6327. *bindRefChunkCurrent = tmpBindRefChunk;
  6328. bindRefChunkCurrent = tmpBindRefChunk;
  6329. }
  6330. }
  6331. Assert((bindRefChunkCurrent+1) <= bindRefChunkEnd);
  6332. *bindRefChunkCurrent = addr;
  6333. bindRefChunkCurrent++;
  6334. }
  6335. void JavascriptLibrary::CleanupForClose()
  6336. {
  6337. bindRefChunkCurrent = nullptr;
  6338. bindRefChunkEnd = nullptr;
  6339. }
  6340. void JavascriptLibrary::BeginDynamicFunctionReferences()
  6341. {
  6342. if (this->dynamicFunctionReference == nullptr)
  6343. {
  6344. this->dynamicFunctionReference = RecyclerNew(this->recycler, FunctionReferenceList, this->recycler);
  6345. this->dynamicFunctionReferenceDepth = 0;
  6346. }
  6347. this->dynamicFunctionReferenceDepth++;
  6348. }
  6349. void JavascriptLibrary::EndDynamicFunctionReferences()
  6350. {
  6351. Assert(this->dynamicFunctionReference != nullptr);
  6352. this->dynamicFunctionReferenceDepth--;
  6353. if (this->dynamicFunctionReferenceDepth == 0)
  6354. {
  6355. this->dynamicFunctionReference->Clear();
  6356. }
  6357. }
  6358. void JavascriptLibrary::RegisterDynamicFunctionReference(FunctionProxy* func)
  6359. {
  6360. Assert(this->dynamicFunctionReferenceDepth > 0);
  6361. this->dynamicFunctionReference->Push(func);
  6362. }
  6363. #ifdef ENABLE_SCRIPT_PROFILING
  6364. // Register for profiler
  6365. #define DEFINE_OBJECT_NAME(object) const char16 *pwszObjectName = _u(#object);
  6366. #define REGISTER_OBJECT(object)\
  6367. if (FAILED(hr = this->ProfilerRegister##object()))\
  6368. {\
  6369. return hr; \
  6370. }\
  6371. #define REG_LIB_FUNC_CORE(pwszObjectName, pwszFunctionName, functionPropertyId, entryPoint)\
  6372. if (FAILED(hr = this->GetScriptContext()->RegisterLibraryFunction(pwszObjectName, pwszFunctionName, functionPropertyId, entryPoint)))\
  6373. {\
  6374. return hr; \
  6375. }\
  6376. #define REG_OBJECTS_DYNAMIC_LIB_FUNC(pwszFunctionName, nFuncNameLen, entryPoint) {\
  6377. Js::PropertyRecord const * propRecord; \
  6378. this->GetScriptContext()->GetOrAddPropertyRecord(pwszFunctionName, nFuncNameLen, &propRecord); \
  6379. REG_LIB_FUNC_CORE(pwszObjectName, pwszFunctionName, propRecord->GetPropertyId(), entryPoint)\
  6380. }
  6381. #define REG_LIB_FUNC(pwszObjectName, functionPropertyId, entryPoint)\
  6382. REG_LIB_FUNC_CORE(pwszObjectName, _u(#functionPropertyId), PropertyIds::##functionPropertyId, entryPoint)\
  6383. #define REG_OBJECTS_LIB_FUNC(functionPropertyId, entryPoint)\
  6384. REG_LIB_FUNC(pwszObjectName, functionPropertyId, entryPoint)\
  6385. #define REG_OBJECTS_LIB_FUNC2(functionPropertyId, pwszFunctionPropertyName, entryPoint)\
  6386. REG_LIB_FUNC_CORE(pwszObjectName, pwszFunctionPropertyName, PropertyIds::##functionPropertyId, entryPoint)\
  6387. #define REG_GLOBAL_LIB_FUNC(functionPropertyId, entryPoint)\
  6388. REG_LIB_FUNC(NULL, functionPropertyId, entryPoint)\
  6389. #define REG_GLOBAL_CONSTRUCTOR(functionPropertyId)\
  6390. REG_GLOBAL_LIB_FUNC(functionPropertyId, Javascript##functionPropertyId##::NewInstance)\
  6391. #define REGISTER_ERROR_OBJECT(functionPropertyId)\
  6392. REG_GLOBAL_LIB_FUNC(functionPropertyId, JavascriptError::New##functionPropertyId##Instance)\
  6393. REG_LIB_FUNC(_u(#functionPropertyId), toString, JavascriptError::EntryToString)\
  6394. HRESULT JavascriptLibrary::ProfilerRegisterBuiltIns()
  6395. {
  6396. HRESULT hr = S_OK;
  6397. // Register functions directly in global scope
  6398. REG_GLOBAL_LIB_FUNC(eval, GlobalObject::EntryEval);
  6399. REG_GLOBAL_LIB_FUNC(parseInt, GlobalObject::EntryParseInt);
  6400. REG_GLOBAL_LIB_FUNC(parseFloat, GlobalObject::EntryParseFloat);
  6401. REG_GLOBAL_LIB_FUNC(isNaN, GlobalObject::EntryIsNaN);
  6402. REG_GLOBAL_LIB_FUNC(isFinite, GlobalObject::EntryIsFinite);
  6403. REG_GLOBAL_LIB_FUNC(decodeURI, GlobalObject::EntryDecodeURI);
  6404. REG_GLOBAL_LIB_FUNC(decodeURIComponent, GlobalObject::EntryDecodeURIComponent);
  6405. REG_GLOBAL_LIB_FUNC(encodeURI, GlobalObject::EntryEncodeURI);
  6406. REG_GLOBAL_LIB_FUNC(encodeURIComponent, GlobalObject::EntryEncodeURIComponent);
  6407. REG_GLOBAL_LIB_FUNC(escape, GlobalObject::EntryEscape);
  6408. REG_GLOBAL_LIB_FUNC(unescape, GlobalObject::EntryUnEscape);
  6409. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  6410. if (config.SupportsCollectGarbage())
  6411. {
  6412. REG_GLOBAL_LIB_FUNC(CollectGarbage, GlobalObject::EntryCollectGarbage);
  6413. }
  6414. // Register constructors, prototypes and objects in global
  6415. REGISTER_OBJECT(Object);
  6416. REGISTER_OBJECT(Array);
  6417. REGISTER_OBJECT(Boolean);
  6418. REGISTER_OBJECT(Date);
  6419. REGISTER_OBJECT(Function);
  6420. REGISTER_OBJECT(Math);
  6421. REGISTER_OBJECT(Number);
  6422. REGISTER_OBJECT(String);
  6423. REGISTER_OBJECT(RegExp);
  6424. REGISTER_OBJECT(JSON);
  6425. REGISTER_OBJECT(Map);
  6426. REGISTER_OBJECT(Set);
  6427. REGISTER_OBJECT(WeakMap);
  6428. REGISTER_OBJECT(WeakSet);
  6429. REGISTER_OBJECT(Symbol);
  6430. REGISTER_OBJECT(Iterator);
  6431. REGISTER_OBJECT(ArrayIterator);
  6432. REGISTER_OBJECT(MapIterator);
  6433. REGISTER_OBJECT(SetIterator);
  6434. REGISTER_OBJECT(StringIterator);
  6435. REGISTER_OBJECT(TypedArray);
  6436. if (config.IsES6PromiseEnabled())
  6437. {
  6438. REGISTER_OBJECT(Promise);
  6439. }
  6440. if (config.IsES6ProxyEnabled())
  6441. {
  6442. REGISTER_OBJECT(Proxy);
  6443. REGISTER_OBJECT(Reflect);
  6444. }
  6445. #ifdef IR_VIEWER
  6446. if (Js::Configuration::Global.flags.IsEnabled(Js::IRViewerFlag))
  6447. {
  6448. REGISTER_OBJECT(IRViewer);
  6449. }
  6450. #endif /* IR_VIEWER */
  6451. // Error Constructors and prototypes
  6452. REGISTER_ERROR_OBJECT(Error);
  6453. REGISTER_ERROR_OBJECT(EvalError);
  6454. REGISTER_ERROR_OBJECT(RangeError);
  6455. REGISTER_ERROR_OBJECT(ReferenceError);
  6456. REGISTER_ERROR_OBJECT(SyntaxError);
  6457. REGISTER_ERROR_OBJECT(TypeError);
  6458. REGISTER_ERROR_OBJECT(URIError);
  6459. #ifdef ENABLE_PROJECTION
  6460. if (config.IsWinRTEnabled())
  6461. {
  6462. REGISTER_ERROR_OBJECT(WinRTError);
  6463. }
  6464. #endif
  6465. return hr;
  6466. }
  6467. HRESULT JavascriptLibrary::ProfilerRegisterObject()
  6468. {
  6469. HRESULT hr = S_OK;
  6470. REG_GLOBAL_CONSTRUCTOR(Object);
  6471. DEFINE_OBJECT_NAME(Object);
  6472. REG_OBJECTS_LIB_FUNC(defineProperty, JavascriptObject::EntryDefineProperty);
  6473. REG_OBJECTS_LIB_FUNC(getOwnPropertyDescriptor, JavascriptObject::EntryGetOwnPropertyDescriptor);
  6474. if (scriptContext->GetConfig()->IsESObjectGetOwnPropertyDescriptorsEnabled())
  6475. {
  6476. REG_OBJECTS_LIB_FUNC(getOwnPropertyDescriptors, JavascriptObject::EntryGetOwnPropertyDescriptors);
  6477. }
  6478. REG_OBJECTS_LIB_FUNC(defineProperties, JavascriptObject::EntryDefineProperties);
  6479. REG_OBJECTS_LIB_FUNC(create, JavascriptObject::EntryCreate);
  6480. REG_OBJECTS_LIB_FUNC(seal, JavascriptObject::EntrySeal);
  6481. REG_OBJECTS_LIB_FUNC(freeze, JavascriptObject::EntryFreeze);
  6482. REG_OBJECTS_LIB_FUNC(preventExtensions, JavascriptObject::EntryPreventExtensions);
  6483. REG_OBJECTS_LIB_FUNC(isSealed, JavascriptObject::EntryIsSealed);
  6484. REG_OBJECTS_LIB_FUNC(isFrozen, JavascriptObject::EntryIsFrozen);
  6485. REG_OBJECTS_LIB_FUNC(isExtensible, JavascriptObject::EntryIsExtensible);
  6486. REG_OBJECTS_LIB_FUNC(getPrototypeOf, JavascriptObject::EntryGetPrototypeOf);
  6487. REG_OBJECTS_LIB_FUNC(keys, JavascriptObject::EntryKeys);
  6488. REG_OBJECTS_LIB_FUNC(getOwnPropertyNames, JavascriptObject::EntryGetOwnPropertyNames);
  6489. REG_OBJECTS_LIB_FUNC(setPrototypeOf, JavascriptObject::EntrySetPrototypeOf);
  6490. REG_OBJECTS_LIB_FUNC(getOwnPropertySymbols, JavascriptObject::EntryGetOwnPropertySymbols);
  6491. REG_OBJECTS_LIB_FUNC(hasOwnProperty, JavascriptObject::EntryHasOwnProperty);
  6492. REG_OBJECTS_LIB_FUNC(propertyIsEnumerable, JavascriptObject::EntryPropertyIsEnumerable);
  6493. REG_OBJECTS_LIB_FUNC(isPrototypeOf, JavascriptObject::EntryIsPrototypeOf);
  6494. REG_OBJECTS_LIB_FUNC(toLocaleString, JavascriptObject::EntryToLocaleString);
  6495. REG_OBJECTS_LIB_FUNC(toString, JavascriptObject::EntryToString);
  6496. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptObject::EntryValueOf);
  6497. REG_OBJECTS_LIB_FUNC(__defineGetter__, JavascriptObject::EntryDefineGetter);
  6498. REG_OBJECTS_LIB_FUNC(__defineSetter__, JavascriptObject::EntryDefineSetter);
  6499. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  6500. if (config.IsES6ObjectExtensionsEnabled())
  6501. {
  6502. REG_OBJECTS_LIB_FUNC(is, JavascriptObject::EntryIs);
  6503. REG_OBJECTS_LIB_FUNC(assign, JavascriptObject::EntryAssign);
  6504. }
  6505. if (config.IsES7ValuesEntriesEnabled())
  6506. {
  6507. REG_OBJECTS_LIB_FUNC(values, JavascriptObject::EntryValues);
  6508. REG_OBJECTS_LIB_FUNC(entries, JavascriptObject::EntryEntries);
  6509. }
  6510. return hr;
  6511. }
  6512. HRESULT JavascriptLibrary::ProfilerRegisterArray()
  6513. {
  6514. HRESULT hr = S_OK;
  6515. REG_GLOBAL_CONSTRUCTOR(Array);
  6516. DEFINE_OBJECT_NAME(Array);
  6517. REG_OBJECTS_LIB_FUNC(isArray, JavascriptArray::EntryIsArray);
  6518. REG_OBJECTS_LIB_FUNC(concat, JavascriptArray::EntryConcat);
  6519. REG_OBJECTS_LIB_FUNC(join, JavascriptArray::EntryJoin);
  6520. REG_OBJECTS_LIB_FUNC(pop, JavascriptArray::EntryPop);
  6521. REG_OBJECTS_LIB_FUNC(push, JavascriptArray::EntryPush);
  6522. REG_OBJECTS_LIB_FUNC(reverse, JavascriptArray::EntryReverse);
  6523. REG_OBJECTS_LIB_FUNC(shift, JavascriptArray::EntryShift);
  6524. REG_OBJECTS_LIB_FUNC(slice, JavascriptArray::EntrySlice);
  6525. REG_OBJECTS_LIB_FUNC(sort, JavascriptArray::EntrySort);
  6526. REG_OBJECTS_LIB_FUNC(splice, JavascriptArray::EntrySplice);
  6527. REG_OBJECTS_LIB_FUNC(toLocaleString, JavascriptArray::EntryToLocaleString);
  6528. REG_OBJECTS_LIB_FUNC(toString, JavascriptArray::EntryToString);
  6529. REG_OBJECTS_LIB_FUNC(unshift, JavascriptArray::EntryUnshift);
  6530. REG_OBJECTS_LIB_FUNC(indexOf, JavascriptArray::EntryIndexOf);
  6531. REG_OBJECTS_LIB_FUNC(every, JavascriptArray::EntryEvery);
  6532. REG_OBJECTS_LIB_FUNC(filter, JavascriptArray::EntryFilter);
  6533. REG_OBJECTS_LIB_FUNC(forEach, JavascriptArray::EntryForEach);
  6534. REG_OBJECTS_LIB_FUNC(lastIndexOf, JavascriptArray::EntryLastIndexOf);
  6535. REG_OBJECTS_LIB_FUNC(map, JavascriptArray::EntryMap);
  6536. REG_OBJECTS_LIB_FUNC(reduce, JavascriptArray::EntryReduce);
  6537. REG_OBJECTS_LIB_FUNC(reduceRight, JavascriptArray::EntryReduceRight);
  6538. REG_OBJECTS_LIB_FUNC(some, JavascriptArray::EntrySome);
  6539. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  6540. if (config.IsES6StringExtensionsEnabled())
  6541. {
  6542. REG_OBJECTS_LIB_FUNC(find, JavascriptArray::EntryFind);
  6543. REG_OBJECTS_LIB_FUNC(findIndex, JavascriptArray::EntryFindIndex);
  6544. }
  6545. // All iterator constructor functions are implemeted in Js when JsBuiltIns are enabled and their entrypoint will be the same
  6546. // The profiler cannot distinguish between them
  6547. if (!scriptContext->IsJsBuiltInEnabled())
  6548. {
  6549. REG_OBJECTS_LIB_FUNC(entries, JavascriptArray::EntryEntries)
  6550. REG_OBJECTS_LIB_FUNC(keys, JavascriptArray::EntryKeys)
  6551. REG_OBJECTS_LIB_FUNC(values, JavascriptArray::EntryValues)
  6552. // _symbolIterator is just an alias for values on Array.prototype so do not register it as its own function
  6553. }
  6554. REG_OBJECTS_LIB_FUNC(fill, JavascriptArray::EntryFill)
  6555. REG_OBJECTS_LIB_FUNC(copyWithin, JavascriptArray::EntryCopyWithin)
  6556. REG_OBJECTS_LIB_FUNC(from, JavascriptArray::EntryFrom);
  6557. REG_OBJECTS_LIB_FUNC(of, JavascriptArray::EntryOf);
  6558. REG_OBJECTS_LIB_FUNC(includes, JavascriptArray::EntryIncludes);
  6559. return hr;
  6560. }
  6561. HRESULT JavascriptLibrary::ProfilerRegisterBoolean()
  6562. {
  6563. HRESULT hr = S_OK;
  6564. REG_GLOBAL_CONSTRUCTOR(Boolean);
  6565. DEFINE_OBJECT_NAME(Boolean);
  6566. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptBoolean::EntryValueOf);
  6567. REG_OBJECTS_LIB_FUNC(toString, JavascriptBoolean::EntryToString);
  6568. return hr;
  6569. }
  6570. HRESULT JavascriptLibrary::ProfilerRegisterDate()
  6571. {
  6572. HRESULT hr = S_OK;
  6573. REG_GLOBAL_CONSTRUCTOR(Date);
  6574. DEFINE_OBJECT_NAME(Date);
  6575. REG_OBJECTS_LIB_FUNC(parse, JavascriptDate::EntryParse);
  6576. REG_OBJECTS_LIB_FUNC(now, JavascriptDate::EntryNow);
  6577. REG_OBJECTS_LIB_FUNC(UTC, JavascriptDate::EntryUTC);
  6578. REG_OBJECTS_LIB_FUNC(getDate, JavascriptDate::EntryGetDate);
  6579. REG_OBJECTS_LIB_FUNC(getDay, JavascriptDate::EntryGetDay);
  6580. REG_OBJECTS_LIB_FUNC(getFullYear, JavascriptDate::EntryGetFullYear);
  6581. REG_OBJECTS_LIB_FUNC(getHours, JavascriptDate::EntryGetHours);
  6582. REG_OBJECTS_LIB_FUNC(getMilliseconds, JavascriptDate::EntryGetMilliseconds);
  6583. REG_OBJECTS_LIB_FUNC(getMinutes, JavascriptDate::EntryGetMinutes);
  6584. REG_OBJECTS_LIB_FUNC(getMonth, JavascriptDate::EntryGetMonth);
  6585. REG_OBJECTS_LIB_FUNC(getSeconds, JavascriptDate::EntryGetSeconds);
  6586. REG_OBJECTS_LIB_FUNC(getTime, JavascriptDate::EntryGetTime);
  6587. REG_OBJECTS_LIB_FUNC(getTimezoneOffset, JavascriptDate::EntryGetTimezoneOffset);
  6588. REG_OBJECTS_LIB_FUNC(getUTCDate, JavascriptDate::EntryGetUTCDate);
  6589. REG_OBJECTS_LIB_FUNC(getUTCDay, JavascriptDate::EntryGetUTCDay);
  6590. REG_OBJECTS_LIB_FUNC(getUTCFullYear, JavascriptDate::EntryGetUTCFullYear);
  6591. REG_OBJECTS_LIB_FUNC(getUTCHours, JavascriptDate::EntryGetUTCHours);
  6592. REG_OBJECTS_LIB_FUNC(getUTCMilliseconds, JavascriptDate::EntryGetUTCMilliseconds);
  6593. REG_OBJECTS_LIB_FUNC(getUTCMinutes, JavascriptDate::EntryGetUTCMinutes);
  6594. REG_OBJECTS_LIB_FUNC(getUTCMonth, JavascriptDate::EntryGetUTCMonth);
  6595. REG_OBJECTS_LIB_FUNC(getUTCSeconds, JavascriptDate::EntryGetUTCSeconds);
  6596. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  6597. if (config.SupportsES3Extensions())
  6598. {
  6599. REG_OBJECTS_LIB_FUNC(getVarDate, JavascriptDate::EntryGetVarDate);
  6600. }
  6601. REG_OBJECTS_LIB_FUNC(getYear, JavascriptDate::EntryGetYear);
  6602. REG_OBJECTS_LIB_FUNC(setDate, JavascriptDate::EntrySetDate);
  6603. REG_OBJECTS_LIB_FUNC(setFullYear, JavascriptDate::EntrySetFullYear);
  6604. REG_OBJECTS_LIB_FUNC(setHours, JavascriptDate::EntrySetHours);
  6605. REG_OBJECTS_LIB_FUNC(setMilliseconds, JavascriptDate::EntrySetMilliseconds);
  6606. REG_OBJECTS_LIB_FUNC(setMinutes, JavascriptDate::EntrySetMinutes);
  6607. REG_OBJECTS_LIB_FUNC(setMonth, JavascriptDate::EntrySetMonth);
  6608. REG_OBJECTS_LIB_FUNC(setSeconds, JavascriptDate::EntrySetSeconds);
  6609. REG_OBJECTS_LIB_FUNC(setTime, JavascriptDate::EntrySetTime);
  6610. REG_OBJECTS_LIB_FUNC(setUTCDate, JavascriptDate::EntrySetUTCDate);
  6611. REG_OBJECTS_LIB_FUNC(setUTCFullYear, JavascriptDate::EntrySetUTCFullYear);
  6612. REG_OBJECTS_LIB_FUNC(setUTCHours, JavascriptDate::EntrySetUTCHours);
  6613. REG_OBJECTS_LIB_FUNC(setUTCMilliseconds, JavascriptDate::EntrySetUTCMilliseconds);
  6614. REG_OBJECTS_LIB_FUNC(setUTCMinutes, JavascriptDate::EntrySetUTCMinutes);
  6615. REG_OBJECTS_LIB_FUNC(setUTCMonth, JavascriptDate::EntrySetUTCMonth);
  6616. REG_OBJECTS_LIB_FUNC(setUTCSeconds, JavascriptDate::EntrySetUTCSeconds);
  6617. REG_OBJECTS_LIB_FUNC(setYear, JavascriptDate::EntrySetYear);
  6618. REG_OBJECTS_LIB_FUNC(toDateString, JavascriptDate::EntryToDateString);
  6619. REG_OBJECTS_LIB_FUNC(toISOString, JavascriptDate::EntryToISOString);
  6620. REG_OBJECTS_LIB_FUNC(toJSON, JavascriptDate::EntryToJSON);
  6621. REG_OBJECTS_LIB_FUNC(toLocaleDateString, JavascriptDate::EntryToLocaleDateString);
  6622. REG_OBJECTS_LIB_FUNC(toLocaleString, JavascriptDate::EntryToLocaleString);
  6623. REG_OBJECTS_LIB_FUNC(toLocaleTimeString, JavascriptDate::EntryToLocaleTimeString);
  6624. REG_OBJECTS_LIB_FUNC(toString, JavascriptDate::EntryToString);
  6625. REG_OBJECTS_LIB_FUNC(toTimeString, JavascriptDate::EntryToTimeString);
  6626. REG_OBJECTS_LIB_FUNC(toUTCString, JavascriptDate::EntryToUTCString);
  6627. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptDate::EntryValueOf);
  6628. return hr;
  6629. }
  6630. HRESULT JavascriptLibrary::ProfilerRegisterFunction()
  6631. {
  6632. HRESULT hr = S_OK;
  6633. REG_GLOBAL_CONSTRUCTOR(Function);
  6634. DEFINE_OBJECT_NAME(Function);
  6635. REG_OBJECTS_LIB_FUNC(apply, JavascriptFunction::EntryApply);
  6636. REG_OBJECTS_LIB_FUNC(bind, JavascriptFunction::EntryBind);
  6637. REG_OBJECTS_LIB_FUNC(call, JavascriptFunction::EntryCall);
  6638. REG_OBJECTS_LIB_FUNC(toString, JavascriptFunction::EntryToString);
  6639. return hr;
  6640. }
  6641. HRESULT JavascriptLibrary::ProfilerRegisterMath()
  6642. {
  6643. HRESULT hr = S_OK;
  6644. DEFINE_OBJECT_NAME(Math);
  6645. REG_OBJECTS_LIB_FUNC(abs, Math::Abs);
  6646. REG_OBJECTS_LIB_FUNC(acos, Math::Acos);
  6647. REG_OBJECTS_LIB_FUNC(asin, Math::Asin);
  6648. REG_OBJECTS_LIB_FUNC(atan, Math::Atan);
  6649. REG_OBJECTS_LIB_FUNC(atan2, Math::Atan2);
  6650. REG_OBJECTS_LIB_FUNC(ceil, Math::Ceil);
  6651. REG_OBJECTS_LIB_FUNC(cos, Math::Cos);
  6652. REG_OBJECTS_LIB_FUNC(exp, Math::Exp);
  6653. REG_OBJECTS_LIB_FUNC(floor, Math::Floor);
  6654. REG_OBJECTS_LIB_FUNC(log, Math::Log);
  6655. REG_OBJECTS_LIB_FUNC(max, Math::Max);
  6656. REG_OBJECTS_LIB_FUNC(min, Math::Min);
  6657. REG_OBJECTS_LIB_FUNC(pow, Math::Pow);
  6658. REG_OBJECTS_LIB_FUNC(random, Math::Random);
  6659. REG_OBJECTS_LIB_FUNC(round, Math::Round);
  6660. REG_OBJECTS_LIB_FUNC(sin, Math::Sin);
  6661. REG_OBJECTS_LIB_FUNC(sqrt, Math::Sqrt);
  6662. REG_OBJECTS_LIB_FUNC(tan, Math::Tan);
  6663. if (scriptContext->GetConfig()->IsES6MathExtensionsEnabled())
  6664. {
  6665. REG_OBJECTS_LIB_FUNC(log10, Math::Log10);
  6666. REG_OBJECTS_LIB_FUNC(log2, Math::Log2);
  6667. REG_OBJECTS_LIB_FUNC(log1p, Math::Log1p);
  6668. REG_OBJECTS_LIB_FUNC(expm1, Math::Expm1);
  6669. REG_OBJECTS_LIB_FUNC(cosh, Math::Cosh);
  6670. REG_OBJECTS_LIB_FUNC(sinh, Math::Sinh);
  6671. REG_OBJECTS_LIB_FUNC(tanh, Math::Tanh);
  6672. REG_OBJECTS_LIB_FUNC(acosh, Math::Acosh);
  6673. REG_OBJECTS_LIB_FUNC(asinh, Math::Asinh);
  6674. REG_OBJECTS_LIB_FUNC(atanh, Math::Atanh);
  6675. REG_OBJECTS_LIB_FUNC(hypot, Math::Hypot);
  6676. REG_OBJECTS_LIB_FUNC(trunc, Math::Trunc);
  6677. REG_OBJECTS_LIB_FUNC(sign, Math::Sign);
  6678. REG_OBJECTS_LIB_FUNC(cbrt, Math::Cbrt);
  6679. REG_OBJECTS_LIB_FUNC(imul, Math::Imul);
  6680. REG_OBJECTS_LIB_FUNC(clz32, Math::Clz32);
  6681. REG_OBJECTS_LIB_FUNC(fround, Math::Fround);
  6682. }
  6683. return hr;
  6684. }
  6685. HRESULT JavascriptLibrary::ProfilerRegisterNumber()
  6686. {
  6687. HRESULT hr = S_OK;
  6688. REG_GLOBAL_CONSTRUCTOR(Number);
  6689. DEFINE_OBJECT_NAME(Number);
  6690. if (scriptContext->GetConfig()->IsES6NumberExtensionsEnabled())
  6691. {
  6692. REG_OBJECTS_LIB_FUNC(isNaN, JavascriptNumber::EntryIsNaN);
  6693. REG_OBJECTS_LIB_FUNC(isFinite, JavascriptNumber::EntryIsFinite);
  6694. REG_OBJECTS_LIB_FUNC(isInteger, JavascriptNumber::EntryIsInteger);
  6695. REG_OBJECTS_LIB_FUNC(isSafeInteger, JavascriptNumber::EntryIsSafeInteger);
  6696. }
  6697. REG_OBJECTS_LIB_FUNC(toExponential, JavascriptNumber::EntryToExponential);
  6698. REG_OBJECTS_LIB_FUNC(toFixed, JavascriptNumber::EntryToFixed);
  6699. REG_OBJECTS_LIB_FUNC(toPrecision, JavascriptNumber::EntryToPrecision);
  6700. REG_OBJECTS_LIB_FUNC(toLocaleString, JavascriptNumber::EntryToLocaleString);
  6701. REG_OBJECTS_LIB_FUNC(toString, JavascriptNumber::EntryToString);
  6702. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptNumber::EntryValueOf);
  6703. return hr;
  6704. }
  6705. HRESULT JavascriptLibrary::ProfilerRegisterString()
  6706. {
  6707. HRESULT hr = S_OK;
  6708. REG_GLOBAL_CONSTRUCTOR(String);
  6709. DEFINE_OBJECT_NAME(String);
  6710. REG_OBJECTS_LIB_FUNC(fromCharCode, JavascriptString::EntryFromCharCode);
  6711. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  6712. if (config.IsES6UnicodeExtensionsEnabled())
  6713. {
  6714. REG_OBJECTS_LIB_FUNC(fromCodePoint, JavascriptString::EntryFromCodePoint);
  6715. REG_OBJECTS_LIB_FUNC(codePointAt, JavascriptString::EntryCodePointAt);
  6716. REG_OBJECTS_LIB_FUNC(normalize, JavascriptString::EntryNormalize);
  6717. }
  6718. REG_OBJECTS_LIB_FUNC(indexOf, JavascriptString::EntryIndexOf);
  6719. REG_OBJECTS_LIB_FUNC(lastIndexOf, JavascriptString::EntryLastIndexOf);
  6720. REG_OBJECTS_LIB_FUNC(replace, JavascriptString::EntryReplace);
  6721. REG_OBJECTS_LIB_FUNC(search, JavascriptString::EntrySearch);
  6722. REG_OBJECTS_LIB_FUNC(slice, JavascriptString::EntrySlice);
  6723. REG_OBJECTS_LIB_FUNC(charAt, JavascriptString::EntryCharAt);
  6724. REG_OBJECTS_LIB_FUNC(charCodeAt, JavascriptString::EntryCharCodeAt);
  6725. REG_OBJECTS_LIB_FUNC(concat, JavascriptString::EntryConcat);
  6726. REG_OBJECTS_LIB_FUNC(localeCompare, JavascriptString::EntryLocaleCompare);
  6727. REG_OBJECTS_LIB_FUNC(match, JavascriptString::EntryMatch);
  6728. REG_OBJECTS_LIB_FUNC(split, JavascriptString::EntrySplit);
  6729. REG_OBJECTS_LIB_FUNC(substring, JavascriptString::EntrySubstring);
  6730. REG_OBJECTS_LIB_FUNC(substr, JavascriptString::EntrySubstr);
  6731. REG_OBJECTS_LIB_FUNC(toLocaleLowerCase, JavascriptString::EntryToLocaleLowerCase);
  6732. REG_OBJECTS_LIB_FUNC(toLocaleUpperCase, JavascriptString::EntryToLocaleUpperCase);
  6733. REG_OBJECTS_LIB_FUNC(toLowerCase, JavascriptString::EntryToLowerCase);
  6734. REG_OBJECTS_LIB_FUNC(toString, JavascriptString::EntryToString);
  6735. REG_OBJECTS_LIB_FUNC(toUpperCase, JavascriptString::EntryToUpperCase);
  6736. REG_OBJECTS_LIB_FUNC(trim, JavascriptString::EntryTrim);
  6737. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptString::EntryValueOf);
  6738. REG_OBJECTS_LIB_FUNC(anchor, JavascriptString::EntryAnchor);
  6739. REG_OBJECTS_LIB_FUNC(big, JavascriptString::EntryBig);
  6740. REG_OBJECTS_LIB_FUNC(blink, JavascriptString::EntryBlink);
  6741. REG_OBJECTS_LIB_FUNC(bold, JavascriptString::EntryBold);
  6742. REG_OBJECTS_LIB_FUNC(fixed, JavascriptString::EntryFixed);
  6743. REG_OBJECTS_LIB_FUNC(fontcolor, JavascriptString::EntryFontColor);
  6744. REG_OBJECTS_LIB_FUNC(fontsize, JavascriptString::EntryFontSize);
  6745. REG_OBJECTS_LIB_FUNC(italics, JavascriptString::EntryItalics);
  6746. REG_OBJECTS_LIB_FUNC(link, JavascriptString::EntryLink);
  6747. REG_OBJECTS_DYNAMIC_LIB_FUNC(_u("small"), 5, JavascriptString::EntrySmall);
  6748. REG_OBJECTS_LIB_FUNC(strike, JavascriptString::EntryStrike);
  6749. REG_OBJECTS_LIB_FUNC(sub, JavascriptString::EntrySub);
  6750. REG_OBJECTS_LIB_FUNC(sup, JavascriptString::EntrySup);
  6751. if (config.IsES6StringExtensionsEnabled())
  6752. {
  6753. REG_OBJECTS_LIB_FUNC(repeat, JavascriptString::EntryRepeat);
  6754. REG_OBJECTS_LIB_FUNC(startsWith, JavascriptString::EntryStartsWith);
  6755. REG_OBJECTS_LIB_FUNC(endsWith, JavascriptString::EntryEndsWith);
  6756. REG_OBJECTS_LIB_FUNC(includes, JavascriptString::EntryIncludes);
  6757. REG_OBJECTS_LIB_FUNC(trimLeft, JavascriptString::EntryTrimLeft);
  6758. REG_OBJECTS_LIB_FUNC(trimRight, JavascriptString::EntryTrimRight);
  6759. }
  6760. REG_OBJECTS_LIB_FUNC(raw, JavascriptString::EntryRaw);
  6761. REG_OBJECTS_LIB_FUNC2(_symbolIterator, _u("[Symbol.iterator]"), JavascriptString::EntrySymbolIterator);
  6762. REG_OBJECTS_LIB_FUNC(padStart, JavascriptString::EntryPadStart);
  6763. REG_OBJECTS_LIB_FUNC(padEnd, JavascriptString::EntryPadEnd);
  6764. return hr;
  6765. }
  6766. HRESULT JavascriptLibrary::ProfilerRegisterRegExp()
  6767. {
  6768. HRESULT hr = S_OK;
  6769. REG_GLOBAL_CONSTRUCTOR(RegExp);
  6770. DEFINE_OBJECT_NAME(RegExp);
  6771. REG_OBJECTS_LIB_FUNC(exec, JavascriptRegExp::EntryExec);
  6772. REG_OBJECTS_LIB_FUNC(test, JavascriptRegExp::EntryTest);
  6773. REG_OBJECTS_LIB_FUNC(toString, JavascriptRegExp::EntryToString);
  6774. // Note: This is deprecated
  6775. REG_OBJECTS_LIB_FUNC(compile, JavascriptRegExp::EntryCompile);
  6776. return hr;
  6777. }
  6778. HRESULT JavascriptLibrary::ProfilerRegisterJSON()
  6779. {
  6780. HRESULT hr = S_OK;
  6781. DEFINE_OBJECT_NAME(JSON);
  6782. REG_OBJECTS_LIB_FUNC(stringify, JSON::Stringify);
  6783. REG_OBJECTS_LIB_FUNC(parse, JSON::Parse);
  6784. return hr;
  6785. }
  6786. HRESULT JavascriptLibrary::ProfilerRegisterAtomics()
  6787. {
  6788. HRESULT hr = S_OK;
  6789. DEFINE_OBJECT_NAME(Atomics);
  6790. REG_OBJECTS_LIB_FUNC(add, AtomicsObject::EntryAdd);
  6791. REG_OBJECTS_LIB_FUNC(and_, AtomicsObject::EntryAnd);
  6792. REG_OBJECTS_LIB_FUNC(compareExchange, AtomicsObject::EntryCompareExchange);
  6793. REG_OBJECTS_LIB_FUNC(exchange, AtomicsObject::EntryExchange);
  6794. REG_OBJECTS_LIB_FUNC(isLockFree, AtomicsObject::EntryIsLockFree);
  6795. REG_OBJECTS_LIB_FUNC(load, AtomicsObject::EntryLoad);
  6796. REG_OBJECTS_LIB_FUNC(or_, AtomicsObject::EntryOr);
  6797. REG_OBJECTS_LIB_FUNC(store, AtomicsObject::EntryStore);
  6798. REG_OBJECTS_LIB_FUNC(sub, AtomicsObject::EntrySub);
  6799. REG_OBJECTS_LIB_FUNC(wait, AtomicsObject::EntryWait);
  6800. REG_OBJECTS_LIB_FUNC(wake, AtomicsObject::EntryWake);
  6801. REG_OBJECTS_LIB_FUNC(xor_, AtomicsObject::EntryXor);
  6802. return hr;
  6803. }
  6804. HRESULT JavascriptLibrary::ProfilerRegisterWeakMap()
  6805. {
  6806. HRESULT hr = S_OK;
  6807. REG_GLOBAL_CONSTRUCTOR(WeakMap);
  6808. DEFINE_OBJECT_NAME(WeakMap);
  6809. REG_OBJECTS_LIB_FUNC2(delete_, _u("delete"), JavascriptWeakMap::EntryDelete);
  6810. REG_OBJECTS_LIB_FUNC(get, JavascriptWeakMap::EntryGet);
  6811. REG_OBJECTS_LIB_FUNC(has, JavascriptWeakMap::EntryHas);
  6812. REG_OBJECTS_LIB_FUNC(set, JavascriptWeakMap::EntrySet);
  6813. return hr;
  6814. }
  6815. HRESULT JavascriptLibrary::ProfilerRegisterWeakSet()
  6816. {
  6817. HRESULT hr = S_OK;
  6818. REG_GLOBAL_CONSTRUCTOR(WeakSet);
  6819. DEFINE_OBJECT_NAME(WeakSet);
  6820. REG_OBJECTS_LIB_FUNC(add, JavascriptWeakSet::EntryAdd);
  6821. REG_OBJECTS_LIB_FUNC2(delete_, _u("delete"), JavascriptWeakSet::EntryDelete);
  6822. REG_OBJECTS_LIB_FUNC(has, JavascriptWeakSet::EntryHas);
  6823. return hr;
  6824. }
  6825. HRESULT JavascriptLibrary::ProfilerRegisterMap()
  6826. {
  6827. HRESULT hr = S_OK;
  6828. REG_GLOBAL_CONSTRUCTOR(Map);
  6829. DEFINE_OBJECT_NAME(Map);
  6830. REG_OBJECTS_LIB_FUNC(clear, JavascriptMap::EntryClear);
  6831. REG_OBJECTS_LIB_FUNC2(delete_, _u("delete"), JavascriptMap::EntryDelete);
  6832. REG_OBJECTS_LIB_FUNC(forEach, JavascriptMap::EntryForEach);
  6833. REG_OBJECTS_LIB_FUNC(get, JavascriptMap::EntryGet);
  6834. REG_OBJECTS_LIB_FUNC(has, JavascriptMap::EntryHas);
  6835. REG_OBJECTS_LIB_FUNC(set, JavascriptMap::EntrySet);
  6836. REG_OBJECTS_LIB_FUNC(entries, JavascriptMap::EntryEntries);
  6837. REG_OBJECTS_LIB_FUNC(keys, JavascriptMap::EntryKeys);
  6838. REG_OBJECTS_LIB_FUNC(values, JavascriptMap::EntryValues);
  6839. return hr;
  6840. }
  6841. HRESULT JavascriptLibrary::ProfilerRegisterSet()
  6842. {
  6843. HRESULT hr = S_OK;
  6844. REG_GLOBAL_CONSTRUCTOR(Set);
  6845. DEFINE_OBJECT_NAME(Set);
  6846. REG_OBJECTS_LIB_FUNC(add, JavascriptSet::EntryAdd);
  6847. REG_OBJECTS_LIB_FUNC(clear, JavascriptSet::EntryClear);
  6848. REG_OBJECTS_LIB_FUNC2(delete_, _u("delete"), JavascriptSet::EntryDelete);
  6849. REG_OBJECTS_LIB_FUNC(forEach, JavascriptSet::EntryForEach);
  6850. REG_OBJECTS_LIB_FUNC(has, JavascriptSet::EntryHas);
  6851. REG_OBJECTS_LIB_FUNC(entries, JavascriptSet::EntryEntries);
  6852. REG_OBJECTS_LIB_FUNC(values, JavascriptSet::EntryValues);
  6853. return hr;
  6854. }
  6855. HRESULT JavascriptLibrary::ProfilerRegisterSymbol()
  6856. {
  6857. HRESULT hr = S_OK;
  6858. REG_GLOBAL_CONSTRUCTOR(Symbol);
  6859. DEFINE_OBJECT_NAME(Symbol);
  6860. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptSymbol::EntryValueOf);
  6861. REG_OBJECTS_LIB_FUNC(toString, JavascriptSymbol::EntryToString);
  6862. REG_OBJECTS_LIB_FUNC2(for_, _u("for"), JavascriptSymbol::EntryFor);
  6863. REG_OBJECTS_LIB_FUNC(keyFor, JavascriptSymbol::EntryKeyFor);
  6864. return hr;
  6865. }
  6866. HRESULT JavascriptLibrary::ProfilerRegisterIterator()
  6867. {
  6868. HRESULT hr = S_OK;
  6869. // Array Iterator has no global constructor
  6870. DEFINE_OBJECT_NAME(Iterator);
  6871. REG_OBJECTS_LIB_FUNC2(_symbolIterator, _u("[Symbol.iterator]"), JavascriptIterator::EntrySymbolIterator);
  6872. return hr;
  6873. }
  6874. HRESULT JavascriptLibrary::ProfilerRegisterArrayIterator()
  6875. {
  6876. HRESULT hr = S_OK;
  6877. // Array Iterator has no global constructor
  6878. #if defined(ENABLE_JS_BUILTINS)
  6879. if (!scriptContext->IsJsBuiltInEnabled())
  6880. {
  6881. DEFINE_OBJECT_NAME(Array Iterator);
  6882. REG_OBJECTS_LIB_FUNC(next, JavascriptArrayIterator::EntryNext);
  6883. }
  6884. #endif
  6885. return hr;
  6886. }
  6887. HRESULT JavascriptLibrary::ProfilerRegisterMapIterator()
  6888. {
  6889. HRESULT hr = S_OK;
  6890. // Map Iterator has no global constructor
  6891. DEFINE_OBJECT_NAME(Map Iterator);
  6892. REG_OBJECTS_LIB_FUNC(next, JavascriptMapIterator::EntryNext);
  6893. return hr;
  6894. }
  6895. HRESULT JavascriptLibrary::ProfilerRegisterSetIterator()
  6896. {
  6897. HRESULT hr = S_OK;
  6898. // Set Iterator has no global constructor
  6899. DEFINE_OBJECT_NAME(Set Iterator);
  6900. REG_OBJECTS_LIB_FUNC(next, JavascriptSetIterator::EntryNext);
  6901. return hr;
  6902. }
  6903. HRESULT JavascriptLibrary::ProfilerRegisterStringIterator()
  6904. {
  6905. HRESULT hr = S_OK;
  6906. // String Iterator has no global constructor
  6907. DEFINE_OBJECT_NAME(String Iterator);
  6908. REG_OBJECTS_LIB_FUNC(next, JavascriptStringIterator::EntryNext);
  6909. return hr;
  6910. }
  6911. HRESULT JavascriptLibrary::ProfilerRegisterTypedArray()
  6912. {
  6913. HRESULT hr = S_OK;
  6914. // TypedArray has no named global constructor
  6915. DEFINE_OBJECT_NAME(TypedArray);
  6916. REG_OBJECTS_LIB_FUNC(from, TypedArrayBase::EntryFrom);
  6917. REG_OBJECTS_LIB_FUNC(of, TypedArrayBase::EntryOf);
  6918. REG_OBJECTS_LIB_FUNC(set, TypedArrayBase::EntrySet);
  6919. REG_OBJECTS_LIB_FUNC(subarray, TypedArrayBase::EntrySubarray);
  6920. REG_OBJECTS_LIB_FUNC(copyWithin, TypedArrayBase::EntryCopyWithin);
  6921. REG_OBJECTS_LIB_FUNC(every, TypedArrayBase::EntryEvery);
  6922. REG_OBJECTS_LIB_FUNC(fill, TypedArrayBase::EntryFill);
  6923. REG_OBJECTS_LIB_FUNC(filter, TypedArrayBase::EntryFilter);
  6924. REG_OBJECTS_LIB_FUNC(find, TypedArrayBase::EntryFind);
  6925. REG_OBJECTS_LIB_FUNC(findIndex, TypedArrayBase::EntryFindIndex);
  6926. REG_OBJECTS_LIB_FUNC(forEach, TypedArrayBase::EntryForEach);
  6927. REG_OBJECTS_LIB_FUNC(indexOf, TypedArrayBase::EntryIndexOf);
  6928. REG_OBJECTS_LIB_FUNC(join, TypedArrayBase::EntryJoin);
  6929. REG_OBJECTS_LIB_FUNC(lastIndexOf, TypedArrayBase::EntryLastIndexOf);
  6930. REG_OBJECTS_LIB_FUNC(map, TypedArrayBase::EntryMap);
  6931. REG_OBJECTS_LIB_FUNC(reduce, TypedArrayBase::EntryReduce);
  6932. REG_OBJECTS_LIB_FUNC(reduceRight, TypedArrayBase::EntryReduceRight);
  6933. REG_OBJECTS_LIB_FUNC(reverse, TypedArrayBase::EntryReverse);
  6934. REG_OBJECTS_LIB_FUNC(slice, TypedArrayBase::EntrySlice);
  6935. REG_OBJECTS_LIB_FUNC(some, TypedArrayBase::EntrySome);
  6936. REG_OBJECTS_LIB_FUNC(sort, TypedArrayBase::EntrySort);
  6937. REG_OBJECTS_LIB_FUNC(includes, TypedArrayBase::EntryIncludes);
  6938. return hr;
  6939. }
  6940. HRESULT JavascriptLibrary::ProfilerRegisterPromise()
  6941. {
  6942. HRESULT hr = S_OK;
  6943. REG_GLOBAL_CONSTRUCTOR(Promise);
  6944. DEFINE_OBJECT_NAME(Promise);
  6945. REG_OBJECTS_LIB_FUNC(all, JavascriptPromise::EntryAll);
  6946. REG_OBJECTS_LIB_FUNC2(catch_, _u("catch"), JavascriptPromise::EntryCatch);
  6947. REG_OBJECTS_LIB_FUNC(race, JavascriptPromise::EntryRace);
  6948. REG_OBJECTS_LIB_FUNC(resolve, JavascriptPromise::EntryResolve);
  6949. REG_OBJECTS_LIB_FUNC(then, JavascriptPromise::EntryThen);
  6950. return hr;
  6951. }
  6952. HRESULT JavascriptLibrary::ProfilerRegisterProxy()
  6953. {
  6954. HRESULT hr = S_OK;
  6955. REG_GLOBAL_CONSTRUCTOR(Proxy);
  6956. DEFINE_OBJECT_NAME(Proxy);
  6957. REG_OBJECTS_LIB_FUNC(revocable, JavascriptProxy::EntryRevocable);
  6958. return hr;
  6959. }
  6960. HRESULT JavascriptLibrary::ProfilerRegisterReflect()
  6961. {
  6962. HRESULT hr = S_OK;
  6963. DEFINE_OBJECT_NAME(Reflect);
  6964. REG_OBJECTS_LIB_FUNC(defineProperty, JavascriptReflect::EntryDefineProperty);
  6965. REG_OBJECTS_LIB_FUNC(deleteProperty, JavascriptReflect::EntryDeleteProperty);
  6966. REG_OBJECTS_LIB_FUNC(get, JavascriptReflect::EntryGet);
  6967. REG_OBJECTS_LIB_FUNC(getOwnPropertyDescriptor, JavascriptReflect::EntryGetOwnPropertyDescriptor);
  6968. REG_OBJECTS_LIB_FUNC(getPrototypeOf, JavascriptReflect::EntryGetPrototypeOf);
  6969. REG_OBJECTS_LIB_FUNC(has, JavascriptReflect::EntryHas);
  6970. REG_OBJECTS_LIB_FUNC(isExtensible, JavascriptReflect::EntryIsExtensible);
  6971. REG_OBJECTS_LIB_FUNC(ownKeys, JavascriptReflect::EntryOwnKeys);
  6972. REG_OBJECTS_LIB_FUNC(preventExtensions, JavascriptReflect::EntryPreventExtensions);
  6973. REG_OBJECTS_LIB_FUNC(set, JavascriptReflect::EntrySet);
  6974. REG_OBJECTS_LIB_FUNC(setPrototypeOf, JavascriptReflect::EntrySetPrototypeOf);
  6975. REG_OBJECTS_LIB_FUNC(apply, JavascriptReflect::EntryApply);
  6976. REG_OBJECTS_LIB_FUNC(construct, JavascriptReflect::EntryConstruct);
  6977. return hr;
  6978. }
  6979. HRESULT JavascriptLibrary::ProfilerRegisterGenerator()
  6980. {
  6981. HRESULT hr = S_OK;
  6982. DEFINE_OBJECT_NAME(Generator);
  6983. REG_OBJECTS_LIB_FUNC(next, JavascriptGenerator::EntryNext);
  6984. REG_OBJECTS_LIB_FUNC(return_, JavascriptGenerator::EntryReturn);
  6985. REG_OBJECTS_LIB_FUNC(throw_, JavascriptGenerator::EntryThrow);
  6986. return hr;
  6987. }
  6988. #ifdef ENABLE_SIMDJS
  6989. HRESULT JavascriptLibrary::ProfilerRegisterSIMD()
  6990. {
  6991. HRESULT hr = S_OK;
  6992. DEFINE_OBJECT_NAME(SIMD);
  6993. // Float32x4
  6994. REG_OBJECTS_LIB_FUNC(Float32x4, SIMDFloat32x4Lib::EntryFloat32x4);
  6995. REG_OBJECTS_LIB_FUNC(check, SIMDFloat32x4Lib::EntryCheck);
  6996. REG_OBJECTS_LIB_FUNC(splat, SIMDFloat32x4Lib::EntrySplat);
  6997. REG_OBJECTS_LIB_FUNC(extractLane, SIMDFloat32x4Lib::EntryExtractLane);
  6998. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDFloat32x4Lib::EntryReplaceLane);
  6999. REG_OBJECTS_LIB_FUNC(fromFloat64x2, SIMDFloat32x4Lib::EntryFromFloat64x2);
  7000. REG_OBJECTS_LIB_FUNC(fromFloat64x2Bits, SIMDFloat32x4Lib::EntryFromFloat64x2Bits);
  7001. REG_OBJECTS_LIB_FUNC(fromInt32x4, SIMDFloat32x4Lib::EntryFromInt32x4);
  7002. REG_OBJECTS_LIB_FUNC(fromUint32x4, SIMDFloat32x4Lib::EntryFromUint32x4);
  7003. REG_OBJECTS_LIB_FUNC(fromInt32x4Bits, SIMDFloat32x4Lib::EntryFromInt32x4Bits);
  7004. REG_OBJECTS_LIB_FUNC(fromInt16x8Bits, SIMDFloat32x4Lib::EntryFromInt16x8Bits);
  7005. REG_OBJECTS_LIB_FUNC(fromInt8x16Bits, SIMDFloat32x4Lib::EntryFromInt8x16Bits);
  7006. REG_OBJECTS_LIB_FUNC(fromUint32x4Bits, SIMDFloat32x4Lib::EntryFromUint32x4Bits);
  7007. REG_OBJECTS_LIB_FUNC(fromUint16x8Bits, SIMDFloat32x4Lib::EntryFromUint16x8Bits);
  7008. REG_OBJECTS_LIB_FUNC(fromUint8x16Bits, SIMDFloat32x4Lib::EntryFromUint8x16Bits);
  7009. REG_OBJECTS_LIB_FUNC(add, SIMDFloat32x4Lib::EntryAdd);
  7010. REG_OBJECTS_LIB_FUNC(sub, SIMDFloat32x4Lib::EntrySub);
  7011. REG_OBJECTS_LIB_FUNC(mul, SIMDFloat32x4Lib::EntryMul);
  7012. REG_OBJECTS_LIB_FUNC(div, SIMDFloat32x4Lib::EntryDiv);
  7013. REG_OBJECTS_LIB_FUNC(and_, SIMDFloat32x4Lib::EntryAnd);
  7014. REG_OBJECTS_LIB_FUNC(or_, SIMDFloat32x4Lib::EntryOr);
  7015. REG_OBJECTS_LIB_FUNC(xor_, SIMDFloat32x4Lib::EntryXor);
  7016. REG_OBJECTS_LIB_FUNC(min, SIMDFloat32x4Lib::EntryMin);
  7017. REG_OBJECTS_LIB_FUNC(max, SIMDFloat32x4Lib::EntryMax);
  7018. REG_OBJECTS_LIB_FUNC(abs, SIMDFloat32x4Lib::EntryAbs);
  7019. REG_OBJECTS_LIB_FUNC(neg, SIMDFloat32x4Lib::EntryNeg);
  7020. REG_OBJECTS_LIB_FUNC(not_, SIMDFloat32x4Lib::EntryNot);
  7021. REG_OBJECTS_LIB_FUNC(sqrt, SIMDFloat32x4Lib::EntrySqrt);
  7022. REG_OBJECTS_LIB_FUNC(reciprocalApproximation, SIMDFloat32x4Lib::EntryReciprocal);
  7023. REG_OBJECTS_LIB_FUNC(reciprocalSqrtApproximation, SIMDFloat32x4Lib::EntryReciprocalSqrt);
  7024. REG_OBJECTS_LIB_FUNC(lessThan, SIMDFloat32x4Lib::EntryLessThan);
  7025. REG_OBJECTS_LIB_FUNC(lessThanOrEqual, SIMDFloat32x4Lib::EntryLessThanOrEqual);
  7026. REG_OBJECTS_LIB_FUNC(equal, SIMDFloat32x4Lib::EntryEqual);
  7027. REG_OBJECTS_LIB_FUNC(notEqual, SIMDFloat32x4Lib::EntryNotEqual);
  7028. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDFloat32x4Lib::EntryGreaterThan);
  7029. REG_OBJECTS_LIB_FUNC(greaterThanOrEqual, SIMDFloat32x4Lib::EntryGreaterThanOrEqual);
  7030. REG_OBJECTS_LIB_FUNC(swizzle, SIMDFloat32x4Lib::EntrySwizzle);
  7031. REG_OBJECTS_LIB_FUNC(shuffle, SIMDFloat32x4Lib::EntryShuffle);
  7032. REG_OBJECTS_LIB_FUNC(select, SIMDFloat32x4Lib::EntrySelect);
  7033. // Float64x2
  7034. REG_OBJECTS_LIB_FUNC(Float64x2, SIMDFloat64x2Lib::EntryFloat64x2);
  7035. REG_OBJECTS_LIB_FUNC(check, SIMDFloat64x2Lib::EntryCheck);
  7036. REG_OBJECTS_LIB_FUNC(splat, SIMDFloat64x2Lib::EntrySplat);
  7037. REG_OBJECTS_LIB_FUNC(fromFloat32x4, SIMDFloat64x2Lib::EntryFromFloat32x4);
  7038. REG_OBJECTS_LIB_FUNC(fromFloat32x4Bits, SIMDFloat64x2Lib::EntryFromFloat32x4Bits);
  7039. REG_OBJECTS_LIB_FUNC(fromInt32x4, SIMDFloat64x2Lib::EntryFromInt32x4);
  7040. REG_OBJECTS_LIB_FUNC(fromInt32x4Bits, SIMDFloat64x2Lib::EntryFromInt32x4Bits);
  7041. REG_OBJECTS_LIB_FUNC(add, SIMDFloat64x2Lib::EntryAdd);
  7042. REG_OBJECTS_LIB_FUNC(sub, SIMDFloat64x2Lib::EntrySub);
  7043. REG_OBJECTS_LIB_FUNC(mul, SIMDFloat64x2Lib::EntryMul);
  7044. REG_OBJECTS_LIB_FUNC(div, SIMDFloat64x2Lib::EntryDiv);
  7045. REG_OBJECTS_LIB_FUNC(min, SIMDFloat64x2Lib::EntryMin);
  7046. REG_OBJECTS_LIB_FUNC(max, SIMDFloat64x2Lib::EntryMax);
  7047. REG_OBJECTS_LIB_FUNC(abs, SIMDFloat64x2Lib::EntryAbs);
  7048. REG_OBJECTS_LIB_FUNC(neg, SIMDFloat64x2Lib::EntryNeg);
  7049. REG_OBJECTS_LIB_FUNC(sqrt, SIMDFloat64x2Lib::EntrySqrt);
  7050. REG_OBJECTS_LIB_FUNC(reciprocalApproximation, SIMDFloat64x2Lib::EntryReciprocal);
  7051. REG_OBJECTS_LIB_FUNC(reciprocalSqrtApproximation, SIMDFloat64x2Lib::EntryReciprocalSqrt);
  7052. REG_OBJECTS_LIB_FUNC(lessThan, SIMDFloat64x2Lib::EntryLessThan);
  7053. REG_OBJECTS_LIB_FUNC(lessThanOrEqual, SIMDFloat64x2Lib::EntryLessThanOrEqual);
  7054. REG_OBJECTS_LIB_FUNC(equal, SIMDFloat64x2Lib::EntryEqual);
  7055. REG_OBJECTS_LIB_FUNC(notEqual, SIMDFloat64x2Lib::EntryNotEqual);
  7056. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDFloat64x2Lib::EntryGreaterThan);
  7057. REG_OBJECTS_LIB_FUNC(greaterThanOrEqual, SIMDFloat64x2Lib::EntryGreaterThanOrEqual);
  7058. REG_OBJECTS_LIB_FUNC(swizzle, SIMDFloat64x2Lib::EntrySwizzle);
  7059. REG_OBJECTS_LIB_FUNC(shuffle, SIMDFloat64x2Lib::EntryShuffle);
  7060. REG_OBJECTS_LIB_FUNC(select, SIMDFloat64x2Lib::EntrySelect);
  7061. // Int32x4
  7062. REG_OBJECTS_LIB_FUNC(Int32x4, SIMDInt32x4Lib::EntryInt32x4);
  7063. REG_OBJECTS_LIB_FUNC(check, SIMDInt32x4Lib::EntryCheck);
  7064. REG_OBJECTS_LIB_FUNC(splat, SIMDInt32x4Lib::EntrySplat);
  7065. REG_OBJECTS_LIB_FUNC(extractLane, SIMDInt32x4Lib::EntryExtractLane);
  7066. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDInt32x4Lib::EntryReplaceLane);
  7067. REG_OBJECTS_LIB_FUNC(fromFloat64x2, SIMDInt32x4Lib::EntryFromFloat64x2);
  7068. REG_OBJECTS_LIB_FUNC(fromFloat64x2Bits, SIMDInt32x4Lib::EntryFromFloat64x2Bits);
  7069. REG_OBJECTS_LIB_FUNC(fromFloat32x4, SIMDInt32x4Lib::EntryFromFloat32x4);
  7070. REG_OBJECTS_LIB_FUNC(fromFloat32x4Bits, SIMDInt32x4Lib::EntryFromFloat32x4Bits);
  7071. REG_OBJECTS_LIB_FUNC(fromUint32x4Bits, SIMDInt32x4Lib::EntryFromUint32x4Bits);
  7072. REG_OBJECTS_LIB_FUNC(fromUint8x16Bits, SIMDInt32x4Lib::EntryFromUint8x16Bits);
  7073. REG_OBJECTS_LIB_FUNC(fromUint16x8Bits, SIMDInt32x4Lib::EntryFromUint16x8Bits);
  7074. REG_OBJECTS_LIB_FUNC(fromInt8x16Bits, SIMDInt32x4Lib::EntryFromInt8x16Bits);
  7075. REG_OBJECTS_LIB_FUNC(fromInt16x8Bits, SIMDInt32x4Lib::EntryFromInt16x8Bits);
  7076. REG_OBJECTS_LIB_FUNC(add, SIMDInt32x4Lib::EntryAdd);
  7077. REG_OBJECTS_LIB_FUNC(sub, SIMDInt32x4Lib::EntrySub);
  7078. REG_OBJECTS_LIB_FUNC(mul, SIMDInt32x4Lib::EntryMul);
  7079. REG_OBJECTS_LIB_FUNC(and_, SIMDInt32x4Lib::EntryAnd);
  7080. REG_OBJECTS_LIB_FUNC(or_, SIMDInt32x4Lib::EntryOr);
  7081. REG_OBJECTS_LIB_FUNC(xor_, SIMDInt32x4Lib::EntryXor);
  7082. REG_OBJECTS_LIB_FUNC(min, SIMDInt32x4Lib::EntryMin);
  7083. REG_OBJECTS_LIB_FUNC(max, SIMDInt32x4Lib::EntryMax);
  7084. REG_OBJECTS_LIB_FUNC(neg, SIMDInt32x4Lib::EntryNeg);
  7085. REG_OBJECTS_LIB_FUNC(not_, SIMDInt32x4Lib::EntryNot);
  7086. REG_OBJECTS_LIB_FUNC(lessThan, SIMDInt32x4Lib::EntryLessThan);
  7087. REG_OBJECTS_LIB_FUNC(lessThanOrEqual, SIMDInt32x4Lib::EntryLessThanOrEqual);
  7088. REG_OBJECTS_LIB_FUNC(equal, SIMDInt32x4Lib::EntryEqual);
  7089. REG_OBJECTS_LIB_FUNC(notEqual, SIMDInt32x4Lib::EntryNotEqual);
  7090. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDInt32x4Lib::EntryGreaterThan);
  7091. REG_OBJECTS_LIB_FUNC(greaterThanOrEqual, SIMDInt32x4Lib::EntryGreaterThanOrEqual);
  7092. REG_OBJECTS_LIB_FUNC(swizzle, SIMDInt32x4Lib::EntrySwizzle);
  7093. REG_OBJECTS_LIB_FUNC(shuffle, SIMDInt32x4Lib::EntryShuffle);
  7094. REG_OBJECTS_LIB_FUNC(shiftLeftByScalar, SIMDInt32x4Lib::EntryShiftLeftByScalar);
  7095. REG_OBJECTS_LIB_FUNC(shiftRightByScalar, SIMDInt32x4Lib::EntryShiftRightByScalar);
  7096. REG_OBJECTS_LIB_FUNC(select, SIMDInt32x4Lib::EntrySelect);
  7097. // Int16x8
  7098. REG_OBJECTS_LIB_FUNC(Int16x8, SIMDInt16x8Lib::EntryInt16x8);
  7099. REG_OBJECTS_LIB_FUNC(splat, SIMDInt16x8Lib::EntryCheck);
  7100. REG_OBJECTS_LIB_FUNC(splat, SIMDInt16x8Lib::EntrySplat);
  7101. REG_OBJECTS_LIB_FUNC(fromFloat32x4Bits, SIMDInt16x8Lib::EntryFromFloat32x4Bits);
  7102. REG_OBJECTS_LIB_FUNC(fromInt32x4Bits, SIMDInt16x8Lib::EntryFromInt32x4Bits);
  7103. REG_OBJECTS_LIB_FUNC(fromInt8x16Bits, SIMDInt16x8Lib::EntryFromInt8x16Bits);
  7104. REG_OBJECTS_LIB_FUNC(fromUint32x4Bits, SIMDInt16x8Lib::EntryFromUint32x4Bits);
  7105. REG_OBJECTS_LIB_FUNC(fromUint16x8Bits, SIMDInt16x8Lib::EntryFromUint16x8Bits);
  7106. REG_OBJECTS_LIB_FUNC(fromUint8x16Bits, SIMDInt16x8Lib::EntryFromUint8x16Bits);
  7107. REG_OBJECTS_LIB_FUNC(neg, SIMDInt16x8Lib::EntryNeg);
  7108. REG_OBJECTS_LIB_FUNC(not_, SIMDInt16x8Lib::EntryNot);
  7109. REG_OBJECTS_LIB_FUNC(add, SIMDInt16x8Lib::EntryAdd);
  7110. REG_OBJECTS_LIB_FUNC(sub, SIMDInt16x8Lib::EntrySub);
  7111. REG_OBJECTS_LIB_FUNC(mul, SIMDInt16x8Lib::EntryMul);
  7112. REG_OBJECTS_LIB_FUNC(and_, SIMDInt16x8Lib::EntryAnd);
  7113. REG_OBJECTS_LIB_FUNC(or_, SIMDInt16x8Lib::EntryOr);
  7114. REG_OBJECTS_LIB_FUNC(xor_, SIMDInt16x8Lib::EntryXor);
  7115. REG_OBJECTS_LIB_FUNC(min, SIMDInt16x8Lib::EntryMin);
  7116. REG_OBJECTS_LIB_FUNC(max, SIMDInt16x8Lib::EntryMax);
  7117. REG_OBJECTS_LIB_FUNC(addSaturate, SIMDInt16x8Lib::EntryAddSaturate);
  7118. REG_OBJECTS_LIB_FUNC(subSaturate, SIMDInt16x8Lib::EntrySubSaturate);
  7119. REG_OBJECTS_LIB_FUNC(lessThan, SIMDInt16x8Lib::EntryLessThan);
  7120. REG_OBJECTS_LIB_FUNC(lessThanOrEqual, SIMDInt16x8Lib::EntryLessThanOrEqual);
  7121. REG_OBJECTS_LIB_FUNC(equal, SIMDInt16x8Lib::EntryEqual);
  7122. REG_OBJECTS_LIB_FUNC(notEqual, SIMDInt16x8Lib::EntryNotEqual);
  7123. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDInt16x8Lib::EntryGreaterThan);
  7124. REG_OBJECTS_LIB_FUNC(greaterThanOrEqual, SIMDInt16x8Lib::EntryGreaterThanOrEqual);
  7125. REG_OBJECTS_LIB_FUNC(extractLane, SIMDInt16x8Lib::EntryExtractLane);
  7126. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDInt16x8Lib::EntryReplaceLane);
  7127. REG_OBJECTS_LIB_FUNC(shiftLeftByScalar, SIMDInt16x8Lib::EntryShiftLeftByScalar);
  7128. REG_OBJECTS_LIB_FUNC(shiftRightByScalar, SIMDInt16x8Lib::EntryShiftRightByScalar);
  7129. REG_OBJECTS_LIB_FUNC(load, SIMDInt16x8Lib::EntryLoad);
  7130. REG_OBJECTS_LIB_FUNC(store, SIMDInt16x8Lib::EntryStore);
  7131. REG_OBJECTS_LIB_FUNC(swizzle, SIMDInt16x8Lib::EntrySwizzle);
  7132. REG_OBJECTS_LIB_FUNC(shuffle, SIMDInt16x8Lib::EntryShuffle);
  7133. REG_OBJECTS_LIB_FUNC(select, SIMDInt16x8Lib::EntrySelect);
  7134. // Int8x16
  7135. REG_OBJECTS_LIB_FUNC(Int8x16, SIMDInt8x16Lib::EntryInt8x16);
  7136. REG_OBJECTS_LIB_FUNC(check, SIMDInt8x16Lib::EntryCheck);
  7137. REG_OBJECTS_LIB_FUNC(splat, SIMDInt8x16Lib::EntrySplat);
  7138. REG_OBJECTS_LIB_FUNC(fromFloat32x4Bits, SIMDInt8x16Lib::EntryFromFloat32x4Bits);
  7139. REG_OBJECTS_LIB_FUNC(fromInt32x4Bits, SIMDInt8x16Lib::EntryFromInt32x4Bits);
  7140. REG_OBJECTS_LIB_FUNC(fromInt16x8Bits, SIMDInt8x16Lib::EntryFromInt16x8Bits);
  7141. REG_OBJECTS_LIB_FUNC(fromUint32x4Bits, SIMDInt8x16Lib::EntryFromUint32x4Bits);
  7142. REG_OBJECTS_LIB_FUNC(fromUint16x8Bits, SIMDInt8x16Lib::EntryFromUint16x8Bits);
  7143. REG_OBJECTS_LIB_FUNC(fromUint8x16Bits, SIMDInt8x16Lib::EntryFromUint8x16Bits);
  7144. REG_OBJECTS_LIB_FUNC(neg, SIMDInt8x16Lib::EntryNeg);
  7145. REG_OBJECTS_LIB_FUNC(not_, SIMDInt8x16Lib::EntryNot);
  7146. REG_OBJECTS_LIB_FUNC(add, SIMDInt8x16Lib::EntryAdd);
  7147. REG_OBJECTS_LIB_FUNC(sub, SIMDInt8x16Lib::EntrySub);
  7148. REG_OBJECTS_LIB_FUNC(mul, SIMDInt8x16Lib::EntryMul);
  7149. REG_OBJECTS_LIB_FUNC(and_, SIMDInt8x16Lib::EntryAnd);
  7150. REG_OBJECTS_LIB_FUNC(or_, SIMDInt8x16Lib::EntryOr);
  7151. REG_OBJECTS_LIB_FUNC(xor_, SIMDInt8x16Lib::EntryXor);
  7152. REG_OBJECTS_LIB_FUNC(min, SIMDInt8x16Lib::EntryMin);
  7153. REG_OBJECTS_LIB_FUNC(max, SIMDInt8x16Lib::EntryMax);
  7154. REG_OBJECTS_LIB_FUNC(addSaturate, SIMDInt8x16Lib::EntryAddSaturate);
  7155. REG_OBJECTS_LIB_FUNC(subSaturate, SIMDInt8x16Lib::EntrySubSaturate);
  7156. REG_OBJECTS_LIB_FUNC(lessThan, SIMDInt8x16Lib::EntryLessThan);
  7157. REG_OBJECTS_LIB_FUNC(lessThanOrEqual, SIMDInt8x16Lib::EntryLessThanOrEqual);
  7158. REG_OBJECTS_LIB_FUNC(equal, SIMDInt8x16Lib::EntryEqual);
  7159. REG_OBJECTS_LIB_FUNC(notEqual, SIMDInt8x16Lib::EntryNotEqual);
  7160. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDInt8x16Lib::EntryGreaterThan);
  7161. REG_OBJECTS_LIB_FUNC(greaterThanOrEqual, SIMDInt8x16Lib::EntryGreaterThanOrEqual);
  7162. REG_OBJECTS_LIB_FUNC(shiftLeftByScalar, SIMDInt8x16Lib::EntryShiftLeftByScalar);
  7163. REG_OBJECTS_LIB_FUNC(shiftRightByScalar, SIMDInt8x16Lib::EntryShiftRightByScalar);
  7164. REG_OBJECTS_LIB_FUNC(swizzle, SIMDInt8x16Lib::EntrySwizzle);
  7165. REG_OBJECTS_LIB_FUNC(shuffle, SIMDInt8x16Lib::EntryShuffle);
  7166. REG_OBJECTS_LIB_FUNC(extractLane, SIMDInt8x16Lib::EntryExtractLane);
  7167. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDInt8x16Lib::EntryReplaceLane);
  7168. REG_OBJECTS_LIB_FUNC(select, SIMDInt8x16Lib::EntrySelect);
  7169. // Bool32x4
  7170. REG_OBJECTS_LIB_FUNC(Bool32x4, SIMDBool32x4Lib::EntryBool32x4);
  7171. REG_OBJECTS_LIB_FUNC(check, SIMDBool32x4Lib::EntryCheck);
  7172. REG_OBJECTS_LIB_FUNC(splat, SIMDBool32x4Lib::EntrySplat);
  7173. REG_OBJECTS_LIB_FUNC(not_, SIMDBool32x4Lib::EntryNot);
  7174. REG_OBJECTS_LIB_FUNC(and_, SIMDBool32x4Lib::EntryAnd);
  7175. REG_OBJECTS_LIB_FUNC(or_, SIMDBool32x4Lib::EntryOr);
  7176. REG_OBJECTS_LIB_FUNC(xor_, SIMDBool32x4Lib::EntryXor);
  7177. REG_OBJECTS_LIB_FUNC(anyTrue, SIMDBool32x4Lib::EntryAnyTrue);
  7178. REG_OBJECTS_LIB_FUNC(allTrue, SIMDBool32x4Lib::EntryAllTrue);
  7179. REG_OBJECTS_LIB_FUNC(extractLane, SIMDBool32x4Lib::EntryExtractLane);
  7180. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDBool32x4Lib::EntryReplaceLane);
  7181. // Bool16x8
  7182. // TODO: Enable with Int16x8 type.
  7183. REG_OBJECTS_LIB_FUNC(Bool16x8, SIMDBool16x8Lib::EntryBool16x8);
  7184. REG_OBJECTS_LIB_FUNC(check, SIMDBool16x8Lib::EntryCheck);
  7185. REG_OBJECTS_LIB_FUNC(splat, SIMDBool16x8Lib::EntrySplat);
  7186. REG_OBJECTS_LIB_FUNC(not_, SIMDBool16x8Lib::EntryNot);
  7187. REG_OBJECTS_LIB_FUNC(and_, SIMDBool16x8Lib::EntryAnd);
  7188. REG_OBJECTS_LIB_FUNC(or_, SIMDBool16x8Lib::EntryOr);
  7189. REG_OBJECTS_LIB_FUNC(xor_, SIMDBool16x8Lib::EntryXor);
  7190. REG_OBJECTS_LIB_FUNC(anyTrue, SIMDBool16x8Lib::EntryAnyTrue);
  7191. REG_OBJECTS_LIB_FUNC(allTrue, SIMDBool16x8Lib::EntryAllTrue);
  7192. REG_OBJECTS_LIB_FUNC(extractLane, SIMDBool16x8Lib::EntryExtractLane);
  7193. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDBool16x8Lib::EntryReplaceLane);
  7194. // Bool8x16
  7195. REG_OBJECTS_LIB_FUNC(Bool8x16, SIMDBool8x16Lib::EntryBool8x16);
  7196. REG_OBJECTS_LIB_FUNC(check, SIMDBool8x16Lib::EntryCheck);
  7197. REG_OBJECTS_LIB_FUNC(splat, SIMDBool8x16Lib::EntrySplat);
  7198. REG_OBJECTS_LIB_FUNC(not_, SIMDBool8x16Lib::EntryNot);
  7199. REG_OBJECTS_LIB_FUNC(and_, SIMDBool8x16Lib::EntryAnd);
  7200. REG_OBJECTS_LIB_FUNC(or_, SIMDBool8x16Lib::EntryOr);
  7201. REG_OBJECTS_LIB_FUNC(xor_, SIMDBool8x16Lib::EntryXor);
  7202. REG_OBJECTS_LIB_FUNC(anyTrue, SIMDBool8x16Lib::EntryAnyTrue);
  7203. REG_OBJECTS_LIB_FUNC(allTrue, SIMDBool8x16Lib::EntryAllTrue);
  7204. REG_OBJECTS_LIB_FUNC(extractLane, SIMDBool8x16Lib::EntryExtractLane);
  7205. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDBool8x16Lib::EntryReplaceLane);
  7206. // Uint32x4
  7207. REG_OBJECTS_LIB_FUNC(Uint32x4, SIMDUint32x4Lib::EntryUint32x4);
  7208. REG_OBJECTS_LIB_FUNC(check, SIMDUint32x4Lib::EntryCheck);
  7209. REG_OBJECTS_LIB_FUNC(splat, SIMDUint32x4Lib::EntrySplat);
  7210. REG_OBJECTS_LIB_FUNC(extractLane, SIMDUint32x4Lib::EntryExtractLane);
  7211. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDUint32x4Lib::EntryReplaceLane);
  7212. REG_OBJECTS_LIB_FUNC(fromFloat32x4, SIMDUint32x4Lib::EntryFromFloat32x4);
  7213. REG_OBJECTS_LIB_FUNC(fromFloat32x4Bits, SIMDUint32x4Lib::EntryFromFloat32x4Bits);
  7214. REG_OBJECTS_LIB_FUNC(fromInt8x16Bits, SIMDUint32x4Lib::EntryFromInt8x16Bits);
  7215. REG_OBJECTS_LIB_FUNC(add, SIMDUint32x4Lib::EntryAdd);
  7216. REG_OBJECTS_LIB_FUNC(sub, SIMDUint32x4Lib::EntrySub);
  7217. REG_OBJECTS_LIB_FUNC(mul, SIMDUint32x4Lib::EntryMul);
  7218. REG_OBJECTS_LIB_FUNC(min, SIMDUint32x4Lib::EntryMin);
  7219. REG_OBJECTS_LIB_FUNC(max, SIMDUint32x4Lib::EntryMax);
  7220. REG_OBJECTS_LIB_FUNC(and_, SIMDUint32x4Lib::EntryAnd);
  7221. REG_OBJECTS_LIB_FUNC(or_, SIMDUint32x4Lib::EntryOr);
  7222. REG_OBJECTS_LIB_FUNC(xor_, SIMDUint32x4Lib::EntryXor);
  7223. REG_OBJECTS_LIB_FUNC(not_, SIMDUint32x4Lib::EntryNot);
  7224. REG_OBJECTS_LIB_FUNC(neg, SIMDUint32x4Lib::EntryNeg);
  7225. REG_OBJECTS_LIB_FUNC(lessThan, SIMDUint32x4Lib::EntryLessThan);
  7226. REG_OBJECTS_LIB_FUNC(lessThanOrEqual, SIMDUint32x4Lib::EntryLessThanOrEqual);
  7227. REG_OBJECTS_LIB_FUNC(equal, SIMDUint32x4Lib::EntryEqual);
  7228. REG_OBJECTS_LIB_FUNC(notEqual, SIMDUint32x4Lib::EntryNotEqual);
  7229. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDUint32x4Lib::EntryGreaterThan);
  7230. REG_OBJECTS_LIB_FUNC(greaterThanOrEqual, SIMDUint32x4Lib::EntryGreaterThanOrEqual);
  7231. REG_OBJECTS_LIB_FUNC(swizzle, SIMDUint32x4Lib::EntrySwizzle);
  7232. REG_OBJECTS_LIB_FUNC(shuffle, SIMDUint32x4Lib::EntryShuffle);
  7233. REG_OBJECTS_LIB_FUNC(shiftLeftByScalar, SIMDUint32x4Lib::EntryShiftLeftByScalar);
  7234. REG_OBJECTS_LIB_FUNC(shiftRightByScalar, SIMDUint32x4Lib::EntryShiftRightByScalar);
  7235. REG_OBJECTS_LIB_FUNC(select, SIMDUint32x4Lib::EntrySelect);
  7236. REG_OBJECTS_LIB_FUNC(load, SIMDUint32x4Lib::EntryLoad);
  7237. REG_OBJECTS_LIB_FUNC(load1, SIMDUint32x4Lib::EntryLoad1);
  7238. REG_OBJECTS_LIB_FUNC(load2, SIMDUint32x4Lib::EntryLoad2);
  7239. REG_OBJECTS_LIB_FUNC(load3, SIMDUint32x4Lib::EntryLoad3);
  7240. REG_OBJECTS_LIB_FUNC(store, SIMDUint32x4Lib::EntryStore);
  7241. REG_OBJECTS_LIB_FUNC(store1, SIMDUint32x4Lib::EntryStore1);
  7242. REG_OBJECTS_LIB_FUNC(store2, SIMDUint32x4Lib::EntryStore2);
  7243. REG_OBJECTS_LIB_FUNC(store3, SIMDUint32x4Lib::EntryStore3);
  7244. // Uint16x8
  7245. REG_OBJECTS_LIB_FUNC(Uint16x8, SIMDUint16x8Lib::EntryUint16x8);
  7246. REG_OBJECTS_LIB_FUNC(splat, SIMDUint16x8Lib::EntryCheck);
  7247. REG_OBJECTS_LIB_FUNC(splat, SIMDUint16x8Lib::EntrySplat);
  7248. REG_OBJECTS_LIB_FUNC(fromFloat32x4Bits, SIMDUint16x8Lib::EntryFromFloat32x4Bits);
  7249. REG_OBJECTS_LIB_FUNC(fromInt32x4Bits, SIMDUint16x8Lib::EntryFromInt32x4Bits);
  7250. REG_OBJECTS_LIB_FUNC(fromInt8x16Bits, SIMDUint16x8Lib::EntryFromInt8x16Bits);
  7251. REG_OBJECTS_LIB_FUNC(fromInt16x8Bits, SIMDUint16x8Lib::EntryFromInt16x8Bits);
  7252. REG_OBJECTS_LIB_FUNC(fromUint32x4Bits, SIMDUint16x8Lib::EntryFromUint32x4Bits);
  7253. REG_OBJECTS_LIB_FUNC(fromUint8x16Bits, SIMDUint16x8Lib::EntryFromUint8x16Bits);
  7254. REG_OBJECTS_LIB_FUNC(not_, SIMDUint16x8Lib::EntryNot);
  7255. REG_OBJECTS_LIB_FUNC(neg, SIMDUint16x8Lib::EntryNeg);
  7256. REG_OBJECTS_LIB_FUNC(add, SIMDUint16x8Lib::EntryAdd);
  7257. REG_OBJECTS_LIB_FUNC(sub, SIMDUint16x8Lib::EntrySub);
  7258. REG_OBJECTS_LIB_FUNC(mul, SIMDUint16x8Lib::EntryMul);
  7259. REG_OBJECTS_LIB_FUNC(and_, SIMDUint16x8Lib::EntryAnd);
  7260. REG_OBJECTS_LIB_FUNC(or_, SIMDUint16x8Lib::EntryOr);
  7261. REG_OBJECTS_LIB_FUNC(xor_, SIMDUint16x8Lib::EntryXor);
  7262. REG_OBJECTS_LIB_FUNC(min, SIMDUint16x8Lib::EntryMin);
  7263. REG_OBJECTS_LIB_FUNC(max, SIMDUint16x8Lib::EntryMax);
  7264. REG_OBJECTS_LIB_FUNC(addSaturate, SIMDUint16x8Lib::EntryAddSaturate);
  7265. REG_OBJECTS_LIB_FUNC(subSaturate, SIMDUint16x8Lib::EntrySubSaturate);
  7266. REG_OBJECTS_LIB_FUNC(lessThan, SIMDUint16x8Lib::EntryLessThan);
  7267. REG_OBJECTS_LIB_FUNC(lessThanOrEqual, SIMDUint16x8Lib::EntryLessThanOrEqual);
  7268. REG_OBJECTS_LIB_FUNC(equal, SIMDUint16x8Lib::EntryEqual);
  7269. REG_OBJECTS_LIB_FUNC(notEqual, SIMDUint16x8Lib::EntryNotEqual);
  7270. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDUint16x8Lib::EntryGreaterThan);
  7271. REG_OBJECTS_LIB_FUNC(greaterThanOrEqual, SIMDUint16x8Lib::EntryGreaterThanOrEqual);
  7272. REG_OBJECTS_LIB_FUNC(extractLane, SIMDUint16x8Lib::EntryExtractLane);
  7273. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDUint16x8Lib::EntryReplaceLane);
  7274. REG_OBJECTS_LIB_FUNC(shiftLeftByScalar, SIMDUint16x8Lib::EntryShiftLeftByScalar);
  7275. REG_OBJECTS_LIB_FUNC(shiftRightByScalar, SIMDUint16x8Lib::EntryShiftRightByScalar);
  7276. REG_OBJECTS_LIB_FUNC(load, SIMDUint16x8Lib::EntryLoad);
  7277. REG_OBJECTS_LIB_FUNC(store, SIMDUint16x8Lib::EntryStore);
  7278. REG_OBJECTS_LIB_FUNC(swizzle, SIMDUint16x8Lib::EntrySwizzle);
  7279. REG_OBJECTS_LIB_FUNC(shuffle, SIMDUint16x8Lib::EntryShuffle);
  7280. REG_OBJECTS_LIB_FUNC(select, SIMDUint16x8Lib::EntrySelect);
  7281. // Uint8x16
  7282. REG_OBJECTS_LIB_FUNC(Uint8x16, SIMDUint8x16Lib::EntryUint8x16);
  7283. REG_OBJECTS_LIB_FUNC(splat, SIMDUint8x16Lib::EntryCheck);
  7284. REG_OBJECTS_LIB_FUNC(splat, SIMDUint8x16Lib::EntrySplat);
  7285. REG_OBJECTS_LIB_FUNC(fromFloat32x4Bits, SIMDUint8x16Lib::EntryFromFloat32x4Bits);
  7286. REG_OBJECTS_LIB_FUNC(fromInt32x4Bits, SIMDUint8x16Lib::EntryFromInt32x4Bits);
  7287. REG_OBJECTS_LIB_FUNC(fromInt16x8Bits, SIMDUint8x16Lib::EntryFromInt16x8Bits);
  7288. REG_OBJECTS_LIB_FUNC(fromInt8x16Bits, SIMDUint8x16Lib::EntryFromInt8x16Bits);
  7289. REG_OBJECTS_LIB_FUNC(fromUint32x4Bits, SIMDUint8x16Lib::EntryFromUint32x4Bits);
  7290. REG_OBJECTS_LIB_FUNC(fromUint16x8Bits, SIMDUint8x16Lib::EntryFromUint16x8Bits);
  7291. REG_OBJECTS_LIB_FUNC(not_, SIMDUint8x16Lib::EntryNot);
  7292. REG_OBJECTS_LIB_FUNC(neg, SIMDUint8x16Lib::EntryNeg);
  7293. REG_OBJECTS_LIB_FUNC(add, SIMDUint8x16Lib::EntryAdd);
  7294. REG_OBJECTS_LIB_FUNC(sub, SIMDUint8x16Lib::EntrySub);
  7295. REG_OBJECTS_LIB_FUNC(mul, SIMDUint8x16Lib::EntryMul);
  7296. REG_OBJECTS_LIB_FUNC(and_, SIMDUint8x16Lib::EntryAnd);
  7297. REG_OBJECTS_LIB_FUNC(or_, SIMDUint8x16Lib::EntryOr);
  7298. REG_OBJECTS_LIB_FUNC(xor_, SIMDUint8x16Lib::EntryXor);
  7299. REG_OBJECTS_LIB_FUNC(min, SIMDUint8x16Lib::EntryMin);
  7300. REG_OBJECTS_LIB_FUNC(max, SIMDUint8x16Lib::EntryMax);
  7301. REG_OBJECTS_LIB_FUNC(addSaturate, SIMDUint8x16Lib::EntryAddSaturate);
  7302. REG_OBJECTS_LIB_FUNC(subSaturate, SIMDUint8x16Lib::EntrySubSaturate);
  7303. REG_OBJECTS_LIB_FUNC(lessThan, SIMDUint8x16Lib::EntryLessThan);
  7304. REG_OBJECTS_LIB_FUNC(lessThanOrEqual, SIMDUint8x16Lib::EntryLessThanOrEqual);
  7305. REG_OBJECTS_LIB_FUNC(equal, SIMDUint8x16Lib::EntryEqual);
  7306. REG_OBJECTS_LIB_FUNC(notEqual, SIMDUint8x16Lib::EntryNotEqual);
  7307. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDUint8x16Lib::EntryGreaterThan);
  7308. REG_OBJECTS_LIB_FUNC(greaterThanOrEqual, SIMDUint8x16Lib::EntryGreaterThanOrEqual);
  7309. REG_OBJECTS_LIB_FUNC(extractLane, SIMDUint8x16Lib::EntryExtractLane);
  7310. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDUint8x16Lib::EntryReplaceLane);
  7311. REG_OBJECTS_LIB_FUNC(shiftLeftByScalar, SIMDUint8x16Lib::EntryShiftLeftByScalar);
  7312. REG_OBJECTS_LIB_FUNC(shiftRightByScalar, SIMDUint8x16Lib::EntryShiftRightByScalar);
  7313. REG_OBJECTS_LIB_FUNC(load, SIMDUint8x16Lib::EntryLoad);
  7314. REG_OBJECTS_LIB_FUNC(store, SIMDUint8x16Lib::EntryStore);
  7315. REG_OBJECTS_LIB_FUNC(swizzle, SIMDUint8x16Lib::EntrySwizzle);
  7316. REG_OBJECTS_LIB_FUNC(shuffle, SIMDUint8x16Lib::EntryShuffle);
  7317. REG_OBJECTS_LIB_FUNC(select, SIMDUint8x16Lib::EntrySelect);
  7318. return hr;
  7319. }
  7320. #endif
  7321. #endif // ENABLE_SCRIPT_PROFILING
  7322. #if DBG
  7323. void JavascriptLibrary::DumpLibraryByteCode()
  7324. {
  7325. #if defined(ENABLE_JS_BUILTINS) || defined(ENABLE_INTL_OBJECT)
  7326. // We aren't going to be passing in a number to check range of -dump:LibInit, that will be done by Intl/Promise
  7327. // This is just to force init Intl code if dump:LibInit has been passed
  7328. if (CONFIG_ISENABLED(DumpFlag) && Js::Configuration::Global.flags.Dump.IsEnabled(Js::JsLibInitPhase))
  7329. {
  7330. for (uint i = 0; i <= MaxEngineInterfaceExtensionKind; i++)
  7331. {
  7332. EngineExtensionObjectBase* engineExtension = this->GetEngineInterfaceObject()->GetEngineExtension((Js::EngineInterfaceExtensionKind)i);
  7333. if (engineExtension != nullptr && engineExtension->GetHasByteCode())
  7334. {
  7335. engineExtension->DumpByteCode();
  7336. }
  7337. }
  7338. }
  7339. #endif
  7340. }
  7341. #endif
  7342. #ifdef IR_VIEWER
  7343. HRESULT JavascriptLibrary::ProfilerRegisterIRViewer()
  7344. {
  7345. HRESULT hr = S_OK;
  7346. DEFINE_OBJECT_NAME(IRViewer);
  7347. // TODO (t-doilij) move GlobalObject::EntryParseIR to JavascriptIRViewer::EntryParseIR
  7348. REG_LIB_FUNC_CORE(pwszObjectName, _u("parseIR"), scriptContext->GetOrAddPropertyIdTracked(_u("parseIR")), GlobalObject::EntryParseIR);
  7349. REG_LIB_FUNC_CORE(pwszObjectName, _u("functionList"), scriptContext->GetOrAddPropertyIdTracked(_u("functionList")), GlobalObject::EntryFunctionList);
  7350. REG_LIB_FUNC_CORE(pwszObjectName, _u("rejitFunction"), scriptContext->GetOrAddPropertyIdTracked(_u("rejitFunction")), GlobalObject::EntryRejitFunction);
  7351. return hr;
  7352. }
  7353. #endif /* IR_VIEWER */
  7354. }