JavascriptLibrary.cpp 412 KB

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