JavascriptLibrary.cpp 435 KB

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