JavascriptLibrary.cpp 478 KB

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