JavascriptLibrary.cpp 492 KB

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