JavascriptLibrary.cpp 434 KB

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