JavascriptLibrary.cpp 490 KB

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