JavascriptLibrary.cpp 435 KB

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