JavascriptLibrary.cpp 464 KB

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