2
0

JavascriptLibrary.cpp 379 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. 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 "Types\DynamicObjectEnumerator.h"
  16. #include "Types\DynamicObjectSnapshotEnumerator.h"
  17. #include "Types\DynamicObjectSnapshotEnumeratorWPCache.h"
  18. #include "Library\ForInObjectEnumerator.h"
  19. #include "Library\NullEnumerator.h"
  20. #include "Library\EngineInterfaceObject.h"
  21. #include "Library\IntlEngineInterfaceExtensionObject.h"
  22. #include "Library\ThrowErrorObject.h"
  23. #include "Library\StackScriptFunction.h"
  24. namespace Js
  25. {
  26. SimplePropertyDescriptor const JavascriptLibrary::SharedFunctionPropertyDescriptors[2] =
  27. {
  28. SimplePropertyDescriptor(BuiltInPropertyRecords::prototype, PropertyWritable),
  29. SimplePropertyDescriptor(BuiltInPropertyRecords::name, PropertyConfigurable | PropertyWritable)
  30. };
  31. SimpleTypeHandler<1> JavascriptLibrary::SharedPrototypeTypeHandler(BuiltInPropertyRecords::constructor, PropertyWritable | PropertyConfigurable, PropertyTypesWritableDataOnly, 4, sizeof(DynamicObject));
  32. SimpleTypeHandler<1> JavascriptLibrary::SharedFunctionWithoutPrototypeTypeHandler(BuiltInPropertyRecords::name, PropertyConfigurable | PropertyWritable);
  33. SimpleTypeHandler<1> JavascriptLibrary::SharedFunctionWithPrototypeTypeHandlerV11(BuiltInPropertyRecords::prototype, PropertyWritable);
  34. SimpleTypeHandler<2> JavascriptLibrary::SharedFunctionWithPrototypeTypeHandler(SharedFunctionPropertyDescriptors);
  35. SimpleTypeHandler<1> JavascriptLibrary::SharedIdMappedFunctionWithPrototypeTypeHandler(BuiltInPropertyRecords::prototype);
  36. SimpleTypeHandler<1> JavascriptLibrary::SharedFunctionWithLengthTypeHandler(BuiltInPropertyRecords::length);
  37. MissingPropertyTypeHandler JavascriptLibrary::MissingPropertyHolderTypeHandler;
  38. SimplePropertyDescriptor const JavascriptLibrary::HeapArgumentsPropertyDescriptorsV11[2] =
  39. {
  40. SimplePropertyDescriptor(BuiltInPropertyRecords::length, PropertyConfigurable | PropertyWritable),
  41. SimplePropertyDescriptor(BuiltInPropertyRecords::callee, PropertyConfigurable | PropertyWritable)
  42. };
  43. SimplePropertyDescriptor const JavascriptLibrary::HeapArgumentsPropertyDescriptors[3] =
  44. {
  45. SimplePropertyDescriptor(BuiltInPropertyRecords::length, PropertyConfigurable | PropertyWritable),
  46. SimplePropertyDescriptor(BuiltInPropertyRecords::callee, PropertyConfigurable | PropertyWritable),
  47. SimplePropertyDescriptor(BuiltInPropertyRecords::_symbolIterator, PropertyConfigurable | PropertyWritable)
  48. };
  49. SimplePropertyDescriptor const JavascriptLibrary::FunctionWithLengthAndPrototypeTypeDescriptors[2] =
  50. {
  51. SimplePropertyDescriptor(BuiltInPropertyRecords::prototype, PropertyNone),
  52. SimplePropertyDescriptor(BuiltInPropertyRecords::length, PropertyConfigurable)
  53. };
  54. void JavascriptLibrary::Initialize(ScriptContext* scriptContext, GlobalObject * globalObject)
  55. {
  56. PROBE_STACK(scriptContext, Js::Constants::MinStackDefault);
  57. #ifdef PROFILE_EXEC
  58. scriptContext->ProfileBegin(Js::LibInitPhase);
  59. #endif
  60. this->scriptContext = scriptContext;
  61. this->recycler = scriptContext->GetRecycler();
  62. this->undeclBlockVarSentinel = RecyclerNew(recycler, UndeclaredBlockVariable, StaticType::New(scriptContext, TypeIds_Null, nullptr, nullptr));
  63. typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain = RecyclerNew(recycler, JsUtil::List<Type *>, recycler);
  64. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  65. // WARNING: Any objects created here using DeferredTypeHandler need to appear in EnsureLibraryReadyForHybridDebugging
  66. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  67. // Library is not zero-initialized. memset the memory occupied by builtinFunctions array to 0.
  68. memset(builtinFunctions, 0, sizeof(JavascriptFunction *) * BuiltinFunction::Count);
  69. funcInfoToBuiltinIdMap = Anew(scriptContext->GeneralAllocator(), FuncInfoToBuiltinIdMap, scriptContext->GeneralAllocator());
  70. #define LIBRARY_FUNCTION(target, name, argc, flags, entry) \
  71. funcInfoToBuiltinIdMap->AddNew(&entry, BuiltinFunction::##target##_##name);
  72. #include "LibraryFunction.h"
  73. #undef LIBRARY_FUNCTION
  74. // Note: InitializePrototypes and InitializeTypes must be called first.
  75. InitializePrototypes();
  76. InitializeTypes();
  77. InitializeGlobal(globalObject);
  78. InitializeComplexThings();
  79. InitializeStaticValues();
  80. // Do an early check of hybrid debugging. Note that script engine is not ready, so objects that run script in initializer
  81. // can't be un-deferred yet. However, we can possibly mark isHybridDebugging and avoid deferring new runtime objects.
  82. EnsureReadyIfHybridDebugging(/*isScriptEngineReady*/false);
  83. #if ENABLE_COPYONACCESS_ARRAY
  84. if (!PHASE_OFF1(CopyOnAccessArrayPhase))
  85. {
  86. this->cacheForCopyOnAccessArraySegments = RecyclerNewZ(this->recycler, CacheForCopyOnAccessArraySegments);
  87. }
  88. #endif
  89. #ifdef PROFILE_EXEC
  90. scriptContext->ProfileEnd(Js::LibInitPhase);
  91. #endif
  92. }
  93. void JavascriptLibrary::Uninitialize()
  94. {
  95. this->globalObject = nullptr;
  96. }
  97. void JavascriptLibrary::InitializePrototypes()
  98. {
  99. Recycler* recycler = this->GetRecycler();
  100. nullValue = RecyclerNew(recycler, RecyclableObject, StaticType::New(scriptContext, TypeIds_Null, nullptr, nullptr));
  101. nullValue->GetType()->SetHasSpecialPrototype(true);
  102. ArrayBuffer* baseArrayBuffer;
  103. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  104. // WARNING: Any objects here using DeferredTypeHandler need to appear in EnsureLibraryReadyForHybridDebugging
  105. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  106. // The prototype property of the object prototype is null.
  107. objectPrototype = ObjectPrototypeObject::New(recycler,
  108. DynamicType::New(scriptContext, TypeIds_Object, nullValue, nullptr,
  109. DeferredTypeHandler<InitializeObjectPrototype>::GetDefaultInstance()));
  110. constructorPrototypeObjectType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  111. &SharedPrototypeTypeHandler, true, true);
  112. constructorPrototypeObjectType->SetHasNoEnumerableProperties(true);
  113. if (scriptContext->GetConfig()->IsTypedArrayEnabled())
  114. {
  115. if (scriptContext->GetConfig()->IsES6TypedArrayExtensionsEnabled())
  116. {
  117. arrayBufferPrototype = DynamicObject::New(recycler,
  118. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  119. DeferredTypeHandler<InitializeArrayBufferPrototype>::GetDefaultInstance()));
  120. arrayBufferType = DynamicType::New(scriptContext, TypeIds_ArrayBuffer, arrayBufferPrototype, nullptr,
  121. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  122. dataViewPrototype = DynamicObject::New(recycler,
  123. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  124. DeferredTypeHandler<InitializeDataViewPrototype>::GetDefaultInstance()));
  125. typedArrayPrototype = DynamicObject::New(recycler,
  126. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  127. DeferredTypeHandler<InitializeTypedArrayPrototype>::GetDefaultInstance()));
  128. Int8ArrayPrototype = DynamicObject::New(recycler,
  129. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  130. DeferredTypeHandler<InitializeInt8ArrayPrototype>::GetDefaultInstance()));
  131. Uint8ArrayPrototype = DynamicObject::New(recycler,
  132. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  133. DeferredTypeHandler<InitializeUint8ArrayPrototype>::GetDefaultInstance()));
  134. // If ES6 TypedArrays are enabled, we have Khronos Interop mode enabled
  135. Uint8ClampedArrayPrototype = DynamicObject::New(recycler,
  136. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  137. DeferredTypeHandler<InitializeUint8ClampedArrayPrototype>::GetDefaultInstance()));
  138. Int16ArrayPrototype = DynamicObject::New(recycler,
  139. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  140. DeferredTypeHandler<InitializeInt16ArrayPrototype>::GetDefaultInstance()));
  141. Uint16ArrayPrototype = DynamicObject::New(recycler,
  142. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  143. DeferredTypeHandler<InitializeUint16ArrayPrototype>::GetDefaultInstance()));
  144. Int32ArrayPrototype = DynamicObject::New(recycler,
  145. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  146. DeferredTypeHandler<InitializeInt32ArrayPrototype>::GetDefaultInstance()));
  147. Uint32ArrayPrototype = DynamicObject::New(recycler,
  148. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  149. DeferredTypeHandler<InitializeUint32ArrayPrototype>::GetDefaultInstance()));
  150. Float32ArrayPrototype = DynamicObject::New(recycler,
  151. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  152. DeferredTypeHandler<InitializeFloat32ArrayPrototype>::GetDefaultInstance()));
  153. Float64ArrayPrototype = DynamicObject::New(recycler,
  154. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  155. DeferredTypeHandler<InitializeFloat64ArrayPrototype>::GetDefaultInstance()));
  156. Int64ArrayPrototype = DynamicObject::New(recycler,
  157. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  158. DeferredTypeHandler<InitializeInt64ArrayPrototype>::GetDefaultInstance()));
  159. Uint64ArrayPrototype = DynamicObject::New(recycler,
  160. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  161. DeferredTypeHandler<InitializeUint64ArrayPrototype>::GetDefaultInstance()));
  162. BoolArrayPrototype = DynamicObject::New(recycler,
  163. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  164. DeferredTypeHandler<InitializeBoolArrayPrototype>::GetDefaultInstance()));
  165. CharArrayPrototype = DynamicObject::New(recycler,
  166. DynamicType::New(scriptContext, TypeIds_Object, typedArrayPrototype, nullptr,
  167. DeferredTypeHandler<InitializeCharArrayPrototype>::GetDefaultInstance()));
  168. }
  169. else
  170. {
  171. arrayBufferPrototype = JavascriptArrayBuffer::Create(0,
  172. DynamicType::New(scriptContext, TypeIds_ArrayBuffer, objectPrototype, nullptr,
  173. DeferredTypeHandler<InitializeArrayBufferPrototype>::GetDefaultInstance()));
  174. arrayBufferType = DynamicType::New(scriptContext, TypeIds_ArrayBuffer, arrayBufferPrototype, nullptr,
  175. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  176. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  177. Int8ArrayPrototype = RecyclerNew(recycler, Int8Array, baseArrayBuffer, 0, 0,
  178. DynamicType::New(scriptContext, TypeIds_Int8Array, objectPrototype, nullptr,
  179. DeferredTypeHandler<InitializeInt8ArrayPrototype>::GetDefaultInstance()));
  180. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  181. Uint8ArrayPrototype = RecyclerNew(recycler, Uint8Array, baseArrayBuffer, 0, 0,
  182. DynamicType::New(scriptContext, TypeIds_Uint8Array, objectPrototype, nullptr,
  183. DeferredTypeHandler<InitializeUint8ArrayPrototype>::GetDefaultInstance()));
  184. dataViewPrototype = DynamicObject::New(recycler,
  185. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  186. DeferredTypeHandler<InitializeDataViewPrototype>::GetDefaultInstance()));
  187. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  188. Uint8ClampedArrayPrototype = RecyclerNew(recycler, Uint8ClampedArray, baseArrayBuffer, 0, 0,
  189. DynamicType::New(scriptContext, TypeIds_Uint8ClampedArray, objectPrototype, nullptr,
  190. DeferredTypeHandler<InitializeUint8ClampedArrayPrototype>::GetDefaultInstance()));
  191. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  192. Int16ArrayPrototype = RecyclerNew(recycler, Int16Array, baseArrayBuffer, 0, 0,
  193. DynamicType::New(scriptContext, TypeIds_Int16Array, objectPrototype, nullptr,
  194. DeferredTypeHandler<InitializeInt16ArrayPrototype>::GetDefaultInstance()));
  195. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  196. Uint16ArrayPrototype = RecyclerNew(recycler, Uint16Array, baseArrayBuffer, 0, 0,
  197. DynamicType::New(scriptContext, TypeIds_Uint16Array, objectPrototype, nullptr,
  198. DeferredTypeHandler<InitializeUint16ArrayPrototype>::GetDefaultInstance()));
  199. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  200. Int32ArrayPrototype = RecyclerNew(recycler, Int32Array, baseArrayBuffer, 0, 0,
  201. DynamicType::New(scriptContext, TypeIds_Int32Array, objectPrototype, nullptr,
  202. DeferredTypeHandler<InitializeInt32ArrayPrototype>::GetDefaultInstance()));
  203. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  204. Uint32ArrayPrototype = RecyclerNew(recycler, Uint32Array, baseArrayBuffer, 0, 0,
  205. DynamicType::New(scriptContext, TypeIds_Uint32Array, objectPrototype, nullptr,
  206. DeferredTypeHandler<InitializeUint32ArrayPrototype>::GetDefaultInstance()));
  207. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  208. Float32ArrayPrototype = RecyclerNew(recycler, Float32Array, baseArrayBuffer, 0, 0,
  209. DynamicType::New(scriptContext, TypeIds_Float32Array, objectPrototype, nullptr,
  210. DeferredTypeHandler<InitializeFloat32ArrayPrototype>::GetDefaultInstance()));
  211. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  212. Float64ArrayPrototype = RecyclerNew(recycler, Float64Array, baseArrayBuffer, 0, 0,
  213. DynamicType::New(scriptContext, TypeIds_Float64Array, objectPrototype, nullptr,
  214. DeferredTypeHandler<InitializeFloat64ArrayPrototype>::GetDefaultInstance()));
  215. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  216. Int64ArrayPrototype = RecyclerNew(recycler, Int64Array, baseArrayBuffer, 0, 0,
  217. DynamicType::New(scriptContext, TypeIds_Int64Array, objectPrototype, nullptr,
  218. DeferredTypeHandler<InitializeInt64ArrayPrototype>::GetDefaultInstance()));
  219. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  220. Uint64ArrayPrototype = RecyclerNew(recycler, Uint64Array, baseArrayBuffer, 0, 0,
  221. DynamicType::New(scriptContext, TypeIds_Uint64Array, objectPrototype, nullptr,
  222. DeferredTypeHandler<InitializeUint64ArrayPrototype>::GetDefaultInstance()));
  223. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  224. BoolArrayPrototype = RecyclerNew(recycler, BoolArray, baseArrayBuffer, 0, 0,
  225. DynamicType::New(scriptContext, TypeIds_BoolArray, objectPrototype, nullptr,
  226. DeferredTypeHandler<InitializeBoolArrayPrototype>::GetDefaultInstance()));
  227. baseArrayBuffer = JavascriptArrayBuffer::Create(0, arrayBufferType);
  228. CharArrayPrototype = RecyclerNew(recycler, CharArray, baseArrayBuffer, 0, 0,
  229. DynamicType::New(scriptContext, TypeIds_CharArray, objectPrototype, nullptr,
  230. DeferredTypeHandler<InitializeCharArrayPrototype>::GetDefaultInstance()));
  231. }
  232. }
  233. else
  234. {
  235. arrayBufferType = nullptr;
  236. arrayBufferPrototype = nullptr;
  237. dataViewPrototype = nullptr;
  238. Int8ArrayPrototype = nullptr;
  239. Uint8ArrayPrototype = nullptr;
  240. Uint8ClampedArrayPrototype = nullptr;
  241. Int16ArrayPrototype = nullptr;
  242. Uint16ArrayPrototype = nullptr;
  243. Int32ArrayPrototype = nullptr;
  244. Uint32ArrayPrototype = nullptr;
  245. Float32ArrayPrototype = nullptr;
  246. Float64ArrayPrototype = nullptr;
  247. Int64ArrayPrototype = nullptr;
  248. Uint64ArrayPrototype = nullptr;
  249. BoolArrayPrototype = nullptr;
  250. CharArrayPrototype = nullptr;
  251. }
  252. arrayPrototype = JavascriptArray::New<Var, JavascriptArray, 0>(0,
  253. DynamicType::New(scriptContext, TypeIds_Array, objectPrototype, nullptr,
  254. DeferredTypeHandler<InitializeArrayPrototype>::GetDefaultInstance()), recycler);
  255. booleanPrototype = RecyclerNew(recycler, JavascriptBooleanObject, nullptr,
  256. DynamicType::New(scriptContext, TypeIds_BooleanObject, objectPrototype, nullptr,
  257. DeferredTypeHandler<InitializeBooleanPrototype>::GetDefaultInstance()));
  258. numberPrototype = RecyclerNew(recycler, JavascriptNumberObject, TaggedInt::ToVarUnchecked(0),
  259. DynamicType::New(scriptContext, TypeIds_NumberObject, objectPrototype, nullptr,
  260. DeferredTypeHandler<InitializeNumberPrototype>::GetDefaultInstance()));
  261. stringPrototype = RecyclerNew(recycler, JavascriptStringObject, nullptr,
  262. DynamicType::New(scriptContext, TypeIds_StringObject, objectPrototype, nullptr,
  263. DeferredTypeHandler<InitializeStringPrototype>::GetDefaultInstance()));
  264. if (scriptContext->GetConfig()->IsES6PrototypeChain())
  265. {
  266. datePrototype = DynamicObject::New(recycler,
  267. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  268. DeferredTypeHandler<InitializeDatePrototype>::GetDefaultInstance()));
  269. regexPrototype = DynamicObject::New(recycler,
  270. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  271. DeferredTypeHandler<InitializeRegexPrototype>::GetDefaultInstance()));
  272. }
  273. else
  274. {
  275. double initDateValue = JavascriptNumber::NaN;
  276. datePrototype = RecyclerNewZ(recycler, JavascriptDate, initDateValue,
  277. DynamicType::New(scriptContext, TypeIds_Date, objectPrototype, nullptr,
  278. DeferredTypeHandler<InitializeDatePrototype>::GetDefaultInstance()));
  279. }
  280. if (scriptContext->GetConfig()->IsES6PrototypeChain())
  281. {
  282. errorPrototype = DynamicObject::New(recycler,
  283. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  284. DeferredTypeHandler<InitializeErrorPrototype>::GetDefaultInstance()));
  285. evalErrorPrototype = DynamicObject::New(recycler,
  286. DynamicType::New(scriptContext, TypeIds_Object, errorPrototype, nullptr,
  287. DeferredTypeHandler<InitializeEvalErrorPrototype>::GetDefaultInstance()));
  288. rangeErrorPrototype = DynamicObject::New(recycler,
  289. DynamicType::New(scriptContext, TypeIds_Object, errorPrototype, nullptr,
  290. DeferredTypeHandler<InitializeRangeErrorPrototype>::GetDefaultInstance()));
  291. referenceErrorPrototype = DynamicObject::New(recycler,
  292. DynamicType::New(scriptContext, TypeIds_Object, errorPrototype, nullptr,
  293. DeferredTypeHandler<InitializeReferenceErrorPrototype>::GetDefaultInstance()));
  294. syntaxErrorPrototype = DynamicObject::New(recycler,
  295. DynamicType::New(scriptContext, TypeIds_Object, errorPrototype, nullptr,
  296. DeferredTypeHandler<InitializeSyntaxErrorPrototype>::GetDefaultInstance()));
  297. typeErrorPrototype = DynamicObject::New(recycler,
  298. DynamicType::New(scriptContext, TypeIds_Object, errorPrototype, nullptr,
  299. DeferredTypeHandler<InitializeTypeErrorPrototype>::GetDefaultInstance()));
  300. uriErrorPrototype = DynamicObject::New(recycler,
  301. DynamicType::New(scriptContext, TypeIds_Object, errorPrototype, nullptr,
  302. DeferredTypeHandler<InitializeURIErrorPrototype>::GetDefaultInstance()));
  303. }
  304. else
  305. {
  306. errorPrototype = RecyclerNew(this->GetRecycler(), JavascriptError,
  307. DynamicType::New(scriptContext, TypeIds_Error, objectPrototype, nullptr,
  308. DeferredTypeHandler<InitializeErrorPrototype>::GetDefaultInstance()),
  309. /*isExternalError*/FALSE, /*isPrototype*/TRUE);
  310. evalErrorPrototype = RecyclerNew(this->GetRecycler(), JavascriptError,
  311. DynamicType::New(scriptContext, TypeIds_Error, errorPrototype, nullptr,
  312. DeferredTypeHandler<InitializeEvalErrorPrototype>::GetDefaultInstance()),
  313. /*isExternalError*/FALSE, /*isPrototype*/TRUE);
  314. rangeErrorPrototype = RecyclerNew(this->GetRecycler(), JavascriptError,
  315. DynamicType::New(scriptContext, TypeIds_Error, errorPrototype, nullptr,
  316. DeferredTypeHandler<InitializeRangeErrorPrototype>::GetDefaultInstance()),
  317. /*isExternalError*/FALSE, /*isPrototype*/TRUE);
  318. referenceErrorPrototype = RecyclerNew(this->GetRecycler(), JavascriptError,
  319. DynamicType::New(scriptContext, TypeIds_Error, errorPrototype, nullptr,
  320. DeferredTypeHandler<InitializeReferenceErrorPrototype>::GetDefaultInstance()),
  321. /*isExternalError*/FALSE, /*isPrototype*/TRUE);
  322. syntaxErrorPrototype = RecyclerNew(this->GetRecycler(), JavascriptError,
  323. DynamicType::New(scriptContext, TypeIds_Error, errorPrototype, nullptr,
  324. DeferredTypeHandler<InitializeSyntaxErrorPrototype>::GetDefaultInstance()),
  325. /*isExternalError*/FALSE, /*isPrototype*/TRUE);
  326. typeErrorPrototype = RecyclerNew(this->GetRecycler(), JavascriptError,
  327. DynamicType::New(scriptContext, TypeIds_Error, errorPrototype, nullptr,
  328. DeferredTypeHandler<InitializeTypeErrorPrototype>::GetDefaultInstance()),
  329. /*isExternalError*/FALSE, /*isPrototype*/TRUE);
  330. uriErrorPrototype = RecyclerNew(this->GetRecycler(), JavascriptError,
  331. DynamicType::New(scriptContext, TypeIds_Error, errorPrototype, nullptr,
  332. DeferredTypeHandler<InitializeURIErrorPrototype>::GetDefaultInstance()),
  333. /*isExternalError*/FALSE, /*isPrototype*/TRUE);
  334. }
  335. functionPrototype = RecyclerNew(recycler, JavascriptFunction,
  336. DynamicType::New(scriptContext, TypeIds_Function, objectPrototype, JavascriptFunction::PrototypeEntryPoint,
  337. DeferredTypeHandler<InitializeFunctionPrototype>::GetDefaultInstance()), &JavascriptFunction::EntryInfo::PrototypeEntryPoint);
  338. symbolPrototype = nullptr;
  339. mapPrototype = nullptr;
  340. setPrototype = nullptr;
  341. weakMapPrototype = nullptr;
  342. weakSetPrototype = nullptr;
  343. arrayIteratorPrototype = nullptr;
  344. mapIteratorPrototype = nullptr;
  345. setIteratorPrototype = nullptr;
  346. stringIteratorPrototype = nullptr;
  347. promisePrototype = nullptr;
  348. javascriptEnumeratorIteratorPrototype = nullptr;
  349. generatorFunctionPrototype = nullptr;
  350. generatorPrototype = nullptr;
  351. iteratorPrototype = nullptr;
  352. if (scriptContext->GetConfig()->IsES6SymbolEnabled())
  353. {
  354. symbolPrototype = DynamicObject::New(recycler,
  355. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  356. DeferredTypeHandler<InitializeSymbolPrototype>::GetDefaultInstance()));
  357. }
  358. if (scriptContext->GetConfig()->IsES6MapEnabled())
  359. {
  360. mapPrototype = DynamicObject::New(recycler,
  361. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  362. DeferredTypeHandler<InitializeMapPrototype>::GetDefaultInstance()));
  363. }
  364. if (scriptContext->GetConfig()->IsES6SetEnabled())
  365. {
  366. setPrototype = DynamicObject::New(recycler,
  367. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  368. DeferredTypeHandler<InitializeSetPrototype>::GetDefaultInstance()));
  369. }
  370. if (scriptContext->GetConfig()->IsES6WeakMapEnabled())
  371. {
  372. weakMapPrototype = DynamicObject::New(recycler,
  373. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  374. DeferredTypeHandler<InitializeWeakMapPrototype>::GetDefaultInstance()));
  375. }
  376. if (scriptContext->GetConfig()->IsES6WeakSetEnabled())
  377. {
  378. weakSetPrototype = DynamicObject::New(recycler,
  379. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  380. DeferredTypeHandler<InitializeWeakSetPrototype>::GetDefaultInstance()));
  381. }
  382. if (scriptContext->GetConfig()->IsES6IteratorsEnabled())
  383. {
  384. iteratorPrototype = DynamicObject::New(recycler,
  385. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  386. DeferredTypeHandler<InitializeIteratorPrototype>::GetDefaultInstance()));
  387. arrayIteratorPrototype = DynamicObject::New(recycler,
  388. DynamicType::New(scriptContext, TypeIds_Object, iteratorPrototype, nullptr,
  389. DeferredTypeHandler<InitializeArrayIteratorPrototype>::GetDefaultInstance()));
  390. mapIteratorPrototype = DynamicObject::New(recycler,
  391. DynamicType::New(scriptContext, TypeIds_Object, iteratorPrototype, nullptr,
  392. DeferredTypeHandler<InitializeMapIteratorPrototype>::GetDefaultInstance()));
  393. setIteratorPrototype = DynamicObject::New(recycler,
  394. DynamicType::New(scriptContext, TypeIds_Object, iteratorPrototype, nullptr,
  395. DeferredTypeHandler<InitializeSetIteratorPrototype>::GetDefaultInstance()));
  396. stringIteratorPrototype = DynamicObject::New(recycler,
  397. DynamicType::New(scriptContext, TypeIds_Object, iteratorPrototype, nullptr,
  398. DeferredTypeHandler<InitializeStringIteratorPrototype>::GetDefaultInstance()));
  399. }
  400. if (scriptContext->GetConfig()->IsES6PromiseEnabled())
  401. {
  402. promisePrototype = DynamicObject::New(recycler,
  403. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  404. DeferredTypeHandler<InitializePromisePrototype>::GetDefaultInstance()));
  405. }
  406. if (scriptContext->GetConfig()->IsES6ProxyEnabled())
  407. {
  408. RecyclableObject* proto =
  409. scriptContext->GetConfig()->IsES6IteratorsEnabled() ?
  410. iteratorPrototype :
  411. objectPrototype;
  412. javascriptEnumeratorIteratorPrototype = DynamicObject::New(recycler,
  413. DynamicType::New(scriptContext, TypeIds_Object, proto, nullptr,
  414. DeferredTypeHandler<InitializeJavascriptEnumeratorIteratorPrototype>::GetDefaultInstance()));
  415. }
  416. if (scriptContext->GetConfig()->IsES6GeneratorsEnabled())
  417. {
  418. generatorFunctionPrototype = DynamicObject::New(recycler,
  419. DynamicType::New(scriptContext, TypeIds_Object, functionPrototype, nullptr,
  420. DeferredTypeHandler<InitializeGeneratorFunctionPrototype>::GetDefaultInstance()));
  421. RecyclableObject* proto =
  422. scriptContext->GetConfig()->IsES6IteratorsEnabled() ?
  423. iteratorPrototype :
  424. objectPrototype;
  425. generatorPrototype = DynamicObject::New(recycler,
  426. DynamicType::New(scriptContext, TypeIds_Object, proto, nullptr,
  427. DeferredTypeHandler<InitializeGeneratorPrototype>::GetDefaultInstance()));
  428. }
  429. }
  430. void JavascriptLibrary::InitializeTypes()
  431. {
  432. Recycler* recycler = this->GetRecycler();
  433. ScriptConfiguration const *config = scriptContext->GetConfig();
  434. enumeratorType = StaticType::New(scriptContext, TypeIds_Enumerator, objectPrototype, nullptr);
  435. // Initialize Array/Argument types
  436. uint heapArgumentPropertyDescriptorsCount = 0;
  437. SimplePropertyDescriptor const * heapArgumentPropertyDescriptors = nullptr;
  438. if (config->IsES6IteratorsEnabled())
  439. {
  440. heapArgumentPropertyDescriptors = HeapArgumentsPropertyDescriptors;
  441. heapArgumentPropertyDescriptorsCount = _countof(HeapArgumentsPropertyDescriptors);
  442. }
  443. else
  444. {
  445. heapArgumentPropertyDescriptorsCount = _countof(HeapArgumentsPropertyDescriptorsV11);
  446. heapArgumentPropertyDescriptors = HeapArgumentsPropertyDescriptorsV11;
  447. }
  448. heapArgumentsType = DynamicType::New(scriptContext, TypeIds_Arguments, objectPrototype, nullptr,
  449. SimpleDictionaryTypeHandler::New(scriptContext, heapArgumentPropertyDescriptors, heapArgumentPropertyDescriptorsCount, 0, 0, true, true), true, true);
  450. activationObjectType = DynamicType::New(scriptContext, TypeIds_ActivationObject, nullValue, nullptr,
  451. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  452. arrayType = DynamicType::New(scriptContext, TypeIds_Array, arrayPrototype, nullptr,
  453. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  454. nativeIntArrayType = DynamicType::New(scriptContext, TypeIds_NativeIntArray, arrayPrototype, nullptr,
  455. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  456. #if ENABLE_COPYONACCESS_ARRAY
  457. copyOnAccessNativeIntArrayType = DynamicType::New(scriptContext, TypeIds_CopyOnAccessNativeIntArray, arrayPrototype, nullptr,
  458. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  459. #endif
  460. nativeFloatArrayType = DynamicType::New(scriptContext, TypeIds_NativeFloatArray, arrayPrototype, nullptr,
  461. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  462. arrayBufferType = DynamicType::New(scriptContext, TypeIds_ArrayBuffer, arrayBufferPrototype, nullptr,
  463. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  464. dataViewType = DynamicType::New(scriptContext, TypeIds_DataView, dataViewPrototype, nullptr,
  465. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  466. int8ArrayType = DynamicType::New(scriptContext, TypeIds_Int8Array, Int8ArrayPrototype, nullptr,
  467. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  468. uint8ArrayType = DynamicType::New(scriptContext, TypeIds_Uint8Array, Uint8ArrayPrototype, nullptr,
  469. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  470. uint8ClampedArrayType = DynamicType::New(scriptContext, TypeIds_Uint8ClampedArray, Uint8ClampedArrayPrototype, nullptr,
  471. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  472. int16ArrayType = DynamicType::New(scriptContext, TypeIds_Int16Array, Int16ArrayPrototype, nullptr,
  473. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  474. uint16ArrayType = DynamicType::New(scriptContext, TypeIds_Uint16Array, Uint16ArrayPrototype, nullptr,
  475. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  476. int32ArrayType = DynamicType::New(scriptContext, TypeIds_Int32Array, Int32ArrayPrototype, nullptr,
  477. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  478. uint32ArrayType = DynamicType::New(scriptContext, TypeIds_Uint32Array, Uint32ArrayPrototype, nullptr,
  479. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  480. float32ArrayType = DynamicType::New(scriptContext, TypeIds_Float32Array, Float32ArrayPrototype, nullptr,
  481. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  482. float64ArrayType = DynamicType::New(scriptContext, TypeIds_Float64Array, Float64ArrayPrototype, nullptr,
  483. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  484. int64ArrayType = DynamicType::New(scriptContext, TypeIds_Int64Array, Int64ArrayPrototype, nullptr,
  485. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  486. uint64ArrayType = DynamicType::New(scriptContext, TypeIds_Uint64Array, Uint64ArrayPrototype, nullptr,
  487. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  488. boolArrayType = DynamicType::New(scriptContext, TypeIds_BoolArray, BoolArrayPrototype, nullptr,
  489. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  490. charArrayType = DynamicType::New(scriptContext, TypeIds_CharArray, CharArrayPrototype, nullptr,
  491. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  492. errorType = DynamicType::New(scriptContext, TypeIds_Error, errorPrototype, nullptr,
  493. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  494. evalErrorType = DynamicType::New(scriptContext, TypeIds_Error, evalErrorPrototype, nullptr,
  495. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  496. rangeErrorType = DynamicType::New(scriptContext, TypeIds_Error, rangeErrorPrototype, nullptr,
  497. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  498. referenceErrorType = DynamicType::New(scriptContext, TypeIds_Error, referenceErrorPrototype, nullptr,
  499. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  500. syntaxErrorType = DynamicType::New(scriptContext, TypeIds_Error, syntaxErrorPrototype, nullptr,
  501. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  502. typeErrorType = DynamicType::New(scriptContext, TypeIds_Error, typeErrorPrototype, nullptr,
  503. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  504. uriErrorType = DynamicType::New(scriptContext, TypeIds_Error, uriErrorPrototype, nullptr,
  505. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  506. symbolTypeStatic = nullptr;
  507. symbolTypeDynamic = nullptr;
  508. withType = nullptr;
  509. proxyType = nullptr;
  510. promiseType = nullptr;
  511. javascriptEnumeratorIteratorType = nullptr;
  512. // Initialize boolean types
  513. booleanTypeStatic = StaticType::New(scriptContext, TypeIds_Boolean, booleanPrototype, nullptr);
  514. booleanTypeDynamic = DynamicType::New(scriptContext, TypeIds_BooleanObject, booleanPrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  515. if (config->IsES6SymbolEnabled())
  516. {
  517. // Initialize symbol types
  518. symbolTypeStatic = StaticType::New(scriptContext, TypeIds_Symbol, symbolPrototype, nullptr);
  519. symbolTypeDynamic = DynamicType::New(scriptContext, TypeIds_SymbolObject, symbolPrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  520. }
  521. if (config->IsES6UnscopablesEnabled())
  522. {
  523. withType = StaticType::New(scriptContext, TypeIds_WithScopeObject, GetNull(), nullptr);
  524. }
  525. if (config->IsES6SpreadEnabled())
  526. {
  527. SpreadArgumentType = DynamicType::New(scriptContext, TypeIds_SpreadArgument, GetNull(), nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  528. }
  529. if (config->IsES6ProxyEnabled())
  530. {
  531. // 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.
  532. // 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
  533. // continue prototype chain walk after proxy.
  534. proxyType = DynamicType::New(scriptContext, TypeIds_Proxy, GetNull(), nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  535. javascriptEnumeratorIteratorType = DynamicType::New(scriptContext, TypeIds_JavascriptEnumeratorIterator, javascriptEnumeratorIteratorPrototype, nullptr,
  536. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  537. }
  538. if (config->IsES6PromiseEnabled())
  539. {
  540. promiseType = DynamicType::New(scriptContext, TypeIds_Promise, promisePrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  541. }
  542. // Initialize Date types
  543. dateType = DynamicType::New(scriptContext, TypeIds_Date, datePrototype, nullptr,
  544. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  545. variantDateType = StaticType::New(scriptContext, TypeIds_VariantDate, nullValue, nullptr);
  546. anonymousFunctionTypeHandler = NullTypeHandler<false>::GetDefaultInstance();
  547. anonymousFunctionWithPrototypeTypeHandler = &SharedFunctionWithPrototypeTypeHandlerV11;
  548. // Initialize function types
  549. if (config->IsES6FunctionNameEnabled())
  550. {
  551. functionTypeHandler = &SharedFunctionWithoutPrototypeTypeHandler;
  552. }
  553. else
  554. {
  555. functionTypeHandler = anonymousFunctionTypeHandler;
  556. }
  557. if (config->IsES6FunctionNameEnabled())
  558. {
  559. functionWithPrototypeTypeHandler = &SharedFunctionWithPrototypeTypeHandler;
  560. }
  561. else
  562. {
  563. functionWithPrototypeTypeHandler = anonymousFunctionWithPrototypeTypeHandler;
  564. }
  565. functionWithPrototypeTypeHandler->SetHasKnownSlot0();
  566. externalFunctionWithDeferredPrototypeType = CreateDeferredPrototypeFunctionTypeNoProfileThunk(JavascriptExternalFunction::ExternalFunctionThunk, true /*isShared*/);
  567. wrappedFunctionWithDeferredPrototypeType = CreateDeferredPrototypeFunctionTypeNoProfileThunk(JavascriptExternalFunction::WrappedFunctionThunk, true /*isShared*/);
  568. stdCallFunctionWithDeferredPrototypeType = CreateDeferredPrototypeFunctionTypeNoProfileThunk(JavascriptExternalFunction::StdCallExternalFunctionThunk, true /*isShared*/);
  569. idMappedFunctionWithPrototypeType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, JavascriptExternalFunction::ExternalFunctionThunk,
  570. &SharedIdMappedFunctionWithPrototypeTypeHandler, true, true);
  571. externalConstructorFunctionWithDeferredPrototypeType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, JavascriptExternalFunction::ExternalFunctionThunk,
  572. Js::DeferredTypeHandler<Js::JavascriptExternalFunction::DeferredInitializer>::GetDefaultInstance(), true, true);
  573. if (config->IsES6FunctionNameEnabled())
  574. {
  575. boundFunctionType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, BoundFunction::NewInstance,
  576. GetDeferredFunctionTypeHandler(), true, true);
  577. }
  578. else
  579. {
  580. boundFunctionType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, BoundFunction::NewInstance,
  581. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  582. }
  583. crossSiteDeferredPrototypeFunctionType = CreateDeferredPrototypeFunctionTypeNoProfileThunk(
  584. scriptContext->CurrentCrossSiteThunk, true /*isShared*/);
  585. crossSiteIdMappedFunctionWithPrototypeType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, scriptContext->CurrentCrossSiteThunk,
  586. &SharedIdMappedFunctionWithPrototypeTypeHandler, true, true);
  587. crossSiteExternalConstructFunctionWithPrototypeType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, scriptContext->CurrentCrossSiteThunk,
  588. Js::DeferredTypeHandler<Js::JavascriptExternalFunction::DeferredInitializer>::GetDefaultInstance(), true, true);
  589. // Initialize Number types
  590. numberTypeStatic = StaticType::New(scriptContext, TypeIds_Number, numberPrototype, nullptr);
  591. int64NumberTypeStatic = StaticType::New(scriptContext, TypeIds_Int64Number, numberPrototype, nullptr);
  592. uint64NumberTypeStatic = StaticType::New(scriptContext, TypeIds_UInt64Number, numberPrototype, nullptr);
  593. numberTypeDynamic = DynamicType::New(scriptContext, TypeIds_NumberObject, numberPrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  594. // SIMD_JS
  595. // Initialize types
  596. if (GetScriptContext()->GetConfig()->IsSimdjsEnabled())
  597. {
  598. simdFloat32x4TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDFloat32x4, nullValue /*prototype*/, nullptr);
  599. simdFloat64x2TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDFloat64x2, nullValue /*prototype*/, nullptr);
  600. simdInt32x4TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDInt32x4, nullValue /*prototype*/, nullptr);
  601. simdInt8x16TypeStatic = StaticType::New(scriptContext, TypeIds_SIMDInt8x16, nullValue /*prototype*/, nullptr);
  602. }
  603. // Initialize Object types
  604. for (int16 i = 0; i < PreInitializedObjectTypeCount; i++)
  605. {
  606. SimplePathTypeHandler * typeHandler =
  607. SimplePathTypeHandler::New(
  608. scriptContext,
  609. scriptContext->GetRootPath(),
  610. 0,
  611. i * InlineSlotCountIncrement,
  612. sizeof(DynamicObject),
  613. true,
  614. true);
  615. typeHandler->SetIsInlineSlotCapacityLocked();
  616. objectTypes[i] = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr, typeHandler, true, true);
  617. }
  618. for (int16 i = 0; i < PreInitializedObjectTypeCount; i++)
  619. {
  620. SimplePathTypeHandler * typeHandler =
  621. SimplePathTypeHandler::New(
  622. scriptContext,
  623. scriptContext->GetRootPath(),
  624. 0,
  625. DynamicTypeHandler::GetObjectHeaderInlinableSlotCapacity() + i * InlineSlotCountIncrement,
  626. DynamicTypeHandler::GetOffsetOfObjectHeaderInlineSlots(),
  627. true,
  628. true);
  629. typeHandler->SetIsInlineSlotCapacityLocked();
  630. objectHeaderInlinedTypes[i] =
  631. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr, typeHandler, true, true);
  632. }
  633. // Initialize regex types
  634. TypePath *const regexResultPath = TypePath::New(recycler);
  635. regexResultPath->Add(BuiltInPropertyRecords::input);
  636. regexResultPath->Add(BuiltInPropertyRecords::index);
  637. regexResultType = DynamicType::New(scriptContext, TypeIds_Array, arrayPrototype, nullptr,
  638. SimplePathTypeHandler::New(scriptContext, regexResultPath, regexResultPath->GetPathLength(), JavascriptRegularExpressionResult::InlineSlotCount, sizeof(JavascriptArray), true, true), true, true);
  639. // Initialize string types
  640. stringTypeStatic = StaticType::New(scriptContext, TypeIds_String, stringPrototype, nullptr);
  641. stringTypeDynamic = DynamicType::New(scriptContext, TypeIds_StringObject, stringPrototype, nullptr, NullTypeHandler<false>::GetDefaultInstance(), true, true);
  642. // Initialize Throw error object type
  643. throwErrorObjectType = StaticType::New(scriptContext, TypeIds_Undefined, nullValue, ThrowErrorObject::DefaultEntryPoint);
  644. mapType = nullptr;
  645. setType = nullptr;
  646. weakMapType = nullptr;
  647. weakSetType = nullptr;
  648. iteratorResultType = nullptr;
  649. arrayIteratorType = nullptr;
  650. mapIteratorType = nullptr;
  651. setIteratorType = nullptr;
  652. stringIteratorType = nullptr;
  653. if (config->IsES6MapEnabled())
  654. {
  655. mapType = DynamicType::New(scriptContext, TypeIds_Map, mapPrototype, nullptr,
  656. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  657. }
  658. if (config->IsES6SetEnabled())
  659. {
  660. setType = DynamicType::New(scriptContext, TypeIds_Set, setPrototype, nullptr,
  661. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  662. }
  663. if (config->IsES6WeakMapEnabled())
  664. {
  665. weakMapType = DynamicType::New(scriptContext, TypeIds_WeakMap, weakMapPrototype, nullptr,
  666. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  667. }
  668. if (config->IsES6WeakSetEnabled())
  669. {
  670. weakSetType = DynamicType::New(scriptContext, TypeIds_WeakSet, weakSetPrototype, nullptr,
  671. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  672. }
  673. if (config->IsES6IteratorsEnabled())
  674. {
  675. TypePath *const iteratorResultPath = TypePath::New(recycler);
  676. iteratorResultPath->Add(BuiltInPropertyRecords::value);
  677. iteratorResultPath->Add(BuiltInPropertyRecords::done);
  678. iteratorResultType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  679. SimplePathTypeHandler::New(scriptContext, iteratorResultPath, iteratorResultPath->GetPathLength(), 2, sizeof(DynamicObject), true, true), true, true);
  680. arrayIteratorType = DynamicType::New(scriptContext, TypeIds_ArrayIterator, arrayIteratorPrototype, nullptr,
  681. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  682. mapIteratorType = DynamicType::New(scriptContext, TypeIds_MapIterator, mapIteratorPrototype, nullptr,
  683. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  684. setIteratorType = DynamicType::New(scriptContext, TypeIds_SetIterator, setIteratorPrototype, nullptr,
  685. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  686. stringIteratorType = DynamicType::New(scriptContext, TypeIds_StringIterator, stringIteratorPrototype, nullptr,
  687. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  688. }
  689. if (config->IsES6GeneratorsEnabled())
  690. {
  691. generatorConstructorPrototypeObjectType = DynamicType::New(scriptContext, TypeIds_Object, generatorPrototype, nullptr,
  692. NullTypeHandler<false>::GetDefaultInstance(), true, true);
  693. generatorConstructorPrototypeObjectType->SetHasNoEnumerableProperties(true);
  694. }
  695. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  696. debugDisposableObjectType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  697. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  698. debugFuncExecutorInDisposeObjectType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  699. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  700. #endif
  701. }
  702. void JavascriptLibrary::InitializeGeneratorFunction(DynamicObject *function, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  703. {
  704. bool isAnonymousFunction = JavascriptGeneratorFunction::FromVar(function)->IsAnonymousFunction();
  705. JavascriptLibrary* javascriptLibrary = function->GetType()->GetLibrary();
  706. typeHandler->Convert(function, isAnonymousFunction ? javascriptLibrary->anonymousFunctionWithPrototypeTypeHandler : javascriptLibrary->functionWithPrototypeTypeHandler);
  707. function->SetPropertyWithAttributes(PropertyIds::prototype, javascriptLibrary->CreateGeneratorConstructorPrototypeObject(), PropertyWritable, nullptr);
  708. if (function->GetScriptContext()->GetConfig()->IsES6FunctionNameEnabled() && !isAnonymousFunction)
  709. {
  710. JavascriptString * functionName = nullptr;
  711. DebugOnly(bool status = ) ((Js::JavascriptFunction*)function)->GetFunctionName(&functionName);
  712. Assert(status);
  713. function->SetPropertyWithAttributes(PropertyIds::name,functionName, PropertyConfigurable, nullptr);
  714. }
  715. }
  716. template<bool addPrototype>
  717. void JavascriptLibrary::InitializeFunction(DynamicObject *function, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  718. {
  719. JavascriptLibrary* javascriptLibrary = function->GetType()->GetLibrary();
  720. ScriptFunction *scriptFunction = nullptr;
  721. bool useAnonymous = false;
  722. if (ScriptFunction::Is(function))
  723. {
  724. scriptFunction = Js::ScriptFunction::FromVar(function);
  725. useAnonymous = scriptFunction->IsAnonymousFunction();
  726. }
  727. if (!addPrototype)
  728. {
  729. Assert(!useAnonymous);
  730. typeHandler->Convert(function, javascriptLibrary->functionTypeHandler);
  731. }
  732. else
  733. {
  734. typeHandler->Convert(function, useAnonymous ? javascriptLibrary->anonymousFunctionWithPrototypeTypeHandler : javascriptLibrary->functionWithPrototypeTypeHandler);
  735. function->SetProperty(PropertyIds::prototype, javascriptLibrary->CreateConstructorPrototypeObject((Js::JavascriptFunction *)function), PropertyOperation_None, nullptr);
  736. }
  737. if (scriptFunction)
  738. {
  739. if (scriptFunction->GetFunctionInfo()->IsClassConstructor())
  740. {
  741. scriptFunction->SetWritable(Js::PropertyIds::prototype, FALSE);
  742. }
  743. }
  744. ScriptContext *scriptContext = function->GetScriptContext();
  745. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  746. {
  747. if(scriptFunction && (useAnonymous || scriptFunction->GetFunctionProxy()->EnsureDeserialized()->GetIsStaticNameFunction()))
  748. {
  749. return;
  750. }
  751. JavascriptString * functionName = nullptr;
  752. if (((Js::JavascriptFunction*)function)->GetFunctionName(&functionName))
  753. {
  754. function->SetPropertyWithAttributes(PropertyIds::name, functionName, PropertyConfigurable, nullptr);
  755. }
  756. }
  757. }
  758. template<bool isNameAvailable, bool isPrototypeAvailable>
  759. class InitializeFunctionDeferredTypeHandlerFilter
  760. {
  761. public:
  762. static bool HasFilter() { return true; }
  763. static bool HasProperty(PropertyId propertyId)
  764. {
  765. switch (propertyId)
  766. {
  767. case PropertyIds::prototype:
  768. return isPrototypeAvailable;
  769. case PropertyIds::name:
  770. return isNameAvailable;
  771. }
  772. return false;
  773. }
  774. };
  775. template<bool isNameAvailable, bool isPrototypeAvailable>
  776. DynamicTypeHandler * JavascriptLibrary::GetDeferredFunctionTypeHandlerBase()
  777. {
  778. return DeferredTypeHandler<InitializeFunction<isPrototypeAvailable>, InitializeFunctionDeferredTypeHandlerFilter<isNameAvailable, isPrototypeAvailable>>::GetDefaultInstance();
  779. }
  780. template<bool isNameAvailable, bool isPrototypeAvailable>
  781. DynamicTypeHandler * JavascriptLibrary::GetDeferredGeneratorFunctionTypeHandlerBase()
  782. {
  783. return DeferredTypeHandler<InitializeGeneratorFunction, InitializeFunctionDeferredTypeHandlerFilter<isNameAvailable, isPrototypeAvailable>>::GetDefaultInstance();
  784. }
  785. DynamicTypeHandler * JavascriptLibrary::GetDeferredAnonymousPrototypeGeneratorFunctionTypeHandler()
  786. {
  787. return JavascriptLibrary::GetDeferredGeneratorFunctionTypeHandlerBase</*isNameAvailable*/ false>();
  788. }
  789. DynamicTypeHandler * JavascriptLibrary::GetDeferredPrototypeGeneratorFunctionTypeHandler(ScriptContext* scriptContext)
  790. {
  791. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  792. {
  793. return JavascriptLibrary::GetDeferredGeneratorFunctionTypeHandlerBase</*isNameAvailable*/ true>();
  794. }
  795. else
  796. {
  797. return JavascriptLibrary::GetDeferredGeneratorFunctionTypeHandlerBase</*isNameAvailable*/ false>();
  798. }
  799. }
  800. DynamicTypeHandler * JavascriptLibrary::GetDeferredAnonymousPrototypeFunctionTypeHandler()
  801. {
  802. return JavascriptLibrary::GetDeferredFunctionTypeHandlerBase</*isNameAvailable*/ false>();
  803. }
  804. DynamicTypeHandler * JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler(ScriptContext* scriptContext)
  805. {
  806. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  807. {
  808. return JavascriptLibrary::GetDeferredFunctionTypeHandlerBase</*isNameAvailable*/ true>();
  809. }
  810. else
  811. {
  812. return JavascriptLibrary::GetDeferredFunctionTypeHandlerBase</*isNameAvailable*/ false>();
  813. }
  814. }
  815. DynamicTypeHandler * JavascriptLibrary::GetDeferredAnonymousFunctionTypeHandler()
  816. {
  817. return anonymousFunctionTypeHandler;
  818. }
  819. DynamicTypeHandler * JavascriptLibrary::GetDeferredFunctionTypeHandler()
  820. {
  821. if (this->GetScriptContext()->GetConfig()->IsES6FunctionNameEnabled())
  822. {
  823. return GetDeferredFunctionTypeHandlerBase</*isNameAvailable*/ true, /*isPrototypeAvailable*/ false>();
  824. }
  825. return functionTypeHandler;
  826. }
  827. DynamicTypeHandler * JavascriptLibrary::ScriptFunctionTypeHandler(bool hasPrototype, bool isAnonymousFunction)
  828. {
  829. DynamicTypeHandler * scriptFunctionTypeHandler = nullptr;
  830. if (hasPrototype)
  831. {
  832. scriptFunctionTypeHandler = isAnonymousFunction ?
  833. this->GetDeferredAnonymousFunctionTypeHandler() : this->GetDeferredFunctionTypeHandler();
  834. }
  835. else
  836. {
  837. scriptFunctionTypeHandler = isAnonymousFunction ?
  838. JavascriptLibrary::GetDeferredAnonymousPrototypeFunctionTypeHandler() : JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler(scriptContext);
  839. }
  840. return scriptFunctionTypeHandler;
  841. }
  842. DynamicType * JavascriptLibrary::CreateDeferredPrototypeGeneratorFunctionType(JavascriptMethod entrypoint, bool isAnonymousFunction, bool isShared)
  843. {
  844. return DynamicType::New(scriptContext, TypeIds_Function, generatorFunctionPrototype, entrypoint,
  845. isAnonymousFunction ? GetDeferredAnonymousPrototypeGeneratorFunctionTypeHandler() : GetDeferredPrototypeGeneratorFunctionTypeHandler(scriptContext), isShared, isShared);
  846. }
  847. DynamicType * JavascriptLibrary::CreateDeferredPrototypeFunctionType(JavascriptMethod entrypoint)
  848. {
  849. return CreateDeferredPrototypeFunctionTypeNoProfileThunk(this->inDispatchProfileMode ? ProfileEntryThunk : entrypoint);
  850. }
  851. DynamicType * JavascriptLibrary::CreateDeferredPrototypeFunctionTypeNoProfileThunk(JavascriptMethod entrypoint, bool isShared)
  852. {
  853. // Note: the lack of TypeHandler switching here based on the isAnonymousFunction flag is intentional.
  854. // We can't switch shared typeHandlers and RuntimeFunctions do not produce script code for us to know if a function is Anonymous.
  855. // As a result we may have an issue where hasProperty would say you have a name property but getProperty returns undefined
  856. return DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, entrypoint,
  857. GetDeferredPrototypeFunctionTypeHandler(scriptContext), isShared, isShared);
  858. }
  859. DynamicType * JavascriptLibrary::CreateFunctionType(JavascriptMethod entrypoint, RecyclableObject* prototype)
  860. {
  861. if (prototype == nullptr)
  862. {
  863. prototype = functionPrototype;
  864. }
  865. return DynamicType::New(scriptContext, TypeIds_Function, prototype, entrypoint,
  866. GetDeferredFunctionTypeHandler(), false, false);
  867. }
  868. DynamicType * JavascriptLibrary::CreateFunctionWithLengthType(FunctionInfo * functionInfo)
  869. {
  870. return CreateFunctionWithLengthType(this->GetFunctionPrototype(), functionInfo);
  871. }
  872. DynamicType * JavascriptLibrary::CreateFunctionWithLengthAndPrototypeType(FunctionInfo * functionInfo)
  873. {
  874. return CreateFunctionWithLengthAndPrototypeType(this->GetFunctionPrototype(), functionInfo);
  875. }
  876. DynamicType * JavascriptLibrary::CreateFunctionWithLengthType(DynamicObject * prototype, FunctionInfo * functionInfo)
  877. {
  878. Assert(!functionInfo->HasBody());
  879. return DynamicType::New(scriptContext, TypeIds_Function, prototype,
  880. this->inProfileMode? ProfileEntryThunk : functionInfo->GetOriginalEntryPoint(),
  881. &SharedFunctionWithLengthTypeHandler);
  882. }
  883. DynamicType * JavascriptLibrary::CreateFunctionWithLengthAndPrototypeType(DynamicObject * prototype, FunctionInfo * functionInfo)
  884. {
  885. Assert(!functionInfo->HasBody());
  886. return DynamicType::New(scriptContext, TypeIds_Function, prototype,
  887. this->inProfileMode? ProfileEntryThunk : functionInfo->GetOriginalEntryPoint(),
  888. SimpleDictionaryTypeHandler::New(scriptContext, FunctionWithLengthAndPrototypeTypeDescriptors, _countof(FunctionWithLengthAndPrototypeTypeDescriptors), 0, 0));
  889. }
  890. void JavascriptLibrary::InitializeProperties(ThreadContext * threadContext)
  891. {
  892. if ( threadContext->GetMaxPropertyId() < PropertyIds::_countJSOnlyProperty )
  893. {
  894. threadContext->UncheckedAddBuiltInPropertyId();
  895. }
  896. }
  897. DynamicObject * JavascriptLibraryBase::GetObjectPrototype()
  898. {
  899. return GetObjectPrototypeObject();
  900. }
  901. void JavascriptLibraryBase::Finalize(bool isShutdown)
  902. {
  903. if (scriptContext)
  904. {
  905. // Clear the weak reference dictionary so we don't need to clean them
  906. // during PostCollectCallBack before Dispose deleting the script context.
  907. scriptContext->ResetWeakReferenceDicitionaryList();
  908. }
  909. }
  910. void JavascriptLibraryBase::Dispose(bool isShutdown)
  911. {
  912. if (scriptContext)
  913. {
  914. if (isShutdown)
  915. {
  916. // during shut down the global object might not be closed yet.
  917. // Clear the global object from the script context so it doesn't
  918. // get unpinned (which may fail because the recycler is shutting down)
  919. scriptContext->Close(true);
  920. scriptContext->ClearGlobalObject();
  921. }
  922. else
  923. {
  924. Assert(scriptContext->IsClosed());
  925. }
  926. HeapDelete(scriptContext);
  927. scriptContext = nullptr;
  928. }
  929. }
  930. JavascriptEnumerator * JavascriptLibrary::GetNullEnumerator() const
  931. {
  932. return nullEnumerator;
  933. }
  934. #define ADD_TYPEDARRAY_CONSTRUCTOR(typedarrayConstructor, TypedArray) \
  935. typedarrayConstructor = CreateBuiltinConstructor(&TypedArray##::EntryInfo::NewInstance, \
  936. DeferredTypeHandler<Initialize##TypedArray##Constructor>::GetDefaultInstance()); \
  937. AddFunction(globalObject, PropertyIds::TypedArray, typedarrayConstructor); \
  938. void JavascriptLibrary::InitializeGlobal(GlobalObject * globalObject)
  939. {
  940. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  941. // WARNING: Any objects here using DeferredTypeHandler need to appear in EnsureLibraryReadyForHybridDebugging
  942. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  943. RecyclableObject* globalObjectPrototype = GetObjectPrototype();
  944. globalObject->SetPrototype(globalObjectPrototype);
  945. Recycler * recycler = this->GetRecycler();
  946. pi = JavascriptNumber::New(Math::PI, scriptContext);
  947. nan = JavascriptNumber::New(JavascriptNumber::NaN, scriptContext);
  948. negativeInfinite = JavascriptNumber::New(JavascriptNumber::NEGATIVE_INFINITY, scriptContext);
  949. positiveInfinite = JavascriptNumber::New(JavascriptNumber::POSITIVE_INFINITY, scriptContext);
  950. minValue = JavascriptNumber::New(JavascriptNumber::MIN_VALUE, scriptContext);
  951. maxValue = JavascriptNumber::New(JavascriptNumber::MAX_VALUE, scriptContext);
  952. negativeZero = JavascriptNumber::New(JavascriptNumber::NEG_ZERO, scriptContext);
  953. undefinedValue = RecyclerNew(recycler, RecyclableObject,
  954. StaticType::New(scriptContext, TypeIds_Undefined, nullValue, nullptr));
  955. missingPropertyHolder = RecyclerNewPlus(recycler, sizeof(Var), DynamicObject,
  956. DynamicType::New(scriptContext, TypeIds_Object, nullValue, nullptr, &MissingPropertyHolderTypeHandler));
  957. MissingPropertyTypeHandler::SetUndefinedPropertySlot(missingPropertyHolder);
  958. emptyString = CreateEmptyString(); // Must be created before other calls to CreateString
  959. nullString = CreateEmptyString(); // Must be distinct from emptyString (for the DOM)
  960. quotesString = CreateStringFromCppLiteral(L"\"\"");
  961. whackString = CreateStringFromCppLiteral(L"/");
  962. undefinedDisplayString = CreateStringFromCppLiteral(L"undefined");
  963. nanDisplayString = CreateStringFromCppLiteral(L"NaN");
  964. nullDisplayString = CreateStringFromCppLiteral(L"null");
  965. unknownDisplayString = CreateStringFromCppLiteral(L"unknown");
  966. commaDisplayString = CreateStringFromCppLiteral(L",");
  967. commaSpaceDisplayString = CreateStringFromCppLiteral(L", ");
  968. trueDisplayString = CreateStringFromCppLiteral(L"true");
  969. falseDisplayString = CreateStringFromCppLiteral(L"false");
  970. lengthDisplayString = CreateStringFromCppLiteral(L"length");
  971. objectDisplayString = CreateStringFromCppLiteral(L"[object Object]");
  972. errorDisplayString = CreateStringFromCppLiteral(L"[object Error]");
  973. stringTypeDisplayString = CreateStringFromCppLiteral(L"string");
  974. functionPrefixString = CreateStringFromCppLiteral(L"function ");
  975. generatorFunctionPrefixString = CreateStringFromCppLiteral(L"function* ");
  976. functionDisplayString = CreateStringFromCppLiteral(JS_DISPLAY_STRING_FUNCTION_ANONYMOUS);
  977. xDomainFunctionDisplayString = CreateStringFromCppLiteral(L"\012function anonymous() {\012 [x-domain code]\012}\012");
  978. invalidDateString = CreateStringFromCppLiteral(L"Invalid Date");
  979. objectTypeDisplayString = CreateStringFromCppLiteral(L"object");
  980. functionTypeDisplayString = CreateStringFromCppLiteral(L"function");
  981. booleanTypeDisplayString = CreateStringFromCppLiteral(L"boolean");
  982. numberTypeDisplayString = CreateStringFromCppLiteral(L"number");
  983. promiseResolveFunction = nullptr;
  984. if (GetScriptContext()->GetConfig()->IsSimdjsEnabled())
  985. {
  986. simdFloat32x4DisplayString = CreateStringFromCppLiteral(L"Float32x4");
  987. simdFloat64x2DisplayString = CreateStringFromCppLiteral(L"Float64x2");
  988. simdInt32x4DisplayString = CreateStringFromCppLiteral(L"Int32x4");
  989. }
  990. if (scriptContext->GetConfig()->IsES6SymbolEnabled())
  991. {
  992. symbolTypeDisplayString = CreateStringFromCppLiteral(L"symbol");
  993. symbolHasInstance = CreateSymbol(BuiltInPropertyRecords::_symbolHasInstance);
  994. symbolIsConcatSpreadable = CreateSymbol(BuiltInPropertyRecords::_symbolIsConcatSpreadable);
  995. symbolIterator = CreateSymbol(BuiltInPropertyRecords::_symbolIterator);
  996. symbolSpecies = CreateSymbol(BuiltInPropertyRecords::_symbolSpecies);
  997. symbolToPrimitive = CreateSymbol(BuiltInPropertyRecords::_symbolToPrimitive);
  998. symbolToStringTag = CreateSymbol(BuiltInPropertyRecords::_symbolToStringTag);
  999. symbolUnscopables = CreateSymbol(BuiltInPropertyRecords::_symbolUnscopables);
  1000. }
  1001. else
  1002. {
  1003. symbolTypeDisplayString = nullptr;
  1004. symbolHasInstance = nullptr;
  1005. symbolIsConcatSpreadable = nullptr;
  1006. symbolIterator = nullptr;
  1007. symbolSpecies = nullptr;
  1008. symbolToPrimitive = nullptr;
  1009. symbolToStringTag = nullptr;
  1010. symbolUnscopables = nullptr;
  1011. }
  1012. debuggerDeadZoneBlockVariableString = CreateStringFromCppLiteral(L"[Uninitialized block variable]");
  1013. defaultAccessorFunction = CreateNonProfiledFunction(&JavascriptOperators::EntryInfo::DefaultAccessor);
  1014. if (scriptContext->GetConfig()->IsErrorStackTraceEnabled())
  1015. {
  1016. stackTraceAccessorFunction = CreateNonProfiledFunction(&JavascriptExceptionOperators::EntryInfo::StackTraceAccessor);
  1017. stackTraceAccessorFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone, nullptr);
  1018. }
  1019. throwTypeErrorAccessorFunction = CreateNonProfiledFunction(&JavascriptExceptionOperators::EntryInfo::ThrowTypeErrorAccessor);
  1020. throwTypeErrorAccessorFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone, nullptr);
  1021. throwTypeErrorCallerAccessorFunction = CreateNonProfiledFunction(&JavascriptExceptionOperators::EntryInfo::ThrowTypeErrorCallerAccessor);
  1022. throwTypeErrorCallerAccessorFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone, nullptr);
  1023. throwTypeErrorCalleeAccessorFunction = CreateNonProfiledFunction(&JavascriptExceptionOperators::EntryInfo::ThrowTypeErrorCalleeAccessor);
  1024. throwTypeErrorCalleeAccessorFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone, nullptr);
  1025. throwTypeErrorArgumentsAccessorFunction = CreateNonProfiledFunction(&JavascriptExceptionOperators::EntryInfo::ThrowTypeErrorArgumentsAccessor);
  1026. throwTypeErrorArgumentsAccessorFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone, nullptr);
  1027. if (scriptContext->GetConfig()->Is__proto__Enabled())
  1028. {
  1029. __proto__getterFunction = CreateNonProfiledFunction(&ObjectPrototypeObject::EntryInfo::__proto__getter);
  1030. __proto__getterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone, nullptr);
  1031. __proto__setterFunction = CreateNonProfiledFunction(&ObjectPrototypeObject::EntryInfo::__proto__setter);
  1032. __proto__setterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone, nullptr);
  1033. }
  1034. if (scriptContext->GetConfig()->IsES6PromiseEnabled())
  1035. {
  1036. identityFunction = CreateNonProfiledFunction(&JavascriptPromise::EntryInfo::Identity);
  1037. identityFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone, nullptr);
  1038. throwerFunction = CreateNonProfiledFunction(&JavascriptPromise::EntryInfo::Thrower);
  1039. throwerFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone, nullptr);
  1040. }
  1041. booleanTrue = RecyclerNew(recycler, JavascriptBoolean, true, booleanTypeStatic);
  1042. booleanFalse = RecyclerNew(recycler, JavascriptBoolean, false, booleanTypeStatic);
  1043. randSeed = 0;
  1044. AddMember(globalObject, PropertyIds::NaN, nan, PropertyNone);
  1045. AddMember(globalObject, PropertyIds::Infinity, positiveInfinite, PropertyNone);
  1046. AddMember(globalObject, PropertyIds::undefined, undefinedValue, PropertyNone);
  1047. // Note: Any global function added/removed/changed here should also be updated in JavascriptLibrary::ProfilerRegisterBuiltinFunctions
  1048. // so that the new functions show up in the profiler too.
  1049. JavascriptFunction ** builtinFuncs = this->GetBuiltinFunctions();
  1050. evalFunctionObject = AddFunctionToLibraryObject(globalObject, PropertyIds::eval, &GlobalObject::EntryInfo::Eval, 1);
  1051. parseIntFunctionObject = AddFunctionToLibraryObject(globalObject, PropertyIds::parseInt, &GlobalObject::EntryInfo::ParseInt, 2);
  1052. builtinFuncs[BuiltinFunction::GlobalObject_ParseInt] = parseIntFunctionObject;
  1053. parseFloatFunctionObject = AddFunctionToLibraryObject(globalObject, PropertyIds::parseFloat, &GlobalObject::EntryInfo::ParseFloat, 1);
  1054. AddFunctionToLibraryObject(globalObject, PropertyIds::isNaN, &GlobalObject::EntryInfo::IsNaN, 1);
  1055. AddFunctionToLibraryObject(globalObject, PropertyIds::isFinite, &GlobalObject::EntryInfo::IsFinite, 1);
  1056. AddFunctionToLibraryObject(globalObject, PropertyIds::decodeURI, &GlobalObject::EntryInfo::DecodeURI, 1);
  1057. AddFunctionToLibraryObject(globalObject, PropertyIds::decodeURIComponent, &GlobalObject::EntryInfo::DecodeURIComponent, 1);
  1058. AddFunctionToLibraryObject(globalObject, PropertyIds::encodeURI, &GlobalObject::EntryInfo::EncodeURI, 1);
  1059. AddFunctionToLibraryObject(globalObject, PropertyIds::encodeURIComponent, &GlobalObject::EntryInfo::EncodeURIComponent, 1);
  1060. AddFunctionToLibraryObject(globalObject, PropertyIds::escape, &GlobalObject::EntryInfo::Escape, 1);
  1061. AddFunctionToLibraryObject(globalObject, PropertyIds::unescape, &GlobalObject::EntryInfo::UnEscape, 1);
  1062. if (scriptContext->GetConfig()->SupportsCollectGarbage())
  1063. {
  1064. AddFunctionToLibraryObject(globalObject, PropertyIds::CollectGarbage, &GlobalObject::EntryInfo::CollectGarbage, 0);
  1065. }
  1066. #ifdef IR_VIEWER
  1067. if (Js::Configuration::Global.flags.IsEnabled(Js::IRViewerFlag))
  1068. {
  1069. AddFunctionToLibraryObjectWithPropertyName(globalObject, L"parseIR", &GlobalObject::EntryInfo::ParseIR, 1);
  1070. AddFunctionToLibraryObjectWithPropertyName(globalObject, L"functionList", &GlobalObject::EntryInfo::FunctionList, 1);
  1071. AddFunctionToLibraryObjectWithPropertyName(globalObject, L"rejitFunction", &GlobalObject::EntryInfo::RejitFunction, 2);
  1072. }
  1073. #endif /* IR_VIEWER */
  1074. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  1075. builtInConstructorCache = RecyclerNew(this->GetRecycler(), ConstructorCache);
  1076. builtInConstructorCache->PopulateForSkipDefaultNewObject(this->GetScriptContext());
  1077. objectConstructor = CreateBuiltinConstructor(&JavascriptObject::EntryInfo::NewInstance,
  1078. DeferredTypeHandler<InitializeObjectConstructor>::GetDefaultInstance());
  1079. AddFunction(globalObject, PropertyIds::Object, objectConstructor);
  1080. arrayConstructor = CreateBuiltinConstructor(&JavascriptArray::EntryInfo::NewInstance,
  1081. DeferredTypeHandler<InitializeArrayConstructor>::GetDefaultInstance());
  1082. SetArrayObjectHasUserDefinedSpecies(false);
  1083. AddFunction(globalObject, PropertyIds::Array, arrayConstructor);
  1084. booleanConstructor = CreateBuiltinConstructor(&JavascriptBoolean::EntryInfo::NewInstance,
  1085. DeferredTypeHandler<InitializeBooleanConstructor>::GetDefaultInstance());
  1086. AddFunction(globalObject, PropertyIds::Boolean, booleanConstructor);
  1087. symbolConstructor = nullptr;
  1088. proxyConstructor = nullptr;
  1089. promiseConstructor = nullptr;
  1090. reflectObject = nullptr;
  1091. if (scriptContext->GetConfig()->IsES6SymbolEnabled())
  1092. {
  1093. symbolConstructor = CreateBuiltinConstructor(&JavascriptSymbol::EntryInfo::NewInstance,
  1094. DeferredTypeHandler<InitializeSymbolConstructor>::GetDefaultInstance());
  1095. AddFunction(globalObject, PropertyIds::Symbol, symbolConstructor);
  1096. }
  1097. if (scriptContext->GetConfig()->IsES6ProxyEnabled())
  1098. {
  1099. proxyConstructor = CreateBuiltinConstructor(&JavascriptProxy::EntryInfo::NewInstance,
  1100. DeferredTypeHandler<InitializeProxyConstructor>::GetDefaultInstance());
  1101. AddFunction(globalObject, PropertyIds::Proxy, proxyConstructor);
  1102. reflectObject = DynamicObject::New(recycler,
  1103. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1104. DeferredTypeHandler<InitializeReflectObject>::GetDefaultInstance()));
  1105. AddMember(globalObject, PropertyIds::Reflect, reflectObject);
  1106. }
  1107. if (scriptContext->GetConfig()->IsES6PromiseEnabled())
  1108. {
  1109. promiseConstructor = CreateBuiltinConstructor(&JavascriptPromise::EntryInfo::NewInstance,
  1110. DeferredTypeHandler<InitializePromiseConstructor>::GetDefaultInstance());
  1111. AddFunction(globalObject, PropertyIds::Promise, promiseConstructor);
  1112. }
  1113. dateConstructor = CreateBuiltinConstructor(&JavascriptDate::EntryInfo::NewInstance,
  1114. DeferredTypeHandler<InitializeDateConstructor>::GetDefaultInstance());
  1115. AddFunction(globalObject, PropertyIds::Date, dateConstructor);
  1116. functionConstructor = CreateBuiltinConstructor(&JavascriptFunction::EntryInfo::NewInstance,
  1117. DeferredTypeHandler<InitializeFunctionConstructor>::GetDefaultInstance());
  1118. AddFunction(globalObject, PropertyIds::Function, functionConstructor);
  1119. mathObject = DynamicObject::New(recycler,
  1120. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1121. DeferredTypeHandler<InitializeMathObject>::GetDefaultInstance()));
  1122. AddMember(globalObject, PropertyIds::Math, mathObject);
  1123. #if ENABLE_NATIVE_CODEGEN
  1124. // SIMD_JS
  1125. // we declare global objects and lib functions only if SSE2 is available. Else, we use the polyfill.
  1126. if (AutoSystemInfo::Data.SSE2Available() && GetScriptContext()->GetConfig()->IsSimdjsEnabled())
  1127. {
  1128. simdObject = DynamicObject::New(recycler,
  1129. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1130. DeferredTypeHandler<InitializeSIMDObject>::GetDefaultInstance()));
  1131. AddMember(globalObject, PropertyIds::SIMD, simdObject, PropertyNone);
  1132. // Initialize toString functions. Do it here instead of InitializeSIMDObject, since we can possible access those fields before SIMD object is deferred initialized (e.g. SIMD object coming from ASMJS code).
  1133. simdFloat32x4ToStringFunction = DefaultCreateFunction(&JavascriptSIMDFloat32x4::EntryInfo::ToString, 1, nullptr, nullptr, PropertyIds::toString);
  1134. simdFloat64x2ToStringFunction = DefaultCreateFunction(&JavascriptSIMDFloat64x2::EntryInfo::ToString, 1, nullptr, nullptr, PropertyIds::toString);
  1135. simdInt32x4ToStringFunction = DefaultCreateFunction(&JavascriptSIMDInt32x4::EntryInfo::ToString, 1, nullptr, nullptr, PropertyIds::toString);
  1136. simdInt8x16ToStringFunction = DefaultCreateFunction(&JavascriptSIMDInt8x16::EntryInfo::ToString, 1, nullptr, nullptr, PropertyIds::toString);
  1137. }
  1138. #endif
  1139. debugObject = nullptr;
  1140. numberConstructor = CreateBuiltinConstructor(&JavascriptNumber::EntryInfo::NewInstance,
  1141. DeferredTypeHandler<InitializeNumberConstructor>::GetDefaultInstance());
  1142. AddFunction(globalObject, PropertyIds::Number, numberConstructor);
  1143. stringConstructor = CreateBuiltinConstructor(&JavascriptString::EntryInfo::NewInstance,
  1144. DeferredTypeHandler<InitializeStringConstructor>::GetDefaultInstance());
  1145. AddFunction(globalObject, PropertyIds::String, stringConstructor);
  1146. regexConstructorType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, JavascriptRegExp::NewInstance,
  1147. DeferredTypeHandler<InitializeRegexConstructor>::GetDefaultInstance());
  1148. regexConstructor = RecyclerNewEnumClass(recycler, EnumFunctionClass, JavascriptRegExpConstructor, regexConstructorType);
  1149. AddFunction(globalObject, PropertyIds::RegExp, regexConstructor);
  1150. if (scriptContext->GetConfig()->IsTypedArrayEnabled())
  1151. {
  1152. arrayBufferConstructor = CreateBuiltinConstructor(&ArrayBuffer::EntryInfo::NewInstance,
  1153. DeferredTypeHandler<InitializeArrayBufferConstructor>::GetDefaultInstance());
  1154. AddFunction(globalObject, PropertyIds::ArrayBuffer, arrayBufferConstructor);
  1155. dataViewConstructor = CreateBuiltinConstructor(&DataView::EntryInfo::NewInstance,
  1156. DeferredTypeHandler<InitializeDataViewConstructor>::GetDefaultInstance());
  1157. AddFunction(globalObject, PropertyIds::DataView, dataViewConstructor);
  1158. if (scriptContext->GetConfig()->IsES6TypedArrayExtensionsEnabled())
  1159. {
  1160. typedArrayConstructor = CreateBuiltinConstructor(&TypedArrayBase::EntryInfo::NewInstance,
  1161. DeferredTypeHandler<InitializeTypedArrayConstructor>::GetDefaultInstance(),
  1162. functionPrototype);
  1163. Int8ArrayConstructor = CreateBuiltinConstructor(&Int8Array::EntryInfo::NewInstance,
  1164. DeferredTypeHandler<InitializeInt8ArrayConstructor>::GetDefaultInstance(),
  1165. typedArrayConstructor);
  1166. AddFunction(globalObject, PropertyIds::Int8Array, Int8ArrayConstructor);
  1167. Uint8ArrayConstructor = CreateBuiltinConstructor(&Uint8Array::EntryInfo::NewInstance,
  1168. DeferredTypeHandler<InitializeUint8ArrayConstructor>::GetDefaultInstance(),
  1169. typedArrayConstructor);
  1170. AddFunction(globalObject, PropertyIds::Uint8Array, Uint8ArrayConstructor);
  1171. Uint8ClampedArrayConstructor = CreateBuiltinConstructor(&Uint8ClampedArray::EntryInfo::NewInstance,
  1172. DeferredTypeHandler<InitializeUint8ClampedArrayConstructor>::GetDefaultInstance(),
  1173. typedArrayConstructor);
  1174. AddFunction(globalObject, PropertyIds::Uint8ClampedArray, Uint8ClampedArrayConstructor);
  1175. Int16ArrayConstructor = CreateBuiltinConstructor(&Int16Array::EntryInfo::NewInstance,
  1176. DeferredTypeHandler<InitializeInt16ArrayConstructor>::GetDefaultInstance(),
  1177. typedArrayConstructor);
  1178. AddFunction(globalObject, PropertyIds::Int16Array, Int16ArrayConstructor);
  1179. Uint16ArrayConstructor = CreateBuiltinConstructor(&Uint16Array::EntryInfo::NewInstance,
  1180. DeferredTypeHandler<InitializeUint16ArrayConstructor>::GetDefaultInstance(),
  1181. typedArrayConstructor);
  1182. AddFunction(globalObject, PropertyIds::Uint16Array, Uint16ArrayConstructor);
  1183. Int32ArrayConstructor = CreateBuiltinConstructor(&Int32Array::EntryInfo::NewInstance,
  1184. DeferredTypeHandler<InitializeInt32ArrayConstructor>::GetDefaultInstance(),
  1185. typedArrayConstructor);
  1186. AddFunction(globalObject, PropertyIds::Int32Array, Int32ArrayConstructor);
  1187. Uint32ArrayConstructor = CreateBuiltinConstructor(&Uint32Array::EntryInfo::NewInstance,
  1188. DeferredTypeHandler<InitializeUint32ArrayConstructor>::GetDefaultInstance(),
  1189. typedArrayConstructor);
  1190. AddFunction(globalObject, PropertyIds::Uint32Array, Uint32ArrayConstructor);
  1191. Float32ArrayConstructor = CreateBuiltinConstructor(&Float32Array::EntryInfo::NewInstance,
  1192. DeferredTypeHandler<InitializeFloat32ArrayConstructor>::GetDefaultInstance(),
  1193. typedArrayConstructor);
  1194. AddFunction(globalObject, PropertyIds::Float32Array, Float32ArrayConstructor);
  1195. Float64ArrayConstructor = CreateBuiltinConstructor(&Float64Array::EntryInfo::NewInstance,
  1196. DeferredTypeHandler<InitializeFloat64ArrayConstructor>::GetDefaultInstance(),
  1197. typedArrayConstructor);
  1198. AddFunction(globalObject, PropertyIds::Float64Array, Float64ArrayConstructor);
  1199. }
  1200. else
  1201. {
  1202. ADD_TYPEDARRAY_CONSTRUCTOR(Int8ArrayConstructor, Int8Array);
  1203. ADD_TYPEDARRAY_CONSTRUCTOR(Uint8ArrayConstructor, Uint8Array);
  1204. ADD_TYPEDARRAY_CONSTRUCTOR(Uint8ClampedArrayConstructor, Uint8ClampedArray);
  1205. ADD_TYPEDARRAY_CONSTRUCTOR(Int16ArrayConstructor, Int16Array);
  1206. ADD_TYPEDARRAY_CONSTRUCTOR(Uint16ArrayConstructor, Uint16Array);
  1207. ADD_TYPEDARRAY_CONSTRUCTOR(Int32ArrayConstructor, Int32Array);
  1208. ADD_TYPEDARRAY_CONSTRUCTOR(Uint32ArrayConstructor, Uint32Array);
  1209. ADD_TYPEDARRAY_CONSTRUCTOR(Float32ArrayConstructor, Float32Array);
  1210. ADD_TYPEDARRAY_CONSTRUCTOR(Float64ArrayConstructor, Float64Array);
  1211. }
  1212. }
  1213. else
  1214. {
  1215. arrayBufferConstructor = nullptr;
  1216. Int8ArrayConstructor = nullptr;
  1217. Uint8ArrayConstructor = nullptr;
  1218. Uint8ClampedArrayConstructor = nullptr;
  1219. Int16ArrayConstructor = nullptr;
  1220. Uint16ArrayConstructor = nullptr;
  1221. Int32ArrayConstructor = nullptr;
  1222. Uint32ArrayConstructor = nullptr;
  1223. Float32ArrayConstructor = nullptr;
  1224. Float64ArrayConstructor = nullptr;
  1225. dataViewConstructor = nullptr;
  1226. }
  1227. JSONObject = DynamicObject::New(recycler,
  1228. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1229. DeferredTypeHandler<InitializeJSONObject>::GetDefaultInstance()));
  1230. AddMember(globalObject, PropertyIds::JSON, JSONObject);
  1231. #ifdef ENABLE_INTL_OBJECT
  1232. if (scriptContext->GetConfig()->IsIntlEnabled())
  1233. {
  1234. IntlObject = DynamicObject::New(recycler,
  1235. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  1236. DeferredTypeHandler<InitializeIntlObject>::GetDefaultInstance()));
  1237. AddMember(globalObject, PropertyIds::Intl, IntlObject);
  1238. }
  1239. else
  1240. {
  1241. IntlObject = nullptr;
  1242. }
  1243. #endif
  1244. #if defined(ENABLE_INTL_OBJECT) || defined(ENABLE_PROJECTION)
  1245. engineInterfaceObject = EngineInterfaceObject::New(recycler,
  1246. DynamicType::New(scriptContext, TypeIds_EngineInterfaceObject, objectPrototype, nullptr,
  1247. DeferredTypeHandler<InitializeEngineInterfaceObject>::GetDefaultInstance()));
  1248. #ifdef ENABLE_INTL_OBJECT
  1249. IntlEngineInterfaceExtensionObject* intlExtension = RecyclerNew(recycler, IntlEngineInterfaceExtensionObject, scriptContext);
  1250. engineInterfaceObject->SetEngineExtension(EngineInterfaceExtensionKind_Intl, intlExtension);
  1251. #endif
  1252. #endif
  1253. mapConstructor = nullptr;
  1254. setConstructor = nullptr;
  1255. weakMapConstructor = nullptr;
  1256. weakSetConstructor = nullptr;
  1257. generatorFunctionConstructor = nullptr;
  1258. if (scriptContext->GetConfig()->IsES6MapEnabled())
  1259. {
  1260. mapConstructor = CreateBuiltinConstructor(&JavascriptMap::EntryInfo::NewInstance,
  1261. DeferredTypeHandler<InitializeMapConstructor>::GetDefaultInstance());
  1262. AddFunction(globalObject, PropertyIds::Map, mapConstructor);
  1263. }
  1264. if (scriptContext->GetConfig()->IsES6SetEnabled())
  1265. {
  1266. setConstructor = CreateBuiltinConstructor(&JavascriptSet::EntryInfo::NewInstance,
  1267. DeferredTypeHandler<InitializeSetConstructor>::GetDefaultInstance());
  1268. AddFunction(globalObject, PropertyIds::Set, setConstructor);
  1269. }
  1270. if (scriptContext->GetConfig()->IsES6WeakMapEnabled())
  1271. {
  1272. weakMapConstructor = CreateBuiltinConstructor(&JavascriptWeakMap::EntryInfo::NewInstance,
  1273. DeferredTypeHandler<InitializeWeakMapConstructor>::GetDefaultInstance());
  1274. AddFunction(globalObject, PropertyIds::WeakMap, weakMapConstructor);
  1275. }
  1276. if (scriptContext->GetConfig()->IsES6WeakSetEnabled())
  1277. {
  1278. weakSetConstructor = CreateBuiltinConstructor(&JavascriptWeakSet::EntryInfo::NewInstance,
  1279. DeferredTypeHandler<InitializeWeakSetConstructor>::GetDefaultInstance());
  1280. AddFunction(globalObject, PropertyIds::WeakSet, weakSetConstructor);
  1281. }
  1282. if (scriptContext->GetConfig()->IsES6GeneratorsEnabled())
  1283. {
  1284. generatorFunctionConstructor = CreateBuiltinConstructor(&JavascriptGeneratorFunction::EntryInfo::NewInstance,
  1285. DeferredTypeHandler<InitializeGeneratorFunctionConstructor>::GetDefaultInstance(),
  1286. functionConstructor);
  1287. // GeneratorFunction is not a global property by ES6 spec so don't add it to the global object
  1288. }
  1289. errorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewErrorInstance,
  1290. DeferredTypeHandler<InitializeErrorConstructor>::GetDefaultInstance());
  1291. AddFunction(globalObject, PropertyIds::Error, errorConstructor);
  1292. RuntimeFunction* nativeErrorPrototype = nullptr;
  1293. if (scriptContext->GetConfig()->IsES6PrototypeChain())
  1294. {
  1295. nativeErrorPrototype = errorConstructor;
  1296. }
  1297. evalErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewEvalErrorInstance,
  1298. DeferredTypeHandler<InitializeEvalErrorConstructor>::GetDefaultInstance(),
  1299. nativeErrorPrototype);
  1300. AddFunction(globalObject, PropertyIds::EvalError, evalErrorConstructor);
  1301. rangeErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewRangeErrorInstance,
  1302. DeferredTypeHandler<InitializeRangeErrorConstructor>::GetDefaultInstance(),
  1303. nativeErrorPrototype);
  1304. AddFunction(globalObject, PropertyIds::RangeError, rangeErrorConstructor);
  1305. referenceErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewReferenceErrorInstance,
  1306. DeferredTypeHandler<InitializeReferenceErrorConstructor>::GetDefaultInstance(),
  1307. nativeErrorPrototype);
  1308. AddFunction(globalObject, PropertyIds::ReferenceError, referenceErrorConstructor);
  1309. syntaxErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewSyntaxErrorInstance,
  1310. DeferredTypeHandler<InitializeSyntaxErrorConstructor>::GetDefaultInstance(),
  1311. nativeErrorPrototype);
  1312. AddFunction(globalObject, PropertyIds::SyntaxError, syntaxErrorConstructor);
  1313. typeErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewTypeErrorInstance,
  1314. DeferredTypeHandler<InitializeTypeErrorConstructor>::GetDefaultInstance(),
  1315. nativeErrorPrototype);
  1316. AddFunction(globalObject, PropertyIds::TypeError, typeErrorConstructor);
  1317. uriErrorConstructor = CreateBuiltinConstructor(&JavascriptError::EntryInfo::NewURIErrorInstance,
  1318. DeferredTypeHandler<InitializeURIErrorConstructor>::GetDefaultInstance(),
  1319. nativeErrorPrototype);
  1320. AddFunction(globalObject, PropertyIds::URIError, uriErrorConstructor);
  1321. nullEnumerator = RecyclerNew(this->recycler, NullEnumerator, scriptContext);
  1322. }
  1323. void JavascriptLibrary::EnsureDebugObject(DynamicObject* newDebugObject)
  1324. {
  1325. Assert(!debugObject);
  1326. if (!debugObject)
  1327. {
  1328. this->debugObject = newDebugObject;
  1329. AddMember(globalObject, PropertyIds::Debug, debugObject);
  1330. }
  1331. }
  1332. void JavascriptLibrary::SetDebugObjectNonUserAccessor(FunctionInfo *funcGetter, FunctionInfo *funcSetter)
  1333. {
  1334. Assert(funcGetter);
  1335. Assert(funcSetter);
  1336. debugObjectNonUserGetterFunction = CreateNonProfiledFunction(funcGetter);
  1337. debugObjectNonUserGetterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone, nullptr);
  1338. debugObjectNonUserSetterFunction = CreateNonProfiledFunction(funcSetter);
  1339. debugObjectNonUserSetterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone, nullptr);
  1340. }
  1341. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  1342. void JavascriptLibrary::SetDebugObjectFaultInjectionCookieGetterAccessor(FunctionInfo *funcGetter, FunctionInfo *funcSetter)
  1343. {
  1344. Assert(funcGetter);
  1345. Assert(funcSetter);
  1346. debugObjectFaultInjectionCookieGetterFunction = CreateNonProfiledFunction(funcGetter);
  1347. debugObjectFaultInjectionCookieGetterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone, nullptr);
  1348. debugObjectFaultInjectionCookieSetterFunction = CreateNonProfiledFunction(funcSetter);
  1349. debugObjectFaultInjectionCookieSetterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone, nullptr);
  1350. }
  1351. #endif
  1352. void JavascriptLibrary::SetDebugObjectDebugModeAccessor(FunctionInfo *funcGetter)
  1353. {
  1354. Assert(funcGetter);
  1355. debugObjectDebugModeGetterFunction = CreateNonProfiledFunction(funcGetter);
  1356. debugObjectDebugModeGetterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone, nullptr);
  1357. }
  1358. void JavascriptLibrary::InitializeArrayConstructor(DynamicObject* arrayConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1359. {
  1360. typeHandler->Convert(arrayConstructor, mode, 6);
  1361. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterArray
  1362. // so that the update is in sync with profiler
  1363. ScriptContext* scriptContext = arrayConstructor->GetScriptContext();
  1364. JavascriptLibrary* library = arrayConstructor->GetLibrary();
  1365. JavascriptFunction ** builtinFuncs = library->GetBuiltinFunctions();
  1366. library->AddMember(arrayConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone);
  1367. library->AddMember(arrayConstructor, PropertyIds::prototype, scriptContext->GetLibrary()->arrayPrototype, PropertyNone);
  1368. if (scriptContext->GetConfig()->IsES6SpeciesEnabled())
  1369. {
  1370. library->AddAccessorsToLibraryObject(arrayConstructor, PropertyIds::_symbolSpecies, &JavascriptArray::EntryInfo::GetterSymbolSpecies, nullptr);
  1371. }
  1372. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1373. {
  1374. library->AddMember(arrayConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Array), PropertyConfigurable);
  1375. }
  1376. builtinFuncs[BuiltinFunction::Array_IsArray] = library->AddFunctionToLibraryObject(arrayConstructor, PropertyIds::isArray, &JavascriptArray::EntryInfo::IsArray, 1);
  1377. // Array.from and Array.of are implemented as part of the ES6 TypedArray feature
  1378. if (scriptContext->GetConfig()->IsES6TypedArrayExtensionsEnabled())
  1379. {
  1380. library->AddFunctionToLibraryObject(arrayConstructor, PropertyIds::from, &JavascriptArray::EntryInfo::From, 1);
  1381. library->AddFunctionToLibraryObject(arrayConstructor, PropertyIds::of, &JavascriptArray::EntryInfo::Of, 0);
  1382. }
  1383. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  1384. arrayConstructor->SetHasNoEnumerableProperties(true);
  1385. }
  1386. void JavascriptLibrary::InitializeArrayPrototype(DynamicObject* arrayPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1387. {
  1388. typeHandler->Convert(arrayPrototype, mode, 24);
  1389. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterArray
  1390. // so that the update is in sync with profiler
  1391. ScriptContext* scriptContext = arrayPrototype->GetScriptContext();
  1392. JavascriptLibrary* library = arrayPrototype->GetLibrary();
  1393. library->AddMember(arrayPrototype, PropertyIds::constructor, library->arrayConstructor);
  1394. JavascriptFunction ** builtinFuncs = library->GetBuiltinFunctions();
  1395. builtinFuncs[BuiltinFunction::Array_Push] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::push, &JavascriptArray::EntryInfo::Push, 1);
  1396. builtinFuncs[BuiltinFunction::Array_Concat] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::concat, &JavascriptArray::EntryInfo::Concat, 1);
  1397. builtinFuncs[BuiltinFunction::Array_Join] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::join, &JavascriptArray::EntryInfo::Join, 1);
  1398. builtinFuncs[BuiltinFunction::Array_Pop] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::pop, &JavascriptArray::EntryInfo::Pop, 0);
  1399. builtinFuncs[BuiltinFunction::Array_Reverse] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reverse, &JavascriptArray::EntryInfo::Reverse, 0);
  1400. builtinFuncs[BuiltinFunction::Array_Shift] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::shift, &JavascriptArray::EntryInfo::Shift, 0);
  1401. builtinFuncs[BuiltinFunction::Array_Slice] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::slice, &JavascriptArray::EntryInfo::Slice, 2);
  1402. /* No inlining Array_Sort */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::sort, &JavascriptArray::EntryInfo::Sort, 1);
  1403. builtinFuncs[BuiltinFunction::Array_Splice] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::splice, &JavascriptArray::EntryInfo::Splice, 2);
  1404. // The toString and toLocaleString properties are shared between Array.prototype and %TypedArray%.prototype.
  1405. // Whichever prototype is initialized first will create the functions, the other should just load the existing function objects.
  1406. if (library->arrayPrototypeToStringFunction == nullptr)
  1407. {
  1408. Assert(library->arrayPrototypeToLocaleStringFunction == nullptr);
  1409. library->arrayPrototypeToLocaleStringFunction = /* No inlining Array_ToLocaleString */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::toLocaleString, &JavascriptArray::EntryInfo::ToLocaleString, 0);
  1410. library->arrayPrototypeToStringFunction = /* No inlining Array_ToString */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::toString, &JavascriptArray::EntryInfo::ToString, 0);
  1411. }
  1412. else
  1413. {
  1414. Assert(library->arrayPrototypeToLocaleStringFunction);
  1415. library->AddMember(arrayPrototype, PropertyIds::toLocaleString, library->arrayPrototypeToLocaleStringFunction);
  1416. library->AddMember(arrayPrototype, PropertyIds::toString, library->arrayPrototypeToStringFunction);
  1417. }
  1418. builtinFuncs[BuiltinFunction::Array_Unshift] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::unshift, &JavascriptArray::EntryInfo::Unshift, 1);
  1419. builtinFuncs[BuiltinFunction::Array_IndexOf] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::indexOf, &JavascriptArray::EntryInfo::IndexOf, 1);
  1420. /* No inlining Array_Every */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::every, &JavascriptArray::EntryInfo::Every, 1);
  1421. /* No inlining Array_Filter */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::filter, &JavascriptArray::EntryInfo::Filter, 1);
  1422. /* No inlining Array_ForEach */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::forEach, &JavascriptArray::EntryInfo::ForEach, 1);
  1423. builtinFuncs[BuiltinFunction::Array_LastIndexOf] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::lastIndexOf, &JavascriptArray::EntryInfo::LastIndexOf, 1);
  1424. /* No inlining Array_Map */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::map, &JavascriptArray::EntryInfo::Map, 1);
  1425. /* No inlining Array_Reduce */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reduce, &JavascriptArray::EntryInfo::Reduce, 1);
  1426. /* No inlining Array_ReduceRight */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reduceRight, &JavascriptArray::EntryInfo::ReduceRight, 1);
  1427. /* No inlining Array_Some */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::some, &JavascriptArray::EntryInfo::Some, 1);
  1428. if (scriptContext->GetConfig()->IsES6StringExtensionsEnabled()) // This is not a typo, Array.prototype.find and .findIndex are part of the ES6 Improved String APIs feature
  1429. {
  1430. /* No inlining Array_Find */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::find, &JavascriptArray::EntryInfo::Find, 1);
  1431. /* No inlining Array_FindIndex */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::findIndex, &JavascriptArray::EntryInfo::FindIndex, 1);
  1432. }
  1433. if (scriptContext->GetConfig()->IsES6IteratorsEnabled())
  1434. {
  1435. /* No inlining Array_Entries */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::entries, &JavascriptArray::EntryInfo::Entries, 0);
  1436. /* No inlining Array_Keys */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::keys, &JavascriptArray::EntryInfo::Keys, 0);
  1437. JavascriptFunction *values = library->arrayPrototypeValuesFunction ? library->arrayPrototypeValuesFunction : /* No inlining Array_Values */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::values, &JavascriptArray::EntryInfo::Values, 0);
  1438. /* No inlining Array_SymbolIterator */ library->AddMember(arrayPrototype, PropertyIds::_symbolIterator, values);
  1439. }
  1440. if (scriptContext->GetConfig()->IsES6UnscopablesEnabled())
  1441. {
  1442. DynamicType* dynamicType = DynamicType::New(scriptContext, TypeIds_Object, library->nullValue, nullptr, NullTypeHandler<false>::GetDefaultInstance(), false);
  1443. DynamicObject* unscopables_blacklist = DynamicObject::New(library->GetRecycler(), dynamicType);
  1444. unscopables_blacklist->SetProperty(PropertyIds::find, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1445. unscopables_blacklist->SetProperty(PropertyIds::findIndex, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1446. unscopables_blacklist->SetProperty(PropertyIds::fill, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1447. unscopables_blacklist->SetProperty(PropertyIds::copyWithin, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1448. unscopables_blacklist->SetProperty(PropertyIds::entries, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1449. unscopables_blacklist->SetProperty(PropertyIds::keys, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1450. unscopables_blacklist->SetProperty(PropertyIds::values, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
  1451. library->AddMember(arrayPrototype, PropertyIds::_symbolUnscopables, unscopables_blacklist, PropertyConfigurable);
  1452. }
  1453. if (scriptContext->GetConfig()->IsES6TypedArrayExtensionsEnabled()) // This is not a typo, Array.prototype.fill and .copyWithin are part of the ES6 TypedArray feature
  1454. {
  1455. /* No inlining Array_Fill */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::fill, &JavascriptArray::EntryInfo::Fill, 1);
  1456. /* No inlining Array_CopyWithin */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::copyWithin, &JavascriptArray::EntryInfo::CopyWithin, 2);
  1457. }
  1458. if (scriptContext->GetConfig()->IsES7BuiltinsEnabled())
  1459. {
  1460. builtinFuncs[BuiltinFunction::Array_Includes] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::includes, &JavascriptArray::EntryInfo::Includes, 1);
  1461. }
  1462. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  1463. arrayPrototype->SetHasNoEnumerableProperties(true);
  1464. }
  1465. void JavascriptLibrary::InitializeArrayBufferConstructor(DynamicObject* arrayBufferConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1466. {
  1467. typeHandler->Convert(arrayBufferConstructor, mode, 4);
  1468. ScriptContext* scriptContext = arrayBufferConstructor->GetScriptContext();
  1469. JavascriptLibrary* library = arrayBufferConstructor->GetLibrary();
  1470. library->AddMember(arrayBufferConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone);
  1471. library->AddMember(arrayBufferConstructor, PropertyIds::prototype, scriptContext->GetLibrary()->arrayBufferPrototype, PropertyNone);
  1472. if (scriptContext->GetConfig()->IsES6SpeciesEnabled())
  1473. {
  1474. library->AddAccessorsToLibraryObject(arrayBufferConstructor, PropertyIds::_symbolSpecies, &ArrayBuffer::EntryInfo::GetterSymbolSpecies, nullptr);
  1475. }
  1476. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1477. {
  1478. library->AddMember(arrayBufferConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::ArrayBuffer), PropertyConfigurable);
  1479. }
  1480. library->AddFunctionToLibraryObject(arrayBufferConstructor, PropertyIds::isView, &ArrayBuffer::EntryInfo::IsView, 1);
  1481. if (scriptContext->GetConfig()->IsArrayBufferTransferEnabled())
  1482. {
  1483. library->AddFunctionToLibraryObject(arrayBufferConstructor, PropertyIds::transfer, &ArrayBuffer::EntryInfo::Transfer, 2);
  1484. }
  1485. arrayBufferConstructor->SetHasNoEnumerableProperties(true);
  1486. }
  1487. void JavascriptLibrary::InitializeArrayBufferPrototype(DynamicObject* arrayBufferPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1488. {
  1489. typeHandler->Convert(arrayBufferPrototype, mode, 2);
  1490. ScriptContext* scriptContext = arrayBufferPrototype->GetScriptContext();
  1491. JavascriptLibrary* library = arrayBufferPrototype->GetLibrary();
  1492. library->AddMember(arrayBufferPrototype, PropertyIds::constructor, library->arrayBufferConstructor);
  1493. library->AddFunctionToLibraryObject(arrayBufferPrototype, PropertyIds::slice, &ArrayBuffer::EntryInfo::Slice, 2);
  1494. if (scriptContext->GetConfig()->IsES6TypedArrayExtensionsEnabled())
  1495. {
  1496. library->AddAccessorsToLibraryObject(arrayBufferPrototype, PropertyIds::byteLength, &ArrayBuffer::EntryInfo::GetterByteLength, nullptr);
  1497. }
  1498. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1499. {
  1500. library->AddMember(arrayBufferPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"ArrayBuffer"), PropertyConfigurable);
  1501. }
  1502. arrayBufferPrototype->SetHasNoEnumerableProperties(true);
  1503. }
  1504. void JavascriptLibrary::InitializeDataViewConstructor(DynamicObject* dataViewConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1505. {
  1506. typeHandler->Convert(dataViewConstructor, mode, 3);
  1507. ScriptContext* scriptContext = dataViewConstructor->GetScriptContext();
  1508. JavascriptLibrary* library = dataViewConstructor->GetLibrary();
  1509. library->AddMember(dataViewConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone);
  1510. library->AddMember(dataViewConstructor, PropertyIds::prototype, scriptContext->GetLibrary()->dataViewPrototype, PropertyNone);
  1511. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1512. {
  1513. library->AddMember(dataViewConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::DataView), PropertyConfigurable);
  1514. }
  1515. dataViewConstructor->SetHasNoEnumerableProperties(true);
  1516. }
  1517. void JavascriptLibrary::InitializeDataViewPrototype(DynamicObject* dataViewPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1518. {
  1519. typeHandler->Convert(dataViewPrototype, mode, 2);
  1520. ScriptContext* scriptContext = dataViewPrototype->GetScriptContext();
  1521. JavascriptLibrary* library = dataViewPrototype->GetLibrary();
  1522. library->AddMember(dataViewPrototype, PropertyIds::constructor, library->dataViewConstructor);
  1523. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setInt8, &DataView::EntryInfo::SetInt8, 1);
  1524. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setUint8, &DataView::EntryInfo::SetUint8, 1);
  1525. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setInt16, &DataView::EntryInfo::SetInt16, 1);
  1526. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setUint16, &DataView::EntryInfo::SetUint16, 1);
  1527. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setInt32, &DataView::EntryInfo::SetInt32, 1);
  1528. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setUint32, &DataView::EntryInfo::SetUint32, 1);
  1529. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setFloat32, &DataView::EntryInfo::SetFloat32, 1);
  1530. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::setFloat64, &DataView::EntryInfo::SetFloat64, 1);
  1531. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getInt8, &DataView::EntryInfo::GetInt8, 1);
  1532. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getUint8, &DataView::EntryInfo::GetUint8, 1);
  1533. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getInt16, &DataView::EntryInfo::GetInt16, 1);
  1534. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getUint16, &DataView::EntryInfo::GetUint16, 1);
  1535. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getInt32, &DataView::EntryInfo::GetInt32, 1);
  1536. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getUint32, &DataView::EntryInfo::GetUint32, 1);
  1537. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getFloat32, &DataView::EntryInfo::GetFloat32, 1);
  1538. library->AddFunctionToLibraryObject(dataViewPrototype, PropertyIds::getFloat64, &DataView::EntryInfo::GetFloat64, 1);
  1539. library->AddAccessorsToLibraryObject(dataViewPrototype, PropertyIds::buffer, &DataView::EntryInfo::GetterBuffer, nullptr);
  1540. library->AddAccessorsToLibraryObject(dataViewPrototype, PropertyIds::byteLength, &DataView::EntryInfo::GetterByteLength, nullptr);
  1541. library->AddAccessorsToLibraryObject(dataViewPrototype, PropertyIds::byteOffset, &DataView::EntryInfo::GetterByteOffset, nullptr);
  1542. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1543. {
  1544. library->AddMember(dataViewPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"DataView"), PropertyConfigurable);
  1545. }
  1546. dataViewPrototype->SetHasNoEnumerableProperties(true);
  1547. }
  1548. void JavascriptLibrary::InitializeTypedArrayConstructor(DynamicObject* typedArrayConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1549. {
  1550. typeHandler->Convert(typedArrayConstructor, mode, 5);
  1551. ScriptContext* scriptContext = typedArrayConstructor->GetScriptContext();
  1552. JavascriptLibrary* library = typedArrayConstructor->GetLibrary();
  1553. Assert(scriptContext->GetConfig()->IsES6TypedArrayExtensionsEnabled());
  1554. library->AddMember(typedArrayConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(3), PropertyNone);
  1555. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1556. {
  1557. library->AddMember(typedArrayConstructor, PropertyIds::name, library->CreateStringFromCppLiteral(L"TypedArray"), PropertyConfigurable);
  1558. }
  1559. library->AddMember(typedArrayConstructor, PropertyIds::prototype, library->typedArrayPrototype, PropertyNone);
  1560. library->AddFunctionToLibraryObject(typedArrayConstructor, PropertyIds::from, &TypedArrayBase::EntryInfo::From, 1);
  1561. library->AddFunctionToLibraryObject(typedArrayConstructor, PropertyIds::of, &TypedArrayBase::EntryInfo::Of, 0);
  1562. if (scriptContext->GetConfig()->IsES6SpeciesEnabled())
  1563. {
  1564. library->AddAccessorsToLibraryObject(typedArrayConstructor, PropertyIds::_symbolSpecies, &TypedArrayBase::EntryInfo::GetterSymbolSpecies, nullptr);
  1565. }
  1566. typedArrayConstructor->SetHasNoEnumerableProperties(true);
  1567. }
  1568. void JavascriptLibrary::InitializeTypedArrayPrototype(DynamicObject* typedarrayPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1569. {
  1570. typeHandler->Convert(typedarrayPrototype, mode, 31);
  1571. ScriptContext* scriptContext = typedarrayPrototype->GetScriptContext();
  1572. JavascriptLibrary* library = typedarrayPrototype->GetLibrary();
  1573. Assert(scriptContext->GetConfig()->IsES6TypedArrayExtensionsEnabled());
  1574. library->AddMember(typedarrayPrototype, PropertyIds::constructor, library->typedArrayConstructor);
  1575. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::set, &TypedArrayBase::EntryInfo::Set, 2);
  1576. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::subarray, &TypedArrayBase::EntryInfo::Subarray, 2);
  1577. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::copyWithin, &TypedArrayBase::EntryInfo::CopyWithin, 2);
  1578. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::every, &TypedArrayBase::EntryInfo::Every, 1);
  1579. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::fill, &TypedArrayBase::EntryInfo::Fill, 1);
  1580. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::filter, &TypedArrayBase::EntryInfo::Filter, 1);
  1581. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::find, &TypedArrayBase::EntryInfo::Find, 1);
  1582. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::findIndex, &TypedArrayBase::EntryInfo::FindIndex, 1);
  1583. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::forEach, &TypedArrayBase::EntryInfo::ForEach, 1);
  1584. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::indexOf, &TypedArrayBase::EntryInfo::IndexOf, 1);
  1585. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::join, &TypedArrayBase::EntryInfo::Join, 1);
  1586. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::lastIndexOf, &TypedArrayBase::EntryInfo::LastIndexOf, 1);
  1587. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::map, &TypedArrayBase::EntryInfo::Map, 1);
  1588. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::reduce, &TypedArrayBase::EntryInfo::Reduce, 1);
  1589. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::reduceRight, &TypedArrayBase::EntryInfo::ReduceRight, 1);
  1590. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::reverse, &TypedArrayBase::EntryInfo::Reverse, 0);
  1591. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::slice, &TypedArrayBase::EntryInfo::Slice, 2);
  1592. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::some, &TypedArrayBase::EntryInfo::Some, 1);
  1593. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::sort, &TypedArrayBase::EntryInfo::Sort, 1);
  1594. if (scriptContext->GetConfig()->IsES6IteratorsEnabled())
  1595. {
  1596. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::entries, &TypedArrayBase::EntryInfo::Entries, 0);
  1597. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::keys, &TypedArrayBase::EntryInfo::Keys, 0);
  1598. JavascriptFunction* valuesFunc = library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::values, &TypedArrayBase::EntryInfo::Values, 0);
  1599. library->AddMember(typedarrayPrototype, PropertyIds::_symbolIterator, valuesFunc);
  1600. }
  1601. if (scriptContext->GetConfig()->IsES7BuiltinsEnabled())
  1602. {
  1603. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::includes, &TypedArrayBase::EntryInfo::Includes, 1);
  1604. }
  1605. library->AddAccessorsToLibraryObject(typedarrayPrototype, PropertyIds::buffer, &TypedArrayBase::EntryInfo::GetterBuffer, nullptr);
  1606. library->AddAccessorsToLibraryObject(typedarrayPrototype, PropertyIds::byteLength, &TypedArrayBase::EntryInfo::GetterByteLength, nullptr);
  1607. library->AddAccessorsToLibraryObject(typedarrayPrototype, PropertyIds::byteOffset, &TypedArrayBase::EntryInfo::GetterByteOffset, nullptr);
  1608. library->AddAccessorsToLibraryObject(typedarrayPrototype, PropertyIds::length, &TypedArrayBase::EntryInfo::GetterLength, nullptr);
  1609. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1610. {
  1611. library->AddAccessorsToLibraryObjectWithName(typedarrayPrototype, PropertyIds::_symbolToStringTag,
  1612. PropertyIds::_RuntimeFunctionNameId_toStringTag, &TypedArrayBase::EntryInfo::GetterSymbolToStringTag, nullptr);
  1613. }
  1614. // The toString and toLocaleString properties are shared between Array.prototype and %TypedArray%.prototype.
  1615. // Whichever prototype is initialized first will create the functions, the other should just load the existing function objects.
  1616. if (library->arrayPrototypeToStringFunction == nullptr)
  1617. {
  1618. Assert(library->arrayPrototypeToLocaleStringFunction == nullptr);
  1619. library->arrayPrototypeToLocaleStringFunction = library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::toLocaleString, &JavascriptArray::EntryInfo::ToLocaleString, 0);
  1620. library->arrayPrototypeToStringFunction = library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::toString, &JavascriptArray::EntryInfo::ToString, 0);
  1621. }
  1622. else
  1623. {
  1624. Assert(library->arrayPrototypeToLocaleStringFunction);
  1625. library->AddMember(typedarrayPrototype, PropertyIds::toLocaleString, library->arrayPrototypeToLocaleStringFunction);
  1626. library->AddMember(typedarrayPrototype, PropertyIds::toString, library->arrayPrototypeToStringFunction);
  1627. }
  1628. typedarrayPrototype->SetHasNoEnumerableProperties(true);
  1629. }
  1630. #define INIT_TYPEDARRAY_CONSTRUCTOR(typedArray, typedarrayPrototype, TypeName) \
  1631. void JavascriptLibrary::Initialize##typedArray##Constructor(DynamicObject* typedArrayConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode) \
  1632. { \
  1633. typeHandler->Convert(typedArrayConstructor, mode, 4); \
  1634. ScriptContext* scriptContext = typedArrayConstructor->GetScriptContext(); \
  1635. JavascriptLibrary* library = typedArrayConstructor->GetLibrary(); \
  1636. if (scriptContext->GetConfig()->IsES6TypedArrayExtensionsEnabled()) \
  1637. { \
  1638. library->AddMember(typedArrayConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(3), PropertyNone); \
  1639. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled()) \
  1640. { \
  1641. library->AddMember(typedArrayConstructor, PropertyIds::name, library->CreateStringFromCppLiteral(L#typedArray), PropertyConfigurable); \
  1642. } \
  1643. } \
  1644. else \
  1645. { \
  1646. library->AddMember(typedArrayConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone); \
  1647. } \
  1648. library->AddMember(typedArrayConstructor, PropertyIds::BYTES_PER_ELEMENT, TaggedInt::ToVarUnchecked(sizeof(TypeName)), PropertyNone); \
  1649. library->AddMember(typedArrayConstructor, PropertyIds::prototype, scriptContext->GetLibrary()->##typedarrayPrototype##, PropertyNone); \
  1650. typedArrayConstructor->SetHasNoEnumerableProperties(true); \
  1651. } \
  1652. INIT_TYPEDARRAY_CONSTRUCTOR(Int8Array, Int8ArrayPrototype, int8);
  1653. INIT_TYPEDARRAY_CONSTRUCTOR(Uint8Array, Uint8ArrayPrototype, uint8);
  1654. INIT_TYPEDARRAY_CONSTRUCTOR(Uint8ClampedArray, Uint8ClampedArrayPrototype, uint8);
  1655. INIT_TYPEDARRAY_CONSTRUCTOR(Int16Array, Int16ArrayPrototype, int16);
  1656. INIT_TYPEDARRAY_CONSTRUCTOR(Uint16Array, Uint16ArrayPrototype, uint16);
  1657. INIT_TYPEDARRAY_CONSTRUCTOR(Int32Array, Int32ArrayPrototype, int32);
  1658. INIT_TYPEDARRAY_CONSTRUCTOR(Uint32Array, Uint32ArrayPrototype, uint32);
  1659. INIT_TYPEDARRAY_CONSTRUCTOR(Float32Array, Float32ArrayPrototype, float);
  1660. INIT_TYPEDARRAY_CONSTRUCTOR(Float64Array, Float64ArrayPrototype, double);
  1661. #define INIT_TYPEDARRAY_PROTOTYPE(typedArray, typedarrayPrototype, TypeName) \
  1662. void JavascriptLibrary::Initialize##typedarrayPrototype##(DynamicObject* typedarrayPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode) \
  1663. { \
  1664. typeHandler->Convert(typedarrayPrototype, mode, 2); \
  1665. ScriptContext* scriptContext = typedarrayPrototype->GetScriptContext(); \
  1666. JavascriptLibrary* library = typedarrayPrototype->GetLibrary(); \
  1667. library->AddMember(typedarrayPrototype, PropertyIds::constructor, library->##typedArray##Constructor); \
  1668. if (scriptContext->GetConfig()->IsES6TypedArrayExtensionsEnabled()) \
  1669. { \
  1670. library->AddMember(typedarrayPrototype, PropertyIds::BYTES_PER_ELEMENT, TaggedInt::ToVarUnchecked(sizeof(TypeName)), PropertyNone); \
  1671. } \
  1672. else \
  1673. { \
  1674. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::set, &##typedArray##::EntryInfo::Set, 2); \
  1675. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::subarray, &##typedArray##::EntryInfo::Subarray, 2); \
  1676. } \
  1677. typedarrayPrototype->SetHasNoEnumerableProperties(true); \
  1678. } \
  1679. INIT_TYPEDARRAY_PROTOTYPE(Int8Array, Int8ArrayPrototype, int8);
  1680. INIT_TYPEDARRAY_PROTOTYPE(Uint8Array, Uint8ArrayPrototype, uint8);
  1681. INIT_TYPEDARRAY_PROTOTYPE(Uint8ClampedArray, Uint8ClampedArrayPrototype, uint8);
  1682. INIT_TYPEDARRAY_PROTOTYPE(Int16Array, Int16ArrayPrototype, int16);
  1683. INIT_TYPEDARRAY_PROTOTYPE(Uint16Array, Uint16ArrayPrototype, uint16);
  1684. INIT_TYPEDARRAY_PROTOTYPE(Int32Array, Int32ArrayPrototype, int32);
  1685. INIT_TYPEDARRAY_PROTOTYPE(Uint32Array, Uint32ArrayPrototype, uint32);
  1686. INIT_TYPEDARRAY_PROTOTYPE(Float32Array, Float32ArrayPrototype, float);
  1687. INIT_TYPEDARRAY_PROTOTYPE(Float64Array, Float64ArrayPrototype, double);
  1688. // For Microsoft extension typed array, like Int64Array, BoolArray, we don't have constructor as they can only be created from the projection arguments.
  1689. // there is no subarray method either as that's another way to create typed array.
  1690. #define INIT_MSINTERNAL_TYPEDARRAY_PROTOTYPE(typedArray, typedarrayPrototype) \
  1691. void JavascriptLibrary::Initialize##typedarrayPrototype##(DynamicObject* typedarrayPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode) \
  1692. { \
  1693. typeHandler->Convert(typedarrayPrototype, mode, 1); \
  1694. JavascriptLibrary* library = typedarrayPrototype->GetLibrary(); \
  1695. library->AddFunctionToLibraryObject(typedarrayPrototype, PropertyIds::set, &##typedArray##::EntryInfo::Set, 2); \
  1696. typedarrayPrototype->SetHasNoEnumerableProperties(true); \
  1697. } \
  1698. INIT_MSINTERNAL_TYPEDARRAY_PROTOTYPE(Int64Array, Int64ArrayPrototype);
  1699. INIT_MSINTERNAL_TYPEDARRAY_PROTOTYPE(Uint64Array, Uint64ArrayPrototype);
  1700. INIT_MSINTERNAL_TYPEDARRAY_PROTOTYPE(BoolArray, BoolArrayPrototype);
  1701. INIT_MSINTERNAL_TYPEDARRAY_PROTOTYPE(CharArray, CharArrayPrototype);
  1702. void JavascriptLibrary::InitializeErrorConstructor(DynamicObject* constructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1703. {
  1704. typeHandler->Convert(constructor, mode, 4);
  1705. ScriptContext* scriptContext = constructor->GetScriptContext();
  1706. JavascriptLibrary* library = constructor->GetLibrary();
  1707. library->AddMember(constructor, PropertyIds::prototype, library->errorPrototype, PropertyNone);
  1708. library->AddMember(constructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone);
  1709. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1710. {
  1711. library->AddMember(constructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Error), PropertyConfigurable);
  1712. }
  1713. if (scriptContext->GetConfig()->IsErrorStackTraceEnabled())
  1714. {
  1715. library->AddMember(constructor, PropertyIds::stackTraceLimit, JavascriptNumber::ToVar(JavascriptExceptionOperators::DefaultStackTraceLimit, scriptContext), PropertyConfigurable | PropertyWritable | PropertyEnumerable);
  1716. }
  1717. constructor->SetHasNoEnumerableProperties(true);
  1718. }
  1719. void JavascriptLibrary::InitializeErrorPrototype(DynamicObject* prototype, DeferredTypeHandlerBase* typeHandler, DeferredInitializeMode mode)
  1720. {
  1721. typeHandler->Convert(prototype, mode, 4);
  1722. JavascriptLibrary* library = prototype->GetLibrary();
  1723. library->AddMember(prototype, PropertyIds::constructor, library->errorConstructor);
  1724. bool hasNoEnumerableProperties = true;
  1725. PropertyAttributes prototypeNameMessageAttributes = PropertyConfigurable | PropertyWritable;
  1726. library->AddMember(prototype, PropertyIds::name, library->CreateStringFromCppLiteral(L"Error"), prototypeNameMessageAttributes);
  1727. library->AddMember(prototype, PropertyIds::message, library->GetEmptyString(), prototypeNameMessageAttributes);
  1728. library->AddFunctionToLibraryObject(prototype, PropertyIds::toString, &JavascriptError::EntryInfo::ToString, 0);
  1729. prototype->SetHasNoEnumerableProperties(hasNoEnumerableProperties);
  1730. }
  1731. #define INIT_ERROR_CONSTRUCTOR(error) \
  1732. void JavascriptLibrary::Initialize##error##Constructor(DynamicObject* constructor, DeferredTypeHandlerBase* typeHandler, DeferredInitializeMode mode) \
  1733. { \
  1734. typeHandler->Convert(constructor, mode, 3); \
  1735. ScriptContext* scriptContext = constructor->GetScriptContext(); \
  1736. JavascriptLibrary* library = constructor->GetLibrary(); \
  1737. library->AddMember(constructor, PropertyIds::prototype, library->Get##error##Prototype(), PropertyNone); \
  1738. library->AddMember(constructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone); \
  1739. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled()) \
  1740. { \
  1741. PropertyAttributes prototypeNameMessageAttributes = PropertyConfigurable; \
  1742. library->AddMember(constructor, PropertyIds::name, library->CreateStringFromCppLiteral(L#error), prototypeNameMessageAttributes); \
  1743. } \
  1744. constructor->SetHasNoEnumerableProperties(true); \
  1745. } \
  1746. INIT_ERROR_CONSTRUCTOR(EvalError);
  1747. INIT_ERROR_CONSTRUCTOR(RangeError);
  1748. INIT_ERROR_CONSTRUCTOR(ReferenceError);
  1749. INIT_ERROR_CONSTRUCTOR(SyntaxError);
  1750. INIT_ERROR_CONSTRUCTOR(TypeError);
  1751. INIT_ERROR_CONSTRUCTOR(URIError);
  1752. #define INIT_ERROR_PROTOTYPE(error) \
  1753. void JavascriptLibrary::Initialize##error##Prototype(DynamicObject* prototype, DeferredTypeHandlerBase* typeHandler, DeferredInitializeMode mode) \
  1754. { \
  1755. typeHandler->Convert(prototype, mode, 4); \
  1756. JavascriptLibrary* library = prototype->GetLibrary(); \
  1757. library->AddMember(prototype, PropertyIds::constructor, library->Get##error##Constructor()); \
  1758. bool hasNoEnumerableProperties = true; \
  1759. PropertyAttributes prototypeNameMessageAttributes = PropertyConfigurable | PropertyWritable; \
  1760. library->AddMember(prototype, PropertyIds::name, library->CreateStringFromCppLiteral(L#error), prototypeNameMessageAttributes); \
  1761. library->AddMember(prototype, PropertyIds::message, library->GetEmptyString(), prototypeNameMessageAttributes); \
  1762. library->AddFunctionToLibraryObject(prototype, PropertyIds::toString, &JavascriptError::EntryInfo::ToString, 0); \
  1763. prototype->SetHasNoEnumerableProperties(hasNoEnumerableProperties); \
  1764. } \
  1765. INIT_ERROR_PROTOTYPE(EvalError);
  1766. INIT_ERROR_PROTOTYPE(RangeError);
  1767. INIT_ERROR_PROTOTYPE(ReferenceError);
  1768. INIT_ERROR_PROTOTYPE(SyntaxError);
  1769. INIT_ERROR_PROTOTYPE(TypeError);
  1770. INIT_ERROR_PROTOTYPE(URIError);
  1771. void JavascriptLibrary::InitializeBooleanConstructor(DynamicObject* booleanConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1772. {
  1773. typeHandler->Convert(booleanConstructor, mode, 3);
  1774. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterBoolean
  1775. // so that the update is in sync with profiler
  1776. ScriptContext* scriptContext = booleanConstructor->GetScriptContext();
  1777. JavascriptLibrary* library = booleanConstructor->GetLibrary();
  1778. library->AddMember(booleanConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone);
  1779. library->AddMember(booleanConstructor, PropertyIds::prototype, library->booleanPrototype, PropertyNone);
  1780. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1781. {
  1782. library->AddMember(booleanConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Boolean), PropertyConfigurable);
  1783. }
  1784. booleanConstructor->SetHasNoEnumerableProperties(true);
  1785. }
  1786. void JavascriptLibrary::InitializeBooleanPrototype(DynamicObject* booleanPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1787. {
  1788. typeHandler->Convert(booleanPrototype, mode, 3);
  1789. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterBoolean
  1790. // so that the update is in sync with profiler
  1791. JavascriptLibrary* library = booleanPrototype->GetLibrary();
  1792. ScriptContext* scriptContext = booleanPrototype->GetScriptContext();
  1793. library->AddMember(booleanPrototype, PropertyIds::constructor, library->booleanConstructor);
  1794. scriptContext->SetBuiltInLibraryFunction(JavascriptBoolean::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  1795. library->AddFunctionToLibraryObject(booleanPrototype, PropertyIds::valueOf, &JavascriptBoolean::EntryInfo::ValueOf, 0));
  1796. scriptContext->SetBuiltInLibraryFunction(JavascriptBoolean::EntryInfo::ToString.GetOriginalEntryPoint(),
  1797. library->AddFunctionToLibraryObject(booleanPrototype, PropertyIds::toString, &JavascriptBoolean::EntryInfo::ToString, 0));
  1798. booleanPrototype->SetHasNoEnumerableProperties(true);
  1799. }
  1800. void JavascriptLibrary::InitializeSymbolConstructor(DynamicObject* symbolConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1801. {
  1802. typeHandler->Convert(symbolConstructor, mode, 12);
  1803. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSymbol
  1804. // so that the update is in sync with profiler
  1805. JavascriptLibrary* library = symbolConstructor->GetLibrary();
  1806. ScriptContext* scriptContext = symbolConstructor->GetScriptContext();
  1807. library->AddMember(symbolConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone);
  1808. library->AddMember(symbolConstructor, PropertyIds::prototype, library->symbolPrototype, PropertyNone);
  1809. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1810. {
  1811. library->AddMember(symbolConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Symbol), PropertyConfigurable);
  1812. }
  1813. if (scriptContext->GetConfig()->IsES6HasInstanceEnabled())
  1814. {
  1815. library->AddMember(symbolConstructor, PropertyIds::hasInstance, library->GetSymbolHasInstance(), PropertyNone);
  1816. }
  1817. if (scriptContext->GetConfig()->IsES6IsConcatSpreadableEnabled())
  1818. {
  1819. library->AddMember(symbolConstructor, PropertyIds::isConcatSpreadable, library->GetSymbolIsConcatSpreadable(), PropertyNone);
  1820. }
  1821. library->AddMember(symbolConstructor, PropertyIds::iterator, library->GetSymbolIterator(), PropertyNone);
  1822. if (scriptContext->GetConfig()->IsES6SpeciesEnabled())
  1823. {
  1824. library->AddMember(symbolConstructor, PropertyIds::species, library->GetSymbolSpecies(), PropertyNone);
  1825. }
  1826. if (scriptContext->GetConfig()->IsES6ToPrimitiveEnabled())
  1827. {
  1828. library->AddMember(symbolConstructor, PropertyIds::toPrimitive, library->GetSymbolToPrimitive(), PropertyNone);
  1829. }
  1830. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1831. {
  1832. library->AddMember(symbolConstructor, PropertyIds::toStringTag, library->GetSymbolToStringTag(), PropertyNone);
  1833. }
  1834. library->AddMember(symbolConstructor, PropertyIds::unscopables, library->GetSymbolUnscopables(), PropertyNone);
  1835. library->AddFunctionToLibraryObject(symbolConstructor, PropertyIds::for_, &JavascriptSymbol::EntryInfo::For, 1);
  1836. library->AddFunctionToLibraryObject(symbolConstructor, PropertyIds::keyFor, &JavascriptSymbol::EntryInfo::KeyFor, 1);
  1837. symbolConstructor->SetHasNoEnumerableProperties(true);
  1838. }
  1839. void JavascriptLibrary::InitializeSymbolPrototype(DynamicObject* symbolPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1840. {
  1841. typeHandler->Convert(symbolPrototype, mode, 5);
  1842. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSymbol
  1843. // so that the update is in sync with profiler
  1844. JavascriptLibrary* library = symbolPrototype->GetLibrary();
  1845. ScriptContext* scriptContext = symbolPrototype->GetScriptContext();
  1846. library->AddMember(symbolPrototype, PropertyIds::constructor, library->symbolConstructor);
  1847. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1848. {
  1849. library->AddMember(symbolPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"Symbol"), PropertyConfigurable);
  1850. }
  1851. scriptContext->SetBuiltInLibraryFunction(JavascriptSymbol::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  1852. library->AddFunctionToLibraryObject(symbolPrototype, PropertyIds::valueOf, &JavascriptSymbol::EntryInfo::ValueOf, 0));
  1853. scriptContext->SetBuiltInLibraryFunction(JavascriptSymbol::EntryInfo::ToString.GetOriginalEntryPoint(),
  1854. library->AddFunctionToLibraryObject(symbolPrototype, PropertyIds::toString, &JavascriptSymbol::EntryInfo::ToString, 0));
  1855. if (scriptContext->GetConfig()->IsES6ToPrimitiveEnabled())
  1856. {
  1857. scriptContext->SetBuiltInLibraryFunction(JavascriptSymbol::EntryInfo::SymbolToPrimitive.GetOriginalEntryPoint(),
  1858. library->AddFunctionToLibraryObjectWithName(symbolPrototype, PropertyIds::_symbolToPrimitive, PropertyIds::_RuntimeFunctionNameId_toPrimitive,
  1859. &JavascriptSymbol::EntryInfo::SymbolToPrimitive, 1));
  1860. symbolPrototype->SetWritable(PropertyIds::_symbolToPrimitive, false);
  1861. }
  1862. symbolPrototype->SetHasNoEnumerableProperties(true);
  1863. }
  1864. void JavascriptLibrary::InitializePromiseConstructor(DynamicObject* promiseConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1865. {
  1866. typeHandler->Convert(promiseConstructor, mode, 8);
  1867. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterPromise
  1868. // so that the update is in sync with profiler
  1869. JavascriptLibrary* library = promiseConstructor->GetLibrary();
  1870. ScriptContext* scriptContext = promiseConstructor->GetScriptContext();
  1871. library->AddMember(promiseConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone);
  1872. library->AddMember(promiseConstructor, PropertyIds::prototype, library->promisePrototype, PropertyNone);
  1873. if (scriptContext->GetConfig()->IsES6SpeciesEnabled())
  1874. {
  1875. library->AddAccessorsToLibraryObject(promiseConstructor, PropertyIds::_symbolSpecies, &JavascriptPromise::EntryInfo::GetterSymbolSpecies, nullptr);
  1876. }
  1877. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1878. {
  1879. library->AddMember(promiseConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Promise), PropertyConfigurable);
  1880. }
  1881. library->AddFunctionToLibraryObject(promiseConstructor, PropertyIds::all, &JavascriptPromise::EntryInfo::All, 1);
  1882. library->AddFunctionToLibraryObject(promiseConstructor, PropertyIds::race, &JavascriptPromise::EntryInfo::Race, 1);
  1883. library->AddFunctionToLibraryObject(promiseConstructor, PropertyIds::reject, &JavascriptPromise::EntryInfo::Reject, 1);
  1884. library->AddMember(promiseConstructor, PropertyIds::resolve, library->EnsurePromiseResolveFunction(), PropertyBuiltInMethodDefaults);
  1885. promiseConstructor->SetHasNoEnumerableProperties(true);
  1886. }
  1887. JavascriptFunction* JavascriptLibrary::EnsurePromiseResolveFunction()
  1888. {
  1889. if (promiseResolveFunction == nullptr)
  1890. {
  1891. promiseResolveFunction = DefaultCreateFunction(&JavascriptPromise::EntryInfo::Resolve, 1, nullptr, nullptr, PropertyIds::resolve);
  1892. }
  1893. return promiseResolveFunction;
  1894. }
  1895. void JavascriptLibrary::InitializePromisePrototype(DynamicObject* promisePrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1896. {
  1897. typeHandler->Convert(promisePrototype, mode, 4);
  1898. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterPromise
  1899. // so that the update is in sync with profiler
  1900. JavascriptLibrary* library = promisePrototype->GetLibrary();
  1901. ScriptContext* scriptContext = promisePrototype->GetScriptContext();
  1902. library->AddMember(promisePrototype, PropertyIds::constructor, library->promiseConstructor);
  1903. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1904. {
  1905. library->AddMember(promisePrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"Promise"), PropertyConfigurable);
  1906. }
  1907. scriptContext->SetBuiltInLibraryFunction(JavascriptPromise::EntryInfo::Catch.GetOriginalEntryPoint(),
  1908. library->AddFunctionToLibraryObject(promisePrototype, PropertyIds::catch_, &JavascriptPromise::EntryInfo::Catch, 1));
  1909. scriptContext->SetBuiltInLibraryFunction(JavascriptPromise::EntryInfo::Then.GetOriginalEntryPoint(),
  1910. library->AddFunctionToLibraryObject(promisePrototype, PropertyIds::then, &JavascriptPromise::EntryInfo::Then, 2));
  1911. promisePrototype->SetHasNoEnumerableProperties(true);
  1912. }
  1913. void JavascriptLibrary::InitializeGeneratorFunctionConstructor(DynamicObject* generatorFunctionConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1914. {
  1915. typeHandler->Convert(generatorFunctionConstructor, mode, 3);
  1916. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterGeneratorFunction
  1917. // so that the update is in sync with profiler
  1918. JavascriptLibrary* library = generatorFunctionConstructor->GetLibrary();
  1919. ScriptContext* scriptContext = generatorFunctionConstructor->GetScriptContext();
  1920. library->AddMember(generatorFunctionConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  1921. library->AddMember(generatorFunctionConstructor, PropertyIds::prototype, library->generatorFunctionPrototype, PropertyNone);
  1922. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1923. {
  1924. library->AddMember(generatorFunctionConstructor, PropertyIds::name, library->CreateStringFromCppLiteral(L"GeneratorFunction"), PropertyConfigurable);
  1925. }
  1926. generatorFunctionConstructor->SetHasNoEnumerableProperties(true);
  1927. }
  1928. void JavascriptLibrary::InitializeGeneratorFunctionPrototype(DynamicObject* generatorFunctionPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1929. {
  1930. typeHandler->Convert(generatorFunctionPrototype, mode, 3);
  1931. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterGeneratorFunction
  1932. // so that the update is in sync with profiler
  1933. JavascriptLibrary* library = generatorFunctionPrototype->GetLibrary();
  1934. ScriptContext* scriptContext = library->GetScriptContext();
  1935. library->AddMember(generatorFunctionPrototype, PropertyIds::constructor, library->generatorFunctionConstructor, PropertyConfigurable);
  1936. library->AddMember(generatorFunctionPrototype, PropertyIds::prototype, library->generatorPrototype, PropertyConfigurable);
  1937. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1938. {
  1939. library->AddMember(generatorFunctionPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"GeneratorFunction"), PropertyConfigurable);
  1940. }
  1941. generatorFunctionPrototype->SetHasNoEnumerableProperties(true);
  1942. }
  1943. void JavascriptLibrary::InitializeGeneratorPrototype(DynamicObject* generatorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1944. {
  1945. typeHandler->Convert(generatorPrototype, mode, 5);
  1946. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterGenerator
  1947. // so that the update is in sync with profiler
  1948. JavascriptLibrary* library = generatorPrototype->GetLibrary();
  1949. ScriptContext* scriptContext = library->GetScriptContext();
  1950. library->AddMember(generatorPrototype, PropertyIds::constructor, library->generatorFunctionPrototype, PropertyConfigurable);
  1951. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  1952. {
  1953. library->AddMember(generatorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"Generator"), PropertyConfigurable);
  1954. }
  1955. library->AddFunctionToLibraryObject(generatorPrototype, PropertyIds::next, &JavascriptGenerator::EntryInfo::Next, 1);
  1956. library->AddFunctionToLibraryObject(generatorPrototype, PropertyIds::return_, &JavascriptGenerator::EntryInfo::Return, 1);
  1957. library->AddFunctionToLibraryObject(generatorPrototype, PropertyIds::throw_, &JavascriptGenerator::EntryInfo::Throw, 1);
  1958. generatorPrototype->SetHasNoEnumerableProperties(true);
  1959. }
  1960. void JavascriptLibrary::InitializeProxyConstructor(DynamicObject* proxyConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1961. {
  1962. typeHandler->Convert(proxyConstructor, mode, 4);
  1963. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSymbol
  1964. // so that the update is in sync with profiler
  1965. JavascriptLibrary* library = proxyConstructor->GetLibrary();
  1966. ScriptContext* scriptContext = proxyConstructor->GetScriptContext();
  1967. library->AddMember(proxyConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(2), PropertyConfigurable);
  1968. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1969. {
  1970. library->AddMember(proxyConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Proxy), PropertyConfigurable);
  1971. }
  1972. library->AddFunctionToLibraryObject(proxyConstructor, PropertyIds::revocable, &JavascriptProxy::EntryInfo::Revocable, PropertyNone);
  1973. proxyConstructor->SetHasNoEnumerableProperties(true);
  1974. }
  1975. void JavascriptLibrary::InitializeProxyPrototype(DynamicObject* proxyPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1976. {
  1977. typeHandler->Convert(proxyPrototype, mode, 1);
  1978. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSymbol
  1979. // so that the update is in sync with profiler
  1980. JavascriptLibrary* library = proxyPrototype->GetLibrary();
  1981. library->AddMember(proxyPrototype, PropertyIds::constructor, library->proxyConstructor);
  1982. proxyPrototype->SetHasNoEnumerableProperties(true);
  1983. }
  1984. void JavascriptLibrary::InitializeDateConstructor(DynamicObject* dateConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  1985. {
  1986. typeHandler->Convert(dateConstructor, mode, 6);
  1987. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterDate
  1988. // so that the update is in sync with profiler
  1989. JavascriptLibrary* library = dateConstructor->GetLibrary();
  1990. ScriptContext* scriptContext = dateConstructor->GetScriptContext();
  1991. library->AddMember(dateConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(7), PropertyNone);
  1992. library->AddMember(dateConstructor, PropertyIds::prototype, library->datePrototype, PropertyNone);
  1993. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  1994. {
  1995. library->AddMember(dateConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Date), PropertyConfigurable);
  1996. }
  1997. library->AddFunctionToLibraryObject(dateConstructor, PropertyIds::parse, &JavascriptDate::EntryInfo::Parse, 1); // should be static
  1998. library->AddFunctionToLibraryObject(dateConstructor, PropertyIds::now, &JavascriptDate::EntryInfo::Now, 0); // should be static
  1999. library->AddFunctionToLibraryObject(dateConstructor, PropertyIds::UTC, &JavascriptDate::EntryInfo::UTC, 7); // should be static
  2000. dateConstructor->SetHasNoEnumerableProperties(true);
  2001. }
  2002. void JavascriptLibrary::InitializeDatePrototype(DynamicObject* datePrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2003. {
  2004. typeHandler->Convert(datePrototype, mode, 51);
  2005. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterDate
  2006. // so that the update is in sync with profiler
  2007. ScriptContext* scriptContext = datePrototype->GetScriptContext();
  2008. JavascriptLibrary* library = datePrototype->GetLibrary();
  2009. library->AddMember(datePrototype, PropertyIds::constructor, library->dateConstructor);
  2010. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetDate.GetOriginalEntryPoint(),
  2011. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getDate, &JavascriptDate::EntryInfo::GetDate, 0));
  2012. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetDay.GetOriginalEntryPoint(),
  2013. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getDay, &JavascriptDate::EntryInfo::GetDay, 0));
  2014. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetFullYear.GetOriginalEntryPoint(),
  2015. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getFullYear, &JavascriptDate::EntryInfo::GetFullYear, 0));
  2016. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetHours.GetOriginalEntryPoint(),
  2017. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getHours, &JavascriptDate::EntryInfo::GetHours, 0));
  2018. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetMilliseconds.GetOriginalEntryPoint(),
  2019. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getMilliseconds, &JavascriptDate::EntryInfo::GetMilliseconds, 0));
  2020. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetMinutes.GetOriginalEntryPoint(),
  2021. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getMinutes, &JavascriptDate::EntryInfo::GetMinutes, 0));
  2022. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetMonth.GetOriginalEntryPoint(),
  2023. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getMonth, &JavascriptDate::EntryInfo::GetMonth, 0));
  2024. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetSeconds.GetOriginalEntryPoint(),
  2025. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getSeconds, &JavascriptDate::EntryInfo::GetSeconds, 0));
  2026. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetTime.GetOriginalEntryPoint(),
  2027. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getTime, &JavascriptDate::EntryInfo::GetTime, 0));
  2028. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetTimezoneOffset.GetOriginalEntryPoint(),
  2029. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getTimezoneOffset, &JavascriptDate::EntryInfo::GetTimezoneOffset, 0));
  2030. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCDate.GetOriginalEntryPoint(),
  2031. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCDate, &JavascriptDate::EntryInfo::GetUTCDate, 0));
  2032. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCDay.GetOriginalEntryPoint(),
  2033. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCDay, &JavascriptDate::EntryInfo::GetUTCDay, 0));
  2034. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCFullYear.GetOriginalEntryPoint(),
  2035. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCFullYear, &JavascriptDate::EntryInfo::GetUTCFullYear, 0));
  2036. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCHours.GetOriginalEntryPoint(),
  2037. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCHours, &JavascriptDate::EntryInfo::GetUTCHours, 0));
  2038. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCMilliseconds.GetOriginalEntryPoint(),
  2039. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCMilliseconds, &JavascriptDate::EntryInfo::GetUTCMilliseconds, 0));
  2040. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCMinutes.GetOriginalEntryPoint(),
  2041. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCMinutes, &JavascriptDate::EntryInfo::GetUTCMinutes, 0));
  2042. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCMonth.GetOriginalEntryPoint(),
  2043. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCMonth, &JavascriptDate::EntryInfo::GetUTCMonth, 0));
  2044. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetUTCSeconds.GetOriginalEntryPoint(),
  2045. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getUTCSeconds, &JavascriptDate::EntryInfo::GetUTCSeconds, 0));
  2046. if (scriptContext->GetConfig()->SupportsES3Extensions())
  2047. {
  2048. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetVarDate.GetOriginalEntryPoint(),
  2049. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getVarDate, &JavascriptDate::EntryInfo::GetVarDate, 0));
  2050. }
  2051. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::GetYear.GetOriginalEntryPoint(),
  2052. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::getYear, &JavascriptDate::EntryInfo::GetYear, 0));
  2053. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetDate.GetOriginalEntryPoint(),
  2054. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setDate, &JavascriptDate::EntryInfo::SetDate, 1));
  2055. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetFullYear.GetOriginalEntryPoint(),
  2056. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setFullYear, &JavascriptDate::EntryInfo::SetFullYear, 3));
  2057. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetHours.GetOriginalEntryPoint(),
  2058. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setHours, &JavascriptDate::EntryInfo::SetHours, 4));
  2059. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetMilliseconds.GetOriginalEntryPoint(),
  2060. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setMilliseconds, &JavascriptDate::EntryInfo::SetMilliseconds, 1));
  2061. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetMinutes.GetOriginalEntryPoint(),
  2062. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setMinutes, &JavascriptDate::EntryInfo::SetMinutes, 3));
  2063. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetMonth.GetOriginalEntryPoint(),
  2064. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setMonth, &JavascriptDate::EntryInfo::SetMonth, 2));
  2065. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetSeconds.GetOriginalEntryPoint(),
  2066. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setSeconds, &JavascriptDate::EntryInfo::SetSeconds, 2));
  2067. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetTime.GetOriginalEntryPoint(),
  2068. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setTime, &JavascriptDate::EntryInfo::SetTime, 1));
  2069. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCDate.GetOriginalEntryPoint(),
  2070. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCDate, &JavascriptDate::EntryInfo::SetUTCDate, 1));
  2071. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCFullYear.GetOriginalEntryPoint(),
  2072. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCFullYear, &JavascriptDate::EntryInfo::SetUTCFullYear, 3));
  2073. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCHours.GetOriginalEntryPoint(),
  2074. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCHours, &JavascriptDate::EntryInfo::SetUTCHours, 4));
  2075. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCMilliseconds.GetOriginalEntryPoint(),
  2076. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCMilliseconds, &JavascriptDate::EntryInfo::SetUTCMilliseconds, 1));
  2077. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCMinutes.GetOriginalEntryPoint(),
  2078. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCMinutes, &JavascriptDate::EntryInfo::SetUTCMinutes, 3));
  2079. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCMonth.GetOriginalEntryPoint(),
  2080. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCMonth, &JavascriptDate::EntryInfo::SetUTCMonth, 2));
  2081. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetUTCSeconds.GetOriginalEntryPoint(),
  2082. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setUTCSeconds, &JavascriptDate::EntryInfo::SetUTCSeconds, 2));
  2083. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SetYear.GetOriginalEntryPoint(),
  2084. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::setYear, &JavascriptDate::EntryInfo::SetYear, 1));
  2085. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToDateString.GetOriginalEntryPoint(),
  2086. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toDateString, &JavascriptDate::EntryInfo::ToDateString, 0));
  2087. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToISOString.GetOriginalEntryPoint(),
  2088. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toISOString, &JavascriptDate::EntryInfo::ToISOString, 0));
  2089. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToJSON.GetOriginalEntryPoint(),
  2090. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toJSON, &JavascriptDate::EntryInfo::ToJSON, 1));
  2091. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToLocaleDateString.GetOriginalEntryPoint(),
  2092. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toLocaleDateString, &JavascriptDate::EntryInfo::ToLocaleDateString, 0));
  2093. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToLocaleString.GetOriginalEntryPoint(),
  2094. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toLocaleString, &JavascriptDate::EntryInfo::ToLocaleString, 0));
  2095. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToLocaleTimeString.GetOriginalEntryPoint(),
  2096. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toLocaleTimeString, &JavascriptDate::EntryInfo::ToLocaleTimeString, 0));
  2097. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToString.GetOriginalEntryPoint(),
  2098. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toString, &JavascriptDate::EntryInfo::ToString, 0));
  2099. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToTimeString.GetOriginalEntryPoint(),
  2100. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toTimeString, &JavascriptDate::EntryInfo::ToTimeString, 0));
  2101. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ToUTCString.GetOriginalEntryPoint(),
  2102. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toUTCString, &JavascriptDate::EntryInfo::ToUTCString, 0));
  2103. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::toGMTString, &JavascriptDate::EntryInfo::ToGMTString, 0);
  2104. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  2105. library->AddFunctionToLibraryObject(datePrototype, PropertyIds::valueOf, &JavascriptDate::EntryInfo::ValueOf, 0));
  2106. if (scriptContext->GetConfig()->IsES6ToPrimitiveEnabled())
  2107. {
  2108. scriptContext->SetBuiltInLibraryFunction(JavascriptDate::EntryInfo::SymbolToPrimitive.GetOriginalEntryPoint(),
  2109. library->AddFunctionToLibraryObjectWithName(datePrototype, PropertyIds::_symbolToPrimitive, PropertyIds::_RuntimeFunctionNameId_toPrimitive,
  2110. &JavascriptDate::EntryInfo::SymbolToPrimitive, 1));
  2111. datePrototype->SetWritable(PropertyIds::_symbolToPrimitive, false);
  2112. }
  2113. datePrototype->SetHasNoEnumerableProperties(true);
  2114. }
  2115. void JavascriptLibrary::InitializeFunctionConstructor(DynamicObject* functionConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2116. {
  2117. typeHandler->Convert(functionConstructor, mode, 3);
  2118. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterFunction
  2119. // so that the update is in sync with profiler
  2120. ScriptContext* scriptContext = functionConstructor->GetScriptContext();
  2121. JavascriptLibrary* library = functionConstructor->GetLibrary();
  2122. library->AddMember(functionConstructor, PropertyIds::prototype, library->functionPrototype, PropertyNone);
  2123. library->AddMember(functionConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable);
  2124. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2125. {
  2126. library->AddMember(functionConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Function), PropertyConfigurable);
  2127. }
  2128. functionConstructor->SetHasNoEnumerableProperties(true);
  2129. }
  2130. void JavascriptLibrary::InitializeFunctionPrototype(DynamicObject* functionPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2131. {
  2132. typeHandler->Convert(functionPrototype, mode, 7);
  2133. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterFunction
  2134. // so that the update is in sync with profiler
  2135. ScriptContext* scriptContext = functionPrototype->GetScriptContext();
  2136. JavascriptLibrary* library = functionPrototype->GetLibrary();
  2137. JavascriptFunction ** builtinFuncs = library->GetBuiltinFunctions();
  2138. library->AddMember(functionPrototype, PropertyIds::constructor, library->functionConstructor);
  2139. library->AddMember(functionPrototype, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyConfigurable);
  2140. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2141. {
  2142. library->AddMember(functionPrototype, PropertyIds::name, LiteralString::CreateEmptyString(scriptContext->GetLibrary()->GetStringTypeStatic()), PropertyConfigurable);
  2143. }
  2144. JavascriptFunction *func = library->AddFunctionToLibraryObject(functionPrototype, PropertyIds::apply, &JavascriptFunction::EntryInfo::Apply, 2);
  2145. builtinFuncs[BuiltinFunction::Function_Apply] = func;
  2146. library->AddFunctionToLibraryObject(functionPrototype, PropertyIds::bind, &JavascriptFunction::EntryInfo::Bind, 1);
  2147. func = library->AddFunctionToLibraryObject(functionPrototype, PropertyIds::call, &JavascriptFunction::EntryInfo::Call, 1);
  2148. builtinFuncs[BuiltinFunction::Function_Call] = func;
  2149. library->AddFunctionToLibraryObject(functionPrototype, PropertyIds::toString, &JavascriptFunction::EntryInfo::ToString, 0);
  2150. if (scriptContext->GetConfig()->IsES6HasInstanceEnabled())
  2151. {
  2152. scriptContext->SetBuiltInLibraryFunction(JavascriptFunction::EntryInfo::SymbolHasInstance.GetOriginalEntryPoint(),
  2153. library->AddFunctionToLibraryObjectWithName(functionPrototype, PropertyIds::_symbolHasInstance, PropertyIds::_RuntimeFunctionNameId_hasInstance,
  2154. &JavascriptFunction::EntryInfo::SymbolHasInstance, 1));
  2155. functionPrototype->SetWritable(PropertyIds::_symbolHasInstance, false);
  2156. }
  2157. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  2158. functionPrototype->SetHasNoEnumerableProperties(true);
  2159. }
  2160. void JavascriptLibrary::InitializeComplexThings()
  2161. {
  2162. emptyRegexPattern = RegexHelper::CompileDynamic(scriptContext, L"", 0, L"", 0, false);
  2163. Recycler *const recycler = GetRecycler();
  2164. const ScriptConfiguration *scriptConfig = scriptContext->GetConfig();
  2165. // Creating the regex prototype object requires compiling an empty regex, which may require error types to be
  2166. // initialized first (such as when a stack probe fails). So, the regex prototype and other things that depend on it are
  2167. // initialized here, which will be after the dependency types are initialized.
  2168. //
  2169. // In ES6, RegExp.prototype is not a RegExp object itself so we do not need to wait and create an empty RegExp.
  2170. // Instead, we just create an ordinary object prototype for RegExp.prototype in InitializePrototypes.
  2171. if (!scriptConfig->IsES6PrototypeChain() && regexPrototype == nullptr)
  2172. {
  2173. regexPrototype = RecyclerNew(recycler, JavascriptRegExp, emptyRegexPattern,
  2174. DynamicType::New(scriptContext, TypeIds_RegEx, objectPrototype, nullptr,
  2175. DeferredTypeHandler<InitializeRegexPrototype>::GetDefaultInstance()));
  2176. }
  2177. SimplePathTypeHandler *typeHandler =
  2178. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true);
  2179. // See JavascriptRegExp::IsWritable for property writability
  2180. if (!scriptConfig->IsES6RegExPrototypePropertiesEnabled())
  2181. {
  2182. typeHandler->ClearHasOnlyWritableDataProperties();
  2183. }
  2184. regexType = DynamicType::New(scriptContext, TypeIds_RegEx, regexPrototype, nullptr, typeHandler, true, true);
  2185. }
  2186. void JavascriptLibrary::InitializeMathObject(DynamicObject* mathObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2187. {
  2188. typeHandler->Convert(mathObject, mode, 42);
  2189. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterMath
  2190. // so that the update is in sync with profiler
  2191. ScriptContext* scriptContext = mathObject->GetScriptContext();
  2192. JavascriptLibrary* library = mathObject->GetLibrary();
  2193. library->AddMember(mathObject, PropertyIds::E, JavascriptNumber::New(Math::E, scriptContext), PropertyNone);
  2194. library->AddMember(mathObject, PropertyIds::LN10, JavascriptNumber::New(Math::LN10, scriptContext), PropertyNone);
  2195. library->AddMember(mathObject, PropertyIds::LN2, JavascriptNumber::New(Math::LN2, scriptContext), PropertyNone);
  2196. library->AddMember(mathObject, PropertyIds::LOG2E, JavascriptNumber::New(Math::LOG2E, scriptContext), PropertyNone);
  2197. library->AddMember(mathObject, PropertyIds::LOG10E, JavascriptNumber::New(Math::LOG10E, scriptContext), PropertyNone);
  2198. library->AddMember(mathObject, PropertyIds::PI, library->pi, PropertyNone);
  2199. library->AddMember(mathObject, PropertyIds::SQRT1_2, JavascriptNumber::New(Math::SQRT1_2, scriptContext), PropertyNone);
  2200. library->AddMember(mathObject, PropertyIds::SQRT2, JavascriptNumber::New(Math::SQRT2, scriptContext), PropertyNone);
  2201. JavascriptFunction ** builtinFuncs = library->GetBuiltinFunctions();
  2202. builtinFuncs[BuiltinFunction::Math_Abs] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::abs, &Math::EntryInfo::Abs, 1);
  2203. builtinFuncs[BuiltinFunction::Math_Acos] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::acos, &Math::EntryInfo::Acos, 1);
  2204. builtinFuncs[BuiltinFunction::Math_Asin] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::asin, &Math::EntryInfo::Asin, 1);
  2205. builtinFuncs[BuiltinFunction::Math_Atan] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::atan, &Math::EntryInfo::Atan, 1);
  2206. builtinFuncs[BuiltinFunction::Math_Atan2] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::atan2, &Math::EntryInfo::Atan2, 2);
  2207. builtinFuncs[BuiltinFunction::Math_Cos] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::cos, &Math::EntryInfo::Cos, 1);
  2208. builtinFuncs[BuiltinFunction::Math_Ceil] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::ceil, &Math::EntryInfo::Ceil, 1);
  2209. builtinFuncs[BuiltinFunction::Math_Exp] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::exp, &Math::EntryInfo::Exp, 1);
  2210. builtinFuncs[BuiltinFunction::Math_Floor] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::floor, &Math::EntryInfo::Floor, 1);
  2211. builtinFuncs[BuiltinFunction::Math_Log] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::log, &Math::EntryInfo::Log, 1);
  2212. builtinFuncs[BuiltinFunction::Math_Max] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::max, &Math::EntryInfo::Max, 2);
  2213. builtinFuncs[BuiltinFunction::Math_Min] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::min, &Math::EntryInfo::Min, 2);
  2214. builtinFuncs[BuiltinFunction::Math_Pow] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::pow, &Math::EntryInfo::Pow, 2);
  2215. builtinFuncs[BuiltinFunction::Math_Random] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::random, &Math::EntryInfo::Random, 0);
  2216. builtinFuncs[BuiltinFunction::Math_Round] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::round, &Math::EntryInfo::Round, 1);
  2217. builtinFuncs[BuiltinFunction::Math_Sin] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::sin, &Math::EntryInfo::Sin, 1);
  2218. builtinFuncs[BuiltinFunction::Math_Sqrt] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::sqrt, &Math::EntryInfo::Sqrt, 1);
  2219. builtinFuncs[BuiltinFunction::Math_Tan] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::tan, &Math::EntryInfo::Tan, 1);
  2220. if (scriptContext->GetConfig()->IsES6MathExtensionsEnabled())
  2221. {
  2222. builtinFuncs[BuiltinFunction::Math_Imul] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::imul, &Math::EntryInfo::Imul, 2);
  2223. builtinFuncs[BuiltinFunction::Math_Fround] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::fround, &Math::EntryInfo::Fround, 1);
  2224. /*builtinFuncs[BuiltinFunction::Math_Log10] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::log10, &Math::EntryInfo::Log10, 1);
  2225. /*builtinFuncs[BuiltinFunction::Math_Log2] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::log2, &Math::EntryInfo::Log2, 1);
  2226. /*builtinFuncs[BuiltinFunction::Math_Log1p] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::log1p, &Math::EntryInfo::Log1p, 1);
  2227. /*builtinFuncs[BuiltinFunction::Math_Expm1] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::expm1, &Math::EntryInfo::Expm1, 1);
  2228. /*builtinFuncs[BuiltinFunction::Math_Cosh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::cosh, &Math::EntryInfo::Cosh, 1);
  2229. /*builtinFuncs[BuiltinFunction::Math_Sinh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::sinh, &Math::EntryInfo::Sinh, 1);
  2230. /*builtinFuncs[BuiltinFunction::Math_Tanh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::tanh, &Math::EntryInfo::Tanh, 1);
  2231. /*builtinFuncs[BuiltinFunction::Math_Acosh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::acosh, &Math::EntryInfo::Acosh, 1);
  2232. /*builtinFuncs[BuiltinFunction::Math_Asinh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::asinh, &Math::EntryInfo::Asinh, 1);
  2233. /*builtinFuncs[BuiltinFunction::Math_Atanh] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::atanh, &Math::EntryInfo::Atanh, 1);
  2234. /*builtinFuncs[BuiltinFunction::Math_Hypot] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::hypot, &Math::EntryInfo::Hypot, 2);
  2235. /*builtinFuncs[BuiltinFunction::Math_Trunc] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::trunc, &Math::EntryInfo::Trunc, 1);
  2236. /*builtinFuncs[BuiltinFunction::Math_Sign] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::sign, &Math::EntryInfo::Sign, 1);
  2237. /*builtinFuncs[BuiltinFunction::Math_Cbrt] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::cbrt, &Math::EntryInfo::Cbrt, 1);
  2238. /*builtinFuncs[BuiltinFunction::Math_Clz32] =*/ library->AddFunctionToLibraryObject(mathObject, PropertyIds::clz32, &Math::EntryInfo::Clz32, 1);
  2239. }
  2240. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  2241. {
  2242. library->AddMember(mathObject, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"Math"), PropertyConfigurable);
  2243. }
  2244. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  2245. mathObject->SetHasNoEnumerableProperties(true);
  2246. }
  2247. #if ENABLE_NATIVE_CODEGEN
  2248. // SIMD_JS
  2249. void JavascriptLibrary::InitializeSIMDObject(DynamicObject* simdObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2250. {
  2251. // Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSIMD so that the update is in sync with profiler
  2252. typeHandler->Convert(simdObject, mode, 2);
  2253. JavascriptLibrary* library = simdObject->GetLibrary();
  2254. // only functions to be inlined to be added to builtinFuncs
  2255. JavascriptFunction ** builtinFuncs = library->GetBuiltinFunctions();
  2256. // Float32x4
  2257. JavascriptFunction* float32x4Function = library->AddFunctionToLibraryObject(simdObject, PropertyIds::Float32x4, &SIMDFloat32x4Lib::EntryInfo::Float32x4, 5, PropertyNone);
  2258. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::check, &SIMDFloat32x4Lib::EntryInfo::Check, 2, PropertyNone);
  2259. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::zero, &SIMDFloat32x4Lib::EntryInfo::Zero, 1, PropertyNone);
  2260. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::splat, &SIMDFloat32x4Lib::EntryInfo::Splat, 2, PropertyNone);
  2261. // Lane Access
  2262. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::extractLane, &SIMDFloat32x4Lib::EntryInfo::ExtractLane, 3, PropertyNone);
  2263. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::replaceLane, &SIMDFloat32x4Lib::EntryInfo::ReplaceLane, 4, PropertyNone);
  2264. // type conversions
  2265. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromFloat64x2, &SIMDFloat32x4Lib::EntryInfo::FromFloat64x2, 2, PropertyNone);
  2266. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromFloat64x2Bits, &SIMDFloat32x4Lib::EntryInfo::FromFloat64x2Bits, 2, PropertyNone);
  2267. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromInt32x4, &SIMDFloat32x4Lib::EntryInfo::FromInt32x4, 2, PropertyNone);
  2268. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::fromInt32x4Bits, &SIMDFloat32x4Lib::EntryInfo::FromInt32x4Bits, 2, PropertyNone);
  2269. // binary ops
  2270. builtinFuncs[BuiltinFunction::SIMD_Float32x4_Add] = library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::add, &SIMDFloat32x4Lib::EntryInfo::Add, 3, PropertyNone);
  2271. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::sub, &SIMDFloat32x4Lib::EntryInfo::Sub, 3, PropertyNone);
  2272. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::mul, &SIMDFloat32x4Lib::EntryInfo::Mul, 3, PropertyNone);
  2273. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::div, &SIMDFloat32x4Lib::EntryInfo::Div, 3, PropertyNone);
  2274. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::and, &SIMDFloat32x4Lib::EntryInfo::And, 3, PropertyNone);
  2275. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::or, &SIMDFloat32x4Lib::EntryInfo::Or, 3, PropertyNone);
  2276. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::xor, &SIMDFloat32x4Lib::EntryInfo::Xor, 3, PropertyNone);
  2277. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::min, &SIMDFloat32x4Lib::EntryInfo::Min, 3, PropertyNone);
  2278. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::max, &SIMDFloat32x4Lib::EntryInfo::Max, 3, PropertyNone);
  2279. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::scale, &SIMDFloat32x4Lib::EntryInfo::Scale, 3, PropertyNone);
  2280. // unary ops
  2281. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::abs, &SIMDFloat32x4Lib::EntryInfo::Abs, 2, PropertyNone);
  2282. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::neg, &SIMDFloat32x4Lib::EntryInfo::Neg, 2, PropertyNone);
  2283. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::not, &SIMDFloat32x4Lib::EntryInfo::Not, 2, PropertyNone);
  2284. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::sqrt, &SIMDFloat32x4Lib::EntryInfo::Sqrt, 2, PropertyNone);
  2285. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::reciprocal, &SIMDFloat32x4Lib::EntryInfo::Reciprocal, 2, PropertyNone);
  2286. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::reciprocalSqrt, &SIMDFloat32x4Lib::EntryInfo::ReciprocalSqrt, 2, PropertyNone);
  2287. // compare ops
  2288. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::lessThan, &SIMDFloat32x4Lib::EntryInfo::LessThan, 3, PropertyNone);
  2289. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::lessThanOrEqual, &SIMDFloat32x4Lib::EntryInfo::LessThanOrEqual, 3, PropertyNone);
  2290. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::equal, &SIMDFloat32x4Lib::EntryInfo::Equal, 3, PropertyNone);
  2291. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::notEqual, &SIMDFloat32x4Lib::EntryInfo::NotEqual, 3, PropertyNone);
  2292. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::greaterThan, &SIMDFloat32x4Lib::EntryInfo::GreaterThan, 3, PropertyNone);
  2293. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::greaterThanOrEqual, &SIMDFloat32x4Lib::EntryInfo::GreaterThanOrEqual,3, PropertyNone);
  2294. // others
  2295. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::swizzle, &SIMDFloat32x4Lib::EntryInfo::Swizzle, 3, PropertyNone);
  2296. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::shuffle, &SIMDFloat32x4Lib::EntryInfo::Shuffle, 4, PropertyNone);
  2297. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::clamp, &SIMDFloat32x4Lib::EntryInfo::Clamp, 4, PropertyNone);
  2298. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::select, &SIMDFloat32x4Lib::EntryInfo::Select, 4, PropertyNone);
  2299. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::load, &SIMDFloat32x4Lib::EntryInfo::Load, 3, PropertyNone);
  2300. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::load1, &SIMDFloat32x4Lib::EntryInfo::Load1, 3, PropertyNone);
  2301. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::load2, &SIMDFloat32x4Lib::EntryInfo::Load2, 3, PropertyNone);
  2302. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::load3, &SIMDFloat32x4Lib::EntryInfo::Load3, 3, PropertyNone);
  2303. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::store, &SIMDFloat32x4Lib::EntryInfo::Store, 4, PropertyNone);
  2304. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::store1, &SIMDFloat32x4Lib::EntryInfo::Store1, 4, PropertyNone);
  2305. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::store2, &SIMDFloat32x4Lib::EntryInfo::Store2, 4, PropertyNone);
  2306. library->AddFunctionToLibraryObject(float32x4Function, PropertyIds::store3, &SIMDFloat32x4Lib::EntryInfo::Store3, 4, PropertyNone);
  2307. // end Float32x4
  2308. // Float64x2
  2309. JavascriptFunction* float64x2Function = library->AddFunctionToLibraryObject(simdObject, PropertyIds::Float64x2, &SIMDFloat64x2Lib::EntryInfo::Float64x2, 3, PropertyNone);
  2310. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::check, &SIMDFloat64x2Lib::EntryInfo::Check, 2, PropertyNone);
  2311. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::zero, &SIMDFloat64x2Lib::EntryInfo::Zero, 1, PropertyNone);
  2312. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::splat, &SIMDFloat64x2Lib::EntryInfo::Splat, 2, PropertyNone);
  2313. // type conversions
  2314. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::fromFloat32x4, &SIMDFloat64x2Lib::EntryInfo::FromFloat32x4, 2, PropertyNone);
  2315. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::fromFloat32x4Bits, &SIMDFloat64x2Lib::EntryInfo::FromFloat32x4Bits, 2, PropertyNone);
  2316. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::fromInt32x4, &SIMDFloat64x2Lib::EntryInfo::FromInt32x4, 2, PropertyNone);
  2317. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::fromInt32x4Bits, &SIMDFloat64x2Lib::EntryInfo::FromInt32x4Bits, 2, PropertyNone);
  2318. // binary ops
  2319. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::add, &SIMDFloat64x2Lib::EntryInfo::Add, 3, PropertyNone);
  2320. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::sub, &SIMDFloat64x2Lib::EntryInfo::Sub, 3, PropertyNone);
  2321. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::mul, &SIMDFloat64x2Lib::EntryInfo::Mul, 3, PropertyNone);
  2322. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::div, &SIMDFloat64x2Lib::EntryInfo::Div, 3, PropertyNone);
  2323. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::min, &SIMDFloat64x2Lib::EntryInfo::Min, 3, PropertyNone);
  2324. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::max, &SIMDFloat64x2Lib::EntryInfo::Max, 3, PropertyNone);
  2325. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::scale, &SIMDFloat64x2Lib::EntryInfo::Scale, 3, PropertyNone);
  2326. // unary ops
  2327. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::abs, &SIMDFloat64x2Lib::EntryInfo::Abs, 2, PropertyNone);
  2328. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::neg, &SIMDFloat64x2Lib::EntryInfo::Neg, 2, PropertyNone);
  2329. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::sqrt, &SIMDFloat64x2Lib::EntryInfo::Sqrt, 2, PropertyNone);
  2330. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::reciprocal, &SIMDFloat64x2Lib::EntryInfo::Reciprocal, 2, PropertyNone);
  2331. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::reciprocalSqrt, &SIMDFloat64x2Lib::EntryInfo::ReciprocalSqrt, 2, PropertyNone);
  2332. // compare ops
  2333. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::lessThan, &SIMDFloat64x2Lib::EntryInfo::LessThan, 3, PropertyNone);
  2334. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::lessThanOrEqual, &SIMDFloat64x2Lib::EntryInfo::LessThanOrEqual, 3, PropertyNone);
  2335. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::equal, &SIMDFloat64x2Lib::EntryInfo::Equal, 3, PropertyNone);
  2336. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::notEqual, &SIMDFloat64x2Lib::EntryInfo::NotEqual, 3, PropertyNone);
  2337. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::greaterThan, &SIMDFloat64x2Lib::EntryInfo::GreaterThan, 3, PropertyNone);
  2338. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::greaterThanOrEqual, &SIMDFloat64x2Lib::EntryInfo::GreaterThanOrEqual, 3, PropertyNone);
  2339. // others
  2340. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::swizzle, &SIMDFloat64x2Lib::EntryInfo::Swizzle, 3, PropertyNone);
  2341. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::shuffle, &SIMDFloat64x2Lib::EntryInfo::Shuffle, 4, PropertyNone);
  2342. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::clamp, &SIMDFloat64x2Lib::EntryInfo::Clamp, 4, PropertyNone);
  2343. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::select, &SIMDFloat64x2Lib::EntryInfo::Select, 4, PropertyNone);
  2344. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::load, &SIMDFloat64x2Lib::EntryInfo::Load, 3, PropertyNone);
  2345. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::load1, &SIMDFloat64x2Lib::EntryInfo::Load1, 3, PropertyNone);
  2346. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::store, &SIMDFloat64x2Lib::EntryInfo::Store, 4, PropertyNone);
  2347. library->AddFunctionToLibraryObject(float64x2Function, PropertyIds::store1, &SIMDFloat64x2Lib::EntryInfo::Store1, 4, PropertyNone);
  2348. // end Float64x2
  2349. // Int32x4
  2350. JavascriptFunction* int32x4Function = library->AddFunctionToLibraryObject(simdObject, PropertyIds::Int32x4, &SIMDInt32x4Lib::EntryInfo::Int32x4, 5, PropertyNone);
  2351. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::check, &SIMDInt32x4Lib::EntryInfo::Check, 2, PropertyNone);
  2352. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::zero, &SIMDInt32x4Lib::EntryInfo::Zero, 1, PropertyNone);
  2353. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::splat, &SIMDInt32x4Lib::EntryInfo::Splat, 2, PropertyNone);
  2354. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::bool_, &SIMDInt32x4Lib::EntryInfo::Bool, 5, PropertyNone);
  2355. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::withFlagX, &SIMDInt32x4Lib::EntryInfo::WithFlagX, 3, PropertyNone);
  2356. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::withFlagY, &SIMDInt32x4Lib::EntryInfo::WithFlagY, 3, PropertyNone);
  2357. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::withFlagZ, &SIMDInt32x4Lib::EntryInfo::WithFlagZ, 3, PropertyNone);
  2358. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::withFlagW, &SIMDInt32x4Lib::EntryInfo::WithFlagW, 3, PropertyNone);
  2359. // Lane Access
  2360. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::extractLane, &SIMDInt32x4Lib::EntryInfo::ExtractLane, 3, PropertyNone);
  2361. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::replaceLane, &SIMDInt32x4Lib::EntryInfo::ReplaceLane, 4, PropertyNone);
  2362. // type conversions
  2363. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromFloat64x2, &SIMDInt32x4Lib::EntryInfo::FromFloat64x2, 2, PropertyNone);
  2364. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromFloat64x2Bits, &SIMDInt32x4Lib::EntryInfo::FromFloat64x2Bits, 2, PropertyNone);
  2365. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromFloat32x4, &SIMDInt32x4Lib::EntryInfo::FromFloat32x4, 2, PropertyNone);
  2366. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::fromFloat32x4Bits, &SIMDInt32x4Lib::EntryInfo::FromFloat32x4Bits, 2, PropertyNone);
  2367. // binary ops
  2368. builtinFuncs[BuiltinFunction::SIMD_Int32x4_Add] = library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::add, &SIMDInt32x4Lib::EntryInfo::Add, 3, PropertyNone);
  2369. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::sub, &SIMDInt32x4Lib::EntryInfo::Sub, 3, PropertyNone);
  2370. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::mul, &SIMDInt32x4Lib::EntryInfo::Mul, 3, PropertyNone);
  2371. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::and, &SIMDInt32x4Lib::EntryInfo::And, 3, PropertyNone);
  2372. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::or, &SIMDInt32x4Lib::EntryInfo::Or, 3, PropertyNone);
  2373. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::xor, &SIMDInt32x4Lib::EntryInfo::Xor, 3, PropertyNone);
  2374. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::neg, &SIMDInt32x4Lib::EntryInfo::Neg, 2, PropertyNone);
  2375. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::not, &SIMDInt32x4Lib::EntryInfo::Not, 2, PropertyNone);
  2376. // compare ops
  2377. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::lessThan, &SIMDInt32x4Lib::EntryInfo::LessThan, 3, PropertyNone);
  2378. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::equal, &SIMDInt32x4Lib::EntryInfo::Equal, 3, PropertyNone);
  2379. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::greaterThan, &SIMDInt32x4Lib::EntryInfo::GreaterThan, 3, PropertyNone);
  2380. // others
  2381. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::swizzle, &SIMDInt32x4Lib::EntryInfo::Swizzle, 3, PropertyNone);
  2382. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::shuffle, &SIMDInt32x4Lib::EntryInfo::Shuffle, 4, PropertyNone);
  2383. // shift
  2384. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::shiftLeft, &SIMDInt32x4Lib::EntryInfo::ShiftLeft, 3, PropertyNone);
  2385. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::shiftRightLogical, &SIMDInt32x4Lib::EntryInfo::ShiftRightLogical, 3, PropertyNone);
  2386. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::shiftRightArithmetic, &SIMDInt32x4Lib::EntryInfo::ShiftRightArithmetic, 3, PropertyNone);
  2387. // select
  2388. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::select, &SIMDInt32x4Lib::EntryInfo::Select, 4, PropertyNone);
  2389. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::load, &SIMDInt32x4Lib::EntryInfo::Load, 3, PropertyNone);
  2390. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::load1, &SIMDInt32x4Lib::EntryInfo::Load1, 3, PropertyNone);
  2391. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::load2, &SIMDInt32x4Lib::EntryInfo::Load2, 3, PropertyNone);
  2392. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::load3, &SIMDInt32x4Lib::EntryInfo::Load3, 3, PropertyNone);
  2393. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::store, &SIMDInt32x4Lib::EntryInfo::Store, 4, PropertyNone);
  2394. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::store1, &SIMDInt32x4Lib::EntryInfo::Store1, 4, PropertyNone);
  2395. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::store2, &SIMDInt32x4Lib::EntryInfo::Store2, 4, PropertyNone);
  2396. library->AddFunctionToLibraryObject(int32x4Function, PropertyIds::store3, &SIMDInt32x4Lib::EntryInfo::Store3, 4, PropertyNone);
  2397. // end Int32x4
  2398. // Int8x16
  2399. JavascriptFunction* int8x16Function = library->AddFunctionToLibraryObject(simdObject, PropertyIds::Int8x16, &SIMDInt8x16Lib::EntryInfo::Int8x16, 17, PropertyNone);
  2400. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::check, &SIMDInt8x16Lib::EntryInfo::Check, 2, PropertyNone);
  2401. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::zero, &SIMDInt8x16Lib::EntryInfo::Zero, 1, PropertyNone);
  2402. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::splat, &SIMDInt8x16Lib::EntryInfo::Splat, 2, PropertyNone);
  2403. // type conversions
  2404. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::fromFloat32x4Bits, &SIMDInt8x16Lib::EntryInfo::FromFloat32x4Bits, 2, PropertyNone);
  2405. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::fromInt32x4Bits, &SIMDInt8x16Lib::EntryInfo::FromInt32x4Bits, 2, PropertyNone);
  2406. // binary ops
  2407. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::add, &SIMDInt8x16Lib::EntryInfo::Add, 3, PropertyNone);
  2408. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::sub, &SIMDInt8x16Lib::EntryInfo::Sub, 3, PropertyNone);
  2409. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::mul, &SIMDInt8x16Lib::EntryInfo::Mul, 3, PropertyNone);
  2410. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::and, &SIMDInt8x16Lib::EntryInfo::And, 3, PropertyNone);
  2411. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::or , &SIMDInt8x16Lib::EntryInfo::Or , 3, PropertyNone);
  2412. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::xor, &SIMDInt8x16Lib::EntryInfo::Xor, 3, PropertyNone);
  2413. // unary ops
  2414. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::neg, &SIMDInt8x16Lib::EntryInfo::Neg, 2, PropertyNone);
  2415. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::not, &SIMDInt8x16Lib::EntryInfo::Not, 2, PropertyNone);
  2416. // compare ops
  2417. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::lessThan, &SIMDInt8x16Lib::EntryInfo::LessThan, 3, PropertyNone);
  2418. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::equal , &SIMDInt8x16Lib::EntryInfo::Equal , 3, PropertyNone);
  2419. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::greaterThan, &SIMDInt8x16Lib::EntryInfo::GreaterThan, 3, PropertyNone);
  2420. // shift
  2421. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::shiftLeftByScalar, &SIMDInt8x16Lib::EntryInfo::ShiftLeftByScalar, 3, PropertyNone);
  2422. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::shiftRightLogicalByScalar, &SIMDInt8x16Lib::EntryInfo::ShiftRightLogicalByScalar, 3, PropertyNone);
  2423. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::shiftRightArithmeticByScalar, &SIMDInt8x16Lib::EntryInfo::ShiftRightArithmeticByScalar, 3, PropertyNone);
  2424. // Lane Access
  2425. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::extractLane, &SIMDInt8x16Lib::EntryInfo::ExtractLane, 3, PropertyNone);
  2426. library->AddFunctionToLibraryObject(int8x16Function, PropertyIds::replaceLane, &SIMDInt8x16Lib::EntryInfo::ReplaceLane, 4, PropertyNone);
  2427. // end Int8x16
  2428. }
  2429. #endif
  2430. void JavascriptLibrary::InitializeReflectObject(DynamicObject* reflectObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2431. {
  2432. typeHandler->Convert(reflectObject, mode, 12);
  2433. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterReflect
  2434. // so that the update is in sync with profiler
  2435. ScriptContext* scriptContext = reflectObject->GetScriptContext();
  2436. JavascriptLibrary* library = reflectObject->GetLibrary();
  2437. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::DefineProperty.GetOriginalEntryPoint(),
  2438. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::defineProperty, &JavascriptReflect::EntryInfo::DefineProperty, 3));
  2439. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::DeleteProperty.GetOriginalEntryPoint(),
  2440. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::deleteProperty, &JavascriptReflect::EntryInfo::DeleteProperty, 2));
  2441. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Enumerate.GetOriginalEntryPoint(),
  2442. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::enumerate, &JavascriptReflect::EntryInfo::Enumerate, 1));
  2443. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Get.GetOriginalEntryPoint(),
  2444. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::get, &JavascriptReflect::EntryInfo::Get, 2));
  2445. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::GetOwnPropertyDescriptor.GetOriginalEntryPoint(),
  2446. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::getOwnPropertyDescriptor, &JavascriptReflect::EntryInfo::GetOwnPropertyDescriptor, 2));
  2447. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::GetPrototypeOf.GetOriginalEntryPoint(),
  2448. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::getPrototypeOf, &JavascriptReflect::EntryInfo::GetPrototypeOf, 1));
  2449. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Has.GetOriginalEntryPoint(),
  2450. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::has, &JavascriptReflect::EntryInfo::Has, 2));
  2451. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::IsExtensible.GetOriginalEntryPoint(),
  2452. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::isExtensible, &JavascriptReflect::EntryInfo::IsExtensible, 1));
  2453. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::OwnKeys.GetOriginalEntryPoint(),
  2454. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::ownKeys, &JavascriptReflect::EntryInfo::OwnKeys, 1));
  2455. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::PreventExtensions.GetOriginalEntryPoint(),
  2456. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::preventExtensions, &JavascriptReflect::EntryInfo::PreventExtensions, 1));
  2457. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Set.GetOriginalEntryPoint(),
  2458. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::set, &JavascriptReflect::EntryInfo::Set, 3));
  2459. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::SetPrototypeOf.GetOriginalEntryPoint(),
  2460. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::setPrototypeOf, &JavascriptReflect::EntryInfo::SetPrototypeOf, 2));
  2461. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Apply.GetOriginalEntryPoint(),
  2462. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::apply, &JavascriptReflect::EntryInfo::Apply, 3));
  2463. scriptContext->SetBuiltInLibraryFunction(JavascriptReflect::EntryInfo::Construct.GetOriginalEntryPoint(),
  2464. library->AddFunctionToLibraryObject(reflectObject, PropertyIds::construct, &JavascriptReflect::EntryInfo::Construct, 2));
  2465. }
  2466. void JavascriptLibrary::InitializeStaticValues()
  2467. {
  2468. constructorCacheDefaultInstance = &Js::ConstructorCache::DefaultInstance;
  2469. absDoubleCst = Js::JavascriptNumber::AbsDoubleCst;
  2470. uintConvertConst = Js::JavascriptNumber::UIntConvertConst;
  2471. defaultPropertyDescriptor.SetValue(undefinedValue);
  2472. defaultPropertyDescriptor.SetWritable(false);
  2473. defaultPropertyDescriptor.SetGetter(defaultAccessorFunction);
  2474. defaultPropertyDescriptor.SetSetter(defaultAccessorFunction);
  2475. defaultPropertyDescriptor.SetEnumerable(false);
  2476. defaultPropertyDescriptor.SetConfigurable(false);
  2477. #if !defined(_M_X64_OR_ARM64)
  2478. vtableAddresses[VTableValue::VtableJavascriptNumber] = VirtualTableInfo<Js::JavascriptNumber>::Address;
  2479. #endif
  2480. vtableAddresses[VTableValue::VtableDynamicObject] = VirtualTableInfo<Js::DynamicObject>::Address;
  2481. vtableAddresses[VTableValue::VtableInvalid] = Js::ScriptContextOptimizationOverrideInfo::InvalidVtable;
  2482. vtableAddresses[VTableValue::VtablePropertyString] = VirtualTableInfo<Js::PropertyString>::Address;
  2483. vtableAddresses[VTableValue::VtableJavascriptBoolean] = VirtualTableInfo<Js::JavascriptBoolean>::Address;
  2484. vtableAddresses[VTableValue::VtableSmallDynamicObjectSnapshotEnumeratorWPCache] = VirtualTableInfo<Js::DynamicObjectSnapshotEnumeratorWPCache<Js::BigPropertyIndex,true,false>>::Address;
  2485. vtableAddresses[VTableValue::VtableJavascriptArray] = VirtualTableInfo<Js::JavascriptArray>::Address;
  2486. vtableAddresses[VTableValue::VtableInt8Array] = VirtualTableInfo<Js::Int8Array>::Address;
  2487. vtableAddresses[VTableValue::VtableUint8Array] = VirtualTableInfo<Js::Uint8Array>::Address;
  2488. vtableAddresses[VTableValue::VtableUint8ClampedArray] = VirtualTableInfo<Js::Uint8ClampedArray>::Address;
  2489. vtableAddresses[VTableValue::VtableInt16Array] = VirtualTableInfo<Js::Int16Array>::Address;
  2490. vtableAddresses[VTableValue::VtableUint16Array] = VirtualTableInfo<Js::Uint16Array>::Address;
  2491. vtableAddresses[VTableValue::VtableInt32Array] = VirtualTableInfo<Js::Int32Array>::Address;
  2492. vtableAddresses[VTableValue::VtableUint32Array] = VirtualTableInfo<Js::Uint32Array>::Address;
  2493. vtableAddresses[VTableValue::VtableFloat32Array] = VirtualTableInfo<Js::Float32Array>::Address;
  2494. vtableAddresses[VTableValue::VtableFloat64Array] = VirtualTableInfo<Js::Float64Array>::Address;
  2495. vtableAddresses[VTableValue::VtableInt64Array] = VirtualTableInfo<Js::Int64Array>::Address;
  2496. vtableAddresses[VTableValue::VtableUint64Array] = VirtualTableInfo<Js::Uint64Array>::Address;
  2497. vtableAddresses[VTableValue::VtableInt8VirtualArray] = VirtualTableInfo<Js::Int8VirtualArray>::Address;
  2498. vtableAddresses[VTableValue::VtableUint8VirtualArray] = VirtualTableInfo<Js::Uint8VirtualArray>::Address;
  2499. vtableAddresses[VTableValue::VtableUint8ClampedVirtualArray] = VirtualTableInfo<Js::Uint8ClampedVirtualArray>::Address;
  2500. vtableAddresses[VTableValue::VtableInt16VirtualArray] = VirtualTableInfo<Js::Int16VirtualArray>::Address;
  2501. vtableAddresses[VTableValue::VtableUint16VirtualArray] = VirtualTableInfo<Js::Uint16VirtualArray>::Address;
  2502. vtableAddresses[VTableValue::VtableInt32VirtualArray] = VirtualTableInfo<Js::Int32VirtualArray>::Address;
  2503. vtableAddresses[VTableValue::VtableUint32VirtualArray] = VirtualTableInfo<Js::Uint32VirtualArray>::Address;
  2504. vtableAddresses[VTableValue::VtableFloat32VirtualArray] = VirtualTableInfo<Js::Float32VirtualArray>::Address;
  2505. vtableAddresses[VTableValue::VtableFloat64VirtualArray] = VirtualTableInfo<Js::Float64VirtualArray>::Address;
  2506. vtableAddresses[VTableValue::VtableBoolArray] = VirtualTableInfo<Js::BoolArray>::Address;
  2507. vtableAddresses[VTableValue::VtableCharArray] = VirtualTableInfo<Js::CharArray>::Address;
  2508. vtableAddresses[VTableValue::VtableNativeIntArray] = VirtualTableInfo<Js::JavascriptNativeIntArray>::Address;
  2509. #if ENABLE_COPYONACCESS_ARRAY
  2510. vtableAddresses[VTableValue::VtableCopyOnAccessNativeIntArray] = VirtualTableInfo<Js::JavascriptCopyOnAccessNativeIntArray>::Address;
  2511. #endif
  2512. vtableAddresses[VTableValue::VtableNativeFloatArray] = VirtualTableInfo<Js::JavascriptNativeFloatArray>::Address;
  2513. vtableAddresses[VTableValue::VtableJavascriptNativeIntArray] = VirtualTableInfo<Js::JavascriptNativeIntArray>::Address;
  2514. vtableAddresses[VTableValue::VtableJavascriptRegExp] = VirtualTableInfo<Js::JavascriptRegExp>::Address;
  2515. vtableAddresses[VTableValue::VtableStackScriptFunction] = VirtualTableInfo<Js::StackScriptFunction>::Address;
  2516. vtableAddresses[VTableValue::VtableConcatStringMulti] = VirtualTableInfo<Js::ConcatStringMulti>::Address;
  2517. vtableAddresses[VTableValue::VtableCompoundString] = VirtualTableInfo<Js::CompoundString>::Address;
  2518. // SIMD_JS
  2519. vtableAddresses[VTableValue::VtableSimd128F4] = VirtualTableInfo<Js::JavascriptSIMDFloat32x4>::Address;
  2520. vtableAddresses[VTableValue::VtableSimd128I4] = VirtualTableInfo<Js::JavascriptSIMDInt32x4>::Address;
  2521. }
  2522. //
  2523. // Ensure library ready if started hybrid debugging. Call this to support hybrid debugging when engine starts debug mode.
  2524. //
  2525. HRESULT JavascriptLibrary::EnsureReadyIfHybridDebugging(bool isScriptEngineReady /*= true*/)
  2526. {
  2527. HRESULT hr = S_OK;
  2528. this->isHybridDebugging = Js::Configuration::Global.IsHybridDebugging();
  2529. // If just started hybrid debugging, ensure library objects ready (but only if we can run script now)
  2530. if (this->isHybridDebugging && !this->isLibraryReadyForHybridDebugging && isScriptEngineReady)
  2531. {
  2532. BEGIN_JS_RUNTIME_CALL_EX_AND_TRANSLATE_EXCEPTION_AND_ERROROBJECT_TO_HRESULT_NESTED(scriptContext, /*doCleanup*/false)
  2533. {
  2534. EnsureLibraryReadyForHybridDebugging();
  2535. }
  2536. END_JS_RUNTIME_CALL_AND_TRANSLATE_EXCEPTION_AND_ERROROBJECT_TO_HRESULT(hr)
  2537. }
  2538. return hr;
  2539. }
  2540. //
  2541. // If under hybrid debugging, ensure one object ready (not using deferred type handler).
  2542. //
  2543. DynamicObject* JavascriptLibrary::EnsureReadyIfHybridDebugging(DynamicObject* obj)
  2544. {
  2545. if (IsHybridDebugging())
  2546. {
  2547. Assert(!obj->GetScriptContext()->GetThreadContext()->IsDisableImplicitCall());
  2548. if (!obj->GetTypeHandler()->EnsureObjectReady(obj))
  2549. {
  2550. return obj;
  2551. }
  2552. }
  2553. return obj;
  2554. }
  2555. //
  2556. // When starting hybrid debugging, ensure all library objects ready (not using deferred type handler).
  2557. //
  2558. void JavascriptLibrary::EnsureLibraryReadyForHybridDebugging()
  2559. {
  2560. Assert(IsHybridDebugging() && !isLibraryReadyForHybridDebugging);
  2561. // Note: List all library objects that use DeferredTypeHandler
  2562. DynamicObject* objects[] =
  2563. {
  2564. this->objectPrototype,
  2565. this->arrayPrototype,
  2566. this->arrayBufferPrototype,
  2567. this->dataViewPrototype,
  2568. this->typedArrayPrototype,
  2569. this->Int8ArrayPrototype,
  2570. this->Uint8ArrayPrototype,
  2571. this->Uint8ClampedArrayPrototype,
  2572. this->Int16ArrayPrototype,
  2573. this->Uint16ArrayPrototype,
  2574. this->Int32ArrayPrototype,
  2575. this->Uint32ArrayPrototype,
  2576. this->Float32ArrayPrototype,
  2577. this->Float64ArrayPrototype,
  2578. this->Int64ArrayPrototype,
  2579. this->Uint64ArrayPrototype,
  2580. this->BoolArrayPrototype,
  2581. this->CharArrayPrototype,
  2582. this->booleanPrototype,
  2583. this->datePrototype,
  2584. this->functionPrototype,
  2585. this->numberPrototype,
  2586. this->stringPrototype,
  2587. this->mapPrototype,
  2588. this->setPrototype,
  2589. this->weakMapPrototype,
  2590. this->weakSetPrototype,
  2591. this->regexPrototype,
  2592. this->symbolPrototype,
  2593. this->arrayIteratorPrototype,
  2594. this->promisePrototype,
  2595. this->javascriptEnumeratorIteratorPrototype,
  2596. this->generatorFunctionPrototype,
  2597. this->generatorPrototype,
  2598. this->errorPrototype,
  2599. this->evalErrorPrototype,
  2600. this->rangeErrorPrototype,
  2601. this->referenceErrorPrototype,
  2602. this->syntaxErrorPrototype,
  2603. this->typeErrorPrototype,
  2604. this->uriErrorPrototype,
  2605. this->objectConstructor,
  2606. this->arrayConstructor,
  2607. this->booleanConstructor,
  2608. this->dateConstructor,
  2609. this->functionConstructor,
  2610. this->debugObject,
  2611. this->mathObject,
  2612. this->numberConstructor,
  2613. this->stringConstructor,
  2614. this->regexConstructor,
  2615. this->arrayBufferConstructor,
  2616. this->dataViewConstructor,
  2617. this->typedArrayConstructor,
  2618. this->Int8ArrayConstructor,
  2619. this->Uint8ArrayConstructor,
  2620. this->Uint8ClampedArrayConstructor,
  2621. this->Int16ArrayConstructor,
  2622. this->Uint16ArrayConstructor,
  2623. this->Int32ArrayConstructor,
  2624. this->Uint32ArrayConstructor,
  2625. this->Float32ArrayConstructor,
  2626. this->Float64ArrayConstructor,
  2627. this->JSONObject,
  2628. #ifdef ENABLE_INTL_OBJECT
  2629. this->IntlObject,
  2630. #endif
  2631. this->mapConstructor,
  2632. this->setConstructor,
  2633. this->weakMapConstructor,
  2634. this->weakSetConstructor,
  2635. this->symbolConstructor,
  2636. this->promiseConstructor,
  2637. this->proxyConstructor,
  2638. this->generatorFunctionConstructor,
  2639. this->errorConstructor,
  2640. this->evalErrorConstructor,
  2641. this->rangeErrorConstructor,
  2642. this->referenceErrorConstructor,
  2643. this->syntaxErrorConstructor,
  2644. this->typeErrorConstructor,
  2645. this->uriErrorConstructor,
  2646. };
  2647. Assert(!scriptContext->GetThreadContext()->IsDisableImplicitCall());
  2648. for (int i = 0; i < _countof(objects); i++)
  2649. {
  2650. if (objects[i]) // may be NULL for compat mode
  2651. {
  2652. objects[i]->GetTypeHandler()->EnsureObjectReady(objects[i]);
  2653. }
  2654. }
  2655. isLibraryReadyForHybridDebugging = true;
  2656. }
  2657. // Note: This function is only used in float preferencing scenarios. Should remove it once we do away with float preferencing.
  2658. // Cases like,
  2659. // case PropertyIds::concat:
  2660. // case PropertyIds::indexOf:
  2661. // case PropertyIds::lastIndexOf:
  2662. // case PropertyIds::slice:
  2663. // which have same names for Array and String cannot be resolved just by the property id
  2664. BuiltinFunction JavascriptLibrary::GetBuiltinFunctionForPropId(PropertyId id)
  2665. {
  2666. switch (id)
  2667. {
  2668. case PropertyIds::abs:
  2669. return BuiltinFunction::Math_Abs;
  2670. // For now, avoid mapping Math.atan2 to a direct CRT call, as the
  2671. // fast CRT helper doesn't handle denormals correctly.
  2672. // case PropertyIds::atan2:
  2673. // return BuiltinFunction::Atan2;
  2674. case PropertyIds::acos:
  2675. return BuiltinFunction::Math_Acos;
  2676. case PropertyIds::asin:
  2677. return BuiltinFunction::Math_Asin;
  2678. case PropertyIds::atan:
  2679. return BuiltinFunction::Math_Atan;
  2680. case PropertyIds::cos:
  2681. return BuiltinFunction::Math_Cos;
  2682. case PropertyIds::exp:
  2683. return BuiltinFunction::Math_Exp;
  2684. case PropertyIds::log:
  2685. return BuiltinFunction::Math_Log;
  2686. case PropertyIds::pow:
  2687. return BuiltinFunction::Math_Pow;
  2688. case PropertyIds::random:
  2689. return BuiltinFunction::Math_Random;
  2690. case PropertyIds::sin:
  2691. return BuiltinFunction::Math_Sin;
  2692. case PropertyIds::sqrt:
  2693. return BuiltinFunction::Math_Sqrt;
  2694. case PropertyIds::tan:
  2695. return BuiltinFunction::Math_Tan;
  2696. case PropertyIds::floor:
  2697. return BuiltinFunction::Math_Floor;
  2698. case PropertyIds::ceil:
  2699. return BuiltinFunction::Math_Ceil;
  2700. case PropertyIds::round:
  2701. return BuiltinFunction::Math_Round;
  2702. case PropertyIds::max:
  2703. return BuiltinFunction::Math_Max;
  2704. case PropertyIds::min:
  2705. return BuiltinFunction::Math_Min;
  2706. case PropertyIds::imul:
  2707. return BuiltinFunction::Math_Imul;
  2708. case PropertyIds::fround:
  2709. return BuiltinFunction::Math_Fround;
  2710. case PropertyIds::codePointAt:
  2711. return BuiltinFunction::String_CodePointAt;
  2712. case PropertyIds::push:
  2713. return BuiltinFunction::Array_Push;
  2714. case PropertyIds::concat:
  2715. return BuiltinFunction::Array_Concat;
  2716. case PropertyIds::indexOf:
  2717. return BuiltinFunction::Array_IndexOf;
  2718. case PropertyIds::includes:
  2719. return BuiltinFunction::Array_Includes;
  2720. case PropertyIds::isArray:
  2721. return BuiltinFunction::Array_IsArray;
  2722. case PropertyIds::join:
  2723. return BuiltinFunction::Array_Join;
  2724. case PropertyIds::lastIndexOf:
  2725. return BuiltinFunction::Array_LastIndexOf;
  2726. case PropertyIds::reverse:
  2727. return BuiltinFunction::Array_Reverse;
  2728. case PropertyIds::shift:
  2729. return BuiltinFunction::Array_Shift;
  2730. case PropertyIds::slice:
  2731. return BuiltinFunction::Array_Slice;
  2732. case PropertyIds::splice:
  2733. return BuiltinFunction::Array_Splice;
  2734. case PropertyIds::unshift:
  2735. return BuiltinFunction::Array_Unshift;
  2736. case PropertyIds::apply:
  2737. return BuiltinFunction::Function_Apply;
  2738. case PropertyIds::charAt:
  2739. return BuiltinFunction::String_CharAt;
  2740. case PropertyIds::charCodeAt:
  2741. return BuiltinFunction::String_CharCodeAt;
  2742. case PropertyIds::fromCharCode:
  2743. return BuiltinFunction::String_FromCharCode;
  2744. case PropertyIds::fromCodePoint:
  2745. return BuiltinFunction::String_FromCodePoint;
  2746. case PropertyIds::link:
  2747. return BuiltinFunction::String_Link;
  2748. case PropertyIds::localeCompare:
  2749. return BuiltinFunction::String_LocaleCompare;
  2750. case PropertyIds::match:
  2751. return BuiltinFunction::String_Match;
  2752. case PropertyIds::replace:
  2753. return BuiltinFunction::String_Replace;
  2754. case PropertyIds::search:
  2755. return BuiltinFunction::String_Search;
  2756. case PropertyIds::split:
  2757. return BuiltinFunction::String_Split;
  2758. case PropertyIds::substr:
  2759. return BuiltinFunction::String_Substr;
  2760. case PropertyIds::substring:
  2761. return BuiltinFunction::String_Substring;
  2762. case PropertyIds::toLocaleLowerCase:
  2763. return BuiltinFunction::String_ToLocaleLowerCase;
  2764. case PropertyIds::toLocaleUpperCase:
  2765. return BuiltinFunction::String_ToLocaleUpperCase;
  2766. case PropertyIds::toLowerCase:
  2767. return BuiltinFunction::String_ToLowerCase;
  2768. case PropertyIds::toUpperCase:
  2769. return BuiltinFunction::String_ToUpperCase;
  2770. case PropertyIds::trim:
  2771. return BuiltinFunction::String_Trim;
  2772. case PropertyIds::trimLeft:
  2773. return BuiltinFunction::String_TrimLeft;
  2774. case PropertyIds::trimRight:
  2775. return BuiltinFunction::String_TrimRight;
  2776. case PropertyIds::exec:
  2777. return BuiltinFunction::RegExp_Exec;
  2778. default:
  2779. return BuiltinFunction::None;
  2780. }
  2781. }
  2782. // Returns built-in enum value for given funcInfo. Ultimately this will work for all built-ins (not only Math.*).
  2783. // Used by inliner.
  2784. //static
  2785. BuiltinFunction JavascriptLibrary::GetBuiltInForFuncInfo(FunctionInfo* funcInfo, ScriptContext *scriptContext)
  2786. {
  2787. Assert(funcInfo);
  2788. return scriptContext->GetLibrary()->funcInfoToBuiltinIdMap->Item(funcInfo);
  2789. }
  2790. // Returns true if the function's return type is always float.
  2791. BOOL JavascriptLibrary::IsFltFunc(BuiltinFunction index)
  2792. {
  2793. // Note: MathFuncion is one of built-ins.
  2794. if (!JavascriptLibrary::CanFloatPreferenceFunc(index))
  2795. {
  2796. return FALSE;
  2797. }
  2798. Js::BuiltInFlags builtInFlags = JavascriptLibrary::GetFlagsForBuiltIn(index);
  2799. Js::BuiltInArgSpecizationType dstType = Js::JavascriptLibrary::GetBuiltInArgType(builtInFlags, Js::BuiltInArgShift::BIAS_Dst);
  2800. bool isFloatFunc = dstType == Js::BuiltInArgSpecizationType::BIAST_Float;
  2801. return isFloatFunc;
  2802. }
  2803. size_t const JavascriptLibrary::LibraryFunctionArgC[] = {
  2804. #define LIBRARY_FUNCTION(obj, name, argc, flags, entry) argc,
  2805. #include "LibraryFunction.h"
  2806. #undef LIBRARY_FUNCTION
  2807. 0
  2808. };
  2809. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2810. wchar_t const * const JavascriptLibrary::LibraryFunctionName[] = {
  2811. #define LIBRARY_FUNCTION(obj, name, argc, flags, entry) L#obj L"." L#name,
  2812. #include "LibraryFunction.h"
  2813. #undef LIBRARY_FUNCTION
  2814. 0
  2815. };
  2816. #endif
  2817. int const JavascriptLibrary::LibraryFunctionFlags[] = {
  2818. #define LIBRARY_FUNCTION(obj, name, argc, flags, entry) flags,
  2819. #include "LibraryFunction.h"
  2820. #undef LIBRARY_FUNCTION
  2821. BIF_None
  2822. };
  2823. bool JavascriptLibrary::IsFloatFunctionCallsite(BuiltinFunction index, size_t argc)
  2824. {
  2825. if (IsFltFunc(index))
  2826. {
  2827. Assert(index < BuiltinFunction::Count);
  2828. if (argc)
  2829. {
  2830. return JavascriptLibrary::LibraryFunctionArgC[index] <= (argc - 1 /* this */);
  2831. }
  2832. }
  2833. return false;
  2834. }
  2835. // For abs, min, max -- return can be int or float, but still return true from here.
  2836. BOOL JavascriptLibrary::CanFloatPreferenceFunc(BuiltinFunction index)
  2837. {
  2838. // Shortcut the common case:
  2839. if (index == BuiltinFunction::None)
  2840. {
  2841. return FALSE;
  2842. }
  2843. switch (index)
  2844. {
  2845. case BuiltinFunction::Math_Abs:
  2846. case BuiltinFunction::Math_Acos:
  2847. case BuiltinFunction::Math_Asin:
  2848. case BuiltinFunction::Math_Atan:
  2849. case BuiltinFunction::Math_Cos:
  2850. case BuiltinFunction::Math_Exp:
  2851. case BuiltinFunction::Math_Log:
  2852. case BuiltinFunction::Math_Min:
  2853. case BuiltinFunction::Math_Max:
  2854. case BuiltinFunction::Math_Pow:
  2855. case BuiltinFunction::Math_Random:
  2856. case BuiltinFunction::Math_Sin:
  2857. case BuiltinFunction::Math_Sqrt:
  2858. case BuiltinFunction::Math_Tan:
  2859. case BuiltinFunction::Math_Fround:
  2860. return TRUE;
  2861. }
  2862. return FALSE;
  2863. }
  2864. bool JavascriptLibrary::IsFltBuiltInConst(PropertyId propertyId)
  2865. {
  2866. switch (propertyId)
  2867. {
  2868. case Js::PropertyIds::E:
  2869. case Js::PropertyIds::LN10:
  2870. case Js::PropertyIds::LN2:
  2871. case Js::PropertyIds::LOG2E:
  2872. case Js::PropertyIds::LOG10E:
  2873. case Js::PropertyIds::PI:
  2874. case Js::PropertyIds::SQRT1_2:
  2875. case Js::PropertyIds::SQRT2:
  2876. return true;
  2877. }
  2878. return false;
  2879. }
  2880. void JavascriptLibrary::TypeAndPrototypesAreEnsuredToHaveOnlyWritableDataProperties(Type *const type)
  2881. {
  2882. Assert(type);
  2883. Assert(type->GetScriptContext() == scriptContext);
  2884. Assert(type->AreThisAndPrototypesEnsuredToHaveOnlyWritableDataProperties());
  2885. Assert(!scriptContext->IsClosed());
  2886. if(typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain->Count() == 0)
  2887. {
  2888. scriptContext->RegisterPrototypeChainEnsuredToHaveOnlyWritableDataPropertiesScriptContext();
  2889. }
  2890. typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain->Add(type);
  2891. }
  2892. void JavascriptLibrary::NoPrototypeChainsAreEnsuredToHaveOnlyWritableDataProperties()
  2893. {
  2894. for(int i = 0; i < typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain->Count(); ++i)
  2895. {
  2896. typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain
  2897. ->Item(i)
  2898. ->SetAreThisAndPrototypesEnsuredToHaveOnlyWritableDataProperties(false);
  2899. }
  2900. typesEnsuredToHaveOnlyWritableDataPropertiesInItAndPrototypeChain->ClearAndZero();
  2901. }
  2902. void JavascriptLibrary::InitializeNumberConstructor(DynamicObject* numberConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2903. {
  2904. typeHandler->Convert(numberConstructor, mode, 17);
  2905. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterNumber
  2906. // so that the update is in sync with profiler
  2907. ScriptContext* scriptContext = numberConstructor->GetScriptContext();
  2908. JavascriptLibrary* library = numberConstructor->GetLibrary();
  2909. library->AddMember(numberConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone);
  2910. library->AddMember(numberConstructor, PropertyIds::prototype, library->numberPrototype, PropertyNone);
  2911. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2912. {
  2913. library->AddMember(numberConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Number), PropertyConfigurable);
  2914. }
  2915. library->AddMember(numberConstructor, PropertyIds::MAX_VALUE, library->maxValue, PropertyNone);
  2916. library->AddMember(numberConstructor, PropertyIds::MIN_VALUE, library->minValue, PropertyNone);
  2917. library->AddMember(numberConstructor, PropertyIds::NaN, library->nan, PropertyNone);
  2918. library->AddMember(numberConstructor, PropertyIds::NEGATIVE_INFINITY, library->negativeInfinite, PropertyNone);
  2919. library->AddMember(numberConstructor, PropertyIds::POSITIVE_INFINITY, library->positiveInfinite, PropertyNone);
  2920. if (scriptContext->GetConfig()->IsES6NumberExtensionsEnabled())
  2921. {
  2922. #ifdef DBG
  2923. double epsilon = 0.0;
  2924. for (double next = 1.0; next + 1.0 != 1.0; next = next / 2.0)
  2925. {
  2926. epsilon = next;
  2927. }
  2928. Assert(epsilon == Math::EPSILON);
  2929. #endif
  2930. library->AddMember(numberConstructor, PropertyIds::EPSILON, JavascriptNumber::New(Math::EPSILON, scriptContext), PropertyNone);
  2931. library->AddMember(numberConstructor, PropertyIds::MAX_SAFE_INTEGER, JavascriptNumber::New(Math::MAX_SAFE_INTEGER, scriptContext), PropertyNone);
  2932. library->AddMember(numberConstructor, PropertyIds::MIN_SAFE_INTEGER, JavascriptNumber::New(Math::MIN_SAFE_INTEGER, scriptContext), PropertyNone);
  2933. AssertMsg(library->parseIntFunctionObject != nullptr, "Where is parseIntFunctionObject? Should have been initialized with Global object initialization");
  2934. AssertMsg(library->parseFloatFunctionObject != nullptr, "Where is parseIntFunctionObject? Should have been initialized with Global object initialization");
  2935. library->AddMember(numberConstructor, PropertyIds::parseInt, library->parseIntFunctionObject);
  2936. library->AddMember(numberConstructor, PropertyIds::parseFloat, library->parseFloatFunctionObject);
  2937. library->AddFunctionToLibraryObject(numberConstructor, PropertyIds::isNaN, &JavascriptNumber::EntryInfo::IsNaN, 1);
  2938. library->AddFunctionToLibraryObject(numberConstructor, PropertyIds::isFinite, &JavascriptNumber::EntryInfo::IsFinite, 1);
  2939. library->AddFunctionToLibraryObject(numberConstructor, PropertyIds::isInteger, &JavascriptNumber::EntryInfo::IsInteger, 1);
  2940. library->AddFunctionToLibraryObject(numberConstructor, PropertyIds::isSafeInteger, &JavascriptNumber::EntryInfo::IsSafeInteger, 1);
  2941. }
  2942. numberConstructor->SetHasNoEnumerableProperties(true);
  2943. }
  2944. void JavascriptLibrary::InitializeNumberPrototype(DynamicObject* numberPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2945. {
  2946. typeHandler->Convert(numberPrototype, mode, 8);
  2947. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterNumber
  2948. // so that the update is in sync with profiler
  2949. ScriptContext* scriptContext = numberPrototype->GetScriptContext();
  2950. JavascriptLibrary* library = numberPrototype->GetLibrary();
  2951. library->AddMember(numberPrototype, PropertyIds::constructor, library->numberConstructor);
  2952. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ToExponential.GetOriginalEntryPoint(),
  2953. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::toExponential, &JavascriptNumber::EntryInfo::ToExponential, 1));
  2954. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ToFixed.GetOriginalEntryPoint(),
  2955. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::toFixed, &JavascriptNumber::EntryInfo::ToFixed, 1));
  2956. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ToPrecision.GetOriginalEntryPoint(),
  2957. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::toPrecision, &JavascriptNumber::EntryInfo::ToPrecision, 1));
  2958. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ToLocaleString.GetOriginalEntryPoint(),
  2959. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::toLocaleString, &JavascriptNumber::EntryInfo::ToLocaleString, 0));
  2960. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ToString.GetOriginalEntryPoint(),
  2961. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::toString, &JavascriptNumber::EntryInfo::ToString, 1));
  2962. scriptContext->SetBuiltInLibraryFunction(JavascriptNumber::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  2963. library->AddFunctionToLibraryObject(numberPrototype, PropertyIds::valueOf, &JavascriptNumber::EntryInfo::ValueOf, 0));
  2964. numberPrototype->SetHasNoEnumerableProperties(true);
  2965. }
  2966. void JavascriptLibrary::InitializeObjectConstructor(DynamicObject* objectConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  2967. {
  2968. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterObject
  2969. // so that the update is in sync with profiler
  2970. JavascriptLibrary* library = objectConstructor->GetLibrary();
  2971. ScriptContext* scriptContext = objectConstructor->GetScriptContext();
  2972. int propertyCount = 17;
  2973. if (scriptContext->GetConfig()->IsES6SymbolEnabled())
  2974. {
  2975. propertyCount += 1;
  2976. }
  2977. if (scriptContext->GetConfig()->IsES6ObjectExtensionsEnabled())
  2978. {
  2979. propertyCount += 2;
  2980. }
  2981. typeHandler->Convert(objectConstructor, mode, propertyCount);
  2982. library->AddMember(objectConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone);
  2983. library->AddMember(objectConstructor, PropertyIds::prototype, library->objectPrototype, PropertyNone);
  2984. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  2985. {
  2986. library->AddMember(objectConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Object), PropertyConfigurable);
  2987. }
  2988. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::DefineProperty.GetOriginalEntryPoint(),
  2989. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::defineProperty, &JavascriptObject::EntryInfo::DefineProperty, 3));
  2990. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::GetOwnPropertyDescriptor.GetOriginalEntryPoint(),
  2991. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::getOwnPropertyDescriptor, &JavascriptObject::EntryInfo::GetOwnPropertyDescriptor, 2));
  2992. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::DefineProperties.GetOriginalEntryPoint(),
  2993. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::defineProperties, &JavascriptObject::EntryInfo::DefineProperties, 2));
  2994. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::create, &JavascriptObject::EntryInfo::Create, 2);
  2995. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Seal.GetOriginalEntryPoint(),
  2996. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::seal, &JavascriptObject::EntryInfo::Seal, 1));
  2997. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Freeze.GetOriginalEntryPoint(),
  2998. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::freeze, &JavascriptObject::EntryInfo::Freeze, 1));
  2999. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::PreventExtensions.GetOriginalEntryPoint(),
  3000. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::preventExtensions, &JavascriptObject::EntryInfo::PreventExtensions, 1));
  3001. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::IsSealed.GetOriginalEntryPoint(),
  3002. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::isSealed, &JavascriptObject::EntryInfo::IsSealed, 1));
  3003. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::IsFrozen.GetOriginalEntryPoint(),
  3004. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::isFrozen, &JavascriptObject::EntryInfo::IsFrozen, 1));
  3005. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::IsExtensible.GetOriginalEntryPoint(),
  3006. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::isExtensible, &JavascriptObject::EntryInfo::IsExtensible, 1));
  3007. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::GetPrototypeOf.GetOriginalEntryPoint(),
  3008. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::getPrototypeOf, &JavascriptObject::EntryInfo::GetPrototypeOf, 1));
  3009. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Keys.GetOriginalEntryPoint(),
  3010. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::keys, &JavascriptObject::EntryInfo::Keys, 1));
  3011. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::GetOwnPropertyNames.GetOriginalEntryPoint(),
  3012. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::getOwnPropertyNames, &JavascriptObject::EntryInfo::GetOwnPropertyNames, 1));
  3013. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::SetPrototypeOf.GetOriginalEntryPoint(),
  3014. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::setPrototypeOf, &JavascriptObject::EntryInfo::SetPrototypeOf, 2));
  3015. if (scriptContext->GetConfig()->IsES6SymbolEnabled())
  3016. {
  3017. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::GetOwnPropertySymbols.GetOriginalEntryPoint(),
  3018. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::getOwnPropertySymbols, &JavascriptObject::EntryInfo::GetOwnPropertySymbols, 1));
  3019. }
  3020. if (scriptContext->GetConfig()->IsES6ObjectExtensionsEnabled())
  3021. {
  3022. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Is.GetOriginalEntryPoint(),
  3023. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::is, &JavascriptObject::EntryInfo::Is, 2));
  3024. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::Assign.GetOriginalEntryPoint(),
  3025. library->AddFunctionToLibraryObject(objectConstructor, PropertyIds::assign, &JavascriptObject::EntryInfo::Assign, 2));
  3026. }
  3027. objectConstructor->SetHasNoEnumerableProperties(true);
  3028. }
  3029. void JavascriptLibrary::InitializeObjectPrototype(DynamicObject* objectPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3030. {
  3031. JavascriptLibrary* library = objectPrototype->GetLibrary();
  3032. ScriptContext* scriptContext = objectPrototype->GetScriptContext();
  3033. bool hasAccessors = scriptContext->GetConfig()->Is__proto__Enabled();
  3034. typeHandler->Convert(objectPrototype, mode, 11, hasAccessors);
  3035. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterObject
  3036. // so that the update is in sync with profiler
  3037. library->AddMember(objectPrototype, PropertyIds::constructor, library->objectConstructor);
  3038. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::hasOwnProperty, &JavascriptObject::EntryInfo::HasOwnProperty, 1);
  3039. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::propertyIsEnumerable, &JavascriptObject::EntryInfo::PropertyIsEnumerable, 1);
  3040. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::isPrototypeOf, &JavascriptObject::EntryInfo::IsPrototypeOf, 1);
  3041. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::toLocaleString, &JavascriptObject::EntryInfo::ToLocaleString, 0);
  3042. library->objectToStringFunction = library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::toString, &JavascriptObject::EntryInfo::ToString, 0);
  3043. library->objectValueOfFunction = library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::valueOf, &JavascriptObject::EntryInfo::ValueOf, 0);
  3044. scriptContext->SetBuiltInLibraryFunction(JavascriptObject::EntryInfo::ToString.GetOriginalEntryPoint(), library->objectToStringFunction);
  3045. if (scriptContext->GetConfig()->Is__proto__Enabled())
  3046. {
  3047. bool hadOnlyWritableDataProperties = objectPrototype->GetDynamicType()->GetTypeHandler()->GetHasOnlyWritableDataProperties();
  3048. objectPrototype->SetAccessors(PropertyIds::__proto__, library->Get__proto__getterFunction(), library->Get__proto__setterFunction(), PropertyOperation_NonFixedValue);
  3049. objectPrototype->SetEnumerable(PropertyIds::__proto__, FALSE);
  3050. // Let's pretend __proto__ is actually writable. We'll make sure we always go through a special code path when writing to it.
  3051. if (hadOnlyWritableDataProperties)
  3052. {
  3053. objectPrototype->GetDynamicType()->GetTypeHandler()->SetHasOnlyWritableDataProperties();
  3054. }
  3055. }
  3056. if (scriptContext->GetConfig()->IsDefineGetterSetterEnabled())
  3057. {
  3058. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::__defineGetter__, &JavascriptObject::EntryInfo::DefineGetter, 2);
  3059. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::__defineSetter__, &JavascriptObject::EntryInfo::DefineSetter, 2);
  3060. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::__lookupGetter__, &JavascriptObject::EntryInfo::LookupGetter, 1);
  3061. library->AddFunctionToLibraryObject(objectPrototype, PropertyIds::__lookupSetter__, &JavascriptObject::EntryInfo::LookupSetter, 1);
  3062. }
  3063. objectPrototype->SetHasNoEnumerableProperties(true);
  3064. }
  3065. void JavascriptLibrary::InitializeRegexConstructor(DynamicObject* regexConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3066. {
  3067. JavascriptLibrary* library = regexConstructor->GetLibrary();
  3068. ScriptContext* scriptContext = regexConstructor->GetScriptContext();
  3069. typeHandler->Convert(regexConstructor, mode, 3);
  3070. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterRegExp
  3071. // so that the update is in sync with profiler
  3072. library->AddMember(regexConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(2), PropertyNone);
  3073. library->AddMember(regexConstructor, PropertyIds::prototype, library->regexPrototype, PropertyNone);
  3074. if (scriptContext->GetConfig()->IsES6SpeciesEnabled())
  3075. {
  3076. library->AddAccessorsToLibraryObject(regexConstructor, PropertyIds::_symbolSpecies, &JavascriptRegExp::EntryInfo::GetterSymbolSpecies, nullptr);
  3077. }
  3078. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3079. {
  3080. library->AddMember(regexConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::RegExp), PropertyConfigurable);
  3081. }
  3082. regexConstructor->SetHasNoEnumerableProperties(true);
  3083. }
  3084. void JavascriptLibrary::InitializeRegexPrototype(DynamicObject* regexPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3085. {
  3086. typeHandler->Convert(regexPrototype, mode, 5);
  3087. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterRegExp
  3088. // so that the update is in sync with profiler
  3089. JavascriptFunction * func;
  3090. JavascriptLibrary* library = regexPrototype->GetLibrary();
  3091. JavascriptFunction ** builtinFuncs = library->GetBuiltinFunctions();
  3092. library->AddMember(regexPrototype, PropertyIds::constructor, library->regexConstructor);
  3093. func = library->AddFunctionToLibraryObject(regexPrototype, PropertyIds::exec, &JavascriptRegExp::EntryInfo::Exec, 1);
  3094. builtinFuncs[BuiltinFunction::RegExp_Exec] = func;
  3095. library->AddFunctionToLibraryObject(regexPrototype, PropertyIds::test, &JavascriptRegExp::EntryInfo::Test, 1);
  3096. library->AddFunctionToLibraryObject(regexPrototype, PropertyIds::toString, &JavascriptRegExp::EntryInfo::ToString, 0);
  3097. // This is deprecated. Should be guarded with appropriate version flag.
  3098. library->AddFunctionToLibraryObject(regexPrototype, PropertyIds::compile, &JavascriptRegExp::EntryInfo::Compile, 2);
  3099. const ScriptConfiguration* scriptConfig = regexPrototype->GetScriptContext()->GetConfig();
  3100. if (scriptConfig->IsES6RegExPrototypePropertiesEnabled())
  3101. {
  3102. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::global, &JavascriptRegExp::EntryInfo::GetterGlobal, nullptr);
  3103. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::ignoreCase, &JavascriptRegExp::EntryInfo::GetterIgnoreCase, nullptr);
  3104. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::multiline, &JavascriptRegExp::EntryInfo::GetterMultiline, nullptr);
  3105. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::options, &JavascriptRegExp::EntryInfo::GetterOptions, nullptr);
  3106. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::source, &JavascriptRegExp::EntryInfo::GetterSource, nullptr);
  3107. if (scriptConfig->IsES6RegExStickyEnabled())
  3108. {
  3109. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::sticky, &JavascriptRegExp::EntryInfo::GetterSticky, nullptr);
  3110. }
  3111. if (scriptConfig->IsES6UnicodeExtensionsEnabled())
  3112. {
  3113. library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::unicode, &JavascriptRegExp::EntryInfo::GetterUnicode, nullptr);
  3114. }
  3115. }
  3116. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, library->GetScriptContext()));
  3117. regexPrototype->SetHasNoEnumerableProperties(true);
  3118. }
  3119. void JavascriptLibrary::InitializeStringConstructor(DynamicObject* stringConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3120. {
  3121. typeHandler->Convert(stringConstructor, mode, 6);
  3122. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterString
  3123. // so that the update is in sync with profiler
  3124. JavascriptLibrary* library = stringConstructor->GetLibrary();
  3125. ScriptContext* scriptContext = stringConstructor->GetScriptContext();
  3126. JavascriptFunction ** builtinFuncs = library->GetBuiltinFunctions();
  3127. library->AddMember(stringConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone);
  3128. library->AddMember(stringConstructor, PropertyIds::prototype, library->stringPrototype, PropertyNone);
  3129. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3130. {
  3131. library->AddMember(stringConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::String), PropertyConfigurable);
  3132. }
  3133. builtinFuncs[BuiltinFunction::String_FromCharCode] = library->AddFunctionToLibraryObject(stringConstructor, PropertyIds::fromCharCode, &JavascriptString::EntryInfo::FromCharCode, 1);
  3134. if(scriptContext->GetConfig()->IsES6UnicodeExtensionsEnabled())
  3135. {
  3136. builtinFuncs[BuiltinFunction::String_FromCodePoint] = library->AddFunctionToLibraryObject(stringConstructor, PropertyIds::fromCodePoint, &JavascriptString::EntryInfo::FromCodePoint, 1);
  3137. }
  3138. if (scriptContext->GetConfig()->IsES6StringTemplateEnabled())
  3139. {
  3140. /* No inlining String_Raw */ library->AddFunctionToLibraryObject(stringConstructor, PropertyIds::raw, &JavascriptString::EntryInfo::Raw, 1);
  3141. }
  3142. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  3143. stringConstructor->SetHasNoEnumerableProperties(true);
  3144. }
  3145. void JavascriptLibrary::InitializeStringPrototype(DynamicObject* stringPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3146. {
  3147. typeHandler->Convert(stringPrototype, mode, 38);
  3148. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterString
  3149. // so that the update is in sync with profiler
  3150. ScriptContext* scriptContext = stringPrototype->GetScriptContext();
  3151. JavascriptLibrary* library = stringPrototype->GetLibrary();
  3152. JavascriptFunction ** builtinFuncs = library->GetBuiltinFunctions();
  3153. library->AddMember(stringPrototype, PropertyIds::constructor, library->stringConstructor);
  3154. builtinFuncs[BuiltinFunction::String_IndexOf] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::indexOf, &JavascriptString::EntryInfo::IndexOf, 1);
  3155. builtinFuncs[BuiltinFunction::String_LastIndexOf] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::lastIndexOf, &JavascriptString::EntryInfo::LastIndexOf, 1);
  3156. builtinFuncs[BuiltinFunction::String_Replace] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::replace, &JavascriptString::EntryInfo::Replace, 2);
  3157. builtinFuncs[BuiltinFunction::String_Search] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::search, &JavascriptString::EntryInfo::Search, 1);
  3158. builtinFuncs[BuiltinFunction::String_Slice] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::slice, &JavascriptString::EntryInfo::Slice, 2);
  3159. if (CONFIG_FLAG(ES6Unicode))
  3160. {
  3161. builtinFuncs[BuiltinFunction::String_CodePointAt] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::codePointAt, &JavascriptString::EntryInfo::CodePointAt, 1);
  3162. /* builtinFuncs[BuiltinFunction::String_Normalize] =*/library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::normalize, &JavascriptString::EntryInfo::Normalize, 0);
  3163. }
  3164. builtinFuncs[BuiltinFunction::String_CharAt] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::charAt, &JavascriptString::EntryInfo::CharAt, 1);
  3165. builtinFuncs[BuiltinFunction::String_CharCodeAt] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::charCodeAt, &JavascriptString::EntryInfo::CharCodeAt, 1);
  3166. builtinFuncs[BuiltinFunction::String_Concat] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::concat, &JavascriptString::EntryInfo::Concat, 1);
  3167. builtinFuncs[BuiltinFunction::String_LocaleCompare] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::localeCompare, &JavascriptString::EntryInfo::LocaleCompare, 1);
  3168. builtinFuncs[BuiltinFunction::String_Match] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::match, &JavascriptString::EntryInfo::Match, 1);
  3169. builtinFuncs[BuiltinFunction::String_Split] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::split, &JavascriptString::EntryInfo::Split, 2);
  3170. builtinFuncs[BuiltinFunction::String_Substring] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::substring, &JavascriptString::EntryInfo::Substring, 2);
  3171. builtinFuncs[BuiltinFunction::String_Substr] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::substr, &JavascriptString::EntryInfo::Substr, 2);
  3172. builtinFuncs[BuiltinFunction::String_ToLocaleLowerCase] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::toLocaleLowerCase, &JavascriptString::EntryInfo::ToLocaleLowerCase, 0);
  3173. builtinFuncs[BuiltinFunction::String_ToLocaleUpperCase] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::toLocaleUpperCase, &JavascriptString::EntryInfo::ToLocaleUpperCase, 0);
  3174. builtinFuncs[BuiltinFunction::String_ToLowerCase] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::toLowerCase, &JavascriptString::EntryInfo::ToLowerCase, 0);
  3175. scriptContext->SetBuiltInLibraryFunction(JavascriptString::EntryInfo::ToString.GetOriginalEntryPoint(),
  3176. library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::toString, &JavascriptString::EntryInfo::ToString, 0));
  3177. builtinFuncs[BuiltinFunction::String_ToUpperCase] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::toUpperCase, &JavascriptString::EntryInfo::ToUpperCase, 0);
  3178. builtinFuncs[BuiltinFunction::String_Trim] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::trim, &JavascriptString::EntryInfo::Trim, 0);
  3179. scriptContext->SetBuiltInLibraryFunction(JavascriptString::EntryInfo::ValueOf.GetOriginalEntryPoint(),
  3180. library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::valueOf, &JavascriptString::EntryInfo::ValueOf, 0));
  3181. if (scriptContext->GetConfig()->SupportsES3Extensions())
  3182. {
  3183. /* No inlining String_Anchor */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::anchor, &JavascriptString::EntryInfo::Anchor, 1);
  3184. /* No inlining String_Big */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::big, &JavascriptString::EntryInfo::Big, 0);
  3185. /* No inlining String_Blink */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::blink, &JavascriptString::EntryInfo::Blink, 0);
  3186. /* No inlining String_Bold */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::bold, &JavascriptString::EntryInfo::Bold, 0);
  3187. /* No inlining String_Fixed */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::fixed, &JavascriptString::EntryInfo::Fixed, 0);
  3188. /* No inlining String_FontColor */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::fontcolor, &JavascriptString::EntryInfo::FontColor, 1);
  3189. /* No inlining String_FontSize */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::fontsize, &JavascriptString::EntryInfo::FontSize, 1);
  3190. /* No inlining String_Italics */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::italics, &JavascriptString::EntryInfo::Italics, 0);
  3191. builtinFuncs[BuiltinFunction::String_Link] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::link, &JavascriptString::EntryInfo::Link, 1);
  3192. /* No inlining String_Small */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::Small, &JavascriptString::EntryInfo::Small, 0);
  3193. /* No inlining String_Strike */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::strike, &JavascriptString::EntryInfo::Strike, 0);
  3194. /* No inlining String_Sub */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::sub, &JavascriptString::EntryInfo::Sub, 0);
  3195. /* No inlining String_Sup */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::sup, &JavascriptString::EntryInfo::Sup, 0);
  3196. }
  3197. if (scriptContext->GetConfig()->IsES6StringExtensionsEnabled())
  3198. {
  3199. /* No inlining String_Repeat */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::repeat, &JavascriptString::EntryInfo::Repeat, 1);
  3200. /* No inlining String_StartsWith */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::startsWith, &JavascriptString::EntryInfo::StartsWith, 1);
  3201. /* No inlining String_EndsWith */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::endsWith, &JavascriptString::EntryInfo::EndsWith, 1);
  3202. /* No inlining String_Includes */ library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::includes, &JavascriptString::EntryInfo::Includes, 1);
  3203. builtinFuncs[BuiltinFunction::String_TrimLeft] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::trimLeft, &JavascriptString::EntryInfo::TrimLeft, 0);
  3204. builtinFuncs[BuiltinFunction::String_TrimRight] = library->AddFunctionToLibraryObject(stringPrototype, PropertyIds::trimRight, &JavascriptString::EntryInfo::TrimRight, 0);
  3205. }
  3206. if (scriptContext->GetConfig()->IsES6IteratorsEnabled())
  3207. {
  3208. library->AddFunctionToLibraryObjectWithName(stringPrototype, PropertyIds::_symbolIterator, PropertyIds::_RuntimeFunctionNameId_iterator,
  3209. &JavascriptString::EntryInfo::SymbolIterator, 0);
  3210. }
  3211. DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
  3212. stringPrototype->SetHasNoEnumerableProperties(true);
  3213. }
  3214. void JavascriptLibrary::InitializeMapConstructor(DynamicObject* mapConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3215. {
  3216. typeHandler->Convert(mapConstructor, mode, 3);
  3217. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterMap
  3218. // so that the update is in sync with profiler
  3219. JavascriptLibrary* library = mapConstructor->GetLibrary();
  3220. ScriptContext* scriptContext = mapConstructor->GetScriptContext();
  3221. library->AddMember(mapConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone);
  3222. library->AddMember(mapConstructor, PropertyIds::prototype, library->mapPrototype, PropertyNone);
  3223. if (scriptContext->GetConfig()->IsES6SpeciesEnabled())
  3224. {
  3225. library->AddAccessorsToLibraryObject(mapConstructor, PropertyIds::_symbolSpecies, &JavascriptMap::EntryInfo::GetterSymbolSpecies, nullptr);
  3226. }
  3227. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3228. {
  3229. library->AddMember(mapConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Map), PropertyConfigurable);
  3230. }
  3231. mapConstructor->SetHasNoEnumerableProperties(true);
  3232. }
  3233. void JavascriptLibrary::InitializeMapPrototype(DynamicObject* mapPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3234. {
  3235. typeHandler->Convert(mapPrototype, mode, 13, true);
  3236. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterMap
  3237. // so that the update is in sync with profiler
  3238. ScriptContext* scriptContext = mapPrototype->GetScriptContext();
  3239. JavascriptLibrary* library = mapPrototype->GetLibrary();
  3240. library->AddMember(mapPrototype, PropertyIds::constructor, library->mapConstructor);
  3241. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::clear, &JavascriptMap::EntryInfo::Clear, 0);
  3242. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::delete_, &JavascriptMap::EntryInfo::Delete, 1);
  3243. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::forEach, &JavascriptMap::EntryInfo::ForEach, 1);
  3244. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::get, &JavascriptMap::EntryInfo::Get, 1);
  3245. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::has, &JavascriptMap::EntryInfo::Has, 1);
  3246. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::set, &JavascriptMap::EntryInfo::Set, 2);
  3247. library->AddAccessorsToLibraryObject(mapPrototype, PropertyIds::size, &JavascriptMap::EntryInfo::SizeGetter, nullptr);
  3248. if (scriptContext->GetConfig()->IsES6IteratorsEnabled())
  3249. {
  3250. JavascriptFunction* entriesFunc;
  3251. entriesFunc = library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::entries, &JavascriptMap::EntryInfo::Entries, 0);
  3252. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::keys, &JavascriptMap::EntryInfo::Keys, 0);
  3253. library->AddFunctionToLibraryObject(mapPrototype, PropertyIds::values, &JavascriptMap::EntryInfo::Values, 0);
  3254. library->AddMember(mapPrototype, PropertyIds::_symbolIterator, entriesFunc);
  3255. }
  3256. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  3257. {
  3258. library->AddMember(mapPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"Map"), PropertyConfigurable);
  3259. }
  3260. mapPrototype->SetHasNoEnumerableProperties(true);
  3261. }
  3262. void JavascriptLibrary::InitializeSetConstructor(DynamicObject* setConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3263. {
  3264. typeHandler->Convert(setConstructor, mode, 3);
  3265. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSet
  3266. // so that the update is in sync with profiler
  3267. JavascriptLibrary* library = setConstructor->GetLibrary();
  3268. ScriptContext* scriptContext = setConstructor->GetScriptContext();
  3269. library->AddMember(setConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone);
  3270. library->AddMember(setConstructor, PropertyIds::prototype, library->setPrototype, PropertyNone);
  3271. if (scriptContext->GetConfig()->IsES6SpeciesEnabled())
  3272. {
  3273. library->AddAccessorsToLibraryObject(setConstructor, PropertyIds::_symbolSpecies, &JavascriptSet::EntryInfo::GetterSymbolSpecies, nullptr);
  3274. }
  3275. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3276. {
  3277. library->AddMember(setConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::Set), PropertyConfigurable);
  3278. }
  3279. setConstructor->SetHasNoEnumerableProperties(true);
  3280. }
  3281. void JavascriptLibrary::InitializeSetPrototype(DynamicObject* setPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3282. {
  3283. typeHandler->Convert(setPrototype, mode, 12, true);
  3284. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSet
  3285. // so that the update is in sync with profiler
  3286. ScriptContext* scriptContext = setPrototype->GetScriptContext();
  3287. JavascriptLibrary* library = setPrototype->GetLibrary();
  3288. library->AddMember(setPrototype, PropertyIds::constructor, library->setConstructor);
  3289. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::add, &JavascriptSet::EntryInfo::Add, 1);
  3290. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::clear, &JavascriptSet::EntryInfo::Clear, 0);
  3291. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::delete_, &JavascriptSet::EntryInfo::Delete, 1);
  3292. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::forEach, &JavascriptSet::EntryInfo::ForEach, 1);
  3293. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::has, &JavascriptSet::EntryInfo::Has, 1);
  3294. library->AddAccessorsToLibraryObject(setPrototype, PropertyIds::size, &JavascriptSet::EntryInfo::SizeGetter, nullptr);
  3295. if (scriptContext->GetConfig()->IsES6IteratorsEnabled())
  3296. {
  3297. JavascriptFunction* valuesFunc;
  3298. library->AddFunctionToLibraryObject(setPrototype, PropertyIds::entries, &JavascriptSet::EntryInfo::Entries, 0);
  3299. valuesFunc = library->AddFunctionToLibraryObject(setPrototype, PropertyIds::values, &JavascriptSet::EntryInfo::Values, 0);
  3300. library->AddMember(setPrototype, PropertyIds::keys, valuesFunc);
  3301. library->AddMember(setPrototype, PropertyIds::_symbolIterator, valuesFunc);
  3302. }
  3303. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  3304. {
  3305. library->AddMember(setPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"Set"), PropertyConfigurable);
  3306. }
  3307. setPrototype->SetHasNoEnumerableProperties(true);
  3308. }
  3309. void JavascriptLibrary::InitializeWeakMapConstructor(DynamicObject* weakMapConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3310. {
  3311. typeHandler->Convert(weakMapConstructor, mode, 3);
  3312. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterWeakMap
  3313. // so that the update is in sync with profiler
  3314. JavascriptLibrary* library = weakMapConstructor->GetLibrary();
  3315. ScriptContext* scriptContext = weakMapConstructor->GetScriptContext();
  3316. library->AddMember(weakMapConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone);
  3317. library->AddMember(weakMapConstructor, PropertyIds::prototype, library->weakMapPrototype, PropertyNone);
  3318. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3319. {
  3320. library->AddMember(weakMapConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::WeakMap), PropertyConfigurable);
  3321. }
  3322. weakMapConstructor->SetHasNoEnumerableProperties(true);
  3323. }
  3324. void JavascriptLibrary::InitializeWeakMapPrototype(DynamicObject* weakMapPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3325. {
  3326. typeHandler->Convert(weakMapPrototype, mode, 6);
  3327. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterWeakMap
  3328. // so that the update is in sync with profiler
  3329. ScriptContext* scriptContext = weakMapPrototype->GetScriptContext();
  3330. JavascriptLibrary* library = weakMapPrototype->GetLibrary();
  3331. library->AddMember(weakMapPrototype, PropertyIds::constructor, library->weakMapConstructor);
  3332. library->AddFunctionToLibraryObject(weakMapPrototype, PropertyIds::delete_, &JavascriptWeakMap::EntryInfo::Delete, 1);
  3333. library->AddFunctionToLibraryObject(weakMapPrototype, PropertyIds::get, &JavascriptWeakMap::EntryInfo::Get, 1);
  3334. library->AddFunctionToLibraryObject(weakMapPrototype, PropertyIds::has, &JavascriptWeakMap::EntryInfo::Has, 1);
  3335. library->AddFunctionToLibraryObject(weakMapPrototype, PropertyIds::set, &JavascriptWeakMap::EntryInfo::Set, 2);
  3336. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  3337. {
  3338. library->AddMember(weakMapPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"WeakMap"), PropertyConfigurable);
  3339. }
  3340. weakMapPrototype->SetHasNoEnumerableProperties(true);
  3341. }
  3342. void JavascriptLibrary::InitializeWeakSetConstructor(DynamicObject* weakSetConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3343. {
  3344. typeHandler->Convert(weakSetConstructor, mode, 3);
  3345. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterWeakSet
  3346. // so that the update is in sync with profiler
  3347. JavascriptLibrary* library = weakSetConstructor->GetLibrary();
  3348. ScriptContext* scriptContext = weakSetConstructor->GetScriptContext();
  3349. library->AddMember(weakSetConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone);
  3350. library->AddMember(weakSetConstructor, PropertyIds::prototype, library->weakSetPrototype, PropertyNone);
  3351. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3352. {
  3353. library->AddMember(weakSetConstructor, PropertyIds::name, scriptContext->GetPropertyString(PropertyIds::WeakSet), PropertyConfigurable);
  3354. }
  3355. weakSetConstructor->SetHasNoEnumerableProperties(true);
  3356. }
  3357. void JavascriptLibrary::InitializeWeakSetPrototype(DynamicObject* weakSetPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3358. {
  3359. typeHandler->Convert(weakSetPrototype, mode, 5);
  3360. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterWeakSet
  3361. // so that the update is in sync with profiler
  3362. ScriptContext* scriptContext = weakSetPrototype->GetScriptContext();
  3363. JavascriptLibrary* library = weakSetPrototype->GetLibrary();
  3364. library->AddMember(weakSetPrototype, PropertyIds::constructor, library->weakSetConstructor);
  3365. library->AddFunctionToLibraryObject(weakSetPrototype, PropertyIds::add, &JavascriptWeakSet::EntryInfo::Add, 1);
  3366. library->AddFunctionToLibraryObject(weakSetPrototype, PropertyIds::delete_, &JavascriptWeakSet::EntryInfo::Delete, 1);
  3367. library->AddFunctionToLibraryObject(weakSetPrototype, PropertyIds::has, &JavascriptWeakSet::EntryInfo::Has, 1);
  3368. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  3369. {
  3370. library->AddMember(weakSetPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"WeakSet"), PropertyConfigurable);
  3371. }
  3372. weakSetPrototype->SetHasNoEnumerableProperties(true);
  3373. }
  3374. void JavascriptLibrary::InitializeIteratorPrototype(DynamicObject* iteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3375. {
  3376. typeHandler->Convert(iteratorPrototype, mode, 1);
  3377. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterIterator
  3378. // so that the update is in sync with profiler
  3379. JavascriptLibrary* library = iteratorPrototype->GetLibrary();
  3380. library->AddFunctionToLibraryObjectWithName(iteratorPrototype, PropertyIds::_symbolIterator, PropertyIds::_RuntimeFunctionNameId_iterator,
  3381. &JavascriptIterator::EntryInfo::SymbolIterator, 0);
  3382. }
  3383. void JavascriptLibrary::InitializeArrayIteratorPrototype(DynamicObject* arrayIteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3384. {
  3385. typeHandler->Convert(arrayIteratorPrototype, mode, 2);
  3386. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterArrayIterator
  3387. // so that the update is in sync with profiler
  3388. JavascriptLibrary* library = arrayIteratorPrototype->GetLibrary();
  3389. ScriptContext* scriptContext = library->GetScriptContext();
  3390. library->AddFunctionToLibraryObject(arrayIteratorPrototype, PropertyIds::next, &JavascriptArrayIterator::EntryInfo::Next, 0);
  3391. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  3392. {
  3393. library->AddMember(arrayIteratorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"Array Iterator"), PropertyConfigurable);
  3394. }
  3395. }
  3396. void JavascriptLibrary::InitializeMapIteratorPrototype(DynamicObject* mapIteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3397. {
  3398. typeHandler->Convert(mapIteratorPrototype, mode, 2);
  3399. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterMapIterator
  3400. // so that the update is in sync with profiler
  3401. JavascriptLibrary* library = mapIteratorPrototype->GetLibrary();
  3402. ScriptContext* scriptContext = library->GetScriptContext();
  3403. library->AddFunctionToLibraryObject(mapIteratorPrototype, PropertyIds::next, &JavascriptMapIterator::EntryInfo::Next, 0);
  3404. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  3405. {
  3406. library->AddMember(mapIteratorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"Map Iterator"), PropertyConfigurable);
  3407. }
  3408. }
  3409. void JavascriptLibrary::InitializeSetIteratorPrototype(DynamicObject* setIteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3410. {
  3411. typeHandler->Convert(setIteratorPrototype, mode, 2);
  3412. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterSetIterator
  3413. // so that the update is in sync with profiler
  3414. JavascriptLibrary* library = setIteratorPrototype->GetLibrary();
  3415. ScriptContext* scriptContext = library->GetScriptContext();
  3416. library->AddFunctionToLibraryObject(setIteratorPrototype, PropertyIds::next, &JavascriptSetIterator::EntryInfo::Next, 0);
  3417. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  3418. {
  3419. library->AddMember(setIteratorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"Set Iterator"), PropertyConfigurable);
  3420. }
  3421. }
  3422. void JavascriptLibrary::InitializeStringIteratorPrototype(DynamicObject* stringIteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3423. {
  3424. typeHandler->Convert(stringIteratorPrototype, mode, 2);
  3425. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterStringIterator
  3426. // so that the update is in sync with profiler
  3427. JavascriptLibrary* library = stringIteratorPrototype->GetLibrary();
  3428. ScriptContext* scriptContext = library->GetScriptContext();
  3429. library->AddFunctionToLibraryObject(stringIteratorPrototype, PropertyIds::next, &JavascriptStringIterator::EntryInfo::Next, 0);
  3430. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  3431. {
  3432. library->AddMember(stringIteratorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"String Iterator"), PropertyConfigurable);
  3433. }
  3434. }
  3435. void JavascriptLibrary::InitializeJavascriptEnumeratorIteratorPrototype(DynamicObject* javascriptEnumeratorIteratorPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3436. {
  3437. typeHandler->Convert(javascriptEnumeratorIteratorPrototype, mode, 2);
  3438. // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterEnumeratorIterator
  3439. // so that the update is in sync with profiler
  3440. JavascriptLibrary* library = javascriptEnumeratorIteratorPrototype->GetLibrary();
  3441. ScriptContext* scriptContext = library->GetScriptContext();
  3442. library->AddFunctionToLibraryObject(javascriptEnumeratorIteratorPrototype, PropertyIds::next, &JavascriptEnumeratorIterator::EntryInfo::Next, 0);
  3443. if (scriptContext->GetConfig()->IsES6ToStringTagEnabled())
  3444. {
  3445. library->AddMember(javascriptEnumeratorIteratorPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral(L"Enumerator Iterator"), PropertyConfigurable);
  3446. }
  3447. }
  3448. RuntimeFunction* JavascriptLibrary::CreateBuiltinConstructor(FunctionInfo * functionInfo, DynamicTypeHandler * typeHandler, DynamicObject* prototype)
  3449. {
  3450. Assert((functionInfo->GetAttributes() & FunctionInfo::Attributes::ErrorOnNew) == 0);
  3451. if (prototype == nullptr)
  3452. {
  3453. prototype = functionPrototype;
  3454. }
  3455. ConstructorCache* ctorCache = ((functionInfo->GetAttributes() & FunctionInfo::Attributes::SkipDefaultNewObject) != 0) ?
  3456. this->builtInConstructorCache : &ConstructorCache::DefaultInstance;
  3457. return RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, RuntimeFunction,
  3458. DynamicType::New(scriptContext, TypeIds_Function, prototype, functionInfo->GetOriginalEntryPoint(), typeHandler),
  3459. functionInfo, ctorCache);
  3460. }
  3461. JavascriptExternalFunction* JavascriptLibrary::CreateExternalConstructor(Js::ExternalMethod entryPoint, PropertyId nameId, RecyclableObject * prototype)
  3462. {
  3463. Assert(nameId >= Js::InternalPropertyIds::Count && scriptContext->IsTrackedPropertyId(nameId));
  3464. JavascriptExternalFunction* function = this->CreateIdMappedExternalFunction(entryPoint, idMappedFunctionWithPrototypeType);
  3465. function->SetFunctionNameId(TaggedInt::ToVarUnchecked(nameId));
  3466. Js::RecyclableObject* objPrototype;
  3467. if (prototype == nullptr)
  3468. {
  3469. objPrototype = CreateConstructorPrototypeObject(function);
  3470. Assert(!objPrototype->IsEnumerable(Js::PropertyIds::constructor));
  3471. }
  3472. else
  3473. {
  3474. objPrototype = Js::RecyclableObject::FromVar(prototype);
  3475. Js::JavascriptOperators::InitProperty(objPrototype, Js::PropertyIds::constructor, function);
  3476. objPrototype->SetEnumerable(Js::PropertyIds::constructor, false);
  3477. }
  3478. Assert(!function->IsEnumerable(Js::PropertyIds::prototype));
  3479. Assert(!function->IsConfigurable(Js::PropertyIds::prototype));
  3480. Assert(!function->IsWritable(Js::PropertyIds::prototype));
  3481. function->SetPropertyWithAttributes(Js::PropertyIds::prototype, objPrototype, PropertyNone, nullptr);
  3482. if (scriptContext->GetConfig()->IsES6FunctionNameEnabled())
  3483. {
  3484. JavascriptString * functionName = nullptr;
  3485. DebugOnly(bool status =) function->GetFunctionName(&functionName);
  3486. AssertMsg(status,"CreateExternalConstructor sets the functionNameId, status should always be true");
  3487. function->SetPropertyWithAttributes(PropertyIds::name, functionName, PropertyConfigurable, nullptr);
  3488. }
  3489. return function;
  3490. }
  3491. JavascriptExternalFunction* JavascriptLibrary::CreateExternalConstructor(Js::ExternalMethod entryPoint, PropertyId nameId, InitializeMethod method, unsigned short deferredTypeSlots, bool hasAccessors)
  3492. {
  3493. Assert(nameId >= Js::InternalPropertyIds::Count && scriptContext->IsTrackedPropertyId(nameId));
  3494. // Make sure the actual entry point is never null.
  3495. if (entryPoint == nullptr)
  3496. {
  3497. entryPoint = Js::RecyclableObject::DefaultExternalEntryPoint;
  3498. }
  3499. JavascriptExternalFunction* function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptExternalFunction, entryPoint,
  3500. externalConstructorFunctionWithDeferredPrototypeType, method, deferredTypeSlots, hasAccessors);
  3501. function->SetFunctionNameId(TaggedInt::ToVarUnchecked(nameId));
  3502. return function;
  3503. }
  3504. RuntimeFunction* JavascriptLibrary::DefaultCreateFunction(FunctionInfo * functionInfo, int length, DynamicObject * prototype, DynamicType * functionType, PropertyId nameId)
  3505. {
  3506. Assert(nameId >= Js::InternalPropertyIds::Count && scriptContext->IsTrackedPropertyId(nameId));
  3507. return DefaultCreateFunction(functionInfo, length, prototype, functionType, TaggedInt::ToVarUnchecked((int)nameId));
  3508. }
  3509. RuntimeFunction* JavascriptLibrary::DefaultCreateFunction(FunctionInfo * functionInfo, int length, DynamicObject * prototype, DynamicType * functionType, Var nameId)
  3510. {
  3511. Assert(nameId != nullptr);
  3512. RuntimeFunction * function;
  3513. if (nullptr == functionType)
  3514. {
  3515. functionType = (nullptr == prototype) ?
  3516. CreateFunctionWithLengthType(functionInfo) : CreateFunctionWithLengthAndPrototypeType(functionInfo);
  3517. }
  3518. function = RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, RuntimeFunction, functionType, functionInfo);
  3519. if (prototype != nullptr)
  3520. {
  3521. // NOTE: Assume all built in function prototype doesn't contain valueOf or toString that has side effects
  3522. function->SetPropertyWithAttributes(PropertyIds::prototype, prototype, PropertyNone, nullptr, PropertyOperation_None, SideEffects_None);
  3523. }
  3524. function->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(length), PropertyConfigurable, nullptr);
  3525. function->SetFunctionNameId(nameId);
  3526. if (function->GetScriptContext()->GetConfig()->IsES6FunctionNameEnabled())
  3527. {
  3528. JavascriptString * functionName = nullptr;
  3529. DebugOnly(bool status = ) function->GetFunctionName(&functionName);
  3530. AssertMsg(status, "DefaultCreateFunction sets the functionNameId, status should always be true");
  3531. function->SetPropertyWithAttributes(PropertyIds::name, functionName, PropertyConfigurable, nullptr);
  3532. }
  3533. #ifdef HEAP_ENUMERATION_VALIDATION
  3534. if (prototype) prototype->SetHeapEnumValidationCookie(HEAP_ENUMERATION_LIBRARY_OBJECT_COOKIE);
  3535. function->SetHeapEnumValidationCookie(HEAP_ENUMERATION_LIBRARY_OBJECT_COOKIE);
  3536. #endif
  3537. return function;
  3538. }
  3539. JavascriptFunction* JavascriptLibrary::AddFunction(DynamicObject* object, PropertyId propertyId, RuntimeFunction* function)
  3540. {
  3541. AddMember(object, propertyId, function);
  3542. function->SetFunctionNameId(TaggedInt::ToVarUnchecked((int)propertyId));
  3543. return function;
  3544. }
  3545. JavascriptFunction * JavascriptLibrary::AddFunctionToLibraryObject(DynamicObject* object, PropertyId propertyId, FunctionInfo * functionInfo, int length, PropertyAttributes attributes)
  3546. {
  3547. RuntimeFunction* function = DefaultCreateFunction(functionInfo, length, nullptr, nullptr, propertyId);
  3548. AddMember(object, propertyId, function, attributes);
  3549. return function;
  3550. }
  3551. JavascriptFunction * JavascriptLibrary::AddFunctionToLibraryObjectWithPrototype(GlobalObject * object, PropertyId propertyId, FunctionInfo * functionInfo, int length, DynamicObject * prototype, DynamicType * functionType)
  3552. {
  3553. RuntimeFunction* function = DefaultCreateFunction(functionInfo, length, prototype, functionType, propertyId);
  3554. AddMember(object, propertyId, function);
  3555. return function;
  3556. }
  3557. JavascriptFunction * JavascriptLibrary::AddFunctionToLibraryObjectWithName(DynamicObject* object, PropertyId propertyId, PropertyId name, FunctionInfo * functionInfo, int length)
  3558. {
  3559. RuntimeFunction* function = DefaultCreateFunction(functionInfo, length, nullptr, nullptr, name);
  3560. AddMember(object, propertyId, function);
  3561. return function;
  3562. }
  3563. void JavascriptLibrary::AddAccessorsToLibraryObject(DynamicObject* object, PropertyId propertyId, FunctionInfo * getterFunctionInfo, FunctionInfo * setterFunctionInfo)
  3564. {
  3565. AddAccessorsToLibraryObjectWithName(object, propertyId, propertyId, getterFunctionInfo, setterFunctionInfo);
  3566. }
  3567. void JavascriptLibrary::AddAccessorsToLibraryObjectWithName(DynamicObject* object, PropertyId propertyId, PropertyId name, FunctionInfo * getterFunctionInfo, FunctionInfo * setterFunctionInfo)
  3568. {
  3569. Js::RecyclableObject * getter;
  3570. Js::RecyclableObject * setter;
  3571. if (getterFunctionInfo != nullptr)
  3572. {
  3573. Var name_withGetPrefix = LiteralString::Concat(LiteralString::NewCopySz(L"get ", scriptContext), scriptContext->GetPropertyString(name));
  3574. RuntimeFunction* getterFunction = DefaultCreateFunction(getterFunctionInfo, 0, nullptr, nullptr, name_withGetPrefix);
  3575. getterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(0), PropertyNone, nullptr);
  3576. getter = getterFunction;
  3577. }
  3578. else
  3579. {
  3580. getter = GetUndefined();
  3581. }
  3582. if (setterFunctionInfo != nullptr)
  3583. {
  3584. Var name_withSetPrefix = LiteralString::Concat(LiteralString::NewCopySz(L"set ", scriptContext), scriptContext->GetPropertyString(name));
  3585. RuntimeFunction* setterFunction = DefaultCreateFunction(setterFunctionInfo, 0, nullptr, nullptr, name_withSetPrefix);
  3586. setterFunction->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyNone, nullptr);
  3587. setter = setterFunction;
  3588. }
  3589. else
  3590. {
  3591. setter = GetUndefined();
  3592. }
  3593. object->SetAccessors(propertyId, getter, setter);
  3594. object->SetAttributes(propertyId, PropertyConfigurable | PropertyWritable);
  3595. }
  3596. void JavascriptLibrary::AddMember(DynamicObject* object, PropertyId propertyId, Var value)
  3597. {
  3598. AddMember(object, propertyId, value, PropertyBuiltInMethodDefaults);
  3599. }
  3600. void JavascriptLibrary::AddMember(DynamicObject* object, PropertyId propertyId, Var value, PropertyAttributes attributes)
  3601. {
  3602. // NOTE: Assume all built in member doesn't have side effect
  3603. object->SetPropertyWithAttributes(propertyId, value, attributes, nullptr, PropertyOperation_None, SideEffects_None);
  3604. }
  3605. void JavascriptLibrary::InitializeJSONObject(DynamicObject* JSONObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3606. {
  3607. typeHandler->Convert(JSONObject, mode, 3);
  3608. JavascriptLibrary* library = JSONObject->GetLibrary();
  3609. JSONObject->GetScriptContext()->SetBuiltInLibraryFunction(JSON::EntryInfo::Stringify.GetOriginalEntryPoint(),
  3610. library->AddFunctionToLibraryObject(JSONObject, PropertyIds::stringify, &JSON::EntryInfo::Stringify, 3));
  3611. library->AddFunctionToLibraryObject(JSONObject, PropertyIds::parse, &JSON::EntryInfo::Parse, 2);
  3612. if (JSONObject->GetScriptContext()->GetConfig()->IsES6ToStringTagEnabled())
  3613. {
  3614. library->AddMember(JSONObject, PropertyIds::_symbolToStringTag, JSONObject->GetLibrary()->CreateStringFromCppLiteral(L"JSON"), PropertyConfigurable);
  3615. }
  3616. JSONObject->SetHasNoEnumerableProperties(true);
  3617. }
  3618. #if defined(ENABLE_INTL_OBJECT) || defined(ENABLE_PROJECTION)
  3619. void JavascriptLibrary::InitializeEngineInterfaceObject(DynamicObject* engineInterface, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3620. {
  3621. typeHandler->Convert(engineInterface, mode, 3);
  3622. EngineInterfaceObject::FromVar(engineInterface)->Initialize();
  3623. engineInterface->SetHasNoEnumerableProperties(true);
  3624. }
  3625. #endif
  3626. JavascriptFunction* JavascriptLibrary::GetHostPromiseContinuationFunction()
  3627. {
  3628. if (this->hostPromiseContinuationFunction == nullptr)
  3629. {
  3630. this->hostPromiseContinuationFunction = scriptContext->GetHostScriptContext()->InitializeHostPromiseContinuationFunction();
  3631. }
  3632. return this->hostPromiseContinuationFunction;
  3633. }
  3634. void JavascriptLibrary::SetNativeHostPromiseContinuationFunction(PromiseContinuationCallback function, void *state)
  3635. {
  3636. this->nativeHostPromiseContinuationFunction = function;
  3637. this->nativeHostPromiseContinuationFunctionState = state;
  3638. }
  3639. void JavascriptLibrary::PinJsrtContextObject(FinalizableObject* jsrtContext)
  3640. {
  3641. // With JsrtContext supporting cross context, ensure that it doesn't get GCed
  3642. // prematurely. So pin the instance to javascriptLibrary so it will stay alive
  3643. // until any object of it are alive.
  3644. Assert(this->jsrtContextObject == nullptr);
  3645. this->jsrtContextObject = jsrtContext;
  3646. }
  3647. FinalizableObject* JavascriptLibrary::GetPinnedJsrtContextObject()
  3648. {
  3649. return this->jsrtContextObject;
  3650. }
  3651. void JavascriptLibrary::EnqueueTask(Var taskVar)
  3652. {
  3653. Assert(JavascriptFunction::Is(taskVar));
  3654. if (this->nativeHostPromiseContinuationFunction)
  3655. {
  3656. BEGIN_LEAVE_SCRIPT(scriptContext);
  3657. try
  3658. {
  3659. this->nativeHostPromiseContinuationFunction(taskVar, this->nativeHostPromiseContinuationFunctionState);
  3660. }
  3661. catch (...)
  3662. {
  3663. // Hosts are required not to pass exceptions back across the callback boundary. If
  3664. // this happens, it is a bug in the host, not something that we are expected to
  3665. // handle gracefully.
  3666. Js::Throw::FatalInternalError();
  3667. }
  3668. END_LEAVE_SCRIPT(scriptContext);
  3669. }
  3670. else
  3671. {
  3672. JavascriptFunction* hostPromiseContinuationFunction = this->GetHostPromiseContinuationFunction();
  3673. hostPromiseContinuationFunction->GetEntryPoint()(hostPromiseContinuationFunction, Js::CallInfo(Js::CallFlags::CallFlags_Value, 3),
  3674. this->GetUndefined(),
  3675. taskVar,
  3676. JavascriptNumber::ToVar(0, scriptContext));
  3677. }
  3678. }
  3679. #ifdef ENABLE_INTL_OBJECT
  3680. void JavascriptLibrary::ResetIntlObject()
  3681. {
  3682. IntlObject = DynamicObject::New(recycler,
  3683. DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
  3684. DeferredTypeHandler<InitializeIntlObject>::GetDefaultInstance()));
  3685. }
  3686. void JavascriptLibrary::EnsureIntlObjectReady()
  3687. {
  3688. Assert(this->IntlObject != nullptr);
  3689. // For Intl builtins, we need to make sure the Intl object has been initialized before fetching the
  3690. // builtins from the EngineInterfaceObject. This is because the builtins are actually created via
  3691. // Intl.js and are registered into the EngineInterfaceObject as part of Intl object initialization.
  3692. try
  3693. {
  3694. this->IntlObject->GetTypeHandler()->EnsureObjectReady(this->IntlObject);
  3695. }
  3696. catch (JavascriptExceptionObject *e)
  3697. {
  3698. // Propagate the OOM and SOE exceptions only
  3699. if(e == ThreadContext::GetContextForCurrentThread()->GetPendingOOMErrorObject() ||
  3700. e == ThreadContext::GetContextForCurrentThread()->GetPendingSOErrorObject())
  3701. {
  3702. e = e->CloneIfStaticExceptionObject(scriptContext);
  3703. throw e;
  3704. }
  3705. }
  3706. }
  3707. void JavascriptLibrary::InitializeIntlObject(DynamicObject* IntlObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
  3708. {
  3709. typeHandler->Convert(IntlObject, mode, /*initSlotCapacity*/ 2);
  3710. ScriptContext* scriptContext = IntlObject->GetScriptContext();
  3711. if (scriptContext->VerifyAlive()) // Can't initialize if scriptContext closed, will need to run script
  3712. {
  3713. JavascriptLibrary* library = IntlObject->GetLibrary();
  3714. Assert(library->engineInterfaceObject != nullptr);
  3715. IntlEngineInterfaceExtensionObject* intlExtension = static_cast<IntlEngineInterfaceExtensionObject*>(library->GetEngineInterfaceObject()->GetEngineExtension(EngineInterfaceExtensionKind_Intl));
  3716. intlExtension->InjectIntlLibraryCode(scriptContext, IntlObject);
  3717. }
  3718. }
  3719. #endif
  3720. void JavascriptLibrary::SetProfileMode(bool fSet)
  3721. {
  3722. inProfileMode = fSet;
  3723. }
  3724. void JavascriptLibrary::SetDispatchProfile(bool fSet, JavascriptMethod dispatchInvoke)
  3725. {
  3726. if (!fSet)
  3727. {
  3728. this->inDispatchProfileMode = false;
  3729. this->GetScriptContext()->GetHostScriptContext()->SetDispatchInvoke(dispatchInvoke);
  3730. idMappedFunctionWithPrototypeType->SetEntryPoint(JavascriptExternalFunction::ExternalFunctionThunk);
  3731. externalFunctionWithDeferredPrototypeType->SetEntryPoint(JavascriptExternalFunction::ExternalFunctionThunk);
  3732. stdCallFunctionWithDeferredPrototypeType->SetEntryPoint(JavascriptExternalFunction::StdCallExternalFunctionThunk);
  3733. }
  3734. else
  3735. {
  3736. this->inDispatchProfileMode = true;
  3737. this->GetScriptContext()->GetHostScriptContext()->SetDispatchInvoke(dispatchInvoke);
  3738. idMappedFunctionWithPrototypeType->SetEntryPoint(ProfileEntryThunk);
  3739. externalFunctionWithDeferredPrototypeType->SetEntryPoint(ProfileEntryThunk);
  3740. stdCallFunctionWithDeferredPrototypeType->SetEntryPoint(ProfileEntryThunk);
  3741. }
  3742. }
  3743. JavascriptString* JavascriptLibrary::CreateEmptyString()
  3744. {
  3745. return LiteralString::CreateEmptyString(stringTypeStatic);
  3746. }
  3747. JavascriptRegExp* JavascriptLibrary::CreateEmptyRegExp()
  3748. {
  3749. return RecyclerNew(scriptContext->GetRecycler(), JavascriptRegExp, emptyRegexPattern,
  3750. this->GetRegexType());
  3751. }
  3752. void JavascriptLibrary::SetCrossSiteForSharedFunctionType(JavascriptFunction * function)
  3753. {
  3754. Assert(function->GetDynamicType()->GetIsShared());
  3755. if (ScriptFunction::Is(function))
  3756. {
  3757. #if DEBUG
  3758. if (!function->GetFunctionProxy()->GetIsAnonymousFunction())
  3759. {
  3760. Assert(!function->GetFunctionInfo()->IsLambda() ?
  3761. function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler(this->GetScriptContext()) :
  3762. function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredFunctionTypeHandler());
  3763. }
  3764. else
  3765. {
  3766. Assert(!function->GetFunctionInfo()->IsLambda() ?
  3767. function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredAnonymousPrototypeFunctionTypeHandler() :
  3768. function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredAnonymousFunctionTypeHandler());
  3769. }
  3770. #endif
  3771. function->ChangeType();
  3772. function->SetEntryPoint(scriptContext->CurrentCrossSiteThunk);
  3773. }
  3774. else if (BoundFunction::Is(function))
  3775. {
  3776. function->ChangeType();
  3777. function->SetEntryPoint(scriptContext->CurrentCrossSiteThunk);
  3778. }
  3779. else
  3780. {
  3781. DynamicTypeHandler * typeHandler = function->GetDynamicType()->GetTypeHandler();
  3782. if (typeHandler == JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler(this->GetScriptContext()))
  3783. {
  3784. function->ReplaceType(crossSiteDeferredPrototypeFunctionType);
  3785. }
  3786. else if (typeHandler == Js::DeferredTypeHandler<Js::JavascriptExternalFunction::DeferredInitializer>::GetDefaultInstance())
  3787. {
  3788. function->ReplaceType(crossSiteExternalConstructFunctionWithPrototypeType);
  3789. }
  3790. else
  3791. {
  3792. Assert(typeHandler == &SharedIdMappedFunctionWithPrototypeTypeHandler);
  3793. function->ReplaceType(crossSiteIdMappedFunctionWithPrototypeType);
  3794. }
  3795. }
  3796. }
  3797. JavascriptExternalFunction*
  3798. JavascriptLibrary::CreateExternalFunction(ExternalMethod entryPoint, PropertyId nameId, Var signature, JavascriptTypeId prototypeTypeId, UINT64 flags)
  3799. {
  3800. Assert(nameId == 0 || scriptContext->IsTrackedPropertyId(nameId));
  3801. return CreateExternalFunction(entryPoint, TaggedInt::ToVarUnchecked(nameId), signature, prototypeTypeId, flags);
  3802. }
  3803. JavascriptExternalFunction*
  3804. JavascriptLibrary::CreateExternalFunction(ExternalMethod entryPoint, Var nameId, Var signature, JavascriptTypeId prototypeTypeId, UINT64 flags)
  3805. {
  3806. JavascriptExternalFunction* function = EnsureReadyIfHybridDebugging(this->CreateIdMappedExternalFunction(entryPoint, externalFunctionWithDeferredPrototypeType));
  3807. function->SetPrototypeTypeId(prototypeTypeId);
  3808. function->SetExternalFlags(flags);
  3809. function->SetFunctionNameId(nameId);
  3810. function->SetSignature(signature);
  3811. #ifdef HEAP_ENUMERATION_VALIDATION
  3812. function->SetHeapEnumValidationCookie(HEAP_ENUMERATION_LIBRARY_OBJECT_COOKIE);
  3813. #endif
  3814. #ifdef ENABLE_JS_ETW
  3815. JS_ETW(EventWriteJSCRIPT_BUILD_DIRECT_FUNCTION(scriptContext, function, TaggedInt::Is(nameId) ? scriptContext->GetThreadContext()->GetPropertyName(TaggedInt::ToInt32(nameId))->GetBuffer() : ((JavascriptString *)nameId)->GetString()));
  3816. #endif
  3817. #if DBG_DUMP
  3818. if (Js::Configuration::Global.flags.Trace.IsEnabled(Js::HostPhase))
  3819. {
  3820. Output::Print(L"Create new external function: methodAddr= %p, propertyRecord= %p, propertyName= %s\n",
  3821. this, nameId,
  3822. TaggedInt::Is(nameId) ? scriptContext->GetThreadContext()->GetPropertyName(TaggedInt::ToInt32(nameId))->GetBuffer() : ((JavascriptString *)nameId)->GetString());
  3823. }
  3824. #endif
  3825. return function;
  3826. }
  3827. void JavascriptLibrary::EnsureStringTemplateCallsiteObjectList()
  3828. {
  3829. if (this->stringTemplateCallsiteObjectList == nullptr)
  3830. {
  3831. this->stringTemplateCallsiteObjectList = RecyclerNew(GetRecycler(), StringTemplateCallsiteObjectList, GetRecycler());
  3832. }
  3833. }
  3834. void JavascriptLibrary::AddStringTemplateCallsiteObject(RecyclableObject* callsite)
  3835. {
  3836. this->EnsureStringTemplateCallsiteObjectList();
  3837. RecyclerWeakReference<RecyclableObject>* callsiteRef = this->GetRecycler()->CreateWeakReferenceHandle<RecyclableObject>(callsite);
  3838. this->stringTemplateCallsiteObjectList->Item(callsiteRef);
  3839. }
  3840. RecyclableObject* JavascriptLibrary::TryGetStringTemplateCallsiteObject(ParseNodePtr pnode)
  3841. {
  3842. this->EnsureStringTemplateCallsiteObjectList();
  3843. RecyclerWeakReference<RecyclableObject>* callsiteRef = this->stringTemplateCallsiteObjectList->LookupWithKey(pnode);
  3844. if (callsiteRef)
  3845. {
  3846. RecyclableObject* callsite = callsiteRef->Get();
  3847. if (callsite)
  3848. {
  3849. return callsite;
  3850. }
  3851. }
  3852. return nullptr;
  3853. }
  3854. RecyclableObject* JavascriptLibrary::TryGetStringTemplateCallsiteObject(RecyclableObject* callsite)
  3855. {
  3856. this->EnsureStringTemplateCallsiteObjectList();
  3857. RecyclerWeakReference<RecyclableObject>* callsiteRef = this->GetRecycler()->CreateWeakReferenceHandle<RecyclableObject>(callsite);
  3858. RecyclerWeakReference<RecyclableObject>* existingCallsiteRef = this->stringTemplateCallsiteObjectList->LookupWithKey(callsiteRef);
  3859. if (existingCallsiteRef)
  3860. {
  3861. RecyclableObject* existingCallsite = existingCallsiteRef->Get();
  3862. if (existingCallsite)
  3863. {
  3864. return existingCallsite;
  3865. }
  3866. }
  3867. return nullptr;
  3868. }
  3869. #if DBG_DUMP
  3870. const wchar_t* JavascriptLibrary::GetStringTemplateCallsiteObjectKey(Var callsite)
  3871. {
  3872. // Calculate the key for the string template callsite object.
  3873. // Key is combination of the raw string literals delimited by '${}' since string template literals cannot include that symbol.
  3874. // `str1${expr1}str2${expr2}str3` => "str1${}str2${}str3"
  3875. ES5Array* callsiteObj = ES5Array::FromVar(callsite);
  3876. ScriptContext* scriptContext = callsiteObj->GetScriptContext();
  3877. Var var = JavascriptOperators::OP_GetProperty(callsiteObj, Js::PropertyIds::raw, scriptContext);
  3878. ES5Array* rawArray = ES5Array::FromVar(var);
  3879. uint32 arrayLength = rawArray->GetLength();
  3880. uint32 totalStringLength = 0;
  3881. JavascriptString* str;
  3882. Assert(arrayLength != 0);
  3883. // Count the size in characters of the raw strings
  3884. for (uint32 i = 0; i < arrayLength; i++)
  3885. {
  3886. rawArray->DirectGetItemAt(i, &var);
  3887. str = JavascriptString::FromVar(var);
  3888. totalStringLength += str->GetLength();
  3889. }
  3890. uint32 keyLength = totalStringLength + (arrayLength - 1) * 3 + 1;
  3891. wchar_t* key = RecyclerNewArray(scriptContext->GetRecycler(), wchar_t, keyLength);
  3892. wchar_t* ptr = key;
  3893. charcount_t remainingSpace = keyLength;
  3894. // Get first item before loop - there always must be at least one item
  3895. rawArray->DirectGetItemAt(0, &var);
  3896. str = JavascriptString::FromVar(var);
  3897. charcount_t len = str->GetLength();
  3898. js_wmemcpy_s(ptr, remainingSpace, str->GetSz(), len);
  3899. ptr += len;
  3900. remainingSpace -= len;
  3901. // Append a delimiter and the rest of the items
  3902. for (uint32 i = 1; i < arrayLength; i++)
  3903. {
  3904. len = 3; // strlen(L"${}");
  3905. js_wmemcpy_s(ptr, remainingSpace, L"${}", len);
  3906. ptr += len;
  3907. remainingSpace -= len;
  3908. rawArray->DirectGetItemAt(i, &var);
  3909. str = JavascriptString::FromVar(var);
  3910. len = str->GetLength();
  3911. js_wmemcpy_s(ptr, remainingSpace, str->GetSz(), len);
  3912. ptr += len;
  3913. remainingSpace -= len;
  3914. }
  3915. // Ensure string is terminated
  3916. key[keyLength - 1] = L'\0';
  3917. return key;
  3918. }
  3919. #endif
  3920. bool StringTemplateCallsiteObjectComparer<ParseNodePtr>::Equals(ParseNodePtr x, RecyclerWeakReference<Js::RecyclableObject>* y)
  3921. {
  3922. Assert(x != nullptr);
  3923. Assert(x->nop == knopStrTemplate);
  3924. Js::RecyclableObject* obj = y->Get();
  3925. // If the weak reference is dead, we can't be equal.
  3926. if (obj == nullptr)
  3927. {
  3928. return false;
  3929. }
  3930. Js::ES5Array* callsite = Js::ES5Array::FromVar(obj);
  3931. uint32 length = callsite->GetLength();
  3932. Js::Var element;
  3933. Js::JavascriptString* str;
  3934. IdentPtr pid;
  3935. // If the length of string literals is different, these callsite objects are not equal.
  3936. if (x->sxStrTemplate.countStringLiterals != length)
  3937. {
  3938. return false;
  3939. }
  3940. element = Js::JavascriptOperators::OP_GetProperty(callsite, Js::PropertyIds::raw, callsite->GetScriptContext());
  3941. Js::ES5Array* rawArray = Js::ES5Array::FromVar(element);
  3942. // Length of the raw strings should be the same as the cooked string literals.
  3943. Assert(length == rawArray->GetLength());
  3944. x = x->sxStrTemplate.pnodeStringRawLiterals;
  3945. Assert(length != 0);
  3946. for (uint32 i = 0; i < length - 1; i++)
  3947. {
  3948. rawArray->DirectGetItemAt(i, &element);
  3949. str = Js::JavascriptString::FromVar(element);
  3950. Assert(x->nop == knopList);
  3951. Assert(x->sxBin.pnode1->nop == knopStr);
  3952. pid = x->sxBin.pnode1->sxPid.pid;
  3953. // If strings have different length, they aren't equal
  3954. if (pid->Cch() != str->GetLength())
  3955. {
  3956. return false;
  3957. }
  3958. // If the strings at this index are not equal, the callsite objects are not equal.
  3959. if (!JsUtil::CharacterBuffer<wchar_t>::StaticEquals(pid->Psz(), str->GetSz(), str->GetLength()))
  3960. {
  3961. return false;
  3962. }
  3963. x = x->sxBin.pnode2;
  3964. }
  3965. // There should be one more string in the callsite array - and the final string in the ParseNode
  3966. rawArray->DirectGetItemAt(length - 1, &element);
  3967. str = Js::JavascriptString::FromVar(element);
  3968. Assert(x->nop == knopStr);
  3969. pid = x->sxPid.pid;
  3970. // If strings have different length, they aren't equal
  3971. if (pid->Cch() != str->GetLength())
  3972. {
  3973. return false;
  3974. }
  3975. // If the strings at this index are not equal, the callsite objects are not equal.
  3976. if (!JsUtil::CharacterBuffer<wchar_t>::StaticEquals(pid->Psz(), str->GetSz(), str->GetLength()))
  3977. {
  3978. return false;
  3979. }
  3980. return true;
  3981. }
  3982. bool StringTemplateCallsiteObjectComparer<ParseNodePtr>::Equals(ParseNodePtr x, ParseNodePtr y)
  3983. {
  3984. Assert(x != nullptr && y != nullptr);
  3985. Assert(x->nop == knopStrTemplate && y->nop == knopStrTemplate);
  3986. // If the ParseNode is the same, they are equal.
  3987. if (x == y)
  3988. {
  3989. return true;
  3990. }
  3991. x = x->sxStrTemplate.pnodeStringRawLiterals;
  3992. y = y->sxStrTemplate.pnodeStringRawLiterals;
  3993. // If one of the templates only includes one string value, the raw literals ParseNode will
  3994. // be a knopStr instead of knopList.
  3995. if (x->nop != y->nop)
  3996. {
  3997. return false;
  3998. }
  3999. const wchar_t* pid_x;
  4000. const wchar_t* pid_y;
  4001. while (x->nop == knopList)
  4002. {
  4003. // If y is knopStr here, that means x has more strings in the list than y does.
  4004. if (y->nop != knopList)
  4005. {
  4006. return false;
  4007. }
  4008. Assert(x->sxBin.pnode1->nop == knopStr);
  4009. Assert(y->sxBin.pnode1->nop == knopStr);
  4010. pid_x = x->sxBin.pnode1->sxPid.pid->Psz();
  4011. pid_y = y->sxBin.pnode1->sxPid.pid->Psz();
  4012. // If the pid values of each raw string don't match each other, these are different.
  4013. if (!DefaultComparer<const wchar_t*>::Equals(pid_x, pid_y))
  4014. {
  4015. return false;
  4016. }
  4017. x = x->sxBin.pnode2;
  4018. y = y->sxBin.pnode2;
  4019. }
  4020. // If y is still knopList here, that means y has more strings in the list than x does.
  4021. if (y->nop != knopStr)
  4022. {
  4023. return false;
  4024. }
  4025. Assert(x->nop == knopStr);
  4026. pid_x = x->sxPid.pid->Psz();
  4027. pid_y = y->sxPid.pid->Psz();
  4028. // This is the final string in the raw literals list. Return true if they are equal.
  4029. return DefaultComparer<const wchar_t*>::Equals(pid_x, pid_y);
  4030. }
  4031. hash_t StringTemplateCallsiteObjectComparer<ParseNodePtr>::GetHashCode(ParseNodePtr i)
  4032. {
  4033. hash_t hash = 0;
  4034. Assert(i != nullptr);
  4035. Assert(i->nop == knopStrTemplate);
  4036. i = i->sxStrTemplate.pnodeStringRawLiterals;
  4037. const wchar_t* pid;
  4038. while (i->nop == knopList)
  4039. {
  4040. Assert(i->sxBin.pnode1->nop == knopStr);
  4041. pid = i->sxBin.pnode1->sxPid.pid->Psz();
  4042. hash ^= DefaultComparer<const wchar_t*>::GetHashCode(pid);
  4043. hash ^= DefaultComparer<const wchar_t*>::GetHashCode(L"${}");
  4044. i = i->sxBin.pnode2;
  4045. }
  4046. Assert(i->nop == knopStr);
  4047. pid = i->sxPid.pid->Psz();
  4048. hash ^= DefaultComparer<const wchar_t*>::GetHashCode(pid);
  4049. return hash;
  4050. }
  4051. bool StringTemplateCallsiteObjectComparer<RecyclerWeakReference<Js::RecyclableObject>*>::Equals(RecyclerWeakReference<Js::RecyclableObject>* x, ParseNodePtr y)
  4052. {
  4053. return StringTemplateCallsiteObjectComparer<ParseNodePtr>::Equals(y, x);
  4054. }
  4055. bool StringTemplateCallsiteObjectComparer<RecyclerWeakReference<Js::RecyclableObject>*>::Equals(RecyclerWeakReference<Js::RecyclableObject>* x, RecyclerWeakReference<Js::RecyclableObject>* y)
  4056. {
  4057. Js::RecyclableObject* objLeft = x->Get();
  4058. Js::RecyclableObject* objRight = y->Get();
  4059. // If either WeakReference is dead, we can't be equal to anything.
  4060. if (objLeft == nullptr || objRight == nullptr)
  4061. {
  4062. return false;
  4063. }
  4064. // If the Var pointers are the same, they are equal.
  4065. if (objLeft == objRight)
  4066. {
  4067. return true;
  4068. }
  4069. Js::ES5Array* arrayLeft = Js::ES5Array::FromVar(objLeft);
  4070. Js::ES5Array* arrayRight = Js::ES5Array::FromVar(objRight);
  4071. uint32 lengthLeft = arrayLeft->GetLength();
  4072. uint32 lengthRight = arrayRight->GetLength();
  4073. Js::Var varLeft;
  4074. Js::Var varRight;
  4075. // If the length of string literals is different, these callsite objects are not equal.
  4076. if (lengthLeft != lengthRight)
  4077. {
  4078. return false;
  4079. }
  4080. Assert(lengthLeft != 0 && lengthRight != 0);
  4081. // Change to the set of raw strings.
  4082. varLeft = Js::JavascriptOperators::OP_GetProperty(arrayLeft, Js::PropertyIds::raw, arrayLeft->GetScriptContext());
  4083. arrayLeft = Js::ES5Array::FromVar(varLeft);
  4084. varRight = Js::JavascriptOperators::OP_GetProperty(arrayRight, Js::PropertyIds::raw, arrayRight->GetScriptContext());
  4085. arrayRight = Js::ES5Array::FromVar(varRight);
  4086. // Length of the raw strings should be the same as the cooked string literals.
  4087. Assert(lengthLeft == arrayLeft->GetLength());
  4088. Assert(lengthRight == arrayRight->GetLength());
  4089. for (uint32 i = 0; i < lengthLeft; i++)
  4090. {
  4091. arrayLeft->DirectGetItemAt(i, &varLeft);
  4092. arrayRight->DirectGetItemAt(i, &varRight);
  4093. // If the strings at this index are not equal, the callsite objects are not equal.
  4094. if (!Js::JavascriptString::Equals(varLeft, varRight))
  4095. {
  4096. return false;
  4097. }
  4098. }
  4099. return true;
  4100. }
  4101. hash_t StringTemplateCallsiteObjectComparer<RecyclerWeakReference<Js::RecyclableObject>*>::GetHashCode(RecyclerWeakReference<Js::RecyclableObject>* o)
  4102. {
  4103. hash_t hash = 0;
  4104. Js::RecyclableObject* obj = o->Get();
  4105. if (obj == nullptr)
  4106. {
  4107. return hash;
  4108. }
  4109. Js::ES5Array* callsite = Js::ES5Array::FromVar(obj);
  4110. Js::Var var = Js::JavascriptOperators::OP_GetProperty(callsite, Js::PropertyIds::raw, callsite->GetScriptContext());
  4111. Js::ES5Array* rawArray = Js::ES5Array::FromVar(var);
  4112. Assert(rawArray->GetLength() > 0);
  4113. rawArray->DirectGetItemAt(0, &var);
  4114. Js::JavascriptString* str = Js::JavascriptString::FromVar(var);
  4115. hash ^= DefaultComparer<const wchar_t*>::GetHashCode(str->GetSz());
  4116. for (uint32 i = 1; i < rawArray->GetLength(); i++)
  4117. {
  4118. hash ^= DefaultComparer<const wchar_t*>::GetHashCode(L"${}");
  4119. rawArray->DirectGetItemAt(i, &var);
  4120. str = Js::JavascriptString::FromVar(var);
  4121. hash ^= DefaultComparer<const wchar_t*>::GetHashCode(str->GetSz());
  4122. }
  4123. return hash;
  4124. }
  4125. DynamicType * JavascriptLibrary::GetObjectLiteralType(uint16 requestedInlineSlotCapacity)
  4126. {
  4127. if (requestedInlineSlotCapacity <= MaxPreInitializedObjectTypeInlineSlotCount)
  4128. {
  4129. return objectTypes[DynamicTypeHandler::RoundUpInlineSlotCapacity(requestedInlineSlotCapacity) / InlineSlotCountIncrement];
  4130. }
  4131. else
  4132. {
  4133. return objectTypes[PreInitializedObjectTypeCount - 1];
  4134. }
  4135. }
  4136. DynamicType * JavascriptLibrary::GetObjectHeaderInlinedLiteralType(uint16 requestedInlineSlotCapacity)
  4137. {
  4138. Assert(requestedInlineSlotCapacity <= MaxPreInitializedObjectHeaderInlinedTypeInlineSlotCount);
  4139. return
  4140. objectHeaderInlinedTypes[
  4141. (
  4142. DynamicTypeHandler::RoundUpObjectHeaderInlinedInlineSlotCapacity(requestedInlineSlotCapacity) -
  4143. DynamicTypeHandler::GetObjectHeaderInlinableSlotCapacity()
  4144. ) / InlineSlotCountIncrement];
  4145. }
  4146. HeapArgumentsObject* JavascriptLibrary::CreateHeapArguments(Var frameObj, uint32 formalCount)
  4147. {
  4148. AssertMsg(heapArgumentsType, "Where's heapArgumentsType?");
  4149. Recycler *recycler = this->GetRecycler();
  4150. if (!this->arrayPrototypeValuesFunction) //InitializeArrayPrototype can be delay loaded, which could prevent us from access to array.prototype.values
  4151. {
  4152. this->arrayPrototypeValuesFunction = DefaultCreateFunction(&JavascriptArray::EntryInfo::Values, 0, nullptr, nullptr, PropertyIds::values);
  4153. }
  4154. return RecyclerNew(recycler, HeapArgumentsObject, recycler, (ActivationObject*)frameObj, formalCount, heapArgumentsType);
  4155. }
  4156. JavascriptArray* JavascriptLibrary::CreateArray()
  4157. {
  4158. AssertMsg(arrayType, "Where's arrayType?");
  4159. return JavascriptArray::New<Var, JavascriptArray>(this->GetRecycler(), arrayType);
  4160. }
  4161. JavascriptArray* JavascriptLibrary::CreateArray(uint32 length)
  4162. {
  4163. AssertMsg(arrayType, "Where's arrayType?");
  4164. JavascriptArray* arr = JavascriptArray::New<Var, JavascriptArray, 0>(length, arrayType, this->GetRecycler());
  4165. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  4166. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4167. arr->CheckForceES5Array();
  4168. #endif
  4169. return arr;
  4170. }
  4171. JavascriptArray *JavascriptLibrary::CreateArrayOnStack(void *const stackAllocationPointer)
  4172. {
  4173. return JavascriptArray::New<JavascriptArray, 0>(stackAllocationPointer, 0, arrayType);
  4174. }
  4175. JavascriptNativeIntArray* JavascriptLibrary::CreateNativeIntArray()
  4176. {
  4177. AssertMsg(nativeIntArrayType, "Where's nativeIntArrayType?");
  4178. return JavascriptArray::New<int32, JavascriptNativeIntArray>(this->GetRecycler(), nativeIntArrayType);
  4179. }
  4180. JavascriptNativeIntArray* JavascriptLibrary::CreateNativeIntArray(uint32 length)
  4181. {
  4182. AssertMsg(nativeIntArrayType, "Where's nativeIntArrayType?");
  4183. JavascriptNativeIntArray* arr = JavascriptArray::New<int32, JavascriptNativeIntArray, 0>(length, nativeIntArrayType, this->GetRecycler());
  4184. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  4185. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4186. arr->CheckForceES5Array();
  4187. #endif
  4188. return arr;
  4189. }
  4190. JavascriptNativeFloatArray* JavascriptLibrary::CreateNativeFloatArray()
  4191. {
  4192. AssertMsg(nativeFloatArrayType, "Where's nativeFloatArrayType?");
  4193. return JavascriptArray::New<double, JavascriptNativeFloatArray>(this->GetRecycler(), nativeFloatArrayType);
  4194. }
  4195. JavascriptNativeFloatArray* JavascriptLibrary::CreateNativeFloatArray(uint32 length)
  4196. {
  4197. AssertMsg(nativeFloatArrayType, "Where's nativeIntArrayType?");
  4198. JavascriptNativeFloatArray* arr = JavascriptArray::New<double, JavascriptNativeFloatArray, 0>(length, nativeFloatArrayType, this->GetRecycler());
  4199. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  4200. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4201. arr->CheckForceES5Array();
  4202. #endif
  4203. return arr;
  4204. }
  4205. JavascriptArray* JavascriptLibrary::CreateArrayLiteral(uint32 length)
  4206. {
  4207. AssertMsg(arrayType, "Where's arrayType?");
  4208. JavascriptArray* arr = JavascriptArray::NewLiteral<Var, JavascriptArray, 0>(length, arrayType, this->GetRecycler());
  4209. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  4210. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4211. arr->CheckForceES5Array();
  4212. #endif
  4213. return arr;
  4214. }
  4215. JavascriptNativeIntArray* JavascriptLibrary::CreateNativeIntArrayLiteral(uint32 length)
  4216. {
  4217. AssertMsg(nativeIntArrayType, "Where's arrayType?");
  4218. JavascriptNativeIntArray* arr = JavascriptArray::NewLiteral<int32, JavascriptNativeIntArray, 0>(length, nativeIntArrayType, this->GetRecycler());
  4219. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  4220. return arr;
  4221. }
  4222. #if ENABLE_COPYONACCESS_ARRAY
  4223. JavascriptNativeIntArray* JavascriptLibrary::CreateCopyOnAccessNativeIntArrayLiteral(ArrayCallSiteInfo *arrayInfo, FunctionBody *functionBody, const Js::AuxArray<int32> *ints)
  4224. {
  4225. AssertMsg(copyOnAccessNativeIntArrayType, "Where's arrayType?");
  4226. JavascriptNativeIntArray* arr = JavascriptArray::NewCopyOnAccessLiteral<int32, JavascriptCopyOnAccessNativeIntArray, 0>(copyOnAccessNativeIntArrayType, arrayInfo, functionBody, ints, this->GetRecycler());
  4227. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  4228. return arr;
  4229. }
  4230. #endif
  4231. JavascriptNativeFloatArray* JavascriptLibrary::CreateNativeFloatArrayLiteral(uint32 length)
  4232. {
  4233. AssertMsg(nativeFloatArrayType, "Where's arrayType?");
  4234. JavascriptNativeFloatArray* arr = JavascriptArray::NewLiteral<double, JavascriptNativeFloatArray, 0>(length, nativeFloatArrayType, this->GetRecycler());
  4235. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  4236. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4237. arr->CheckForceES5Array();
  4238. #endif
  4239. return arr;
  4240. }
  4241. JavascriptArray* JavascriptLibrary::CreateArray(uint32 length, uint32 size)
  4242. {
  4243. AssertMsg(arrayType, "Where's arrayType?");
  4244. JavascriptArray* arr = RecyclerNew(this->GetRecycler(), JavascriptArray, length, size, arrayType);
  4245. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_ARRAY(arr));
  4246. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4247. arr->CheckForceES5Array();
  4248. #endif
  4249. return arr;
  4250. }
  4251. ArrayBuffer* JavascriptLibrary::CreateArrayBuffer(uint32 length)
  4252. {
  4253. ArrayBuffer* arr = JavascriptArrayBuffer::Create(length, arrayBufferType);
  4254. return arr;
  4255. }
  4256. ArrayBuffer* JavascriptLibrary::CreateArrayBuffer(byte* buffer, uint32 length)
  4257. {
  4258. ArrayBuffer* arr = JavascriptArrayBuffer::Create(buffer, length, arrayBufferType);
  4259. return arr;
  4260. }
  4261. ArrayBuffer* JavascriptLibrary::CreateProjectionArraybuffer(uint32 length)
  4262. {
  4263. ArrayBuffer* arr = ProjectionArrayBuffer::Create(length, arrayBufferType);
  4264. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_OBJECT(arr));
  4265. return arr;
  4266. }
  4267. ArrayBuffer* JavascriptLibrary::CreateProjectionArraybuffer(byte* buffer, uint32 length)
  4268. {
  4269. ArrayBuffer* arr = ProjectionArrayBuffer::Create(buffer, length, arrayBufferType);
  4270. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_OBJECT(arr));
  4271. return arr;
  4272. }
  4273. DataView* JavascriptLibrary::CreateDataView(ArrayBuffer* arrayBuffer, uint32 offset, uint32 length)
  4274. {
  4275. DataView* dataView = RecyclerNew(this->GetRecycler(), DataView, arrayBuffer, offset, length, dataViewType);
  4276. return dataView;
  4277. }
  4278. JavascriptBoolean* JavascriptLibrary::CreateBoolean(BOOL value)
  4279. {
  4280. AssertMsg(booleanTrue, "Where's booleanTrue?");
  4281. AssertMsg(booleanFalse, "Where's booleanFalse?");
  4282. return value ? booleanTrue : booleanFalse;
  4283. }
  4284. JavascriptDate* JavascriptLibrary::CreateDate()
  4285. {
  4286. AssertMsg(dateType, "Where's dateType?");
  4287. return RecyclerNew(this->GetRecycler(), JavascriptDate, 0, dateType);
  4288. }
  4289. JavascriptDate* JavascriptLibrary::CreateDate(double value)
  4290. {
  4291. AssertMsg(dateType, "Where's dateType?");
  4292. return RecyclerNew(this->GetRecycler(), JavascriptDate, value, dateType);
  4293. }
  4294. JavascriptDate* JavascriptLibrary::CreateDate(SYSTEMTIME* pst)
  4295. {
  4296. AssertMsg(dateType, "Where's dateType?");
  4297. double value = DateImplementation::TimeFromSt(pst);
  4298. return CreateDate(value);
  4299. }
  4300. JavascriptMap* JavascriptLibrary::CreateMap()
  4301. {
  4302. AssertMsg(mapType, "Where's mapType?");
  4303. return RecyclerNew(this->GetRecycler(), JavascriptMap, mapType);
  4304. }
  4305. JavascriptSet* JavascriptLibrary::CreateSet()
  4306. {
  4307. AssertMsg(setType, "Where's setType?");
  4308. return RecyclerNew(this->GetRecycler(), JavascriptSet, setType);
  4309. }
  4310. JavascriptWeakMap* JavascriptLibrary::CreateWeakMap()
  4311. {
  4312. AssertMsg(weakMapType, "Where's weakMapType?");
  4313. return RecyclerNewFinalized(this->GetRecycler(), JavascriptWeakMap, weakMapType);
  4314. }
  4315. JavascriptWeakSet* JavascriptLibrary::CreateWeakSet()
  4316. {
  4317. AssertMsg(weakSetType, "Where's weakSetType?");
  4318. return RecyclerNewFinalized(this->GetRecycler(), JavascriptWeakSet, weakSetType);
  4319. }
  4320. JavascriptPromise* JavascriptLibrary::CreatePromise()
  4321. {
  4322. AssertMsg(promiseType, "Where's promiseType?");
  4323. return RecyclerNew(this->GetRecycler(), JavascriptPromise, promiseType);
  4324. }
  4325. JavascriptPromiseAsyncSpawnExecutorFunction* JavascriptLibrary::CreatePromiseAsyncSpawnExecutorFunction(JavascriptMethod entryPoint, JavascriptGenerator* generatorFunction, Var target)
  4326. {
  4327. FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
  4328. DynamicType* type = CreateDeferredPrototypeFunctionType(this->inDispatchProfileMode ? ProfileEntryThunk : entryPoint);
  4329. JavascriptPromiseAsyncSpawnExecutorFunction* function = EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseAsyncSpawnExecutorFunction, type, functionInfo, generatorFunction, target));
  4330. return function;
  4331. }
  4332. JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* JavascriptLibrary::CreatePromiseAsyncSpawnStepArgumentExecutorFunction(JavascriptMethod entryPoint, JavascriptGenerator* generator, Var argument, JavascriptFunction* resolve, JavascriptFunction* reject, bool isReject)
  4333. {
  4334. FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
  4335. DynamicType* type = CreateDeferredPrototypeFunctionType(this->inDispatchProfileMode ? ProfileEntryThunk : entryPoint);
  4336. JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction* function = EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseAsyncSpawnStepArgumentExecutorFunction, type, functionInfo, generator, argument, resolve, reject, isReject));
  4337. return function;
  4338. }
  4339. JavascriptGenerator* JavascriptLibrary::CreateGenerator(Arguments& args, ScriptFunction* scriptFunction, RecyclableObject* prototype)
  4340. {
  4341. Assert(scriptContext->GetConfig()->IsES6GeneratorsEnabled());
  4342. DynamicType* generatorType = CreateGeneratorType(prototype);
  4343. return RecyclerNew(this->GetRecycler(), JavascriptGenerator, generatorType, args, scriptFunction);
  4344. }
  4345. JavascriptError* JavascriptLibrary::CreateError()
  4346. {
  4347. AssertMsg(errorType, "Where's errorType?");
  4348. JavascriptError *pError = RecyclerNew(this->GetRecycler(), JavascriptError, errorType);
  4349. JavascriptError::SetErrorType(pError, kjstError);
  4350. return pError;
  4351. }
  4352. JavascriptSymbol* JavascriptLibrary::CreateSymbol(JavascriptString* description)
  4353. {
  4354. return this->CreateSymbol(description->GetString(), (int)description->GetLength());
  4355. }
  4356. JavascriptSymbol* JavascriptLibrary::CreateSymbol(const wchar_t* description, int descriptionLength)
  4357. {
  4358. ENTER_PINNED_SCOPE(const Js::PropertyRecord, propertyRecord);
  4359. propertyRecord = this->scriptContext->GetThreadContext()->UncheckedAddPropertyId(description, descriptionLength, /*bind*/false, /*isSymbol*/true);
  4360. LEAVE_PINNED_SCOPE();
  4361. return this->CreateSymbol(propertyRecord);
  4362. }
  4363. JavascriptSymbol* JavascriptLibrary::CreateSymbol(const PropertyRecord* propertyRecord)
  4364. {
  4365. AssertMsg(symbolTypeStatic, "Where's symbolTypeStatic?");
  4366. return RecyclerNew(this->GetRecycler(), JavascriptSymbol, propertyRecord, symbolTypeStatic);
  4367. }
  4368. JavascriptError* JavascriptLibrary::CreateExternalError(ErrorTypeEnum errorTypeEnum)
  4369. {
  4370. DynamicType* baseErrorType = NULL;
  4371. switch (errorTypeEnum)
  4372. {
  4373. case kjstError:
  4374. default:
  4375. baseErrorType = errorType;
  4376. break;
  4377. case kjstRangeError:
  4378. baseErrorType = rangeErrorType;
  4379. break;
  4380. case kjstReferenceError:
  4381. baseErrorType = referenceErrorType;
  4382. break;
  4383. case kjstSyntaxError:
  4384. baseErrorType = syntaxErrorType;
  4385. break;
  4386. case kjstTypeError:
  4387. baseErrorType = typeErrorType;
  4388. break;
  4389. case kjstURIError:
  4390. baseErrorType = uriErrorType;
  4391. break;
  4392. }
  4393. JavascriptError *pError = RecyclerNew(recycler, JavascriptError, baseErrorType, TRUE);
  4394. JavascriptError::SetErrorType(pError, errorTypeEnum);
  4395. return pError;
  4396. }
  4397. JavascriptError* JavascriptLibrary::CreateEvalError()
  4398. {
  4399. AssertMsg(evalErrorType, "Where's evalErrorType?");
  4400. JavascriptError *pError = RecyclerNew(this->GetRecycler(), JavascriptError, evalErrorType);
  4401. JavascriptError::SetErrorType(pError, kjstEvalError);
  4402. return pError;
  4403. }
  4404. JavascriptError* JavascriptLibrary::CreateRangeError()
  4405. {
  4406. AssertMsg(rangeErrorType, "Where's rangeErrorType?");
  4407. JavascriptError *pError = RecyclerNew(this->GetRecycler(), JavascriptError, rangeErrorType);
  4408. JavascriptError::SetErrorType(pError, kjstRangeError);
  4409. return pError;
  4410. }
  4411. JavascriptError* JavascriptLibrary::CreateReferenceError()
  4412. {
  4413. AssertMsg(referenceErrorType, "Where's referenceErrorType?");
  4414. JavascriptError *pError = RecyclerNew(this->GetRecycler(), JavascriptError, referenceErrorType);
  4415. JavascriptError::SetErrorType(pError, kjstReferenceError);
  4416. return pError;
  4417. }
  4418. JavascriptError* JavascriptLibrary::CreateSyntaxError()
  4419. {
  4420. AssertMsg(syntaxErrorType, "Where's syntaxErrorType?");
  4421. JavascriptError *pError = RecyclerNew(this->GetRecycler(), JavascriptError, syntaxErrorType);
  4422. JavascriptError::SetErrorType(pError, kjstSyntaxError);
  4423. return pError;
  4424. }
  4425. JavascriptError* JavascriptLibrary::CreateTypeError()
  4426. {
  4427. AssertMsg(typeErrorType, "Where's typeErrorType?");
  4428. JavascriptError *pError = RecyclerNew(this->GetRecycler(), JavascriptError, typeErrorType);
  4429. JavascriptError::SetErrorType(pError, kjstTypeError);
  4430. return pError;
  4431. }
  4432. JavascriptError* JavascriptLibrary::CreateURIError()
  4433. {
  4434. AssertMsg(uriErrorType, "Where's uriErrorType?");
  4435. JavascriptError *pError = RecyclerNew(this->GetRecycler(), JavascriptError, uriErrorType);
  4436. JavascriptError::SetErrorType(pError, kjstURIError);
  4437. return pError;
  4438. }
  4439. JavascriptError* JavascriptLibrary::CreateStackOverflowError()
  4440. {
  4441. #if DBG
  4442. // If we are doing a heap enum, we need to be able to allocate the error object.
  4443. Recycler::AutoAllowAllocationDuringHeapEnum autoAllowAllocationDuringHeapEnum(this->GetRecycler());
  4444. #endif
  4445. JavascriptError* stackOverflowError = scriptContext->GetLibrary()->CreateError();
  4446. JavascriptError::SetErrorMessage(stackOverflowError, VBSERR_OutOfStack, NULL, scriptContext);
  4447. return stackOverflowError;
  4448. }
  4449. JavascriptError* JavascriptLibrary::CreateOutOfMemoryError()
  4450. {
  4451. JavascriptError* outOfMemoryError = scriptContext->GetLibrary()->CreateError();
  4452. JavascriptError::SetErrorMessage(outOfMemoryError, VBSERR_OutOfMemory, NULL, scriptContext);
  4453. return outOfMemoryError;
  4454. }
  4455. JavascriptFunction* JavascriptLibrary::CreateNonProfiledFunction(FunctionInfo * functionInfo)
  4456. {
  4457. Assert(functionInfo->GetAttributes() & FunctionInfo::DoNotProfile);
  4458. return EnsureReadyIfHybridDebugging(RecyclerNew(this->GetRecycler(), RuntimeFunction,
  4459. CreateDeferredPrototypeFunctionTypeNoProfileThunk(functionInfo->GetOriginalEntryPoint()),
  4460. functionInfo));
  4461. }
  4462. ScriptFunction* JavascriptLibrary::CreateScriptFunction(FunctionProxy * proxy)
  4463. {
  4464. ScriptFunctionType* deferredPrototypeType = proxy->EnsureDeferredPrototypeType();
  4465. return EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, ScriptFunction, proxy, deferredPrototypeType));
  4466. }
  4467. AsmJsScriptFunction* JavascriptLibrary::CreateAsmJsScriptFunction(FunctionProxy * proxy)
  4468. {
  4469. ScriptFunctionType* deferredPrototypeType = proxy->EnsureDeferredPrototypeType();
  4470. return EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, AsmJsScriptFunction, proxy, deferredPrototypeType));
  4471. }
  4472. ScriptFunctionWithInlineCache* JavascriptLibrary::CreateScriptFunctionWithInlineCache(FunctionProxy * proxy)
  4473. {
  4474. ScriptFunctionType* deferredPrototypeType = proxy->EnsureDeferredPrototypeType();
  4475. return EnsureReadyIfHybridDebugging(RecyclerNewWithInfoBits(this->GetRecycler(), (Memory::ObjectInfoBits)(EnumFunctionClass | Memory::FinalizableObjectBits), ScriptFunctionWithInlineCache, proxy, deferredPrototypeType));
  4476. }
  4477. GeneratorVirtualScriptFunction* JavascriptLibrary::CreateGeneratorVirtualScriptFunction(FunctionProxy * proxy)
  4478. {
  4479. ScriptFunctionType* deferredPrototypeType = proxy->EnsureDeferredPrototypeType();
  4480. return EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, GeneratorVirtualScriptFunction, proxy, deferredPrototypeType));
  4481. }
  4482. DynamicType * JavascriptLibrary::CreateGeneratorType(RecyclableObject* prototype)
  4483. {
  4484. return DynamicType::New(scriptContext, TypeIds_Generator, prototype, nullptr, NullTypeHandler<false>::GetDefaultInstance());
  4485. }
  4486. template <class MethodType>
  4487. JavascriptExternalFunction* JavascriptLibrary::CreateIdMappedExternalFunction(MethodType entryPoint, DynamicType *pPrototypeType)
  4488. {
  4489. return EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptExternalFunction, entryPoint, pPrototypeType));
  4490. }
  4491. JavascriptGeneratorFunction* JavascriptLibrary::CreateGeneratorFunction(JavascriptMethod entryPoint, GeneratorVirtualScriptFunction* scriptFunction)
  4492. {
  4493. Assert(scriptContext->GetConfig()->IsES6GeneratorsEnabled());
  4494. DynamicType* type = CreateDeferredPrototypeGeneratorFunctionType(entryPoint, scriptFunction->IsAnonymousFunction());
  4495. return EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptGeneratorFunction, type, scriptFunction));
  4496. }
  4497. JavascriptExternalFunction* JavascriptLibrary::CreateStdCallExternalFunction(StdCallJavascriptMethod entryPoint, PropertyId nameId, void *callbackState)
  4498. {
  4499. Assert(nameId == 0 || scriptContext->IsTrackedPropertyId(nameId));
  4500. return CreateStdCallExternalFunction(entryPoint, TaggedInt::ToVarUnchecked(nameId), callbackState);
  4501. }
  4502. JavascriptExternalFunction* JavascriptLibrary::CreateStdCallExternalFunction(StdCallJavascriptMethod entryPoint, Var nameId, void *callbackState)
  4503. {
  4504. JavascriptExternalFunction* function = EnsureReadyIfHybridDebugging(this->CreateIdMappedExternalFunction(entryPoint, stdCallFunctionWithDeferredPrototypeType));
  4505. function->SetFunctionNameId(nameId);
  4506. function->SetCallbackState(callbackState);
  4507. return function;
  4508. }
  4509. JavascriptPromiseCapabilitiesExecutorFunction* JavascriptLibrary::CreatePromiseCapabilitiesExecutorFunction(JavascriptMethod entryPoint, JavascriptPromiseCapability* capability)
  4510. {
  4511. Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());
  4512. FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
  4513. DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);
  4514. JavascriptPromiseCapabilitiesExecutorFunction* function = EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseCapabilitiesExecutorFunction, type, functionInfo, capability));
  4515. function->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(2), PropertyConfigurable, nullptr);
  4516. return function;
  4517. }
  4518. JavascriptPromiseResolveOrRejectFunction* JavascriptLibrary::CreatePromiseResolveOrRejectFunction(JavascriptMethod entryPoint, JavascriptPromise* promise, bool isReject, JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* alreadyResolvedRecord)
  4519. {
  4520. Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());
  4521. FunctionInfo* functionInfo = &Js::JavascriptPromise::EntryInfo::ResolveOrRejectFunction;
  4522. DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);
  4523. JavascriptPromiseResolveOrRejectFunction* function = EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseResolveOrRejectFunction, type, functionInfo, promise, isReject, alreadyResolvedRecord));
  4524. function->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
  4525. return function;
  4526. }
  4527. JavascriptPromiseReactionTaskFunction* JavascriptLibrary::CreatePromiseReactionTaskFunction(JavascriptMethod entryPoint, JavascriptPromiseReaction* reaction, Var argument)
  4528. {
  4529. Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());
  4530. FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
  4531. DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);
  4532. return EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseReactionTaskFunction, type, functionInfo, reaction, argument));
  4533. }
  4534. JavascriptPromiseResolveThenableTaskFunction* JavascriptLibrary::CreatePromiseResolveThenableTaskFunction(JavascriptMethod entryPoint, JavascriptPromise* promise, RecyclableObject* thenable, RecyclableObject* thenFunction)
  4535. {
  4536. Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());
  4537. FunctionInfo* functionInfo = RecyclerNew(this->GetRecycler(), FunctionInfo, entryPoint);
  4538. DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);
  4539. return EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseResolveThenableTaskFunction, type, functionInfo, promise, thenable, thenFunction));
  4540. }
  4541. JavascriptPromiseAllResolveElementFunction* JavascriptLibrary::CreatePromiseAllResolveElementFunction(JavascriptMethod entryPoint, uint32 index, JavascriptArray* values, JavascriptPromiseCapability* capabilities, JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* remainingElements)
  4542. {
  4543. Assert(scriptContext->GetConfig()->IsES6PromiseEnabled());
  4544. FunctionInfo* functionInfo = &Js::JavascriptPromise::EntryInfo::AllResolveElementFunction;
  4545. DynamicType* type = CreateDeferredPrototypeFunctionType(entryPoint);
  4546. JavascriptPromiseAllResolveElementFunction* function = EnsureReadyIfHybridDebugging(RecyclerNewEnumClass(this->GetRecycler(), EnumFunctionClass, JavascriptPromiseAllResolveElementFunction, type, functionInfo, index, values, capabilities, remainingElements));
  4547. function->SetPropertyWithAttributes(PropertyIds::length, TaggedInt::ToVarUnchecked(1), PropertyConfigurable, nullptr);
  4548. return function;
  4549. }
  4550. JavascriptExternalFunction* JavascriptLibrary::CreateWrappedExternalFunction(JavascriptExternalFunction* wrappedFunction)
  4551. {
  4552. // The wrapped function will have profiling, so the wrapper function does not need it.
  4553. JavascriptExternalFunction* function = EnsureReadyIfHybridDebugging(RecyclerNew(this->GetRecycler(), JavascriptExternalFunction, wrappedFunction, wrappedFunctionWithDeferredPrototypeType));
  4554. function->SetFunctionNameId(wrappedFunction->GetSourceString());
  4555. return function;
  4556. }
  4557. #if !FLOATVAR
  4558. JavascriptNumber * JavascriptLibrary::CreateNumber(double value, RecyclerJavascriptNumberAllocator * numberAllocator)
  4559. {
  4560. AssertMsg(numberTypeStatic, "Where's numberTypeStatic?");
  4561. return AllocatorNew(RecyclerJavascriptNumberAllocator, numberAllocator, JavascriptNumber, value, numberTypeStatic);
  4562. }
  4563. #if ENABLE_NATIVE_CODEGEN
  4564. JavascriptNumber* JavascriptLibrary::CreateCodeGenNumber(CodeGenNumberAllocator * alloc, double value)
  4565. {
  4566. AssertMsg(numberTypeStatic, "Where's numberTypeStatic?");
  4567. return new (alloc->Alloc()) JavascriptNumber(value, numberTypeStatic);
  4568. }
  4569. #endif
  4570. #endif
  4571. DynamicObject* JavascriptLibrary::CreateGeneratorConstructorPrototypeObject()
  4572. {
  4573. AssertMsg(generatorConstructorPrototypeObjectType, "Where's generatorConstructorPrototypeObjectType?");
  4574. DynamicObject * prototype = DynamicObject::New(this->GetRecycler(), generatorConstructorPrototypeObjectType);
  4575. // Generator functions' prototype objects are not created with a .constructor property
  4576. return prototype;
  4577. }
  4578. DynamicObject* JavascriptLibrary::CreateConstructorPrototypeObject(JavascriptFunction * constructor)
  4579. {
  4580. AssertMsg(constructorPrototypeObjectType, "Where's constructorPrototypeObjectType?");
  4581. DynamicObject * prototype = DynamicObject::New(this->GetRecycler(), constructorPrototypeObjectType);
  4582. AddMember(prototype, PropertyIds::constructor, constructor);
  4583. return prototype;
  4584. }
  4585. DynamicObject* JavascriptLibrary::CreateObject(
  4586. const bool allowObjectHeaderInlining,
  4587. const PropertyIndex requestedInlineSlotCapacity)
  4588. {
  4589. Assert(GetObjectType());
  4590. Assert(GetObjectHeaderInlinedType());
  4591. const bool useObjectHeaderInlining =
  4592. allowObjectHeaderInlining && FunctionBody::DoObjectHeaderInliningForObjectLiteral(requestedInlineSlotCapacity);
  4593. DynamicType *const type =
  4594. useObjectHeaderInlining
  4595. ? GetObjectHeaderInlinedLiteralType(requestedInlineSlotCapacity)
  4596. : GetObjectLiteralType(requestedInlineSlotCapacity);
  4597. return DynamicObject::New(GetRecycler(), type);
  4598. }
  4599. DynamicObject* JavascriptLibrary::CreateObject(DynamicTypeHandler * typeHandler)
  4600. {
  4601. return DynamicObject::New(this->GetRecycler(),
  4602. Js::DynamicType::New(scriptContext, Js::TypeIds_Object, this->GetObjectPrototype(),
  4603. RecyclableObject::DefaultEntryPoint, typeHandler, false, false));
  4604. }
  4605. DynamicType* JavascriptLibrary::CreateObjectType(RecyclableObject* prototype, Js::TypeId typeId, uint16 requestedInlineSlotCapacity)
  4606. {
  4607. const bool useObjectHeaderInlining = FunctionBody::DoObjectHeaderInliningForConstructor(requestedInlineSlotCapacity);
  4608. const uint16 offsetOfInlineSlots =
  4609. useObjectHeaderInlining
  4610. ? DynamicTypeHandler::GetOffsetOfObjectHeaderInlineSlots()
  4611. : sizeof(DynamicObject);
  4612. DynamicType* dynamicType = nullptr;
  4613. const bool useCache = prototype->GetScriptContext() == this->scriptContext;
  4614. if (useCache &&
  4615. prototype->GetInternalProperty(prototype, Js::InternalPropertyIds::TypeOfPrototypObject, (Js::Var*) &dynamicType, nullptr, this->scriptContext))
  4616. {
  4617. //If the prototype is externalObject, then ExternalObject::Reinitialize can set all the properties to undefined in navigation scenario.
  4618. //Check to make sure dynamicType which is stored as a Js::Var is not undefined.
  4619. //See Blue 419324
  4620. if (dynamicType != nullptr && (Js::Var)dynamicType != this->GetUndefined())
  4621. {
  4622. DynamicTypeHandler *const dynamicTypeHandler = dynamicType->GetTypeHandler();
  4623. if (dynamicTypeHandler->IsObjectHeaderInlinedTypeHandler() == useObjectHeaderInlining &&
  4624. (
  4625. dynamicTypeHandler->GetInlineSlotCapacity() ==
  4626. (
  4627. useObjectHeaderInlining
  4628. ? DynamicTypeHandler::RoundUpObjectHeaderInlinedInlineSlotCapacity(requestedInlineSlotCapacity)
  4629. : DynamicTypeHandler::RoundUpInlineSlotCapacity(requestedInlineSlotCapacity)
  4630. )
  4631. ))
  4632. {
  4633. Assert(dynamicType->GetIsShared());
  4634. return dynamicType;
  4635. }
  4636. }
  4637. }
  4638. SimplePathTypeHandler* typeHandler = SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, requestedInlineSlotCapacity, offsetOfInlineSlots, true, true);
  4639. dynamicType = DynamicType::New(scriptContext, typeId, prototype, RecyclableObject::DefaultEntryPoint, typeHandler, true, true);
  4640. if (useCache)
  4641. {
  4642. prototype->SetInternalProperty(Js::InternalPropertyIds::TypeOfPrototypObject, (Var)dynamicType, PropertyOperationFlags::PropertyOperation_Force, nullptr);
  4643. }
  4644. return dynamicType;
  4645. }
  4646. DynamicType* JavascriptLibrary::CreateObjectTypeNoCache(RecyclableObject* prototype, Js::TypeId typeId)
  4647. {
  4648. return DynamicType::New(scriptContext, typeId, prototype, RecyclableObject::DefaultEntryPoint,
  4649. SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
  4650. }
  4651. DynamicType* JavascriptLibrary::CreateObjectType(RecyclableObject* prototype, uint16 requestedInlineSlotCapacity)
  4652. {
  4653. // We can't reuse the type in objectType even if the prototype is the object prototype, because those has inline slot capacity fixed
  4654. return CreateObjectType(prototype, TypeIds_Object, requestedInlineSlotCapacity);
  4655. }
  4656. DynamicObject* JavascriptLibrary::CreateObject(RecyclableObject* prototype, uint16 requestedInlineSlotCapacity)
  4657. {
  4658. Assert(JavascriptOperators::IsObject(prototype));
  4659. DynamicType* dynamicType = CreateObjectType(prototype, requestedInlineSlotCapacity);
  4660. return DynamicObject::New(this->GetRecycler(), dynamicType);
  4661. }
  4662. PropertyStringCacheMap* JavascriptLibrary::EnsurePropertyStringMap()
  4663. {
  4664. if (this->propertyStringMap == nullptr)
  4665. {
  4666. this->propertyStringMap = RecyclerNew(this->recycler, PropertyStringCacheMap, this->GetRecycler());
  4667. this->scriptContext->RegisterWeakReferenceDictionary((JsUtil::IWeakReferenceDictionary*) this->propertyStringMap);
  4668. }
  4669. return this->propertyStringMap;
  4670. }
  4671. DynamicObject* JavascriptLibrary::CreateActivationObject()
  4672. {
  4673. AssertMsg(activationObjectType, "Where's activationObjectType?");
  4674. return RecyclerNew(this->GetRecycler(), ActivationObject, activationObjectType);
  4675. }
  4676. DynamicObject* JavascriptLibrary::CreatePseudoActivationObject()
  4677. {
  4678. AssertMsg(activationObjectType, "Where's activationObjectType?");
  4679. return RecyclerNew(this->GetRecycler(), PseudoActivationObject, activationObjectType);
  4680. }
  4681. DynamicObject* JavascriptLibrary::CreateBlockActivationObject()
  4682. {
  4683. AssertMsg(activationObjectType, "Where's activationObjectType?");
  4684. return RecyclerNew(this->GetRecycler(), BlockActivationObject, activationObjectType);
  4685. }
  4686. DynamicObject* JavascriptLibrary::CreateConsoleScopeActivationObject()
  4687. {
  4688. AssertMsg(activationObjectType, "Where's activationObjectType?");
  4689. return RecyclerNew(this->GetRecycler(), ConsoleScopeActivationObject, activationObjectType);
  4690. }
  4691. JavascriptString* JavascriptLibrary::GetEmptyString() const
  4692. {
  4693. AssertMsg(emptyString, "Where's emptyString?");
  4694. #ifdef PROFILE_STRINGS
  4695. StringProfiler::RecordEmptyStringRequest(scriptContext);
  4696. #endif
  4697. return emptyString;
  4698. }
  4699. PropertyString* JavascriptLibrary::CreatePropertyString(const Js::PropertyRecord* propertyRecord)
  4700. {
  4701. AssertMsg(stringTypeStatic, "Where's stringTypeStatic?");
  4702. return PropertyString::New(stringTypeStatic, propertyRecord, this->GetRecycler());
  4703. }
  4704. PropertyString* JavascriptLibrary::CreatePropertyString(const Js::PropertyRecord* propertyRecord, ArenaAllocator *arena)
  4705. {
  4706. AssertMsg(stringTypeStatic, "Where's stringTypeStatic?");
  4707. return PropertyString::New(stringTypeStatic, propertyRecord, arena);
  4708. }
  4709. JavascriptVariantDate* JavascriptLibrary::CreateVariantDate(const double value)
  4710. {
  4711. AssertMsg(variantDateType, "Where's variantDateType?");
  4712. return RecyclerNewLeafZ(this->GetRecycler(), JavascriptVariantDate, value, variantDateType);
  4713. }
  4714. JavascriptBooleanObject* JavascriptLibrary::CreateBooleanObject()
  4715. {
  4716. AssertMsg(booleanTypeDynamic, "Where's booleanTypeDynamic?");
  4717. return RecyclerNew(this->GetRecycler(), JavascriptBooleanObject, nullptr, booleanTypeDynamic);
  4718. }
  4719. JavascriptBooleanObject* JavascriptLibrary::CreateBooleanObject(BOOL value)
  4720. {
  4721. AssertMsg(booleanTypeDynamic, "Where's booleanTypeDynamic?");
  4722. return RecyclerNew(this->GetRecycler(), JavascriptBooleanObject, CreateBoolean(value), booleanTypeDynamic);
  4723. }
  4724. JavascriptSymbolObject* JavascriptLibrary::CreateSymbolObject(JavascriptSymbol* value)
  4725. {
  4726. AssertMsg(symbolTypeDynamic, "Where's symbolTypeDynamic?");
  4727. return RecyclerNew(this->GetRecycler(), JavascriptSymbolObject, value, symbolTypeDynamic);
  4728. }
  4729. JavascriptNumberObject* JavascriptLibrary::CreateNumberObject(Var number)
  4730. {
  4731. AssertMsg(numberTypeDynamic, "Where's numberTypeDynamic?");
  4732. return RecyclerNew(this->GetRecycler(), JavascriptNumberObject, number, numberTypeDynamic);
  4733. }
  4734. JavascriptNumberObject* JavascriptLibrary::CreateNumberObjectWithCheck(double value)
  4735. {
  4736. return CreateNumberObject(JavascriptNumber::ToVarWithCheck(value, scriptContext));
  4737. }
  4738. JavascriptStringObject* JavascriptLibrary::CreateStringObject(JavascriptString* value)
  4739. {
  4740. AssertMsg(stringTypeDynamic, "Where's stringTypeDynamic?");
  4741. return RecyclerNew(this->GetRecycler(), JavascriptStringObject, value, stringTypeDynamic);
  4742. }
  4743. JavascriptStringObject* JavascriptLibrary::CreateStringObject(const wchar_t* value, charcount_t length)
  4744. {
  4745. AssertMsg(stringTypeDynamic, "Where's stringTypeDynamic?");
  4746. return RecyclerNew(this->GetRecycler(), JavascriptStringObject,
  4747. Js::JavascriptString::NewWithBuffer(value, length, scriptContext), stringTypeDynamic);
  4748. }
  4749. JavascriptRegExp* JavascriptLibrary::CreateRegExp(UnifiedRegex::RegexPattern* pattern)
  4750. {
  4751. AssertMsg(regexType, "Where's regexType?");
  4752. return RecyclerNew(this->GetRecycler(), JavascriptRegExp, pattern, regexType);
  4753. }
  4754. JavascriptArrayIterator* JavascriptLibrary::CreateArrayIterator(Var iterable, JavascriptArrayIteratorKind kind)
  4755. {
  4756. AssertMsg(arrayIteratorType, "Where's arrayIteratorType");
  4757. return RecyclerNew(this->GetRecycler(), JavascriptArrayIterator, arrayIteratorType, iterable, kind);
  4758. }
  4759. JavascriptMapIterator* JavascriptLibrary::CreateMapIterator(JavascriptMap* map, JavascriptMapIteratorKind kind)
  4760. {
  4761. AssertMsg(mapIteratorType, "Where's mapIteratorType");
  4762. return RecyclerNew(this->GetRecycler(), JavascriptMapIterator, mapIteratorType, map, kind);
  4763. }
  4764. JavascriptSetIterator* JavascriptLibrary::CreateSetIterator(JavascriptSet* set, JavascriptSetIteratorKind kind)
  4765. {
  4766. AssertMsg(setIteratorType, "Where's setIteratorType");
  4767. return RecyclerNew(this->GetRecycler(), JavascriptSetIterator, setIteratorType, set, kind);
  4768. }
  4769. JavascriptStringIterator* JavascriptLibrary::CreateStringIterator(JavascriptString* string)
  4770. {
  4771. AssertMsg(stringIteratorType, "Where's stringIteratorType");
  4772. return RecyclerNew(this->GetRecycler(), JavascriptStringIterator, stringIteratorType, string);
  4773. }
  4774. DynamicObject* JavascriptLibrary::CreateIteratorResultObject(Var value, Var done)
  4775. {
  4776. DynamicObject* iteratorResult = DynamicObject::New(this->GetRecycler(), iteratorResultType);
  4777. iteratorResult->SetSlot(SetSlotArguments(Js::PropertyIds::value, 0, value));
  4778. iteratorResult->SetSlot(SetSlotArguments(Js::PropertyIds::done, 1, done));
  4779. return iteratorResult;
  4780. }
  4781. DynamicObject* JavascriptLibrary::CreateIteratorResultObjectValueFalse(Var value)
  4782. {
  4783. return CreateIteratorResultObject(value, GetFalse());
  4784. }
  4785. DynamicObject* JavascriptLibrary::CreateIteratorResultObjectUndefinedTrue()
  4786. {
  4787. return CreateIteratorResultObject(GetUndefined(), GetTrue());
  4788. }
  4789. RecyclableObject* JavascriptLibrary::CreateThrowErrorObject(JavascriptError* error)
  4790. {
  4791. return ThrowErrorObject::New(this->throwErrorObjectType, error, this->GetRecycler());
  4792. }
  4793. void JavascriptLibrary::SetForInEnumeratorCache(ForInObjectEnumerator* enumerator)
  4794. {
  4795. Assert(enumerator);
  4796. this->cachedForInEnumerator = enumerator->GetWeakReference(this->recycler);
  4797. }
  4798. ForInObjectEnumerator* JavascriptLibrary::GetAndClearForInEnumeratorCache()
  4799. {
  4800. auto cachedEnumerator = this->cachedForInEnumerator;
  4801. if (cachedEnumerator)
  4802. {
  4803. ForInObjectEnumerator * enumerator = cachedEnumerator->Get();
  4804. this->cachedForInEnumerator = nullptr;
  4805. return enumerator;
  4806. }
  4807. return nullptr;
  4808. }
  4809. #if ENABLE_COPYONACCESS_ARRAY
  4810. bool JavascriptLibrary::IsCopyOnAccessArrayCallSite(JavascriptLibrary *lib, ArrayCallSiteInfo *arrayInfo, uint32 length)
  4811. {
  4812. return
  4813. lib->cacheForCopyOnAccessArraySegments
  4814. && lib->cacheForCopyOnAccessArraySegments->IsNotOverHardLimit()
  4815. && (
  4816. PHASE_FORCE1(CopyOnAccessArrayPhase) // -force:copyonaccessarray is only restricted by hard limit of the segment cache
  4817. || (
  4818. !arrayInfo->isNotCopyOnAccessArray // from profile
  4819. && !PHASE_OFF1(CopyOnAccessArrayPhase)
  4820. && lib->cacheForCopyOnAccessArraySegments->IsNotFull() // cache size soft limit through -copyonaccessarraysegmentcachesize:<number>
  4821. && length <= (uint32)CONFIG_FLAG(MaxCopyOnAccessArrayLength) // -maxcopyonaccessarraylength:<number>
  4822. && length >= (uint32)CONFIG_FLAG(MinCopyOnAccessArrayLength) // -mincopyonaccessarraylength:<number>
  4823. )
  4824. );
  4825. }
  4826. bool JavascriptLibrary::IsCachedCopyOnAccessArrayCallSite(const JavascriptLibrary *lib, ArrayCallSiteInfo *arrayInfo)
  4827. {
  4828. return lib->cacheForCopyOnAccessArraySegments
  4829. && lib->cacheForCopyOnAccessArraySegments->IsValidIndex(arrayInfo->copyOnAccessArrayCacheIndex);
  4830. }
  4831. #endif
  4832. // static
  4833. bool JavascriptLibrary::IsTypedArrayConstructor(Var constructor, ScriptContext* scriptContext)
  4834. {
  4835. JavascriptLibrary* library = scriptContext->GetLibrary();
  4836. return constructor == library->GetInt8ArrayConstructor()
  4837. || constructor == library->GetUint8ArrayConstructor()
  4838. || constructor == library->GetUint8ClampedArrayConstructor()
  4839. || constructor == library->GetInt16ArrayConstructor()
  4840. || constructor == library->GetUint16ArrayConstructor()
  4841. || constructor == library->GetInt32ArrayConstructor()
  4842. || constructor == library->GetUint32ArrayConstructor()
  4843. || constructor == library->GetFloat32ArrayConstructor()
  4844. || constructor == library->GetFloat64ArrayConstructor();
  4845. }
  4846. JavascriptFunction ** JavascriptLibrary::GetBuiltinFunctions()
  4847. {
  4848. AssertMsg(this->builtinFunctions, "builtinFunctions table must've been initialized as part of library initialization!");
  4849. return this->builtinFunctions;
  4850. }
  4851. INT_PTR* JavascriptLibrary::GetVTableAddresses()
  4852. {
  4853. AssertMsg(this->vtableAddresses, "vtableAddresses table must've been initialized as part of library initialization!");
  4854. return this->vtableAddresses;
  4855. }
  4856. #if ENABLE_NATIVE_CODEGEN
  4857. //static
  4858. BuiltinFunction JavascriptLibrary::GetBuiltInInlineCandidateId(OpCode opCode)
  4859. {
  4860. switch (opCode)
  4861. {
  4862. case OpCode::InlineMathAcos:
  4863. return BuiltinFunction::Math_Acos;
  4864. case OpCode::InlineMathAsin:
  4865. return BuiltinFunction::Math_Asin;
  4866. case OpCode::InlineMathAtan:
  4867. return BuiltinFunction::Math_Atan;
  4868. case OpCode::InlineMathAtan2:
  4869. return BuiltinFunction::Math_Atan2;
  4870. case OpCode::InlineMathCos:
  4871. return BuiltinFunction::Math_Cos;
  4872. case OpCode::InlineMathExp:
  4873. return BuiltinFunction::Math_Exp;
  4874. case OpCode::InlineMathLog:
  4875. return BuiltinFunction::Math_Log;
  4876. case OpCode::InlineMathPow:
  4877. return BuiltinFunction::Math_Pow;
  4878. case OpCode::InlineMathSin:
  4879. return BuiltinFunction::Math_Sin;
  4880. case OpCode::InlineMathSqrt:
  4881. return BuiltinFunction::Math_Sqrt;
  4882. case OpCode::InlineMathTan:
  4883. return BuiltinFunction::Math_Tan;
  4884. case OpCode::InlineMathAbs:
  4885. return BuiltinFunction::Math_Abs;
  4886. case OpCode::InlineMathClz32:
  4887. return BuiltinFunction::Math_Clz32;
  4888. case OpCode::InlineMathCeil:
  4889. return BuiltinFunction::Math_Ceil;
  4890. case OpCode::InlineMathFloor:
  4891. return BuiltinFunction::Math_Floor;
  4892. case OpCode::InlineMathMax:
  4893. return BuiltinFunction::Math_Max;
  4894. case OpCode::InlineMathMin:
  4895. return BuiltinFunction::Math_Min;
  4896. case OpCode::InlineMathImul:
  4897. return BuiltinFunction::Math_Imul;
  4898. case OpCode::InlineMathRandom:
  4899. return BuiltinFunction::Math_Random;
  4900. case OpCode::InlineMathRound:
  4901. return BuiltinFunction::Math_Round;
  4902. case OpCode::InlineMathFround:
  4903. return BuiltinFunction::Math_Fround;
  4904. case OpCode::InlineStringCharAt:
  4905. return BuiltinFunction::String_CharAt;
  4906. case OpCode::InlineStringCharCodeAt:
  4907. return BuiltinFunction::String_CharCodeAt;
  4908. case OpCode::InlineStringCodePointAt:
  4909. return BuiltinFunction::String_CodePointAt;
  4910. case OpCode::InlineArrayPop:
  4911. return BuiltinFunction::Array_Pop;
  4912. case OpCode::InlineArrayPush:
  4913. return BuiltinFunction::Array_Push;
  4914. case OpCode::InlineFunctionApply:
  4915. return BuiltinFunction::Function_Apply;
  4916. case OpCode::InlineFunctionCall:
  4917. return BuiltinFunction::Function_Call;
  4918. case OpCode::InlineRegExpExec:
  4919. return BuiltinFunction::RegExp_Exec;
  4920. }
  4921. return BuiltinFunction::None;
  4922. }
  4923. #endif
  4924. // Parses given flags and arg kind (dst or src1, or src2) returns the type the arg must be type-specialized to.
  4925. // static
  4926. BuiltInArgSpecizationType JavascriptLibrary::GetBuiltInArgType(BuiltInFlags flags, BuiltInArgShift argKind)
  4927. {
  4928. Assert(argKind == BuiltInArgShift::BIAS_Dst || BuiltInArgShift::BIAS_Src1 || BuiltInArgShift::BIAS_Src2);
  4929. BuiltInArgSpecizationType type = static_cast<BuiltInArgSpecizationType>(
  4930. (flags >> argKind) & // Shift-out everything to the right of start of interesting area.
  4931. ((1 << Js::BIAS_ArgSize) - 1)); // Mask-out everything to the left of interesting area.
  4932. return type;
  4933. }
  4934. // Register for profiler
  4935. #define DEFINE_OBJECT_NAME(object) const wchar_t *pwszObjectName = L#object;
  4936. #define REGISTER_OBJECT(object)\
  4937. if (FAILED(hr = this->ProfilerRegister##object()))\
  4938. {\
  4939. return hr; \
  4940. }\
  4941. #define REG_LIB_FUNC_CORE(pwszObjectName, pwszFunctionName, functionPropertyId, entryPoint)\
  4942. if (FAILED(hr = this->GetScriptContext()->RegisterLibraryFunction(pwszObjectName, pwszFunctionName, functionPropertyId, entryPoint)))\
  4943. {\
  4944. return hr; \
  4945. }\
  4946. #define REG_OBJECTS_DYNAMIC_LIB_FUNC(pwszFunctionName, nFuncNameLen, entryPoint) {\
  4947. Js::PropertyRecord const * propRecord; \
  4948. this->GetScriptContext()->GetOrAddPropertyRecord(pwszFunctionName, nFuncNameLen, &propRecord); \
  4949. REG_LIB_FUNC_CORE(pwszObjectName, pwszFunctionName, propRecord->GetPropertyId(), entryPoint)\
  4950. }
  4951. #define REG_LIB_FUNC(pwszObjectName, functionPropertyId, entryPoint)\
  4952. REG_LIB_FUNC_CORE(pwszObjectName, L#functionPropertyId, PropertyIds::##functionPropertyId, entryPoint)\
  4953. #define REG_OBJECTS_LIB_FUNC(functionPropertyId, entryPoint)\
  4954. REG_LIB_FUNC(pwszObjectName, functionPropertyId, entryPoint)\
  4955. #define REG_OBJECTS_LIB_FUNC2(functionPropertyId, pwszFunctionPropertyName, entryPoint)\
  4956. REG_LIB_FUNC_CORE(pwszObjectName, pwszFunctionPropertyName, PropertyIds::##functionPropertyId, entryPoint)\
  4957. #define REG_GLOBAL_LIB_FUNC(functionPropertyId, entryPoint)\
  4958. REG_LIB_FUNC(NULL, functionPropertyId, entryPoint)\
  4959. #define REG_GLOBAL_CONSTRUCTOR(functionPropertyId)\
  4960. REG_GLOBAL_LIB_FUNC(functionPropertyId, Javascript##functionPropertyId##::NewInstance)\
  4961. #define REGISTER_ERROR_OBJECT(functionPropertyId)\
  4962. REG_GLOBAL_LIB_FUNC(functionPropertyId, JavascriptError::New##functionPropertyId##Instance)\
  4963. REG_LIB_FUNC(L#functionPropertyId, toString, JavascriptError::EntryToString)\
  4964. HRESULT JavascriptLibrary::ProfilerRegisterBuiltIns()
  4965. {
  4966. HRESULT hr = S_OK;
  4967. // Register functions directly in global scope
  4968. REG_GLOBAL_LIB_FUNC(eval, GlobalObject::EntryEval);
  4969. REG_GLOBAL_LIB_FUNC(parseInt, GlobalObject::EntryParseInt);
  4970. REG_GLOBAL_LIB_FUNC(parseFloat, GlobalObject::EntryParseFloat);
  4971. REG_GLOBAL_LIB_FUNC(isNaN, GlobalObject::EntryIsNaN);
  4972. REG_GLOBAL_LIB_FUNC(isFinite, GlobalObject::EntryIsFinite);
  4973. REG_GLOBAL_LIB_FUNC(decodeURI, GlobalObject::EntryDecodeURI);
  4974. REG_GLOBAL_LIB_FUNC(decodeURIComponent, GlobalObject::EntryDecodeURIComponent);
  4975. REG_GLOBAL_LIB_FUNC(encodeURI, GlobalObject::EntryEncodeURI);
  4976. REG_GLOBAL_LIB_FUNC(encodeURIComponent, GlobalObject::EntryEncodeURIComponent);
  4977. REG_GLOBAL_LIB_FUNC(escape, GlobalObject::EntryEscape);
  4978. REG_GLOBAL_LIB_FUNC(unescape, GlobalObject::EntryUnEscape);
  4979. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  4980. if (config.SupportsCollectGarbage())
  4981. {
  4982. REG_GLOBAL_LIB_FUNC(CollectGarbage, GlobalObject::EntryCollectGarbage);
  4983. }
  4984. // Register constructors, prototypes and objects in global
  4985. REGISTER_OBJECT(Object);
  4986. REGISTER_OBJECT(Array);
  4987. REGISTER_OBJECT(Boolean);
  4988. REGISTER_OBJECT(Date);
  4989. REGISTER_OBJECT(Function);
  4990. REGISTER_OBJECT(Math);
  4991. REGISTER_OBJECT(Number);
  4992. REGISTER_OBJECT(String);
  4993. REGISTER_OBJECT(RegExp);
  4994. REGISTER_OBJECT(JSON);
  4995. if (config.IsES6MapEnabled())
  4996. {
  4997. REGISTER_OBJECT(Map);
  4998. }
  4999. if (config.IsES6SetEnabled())
  5000. {
  5001. REGISTER_OBJECT(Set);
  5002. }
  5003. if (config.IsES6WeakMapEnabled())
  5004. {
  5005. REGISTER_OBJECT(WeakMap);
  5006. }
  5007. if (config.IsES6WeakSetEnabled())
  5008. {
  5009. REGISTER_OBJECT(WeakSet);
  5010. }
  5011. if (config.IsES6SymbolEnabled())
  5012. {
  5013. REGISTER_OBJECT(Symbol);
  5014. }
  5015. if (config.IsES6IteratorsEnabled())
  5016. {
  5017. REGISTER_OBJECT(Iterator);
  5018. REGISTER_OBJECT(ArrayIterator);
  5019. REGISTER_OBJECT(MapIterator);
  5020. REGISTER_OBJECT(SetIterator);
  5021. REGISTER_OBJECT(StringIterator);
  5022. REGISTER_OBJECT(EnumeratorIterator);
  5023. }
  5024. if (config.IsES6TypedArrayExtensionsEnabled())
  5025. {
  5026. REGISTER_OBJECT(TypedArray);
  5027. }
  5028. if (config.IsES6PromiseEnabled())
  5029. {
  5030. REGISTER_OBJECT(Promise);
  5031. }
  5032. if (config.IsES6ProxyEnabled())
  5033. {
  5034. REGISTER_OBJECT(Proxy);
  5035. REGISTER_OBJECT(Reflect);
  5036. }
  5037. #ifdef IR_VIEWER
  5038. if (Js::Configuration::Global.flags.IsEnabled(Js::IRViewerFlag))
  5039. {
  5040. REGISTER_OBJECT(IRViewer);
  5041. }
  5042. #endif /* IR_VIEWER */
  5043. // Error Constructors and prototypes
  5044. REGISTER_ERROR_OBJECT(Error);
  5045. REGISTER_ERROR_OBJECT(EvalError);
  5046. REGISTER_ERROR_OBJECT(RangeError);
  5047. REGISTER_ERROR_OBJECT(ReferenceError);
  5048. REGISTER_ERROR_OBJECT(SyntaxError);
  5049. REGISTER_ERROR_OBJECT(TypeError);
  5050. REGISTER_ERROR_OBJECT(URIError);
  5051. #ifdef ENABLE_PROJECTION
  5052. if (config.IsWinRTEnabled())
  5053. {
  5054. REGISTER_ERROR_OBJECT(WinRTError);
  5055. }
  5056. #endif
  5057. return hr;
  5058. }
  5059. HRESULT JavascriptLibrary::ProfilerRegisterObject()
  5060. {
  5061. HRESULT hr = S_OK;
  5062. REG_GLOBAL_CONSTRUCTOR(Object);
  5063. DEFINE_OBJECT_NAME(Object);
  5064. REG_OBJECTS_LIB_FUNC(defineProperty, JavascriptObject::EntryDefineProperty);
  5065. REG_OBJECTS_LIB_FUNC(getOwnPropertyDescriptor, JavascriptObject::EntryGetOwnPropertyDescriptor);
  5066. REG_OBJECTS_LIB_FUNC(defineProperties, JavascriptObject::EntryDefineProperties);
  5067. REG_OBJECTS_LIB_FUNC(create, JavascriptObject::EntryCreate);
  5068. REG_OBJECTS_LIB_FUNC(seal, JavascriptObject::EntrySeal);
  5069. REG_OBJECTS_LIB_FUNC(freeze, JavascriptObject::EntryFreeze);
  5070. REG_OBJECTS_LIB_FUNC(preventExtensions, JavascriptObject::EntryPreventExtensions);
  5071. REG_OBJECTS_LIB_FUNC(isSealed, JavascriptObject::EntryIsSealed);
  5072. REG_OBJECTS_LIB_FUNC(isFrozen, JavascriptObject::EntryIsFrozen);
  5073. REG_OBJECTS_LIB_FUNC(isExtensible, JavascriptObject::EntryIsExtensible);
  5074. REG_OBJECTS_LIB_FUNC(getPrototypeOf, JavascriptObject::EntryGetPrototypeOf);
  5075. REG_OBJECTS_LIB_FUNC(keys, JavascriptObject::EntryKeys);
  5076. REG_OBJECTS_LIB_FUNC(getOwnPropertyNames, JavascriptObject::EntryGetOwnPropertyNames);
  5077. REG_OBJECTS_LIB_FUNC(setPrototypeOf, JavascriptObject::EntrySetPrototypeOf);
  5078. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  5079. if (config.IsES6SymbolEnabled())
  5080. {
  5081. REG_OBJECTS_LIB_FUNC(getOwnPropertySymbols, JavascriptObject::EntryGetOwnPropertySymbols);
  5082. }
  5083. REG_OBJECTS_LIB_FUNC(hasOwnProperty, JavascriptObject::EntryHasOwnProperty);
  5084. REG_OBJECTS_LIB_FUNC(propertyIsEnumerable, JavascriptObject::EntryPropertyIsEnumerable);
  5085. REG_OBJECTS_LIB_FUNC(isPrototypeOf, JavascriptObject::EntryIsPrototypeOf);
  5086. REG_OBJECTS_LIB_FUNC(toLocaleString, JavascriptObject::EntryToLocaleString);
  5087. REG_OBJECTS_LIB_FUNC(toString, JavascriptObject::EntryToString);
  5088. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptObject::EntryValueOf);
  5089. if (config.IsDefineGetterSetterEnabled())
  5090. {
  5091. REG_OBJECTS_LIB_FUNC(__defineGetter__, JavascriptObject::EntryDefineGetter);
  5092. REG_OBJECTS_LIB_FUNC(__defineSetter__, JavascriptObject::EntryDefineSetter);
  5093. }
  5094. if (config.IsES6ObjectExtensionsEnabled())
  5095. {
  5096. REG_OBJECTS_LIB_FUNC(is, JavascriptObject::EntryIs);
  5097. REG_OBJECTS_LIB_FUNC(assign, JavascriptObject::EntryAssign);
  5098. }
  5099. return hr;
  5100. }
  5101. HRESULT JavascriptLibrary::ProfilerRegisterArray()
  5102. {
  5103. HRESULT hr = S_OK;
  5104. REG_GLOBAL_CONSTRUCTOR(Array);
  5105. DEFINE_OBJECT_NAME(Array);
  5106. REG_OBJECTS_LIB_FUNC(isArray, JavascriptArray::EntryIsArray);
  5107. REG_OBJECTS_LIB_FUNC(concat, JavascriptArray::EntryConcat);
  5108. REG_OBJECTS_LIB_FUNC(join, JavascriptArray::EntryJoin);
  5109. REG_OBJECTS_LIB_FUNC(pop, JavascriptArray::EntryPop);
  5110. REG_OBJECTS_LIB_FUNC(push, JavascriptArray::EntryPush);
  5111. REG_OBJECTS_LIB_FUNC(reverse, JavascriptArray::EntryReverse);
  5112. REG_OBJECTS_LIB_FUNC(shift, JavascriptArray::EntryShift);
  5113. REG_OBJECTS_LIB_FUNC(slice, JavascriptArray::EntrySlice);
  5114. REG_OBJECTS_LIB_FUNC(sort, JavascriptArray::EntrySort);
  5115. REG_OBJECTS_LIB_FUNC(splice, JavascriptArray::EntrySplice);
  5116. REG_OBJECTS_LIB_FUNC(toLocaleString, JavascriptArray::EntryToLocaleString);
  5117. REG_OBJECTS_LIB_FUNC(toString, JavascriptArray::EntryToString);
  5118. REG_OBJECTS_LIB_FUNC(unshift, JavascriptArray::EntryUnshift);
  5119. REG_OBJECTS_LIB_FUNC(indexOf, JavascriptArray::EntryIndexOf);
  5120. REG_OBJECTS_LIB_FUNC(every, JavascriptArray::EntryEvery);
  5121. REG_OBJECTS_LIB_FUNC(filter, JavascriptArray::EntryFilter);
  5122. REG_OBJECTS_LIB_FUNC(forEach, JavascriptArray::EntryForEach);
  5123. REG_OBJECTS_LIB_FUNC(lastIndexOf, JavascriptArray::EntryLastIndexOf);
  5124. REG_OBJECTS_LIB_FUNC(map, JavascriptArray::EntryMap);
  5125. REG_OBJECTS_LIB_FUNC(reduce, JavascriptArray::EntryReduce);
  5126. REG_OBJECTS_LIB_FUNC(reduceRight, JavascriptArray::EntryReduceRight);
  5127. REG_OBJECTS_LIB_FUNC(some, JavascriptArray::EntrySome);
  5128. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  5129. if (config.IsES6StringExtensionsEnabled())
  5130. {
  5131. REG_OBJECTS_LIB_FUNC(find, JavascriptArray::EntryFind);
  5132. REG_OBJECTS_LIB_FUNC(findIndex, JavascriptArray::EntryFindIndex);
  5133. }
  5134. if (config.IsES6IteratorsEnabled())
  5135. {
  5136. REG_OBJECTS_LIB_FUNC(entries, JavascriptArray::EntryEntries)
  5137. REG_OBJECTS_LIB_FUNC(keys, JavascriptArray::EntryKeys)
  5138. REG_OBJECTS_LIB_FUNC(values, JavascriptArray::EntryValues)
  5139. // _symbolIterator is just an alias for values on Array.prototype so do not register it as its own function
  5140. }
  5141. if (config.IsES6TypedArrayExtensionsEnabled())
  5142. {
  5143. REG_OBJECTS_LIB_FUNC(fill, JavascriptArray::EntryFill)
  5144. REG_OBJECTS_LIB_FUNC(copyWithin, JavascriptArray::EntryCopyWithin)
  5145. REG_OBJECTS_LIB_FUNC(from, JavascriptArray::EntryFrom);
  5146. REG_OBJECTS_LIB_FUNC(of, JavascriptArray::EntryOf);
  5147. }
  5148. if (config.IsES7BuiltinsEnabled())
  5149. {
  5150. REG_OBJECTS_LIB_FUNC(includes, JavascriptArray::EntryIncludes);
  5151. }
  5152. return hr;
  5153. }
  5154. HRESULT JavascriptLibrary::ProfilerRegisterBoolean()
  5155. {
  5156. HRESULT hr = S_OK;
  5157. REG_GLOBAL_CONSTRUCTOR(Boolean);
  5158. DEFINE_OBJECT_NAME(Boolean);
  5159. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptBoolean::EntryValueOf);
  5160. REG_OBJECTS_LIB_FUNC(toString, JavascriptBoolean::EntryToString);
  5161. return hr;
  5162. }
  5163. HRESULT JavascriptLibrary::ProfilerRegisterDate()
  5164. {
  5165. HRESULT hr = S_OK;
  5166. REG_GLOBAL_CONSTRUCTOR(Date);
  5167. DEFINE_OBJECT_NAME(Date);
  5168. REG_OBJECTS_LIB_FUNC(parse, JavascriptDate::EntryParse);
  5169. REG_OBJECTS_LIB_FUNC(now, JavascriptDate::EntryNow);
  5170. REG_OBJECTS_LIB_FUNC(UTC, JavascriptDate::EntryUTC);
  5171. REG_OBJECTS_LIB_FUNC(getDate, JavascriptDate::EntryGetDate);
  5172. REG_OBJECTS_LIB_FUNC(getDay, JavascriptDate::EntryGetDay);
  5173. REG_OBJECTS_LIB_FUNC(getFullYear, JavascriptDate::EntryGetFullYear);
  5174. REG_OBJECTS_LIB_FUNC(getHours, JavascriptDate::EntryGetHours);
  5175. REG_OBJECTS_LIB_FUNC(getMilliseconds, JavascriptDate::EntryGetMilliseconds);
  5176. REG_OBJECTS_LIB_FUNC(getMinutes, JavascriptDate::EntryGetMinutes);
  5177. REG_OBJECTS_LIB_FUNC(getMonth, JavascriptDate::EntryGetMonth);
  5178. REG_OBJECTS_LIB_FUNC(getSeconds, JavascriptDate::EntryGetSeconds);
  5179. REG_OBJECTS_LIB_FUNC(getTime, JavascriptDate::EntryGetTime);
  5180. REG_OBJECTS_LIB_FUNC(getTimezoneOffset, JavascriptDate::EntryGetTimezoneOffset);
  5181. REG_OBJECTS_LIB_FUNC(getUTCDate, JavascriptDate::EntryGetUTCDate);
  5182. REG_OBJECTS_LIB_FUNC(getUTCDay, JavascriptDate::EntryGetUTCDay);
  5183. REG_OBJECTS_LIB_FUNC(getUTCFullYear, JavascriptDate::EntryGetUTCFullYear);
  5184. REG_OBJECTS_LIB_FUNC(getUTCHours, JavascriptDate::EntryGetUTCHours);
  5185. REG_OBJECTS_LIB_FUNC(getUTCMilliseconds, JavascriptDate::EntryGetUTCMilliseconds);
  5186. REG_OBJECTS_LIB_FUNC(getUTCMinutes, JavascriptDate::EntryGetUTCMinutes);
  5187. REG_OBJECTS_LIB_FUNC(getUTCMonth, JavascriptDate::EntryGetUTCMonth);
  5188. REG_OBJECTS_LIB_FUNC(getUTCSeconds, JavascriptDate::EntryGetUTCSeconds);
  5189. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  5190. if (config.SupportsES3Extensions())
  5191. {
  5192. REG_OBJECTS_LIB_FUNC(getVarDate, JavascriptDate::EntryGetVarDate);
  5193. }
  5194. REG_OBJECTS_LIB_FUNC(getYear, JavascriptDate::EntryGetYear);
  5195. REG_OBJECTS_LIB_FUNC(setDate, JavascriptDate::EntrySetDate);
  5196. REG_OBJECTS_LIB_FUNC(setFullYear, JavascriptDate::EntrySetFullYear);
  5197. REG_OBJECTS_LIB_FUNC(setHours, JavascriptDate::EntrySetHours);
  5198. REG_OBJECTS_LIB_FUNC(setMilliseconds, JavascriptDate::EntrySetMilliseconds);
  5199. REG_OBJECTS_LIB_FUNC(setMinutes, JavascriptDate::EntrySetMinutes);
  5200. REG_OBJECTS_LIB_FUNC(setMonth, JavascriptDate::EntrySetMonth);
  5201. REG_OBJECTS_LIB_FUNC(setSeconds, JavascriptDate::EntrySetSeconds);
  5202. REG_OBJECTS_LIB_FUNC(setTime, JavascriptDate::EntrySetTime);
  5203. REG_OBJECTS_LIB_FUNC(setUTCDate, JavascriptDate::EntrySetUTCDate);
  5204. REG_OBJECTS_LIB_FUNC(setUTCFullYear, JavascriptDate::EntrySetUTCFullYear);
  5205. REG_OBJECTS_LIB_FUNC(setUTCHours, JavascriptDate::EntrySetUTCHours);
  5206. REG_OBJECTS_LIB_FUNC(setUTCMilliseconds, JavascriptDate::EntrySetUTCMilliseconds);
  5207. REG_OBJECTS_LIB_FUNC(setUTCMinutes, JavascriptDate::EntrySetUTCMinutes);
  5208. REG_OBJECTS_LIB_FUNC(setUTCMonth, JavascriptDate::EntrySetUTCMonth);
  5209. REG_OBJECTS_LIB_FUNC(setUTCSeconds, JavascriptDate::EntrySetUTCSeconds);
  5210. REG_OBJECTS_LIB_FUNC(setYear, JavascriptDate::EntrySetYear);
  5211. REG_OBJECTS_LIB_FUNC(toDateString, JavascriptDate::EntryToDateString);
  5212. REG_OBJECTS_LIB_FUNC(toISOString, JavascriptDate::EntryToISOString);
  5213. REG_OBJECTS_LIB_FUNC(toJSON, JavascriptDate::EntryToJSON);
  5214. REG_OBJECTS_LIB_FUNC(toLocaleDateString, JavascriptDate::EntryToLocaleDateString);
  5215. REG_OBJECTS_LIB_FUNC(toLocaleString, JavascriptDate::EntryToLocaleString);
  5216. REG_OBJECTS_LIB_FUNC(toLocaleTimeString, JavascriptDate::EntryToLocaleTimeString);
  5217. REG_OBJECTS_LIB_FUNC(toString, JavascriptDate::EntryToString);
  5218. REG_OBJECTS_LIB_FUNC(toTimeString, JavascriptDate::EntryToTimeString);
  5219. REG_OBJECTS_LIB_FUNC(toUTCString, JavascriptDate::EntryToUTCString);
  5220. REG_OBJECTS_LIB_FUNC(toGMTString, JavascriptDate::EntryToGMTString);
  5221. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptDate::EntryValueOf);
  5222. return hr;
  5223. }
  5224. HRESULT JavascriptLibrary::ProfilerRegisterFunction()
  5225. {
  5226. HRESULT hr = S_OK;
  5227. REG_GLOBAL_CONSTRUCTOR(Function);
  5228. DEFINE_OBJECT_NAME(Function);
  5229. REG_OBJECTS_LIB_FUNC(apply, JavascriptFunction::EntryApply);
  5230. REG_OBJECTS_LIB_FUNC(bind, JavascriptFunction::EntryBind);
  5231. REG_OBJECTS_LIB_FUNC(call, JavascriptFunction::EntryCall);
  5232. REG_OBJECTS_LIB_FUNC(toString, JavascriptFunction::EntryToString);
  5233. return hr;
  5234. }
  5235. HRESULT JavascriptLibrary::ProfilerRegisterMath()
  5236. {
  5237. HRESULT hr = S_OK;
  5238. DEFINE_OBJECT_NAME(Math);
  5239. REG_OBJECTS_LIB_FUNC(abs, Math::Abs);
  5240. REG_OBJECTS_LIB_FUNC(acos, Math::Acos);
  5241. REG_OBJECTS_LIB_FUNC(asin, Math::Asin);
  5242. REG_OBJECTS_LIB_FUNC(atan, Math::Atan);
  5243. REG_OBJECTS_LIB_FUNC(atan2, Math::Atan2);
  5244. REG_OBJECTS_LIB_FUNC(ceil, Math::Ceil);
  5245. REG_OBJECTS_LIB_FUNC(cos, Math::Cos);
  5246. REG_OBJECTS_LIB_FUNC(exp, Math::Exp);
  5247. REG_OBJECTS_LIB_FUNC(floor, Math::Floor);
  5248. REG_OBJECTS_LIB_FUNC(log, Math::Log);
  5249. REG_OBJECTS_LIB_FUNC(max, Math::Max);
  5250. REG_OBJECTS_LIB_FUNC(min, Math::Min);
  5251. REG_OBJECTS_LIB_FUNC(pow, Math::Pow);
  5252. REG_OBJECTS_LIB_FUNC(random, Math::Random);
  5253. REG_OBJECTS_LIB_FUNC(round, Math::Round);
  5254. REG_OBJECTS_LIB_FUNC(sin, Math::Sin);
  5255. REG_OBJECTS_LIB_FUNC(sqrt, Math::Sqrt);
  5256. REG_OBJECTS_LIB_FUNC(tan, Math::Tan);
  5257. if (scriptContext->GetConfig()->IsES6MathExtensionsEnabled())
  5258. {
  5259. REG_OBJECTS_LIB_FUNC(log10, Math::Log10);
  5260. REG_OBJECTS_LIB_FUNC(log2, Math::Log2);
  5261. REG_OBJECTS_LIB_FUNC(log1p, Math::Log1p);
  5262. REG_OBJECTS_LIB_FUNC(expm1, Math::Expm1);
  5263. REG_OBJECTS_LIB_FUNC(cosh, Math::Cosh);
  5264. REG_OBJECTS_LIB_FUNC(sinh, Math::Sinh);
  5265. REG_OBJECTS_LIB_FUNC(tanh, Math::Tanh);
  5266. REG_OBJECTS_LIB_FUNC(acosh, Math::Acosh);
  5267. REG_OBJECTS_LIB_FUNC(asinh, Math::Asinh);
  5268. REG_OBJECTS_LIB_FUNC(atanh, Math::Atanh);
  5269. REG_OBJECTS_LIB_FUNC(hypot, Math::Hypot);
  5270. REG_OBJECTS_LIB_FUNC(trunc, Math::Trunc);
  5271. REG_OBJECTS_LIB_FUNC(sign, Math::Sign);
  5272. REG_OBJECTS_LIB_FUNC(cbrt, Math::Cbrt);
  5273. REG_OBJECTS_LIB_FUNC(imul, Math::Imul);
  5274. REG_OBJECTS_LIB_FUNC(clz32, Math::Clz32);
  5275. REG_OBJECTS_LIB_FUNC(fround, Math::Fround);
  5276. }
  5277. return hr;
  5278. }
  5279. HRESULT JavascriptLibrary::ProfilerRegisterNumber()
  5280. {
  5281. HRESULT hr = S_OK;
  5282. REG_GLOBAL_CONSTRUCTOR(Number);
  5283. DEFINE_OBJECT_NAME(Number);
  5284. if (scriptContext->GetConfig()->IsES6NumberExtensionsEnabled())
  5285. {
  5286. REG_OBJECTS_LIB_FUNC(isNaN, JavascriptNumber::EntryIsNaN);
  5287. REG_OBJECTS_LIB_FUNC(isFinite, JavascriptNumber::EntryIsFinite);
  5288. REG_OBJECTS_LIB_FUNC(isInteger, JavascriptNumber::EntryIsInteger);
  5289. REG_OBJECTS_LIB_FUNC(isSafeInteger, JavascriptNumber::EntryIsSafeInteger);
  5290. }
  5291. REG_OBJECTS_LIB_FUNC(toExponential, JavascriptNumber::EntryToExponential);
  5292. REG_OBJECTS_LIB_FUNC(toFixed, JavascriptNumber::EntryToFixed);
  5293. REG_OBJECTS_LIB_FUNC(toPrecision, JavascriptNumber::EntryToPrecision);
  5294. REG_OBJECTS_LIB_FUNC(toLocaleString, JavascriptNumber::EntryToLocaleString);
  5295. REG_OBJECTS_LIB_FUNC(toString, JavascriptNumber::EntryToString);
  5296. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptNumber::EntryValueOf);
  5297. return hr;
  5298. }
  5299. HRESULT JavascriptLibrary::ProfilerRegisterString()
  5300. {
  5301. HRESULT hr = S_OK;
  5302. REG_GLOBAL_CONSTRUCTOR(String);
  5303. DEFINE_OBJECT_NAME(String);
  5304. REG_OBJECTS_LIB_FUNC(fromCharCode, JavascriptString::EntryFromCharCode);
  5305. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  5306. if (config.IsES6UnicodeExtensionsEnabled())
  5307. {
  5308. REG_OBJECTS_LIB_FUNC(fromCodePoint, JavascriptString::EntryFromCodePoint);
  5309. REG_OBJECTS_LIB_FUNC(codePointAt, JavascriptString::EntryCodePointAt);
  5310. REG_OBJECTS_LIB_FUNC(normalize, JavascriptString::EntryNormalize);
  5311. }
  5312. REG_OBJECTS_LIB_FUNC(indexOf, JavascriptString::EntryIndexOf);
  5313. REG_OBJECTS_LIB_FUNC(lastIndexOf, JavascriptString::EntryLastIndexOf);
  5314. REG_OBJECTS_LIB_FUNC(replace, JavascriptString::EntryReplace);
  5315. REG_OBJECTS_LIB_FUNC(search, JavascriptString::EntrySearch);
  5316. REG_OBJECTS_LIB_FUNC(slice, JavascriptString::EntrySlice);
  5317. REG_OBJECTS_LIB_FUNC(charAt, JavascriptString::EntryCharAt);
  5318. REG_OBJECTS_LIB_FUNC(charCodeAt, JavascriptString::EntryCharCodeAt);
  5319. REG_OBJECTS_LIB_FUNC(concat, JavascriptString::EntryConcat);
  5320. REG_OBJECTS_LIB_FUNC(localeCompare, JavascriptString::EntryLocaleCompare);
  5321. REG_OBJECTS_LIB_FUNC(match, JavascriptString::EntryMatch);
  5322. REG_OBJECTS_LIB_FUNC(split, JavascriptString::EntrySplit);
  5323. REG_OBJECTS_LIB_FUNC(substring, JavascriptString::EntrySubstring);
  5324. REG_OBJECTS_LIB_FUNC(substr, JavascriptString::EntrySubstr);
  5325. REG_OBJECTS_LIB_FUNC(toLocaleLowerCase, JavascriptString::EntryToLocaleLowerCase);
  5326. REG_OBJECTS_LIB_FUNC(toLocaleUpperCase, JavascriptString::EntryToLocaleUpperCase);
  5327. REG_OBJECTS_LIB_FUNC(toLowerCase, JavascriptString::EntryToLowerCase);
  5328. REG_OBJECTS_LIB_FUNC(toString, JavascriptString::EntryToString);
  5329. REG_OBJECTS_LIB_FUNC(toUpperCase, JavascriptString::EntryToUpperCase);
  5330. REG_OBJECTS_LIB_FUNC(trim, JavascriptString::EntryTrim);
  5331. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptString::EntryValueOf);
  5332. if (config.SupportsES3Extensions())
  5333. {
  5334. REG_OBJECTS_LIB_FUNC(anchor, JavascriptString::EntryAnchor);
  5335. REG_OBJECTS_LIB_FUNC(big, JavascriptString::EntryBig);
  5336. REG_OBJECTS_LIB_FUNC(blink, JavascriptString::EntryBlink);
  5337. REG_OBJECTS_LIB_FUNC(bold, JavascriptString::EntryBold);
  5338. REG_OBJECTS_LIB_FUNC(fixed, JavascriptString::EntryFixed);
  5339. REG_OBJECTS_LIB_FUNC(fontcolor, JavascriptString::EntryFontColor);
  5340. REG_OBJECTS_LIB_FUNC(fontsize, JavascriptString::EntryFontSize);
  5341. REG_OBJECTS_LIB_FUNC(italics, JavascriptString::EntryItalics);
  5342. REG_OBJECTS_LIB_FUNC(link, JavascriptString::EntryLink);
  5343. REG_OBJECTS_DYNAMIC_LIB_FUNC(L"small", 5, JavascriptString::EntrySmall);
  5344. REG_OBJECTS_LIB_FUNC(strike, JavascriptString::EntryStrike);
  5345. REG_OBJECTS_LIB_FUNC(sub, JavascriptString::EntrySub);
  5346. REG_OBJECTS_LIB_FUNC(sup, JavascriptString::EntrySup);
  5347. }
  5348. if (config.IsES6StringExtensionsEnabled())
  5349. {
  5350. REG_OBJECTS_LIB_FUNC(repeat, JavascriptString::EntryRepeat);
  5351. REG_OBJECTS_LIB_FUNC(startsWith, JavascriptString::EntryStartsWith);
  5352. REG_OBJECTS_LIB_FUNC(endsWith, JavascriptString::EntryEndsWith);
  5353. REG_OBJECTS_LIB_FUNC(includes, JavascriptString::EntryIncludes);
  5354. REG_OBJECTS_LIB_FUNC(trimLeft, JavascriptString::EntryTrimLeft);
  5355. REG_OBJECTS_LIB_FUNC(trimRight, JavascriptString::EntryTrimRight);
  5356. }
  5357. if (config.IsES6StringTemplateEnabled())
  5358. {
  5359. REG_OBJECTS_LIB_FUNC(raw, JavascriptString::EntryRaw);
  5360. }
  5361. if (config.IsES6IteratorsEnabled())
  5362. {
  5363. REG_OBJECTS_LIB_FUNC2(_symbolIterator, L"[Symbol.iterator]", JavascriptString::EntrySymbolIterator);
  5364. }
  5365. return hr;
  5366. }
  5367. HRESULT JavascriptLibrary::ProfilerRegisterRegExp()
  5368. {
  5369. HRESULT hr = S_OK;
  5370. REG_GLOBAL_CONSTRUCTOR(RegExp);
  5371. DEFINE_OBJECT_NAME(RegExp);
  5372. REG_OBJECTS_LIB_FUNC(exec, JavascriptRegExp::EntryExec);
  5373. REG_OBJECTS_LIB_FUNC(test, JavascriptRegExp::EntryTest);
  5374. REG_OBJECTS_LIB_FUNC(toString, JavascriptRegExp::EntryToString);
  5375. // Note: This is deprecated
  5376. REG_OBJECTS_LIB_FUNC(compile, JavascriptRegExp::EntryCompile);
  5377. return hr;
  5378. }
  5379. HRESULT JavascriptLibrary::ProfilerRegisterJSON()
  5380. {
  5381. HRESULT hr = S_OK;
  5382. DEFINE_OBJECT_NAME(JSON);
  5383. REG_OBJECTS_LIB_FUNC(stringify, JSON::Stringify);
  5384. REG_OBJECTS_LIB_FUNC(parse, JSON::Parse);
  5385. return hr;
  5386. }
  5387. HRESULT JavascriptLibrary::ProfilerRegisterWeakMap()
  5388. {
  5389. HRESULT hr = S_OK;
  5390. REG_GLOBAL_CONSTRUCTOR(WeakMap);
  5391. DEFINE_OBJECT_NAME(WeakMap);
  5392. REG_OBJECTS_LIB_FUNC2(delete_, L"delete", JavascriptWeakMap::EntryDelete);
  5393. REG_OBJECTS_LIB_FUNC(get, JavascriptWeakMap::EntryGet);
  5394. REG_OBJECTS_LIB_FUNC(has, JavascriptWeakMap::EntryHas);
  5395. REG_OBJECTS_LIB_FUNC(set, JavascriptWeakMap::EntrySet);
  5396. return hr;
  5397. }
  5398. HRESULT JavascriptLibrary::ProfilerRegisterWeakSet()
  5399. {
  5400. HRESULT hr = S_OK;
  5401. REG_GLOBAL_CONSTRUCTOR(WeakSet);
  5402. DEFINE_OBJECT_NAME(WeakSet);
  5403. REG_OBJECTS_LIB_FUNC(add, JavascriptWeakSet::EntryAdd);
  5404. REG_OBJECTS_LIB_FUNC2(delete_, L"delete", JavascriptWeakSet::EntryDelete);
  5405. REG_OBJECTS_LIB_FUNC(has, JavascriptWeakSet::EntryHas);
  5406. return hr;
  5407. }
  5408. HRESULT JavascriptLibrary::ProfilerRegisterMap()
  5409. {
  5410. HRESULT hr = S_OK;
  5411. REG_GLOBAL_CONSTRUCTOR(Map);
  5412. DEFINE_OBJECT_NAME(Map);
  5413. REG_OBJECTS_LIB_FUNC(clear, JavascriptMap::EntryClear);
  5414. REG_OBJECTS_LIB_FUNC2(delete_, L"delete", JavascriptMap::EntryDelete);
  5415. REG_OBJECTS_LIB_FUNC(forEach, JavascriptMap::EntryForEach);
  5416. REG_OBJECTS_LIB_FUNC(get, JavascriptMap::EntryGet);
  5417. REG_OBJECTS_LIB_FUNC(has, JavascriptMap::EntryHas);
  5418. REG_OBJECTS_LIB_FUNC(set, JavascriptMap::EntrySet);
  5419. if (scriptContext->GetConfig()->IsES6IteratorsEnabled())
  5420. {
  5421. REG_OBJECTS_LIB_FUNC(entries, JavascriptMap::EntryEntries);
  5422. REG_OBJECTS_LIB_FUNC(keys, JavascriptMap::EntryKeys);
  5423. REG_OBJECTS_LIB_FUNC(values, JavascriptMap::EntryValues);
  5424. }
  5425. return hr;
  5426. }
  5427. HRESULT JavascriptLibrary::ProfilerRegisterSet()
  5428. {
  5429. HRESULT hr = S_OK;
  5430. REG_GLOBAL_CONSTRUCTOR(Set);
  5431. DEFINE_OBJECT_NAME(Set);
  5432. REG_OBJECTS_LIB_FUNC(add, JavascriptSet::EntryAdd);
  5433. REG_OBJECTS_LIB_FUNC(clear, JavascriptSet::EntryClear);
  5434. REG_OBJECTS_LIB_FUNC2(delete_, L"delete", JavascriptSet::EntryDelete);
  5435. REG_OBJECTS_LIB_FUNC(forEach, JavascriptSet::EntryForEach);
  5436. REG_OBJECTS_LIB_FUNC(has, JavascriptSet::EntryHas);
  5437. if (scriptContext->GetConfig()->IsES6IteratorsEnabled())
  5438. {
  5439. REG_OBJECTS_LIB_FUNC(entries, JavascriptSet::EntryEntries);
  5440. REG_OBJECTS_LIB_FUNC(values, JavascriptSet::EntryValues);
  5441. }
  5442. return hr;
  5443. }
  5444. HRESULT JavascriptLibrary::ProfilerRegisterSymbol()
  5445. {
  5446. HRESULT hr = S_OK;
  5447. REG_GLOBAL_CONSTRUCTOR(Symbol);
  5448. DEFINE_OBJECT_NAME(Symbol);
  5449. REG_OBJECTS_LIB_FUNC(valueOf, JavascriptSymbol::EntryValueOf);
  5450. REG_OBJECTS_LIB_FUNC(toString, JavascriptSymbol::EntryToString);
  5451. REG_OBJECTS_LIB_FUNC2(for_, L"for", JavascriptSymbol::EntryFor);
  5452. REG_OBJECTS_LIB_FUNC(keyFor, JavascriptSymbol::EntryKeyFor);
  5453. return hr;
  5454. }
  5455. HRESULT JavascriptLibrary::ProfilerRegisterIterator()
  5456. {
  5457. HRESULT hr = S_OK;
  5458. // Array Iterator has no global constructor
  5459. DEFINE_OBJECT_NAME(Iterator);
  5460. REG_OBJECTS_LIB_FUNC2(_symbolIterator, L"[Symbol.iterator]", JavascriptIterator::EntrySymbolIterator);
  5461. return hr;
  5462. }
  5463. HRESULT JavascriptLibrary::ProfilerRegisterArrayIterator()
  5464. {
  5465. HRESULT hr = S_OK;
  5466. // Array Iterator has no global constructor
  5467. DEFINE_OBJECT_NAME(Array Iterator);
  5468. REG_OBJECTS_LIB_FUNC(next, JavascriptArrayIterator::EntryNext);
  5469. return hr;
  5470. }
  5471. HRESULT JavascriptLibrary::ProfilerRegisterMapIterator()
  5472. {
  5473. HRESULT hr = S_OK;
  5474. // Map Iterator has no global constructor
  5475. DEFINE_OBJECT_NAME(Map Iterator);
  5476. REG_OBJECTS_LIB_FUNC(next, JavascriptMapIterator::EntryNext);
  5477. return hr;
  5478. }
  5479. HRESULT JavascriptLibrary::ProfilerRegisterSetIterator()
  5480. {
  5481. HRESULT hr = S_OK;
  5482. // Set Iterator has no global constructor
  5483. DEFINE_OBJECT_NAME(Set Iterator);
  5484. REG_OBJECTS_LIB_FUNC(next, JavascriptSetIterator::EntryNext);
  5485. return hr;
  5486. }
  5487. HRESULT JavascriptLibrary::ProfilerRegisterStringIterator()
  5488. {
  5489. HRESULT hr = S_OK;
  5490. // String Iterator has no global constructor
  5491. DEFINE_OBJECT_NAME(String Iterator);
  5492. REG_OBJECTS_LIB_FUNC(next, JavascriptStringIterator::EntryNext);
  5493. return hr;
  5494. }
  5495. HRESULT JavascriptLibrary::ProfilerRegisterEnumeratorIterator()
  5496. {
  5497. HRESULT hr = S_OK;
  5498. // Enumerator Iterator has no global constructor
  5499. DEFINE_OBJECT_NAME(Enumerator Iterator);
  5500. REG_OBJECTS_LIB_FUNC(next, JavascriptEnumeratorIterator::EntryNext);
  5501. return hr;
  5502. }
  5503. HRESULT JavascriptLibrary::ProfilerRegisterTypedArray()
  5504. {
  5505. HRESULT hr = S_OK;
  5506. // TypedArray has no named global constructor
  5507. DEFINE_OBJECT_NAME(TypedArray);
  5508. REG_OBJECTS_LIB_FUNC(from, TypedArrayBase::EntryFrom);
  5509. REG_OBJECTS_LIB_FUNC(of, TypedArrayBase::EntryOf);
  5510. REG_OBJECTS_LIB_FUNC(set, TypedArrayBase::EntrySet);
  5511. REG_OBJECTS_LIB_FUNC(subarray, TypedArrayBase::EntrySubarray);
  5512. REG_OBJECTS_LIB_FUNC(copyWithin, TypedArrayBase::EntryCopyWithin);
  5513. REG_OBJECTS_LIB_FUNC(every, TypedArrayBase::EntryEvery);
  5514. REG_OBJECTS_LIB_FUNC(fill, TypedArrayBase::EntryFill);
  5515. REG_OBJECTS_LIB_FUNC(filter, TypedArrayBase::EntryFilter);
  5516. REG_OBJECTS_LIB_FUNC(find, TypedArrayBase::EntryFind);
  5517. REG_OBJECTS_LIB_FUNC(findIndex, TypedArrayBase::EntryFindIndex);
  5518. REG_OBJECTS_LIB_FUNC(forEach, TypedArrayBase::EntryForEach);
  5519. REG_OBJECTS_LIB_FUNC(indexOf, TypedArrayBase::EntryIndexOf);
  5520. REG_OBJECTS_LIB_FUNC(join, TypedArrayBase::EntryJoin);
  5521. REG_OBJECTS_LIB_FUNC(lastIndexOf, TypedArrayBase::EntryLastIndexOf);
  5522. REG_OBJECTS_LIB_FUNC(map, TypedArrayBase::EntryMap);
  5523. REG_OBJECTS_LIB_FUNC(reduce, TypedArrayBase::EntryReduce);
  5524. REG_OBJECTS_LIB_FUNC(reduceRight, TypedArrayBase::EntryReduceRight);
  5525. REG_OBJECTS_LIB_FUNC(reverse, TypedArrayBase::EntryReverse);
  5526. REG_OBJECTS_LIB_FUNC(slice, TypedArrayBase::EntrySlice);
  5527. REG_OBJECTS_LIB_FUNC(some, TypedArrayBase::EntrySome);
  5528. REG_OBJECTS_LIB_FUNC(sort, TypedArrayBase::EntrySort);
  5529. ScriptConfiguration const& config = *(scriptContext->GetConfig());
  5530. if (config.IsES7BuiltinsEnabled())
  5531. {
  5532. REG_OBJECTS_LIB_FUNC(includes, TypedArrayBase::EntryIncludes);
  5533. }
  5534. return hr;
  5535. }
  5536. HRESULT JavascriptLibrary::ProfilerRegisterPromise()
  5537. {
  5538. HRESULT hr = S_OK;
  5539. REG_GLOBAL_CONSTRUCTOR(Promise);
  5540. DEFINE_OBJECT_NAME(Promise);
  5541. REG_OBJECTS_LIB_FUNC(all, JavascriptPromise::EntryAll);
  5542. REG_OBJECTS_LIB_FUNC2(catch_, L"catch", JavascriptPromise::EntryCatch);
  5543. REG_OBJECTS_LIB_FUNC(race, JavascriptPromise::EntryRace);
  5544. REG_OBJECTS_LIB_FUNC(resolve, JavascriptPromise::EntryResolve);
  5545. REG_OBJECTS_LIB_FUNC(then, JavascriptPromise::EntryThen);
  5546. return hr;
  5547. }
  5548. HRESULT JavascriptLibrary::ProfilerRegisterProxy()
  5549. {
  5550. HRESULT hr = S_OK;
  5551. REG_GLOBAL_CONSTRUCTOR(Proxy);
  5552. DEFINE_OBJECT_NAME(Proxy);
  5553. REG_OBJECTS_LIB_FUNC(revocable, JavascriptProxy::EntryRevocable);
  5554. return hr;
  5555. }
  5556. HRESULT JavascriptLibrary::ProfilerRegisterReflect()
  5557. {
  5558. HRESULT hr = S_OK;
  5559. DEFINE_OBJECT_NAME(Reflect);
  5560. REG_OBJECTS_LIB_FUNC(defineProperty, JavascriptReflect::EntryDefineProperty);
  5561. REG_OBJECTS_LIB_FUNC(deleteProperty, JavascriptReflect::EntryDeleteProperty);
  5562. REG_OBJECTS_LIB_FUNC(enumerate, JavascriptReflect::EntryEnumerate);
  5563. REG_OBJECTS_LIB_FUNC(get, JavascriptReflect::EntryGet);
  5564. REG_OBJECTS_LIB_FUNC(getOwnPropertyDescriptor, JavascriptReflect::EntryGetOwnPropertyDescriptor);
  5565. REG_OBJECTS_LIB_FUNC(getPrototypeOf, JavascriptReflect::EntryGetPrototypeOf);
  5566. REG_OBJECTS_LIB_FUNC(has, JavascriptReflect::EntryHas);
  5567. REG_OBJECTS_LIB_FUNC(isExtensible, JavascriptReflect::EntryIsExtensible);
  5568. REG_OBJECTS_LIB_FUNC(ownKeys, JavascriptReflect::EntryOwnKeys);
  5569. REG_OBJECTS_LIB_FUNC(preventExtensions, JavascriptReflect::EntryPreventExtensions);
  5570. REG_OBJECTS_LIB_FUNC(set, JavascriptReflect::EntrySet);
  5571. REG_OBJECTS_LIB_FUNC(setPrototypeOf, JavascriptReflect::EntrySetPrototypeOf);
  5572. REG_OBJECTS_LIB_FUNC(apply, JavascriptReflect::EntryApply);
  5573. REG_OBJECTS_LIB_FUNC(construct, JavascriptReflect::EntryConstruct);
  5574. return hr;
  5575. }
  5576. HRESULT JavascriptLibrary::ProfilerRegisterGenerator()
  5577. {
  5578. HRESULT hr = S_OK;
  5579. DEFINE_OBJECT_NAME(Generator);
  5580. REG_OBJECTS_LIB_FUNC(next, JavascriptGenerator::EntryNext);
  5581. REG_OBJECTS_LIB_FUNC(return_, JavascriptGenerator::EntryReturn);
  5582. REG_OBJECTS_LIB_FUNC(throw_, JavascriptGenerator::EntryThrow);
  5583. return hr;
  5584. }
  5585. #if ENABLE_NATIVE_CODEGEN
  5586. HRESULT JavascriptLibrary::ProfilerRegisterSIMD()
  5587. {
  5588. HRESULT hr = S_OK;
  5589. DEFINE_OBJECT_NAME(SIMD);
  5590. // Float32x4
  5591. REG_OBJECTS_LIB_FUNC(Float32x4, SIMDFloat32x4Lib::EntryFloat32x4);
  5592. REG_OBJECTS_LIB_FUNC(check, SIMDFloat32x4Lib::EntryCheck);
  5593. REG_OBJECTS_LIB_FUNC(zero, SIMDFloat32x4Lib::EntryZero);
  5594. REG_OBJECTS_LIB_FUNC(splat, SIMDFloat32x4Lib::EntrySplat);
  5595. REG_OBJECTS_LIB_FUNC(extractLane, SIMDFloat32x4Lib::EntryExtractLane);
  5596. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDFloat32x4Lib::EntryReplaceLane);
  5597. REG_OBJECTS_LIB_FUNC(fromFloat64x2, SIMDFloat32x4Lib::EntryFromFloat64x2);
  5598. REG_OBJECTS_LIB_FUNC(fromFloat64x2Bits, SIMDFloat32x4Lib::EntryFromFloat64x2Bits);
  5599. REG_OBJECTS_LIB_FUNC(fromInt32x4, SIMDFloat32x4Lib::EntryFromInt32x4);
  5600. REG_OBJECTS_LIB_FUNC(fromInt32x4Bits, SIMDFloat32x4Lib::EntryFromInt32x4Bits);
  5601. REG_OBJECTS_LIB_FUNC(add, SIMDFloat32x4Lib::EntryAdd);
  5602. REG_OBJECTS_LIB_FUNC(sub, SIMDFloat32x4Lib::EntrySub);
  5603. REG_OBJECTS_LIB_FUNC(mul, SIMDFloat32x4Lib::EntryMul);
  5604. REG_OBJECTS_LIB_FUNC(div, SIMDFloat32x4Lib::EntryDiv);
  5605. REG_OBJECTS_LIB_FUNC(and, SIMDFloat32x4Lib::EntryAnd);
  5606. REG_OBJECTS_LIB_FUNC(or, SIMDFloat32x4Lib::EntryOr);
  5607. REG_OBJECTS_LIB_FUNC(xor, SIMDFloat32x4Lib::EntryXor);
  5608. REG_OBJECTS_LIB_FUNC(min, SIMDFloat32x4Lib::EntryMin);
  5609. REG_OBJECTS_LIB_FUNC(max, SIMDFloat32x4Lib::EntryMax);
  5610. REG_OBJECTS_LIB_FUNC(scale, SIMDFloat32x4Lib::EntryScale);
  5611. REG_OBJECTS_LIB_FUNC(abs, SIMDFloat32x4Lib::EntryAbs);
  5612. REG_OBJECTS_LIB_FUNC(neg, SIMDFloat32x4Lib::EntryNeg);
  5613. REG_OBJECTS_LIB_FUNC(not, SIMDFloat32x4Lib::EntryNot);
  5614. REG_OBJECTS_LIB_FUNC(sqrt, SIMDFloat32x4Lib::EntrySqrt);
  5615. REG_OBJECTS_LIB_FUNC(reciprocal, SIMDFloat32x4Lib::EntryReciprocal);
  5616. REG_OBJECTS_LIB_FUNC(reciprocalSqrt, SIMDFloat32x4Lib::EntryReciprocalSqrt);
  5617. REG_OBJECTS_LIB_FUNC(lessThan, SIMDFloat32x4Lib::EntryLessThan);
  5618. REG_OBJECTS_LIB_FUNC(lessThanOrEqual, SIMDFloat32x4Lib::EntryLessThanOrEqual);
  5619. REG_OBJECTS_LIB_FUNC(equal, SIMDFloat32x4Lib::EntryEqual);
  5620. REG_OBJECTS_LIB_FUNC(notEqual, SIMDFloat32x4Lib::EntryNotEqual);
  5621. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDFloat32x4Lib::EntryGreaterThan);
  5622. REG_OBJECTS_LIB_FUNC(greaterThanOrEqual, SIMDFloat32x4Lib::EntryGreaterThanOrEqual);
  5623. REG_OBJECTS_LIB_FUNC(swizzle, SIMDFloat32x4Lib::EntrySwizzle);
  5624. REG_OBJECTS_LIB_FUNC(shuffle, SIMDFloat32x4Lib::EntryShuffle);
  5625. REG_OBJECTS_LIB_FUNC(clamp, SIMDFloat32x4Lib::EntryClamp);
  5626. REG_OBJECTS_LIB_FUNC(select, SIMDFloat32x4Lib::EntrySelect);
  5627. // Float64x2
  5628. REG_OBJECTS_LIB_FUNC(Float64x2, SIMDFloat64x2Lib::EntryFloat64x2);
  5629. REG_OBJECTS_LIB_FUNC(check, SIMDFloat64x2Lib::EntryCheck);
  5630. REG_OBJECTS_LIB_FUNC(zero, SIMDFloat64x2Lib::EntryZero);
  5631. REG_OBJECTS_LIB_FUNC(splat, SIMDFloat64x2Lib::EntrySplat);
  5632. REG_OBJECTS_LIB_FUNC(fromFloat32x4, SIMDFloat64x2Lib::EntryFromFloat32x4);
  5633. REG_OBJECTS_LIB_FUNC(fromFloat32x4Bits, SIMDFloat64x2Lib::EntryFromFloat32x4Bits);
  5634. REG_OBJECTS_LIB_FUNC(fromInt32x4, SIMDFloat64x2Lib::EntryFromInt32x4);
  5635. REG_OBJECTS_LIB_FUNC(fromInt32x4Bits, SIMDFloat64x2Lib::EntryFromInt32x4Bits);
  5636. REG_OBJECTS_LIB_FUNC(add, SIMDFloat64x2Lib::EntryAdd);
  5637. REG_OBJECTS_LIB_FUNC(sub, SIMDFloat64x2Lib::EntrySub);
  5638. REG_OBJECTS_LIB_FUNC(mul, SIMDFloat64x2Lib::EntryMul);
  5639. REG_OBJECTS_LIB_FUNC(div, SIMDFloat64x2Lib::EntryDiv);
  5640. REG_OBJECTS_LIB_FUNC(min, SIMDFloat64x2Lib::EntryMin);
  5641. REG_OBJECTS_LIB_FUNC(max, SIMDFloat64x2Lib::EntryMax);
  5642. REG_OBJECTS_LIB_FUNC(scale, SIMDFloat64x2Lib::EntryScale);
  5643. REG_OBJECTS_LIB_FUNC(abs, SIMDFloat64x2Lib::EntryAbs);
  5644. REG_OBJECTS_LIB_FUNC(neg, SIMDFloat64x2Lib::EntryNeg);
  5645. REG_OBJECTS_LIB_FUNC(sqrt, SIMDFloat64x2Lib::EntrySqrt);
  5646. REG_OBJECTS_LIB_FUNC(reciprocal, SIMDFloat64x2Lib::EntryReciprocal);
  5647. REG_OBJECTS_LIB_FUNC(reciprocalSqrt, SIMDFloat64x2Lib::EntryReciprocalSqrt);
  5648. REG_OBJECTS_LIB_FUNC(lessThan, SIMDFloat64x2Lib::EntryLessThan);
  5649. REG_OBJECTS_LIB_FUNC(lessThanOrEqual, SIMDFloat64x2Lib::EntryLessThanOrEqual);
  5650. REG_OBJECTS_LIB_FUNC(equal, SIMDFloat64x2Lib::EntryEqual);
  5651. REG_OBJECTS_LIB_FUNC(notEqual, SIMDFloat64x2Lib::EntryNotEqual);
  5652. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDFloat64x2Lib::EntryGreaterThan);
  5653. REG_OBJECTS_LIB_FUNC(greaterThanOrEqual, SIMDFloat64x2Lib::EntryGreaterThanOrEqual);
  5654. REG_OBJECTS_LIB_FUNC(swizzle, SIMDFloat64x2Lib::EntrySwizzle);
  5655. REG_OBJECTS_LIB_FUNC(shuffle, SIMDFloat64x2Lib::EntryShuffle);
  5656. REG_OBJECTS_LIB_FUNC(clamp, SIMDFloat64x2Lib::EntryClamp);
  5657. REG_OBJECTS_LIB_FUNC(select, SIMDFloat64x2Lib::EntrySelect);
  5658. // Int32x4
  5659. REG_OBJECTS_LIB_FUNC(Int32x4, SIMDInt32x4Lib::EntryInt32x4);
  5660. REG_OBJECTS_LIB_FUNC(check, SIMDInt32x4Lib::EntryCheck);
  5661. REG_OBJECTS_LIB_FUNC(zero, SIMDInt32x4Lib::EntryZero);
  5662. REG_OBJECTS_LIB_FUNC(splat, SIMDInt32x4Lib::EntrySplat);
  5663. REG_OBJECTS_LIB_FUNC(bool_, SIMDInt32x4Lib::EntryBool);
  5664. REG_OBJECTS_LIB_FUNC(extractLane, SIMDInt32x4Lib::EntryExtractLane);
  5665. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDInt32x4Lib::EntryReplaceLane);
  5666. REG_OBJECTS_LIB_FUNC(withFlagX, SIMDInt32x4Lib::EntryWithFlagX);
  5667. REG_OBJECTS_LIB_FUNC(withFlagY, SIMDInt32x4Lib::EntryWithFlagY);
  5668. REG_OBJECTS_LIB_FUNC(withFlagZ, SIMDInt32x4Lib::EntryWithFlagZ);
  5669. REG_OBJECTS_LIB_FUNC(withFlagW, SIMDInt32x4Lib::EntryWithFlagW);
  5670. REG_OBJECTS_LIB_FUNC(fromFloat64x2, SIMDInt32x4Lib::EntryFromFloat64x2);
  5671. REG_OBJECTS_LIB_FUNC(fromFloat64x2Bits, SIMDInt32x4Lib::EntryFromFloat64x2Bits);
  5672. REG_OBJECTS_LIB_FUNC(fromFloat32x4, SIMDInt32x4Lib::EntryFromFloat32x4);
  5673. REG_OBJECTS_LIB_FUNC(fromFloat32x4Bits, SIMDInt32x4Lib::EntryFromFloat32x4Bits);
  5674. REG_OBJECTS_LIB_FUNC(add, SIMDInt32x4Lib::EntryAdd);
  5675. REG_OBJECTS_LIB_FUNC(sub, SIMDInt32x4Lib::EntrySub);
  5676. REG_OBJECTS_LIB_FUNC(mul, SIMDInt32x4Lib::EntryMul);
  5677. REG_OBJECTS_LIB_FUNC(and, SIMDInt32x4Lib::EntryAnd);
  5678. REG_OBJECTS_LIB_FUNC(or, SIMDInt32x4Lib::EntryOr);
  5679. REG_OBJECTS_LIB_FUNC(xor, SIMDInt32x4Lib::EntryXor);
  5680. REG_OBJECTS_LIB_FUNC(neg, SIMDInt32x4Lib::EntryNeg);
  5681. REG_OBJECTS_LIB_FUNC(not, SIMDInt32x4Lib::EntryNot);
  5682. REG_OBJECTS_LIB_FUNC(lessThan, SIMDInt32x4Lib::EntryLessThan);
  5683. REG_OBJECTS_LIB_FUNC(equal, SIMDInt32x4Lib::EntryEqual);
  5684. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDInt32x4Lib::EntryGreaterThan);
  5685. REG_OBJECTS_LIB_FUNC(swizzle, SIMDInt32x4Lib::EntrySwizzle);
  5686. REG_OBJECTS_LIB_FUNC(shuffle, SIMDInt32x4Lib::EntryShuffle);
  5687. REG_OBJECTS_LIB_FUNC(shiftLeft, SIMDInt32x4Lib::EntryShiftLeft);
  5688. REG_OBJECTS_LIB_FUNC(shiftRightLogical, SIMDInt32x4Lib::EntryShiftRightLogical);
  5689. REG_OBJECTS_LIB_FUNC(shiftRightArithmetic, SIMDInt32x4Lib::EntryShiftRightArithmetic);
  5690. REG_OBJECTS_LIB_FUNC(select, SIMDInt32x4Lib::EntrySelect);
  5691. // Int8x16
  5692. REG_OBJECTS_LIB_FUNC(Int8x16, SIMDInt8x16Lib::EntryInt8x16);
  5693. REG_OBJECTS_LIB_FUNC(check, SIMDInt8x16Lib::EntryCheck);
  5694. REG_OBJECTS_LIB_FUNC(zero, SIMDInt8x16Lib::EntryZero);
  5695. REG_OBJECTS_LIB_FUNC(splat, SIMDInt8x16Lib::EntrySplat);
  5696. REG_OBJECTS_LIB_FUNC(fromFloat32x4Bits, SIMDInt8x16Lib::EntryFromFloat32x4Bits);
  5697. REG_OBJECTS_LIB_FUNC(fromInt32x4Bits, SIMDInt8x16Lib::EntryFromInt32x4Bits);
  5698. REG_OBJECTS_LIB_FUNC(neg, SIMDInt8x16Lib::EntryNeg);
  5699. REG_OBJECTS_LIB_FUNC(not, SIMDInt8x16Lib::EntryNot);
  5700. REG_OBJECTS_LIB_FUNC(add, SIMDInt8x16Lib::EntryAdd);
  5701. REG_OBJECTS_LIB_FUNC(sub, SIMDInt8x16Lib::EntrySub);
  5702. REG_OBJECTS_LIB_FUNC(mul, SIMDInt8x16Lib::EntryMul);
  5703. REG_OBJECTS_LIB_FUNC(and, SIMDInt8x16Lib::EntryAnd);
  5704. REG_OBJECTS_LIB_FUNC(or, SIMDInt8x16Lib::EntryOr);
  5705. REG_OBJECTS_LIB_FUNC(xor, SIMDInt8x16Lib::EntryXor);
  5706. REG_OBJECTS_LIB_FUNC(lessThan, SIMDInt8x16Lib::EntryLessThan);
  5707. REG_OBJECTS_LIB_FUNC(equal, SIMDInt8x16Lib::EntryEqual);
  5708. REG_OBJECTS_LIB_FUNC(greaterThan, SIMDInt8x16Lib::EntryGreaterThan);
  5709. REG_OBJECTS_LIB_FUNC(shiftLeftByScalar, SIMDInt8x16Lib::EntryShiftLeftByScalar);
  5710. REG_OBJECTS_LIB_FUNC(shiftRightLogicalByScalar, SIMDInt8x16Lib::EntryShiftRightLogicalByScalar);
  5711. REG_OBJECTS_LIB_FUNC(shiftRightArithmeticByScalar, SIMDInt8x16Lib::EntryShiftRightArithmeticByScalar);
  5712. REG_OBJECTS_LIB_FUNC(extractLane, SIMDInt8x16Lib::EntryExtractLane);
  5713. REG_OBJECTS_LIB_FUNC(replaceLane, SIMDInt8x16Lib::EntryReplaceLane);
  5714. return hr;
  5715. }
  5716. #endif
  5717. #if DBG
  5718. void JavascriptLibrary::DumpLibraryByteCode()
  5719. {
  5720. #ifdef ENABLE_INTL_OBJECT
  5721. // We aren't going to be passing in a number to check range of -dump:LibInit, that will be done by Intl/Promise
  5722. // This is just to force init Intl code if dump:LibInit has been passed
  5723. if (CONFIG_ISENABLED(DumpFlag) && Js::Configuration::Global.flags.Dump.IsEnabled(Js::JsLibInitPhase))
  5724. {
  5725. for (uint i = 0; i <= MaxEngineInterfaceExtensionKind; i++)
  5726. {
  5727. EngineExtensionObjectBase* engineExtension = this->GetEngineInterfaceObject()->GetEngineExtension((Js::EngineInterfaceExtensionKind)i);
  5728. if (engineExtension != nullptr)
  5729. {
  5730. engineExtension->DumpByteCode();
  5731. }
  5732. }
  5733. }
  5734. #endif
  5735. }
  5736. #endif
  5737. #ifdef IR_VIEWER
  5738. HRESULT JavascriptLibrary::ProfilerRegisterIRViewer()
  5739. {
  5740. HRESULT hr = S_OK;
  5741. DEFINE_OBJECT_NAME(IRViewer);
  5742. // TODO (t-doilij) move GlobalObject::EntryParseIR to JavascriptIRViewer::EntryParseIR
  5743. REG_LIB_FUNC_CORE(pwszObjectName, L"parseIR", scriptContext->GetOrAddPropertyIdTracked(L"parseIR"), GlobalObject::EntryParseIR);
  5744. REG_LIB_FUNC_CORE(pwszObjectName, L"functionList", scriptContext->GetOrAddPropertyIdTracked(L"functionList"), GlobalObject::EntryFunctionList);
  5745. REG_LIB_FUNC_CORE(pwszObjectName, L"rejitFunction", scriptContext->GetOrAddPropertyIdTracked(L"rejitFunction"), GlobalObject::EntryRejitFunction);
  5746. return hr;
  5747. }
  5748. #endif /* IR_VIEWER */
  5749. }