JavascriptLibrary.cpp 440 KB

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