JavascriptLibrary.cpp 406 KB

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