JavascriptLibrary.cpp 440 KB

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