AtomicPlugin.h 209 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969
  1. /*
  2. * Duktape public API for Duktape 1.2.1.
  3. * See the API reference for documentation on call semantics.
  4. * The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
  5. * include guard. Other parts of the header are Duktape
  6. * internal and related to platform/compiler/feature detection.
  7. *
  8. * Git commit 74bd1c845e5198b5e2d6cb7c98e54c3af1d6c0e4 (v1.2.1).
  9. *
  10. * See Duktape AUTHORS.rst and LICENSE.txt for copyright and
  11. * licensing information.
  12. */
  13. /* LICENSE.txt */
  14. /*
  15. * ===============
  16. * Duktape license
  17. * ===============
  18. *
  19. * (http://opensource.org/licenses/MIT)
  20. *
  21. * Copyright (c) 2013-2015 by Duktape authors (see AUTHORS.rst)
  22. *
  23. * Permission is hereby granted, free of charge, to any person obtaining a copy
  24. * of this software and associated documentation files (the "Software"), to deal
  25. * in the Software without restriction, including without limitation the rights
  26. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  27. * copies of the Software, and to permit persons to whom the Software is
  28. * furnished to do so, subject to the following conditions:
  29. *
  30. * The above copyright notice and this permission notice shall be included in
  31. * all copies or substantial portions of the Software.
  32. *
  33. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  34. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  35. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  36. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  37. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  38. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  39. * THE SOFTWARE.
  40. *
  41. */
  42. /* AUTHORS.rst */
  43. /*
  44. * ===============
  45. * Duktape authors
  46. * ===============
  47. *
  48. * Copyright
  49. * =========
  50. *
  51. * Duktape copyrights are held by its authors. Each author has a copyright
  52. * to their contribution, and agrees to irrevocably license the contribution
  53. * under the Duktape ``LICENSE.txt``.
  54. *
  55. * Authors
  56. * =======
  57. *
  58. * Please include an e-mail address, a link to your GitHub profile, or something
  59. * similar to allow your contribution to be identified accurately.
  60. *
  61. * The following people have contributed code and agreed to irrevocably license
  62. * their contributions under the Duktape ``LICENSE.txt`` (in order of appearance):
  63. *
  64. * * Sami Vaarala <[email protected]>
  65. * * Niki Dobrev
  66. * * Andreas \u00d6man <[email protected]>
  67. * * L\u00e1szl\u00f3 Lang\u00f3 <[email protected]>
  68. * * Legimet <[email protected]>
  69. *
  70. * Other contributions
  71. * ===================
  72. *
  73. * The following people have contributed something other than code (e.g. reported
  74. * bugs, provided ideas, etc; roughly in order of appearance):
  75. *
  76. * * Greg Burns
  77. * * Anthony Rabine
  78. * * Carlos Costa
  79. * * Aur\u00e9lien Bouilland
  80. * * Preet Desai (Pris Matic)
  81. * * judofyr (http://www.reddit.com/user/judofyr)
  82. * * Jason Woofenden
  83. * * Micha\u0142 Przyby\u015b
  84. * * Anthony Howe
  85. * * Conrad Pankoff
  86. * * Jim Schimpf
  87. * * Rajaran Gaunker (https://github.com/zimbabao)
  88. * * Andreas \u00d6man
  89. * * Doug Sanden
  90. * * Josh Engebretson (https://github.com/JoshEngebretson)
  91. * * Remo Eichenberger (https://github.com/remoe)
  92. * * Mamod Mehyar (https://github.com/mamod)
  93. * * David Demelier (https://github.com/hftmarkand)
  94. * * Tim Caswell (https://github.com/creationix)
  95. * * Mitchell Blank Jr (https://github.com/mitchblank)
  96. * * https://github.com/yushli
  97. * * Seo Sanghyeon (https://github.com/sanxiyn)
  98. * * Han ChoongWoo (https://github.com/tunz)
  99. * * Joshua Peek (https://github.com/josh)
  100. * * Bruce E. Pascoe (https://github.com/fatcerberus)
  101. * * https://github.com/Kelledin
  102. *
  103. * If you are accidentally missing from this list, send me an e-mail
  104. * (``[email protected]``) and I'll fix the omission.
  105. */
  106. #ifndef DUKTAPE_H_INCLUDED
  107. #define DUKTAPE_H_INCLUDED
  108. #define DUK_SINGLE_FILE
  109. #define DUK_OPT_NO_VOLUNTARY_GC
  110. /*
  111. * Determine platform features, select feature selection defines
  112. * (e.g. _XOPEN_SOURCE), include system headers, and define DUK_USE_XXX
  113. * defines which are (only) checked in Duktape internal code for
  114. * activated features. Duktape feature selection is based on automatic
  115. * feature detection, user supplied DUK_OPT_xxx defines, and optionally
  116. * a "duk_custom.h" user header (if DUK_OPT_HAVE_CUSTOM_H is defined).
  117. *
  118. * When compiling Duktape, DUK_COMPILING_DUKTAPE is set, and this file
  119. * is included before any system headers are included. Feature selection
  120. * defines (e.g. _XOPEN_SOURCE) are defined here before any system headers
  121. * are included (which is a requirement for system headers to work correctly).
  122. * This file is responsible for including all system headers and contains
  123. * all platform dependent cruft in general. When compiling user code,
  124. * DUK_COMPILING_DUKTAPE is not defined, and we must avoid e.g. defining
  125. * unnecessary feature selection defines.
  126. *
  127. * The general order of handling:
  128. * - Compiler feature detection (require no includes)
  129. * - Intermediate platform detection (-> easier platform defines)
  130. * - Platform detection, system includes, byte order detection, etc
  131. * - ANSI C wrappers (e.g. DUK_MEMCMP), wrappers for constants, etc
  132. * - DUK_USE_xxx defines are resolved based on input defines
  133. * - Duktape Date provider settings
  134. * - Final sanity checks
  135. *
  136. * DUK_F_XXX are internal feature detection macros which should not be
  137. * used outside this header.
  138. *
  139. * Useful resources:
  140. *
  141. * http://sourceforge.net/p/predef/wiki/Home/
  142. * http://sourceforge.net/p/predef/wiki/Architectures/
  143. * http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor
  144. * http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
  145. *
  146. * Preprocessor defines available in a particular GCC:
  147. *
  148. * gcc -dM -E - </dev/null # http://www.brain-dump.org/blog/entry/107
  149. */
  150. #ifndef DUK_FEATURES_H_INCLUDED
  151. #define DUK_FEATURES_H_INCLUDED
  152. /*
  153. * Compiler features
  154. */
  155. #undef DUK_F_C99
  156. #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  157. #define DUK_F_C99
  158. #endif
  159. #undef DUK_F_CPP
  160. #if defined(__cplusplus)
  161. #define DUK_F_CPP
  162. #endif
  163. #undef DUK_F_CPP11
  164. #if defined(__cplusplus) && (__cplusplus >= 201103L)
  165. #define DUK_F_CPP11
  166. #endif
  167. /*
  168. * Provides the duk_rdtsc() inline function (if available), limited to
  169. * GCC C99.
  170. *
  171. * See: http://www.mcs.anl.gov/~kazutomo/rdtsc.html
  172. */
  173. /* XXX: more accurate detection of what gcc versions work; more inline
  174. * asm versions for other compilers.
  175. */
  176. #if defined(__GNUC__) && defined(__i386__) && defined(DUK_F_C99) && \
  177. !defined(__cplusplus) /* unsigned long long not standard */
  178. static __inline__ unsigned long long duk_rdtsc(void) {
  179. unsigned long long int x;
  180. __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
  181. return x;
  182. }
  183. #define DUK_RDTSC_AVAILABLE 1
  184. #elif defined(__GNUC__) && defined(__x86_64__) && defined(DUK_F_C99) && \
  185. !defined(__cplusplus) /* unsigned long long not standard */
  186. static __inline__ unsigned long long duk_rdtsc(void) {
  187. unsigned hi, lo;
  188. __asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
  189. return ((unsigned long long) lo) | (((unsigned long long) hi) << 32);
  190. }
  191. #define DUK_RDTSC_AVAILABLE 1
  192. #else
  193. /* not available */
  194. #undef DUK_RDTSC_AVAILABLE
  195. #endif
  196. /*
  197. * Intermediate platform, architecture, and compiler detection. These are
  198. * hopelessly intertwined - e.g. architecture defines depend on compiler etc.
  199. *
  200. * Provide easier defines for platforms and compilers which are often tricky
  201. * or verbose to detect. The intent is not to provide intermediate defines for
  202. * all features; only if existing feature defines are inconvenient.
  203. */
  204. /* Intel x86 (32-bit) */
  205. #if defined(i386) || defined(__i386) || defined(__i386__) || \
  206. defined(__i486__) || defined(__i586__) || defined(__i686__) || \
  207. defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \
  208. defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) || defined(ANDROID) || defined(EMSCRIPTEN)
  209. #define DUK_F_X86
  210. #endif
  211. /* AMD64 (64-bit) */
  212. #if defined(__amd64__) || defined(__amd64) || \
  213. defined(__x86_64__) || defined(__x86_64) || \
  214. defined(_M_X64) || defined(_M_AMD64)
  215. #define DUK_F_X64
  216. #endif
  217. /* X32: 64-bit with 32-bit pointers (allows packed tvals). X32 support is
  218. * not very mature yet.
  219. *
  220. * https://sites.google.com/site/x32abi/
  221. */
  222. #if defined(DUK_F_X64) && \
  223. (defined(_ILP32) || defined(__ILP32__))
  224. #define DUK_F_X32
  225. /* define only one of: DUK_F_X86, DUK_F_X32, or DUK_F_X64 */
  226. #undef DUK_F_X64
  227. #undef DUK_F_X86
  228. #endif
  229. /* ARM */
  230. #if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM)
  231. #define DUK_F_ARM
  232. #endif
  233. /* MIPS */
  234. /* Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
  235. #if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \
  236. defined(_R3000) || defined(_R4000) || defined(_R5900) || \
  237. defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \
  238. defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \
  239. defined(__mips) || defined(__MIPS__)
  240. #define DUK_F_MIPS
  241. #if defined(__LP64__) || defined(__mips64) || defined(__mips64__) || \
  242. defined(__mips_n64)
  243. #define DUK_F_MIPS64
  244. #else
  245. #define DUK_F_MIPS32
  246. #endif
  247. #endif
  248. /* SuperH */
  249. #if defined(__sh__) || \
  250. defined(__sh1__) || defined(__SH1__) || \
  251. defined(__sh2__) || defined(__SH2__) || \
  252. defined(__sh3__) || defined(__SH3__) || \
  253. defined(__sh4__) || defined(__SH4__) || \
  254. defined(__sh5__) || defined(__SH5__)
  255. #define DUK_F_SUPERH
  256. #endif
  257. /* Motorola 68K. Not defined by VBCC, so user must define one of these
  258. * manually when using VBCC.
  259. */
  260. #if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
  261. #define DUK_F_M68K
  262. #endif
  263. /* Linux */
  264. #if defined(__linux) || defined(__linux__) || defined(linux)
  265. #define DUK_F_LINUX
  266. #endif
  267. /* FreeBSD */
  268. #if defined(__FreeBSD__) || defined(__FreeBSD)
  269. #define DUK_F_FREEBSD
  270. #endif
  271. /* NetBSD */
  272. #if defined(__NetBSD__) || defined(__NetBSD)
  273. #define DUK_F_NETBSD
  274. #endif
  275. /* OpenBSD */
  276. #if defined(__OpenBSD__) || defined(__OpenBSD)
  277. #define DUK_F_OPENBSD
  278. #endif
  279. /* BSD variant */
  280. #if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
  281. defined(__bsdi__) || defined(__DragonFly__)
  282. #define DUK_F_BSD
  283. #endif
  284. /* Generic Unix (includes Cygwin) */
  285. #if defined(__unix) || defined(__unix__) || defined(unix) || \
  286. defined(DUK_F_LINUX) || defined(DUK_F_BSD)
  287. #define DUK_F_UNIX
  288. #endif
  289. /* Cygwin */
  290. #if defined(__CYGWIN__)
  291. #define DUK_F_CYGWIN
  292. #endif
  293. /* Windows (32-bit or above) */
  294. #if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \
  295. defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
  296. #define DUK_F_WINDOWS
  297. #endif
  298. #if defined(__APPLE__)
  299. #define DUK_F_APPLE
  300. #endif
  301. /* Atari ST TOS. __TOS__ defined by PureC (which doesn't work as a target now
  302. * because int is 16-bit, to be fixed). No platform define in VBCC apparently,
  303. * so to use with VBCC, user must define '__TOS__' manually.
  304. */
  305. #if defined(__TOS__)
  306. #define DUK_F_TOS
  307. #endif
  308. /* AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
  309. * define 'AMIGA' manually.
  310. */
  311. #if defined(AMIGA) || defined(__amigaos__)
  312. #define DUK_F_AMIGAOS
  313. #endif
  314. /* Flash player (e.g. Crossbridge) */
  315. #if defined(__FLASHPLAYER__)
  316. #define DUK_F_FLASHPLAYER
  317. #endif
  318. /* Emscripten (provided explicitly by user), improve if possible */
  319. #if defined(EMSCRIPTEN)
  320. #define DUK_F_EMSCRIPTEN
  321. #endif
  322. /* QNX */
  323. #if defined(__QNX__)
  324. #define DUK_F_QNX
  325. #endif
  326. /* TI-Nspire (using Ndless) */
  327. #if defined(_TINSPIRE)
  328. #define DUK_F_TINSPIRE
  329. #endif
  330. /* GCC and GCC version convenience define. */
  331. #if defined(__GNUC__)
  332. #define DUK_F_GCC
  333. #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
  334. /* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
  335. #define DUK_F_GCC_VERSION (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
  336. #else
  337. #error cannot figure out gcc version
  338. #endif
  339. #endif
  340. /* Clang */
  341. #if defined(__clang__)
  342. #define DUK_F_CLANG
  343. /* It seems clang also defines __GNUC__, so undo the GCC detection. */
  344. #if defined(DUK_F_GCC)
  345. #undef DUK_F_GCC
  346. #endif
  347. #if defined(DUK_F_GCC_VERSION)
  348. #undef DUK_F_GCC_VERSION
  349. #endif
  350. #endif
  351. /* MSVC */
  352. #if defined(_MSC_VER)
  353. /* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
  354. * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
  355. * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
  356. */
  357. #define DUK_F_MSVC
  358. #if defined(_MSC_FULL_VER)
  359. #if (_MSC_FULL_VER > 100000000)
  360. #define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
  361. #else
  362. #define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
  363. #endif
  364. #endif
  365. #endif /* _MSC_VER */
  366. /* MinGW */
  367. #if defined(__MINGW32__) || defined(__MINGW64__)
  368. /* NOTE: Also GCC flags are detected (DUK_F_GCC etc). */
  369. #define DUK_F_MINGW
  370. #endif
  371. /* BCC (Bruce's C compiler): this is a "torture target" for compilation */
  372. #if defined(__BCC__) || defined(__BCC_VERSION__)
  373. #define DUK_F_BCC
  374. #endif
  375. #if defined(__VBCC__)
  376. #define DUK_F_VBCC
  377. #endif
  378. #if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
  379. !defined(DUK_F_BCC)
  380. /* ULL / LL preprocessor constants should be avoided because they're not
  381. * always available. With suitable options, some compilers will support
  382. * 64-bit integer types but won't support ULL / LL preprocessor constants.
  383. * Assume C99/C++11 environments have these. However, BCC is nominally
  384. * C99 but doesn't support these constants.
  385. */
  386. #define DUK_F_ULL_CONSTS
  387. #endif
  388. /*
  389. * Platform detection, system includes, Date provider selection.
  390. *
  391. * Feature selection (e.g. _XOPEN_SOURCE) must happen before any system
  392. * headers are included. This header should avoid providing any feature
  393. * selection defines when compiling user code (only when compiling Duktape
  394. * itself). If a feature selection option is required for user code to
  395. * compile correctly (e.g. it is needed for type detection), it should
  396. * probably be -checked- here, not defined here.
  397. *
  398. * Date provider selection seems a bit out-of-place here, but since
  399. * the date headers and provider functions are heavily platform
  400. * specific, there's little point in duplicating the platform if-else
  401. * ladder. All platform specific Date provider functions are in
  402. * duk_bi_date.c; here we provide appropriate #defines to enable them,
  403. * and include all the necessary system headers so that duk_bi_date.c
  404. * compiles. Date "providers" are:
  405. *
  406. * NOW = getting current time (required)
  407. * TZO = getting local time offset (required)
  408. * PRS = parse datetime (optional)
  409. * FMT = format datetime (optional)
  410. *
  411. * There's a lot of duplication here, unfortunately, because many
  412. * platforms have similar (but not identical) headers, Date providers,
  413. * etc. The duplication could be removed by more complicated nested
  414. * #ifdefs, but it would then be more difficult to make fixes which
  415. * affect only a specific platform.
  416. *
  417. * XXX: add a way to provide custom functions to provide the critical
  418. * primitives; this would be convenient when porting to unknown platforms
  419. * (rather than muck with Duktape internals).
  420. */
  421. #if defined(DUK_COMPILING_DUKTAPE) && \
  422. (defined(DUK_F_LINUX) || defined(DUK_F_EMSCRIPTEN))
  423. /* A more recent Emscripten (2014-05) seems to lack "linux" environment
  424. * defines, so check for Emscripten explicitly.
  425. */
  426. #ifndef _POSIX_C_SOURCE
  427. #define _POSIX_C_SOURCE 200809L
  428. #endif
  429. #ifndef _GNU_SOURCE
  430. #define _GNU_SOURCE /* e.g. getdate_r */
  431. #endif
  432. #ifndef _XOPEN_SOURCE
  433. #define _XOPEN_SOURCE /* e.g. strptime */
  434. #endif
  435. #endif
  436. #if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
  437. /* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
  438. #define _XOPEN_SOURCE 600
  439. #define _POSIX_C_SOURCE 200112L
  440. #endif
  441. #undef DUK_F_MSVC_CRT_SECURE
  442. #if defined(DUK_F_WINDOWS) && defined(_MSC_VER)
  443. /* http://msdn.microsoft.com/en-us/library/8ef0s5kh.aspx
  444. * http://msdn.microsoft.com/en-us/library/wd3wzwts.aspx
  445. * Seem to be available since VS2005.
  446. */
  447. #if (_MSC_VER >= 1400)
  448. /* VS2005+, secure CRT functions are preferred. Windows Store applications
  449. * (and probably others) should use these.
  450. */
  451. #define DUK_F_MSVC_CRT_SECURE
  452. #endif
  453. #if (_MSC_VER < 1700)
  454. /* VS2012+ has stdint.h, < VS2012 does not (but it's available for download). */
  455. #define DUK_F_NO_STDINT_H
  456. #endif
  457. /* Initial fix: disable secure CRT related warnings when compiling Duktape
  458. * itself (must be defined before including Windows headers). Don't define
  459. * for user code including duktape.h.
  460. */
  461. #if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
  462. #define _CRT_SECURE_NO_WARNINGS
  463. #endif
  464. #endif /* DUK_F_WINDOWS && _MSC_VER */
  465. #if defined(DUK_F_TOS) || defined(DUK_F_BCC)
  466. #define DUK_F_NO_STDINT_H
  467. #endif
  468. /* Workaround for older C++ compilers before including <inttypes.h>,
  469. * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
  470. */
  471. #if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
  472. #define __STDC_LIMIT_MACROS
  473. #endif
  474. #if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
  475. #define __STDC_CONSTANT_MACROS
  476. #endif
  477. #if defined(__APPLE__)
  478. /* Mac OSX, iPhone, Darwin */
  479. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  480. #define DUK_USE_DATE_TZO_GMTIME_R
  481. #define DUK_USE_DATE_PRS_STRPTIME
  482. #define DUK_USE_DATE_FMT_STRFTIME
  483. #include <TargetConditionals.h>
  484. #include <architecture/byte_order.h>
  485. #include <limits.h>
  486. #include <sys/param.h>
  487. #include <sys/time.h>
  488. #include <time.h>
  489. #elif defined(DUK_F_OPENBSD)
  490. /* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
  491. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  492. #define DUK_USE_DATE_TZO_GMTIME_R
  493. #define DUK_USE_DATE_PRS_STRPTIME
  494. #define DUK_USE_DATE_FMT_STRFTIME
  495. #include <sys/types.h>
  496. #include <sys/endian.h>
  497. #include <limits.h>
  498. #include <sys/param.h>
  499. #include <sys/time.h>
  500. #include <time.h>
  501. #elif defined(DUK_F_BSD)
  502. /* other BSD */
  503. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  504. #define DUK_USE_DATE_TZO_GMTIME_R
  505. #define DUK_USE_DATE_PRS_STRPTIME
  506. #define DUK_USE_DATE_FMT_STRFTIME
  507. #include <sys/types.h>
  508. #include <sys/endian.h>
  509. #include <limits.h>
  510. #include <sys/param.h>
  511. #include <sys/time.h>
  512. #include <time.h>
  513. #elif defined(DUK_F_TOS)
  514. /* Atari ST TOS */
  515. #define DUK_USE_DATE_NOW_TIME
  516. #define DUK_USE_DATE_TZO_GMTIME
  517. /* no parsing (not an error) */
  518. #define DUK_USE_DATE_FMT_STRFTIME
  519. #include <limits.h>
  520. #include <time.h>
  521. #elif defined(DUK_F_AMIGAOS)
  522. #if defined(DUK_F_M68K)
  523. /* AmigaOS on M68k */
  524. #define DUK_USE_DATE_NOW_TIME
  525. #define DUK_USE_DATE_TZO_GMTIME
  526. /* no parsing (not an error) */
  527. #define DUK_USE_DATE_FMT_STRFTIME
  528. #include <limits.h>
  529. #include <time.h>
  530. #else
  531. #error AmigaOS but not M68K, not supported now
  532. #endif
  533. #elif defined(DUK_F_WINDOWS)
  534. /* Windows 32-bit and 64-bit are currently the same. */
  535. /* MSVC does not have sys/param.h */
  536. #define DUK_USE_DATE_NOW_WINDOWS
  537. #define DUK_USE_DATE_TZO_WINDOWS
  538. /* Note: PRS and FMT are intentionally left undefined for now. This means
  539. * there is no platform specific date parsing/formatting but there is still
  540. * the ISO 8601 standard format.
  541. */
  542. #include <windows.h>
  543. #include <limits.h>
  544. // ATOMIC BEGIN
  545. #ifdef GetObject
  546. #undef GetObject
  547. #endif
  548. #ifdef MessageBox
  549. #undef MessageBox
  550. #endif
  551. #ifdef GetMessage
  552. #undef GetMessage
  553. #endif
  554. // ATOMIC END
  555. #elif defined(DUK_F_FLASHPLAYER)
  556. /* Crossbridge */
  557. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  558. #define DUK_USE_DATE_TZO_GMTIME_R
  559. #define DUK_USE_DATE_PRS_STRPTIME
  560. #define DUK_USE_DATE_FMT_STRFTIME
  561. #include <endian.h>
  562. #include <limits.h>
  563. #include <sys/param.h>
  564. #include <sys/time.h>
  565. #include <time.h>
  566. #elif defined(DUK_F_QNX)
  567. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  568. #define DUK_USE_DATE_TZO_GMTIME_R
  569. #define DUK_USE_DATE_PRS_STRPTIME
  570. #define DUK_USE_DATE_FMT_STRFTIME
  571. #include <sys/types.h>
  572. #include <limits.h>
  573. #include <sys/param.h>
  574. #include <sys/time.h>
  575. #include <time.h>
  576. #elif defined(DUK_F_TINSPIRE)
  577. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  578. #define DUK_USE_DATE_TZO_GMTIME_R
  579. #define DUK_USE_DATE_PRS_STRPTIME
  580. #define DUK_USE_DATE_FMT_STRFTIME
  581. #include <sys/types.h>
  582. #include <limits.h>
  583. #include <sys/param.h>
  584. #include <sys/time.h>
  585. #include <time.h>
  586. #elif defined(DUK_F_LINUX)
  587. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  588. #define DUK_USE_DATE_TZO_GMTIME_R
  589. #define DUK_USE_DATE_PRS_STRPTIME
  590. #define DUK_USE_DATE_FMT_STRFTIME
  591. #include <sys/types.h>
  592. #if defined(DUK_F_BCC)
  593. /* no endian.h */
  594. #else
  595. #include <endian.h>
  596. #endif /* DUK_F_BCC */
  597. #include <limits.h>
  598. #include <sys/param.h>
  599. #include <sys/time.h>
  600. #include <time.h>
  601. #elif defined(__posix)
  602. /* POSIX */
  603. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  604. #define DUK_USE_DATE_TZO_GMTIME_R
  605. #define DUK_USE_DATE_PRS_STRPTIME
  606. #define DUK_USE_DATE_FMT_STRFTIME
  607. #include <sys/types.h>
  608. #include <endian.h>
  609. #include <limits.h>
  610. #include <sys/param.h>
  611. #include <sys/time.h>
  612. #include <time.h>
  613. #elif defined(DUK_F_CYGWIN)
  614. /* Cygwin -- don't use strptime() for now */
  615. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  616. #define DUK_USE_DATE_TZO_GMTIME_R
  617. #define DUK_USE_DATE_FMT_STRFTIME
  618. #include <sys/types.h>
  619. #include <endian.h>
  620. #include <limits.h>
  621. #include <sys/param.h>
  622. #include <sys/time.h>
  623. #include <time.h>
  624. #else
  625. /* Other UNIX, hopefully others */
  626. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  627. #define DUK_USE_DATE_TZO_GMTIME_R
  628. #define DUK_USE_DATE_PRS_STRPTIME
  629. #define DUK_USE_DATE_FMT_STRFTIME
  630. #include <sys/types.h>
  631. #if defined(DUK_F_BCC)
  632. /* no endian.h */
  633. #else
  634. #include <endian.h>
  635. #endif /* DUK_F_BCC */
  636. #include <limits.h>
  637. #include <sys/param.h>
  638. #include <sys/time.h>
  639. #include <time.h>
  640. #endif
  641. /* Shared includes */
  642. #include <stdio.h>
  643. #include <stdlib.h>
  644. #include <string.h>
  645. #include <stdarg.h> /* varargs */
  646. #include <setjmp.h>
  647. #include <stddef.h> /* e.g. ptrdiff_t */
  648. #if defined(DUK_F_NO_STDINT_H)
  649. /* stdint.h not available */
  650. #else
  651. /* Technically C99 (C++11) but found in many systems. Note the workaround
  652. * above for some C++ compilers (__STDC_LIMIT_MACROS etc).
  653. */
  654. #include <stdint.h>
  655. #endif
  656. #include <math.h>
  657. /*
  658. * Detection for specific libc variants (like uclibc) and other libc specific
  659. * features. Potentially depends on the #includes above.
  660. */
  661. #if defined(__UCLIBC__)
  662. #define DUK_F_UCLIBC
  663. #endif
  664. /*
  665. * Wrapper typedefs and constants for integer types, also sanity check types.
  666. *
  667. * C99 typedefs are quite good but not always available, and we want to avoid
  668. * forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
  669. * all C99 typedefs and Duktape code should only use these typedefs. Type
  670. * detection when C99 is not supported is best effort and may end up detecting
  671. * some types incorrectly.
  672. *
  673. * Pointer sizes are a portability problem: pointers to different types may
  674. * have a different size and function pointers are very difficult to manage
  675. * portably.
  676. *
  677. * http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
  678. *
  679. * Note: there's an interesting corner case when trying to define minimum
  680. * signed integer value constants which leads to the current workaround of
  681. * defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
  682. * for a longer discussion.
  683. *
  684. * Note: avoid typecasts and computations in macro integer constants as they
  685. * can then no longer be used in macro relational expressions (such as
  686. * #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
  687. * being able to compare DUK_SIZE_MAX against a limit.
  688. */
  689. /* XXX: add feature options to force basic types from outside? */
  690. #if !defined(INT_MAX)
  691. #error INT_MAX not defined
  692. #endif
  693. /* Check that architecture is two's complement, standard C allows e.g.
  694. * INT_MIN to be -2**31+1 (instead of -2**31).
  695. */
  696. #if defined(INT_MAX) && defined(INT_MIN)
  697. #if INT_MAX != -(INT_MIN + 1)
  698. #error platform does not seem complement of two
  699. #endif
  700. #else
  701. #error cannot check complement of two
  702. #endif
  703. /* Pointer size determination based on architecture.
  704. * XXX: unsure about BCC correctness.
  705. */
  706. #if defined(DUK_F_X86) || defined(DUK_F_X32) || \
  707. defined(DUK_F_BCC) || \
  708. (defined(__WORDSIZE) && (__WORDSIZE == 32))
  709. #define DUK_F_32BIT_PTRS
  710. #elif defined(DUK_F_X64) || \
  711. (defined(__WORDSIZE) && (__WORDSIZE == 64))
  712. #define DUK_F_64BIT_PTRS
  713. #else
  714. /* not sure, not needed with C99 anyway */
  715. #endif
  716. /* Intermediate define for 'have inttypes.h' */
  717. #undef DUK_F_HAVE_INTTYPES
  718. #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  719. !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
  720. /* vbcc + AmigaOS has C99 but no inttypes.h */
  721. #define DUK_F_HAVE_INTTYPES
  722. #elif defined(__cplusplus) && (__cplusplus >= 201103L)
  723. /* C++11 apparently ratified stdint.h */
  724. #define DUK_F_HAVE_INTTYPES
  725. #endif
  726. /* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
  727. * through automatic detection.
  728. */
  729. #if defined(DUK_F_HAVE_INTTYPES)
  730. /* C99 or compatible */
  731. #define DUK_F_HAVE_64BIT
  732. #include <inttypes.h>
  733. typedef uint8_t duk_uint8_t;
  734. typedef int8_t duk_int8_t;
  735. typedef uint16_t duk_uint16_t;
  736. typedef int16_t duk_int16_t;
  737. typedef uint32_t duk_uint32_t;
  738. typedef int32_t duk_int32_t;
  739. typedef uint64_t duk_uint64_t;
  740. typedef int64_t duk_int64_t;
  741. typedef uint_least8_t duk_uint_least8_t;
  742. typedef int_least8_t duk_int_least8_t;
  743. typedef uint_least16_t duk_uint_least16_t;
  744. typedef int_least16_t duk_int_least16_t;
  745. typedef uint_least32_t duk_uint_least32_t;
  746. typedef int_least32_t duk_int_least32_t;
  747. typedef uint_least64_t duk_uint_least64_t;
  748. typedef int_least64_t duk_int_least64_t;
  749. typedef uint_fast8_t duk_uint_fast8_t;
  750. typedef int_fast8_t duk_int_fast8_t;
  751. typedef uint_fast16_t duk_uint_fast16_t;
  752. typedef int_fast16_t duk_int_fast16_t;
  753. typedef uint_fast32_t duk_uint_fast32_t;
  754. typedef int_fast32_t duk_int_fast32_t;
  755. typedef uint_fast64_t duk_uint_fast64_t;
  756. typedef int_fast64_t duk_int_fast64_t;
  757. typedef uintptr_t duk_uintptr_t;
  758. typedef intptr_t duk_intptr_t;
  759. typedef uintmax_t duk_uintmax_t;
  760. typedef intmax_t duk_intmax_t;
  761. #define DUK_UINT8_MIN 0
  762. #define DUK_UINT8_MAX UINT8_MAX
  763. #define DUK_INT8_MIN INT8_MIN
  764. #define DUK_INT8_MAX INT8_MAX
  765. #define DUK_UINT_LEAST8_MIN 0
  766. #define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX
  767. #define DUK_INT_LEAST8_MIN INT_LEAST8_MIN
  768. #define DUK_INT_LEAST8_MAX INT_LEAST8_MAX
  769. #define DUK_UINT_FAST8_MIN 0
  770. #define DUK_UINT_FAST8_MAX UINT_FAST8_MAX
  771. #define DUK_INT_FAST8_MIN INT_FAST8_MIN
  772. #define DUK_INT_FAST8_MAX INT_FAST8_MAX
  773. #define DUK_UINT16_MIN 0
  774. #define DUK_UINT16_MAX UINT16_MAX
  775. #define DUK_INT16_MIN INT16_MIN
  776. #define DUK_INT16_MAX INT16_MAX
  777. #define DUK_UINT_LEAST16_MIN 0
  778. #define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX
  779. #define DUK_INT_LEAST16_MIN INT_LEAST16_MIN
  780. #define DUK_INT_LEAST16_MAX INT_LEAST16_MAX
  781. #define DUK_UINT_FAST16_MIN 0
  782. #define DUK_UINT_FAST16_MAX UINT_FAST16_MAX
  783. #define DUK_INT_FAST16_MIN INT_FAST16_MIN
  784. #define DUK_INT_FAST16_MAX INT_FAST16_MAX
  785. #define DUK_UINT32_MIN 0
  786. #define DUK_UINT32_MAX UINT32_MAX
  787. #define DUK_INT32_MIN INT32_MIN
  788. #define DUK_INT32_MAX INT32_MAX
  789. #define DUK_UINT_LEAST32_MIN 0
  790. #define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX
  791. #define DUK_INT_LEAST32_MIN INT_LEAST32_MIN
  792. #define DUK_INT_LEAST32_MAX INT_LEAST32_MAX
  793. #define DUK_UINT_FAST32_MIN 0
  794. #define DUK_UINT_FAST32_MAX UINT_FAST32_MAX
  795. #define DUK_INT_FAST32_MIN INT_FAST32_MIN
  796. #define DUK_INT_FAST32_MAX INT_FAST32_MAX
  797. #define DUK_UINT64_MIN 0
  798. #define DUK_UINT64_MAX UINT64_MAX
  799. #define DUK_INT64_MIN INT64_MIN
  800. #define DUK_INT64_MAX INT64_MAX
  801. #define DUK_UINT_LEAST64_MIN 0
  802. #define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX
  803. #define DUK_INT_LEAST64_MIN INT_LEAST64_MIN
  804. #define DUK_INT_LEAST64_MAX INT_LEAST64_MAX
  805. #define DUK_UINT_FAST64_MIN 0
  806. #define DUK_UINT_FAST64_MAX UINT_FAST64_MAX
  807. #define DUK_INT_FAST64_MIN INT_FAST64_MIN
  808. #define DUK_INT_FAST64_MAX INT_FAST64_MAX
  809. #define DUK_UINTPTR_MIN 0
  810. #define DUK_UINTPTR_MAX UINTPTR_MAX
  811. #define DUK_INTPTR_MIN INTPTR_MIN
  812. #define DUK_INTPTR_MAX INTPTR_MAX
  813. #define DUK_UINTMAX_MIN 0
  814. #define DUK_UINTMAX_MAX UINTMAX_MAX
  815. #define DUK_INTMAX_MIN INTMAX_MIN
  816. #define DUK_INTMAX_MAX INTMAX_MAX
  817. #define DUK_SIZE_MIN 0
  818. #define DUK_SIZE_MAX SIZE_MAX
  819. #else /* C99 types */
  820. /* When C99 types are not available, we use heuristic detection to get
  821. * the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
  822. * types are then assumed to be exactly the same for now: these could
  823. * be improved per platform but C99 types are very often now available.
  824. * 64-bit types are not available on all platforms; this is OK at least
  825. * on 32-bit platforms.
  826. *
  827. * This detection code is necessarily a bit hacky and can provide typedefs
  828. * and defines that won't work correctly on some exotic platform.
  829. */
  830. #if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
  831. (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
  832. typedef unsigned char duk_uint8_t;
  833. typedef signed char duk_int8_t;
  834. #else
  835. #error cannot detect 8-bit type
  836. #endif
  837. #if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
  838. typedef unsigned short duk_uint16_t;
  839. typedef signed short duk_int16_t;
  840. #elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
  841. /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
  842. typedef unsigned int duk_uint16_t;
  843. typedef signed int duk_int16_t;
  844. #else
  845. #error cannot detect 16-bit type
  846. #endif
  847. #if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
  848. typedef unsigned int duk_uint32_t;
  849. typedef signed int duk_int32_t;
  850. #elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
  851. /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
  852. typedef unsigned long duk_uint32_t;
  853. typedef signed long duk_int32_t;
  854. #else
  855. #error cannot detect 32-bit type
  856. #endif
  857. /* 64-bit type detection is a bit tricky.
  858. *
  859. * ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
  860. * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
  861. * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
  862. *
  863. * ULL / LL constants are rejected / warned about by some compilers, even if
  864. * the compiler has a 64-bit type and the compiler/system headers provide an
  865. * unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
  866. * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
  867. * bits but can't be sure it is exactly 64 bits. Self tests will catch such
  868. * cases.
  869. */
  870. #undef DUK_F_HAVE_64BIT
  871. #if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
  872. #if (ULONG_MAX > 4294967295UL)
  873. #define DUK_F_HAVE_64BIT
  874. typedef unsigned long duk_uint64_t;
  875. typedef signed long duk_int64_t;
  876. #endif
  877. #endif
  878. #if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
  879. #if (ULLONG_MAX > 4294967295UL)
  880. #define DUK_F_HAVE_64BIT
  881. typedef unsigned long long duk_uint64_t;
  882. typedef signed long long duk_int64_t;
  883. #endif
  884. #endif
  885. #if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
  886. #if (__ULONG_LONG_MAX__ > 4294967295UL)
  887. #define DUK_F_HAVE_64BIT
  888. typedef unsigned long long duk_uint64_t;
  889. typedef signed long long duk_int64_t;
  890. #endif
  891. #endif
  892. #if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
  893. #if (__LONG_LONG_MAX__ > 2147483647L)
  894. #define DUK_F_HAVE_64BIT
  895. typedef unsigned long long duk_uint64_t;
  896. typedef signed long long duk_int64_t;
  897. #endif
  898. #endif
  899. #if !defined(DUK_F_HAVE_64BIT) && \
  900. (defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
  901. /* Both MinGW and MSVC have a 64-bit type. */
  902. #define DUK_F_HAVE_64BIT
  903. typedef unsigned long duk_uint64_t;
  904. typedef signed long duk_int64_t;
  905. #endif
  906. #if !defined(DUK_F_HAVE_64BIT)
  907. /* cannot detect 64-bit type, not always needed so don't error */
  908. #endif
  909. typedef duk_uint8_t duk_uint_least8_t;
  910. typedef duk_int8_t duk_int_least8_t;
  911. typedef duk_uint16_t duk_uint_least16_t;
  912. typedef duk_int16_t duk_int_least16_t;
  913. typedef duk_uint32_t duk_uint_least32_t;
  914. typedef duk_int32_t duk_int_least32_t;
  915. typedef duk_uint8_t duk_uint_fast8_t;
  916. typedef duk_int8_t duk_int_fast8_t;
  917. typedef duk_uint16_t duk_uint_fast16_t;
  918. typedef duk_int16_t duk_int_fast16_t;
  919. typedef duk_uint32_t duk_uint_fast32_t;
  920. typedef duk_int32_t duk_int_fast32_t;
  921. #if defined(DUK_F_HAVE_64BIT)
  922. typedef duk_uint64_t duk_uint_least64_t;
  923. typedef duk_int64_t duk_int_least64_t;
  924. typedef duk_uint64_t duk_uint_fast64_t;
  925. typedef duk_int64_t duk_int_fast64_t;
  926. #endif
  927. #if defined(DUK_F_HAVE_64BIT)
  928. typedef duk_uint64_t duk_uintmax_t;
  929. typedef duk_int64_t duk_intmax_t;
  930. #else
  931. typedef duk_uint32_t duk_uintmax_t;
  932. typedef duk_int32_t duk_intmax_t;
  933. #endif
  934. /* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
  935. * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
  936. * -not- portable. See code-issues.txt for a detailed discussion.
  937. */
  938. #define DUK_UINT8_MIN 0UL
  939. #define DUK_UINT8_MAX 0xffUL
  940. #define DUK_INT8_MIN (-0x80L)
  941. #define DUK_INT8_MAX 0x7fL
  942. #define DUK_UINT_LEAST8_MIN 0UL
  943. #define DUK_UINT_LEAST8_MAX 0xffUL
  944. #define DUK_INT_LEAST8_MIN (-0x80L)
  945. #define DUK_INT_LEAST8_MAX 0x7fL
  946. #define DUK_UINT_FAST8_MIN 0UL
  947. #define DUK_UINT_FAST8_MAX 0xffUL
  948. #define DUK_INT_FAST8_MIN (-0x80L)
  949. #define DUK_INT_FAST8_MAX 0x7fL
  950. #define DUK_UINT16_MIN 0UL
  951. #define DUK_UINT16_MAX 0xffffUL
  952. #define DUK_INT16_MIN (-0x7fffL - 1L)
  953. #define DUK_INT16_MAX 0x7fffL
  954. #define DUK_UINT_LEAST16_MIN 0UL
  955. #define DUK_UINT_LEAST16_MAX 0xffffUL
  956. #define DUK_INT_LEAST16_MIN (-0x7fffL - 1L)
  957. #define DUK_INT_LEAST16_MAX 0x7fffL
  958. #define DUK_UINT_FAST16_MIN 0UL
  959. #define DUK_UINT_FAST16_MAX 0xffffUL
  960. #define DUK_INT_FAST16_MIN (-0x7fffL - 1L)
  961. #define DUK_INT_FAST16_MAX 0x7fffL
  962. #define DUK_UINT32_MIN 0UL
  963. #define DUK_UINT32_MAX 0xffffffffUL
  964. #define DUK_INT32_MIN (-0x7fffffffL - 1L)
  965. #define DUK_INT32_MAX 0x7fffffffL
  966. #define DUK_UINT_LEAST32_MIN 0UL
  967. #define DUK_UINT_LEAST32_MAX 0xffffffffUL
  968. #define DUK_INT_LEAST32_MIN (-0x7fffffffL - 1L)
  969. #define DUK_INT_LEAST32_MAX 0x7fffffffL
  970. #define DUK_UINT_FAST32_MIN 0UL
  971. #define DUK_UINT_FAST32_MAX 0xffffffffUL
  972. #define DUK_INT_FAST32_MIN (-0x7fffffffL - 1L)
  973. #define DUK_INT_FAST32_MAX 0x7fffffffL
  974. /* 64-bit constants. Since LL / ULL constants are not always available,
  975. * use computed values. These values can't be used in preprocessor
  976. * comparisons; flag them as such.
  977. */
  978. #if defined(DUK_F_HAVE_64BIT)
  979. #define DUK_UINT64_MIN ((duk_uint64_t) 0)
  980. #define DUK_UINT64_MAX ((duk_uint64_t) -1)
  981. #define DUK_INT64_MIN ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
  982. #define DUK_INT64_MAX ((duk_int64_t) (DUK_UINT64_MAX >> 1))
  983. #define DUK_UINT_LEAST64_MIN DUK_UINT64_MIN
  984. #define DUK_UINT_LEAST64_MAX DUK_UINT64_MAX
  985. #define DUK_INT_LEAST64_MIN DUK_INT64_MIN
  986. #define DUK_INT_LEAST64_MAX DUK_INT64_MAX
  987. #define DUK_UINT_FAST64_MIN DUK_UINT64_MIN
  988. #define DUK_UINT_FAST64_MAX DUK_UINT64_MAX
  989. #define DUK_INT_FAST64_MIN DUK_INT64_MIN
  990. #define DUK_INT_FAST64_MAX DUK_INT64_MAX
  991. #define DUK_UINT64_MIN_COMPUTED
  992. #define DUK_UINT64_MAX_COMPUTED
  993. #define DUK_INT64_MIN_COMPUTED
  994. #define DUK_INT64_MAX_COMPUTED
  995. #define DUK_UINT_LEAST64_MIN_COMPUTED
  996. #define DUK_UINT_LEAST64_MAX_COMPUTED
  997. #define DUK_INT_LEAST64_MIN_COMPUTED
  998. #define DUK_INT_LEAST64_MAX_COMPUTED
  999. #define DUK_UINT_FAST64_MIN_COMPUTED
  1000. #define DUK_UINT_FAST64_MAX_COMPUTED
  1001. #define DUK_INT_FAST64_MIN_COMPUTED
  1002. #define DUK_INT_FAST64_MAX_COMPUTED
  1003. #endif
  1004. #if defined(DUK_F_HAVE_64BIT)
  1005. #define DUK_UINTMAX_MIN DUK_UINT64_MIN
  1006. #define DUK_UINTMAX_MAX DUK_UINT64_MAX
  1007. #define DUK_INTMAX_MIN DUK_INT64_MIN
  1008. #define DUK_INTMAX_MAX DUK_INT64_MAX
  1009. #define DUK_UINTMAX_MIN_COMPUTED
  1010. #define DUK_UINTMAX_MAX_COMPUTED
  1011. #define DUK_INTMAX_MIN_COMPUTED
  1012. #define DUK_INTMAX_MAX_COMPUTED
  1013. #else
  1014. #define DUK_UINTMAX_MIN 0UL
  1015. #define DUK_UINTMAX_MAX 0xffffffffUL
  1016. #define DUK_INTMAX_MIN (-0x7fffffffL - 1L)
  1017. #define DUK_INTMAX_MAX 0x7fffffffL
  1018. #endif
  1019. /* This detection is not very reliable. */
  1020. #if defined(DUK_F_32BIT_PTRS)
  1021. typedef duk_int32_t duk_intptr_t;
  1022. typedef duk_uint32_t duk_uintptr_t;
  1023. #define DUK_UINTPTR_MIN DUK_UINT32_MIN
  1024. #define DUK_UINTPTR_MAX DUK_UINT32_MAX
  1025. #define DUK_INTPTR_MIN DUK_INT32_MIN
  1026. #define DUK_INTPTR_MAX DUK_INT32_MAX
  1027. #elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
  1028. typedef duk_int64_t duk_intptr_t;
  1029. typedef duk_uint64_t duk_uintptr_t;
  1030. #define DUK_UINTPTR_MIN DUK_UINT64_MIN
  1031. #define DUK_UINTPTR_MAX DUK_UINT64_MAX
  1032. #define DUK_INTPTR_MIN DUK_INT64_MIN
  1033. #define DUK_INTPTR_MAX DUK_INT64_MAX
  1034. #define DUK_UINTPTR_MIN_COMPUTED
  1035. #define DUK_UINTPTR_MAX_COMPUTED
  1036. #define DUK_INTPTR_MIN_COMPUTED
  1037. #define DUK_INTPTR_MAX_COMPUTED
  1038. #else
  1039. #error cannot determine intptr type
  1040. #endif
  1041. /* SIZE_MAX may be missing so use an approximate value for it. */
  1042. #undef DUK_SIZE_MAX_COMPUTED
  1043. #if !defined(SIZE_MAX)
  1044. #define DUK_SIZE_MAX_COMPUTED
  1045. #define SIZE_MAX ((size_t) (-1))
  1046. #endif
  1047. #define DUK_SIZE_MIN 0
  1048. #define DUK_SIZE_MAX SIZE_MAX
  1049. #endif /* C99 types */
  1050. /* A few types are assumed to always exist. */
  1051. typedef size_t duk_size_t;
  1052. typedef ptrdiff_t duk_ptrdiff_t;
  1053. /* The best type for an "all around int" in Duktape internals is "at least
  1054. * 32 bit signed integer" which is most convenient. Same for unsigned type.
  1055. * Prefer 'int' when large enough, as it is almost always a convenient type.
  1056. */
  1057. #if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
  1058. typedef int duk_int_t;
  1059. typedef unsigned int duk_uint_t;
  1060. #define DUK_INT_MIN INT_MIN
  1061. #define DUK_INT_MAX INT_MAX
  1062. #define DUK_UINT_MIN 0
  1063. #define DUK_UINT_MAX UINT_MAX
  1064. #else
  1065. typedef duk_int_fast32_t duk_int_t;
  1066. typedef duk_uint_fast32_t duk_uint_t;
  1067. #define DUK_INT_MIN DUK_INT_FAST32_MIN
  1068. #define DUK_INT_MAX DUK_INT_FAST32_MAX
  1069. #define DUK_UINT_MIN DUK_UINT_FAST32_MIN
  1070. #define DUK_UINT_MAX DUK_UINT_FAST32_MAX
  1071. #endif
  1072. /* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
  1073. * distinction matters for the CPU. These types are used mainly in the
  1074. * executor where it might really matter.
  1075. */
  1076. typedef duk_int_fast32_t duk_int_fast_t;
  1077. typedef duk_uint_fast32_t duk_uint_fast_t;
  1078. #define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN
  1079. #define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX
  1080. #define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN
  1081. #define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX
  1082. /* Small integers (16 bits or more) can fall back to the 'int' type, but
  1083. * have a typedef so they are marked "small" explicitly.
  1084. */
  1085. typedef int duk_small_int_t;
  1086. typedef unsigned int duk_small_uint_t;
  1087. #define DUK_SMALL_INT_MIN INT_MIN
  1088. #define DUK_SMALL_INT_MAX INT_MAX
  1089. #define DUK_SMALL_UINT_MIN 0
  1090. #define DUK_SMALL_UINT_MAX UINT_MAX
  1091. /* Fast variants of small integers, again for really fast paths like the
  1092. * executor.
  1093. */
  1094. typedef duk_int_fast16_t duk_small_int_fast_t;
  1095. typedef duk_uint_fast16_t duk_small_uint_fast_t;
  1096. #define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN
  1097. #define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX
  1098. #define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN
  1099. #define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX
  1100. /* Boolean values are represented with the platform 'int'. */
  1101. typedef duk_small_int_t duk_bool_t;
  1102. #define DUK_BOOL_MIN DUK_SMALL_INT_MIN
  1103. #define DUK_BOOL_MAX DUK_SMALL_INT_MAX
  1104. /* Index values must have at least 32-bit signed range. */
  1105. typedef duk_int_t duk_idx_t;
  1106. #define DUK_IDX_MIN DUK_INT_MIN
  1107. #define DUK_IDX_MAX DUK_INT_MAX
  1108. /* Array index values, could be exact 32 bits.
  1109. * Currently no need for signed duk_arridx_t.
  1110. */
  1111. typedef duk_uint_t duk_uarridx_t;
  1112. #define DUK_UARRIDX_MIN DUK_UINT_MIN
  1113. #define DUK_UARRIDX_MAX DUK_UINT_MAX
  1114. /* Duktape/C function return value, platform int is enough for now to
  1115. * represent 0, 1, or negative error code. Must be compatible with
  1116. * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
  1117. */
  1118. typedef duk_small_int_t duk_ret_t;
  1119. #define DUK_RET_MIN DUK_SMALL_INT_MIN
  1120. #define DUK_RET_MAX DUK_SMALL_INT_MAX
  1121. /* Error codes are represented with platform int. High bits are used
  1122. * for flags and such, so 32 bits are needed.
  1123. */
  1124. typedef duk_int_t duk_errcode_t;
  1125. #define DUK_ERRCODE_MIN DUK_INT_MIN
  1126. #define DUK_ERRCODE_MAX DUK_INT_MAX
  1127. /* Codepoint type. Must be 32 bits or more because it is used also for
  1128. * internal codepoints. The type is signed because negative codepoints
  1129. * are used as internal markers (e.g. to mark EOF or missing argument).
  1130. * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
  1131. * ensure duk_uint32_t casts back and forth nicely. Almost everything
  1132. * else uses the signed one.
  1133. */
  1134. typedef duk_int_t duk_codepoint_t;
  1135. typedef duk_uint_t duk_ucodepoint_t;
  1136. #define DUK_CODEPOINT_MIN DUK_INT_MIN
  1137. #define DUK_CODEPOINT_MAX DUK_INT_MAX
  1138. #define DUK_UCODEPOINT_MIN DUK_UINT_MIN
  1139. #define DUK_UCODEPOINT_MAX DUK_UINT_MAX
  1140. /* IEEE double typedef. */
  1141. typedef double duk_double_t;
  1142. /* We're generally assuming that we're working on a platform with a 32-bit
  1143. * address space. If DUK_SIZE_MAX is a typecast value (which is necessary
  1144. * if SIZE_MAX is missing), the check must be avoided because the
  1145. * preprocessor can't do a comparison.
  1146. */
  1147. #if !defined(DUK_SIZE_MAX)
  1148. #error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
  1149. #elif !defined(DUK_SIZE_MAX_COMPUTED)
  1150. #if DUK_SIZE_MAX < 0xffffffffUL
  1151. /* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
  1152. * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
  1153. * However, it doesn't seem useful to error out compilation if this is the
  1154. * case.
  1155. */
  1156. #endif
  1157. #endif
  1158. /* Convenience define: 32-bit pointers. 32-bit platforms are an important
  1159. * footprint optimization target, and this define allows e.g. struct sizes
  1160. * to be organized for compactness.
  1161. */
  1162. #undef DUK_USE_32BIT_PTRS
  1163. #if defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
  1164. #if DUK_UINTPTR_MAX <= 0xffffffffUL
  1165. #define DUK_USE_32BIT_PTRS
  1166. #endif
  1167. #endif
  1168. /*
  1169. * Check whether we should use 64-bit integers
  1170. */
  1171. /* Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
  1172. * unless they are known to be unreliable. For instance, 64-bit types are
  1173. * available on VBCC but seem to misbehave.
  1174. */
  1175. #if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
  1176. #define DUK_USE_64BIT_OPS
  1177. #else
  1178. #undef DUK_USE_64BIT_OPS
  1179. #endif
  1180. /*
  1181. * Alignment requirement and support for unaligned accesses
  1182. *
  1183. * Assume unaligned accesses are not supported unless specifically allowed
  1184. * in the target platform. Some platforms may support unaligned accesses
  1185. * but alignment to 4 or 8 may still be desirable.
  1186. */
  1187. #undef DUK_USE_UNALIGNED_ACCESSES_POSSIBLE
  1188. #undef DUK_USE_ALIGN_4
  1189. #undef DUK_USE_ALIGN_8
  1190. #if defined(DUK_F_EMSCRIPTEN)
  1191. /* Required on at least some targets, so use whenever Emscripten used,
  1192. * regardless of compilation target.
  1193. */
  1194. #define DUK_USE_ALIGN_8
  1195. #elif defined(DUK_F_ARM)
  1196. #define DUK_USE_ALIGN_4
  1197. #elif defined(DUK_F_MIPS32)
  1198. /* Based on 'make checkalign' there are no alignment requirements on
  1199. * Linux MIPS except for doubles, which need align by 4. Alignment
  1200. * requirements vary based on target though.
  1201. */
  1202. #define DUK_USE_ALIGN_4
  1203. #elif defined(DUK_F_MIPS64)
  1204. /* Good default is a bit arbitrary because alignment requirements
  1205. * depend on target. See https://github.com/svaarala/duktape/issues/102.
  1206. */
  1207. #define DUK_USE_ALIGN_8
  1208. #elif defined(DUK_F_SUPERH)
  1209. /* Based on 'make checkalign' there are no alignment requirements on
  1210. * Linux SH4, but align by 4 is probably a good basic default.
  1211. */
  1212. #define DUK_USE_ALIGN_4
  1213. #elif defined(DUK_F_X86) || defined(DUK_F_X32) || defined(DUK_F_X64) || \
  1214. defined(DUK_F_BCC)
  1215. /* XXX: This is technically not guaranteed because it's possible to configure
  1216. * an x86 to require aligned accesses with Alignment Check (AC) flag.
  1217. */
  1218. #define DUK_USE_UNALIGNED_ACCESSES_POSSIBLE
  1219. #else
  1220. /* Unknown, use safe default */
  1221. #define DUK_USE_ALIGN_8
  1222. #endif
  1223. /* User forced alignment to 4 or 8. */
  1224. #if defined(DUK_OPT_FORCE_ALIGN)
  1225. #undef DUK_USE_UNALIGNED_ACCESSES_POSSIBLE
  1226. #undef DUK_USE_ALIGN_4
  1227. #undef DUK_USE_ALIGN_8
  1228. #if (DUK_OPT_FORCE_ALIGN == 4)
  1229. #define DUK_USE_ALIGN_4
  1230. #elif (DUK_OPT_FORCE_ALIGN == 8)
  1231. #define DUK_USE_ALIGN_8
  1232. #else
  1233. #error invalid DUK_OPT_FORCE_ALIGN value
  1234. #endif
  1235. #endif
  1236. /* Compiler specific hackery needed to force struct size to match aligment,
  1237. * see e.g. duk_hbuffer.h.
  1238. *
  1239. * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
  1240. * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
  1241. */
  1242. #if defined(DUK_F_MSVC)
  1243. #define DUK_USE_PACK_MSVC_PRAGMA
  1244. #elif defined(DUK_F_GCC)
  1245. #define DUK_USE_PACK_GCC_ATTR
  1246. #elif defined(DUK_F_CLANG)
  1247. #define DUK_USE_PACK_CLANG_ATTR
  1248. #else
  1249. #define DUK_USE_PACK_DUMMY_MEMBER
  1250. #endif
  1251. #ifdef DUK_USE_UNALIGNED_ACCESSES_POSSIBLE
  1252. #define DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS
  1253. #else
  1254. #undef DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS
  1255. #endif
  1256. /* Object property allocation layout has implications for memory and code
  1257. * footprint and generated code size/speed. The best layout also depends
  1258. * on whether the platform has alignment requirements or benefits from
  1259. * having mostly aligned accesses.
  1260. */
  1261. #undef DUK_USE_HOBJECT_LAYOUT_1
  1262. #undef DUK_USE_HOBJECT_LAYOUT_2
  1263. #undef DUK_USE_HOBJECT_LAYOUT_3
  1264. #if defined(DUK_USE_UNALIGNED_ACCESSES_POSSIBLE) && \
  1265. !defined(DUK_USE_ALIGN_4) && !defined(DUK_USE_ALIGN_8)
  1266. /* On platforms without any alignment issues, layout 1 is preferable
  1267. * because it compiles to slightly less code and provides direct access
  1268. * to property keys.
  1269. */
  1270. #define DUK_USE_HOBJECT_LAYOUT_1
  1271. #else
  1272. /* On other platforms use layout 2, which requires some padding but
  1273. * is a bit more natural than layout 3 in ordering the entries. Layout
  1274. * 3 is currently not used.
  1275. */
  1276. #define DUK_USE_HOBJECT_LAYOUT_2
  1277. #endif
  1278. /*
  1279. * Byte order and double memory layout detection
  1280. *
  1281. * Endianness detection is a major portability hassle because the macros
  1282. * and headers are not standardized. There's even variance across UNIX
  1283. * platforms. Even with "standard" headers, details like underscore count
  1284. * varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
  1285. * (Crossbridge has a single underscore, for instance).
  1286. *
  1287. * The checks below are structured with this in mind: several approaches are
  1288. * used, and at the end we check if any of them worked. This allows generic
  1289. * approaches to be tried first, and platform/compiler specific hacks tried
  1290. * last. As a last resort, the user can force a specific endianness, as it's
  1291. * not likely that automatic detection will work on the most exotic platforms.
  1292. *
  1293. * Duktape supports little and big endian machines. There's also support
  1294. * for a hybrid used by some ARM machines where integers are little endian
  1295. * but IEEE double values use a mixed order (12345678 -> 43218765). This
  1296. * byte order for doubles is referred to as "mixed endian".
  1297. */
  1298. #undef DUK_F_BYTEORDER
  1299. #undef DUK_USE_BYTEORDER_FORCED
  1300. /* DUK_F_BYTEORDER is set as an intermediate value when detection
  1301. * succeeds, to one of:
  1302. * 1 = little endian
  1303. * 2 = mixed (arm hybrid) endian
  1304. * 3 = big endian
  1305. */
  1306. /* For custom platforms allow user to define byteorder explicitly.
  1307. * Since endianness headers are not standardized, this is a useful
  1308. * workaround for custom platforms for which endianness detection
  1309. * is not directly supported. Perhaps custom hardware is used and
  1310. * user cannot submit upstream patches.
  1311. */
  1312. #if defined(DUK_OPT_FORCE_BYTEORDER)
  1313. #if (DUK_OPT_FORCE_BYTEORDER == 1)
  1314. #define DUK_F_BYTEORDER 1
  1315. #elif (DUK_OPT_FORCE_BYTEORDER == 2)
  1316. #define DUK_F_BYTEORDER 2
  1317. #elif (DUK_OPT_FORCE_BYTEORDER == 3)
  1318. #define DUK_F_BYTEORDER 3
  1319. #else
  1320. #error invalid DUK_OPT_FORCE_BYTEORDER value
  1321. #endif
  1322. #define DUK_USE_BYTEORDER_FORCED
  1323. #endif /* DUK_OPT_FORCE_BYTEORDER */
  1324. /* More or less standard endianness predefines provided by header files.
  1325. * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
  1326. * will be big endian, see: http://lists.mysql.com/internals/443.
  1327. */
  1328. #if !defined(DUK_F_BYTEORDER)
  1329. #if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
  1330. defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
  1331. defined(__LITTLE_ENDIAN__)
  1332. /* Integer little endian */
  1333. #if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
  1334. defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
  1335. #define DUK_F_BYTEORDER 1
  1336. #elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
  1337. defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
  1338. #define DUK_F_BYTEORDER 2
  1339. #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
  1340. /* Float word order not known, assume not a hybrid. */
  1341. #define DUK_F_BYTEORDER 1
  1342. #else
  1343. /* byte order is little endian but cannot determine IEEE double word order */
  1344. #endif /* float word order */
  1345. #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
  1346. defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
  1347. defined(__BIG_ENDIAN__)
  1348. /* Integer big endian */
  1349. #if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
  1350. defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
  1351. #define DUK_F_BYTEORDER 3
  1352. #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
  1353. /* Float word order not known, assume not a hybrid. */
  1354. #define DUK_F_BYTEORDER 3
  1355. #else
  1356. /* byte order is big endian but cannot determine IEEE double word order */
  1357. #endif /* float word order */
  1358. #else
  1359. /* cannot determine byte order */
  1360. #endif /* integer byte order */
  1361. #endif /* !defined(DUK_F_BYTEORDER) */
  1362. /* GCC and Clang provide endianness defines as built-in predefines, with
  1363. * leading and trailing double underscores (e.g. __BYTE_ORDER__). See
  1364. * output of "make gccpredefs" and "make clangpredefs". Clang doesn't
  1365. * seem to provide __FLOAT_WORD_ORDER__.
  1366. * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
  1367. */
  1368. #if !defined(DUK_F_BYTEORDER) && defined(__BYTE_ORDER__)
  1369. #if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
  1370. /* Integer little endian */
  1371. #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  1372. (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
  1373. #define DUK_F_BYTEORDER 1
  1374. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
  1375. (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
  1376. #define DUK_F_BYTEORDER 2
  1377. #elif !defined(__FLOAT_WORD_ORDER__)
  1378. /* Float word order not known, assume not a hybrid. */
  1379. #define DUK_F_BYTEORDER 1
  1380. #else
  1381. /* byte order is little endian but cannot determine IEEE double word order */
  1382. #endif /* float word order */
  1383. #elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  1384. /* Integer big endian */
  1385. #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
  1386. (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
  1387. #define DUK_F_BYTEORDER 3
  1388. #elif !defined(__FLOAT_WORD_ORDER__)
  1389. /* Float word order not known, assume not a hybrid. */
  1390. #define DUK_F_BYTEORDER 3
  1391. #else
  1392. /* byte order is big endian but cannot determine IEEE double word order */
  1393. #endif /* float word order */
  1394. #else
  1395. /* cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
  1396. * integer ordering and is not relevant
  1397. */
  1398. #endif /* integer byte order */
  1399. #endif /* !defined(DUK_F_BYTEORDER) && defined(__BYTE_ORDER__) */
  1400. /* Atari ST TOS */
  1401. #if !defined(DUK_F_BYTEORDER) && defined(DUK_F_TOS)
  1402. #define DUK_F_BYTEORDER 3
  1403. #endif
  1404. /* AmigaOS on M68k */
  1405. #if !defined(DUK_F_BYTEORDER) && defined(DUK_F_AMIGAOS)
  1406. #if defined(DUK_F_M68K)
  1407. #define DUK_F_BYTEORDER 3
  1408. #endif
  1409. #endif
  1410. /* On Windows, assume we're little endian. Even Itanium which has a
  1411. * configurable endianness runs little endian in Windows.
  1412. */
  1413. #if !defined(DUK_F_BYTEORDER) && defined(DUK_F_WINDOWS)
  1414. /* XXX: verify that Windows on ARM is little endian for floating point
  1415. * values too.
  1416. */
  1417. #define DUK_F_BYTEORDER 1
  1418. #endif /* Windows */
  1419. /* Crossbridge should work with the standard byteorder #ifdefs. It doesn't
  1420. * provide _FLOAT_WORD_ORDER but the standard approach now covers that case
  1421. * too. This has been left here just in case.
  1422. */
  1423. #if !defined(DUK_F_BYTEORDER) && defined(DUK_F_FLASHPLAYER)
  1424. #define DUK_F_BYTEORDER 1
  1425. #endif
  1426. /* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
  1427. * $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
  1428. * 67:#define __LITTLEENDIAN__ 1
  1429. * $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
  1430. * 81:#define __BIGENDIAN__ 1
  1431. * $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
  1432. * 70:#define __LITTLEENDIAN__ 1
  1433. */
  1434. #if !defined(DUK_F_BYTEORDER) && defined(DUK_F_QNX)
  1435. /* XXX: ARM hybrid? */
  1436. #if defined(__LITTLEENDIAN__)
  1437. #define DUK_F_BYTEORDER 1
  1438. #elif defined(__BIGENDIAN__)
  1439. #define DUK_F_BYTEORDER 3
  1440. #endif
  1441. #endif
  1442. /* Bruce's C Compiler (BCC), assume we're on x86. */
  1443. #if !defined(DUK_F_BYTEORDER) && defined(DUK_F_BCC)
  1444. #define DUK_F_BYTEORDER 1
  1445. #endif
  1446. /* Check whether or not byte order detection worked based on the intermediate
  1447. * define, and define final values. If detection failed, #error out.
  1448. */
  1449. #if defined(DUK_F_BYTEORDER)
  1450. #if (DUK_F_BYTEORDER == 1)
  1451. #define DUK_USE_INTEGER_LE
  1452. #define DUK_USE_DOUBLE_LE
  1453. #elif (DUK_F_BYTEORDER == 2)
  1454. #define DUK_USE_INTEGER_LE /* integer endianness is little on purpose */
  1455. #define DUK_USE_DOUBLE_ME
  1456. #elif (DUK_F_BYTEORDER == 3)
  1457. #define DUK_USE_INTEGER_BE
  1458. #define DUK_USE_DOUBLE_BE
  1459. #else
  1460. #error unsupported: byte order detection failed (internal error, should not happen)
  1461. #endif /* byte order */
  1462. #else
  1463. #error unsupported: byte order detection failed
  1464. #endif /* defined(DUK_F_BYTEORDER) */
  1465. /*
  1466. * Check whether or not a packed duk_tval representation is possible.
  1467. * What's basically required is that pointers are 32-bit values
  1468. * (sizeof(void *) == 4). Best effort check, not always accurate.
  1469. * If guess goes wrong, crashes may result; self tests also verify
  1470. * the guess.
  1471. */
  1472. #undef DUK_USE_PACKED_TVAL_POSSIBLE
  1473. /* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
  1474. #if !defined(DUK_USE_PACKED_TVAL_POSSIBLE) && defined(DUK_F_HAVE_INTTYPES) && defined(DUK_UINTPTR_MAX)
  1475. #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
  1476. #define DUK_USE_PACKED_TVAL_POSSIBLE
  1477. #endif
  1478. #endif
  1479. /* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
  1480. #if !defined(DUK_USE_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
  1481. #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
  1482. #define DUK_USE_PACKED_TVAL_POSSIBLE
  1483. #endif
  1484. #endif
  1485. /* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
  1486. #if !defined(DUK_USE_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
  1487. #if DUK_SIZE_MAX <= 0xffffffffUL
  1488. #define DUK_USE_PACKED_TVAL_POSSIBLE
  1489. #endif
  1490. #endif
  1491. /* M68K: packed always possible */
  1492. #if !defined(DUK_USE_PACKED_TVAL_POSSIBLE) && defined(DUK_F_M68K)
  1493. #define DUK_USE_PACKED_TVAL_POSSIBLE
  1494. #endif
  1495. /* With Emscripten, force unpacked duk_tval just to be safe, as it seems to
  1496. * break at least on Firefox (probably IEEE double arithmetic is not 100%
  1497. * supported, especially for NaNs).
  1498. */
  1499. #if defined(DUK_USE_PACKED_TVAL_POSSIBLE) && defined(DUK_F_EMSCRIPTEN)
  1500. #undef DUK_USE_PACKED_TVAL_POSSIBLE
  1501. #endif
  1502. /* Microsoft Visual Studio 2010 on x64 fails the above rules and tries to
  1503. * use a packed type. Force unpacked on x64 in general.
  1504. */
  1505. #if defined(DUK_USE_PACKED_TVAL_POSSIBLE) && defined(DUK_F_X64)
  1506. #undef DUK_USE_PACKED_TVAL_POSSIBLE
  1507. #endif
  1508. /* GCC/clang inaccurate math would break compliance and probably duk_tval,
  1509. * so refuse to compile. Relax this if -ffast-math is tested to work.
  1510. */
  1511. #if defined(__FAST_MATH__)
  1512. #error __FAST_MATH__ defined, refusing to compile
  1513. #endif
  1514. /*
  1515. * Detection of double constants and math related functions. Availability
  1516. * of constants and math functions is a significant porting concern.
  1517. *
  1518. * INFINITY/HUGE_VAL is problematic on GCC-3.3: it causes an overflow warning
  1519. * and there is no pragma in GCC-3.3 to disable it. Using __builtin_inf()
  1520. * avoids this problem for some reason.
  1521. */
  1522. #define DUK_DOUBLE_2TO32 4294967296.0
  1523. #define DUK_DOUBLE_2TO31 2147483648.0
  1524. #undef DUK_USE_COMPUTED_INFINITY
  1525. #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
  1526. /* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
  1527. #define DUK_DOUBLE_INFINITY (__builtin_inf())
  1528. #elif defined(INFINITY)
  1529. #define DUK_DOUBLE_INFINITY ((double) INFINITY)
  1530. #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
  1531. #define DUK_DOUBLE_INFINITY (1.0 / 0.0)
  1532. #else
  1533. /* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
  1534. * Use a computed infinity (initialized when a heap is created at the
  1535. * latest).
  1536. */
  1537. extern double duk_computed_infinity;
  1538. #define DUK_USE_COMPUTED_INFINITY
  1539. #define DUK_DOUBLE_INFINITY duk_computed_infinity
  1540. #endif
  1541. #undef DUK_USE_COMPUTED_NAN
  1542. #if defined(NAN)
  1543. #define DUK_DOUBLE_NAN NAN
  1544. #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
  1545. #define DUK_DOUBLE_NAN (0.0 / 0.0)
  1546. #else
  1547. /* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
  1548. * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
  1549. * Use a computed NaN (initialized when a heap is created at the
  1550. * latest).
  1551. */
  1552. extern double duk_computed_nan;
  1553. #define DUK_USE_COMPUTED_NAN
  1554. #define DUK_DOUBLE_NAN duk_computed_nan
  1555. #endif
  1556. /* Many platforms are missing fpclassify() and friends, so use replacements
  1557. * if necessary. The replacement constants (FP_NAN etc) can be anything but
  1558. * match Linux constants now.
  1559. */
  1560. #undef DUK_USE_REPL_FPCLASSIFY
  1561. #undef DUK_USE_REPL_SIGNBIT
  1562. #undef DUK_USE_REPL_ISFINITE
  1563. #undef DUK_USE_REPL_ISNAN
  1564. #undef DUK_USE_REPL_ISINF
  1565. /* Complex condition broken into separate parts. */
  1566. #undef DUK_F_USE_REPL_ALL
  1567. #if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
  1568. defined(FP_SUBNORMAL) && defined(FP_NORMAL))
  1569. /* Missing some obvious constants. */
  1570. #define DUK_F_USE_REPL_ALL
  1571. #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
  1572. /* VBCC is missing the built-ins even in C99 mode (perhaps a header issue) */
  1573. #define DUK_F_USE_REPL_ALL
  1574. #elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
  1575. /* Placeholder fix for (detection is wider than necessary):
  1576. * http://llvm.org/bugs/show_bug.cgi?id=17788
  1577. */
  1578. #define DUK_F_USE_REPL_ALL
  1579. #elif defined(DUK_F_UCLIBC)
  1580. /* At least some uclibc versions have broken floating point math. For
  1581. * example, fpclassify() can incorrectly classify certain NaN formats.
  1582. * To be safe, use replacements.
  1583. */
  1584. #define DUK_F_USE_REPL_ALL
  1585. #endif
  1586. #if defined(DUK_F_USE_REPL_ALL)
  1587. #define DUK_USE_REPL_FPCLASSIFY
  1588. #define DUK_USE_REPL_SIGNBIT
  1589. #define DUK_USE_REPL_ISFINITE
  1590. #define DUK_USE_REPL_ISNAN
  1591. #define DUK_USE_REPL_ISINF
  1592. #define DUK_FPCLASSIFY duk_repl_fpclassify
  1593. #define DUK_SIGNBIT duk_repl_signbit
  1594. #define DUK_ISFINITE duk_repl_isfinite
  1595. #define DUK_ISNAN duk_repl_isnan
  1596. #define DUK_ISINF duk_repl_isinf
  1597. #define DUK_FP_NAN 0
  1598. #define DUK_FP_INFINITE 1
  1599. #define DUK_FP_ZERO 2
  1600. #define DUK_FP_SUBNORMAL 3
  1601. #define DUK_FP_NORMAL 4
  1602. #else
  1603. #define DUK_FPCLASSIFY fpclassify
  1604. #define DUK_SIGNBIT signbit
  1605. #define DUK_ISFINITE isfinite
  1606. #define DUK_ISNAN isnan
  1607. #define DUK_ISINF isinf
  1608. #define DUK_FP_NAN FP_NAN
  1609. #define DUK_FP_INFINITE FP_INFINITE
  1610. #define DUK_FP_ZERO FP_ZERO
  1611. #define DUK_FP_SUBNORMAL FP_SUBNORMAL
  1612. #define DUK_FP_NORMAL FP_NORMAL
  1613. #endif
  1614. #if defined(DUK_F_USE_REPL_ALL)
  1615. #undef DUK_F_USE_REPL_ALL
  1616. #endif
  1617. /* Some math functions are C99 only. This is also an issue with some
  1618. * embedded environments using uclibc where uclibc has been configured
  1619. * not to provide some functions. For now, use replacements whenever
  1620. * using uclibc.
  1621. */
  1622. #undef DUK_USE_MATH_FMIN
  1623. #undef DUK_USE_MATH_FMAX
  1624. #undef DUK_USE_MATH_ROUND
  1625. #if defined(DUK_F_UCLIBC)
  1626. /* uclibc may be missing these */
  1627. #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
  1628. /* vbcc + AmigaOS may be missing these */
  1629. #elif !defined(DUK_F_C99) && !defined(DUK_F_CPP11)
  1630. /* build is not C99 or C++11, play it safe */
  1631. #else
  1632. /* C99 or C++11, no known issues */
  1633. #define DUK_USE_MATH_FMIN
  1634. #define DUK_USE_MATH_FMAX
  1635. #define DUK_USE_MATH_ROUND
  1636. #endif
  1637. /* These functions don't currently need replacement but are wrapped for
  1638. * completeness. Because these are used as function pointers, they need
  1639. * to be defined as concrete C functions (not macros).
  1640. */
  1641. #define DUK_FABS fabs
  1642. #define DUK_FMIN fmin
  1643. #define DUK_FMAX fmax
  1644. #define DUK_FLOOR floor
  1645. #define DUK_CEIL ceil
  1646. #define DUK_FMOD fmod
  1647. #define DUK_POW pow
  1648. #define DUK_ACOS acos
  1649. #define DUK_ASIN asin
  1650. #define DUK_ATAN atan
  1651. #define DUK_ATAN2 atan2
  1652. #define DUK_SIN sin
  1653. #define DUK_COS cos
  1654. #define DUK_TAN tan
  1655. #define DUK_EXP exp
  1656. #define DUK_LOG log
  1657. #define DUK_SQRT sqrt
  1658. /* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
  1659. * see test-bug-netbsd-math-pow.js. Use NetBSD specific workaround.
  1660. * (This might be a wider problem; if so, generalize the define name.)
  1661. */
  1662. #undef DUK_USE_POW_NETBSD_WORKAROUND
  1663. #if defined(DUK_F_NETBSD)
  1664. #define DUK_USE_POW_NETBSD_WORKAROUND
  1665. #endif
  1666. /* Rely as little as possible on compiler behavior for NaN comparison,
  1667. * signed zero handling, etc. Currently never activated but may be needed
  1668. * for broken compilers.
  1669. */
  1670. #undef DUK_USE_PARANOID_MATH
  1671. /* There was a curious bug where test-bi-date-canceling.js would fail e.g.
  1672. * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
  1673. * using doubles would be optimized which then broke some corner case tests.
  1674. * The problem goes away by adding 'volatile' to the datetime computations.
  1675. * Not sure what the actual triggering conditions are, but using this on
  1676. * non-C99 systems solves the known issues and has relatively little cost
  1677. * on other platforms. See bugs/issue-2e9d9c2d761dabaf8136c0897b91a270d1a47147.yaml.
  1678. */
  1679. #undef DUK_USE_PARANOID_DATE_COMPUTATION
  1680. #if !defined(DUK_F_C99)
  1681. #define DUK_USE_PARANOID_DATE_COMPUTATION
  1682. #endif
  1683. /*
  1684. * ANSI C string/memory function wrapper defines to allow easier workarounds.
  1685. * Also convenience macros like DUK_MEMZERO which may be mapped to existing
  1686. * platform function to zero memory (like the deprecated bzero).
  1687. *
  1688. * For instance, some platforms don't support zero-size memcpy correctly,
  1689. * some arcane uclibc versions have a buggy memcpy (but working memmove)
  1690. * and so on. Such broken platforms can be dealt with here.
  1691. *
  1692. * NOTE: ANSI C (various versions) and some implementations require that the
  1693. * pointer arguments to memset(), memcpy(), and memmove() be valid values
  1694. * even when byte size is 0 (even a NULL pointer is considered invalid in
  1695. * this context). Zero-size operations as such are allowed, as long as their
  1696. * pointer arguments point to a valid memory area. The DUK_MEMSET(),
  1697. * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
  1698. * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
  1699. * allowed. If these are not fulfilled, a macro wrapper is needed.
  1700. *
  1701. * http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
  1702. * http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
  1703. *
  1704. * Not sure what's the required behavior when a pointer points just past the
  1705. * end of a buffer, which often happens in practice (e.g. zero size memmoves).
  1706. * For example, if allocation size is 3, the following pointer would not
  1707. * technically point to a valid memory byte:
  1708. *
  1709. * <-- alloc -->
  1710. * | 0 | 1 | 2 | .....
  1711. * ^-- p=3, points after last valid byte (2)
  1712. *
  1713. * If this is a practical issue, wrappers are again needed.
  1714. */
  1715. typedef FILE duk_file;
  1716. #define DUK_STDIN stdin
  1717. #define DUK_STDOUT stdout
  1718. #define DUK_STDERR stderr
  1719. /* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
  1720. * (which is unfortunately named).
  1721. */
  1722. #define DUK_ANSI_MALLOC malloc
  1723. #define DUK_ANSI_REALLOC realloc
  1724. #define DUK_ANSI_CALLOC calloc
  1725. #define DUK_ANSI_FREE free
  1726. /* Old uclibcs have a broken memcpy so use memmove instead (this is overly
  1727. * wide now on purpose):
  1728. * http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
  1729. */
  1730. #if defined(DUK_F_UCLIBC)
  1731. #define DUK_MEMCPY memmove
  1732. #else
  1733. #define DUK_MEMCPY memcpy
  1734. #endif
  1735. #define DUK_MEMMOVE memmove
  1736. #define DUK_MEMCMP memcmp
  1737. #define DUK_MEMSET memset
  1738. #define DUK_STRLEN strlen
  1739. #define DUK_STRCMP strcmp
  1740. #define DUK_STRNCMP strncmp
  1741. #define DUK_PRINTF printf
  1742. #define DUK_FPRINTF fprintf
  1743. #define DUK_SPRINTF sprintf
  1744. #if defined(DUK_F_MSVC)
  1745. /* _snprintf() does NOT NUL terminate on truncation, but Duktape code never
  1746. * assumes that.
  1747. * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
  1748. */
  1749. #define DUK_SNPRINTF _snprintf
  1750. #else
  1751. #define DUK_SNPRINTF snprintf
  1752. #endif
  1753. #define DUK_VSPRINTF vsprintf
  1754. #if defined(DUK_F_MSVC)
  1755. #if (_MSC_VER < 1600)
  1756. /* Older MSVC version are missing vsnprintf() but have _vsnprintf(). */
  1757. #define DUK_VSNPRINTF _vsnprintf
  1758. #else
  1759. #define DUK_VSNPRINTF vsnprintf
  1760. #endif
  1761. #else
  1762. #define DUK_VSNPRINTF vsnprintf
  1763. #endif /* DUK_F_MSVC */
  1764. #define DUK_SSCANF sscanf
  1765. #define DUK_VSSCANF vsscanf
  1766. #define DUK_FOPEN fopen
  1767. #define DUK_FCLOSE fclose
  1768. #define DUK_FREAD fread
  1769. #define DUK_FWRITE fwrite
  1770. #define DUK_FSEEK fseek
  1771. #define DUK_FTELL ftell
  1772. #define DUK_FFLUSH fflush
  1773. #define DUK_FPUTC fputc
  1774. #define DUK_MEMZERO(p,n) \
  1775. DUK_MEMSET((p), 0, (n))
  1776. /*
  1777. * Avoiding platform function pointers.
  1778. *
  1779. * On some platforms built-in functions may be implemented as macros or
  1780. * inline functions, so they can't be necessarily addressed by function
  1781. * pointers. This is certainly the case with some platform "polyfills"
  1782. * which provide missing C99/C++11 functions through macros, and may be
  1783. * the case with VS2013 (see GH-17).
  1784. */
  1785. /* This is now the default: the cost in footprint is negligible. */
  1786. #define DUK_USE_AVOID_PLATFORM_FUNCPTRS
  1787. /*
  1788. * Vararg macro wrappers. We need va_copy() which is defined in C99 / C++11,
  1789. * so an awkward replacement is needed for pre-C99 / pre-C++11 environments.
  1790. * This will quite likely need portability hacks for some non-C99 environments.
  1791. */
  1792. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  1793. /* C99 / C++11 and above: rely on va_copy() which is required.
  1794. * Omit parenthesis on macro right side on purpose to minimize differences
  1795. * to direct use.
  1796. */
  1797. #define DUK_VA_COPY(dest,src) va_copy(dest,src)
  1798. #elif defined(DUK_F_GCC) || defined(DUK_F_CLANG)
  1799. /* GCC: assume we have __va_copy() in non-C99 mode, which should be correct
  1800. * for even quite old GCC versions. Clang matches GCC behavior.
  1801. */
  1802. #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
  1803. #else
  1804. /* Pre-C99: va_list type is implementation dependent. This replacement
  1805. * assumes it is a plain value so that a simple assignment will work.
  1806. * This is not the case on all platforms (it may be a single-array element,
  1807. * for instance).
  1808. */
  1809. #define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
  1810. #endif
  1811. /*
  1812. * Miscellaneous ANSI C or other platform wrappers.
  1813. */
  1814. #define DUK_ABORT abort
  1815. #define DUK_EXIT exit
  1816. /*
  1817. * Macro hackery to convert e.g. __LINE__ to a string without formatting,
  1818. * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
  1819. */
  1820. #define DUK_F_STRINGIFY_HELPER(x) #x
  1821. #define DUK_MACRO_STRINGIFY(x) DUK_F_STRINGIFY_HELPER(x)
  1822. /*
  1823. * Cause segfault macro.
  1824. *
  1825. * This is optionally used by panic handling to cause the program to segfault
  1826. * (instead of e.g. abort()) on panic. Valgrind will then indicate the C
  1827. * call stack leading to the panic.
  1828. */
  1829. #define DUK_CAUSE_SEGFAULT() do { \
  1830. *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; \
  1831. } while (0)
  1832. /*
  1833. * Macro for suppressing warnings for potentially unreferenced variables.
  1834. * The variables can be actually unreferenced or unreferenced in some
  1835. * specific cases only; for instance, if a variable is only debug printed,
  1836. * it is unreferenced when debug printing is disabled.
  1837. *
  1838. * (Introduced here because it's potentially compiler specific.)
  1839. */
  1840. #define DUK_UNREF(x) do { \
  1841. (void) (x); \
  1842. } while (0)
  1843. /*
  1844. * DUK_NORETURN: macro for declaring a 'noreturn' function.
  1845. * Unfortunately the noreturn declaration may appear in various
  1846. * places of a function declaration, so the solution is to wrap
  1847. * the entire declaration inside the macro. Compiler support
  1848. * for using a noreturn declaration on function pointers varies;
  1849. * this macro must only be used for actual function declarations.
  1850. *
  1851. * http://gcc.gnu.org/onlinedocs/gcc-4.3.2//gcc/Function-Attributes.html
  1852. * http://clang.llvm.org/docs/LanguageExtensions.html
  1853. */
  1854. #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L)
  1855. /* since gcc-2.5 */
  1856. #define DUK_NORETURN(decl) decl __attribute__((noreturn))
  1857. #elif defined(__clang__)
  1858. /* syntax same as gcc */
  1859. #define DUK_NORETURN(decl) decl __attribute__((noreturn))
  1860. #elif defined(DUK_F_MSVC)
  1861. /* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
  1862. #define DUK_NORETURN(decl) __declspec(noreturn) decl
  1863. #else
  1864. /* Don't know how to declare a noreturn function, so don't do it; this
  1865. * may cause some spurious compilation warnings (e.g. "variable used
  1866. * uninitialized").
  1867. */
  1868. #define DUK_NORETURN(decl) decl
  1869. #endif
  1870. /*
  1871. * Macro for stating that a certain line cannot be reached.
  1872. *
  1873. * http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Other-Builtins.html#Other-Builtins
  1874. * http://clang.llvm.org/docs/LanguageExtensions.html
  1875. */
  1876. #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
  1877. /* since gcc-4.5 */
  1878. #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while(0)
  1879. #elif defined(__clang__) && defined(__has_builtin)
  1880. #if __has_builtin(__builtin_unreachable)
  1881. /* same as gcc */
  1882. #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while(0)
  1883. #endif
  1884. #else
  1885. /* unknown */
  1886. #endif
  1887. #if !defined(DUK_UNREACHABLE)
  1888. /* Don't know how to declare unreachable point, so don't do it; this
  1889. * may cause some spurious compilation warnings (e.g. "variable used
  1890. * uninitialized").
  1891. */
  1892. #define DUK_UNREACHABLE() /* unreachable */
  1893. #endif
  1894. /*
  1895. * Likely and unlikely branches. Using these is not at all a clear cut case,
  1896. * so the selection is a two-step process: (1) DUK_USE_BRANCH_HINTS is set
  1897. * if the architecture, compiler etc make it useful to use the hints, and (2)
  1898. * a separate check determines how to do them.
  1899. *
  1900. * These macros expect the argument to be a relational expression with an
  1901. * integer value. If used with pointers, you should use an explicit check
  1902. * like:
  1903. *
  1904. * if (DUK_LIKELY(ptr != NULL)) { ... }
  1905. *
  1906. * instead of:
  1907. *
  1908. * if (DUK_LIKELY(ptr)) { ... }
  1909. *
  1910. * http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html (__builtin_expect)
  1911. */
  1912. /* pretty much a placeholder now */
  1913. #if defined(DUK_F_GCC)
  1914. #define DUK_USE_BRANCH_HINTS
  1915. #elif defined(DUK_F_CLANG)
  1916. #define DUK_USE_BRANCH_HINTS
  1917. #else
  1918. #undef DUK_USE_BRANCH_HINTS
  1919. #endif
  1920. #if defined(DUK_USE_BRANCH_HINTS)
  1921. #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
  1922. /* GCC: test not very accurate; enable only in relatively recent builds
  1923. * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
  1924. */
  1925. #define DUK_LIKELY(x) __builtin_expect((x), 1)
  1926. #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
  1927. #elif defined(DUK_F_CLANG)
  1928. #define DUK_LIKELY(x) __builtin_expect((x), 1)
  1929. #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
  1930. #endif
  1931. #endif /* DUK_USE_BRANCH_HINTS */
  1932. #if !defined(DUK_LIKELY)
  1933. #define DUK_LIKELY(x) (x)
  1934. #endif
  1935. #if !defined(DUK_UNLIKELY)
  1936. #define DUK_UNLIKELY(x) (x)
  1937. #endif
  1938. /*
  1939. * Function inlining control
  1940. *
  1941. * DUK_NOINLINE: avoid inlining a function.
  1942. * DUK_INLINE: suggest inlining a function.
  1943. * DUK_ALWAYS_INLINE: force inlining for critical functions.
  1944. */
  1945. #if defined(DUK_F_CLANG)
  1946. #define DUK_NOINLINE __attribute__((noinline))
  1947. #define DUK_INLINE inline
  1948. #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
  1949. #elif defined(DUK_F_GCC) && defined(DUK_F_GCC_VERSION)
  1950. #if (DUK_F_GCC_VERSION >= 30101)
  1951. #define DUK_NOINLINE __attribute__((noinline))
  1952. #define DUK_INLINE inline
  1953. #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
  1954. #endif
  1955. #endif
  1956. #if !defined(DUK_NOINLINE)
  1957. #define DUK_NOINLINE /*nop*/
  1958. #define DUK_INLINE /*nop*/
  1959. #define DUK_ALWAYS_INLINE /*nop*/
  1960. #endif
  1961. /*
  1962. * Symbol visibility macros
  1963. *
  1964. * To avoid C++ declaration issues (see GH-63):
  1965. *
  1966. * - Don't use DUK_LOCAL_DECL for local -data symbols- so that you don't
  1967. * end up with both a "static" declaration and a definition.
  1968. *
  1969. * - Wrap any DUK_INTERNAL_DECL with a '#if !defined(DUK_SINGLE_FILE)'
  1970. * so that the internal declarations (which would map to "static" in
  1971. * a single file distribution) get dropped.
  1972. */
  1973. /* XXX: user override for these? user override for just using the default visibility macros? */
  1974. /* XXX: separate macros for function and data may be necessary at some point. */
  1975. #if defined(DUK_F_GCC_VERSION)
  1976. #if (DUK_F_GCC_VERSION >= 40000) && !(defined(DUK_F_MINGW) || defined(DUK_F_CYGWIN))
  1977. /* Might work on earlier versions too but limit to GCC 4+.
  1978. * MinGW should use Windows specific __declspec or no visibility attributes at all,
  1979. * otherwise: "warning: visibility attribute not supported in this configuration; ignored".
  1980. * Same applies to Cygwin GCC.
  1981. */
  1982. #define DUK_F_GCC_SYMBOL_VISIBILITY
  1983. #endif
  1984. #endif
  1985. #if defined(DUK_F_CLANG) && !defined(DUK_F_GCC_SYMBOL_VISIBILITY)
  1986. #define DUK_F_GCC_SYMBOL_VISIBILITY
  1987. #endif
  1988. #if defined(DUK_OPT_DLL_BUILD) && defined(_WIN32) && (defined(_MSC_VER) || defined(__GNUC__))
  1989. /* __declspec(dllexport) and __declspec(dllimport) only for Windows DLL build.
  1990. * MSVC: any minimum version?
  1991. * MinGW: no minimum version, even gcc-2.95.3 supported dllimport/dllexport.
  1992. */
  1993. #define DUK_F_MSVC_DLL_SYMBOL_VISIBILITY
  1994. #endif
  1995. #if defined(DUK_F_GCC_SYMBOL_VISIBILITY)
  1996. /* GCC 4+ visibility attributes. */
  1997. #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
  1998. #define DUK_EXTERNAL __attribute__ ((visibility("default")))
  1999. #if defined(DUK_SINGLE_FILE)
  2000. #define DUK_INTERNAL_DECL static
  2001. #define DUK_INTERNAL static
  2002. #else
  2003. #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
  2004. #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
  2005. #endif
  2006. #elif defined(DUK_F_MSVC_DLL_SYMBOL_VISIBILITY)
  2007. /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
  2008. * compiling Duktape or the application.
  2009. */
  2010. #if defined(DUK_COMPILING_DUKTAPE)
  2011. #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
  2012. #define DUK_EXTERNAL __declspec(dllexport)
  2013. #else
  2014. #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
  2015. #define DUK_EXTERNAL should_not_happen
  2016. #endif
  2017. #if defined(DUK_SINGLE_FILE)
  2018. #define DUK_INTERNAL_DECL static
  2019. #define DUK_INTERNAL static
  2020. #else
  2021. #define DUK_INTERNAL_DECL extern
  2022. #define DUK_INTERNAL /*empty*/
  2023. #endif
  2024. #else
  2025. /* Default visibility. */
  2026. #define DUK_EXTERNAL_DECL extern
  2027. #define DUK_EXTERNAL /*empty*/
  2028. #if defined(DUK_SINGLE_FILE)
  2029. #define DUK_INTERNAL_DECL static
  2030. #define DUK_INTERNAL static
  2031. #else /* DUK_SINGLE_FILE */
  2032. #define DUK_INTERNAL_DECL extern
  2033. #define DUK_INTERNAL /*empty*/
  2034. #endif
  2035. #endif
  2036. /* For now, these are shared. */
  2037. #define DUK_LOCAL_DECL static
  2038. #define DUK_LOCAL static
  2039. /*
  2040. * __FILE__, __LINE__, __func__ are wrapped. Especially __func__ is a
  2041. * problem because it is not available even in some compilers which try
  2042. * to be C99 compatible (e.g. VBCC with -c99 option).
  2043. */
  2044. #define DUK_FILE_MACRO __FILE__
  2045. #define DUK_LINE_MACRO __LINE__
  2046. #if !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC)
  2047. #define DUK_FUNC_MACRO __func__
  2048. #else
  2049. #define DUK_FUNC_MACRO "unknown"
  2050. #endif
  2051. /*
  2052. * Byteswap macros
  2053. *
  2054. * These are here so that inline assembly or other platform functions can be
  2055. * used if available.
  2056. */
  2057. #define DUK_BSWAP32(x) \
  2058. ((((duk_uint32_t) (x)) >> 24) | \
  2059. ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
  2060. ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
  2061. (((duk_uint32_t) (x)) << 24))
  2062. #define DUK_BSWAP16(x) \
  2063. ((duk_uint16_t) (x) >> 8) | \
  2064. ((duk_uint16_t) (x) << 8)
  2065. /*
  2066. * Architecture string, human readable value exposed in Duktape.env
  2067. */
  2068. #if defined(DUK_F_X86)
  2069. #define DUK_USE_ARCH_STRING "x86"
  2070. #elif defined(DUK_F_X32)
  2071. #define DUK_USE_ARCH_STRING "x32"
  2072. #elif defined(DUK_F_X64)
  2073. #define DUK_USE_ARCH_STRING "x64"
  2074. #elif defined(DUK_F_ARM)
  2075. #define DUK_USE_ARCH_STRING "arm"
  2076. #elif defined(DUK_F_MIPS32)
  2077. #define DUK_USE_ARCH_STRING "mips32"
  2078. #elif defined(DUK_F_MIPS64)
  2079. #define DUK_USE_ARCH_STRING "mips64"
  2080. #elif defined(DUK_F_SUPERH)
  2081. #define DUK_USE_ARCH_STRING "sh"
  2082. #elif defined(DUK_F_M68K)
  2083. #define DUK_USE_ARCH_STRING "m68k"
  2084. #elif defined(DUK_F_FLASHPLAYER)
  2085. #define DUK_USE_ARCH_STRING "flashplayer"
  2086. #elif defined(DUK_F_EMSCRIPTEN)
  2087. #define DUK_USE_ARCH_STRING "emscripten"
  2088. #else
  2089. #define DUK_USE_ARCH_STRING "unknown"
  2090. #endif
  2091. /*
  2092. * OS string, human readable value exposed in Duktape.env
  2093. */
  2094. #if defined(DUK_F_LINUX)
  2095. #define DUK_USE_OS_STRING "linux"
  2096. #elif defined(__APPLE__)
  2097. /* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
  2098. #if TARGET_IPHONE_SIMULATOR
  2099. #define DUK_USE_OS_STRING "iphone-sim"
  2100. #elif TARGET_OS_IPHONE
  2101. #define DUK_USE_OS_STRING "iphone"
  2102. #elif TARGET_OS_MAC
  2103. #define DUK_USE_OS_STRING "ios"
  2104. #else
  2105. #define DUK_USE_OS_STRING "ios-unknown"
  2106. #endif
  2107. #elif defined(DUK_F_FREEBSD)
  2108. #define DUK_USE_OS_STRING "freebsd"
  2109. #elif defined(DUK_F_OPENBSD)
  2110. #define DUK_USE_OS_STRING "openbsd"
  2111. #elif defined(DUK_F_NETBSD)
  2112. #define DUK_USE_OS_STRING "netbsd"
  2113. #elif defined(DUK_F_BSD)
  2114. #define DUK_USE_OS_STRING "bsd"
  2115. #elif defined(DUK_F_UNIX)
  2116. #define DUK_USE_OS_STRING "unix"
  2117. #elif defined(DUK_F_WINDOWS)
  2118. #define DUK_USE_OS_STRING "windows"
  2119. #elif defined(DUK_F_TOS)
  2120. #define DUK_USE_OS_STRING "tos"
  2121. #elif defined(DUK_F_AMIGAOS)
  2122. #define DUK_USE_OS_STRING "amigaos"
  2123. #elif defined(DUK_F_QNX)
  2124. #define DUK_USE_OS_STRING "qnx"
  2125. #elif defined(DUK_F_TINSPIRE)
  2126. #define DUK_USE_OS_STRING "tinspire"
  2127. #else
  2128. #define DUK_USE_OS_STRING "unknown"
  2129. #endif
  2130. /*
  2131. * Compiler string, human readable value exposed in Duktape.env
  2132. */
  2133. #if defined(DUK_F_MINGW)
  2134. #define DUK_USE_COMPILER_STRING "mingw"
  2135. #elif defined(DUK_F_GCC)
  2136. #if defined(DUK_F_CPP)
  2137. #define DUK_USE_COMPILER_STRING "g++"
  2138. #else
  2139. #define DUK_USE_COMPILER_STRING "gcc"
  2140. #endif
  2141. #elif defined(DUK_F_CLANG)
  2142. #define DUK_USE_COMPILER_STRING "clang"
  2143. #elif defined(DUK_F_MSVC)
  2144. #define DUK_USE_COMPILER_STRING "msvc"
  2145. #elif defined(DUK_F_VBCC)
  2146. #define DUK_USE_COMPILER_STRING "vbcc"
  2147. #else
  2148. #define DUK_USE_COMPILER_STRING "unknown"
  2149. #endif
  2150. /*
  2151. * Long control transfer, setjmp/longjmp or alternatives
  2152. *
  2153. * Signal mask is not saved (when that can be communicated to the platform)
  2154. */
  2155. /* dummy non-zero value to be used as an argument for longjmp(), see man longjmp */
  2156. #define DUK_LONGJMP_DUMMY_VALUE 1
  2157. #if defined(DUK_OPT_SETJMP)
  2158. #define DUK_USE_SETJMP
  2159. #elif defined(DUK_OPT_UNDERSCORE_SETJMP)
  2160. #define DUK_USE_UNDERSCORE_SETJMP
  2161. #elif defined(DUK_OPT_SIGSETJMP)
  2162. #define DUK_USE_SIGSETJMP
  2163. #elif defined(__APPLE__)
  2164. /* Use _setjmp() on Apple by default, see GH-55. */
  2165. #define DUK_USE_UNDERSCORE_SETJMP
  2166. #else
  2167. /* The most portable default is setjmp(). */
  2168. #define DUK_USE_SETJMP
  2169. #endif
  2170. #if defined(DUK_USE_UNDERSCORE_SETJMP)
  2171. #define DUK_SETJMP(jb) _setjmp((jb))
  2172. #define DUK_LONGJMP(jb) _longjmp((jb), DUK_LONGJMP_DUMMY_VALUE)
  2173. #elif defined(DUK_USE_SIGSETJMP)
  2174. #define DUK_SETJMP(jb) sigsetjmp((jb), 0 /*savesigs*/)
  2175. #define DUK_LONGJMP(jb) siglongjmp((jb), DUK_LONGJMP_DUMMY_VALUE)
  2176. #elif defined(DUK_USE_SETJMP)
  2177. #define DUK_SETJMP(jb) setjmp((jb))
  2178. #define DUK_LONGJMP(jb) longjmp((jb), DUK_LONGJMP_DUMMY_VALUE)
  2179. #else
  2180. #error internal error
  2181. #endif
  2182. /*
  2183. * Target info string
  2184. */
  2185. #if defined(DUK_OPT_TARGET_INFO)
  2186. #define DUK_USE_TARGET_INFO DUK_OPT_TARGET_INFO
  2187. #else
  2188. #define DUK_USE_TARGET_INFO "unknown"
  2189. #endif
  2190. /*
  2191. * Speed/size and other performance options
  2192. */
  2193. /* Use fast ("inline") refcount operations instead of calling out to helpers
  2194. * by default. The difference in binary size is small (~1kB on x64).
  2195. */
  2196. #define DUK_USE_FAST_REFCOUNT_DEFAULT
  2197. /* Assert for valstack space but don't check for it in non-assert build.
  2198. * Valstack overruns (writing beyond checked space) is memory unsafe and
  2199. * potentially a segfault. Produces a smaller and faster binary.
  2200. * (In practice the speed difference is small with -O3 so default to
  2201. * safer behavior for now.)
  2202. */
  2203. #undef DUK_USE_VALSTACK_UNSAFE
  2204. /* Catch-all flag which can be used to choose between variant algorithms
  2205. * where a speed-size tradeoff exists (e.g. lookup tables). When it really
  2206. * matters, specific use flags may be appropriate.
  2207. */
  2208. #define DUK_USE_PREFER_SIZE
  2209. /*
  2210. * Tagged type representation (duk_tval)
  2211. */
  2212. #undef DUK_USE_PACKED_TVAL
  2213. #if defined(DUK_USE_PACKED_TVAL_POSSIBLE) && !defined(DUK_OPT_NO_PACKED_TVAL)
  2214. #define DUK_USE_PACKED_TVAL
  2215. #endif
  2216. /* Support for 48-bit signed integer duk_tval with transparent semantics. */
  2217. #undef DUK_USE_FASTINT
  2218. #if defined(DUK_OPT_FASTINT)
  2219. #if !defined(DUK_F_HAVE_64BIT)
  2220. #error DUK_OPT_FASTINT requires 64-bit integer type support at the moment
  2221. #endif
  2222. #define DUK_USE_FASTINT
  2223. #endif
  2224. /*
  2225. * Memory management options
  2226. */
  2227. #define DUK_USE_REFERENCE_COUNTING
  2228. #define DUK_USE_DOUBLE_LINKED_HEAP
  2229. #define DUK_USE_MARK_AND_SWEEP
  2230. #define DUK_USE_MS_STRINGTABLE_RESIZE
  2231. #if defined(DUK_OPT_NO_REFERENCE_COUNTING)
  2232. #undef DUK_USE_REFERENCE_COUNTING
  2233. #undef DUK_USE_DOUBLE_LINKED_HEAP
  2234. /* XXX: undef DUK_USE_MS_STRINGTABLE_RESIZE as it is more expensive
  2235. * with more frequent mark-and-sweeps?
  2236. */
  2237. #endif
  2238. #if defined(DUK_OPT_NO_MARK_AND_SWEEP)
  2239. #undef DUK_USE_MARK_AND_SWEEP
  2240. #endif
  2241. #if defined(DUK_USE_MARK_AND_SWEEP)
  2242. #define DUK_USE_VOLUNTARY_GC
  2243. #if defined(DUK_OPT_NO_VOLUNTARY_GC)
  2244. #undef DUK_USE_VOLUNTARY_GC
  2245. #endif
  2246. #endif
  2247. #if !defined(DUK_USE_MARK_AND_SWEEP) && !defined(DUK_USE_REFERENCE_COUNTING)
  2248. #error must have either mark-and-sweep or reference counting enabled
  2249. #endif
  2250. #if defined(DUK_OPT_NO_MS_STRINGTABLE_RESIZE)
  2251. #undef DUK_USE_MS_STRINGTABLE_RESIZE
  2252. #endif
  2253. #undef DUK_USE_GC_TORTURE
  2254. #if defined(DUK_OPT_GC_TORTURE)
  2255. #define DUK_USE_GC_TORTURE
  2256. #endif
  2257. /*
  2258. * String table options
  2259. */
  2260. #if defined(DUK_OPT_STRTAB_CHAIN) && defined(DUK_OPT_STRTAB_CHAIN_SIZE)
  2261. /* Low memory algorithm: separate chaining using arrays, fixed size hash */
  2262. #define DUK_USE_STRTAB_CHAIN
  2263. #define DUK_USE_STRTAB_CHAIN_SIZE DUK_OPT_STRTAB_CHAIN_SIZE
  2264. #else
  2265. /* Default algorithm: open addressing (probing) */
  2266. #define DUK_USE_STRTAB_PROBE
  2267. #endif
  2268. /*
  2269. * Error handling options
  2270. */
  2271. #define DUK_USE_AUGMENT_ERROR_CREATE
  2272. #define DUK_USE_AUGMENT_ERROR_THROW
  2273. #define DUK_USE_TRACEBACKS
  2274. #define DUK_USE_ERRCREATE
  2275. #define DUK_USE_ERRTHROW
  2276. #define DUK_USE_VERBOSE_ERRORS
  2277. #if defined(DUK_OPT_NO_AUGMENT_ERRORS)
  2278. #undef DUK_USE_AUGMENT_ERROR_CREATE
  2279. #undef DUK_USE_AUGMENT_ERROR_THROW
  2280. #undef DUK_USE_TRACEBACKS
  2281. #undef DUK_USE_ERRCREATE
  2282. #undef DUK_USE_ERRTHROW
  2283. #elif defined(DUK_OPT_NO_TRACEBACKS)
  2284. #undef DUK_USE_TRACEBACKS
  2285. #endif
  2286. #if defined(DUK_OPT_NO_VERBOSE_ERRORS)
  2287. #undef DUK_USE_VERBOSE_ERRORS
  2288. #endif
  2289. #if defined(DUK_USE_TRACEBACKS)
  2290. #if defined(DUK_OPT_TRACEBACK_DEPTH)
  2291. #define DUK_USE_TRACEBACK_DEPTH DUK_OPT_TRACEBACK_DEPTH
  2292. #else
  2293. #define DUK_USE_TRACEBACK_DEPTH 10
  2294. #endif
  2295. #endif
  2296. /* Include messages in executor internal errors. */
  2297. #define DUK_USE_VERBOSE_EXECUTOR_ERRORS
  2298. /*
  2299. * Execution and debugger options
  2300. */
  2301. #undef DUK_USE_INTERRUPT_COUNTER
  2302. #if defined(DUK_OPT_INTERRUPT_COUNTER)
  2303. #define DUK_USE_INTERRUPT_COUNTER
  2304. #endif
  2305. #undef DUK_USE_EXEC_TIMEOUT_CHECK
  2306. #if defined(DUK_OPT_EXEC_TIMEOUT_CHECK)
  2307. #define DUK_USE_EXEC_TIMEOUT_CHECK(udata) DUK_OPT_EXEC_TIMEOUT_CHECK((udata))
  2308. #endif
  2309. #undef DUK_USE_DEBUGGER_SUPPORT
  2310. #if defined(DUK_OPT_DEBUGGER_SUPPORT)
  2311. #define DUK_USE_DEBUGGER_SUPPORT
  2312. #endif
  2313. #undef DUK_USE_DEBUGGER_FWD_PRINTALERT
  2314. #if defined(DUK_OPT_DEBUGGER_SUPPORT) && defined(DUK_OPT_DEBUGGER_FWD_PRINTALERT)
  2315. #define DUK_USE_DEBUGGER_FWD_PRINTALERT
  2316. #endif
  2317. #undef DUK_USE_DEBUGGER_FWD_LOGGING
  2318. #if defined(DUK_OPT_DEBUGGER_SUPPORT) && defined(DUK_OPT_DEBUGGER_FWD_LOGGING)
  2319. #define DUK_USE_DEBUGGER_FWD_LOGGING
  2320. #endif
  2321. /* DumpHeap is optional because it's not always needed and has a relatively
  2322. * large footprint.
  2323. */
  2324. #undef DUK_USE_DEBUGGER_DUMPHEAP
  2325. #if defined(DUK_OPT_DEBUGGER_DUMPHEAP)
  2326. #define DUK_USE_DEBUGGER_DUMPHEAP
  2327. #endif
  2328. /* Debugger transport read/write torture. */
  2329. #undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
  2330. #if defined(DUK_OPT_DEBUGGER_TRANSPORT_TORTURE)
  2331. #define DUK_USE_DEBUGGER_TRANSPORT_TORTURE
  2332. #endif
  2333. /* For opcodes with indirect indices, check final index against stack size.
  2334. * This should not be necessary because the compiler is trusted, and we don't
  2335. * bound check non-indirect indices either.
  2336. */
  2337. #undef DUK_USE_EXEC_INDIRECT_BOUND_CHECK
  2338. #if defined(DUK_OPT_DEBUG) || defined(DUK_OPT_ASSERTIONS)
  2339. /* Enabled with debug/assertions just so that any issues can be caught. */
  2340. #define DUK_USE_EXEC_INDIRECT_BOUND_CHECK
  2341. #endif
  2342. /*
  2343. * Debug printing and assertion options
  2344. */
  2345. #undef DUK_USE_DEBUG
  2346. #undef DUK_USE_DPRINT
  2347. #undef DUK_USE_DDPRINT
  2348. #undef DUK_USE_DDDPRINT
  2349. #undef DUK_USE_DPRINT_RDTSC
  2350. #undef DUK_USE_ASSERTIONS
  2351. /* Global debug enable. Compile must be clean on C99 regardless of whether or
  2352. * not debugging is enabled. On non-C99 platforms compile should be clean with
  2353. * debugging disabled but may produce warnings with debugging enabled (related
  2354. * to debug macro hackery and such).
  2355. */
  2356. #if defined(DUK_OPT_DEBUG)
  2357. #define DUK_USE_DEBUG
  2358. #endif
  2359. #if defined(DUK_OPT_DEBUG) && defined(DUK_OPT_DPRINT)
  2360. #define DUK_USE_DPRINT
  2361. #endif
  2362. #if defined(DUK_OPT_DEBUG) && defined(DUK_OPT_DDPRINT)
  2363. #define DUK_USE_DDPRINT
  2364. #endif
  2365. #if defined(DUK_OPT_DEBUG) && defined(DUK_OPT_DDDPRINT)
  2366. #define DUK_USE_DDDPRINT
  2367. #endif
  2368. #undef DUK_USE_DPRINT_COLORS
  2369. #if defined(DUK_OPT_DPRINT_COLORS)
  2370. #define DUK_USE_DPRINT_COLORS
  2371. #endif
  2372. #if defined(DUK_RDTSC_AVAILABLE) && defined(DUK_OPT_DPRINT_RDTSC)
  2373. #define DUK_USE_DPRINT_RDTSC
  2374. #else
  2375. #undef DUK_USE_DPRINT_RDTSC
  2376. #endif
  2377. #if defined(DUK_OPT_ASSERTIONS)
  2378. #define DUK_USE_ASSERTIONS
  2379. #endif
  2380. /* The static buffer for debug printing is quite large by default, so there
  2381. * is an option to shrink it manually for constrained builds.
  2382. */
  2383. #if defined(DUK_OPT_DEBUG_BUFSIZE)
  2384. #define DUK_USE_DEBUG_BUFSIZE DUK_OPT_DEBUG_BUFSIZE
  2385. #else
  2386. #define DUK_USE_DEBUG_BUFSIZE 65536L
  2387. #endif
  2388. /*
  2389. * Ecmascript features / compliance options
  2390. */
  2391. #if defined(DUK_F_BCC)
  2392. /* Math built-in is stubbed out on BCC to allow compiler torture testing. */
  2393. #else
  2394. #define DUK_USE_MATH_BUILTIN
  2395. #endif
  2396. #define DUK_USE_STRICT_DECL
  2397. #if defined(DUK_OPT_NO_STRICT_DECL)
  2398. #undef DUK_USE_STRICT_DECL
  2399. #endif
  2400. #define DUK_USE_REGEXP_SUPPORT
  2401. #if defined(DUK_OPT_NO_REGEXP_SUPPORT)
  2402. #undef DUK_USE_REGEXP_SUPPORT
  2403. #endif
  2404. #undef DUK_USE_STRICT_UTF8_SOURCE
  2405. #if defined(DUK_OPT_STRICT_UTF8_SOURCE)
  2406. #define DUK_USE_STRICT_UTF8_SOURCE
  2407. #endif
  2408. #define DUK_USE_OCTAL_SUPPORT
  2409. #if defined(DUK_OPT_NO_OCTAL_SUPPORT)
  2410. #undef DUK_USE_OCTAL_SUPPORT
  2411. #endif
  2412. #define DUK_USE_SOURCE_NONBMP
  2413. #if defined(DUK_OPT_NO_SOURCE_NONBMP)
  2414. #undef DUK_USE_SOURCE_NONBMP
  2415. #endif
  2416. #define DUK_USE_BROWSER_LIKE
  2417. #if defined(DUK_OPT_NO_BROWSER_LIKE)
  2418. #undef DUK_USE_BROWSER_LIKE
  2419. #endif
  2420. /* E5/E5.1 Section B features. */
  2421. #define DUK_USE_SECTION_B
  2422. #if defined(DUK_OPT_NO_SECTION_B)
  2423. #undef DUK_USE_SECTION_B
  2424. #endif
  2425. /* Non-standard regexp parsing features. */
  2426. #define DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE
  2427. /* Treat function statements (function declarations outside top level of
  2428. * Program or FunctionBody) same as normal function declarations. This is
  2429. * also V8 behavior. See test-dev-func-decl-outside-top.js.
  2430. */
  2431. #define DUK_USE_NONSTD_FUNC_STMT
  2432. #if defined(DUK_OPT_NO_NONSTD_FUNC_STMT)
  2433. #undef DUK_USE_NONSTD_FUNC_STMT
  2434. #endif
  2435. /* Array.prototype.splice() non-standard but real world compatible behavior
  2436. * when deleteCount is omitted.
  2437. */
  2438. #define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
  2439. #if defined(DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT)
  2440. #undef DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
  2441. #endif
  2442. /* Array.prototype.concat() non-standard but real world compatible behavior
  2443. * for non-existent trailing elements.
  2444. */
  2445. #define DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
  2446. #if defined(DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER)
  2447. #undef DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
  2448. #endif
  2449. /* Array.prototype.map() non-standard but real world compatible behavior
  2450. * for non-existent trailing elements.
  2451. */
  2452. #define DUK_USE_NONSTD_ARRAY_MAP_TRAILER
  2453. #if defined(DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER)
  2454. #undef DUK_USE_NONSTD_ARRAY_MAP_TRAILER
  2455. #endif
  2456. /* Non-standard 'caller' property for function instances, see
  2457. * test-bi-function-nonstd-caller-prop.js.
  2458. */
  2459. #undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
  2460. #if defined(DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY)
  2461. #define DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
  2462. #endif
  2463. /* Non-standard Object.prototype.__proto__ (ES6 draft), see
  2464. * test-bi-object-proto-__proto__.js.
  2465. */
  2466. #define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
  2467. #if defined(DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY)
  2468. #undef DUK_USE_ES6_OBJECT_PROTO_PROPERTY
  2469. #endif
  2470. /* Non-standard Object.setPrototypeOf (ES6 draft), see
  2471. * test-bi-object-setprototypeof.js.
  2472. */
  2473. #define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
  2474. #if defined(DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF)
  2475. #undef DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
  2476. #endif
  2477. /* ES6 Proxy object (subset for now). */
  2478. #define DUK_USE_ES6_PROXY
  2479. #if defined(DUK_OPT_NO_ES6_PROXY)
  2480. #undef DUK_USE_ES6_PROXY
  2481. #endif
  2482. /* Record pc-to-line information. */
  2483. #define DUK_USE_PC2LINE
  2484. #if defined(DUK_OPT_NO_PC2LINE)
  2485. #undef DUK_USE_PC2LINE
  2486. #endif
  2487. /* Non-standard function 'source' property. */
  2488. #undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
  2489. #if defined(DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY)
  2490. #define DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
  2491. #endif
  2492. /* CommonJS modules */
  2493. #define DUK_USE_COMMONJS_MODULES
  2494. #if defined(DUK_OPT_NO_COMMONJS_MODULES)
  2495. #undef DUK_USE_COMMONJS_MODULES
  2496. #endif
  2497. /* Additional key argument to setter/getter calls when triggered by property
  2498. * accesses.
  2499. */
  2500. #define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
  2501. #define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
  2502. #if defined(DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT)
  2503. #undef DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
  2504. #undef DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
  2505. #endif
  2506. /* JSON escaping of U+2028 and U+2029.
  2507. */
  2508. #define DUK_USE_NONSTD_JSON_ESC_U2028_U2029
  2509. #if defined(DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029)
  2510. #undef DUK_USE_NONSTD_JSON_ESC_U2028_U2029
  2511. #endif
  2512. /* Allow 32-bit codepoints in String.fromCharCode. */
  2513. #define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
  2514. #if defined(DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT)
  2515. #undef DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
  2516. #endif
  2517. /* Non-standard array fast path write behavior: when writing to numeric
  2518. * indexes of an Array instance, assume Array.prototype doesn't have
  2519. * conflicting properties (e.g. a non-writable property "7").
  2520. */
  2521. #define DUK_USE_NONSTD_ARRAY_WRITE
  2522. #if defined(DUK_OPT_NO_NONSTD_ARRAY_WRITE)
  2523. #undef DUK_USE_NONSTD_ARRAY_WRITE
  2524. #endif
  2525. /*
  2526. * Tailcalls
  2527. */
  2528. /* Tailcalls are enabled by default. The non-standard function 'caller'
  2529. * property feature conflicts with tailcalls quite severely so tailcalls
  2530. * are disabled if the 'caller' property is enabled.
  2531. */
  2532. #define DUK_USE_TAILCALL
  2533. #if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY)
  2534. #undef DUK_USE_TAILCALL
  2535. #endif
  2536. /*
  2537. * Deep vs. shallow stack.
  2538. *
  2539. * Some embedded platforms have very shallow stack (e.g. 64kB); default to
  2540. * a shallow stack on unknown platforms or known embedded platforms.
  2541. */
  2542. #if defined(DUK_F_LINUX) || defined(DUK_F_BSD) || defined(DUK_F_WINDOWS) || \
  2543. defined(DUK_OPT_DEEP_C_STACK)
  2544. #define DUK_USE_DEEP_C_STACK
  2545. #else
  2546. #undef DUK_USE_DEEP_C_STACK
  2547. #endif
  2548. /*
  2549. * Ecmascript compiler
  2550. */
  2551. /* Ensure final bytecode never exceeds a certain byte size and never uses
  2552. * line numbers above a certain limit. This ensures that there is no need
  2553. * to deal with unbounded ranges in e.g. pc2line data structures. For now,
  2554. * limits are set so that signed 32-bit values can represent line number
  2555. * and byte offset with room to spare.
  2556. */
  2557. #define DUK_USE_ESBC_LIMITS
  2558. #define DUK_USE_ESBC_MAX_LINENUMBER 0x7fff0000L
  2559. #define DUK_USE_ESBC_MAX_BYTES 0x7fff0000L
  2560. #undef DUK_USE_SHUFFLE_TORTURE
  2561. #if defined(DUK_OPT_SHUFFLE_TORTURE)
  2562. #define DUK_USE_SHUFFLE_TORTURE
  2563. #endif
  2564. /*
  2565. * User panic handler, panic exit behavior for default panic handler
  2566. */
  2567. #undef DUK_USE_PANIC_HANDLER
  2568. #if defined(DUK_OPT_PANIC_HANDLER)
  2569. #define DUK_USE_PANIC_HANDLER(code,msg) DUK_OPT_PANIC_HANDLER((code),(msg))
  2570. #endif
  2571. #undef DUK_USE_PANIC_ABORT
  2572. #undef DUK_USE_PANIC_EXIT
  2573. #undef DUK_USE_PANIC_SEGFAULT
  2574. #if defined(DUK_OPT_SEGFAULT_ON_PANIC)
  2575. #define DUK_USE_PANIC_SEGFAULT
  2576. #else
  2577. #define DUK_USE_PANIC_ABORT
  2578. #endif
  2579. /*
  2580. * File I/O support. This is now used in a few API calls to e.g. push
  2581. * a string from file contents or eval a file. For portability it must
  2582. * be possible to disable I/O altogether.
  2583. */
  2584. #undef DUK_USE_FILE_IO
  2585. #if !defined(DUK_OPT_NO_FILE_IO)
  2586. #define DUK_USE_FILE_IO
  2587. #endif
  2588. /*
  2589. * Optional run-time self tests executed when a heap is created. Some
  2590. * platform/compiler issues cannot be determined at compile time. One
  2591. * particular example is the bug described in misc/clang_aliasing.c.
  2592. */
  2593. #undef DUK_USE_SELF_TESTS
  2594. #if defined(DUK_OPT_SELF_TESTS)
  2595. #define DUK_USE_SELF_TESTS
  2596. #endif
  2597. /* Double aliasing testcase fails when Emscripten-generated code is run
  2598. * on Firefox. This is not fatal because it only affects packed duk_tval
  2599. * which we avoid with Emscripten.
  2600. */
  2601. #undef DUK_USE_NO_DOUBLE_ALIASING_SELFTEST
  2602. #if defined(DUK_F_EMSCRIPTEN)
  2603. #define DUK_USE_NO_DOUBLE_ALIASING_SELFTEST
  2604. #endif
  2605. /*
  2606. * Codecs
  2607. */
  2608. #define DUK_USE_JX
  2609. #if defined(DUK_OPT_NO_JX)
  2610. #undef DUK_USE_JX
  2611. #endif
  2612. #define DUK_USE_JC
  2613. #if defined(DUK_OPT_NO_JC)
  2614. #undef DUK_USE_JC
  2615. #endif
  2616. /*
  2617. * InitJS code
  2618. */
  2619. /* Always use the built-in InitJS code for now. */
  2620. #define DUK_USE_BUILTIN_INITJS
  2621. /* User provided InitJS. */
  2622. #undef DUK_USE_USER_INITJS
  2623. #if defined(DUK_OPT_USER_INITJS)
  2624. #define DUK_USE_USER_INITJS (DUK_OPT_USER_INITJS)
  2625. #endif
  2626. /*
  2627. * External string data support
  2628. *
  2629. * Allow duk_hstrings to store data also behind an external pointer (see
  2630. * duk_hstring_external). This increases code size slightly but is useful
  2631. * in low memory environments where memory is more limited than flash.
  2632. */
  2633. #undef DUK_USE_HSTRING_EXTDATA
  2634. #if defined(DUK_OPT_EXTERNAL_STRINGS)
  2635. #define DUK_USE_HSTRING_EXTDATA
  2636. #endif
  2637. #undef DUK_USE_EXTSTR_INTERN_CHECK
  2638. #if defined(DUK_OPT_EXTERNAL_STRINGS) && defined(DUK_OPT_EXTSTR_INTERN_CHECK)
  2639. #define DUK_USE_EXTSTR_INTERN_CHECK(udata,ptr,len) DUK_OPT_EXTSTR_INTERN_CHECK((udata), (ptr), (len))
  2640. #endif
  2641. #undef DUK_USE_EXTSTR_FREE
  2642. #if defined(DUK_OPT_EXTERNAL_STRINGS) && defined(DUK_OPT_EXTSTR_FREE)
  2643. #define DUK_USE_EXTSTR_FREE(udata,ptr) DUK_OPT_EXTSTR_FREE((udata), (ptr))
  2644. #endif
  2645. /*
  2646. * Lightweight functions
  2647. */
  2648. /* Force built-ins to use lightfunc function pointers when possible. This
  2649. * makes the built-in functions non-compliant with respect to their property
  2650. * values and such, but is very useful in low memory environments (can save
  2651. * around 14kB of initial RAM footprint).
  2652. */
  2653. #undef DUK_USE_LIGHTFUNC_BUILTINS
  2654. #if defined(DUK_OPT_LIGHTFUNC_BUILTINS)
  2655. #define DUK_USE_LIGHTFUNC_BUILTINS
  2656. #endif
  2657. /*
  2658. * Pointer compression and 16-bit header fields for low memory environments
  2659. */
  2660. #undef DUK_USE_HEAPPTR16
  2661. #undef DUK_USE_HEAPPTR_ENC16
  2662. #undef DUK_USE_HEAPPTR_DEC16
  2663. #if defined(DUK_OPT_HEAPPTR16) && defined(DUK_OPT_HEAPPTR_ENC16) && defined(DUK_OPT_HEAPPTR_DEC16)
  2664. #define DUK_USE_HEAPPTR16
  2665. #define DUK_USE_HEAPPTR_ENC16(udata,ptr) DUK_OPT_HEAPPTR_ENC16((udata),(ptr))
  2666. #define DUK_USE_HEAPPTR_DEC16(udata,ptr) DUK_OPT_HEAPPTR_DEC16((udata),(ptr))
  2667. #endif
  2668. #undef DUK_USE_DATAPTR16
  2669. #undef DUK_USE_DATAPTR_ENC16
  2670. #undef DUK_USE_DATAPTR_DEC16
  2671. #if defined(DUK_OPT_DATAPTR16) && defined(DUK_OPT_DATAPTR_ENC16) && defined(DUK_OPT_DATAPTR_DEC16)
  2672. #define DUK_USE_DATAPTR16
  2673. #define DUK_USE_DATAPTR_ENC16(udata,ptr) DUK_OPT_DATAPTR_ENC16((udata),(ptr))
  2674. #define DUK_USE_DATAPTR_DEC16(udata,ptr) DUK_OPT_DATAPTR_DEC16((udata),(ptr))
  2675. #endif
  2676. #undef DUK_USE_FUNCPTR16
  2677. #undef DUK_USE_FUNCPTR_ENC16
  2678. #undef DUK_USE_FUNCPTR_DEC16
  2679. #if defined(DUK_OPT_FUNCPTR16) && defined(DUK_OPT_FUNCPTR_ENC16) && defined(DUK_OPT_FUNCPTR_DEC16)
  2680. #define DUK_USE_FUNCPTR16
  2681. #define DUK_USE_FUNCPTR_ENC16(udata,ptr) DUK_OPT_FUNCPTR_ENC16((udata),(ptr))
  2682. #define DUK_USE_FUNCPTR_DEC16(udata,ptr) DUK_OPT_FUNCPTR_DEC16((udata),(ptr))
  2683. #endif
  2684. #undef DUK_USE_REFCOUNT16
  2685. #if defined(DUK_OPT_REFCOUNT16)
  2686. #define DUK_USE_REFCOUNT16
  2687. #endif
  2688. #undef DUK_USE_STRHASH16
  2689. #if defined(DUK_OPT_STRHASH16)
  2690. #define DUK_USE_STRHASH16
  2691. #endif
  2692. #undef DUK_USE_STRLEN16
  2693. #if defined(DUK_OPT_STRLEN16)
  2694. #define DUK_USE_STRLEN16
  2695. #endif
  2696. #undef DUK_USE_BUFLEN16
  2697. #if defined(DUK_OPT_BUFLEN16)
  2698. #define DUK_USE_BUFLEN16
  2699. #endif
  2700. #undef DUK_USE_OBJSIZES16
  2701. #if defined(DUK_OPT_OBJSIZES16)
  2702. #define DUK_USE_OBJSIZES16
  2703. #endif
  2704. /* For now, hash part is dropped if and only if 16-bit object fields are used. */
  2705. #define DUK_USE_HOBJECT_HASH_PART
  2706. #if defined(DUK_USE_OBJSIZES16)
  2707. #undef DUK_USE_HOBJECT_HASH_PART
  2708. #endif
  2709. /*
  2710. * Miscellaneous
  2711. */
  2712. #define DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
  2713. #undef DUK_USE_EXPLICIT_NULL_INIT
  2714. #if !defined(DUK_USE_PACKED_TVAL)
  2715. #define DUK_USE_EXPLICIT_NULL_INIT
  2716. #endif
  2717. #define DUK_USE_ZERO_BUFFER_DATA
  2718. #if defined(DUK_OPT_NO_ZERO_BUFFER_DATA)
  2719. #undef DUK_USE_ZERO_BUFFER_DATA
  2720. #endif
  2721. #undef DUK_USE_VARIADIC_MACROS
  2722. #if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
  2723. #define DUK_USE_VARIADIC_MACROS
  2724. #endif
  2725. #if defined(_MSC_VER) && !defined(DUK_USE_VARIADIC_MACROS)
  2726. #if (_MSC_VER >= 1400)
  2727. /* VS2005+ should have variadic macros even when they're not C99. */
  2728. #define DUK_USE_VARIADIC_MACROS
  2729. #endif
  2730. #endif
  2731. /*
  2732. * Variable size array initialization.
  2733. *
  2734. * Variable size array at the end of a structure is nonportable.
  2735. * There are three alternatives:
  2736. *
  2737. * 1) C99 (flexible array member): char buf[]
  2738. * 2) Compiler specific (e.g. GCC): char buf[0]
  2739. * 3) Portable but wastes memory / complicates allocation: char buf[1]
  2740. */
  2741. /* XXX: Currently unused, only hbuffer.h needed this at some point. */
  2742. #undef DUK_USE_FLEX_C99
  2743. #undef DUK_USE_FLEX_ZEROSIZE
  2744. #undef DUK_USE_FLEX_ONESIZE
  2745. #if defined(DUK_F_C99)
  2746. #define DUK_USE_FLEX_C99
  2747. #elif defined(__GNUC__)
  2748. #define DUK_USE_FLEX_ZEROSIZE
  2749. #else
  2750. #define DUK_USE_FLEX_ONESIZE
  2751. #endif
  2752. /*
  2753. * GCC pragmas
  2754. */
  2755. /* XXX: GCC pragma inside a function fails in some earlier GCC versions (e.g. gcc 4.5).
  2756. * This is very approximate but allows clean builds for development right now.
  2757. */
  2758. /* http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html */
  2759. #if defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)
  2760. #define DUK_USE_GCC_PRAGMAS
  2761. #else
  2762. #undef DUK_USE_GCC_PRAGMAS
  2763. #endif
  2764. /*
  2765. * User declarations
  2766. */
  2767. #if defined(DUK_OPT_DECLARE)
  2768. #define DUK_USE_USER_DECLARE() DUK_OPT_DECLARE
  2769. #else
  2770. #define DUK_USE_USER_DECLARE() /* no user declarations */
  2771. #endif
  2772. /*
  2773. * Alternative customization header
  2774. *
  2775. * If you want to modify the final DUK_USE_xxx flags directly (without
  2776. * using the available DUK_OPT_Xxx flags), define DUK_OPT_HAVE_CUSTOM_H
  2777. * and tweak the final flags there.
  2778. */
  2779. #if defined(DUK_OPT_HAVE_CUSTOM_H)
  2780. #include "duk_custom.h"
  2781. #endif
  2782. #endif /* DUK_FEATURES_H_INCLUDED */
  2783. /*
  2784. * BEGIN PUBLIC API
  2785. */
  2786. #ifndef DUK_API_PUBLIC_H_INCLUDED
  2787. #define DUK_API_PUBLIC_H_INCLUDED
  2788. /*
  2789. * Avoid C++ name mangling
  2790. */
  2791. #ifdef __cplusplus
  2792. extern "C" {
  2793. #endif
  2794. /*
  2795. * Some defines forwarded from feature detection
  2796. */
  2797. #undef DUK_API_VARIADIC_MACROS
  2798. #ifdef DUK_USE_VARIADIC_MACROS
  2799. #define DUK_API_VARIADIC_MACROS
  2800. #endif
  2801. #define DUK_API_NORETURN(decl) DUK_NORETURN(decl)
  2802. /*
  2803. * Public API specific typedefs
  2804. *
  2805. * (duk_context *) maps directly to internal type (duk_hthread *).
  2806. * Currently only primitive typedefs have a '_t' suffix.
  2807. *
  2808. * Many types are wrapped by Duktape for portability to rare platforms
  2809. * where e.g. 'int' is a 16-bit type. See practical typing discussion
  2810. * in Duktape web documentation.
  2811. */
  2812. struct duk_memory_functions;
  2813. struct duk_function_list_entry;
  2814. struct duk_number_list_entry;
  2815. typedef void duk_context;
  2816. typedef struct duk_memory_functions duk_memory_functions;
  2817. typedef struct duk_function_list_entry duk_function_list_entry;
  2818. typedef struct duk_number_list_entry duk_number_list_entry;
  2819. typedef duk_ret_t(*duk_c_function)(duk_context *ctx);
  2820. typedef void *(*duk_alloc_function) (void *udata, duk_size_t size);
  2821. typedef void *(*duk_realloc_function) (void *udata, void *ptr, duk_size_t size);
  2822. typedef void(*duk_free_function) (void *udata, void *ptr);
  2823. typedef void(*duk_fatal_function) (duk_context *ctx, duk_errcode_t code, const char *msg);
  2824. typedef void(*duk_decode_char_function) (void *udata, duk_codepoint_t codepoint);
  2825. typedef duk_codepoint_t(*duk_map_char_function) (void *udata, duk_codepoint_t codepoint);
  2826. typedef duk_ret_t(*duk_safe_call_function) (duk_context *ctx);
  2827. typedef duk_size_t(*duk_debug_read_function) (void *udata, char *buffer, duk_size_t length);
  2828. typedef duk_size_t(*duk_debug_write_function) (void *udata, const char *buffer, duk_size_t length);
  2829. typedef duk_size_t(*duk_debug_peek_function) (void *udata);
  2830. typedef void(*duk_debug_read_flush_function) (void *udata);
  2831. typedef void(*duk_debug_write_flush_function) (void *udata);
  2832. typedef void(*duk_debug_detached_function) (void *udata);
  2833. struct duk_memory_functions {
  2834. duk_alloc_function alloc_func;
  2835. duk_realloc_function realloc_func;
  2836. duk_free_function free_func;
  2837. void *udata;
  2838. };
  2839. struct duk_function_list_entry {
  2840. const char *key;
  2841. duk_c_function value;
  2842. duk_idx_t nargs;
  2843. };
  2844. struct duk_number_list_entry {
  2845. const char *key;
  2846. duk_double_t value;
  2847. };
  2848. /*
  2849. * Constants
  2850. */
  2851. /* Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
  2852. * to #ifdef against Duktape API version. The same value is also available
  2853. * to Ecmascript code in Duktape.version. Unofficial development snapshots
  2854. * have 99 for patch level (e.g. 0.10.99 would be a development version
  2855. * after 0.10.0 but before the next official release).
  2856. */
  2857. #define DUK_VERSION 10201L
  2858. /* Git describe for Duktape build. Useful for non-official snapshot builds
  2859. * so that application code can easily log which Duktape snapshot was used.
  2860. * Not available in the Ecmascript environment.
  2861. */
  2862. #define DUK_GIT_DESCRIBE "v1.2.1"
  2863. /* Duktape debug protocol version used by this build. */
  2864. #define DUK_DEBUG_PROTOCOL_VERSION 1
  2865. /* Used to represent invalid index; if caller uses this without checking,
  2866. * this index will map to a non-existent stack entry. Also used in some
  2867. * API calls as a marker to denote "no value".
  2868. */
  2869. #define DUK_INVALID_INDEX DUK_IDX_MIN
  2870. /* Indicates that a native function does not have a fixed number of args,
  2871. * and the argument stack should not be capped/extended at all.
  2872. */
  2873. #define DUK_VARARGS ((duk_int_t) (-1))
  2874. /* Number of value stack entries (in addition to actual call arguments)
  2875. * guaranteed to be allocated on entry to a Duktape/C function.
  2876. */
  2877. #define DUK_API_ENTRY_STACK 64
  2878. /* Value types, used by e.g. duk_get_type() */
  2879. #define DUK_TYPE_NONE 0 /* no value, e.g. invalid index */
  2880. #define DUK_TYPE_UNDEFINED 1 /* Ecmascript undefined */
  2881. #define DUK_TYPE_NULL 2 /* Ecmascript null */
  2882. #define DUK_TYPE_BOOLEAN 3 /* Ecmascript boolean: 0 or 1 */
  2883. #define DUK_TYPE_NUMBER 4 /* Ecmascript number: double */
  2884. #define DUK_TYPE_STRING 5 /* Ecmascript string: CESU-8 / extended UTF-8 encoded */
  2885. #define DUK_TYPE_OBJECT 6 /* Ecmascript object: includes objects, arrays, functions, threads */
  2886. #define DUK_TYPE_BUFFER 7 /* fixed or dynamic, garbage collected byte buffer */
  2887. #define DUK_TYPE_POINTER 8 /* raw void pointer */
  2888. #define DUK_TYPE_LIGHTFUNC 9 /* lightweight function pointer */
  2889. /* Value mask types, used by e.g. duk_get_type_mask() */
  2890. #define DUK_TYPE_MASK_NONE (1 << DUK_TYPE_NONE)
  2891. #define DUK_TYPE_MASK_UNDEFINED (1 << DUK_TYPE_UNDEFINED)
  2892. #define DUK_TYPE_MASK_NULL (1 << DUK_TYPE_NULL)
  2893. #define DUK_TYPE_MASK_BOOLEAN (1 << DUK_TYPE_BOOLEAN)
  2894. #define DUK_TYPE_MASK_NUMBER (1 << DUK_TYPE_NUMBER)
  2895. #define DUK_TYPE_MASK_STRING (1 << DUK_TYPE_STRING)
  2896. #define DUK_TYPE_MASK_OBJECT (1 << DUK_TYPE_OBJECT)
  2897. #define DUK_TYPE_MASK_BUFFER (1 << DUK_TYPE_BUFFER)
  2898. #define DUK_TYPE_MASK_POINTER (1 << DUK_TYPE_POINTER)
  2899. #define DUK_TYPE_MASK_LIGHTFUNC (1 << DUK_TYPE_LIGHTFUNC)
  2900. #define DUK_TYPE_MASK_THROW (1 << 10) /* internal flag value: throw if mask doesn't match */
  2901. /* Coercion hints */
  2902. #define DUK_HINT_NONE 0 /* prefer number, unless input is a Date, in which
  2903. * case prefer string (E5 Section 8.12.8)
  2904. */
  2905. #define DUK_HINT_STRING 1 /* prefer string */
  2906. #define DUK_HINT_NUMBER 2 /* prefer number */
  2907. /* Enumeration flags for duk_enum() */
  2908. #define DUK_ENUM_INCLUDE_NONENUMERABLE (1 << 0) /* enumerate non-numerable properties in addition to enumerable */
  2909. #define DUK_ENUM_INCLUDE_INTERNAL (1 << 1) /* enumerate internal properties (regardless of enumerability) */
  2910. #define DUK_ENUM_OWN_PROPERTIES_ONLY (1 << 2) /* don't walk prototype chain, only check own properties */
  2911. #define DUK_ENUM_ARRAY_INDICES_ONLY (1 << 3) /* only enumerate array indices */
  2912. #define DUK_ENUM_SORT_ARRAY_INDICES (1 << 4) /* sort array indices, use with DUK_ENUM_ARRAY_INDICES_ONLY */
  2913. #define DUK_ENUM_NO_PROXY_BEHAVIOR (1 << 5) /* enumerate a proxy object itself without invoking proxy behavior */
  2914. /* Compilation flags for duk_compile() and duk_eval() */
  2915. #define DUK_COMPILE_EVAL (1 << 0) /* compile eval code (instead of program) */
  2916. #define DUK_COMPILE_FUNCTION (1 << 1) /* compile function code (instead of program) */
  2917. #define DUK_COMPILE_STRICT (1 << 2) /* use strict (outer) context for program, eval, or function */
  2918. #define DUK_COMPILE_SAFE (1 << 3) /* (internal) catch compilation errors */
  2919. #define DUK_COMPILE_NORESULT (1 << 4) /* (internal) omit eval result */
  2920. #define DUK_COMPILE_NOSOURCE (1 << 5) /* (internal) no source string on stack */
  2921. #define DUK_COMPILE_STRLEN (1 << 6) /* (internal) take strlen() of src_buffer (avoids double evaluation in macro) */
  2922. /* Flags for duk_def_prop() and its variants */
  2923. #define DUK_DEFPROP_WRITABLE (1 << 0) /* set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set) */
  2924. #define DUK_DEFPROP_ENUMERABLE (1 << 1) /* set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set) */
  2925. #define DUK_DEFPROP_CONFIGURABLE (1 << 2) /* set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set) */
  2926. #define DUK_DEFPROP_HAVE_WRITABLE (1 << 3) /* set/clear writable */
  2927. #define DUK_DEFPROP_HAVE_ENUMERABLE (1 << 4) /* set/clear enumerable */
  2928. #define DUK_DEFPROP_HAVE_CONFIGURABLE (1 << 5) /* set/clear configurable */
  2929. #define DUK_DEFPROP_HAVE_VALUE (1 << 6) /* set value (given on value stack) */
  2930. #define DUK_DEFPROP_HAVE_GETTER (1 << 7) /* set getter (given on value stack) */
  2931. #define DUK_DEFPROP_HAVE_SETTER (1 << 8) /* set setter (given on value stack) */
  2932. #define DUK_DEFPROP_FORCE (1 << 9) /* force change if possible, may still fail for e.g. virtual properties */
  2933. /* Flags for duk_push_thread_raw() */
  2934. #define DUK_THREAD_NEW_GLOBAL_ENV (1 << 0) /* create a new global environment */
  2935. /* Flags for duk_push_string_file_raw() */
  2936. #define DUK_STRING_PUSH_SAFE (1 << 0) /* no error if file does not exist */
  2937. /* Duktape specific error codes */
  2938. #define DUK_ERR_NONE 0 /* no error (e.g. from duk_get_error_code()) */
  2939. #define DUK_ERR_UNIMPLEMENTED_ERROR 50 /* UnimplementedError */
  2940. #define DUK_ERR_UNSUPPORTED_ERROR 51 /* UnsupportedError */
  2941. #define DUK_ERR_INTERNAL_ERROR 52 /* InternalError */
  2942. #define DUK_ERR_ALLOC_ERROR 53 /* AllocError */
  2943. #define DUK_ERR_ASSERTION_ERROR 54 /* AssertionError */
  2944. #define DUK_ERR_API_ERROR 55 /* APIError */
  2945. #define DUK_ERR_UNCAUGHT_ERROR 56 /* UncaughtError */
  2946. /* Ecmascript E5 specification error codes */
  2947. #define DUK_ERR_ERROR 100 /* Error */
  2948. #define DUK_ERR_EVAL_ERROR 101 /* EvalError */
  2949. #define DUK_ERR_RANGE_ERROR 102 /* RangeError */
  2950. #define DUK_ERR_REFERENCE_ERROR 103 /* ReferenceError */
  2951. #define DUK_ERR_SYNTAX_ERROR 104 /* SyntaxError */
  2952. #define DUK_ERR_TYPE_ERROR 105 /* TypeError */
  2953. #define DUK_ERR_URI_ERROR 106 /* URIError */
  2954. /* Return codes for C functions (shortcut for throwing an error) */
  2955. #define DUK_RET_UNIMPLEMENTED_ERROR (-DUK_ERR_UNIMPLEMENTED_ERROR)
  2956. #define DUK_RET_UNSUPPORTED_ERROR (-DUK_ERR_UNSUPPORTED_ERROR)
  2957. #define DUK_RET_INTERNAL_ERROR (-DUK_ERR_INTERNAL_ERROR)
  2958. #define DUK_RET_ALLOC_ERROR (-DUK_ERR_ALLOC_ERROR)
  2959. #define DUK_RET_ASSERTION_ERROR (-DUK_ERR_ASSERTION_ERROR)
  2960. #define DUK_RET_API_ERROR (-DUK_ERR_API_ERROR)
  2961. #define DUK_RET_UNCAUGHT_ERROR (-DUK_ERR_UNCAUGHT_ERROR)
  2962. #define DUK_RET_ERROR (-DUK_ERR_ERROR)
  2963. #define DUK_RET_EVAL_ERROR (-DUK_ERR_EVAL_ERROR)
  2964. #define DUK_RET_RANGE_ERROR (-DUK_ERR_RANGE_ERROR)
  2965. #define DUK_RET_REFERENCE_ERROR (-DUK_ERR_REFERENCE_ERROR)
  2966. #define DUK_RET_SYNTAX_ERROR (-DUK_ERR_SYNTAX_ERROR)
  2967. #define DUK_RET_TYPE_ERROR (-DUK_ERR_TYPE_ERROR)
  2968. #define DUK_RET_URI_ERROR (-DUK_ERR_URI_ERROR)
  2969. /* Return codes for protected calls (duk_safe_call(), duk_pcall()). */
  2970. #define DUK_EXEC_SUCCESS 0
  2971. #define DUK_EXEC_ERROR 1
  2972. /* Log levels */
  2973. #define DUK_LOG_TRACE 0
  2974. #define DUK_LOG_DEBUG 1
  2975. #define DUK_LOG_INFO 2
  2976. #define DUK_LOG_WARN 3
  2977. #define DUK_LOG_ERROR 4
  2978. #define DUK_LOG_FATAL 5
  2979. /*
  2980. * If no variadic macros, __FILE__ and __LINE__ are passed through globals
  2981. * which is ugly and not thread safe.
  2982. */
  2983. #ifndef DUK_API_VARIADIC_MACROS
  2984. DUK_EXTERNAL_DECL const char *duk_api_global_filename;
  2985. DUK_EXTERNAL_DECL duk_int_t duk_api_global_line;
  2986. #endif
  2987. /*
  2988. * Context management
  2989. */
  2990. DUK_EXTERNAL_DECL
  2991. duk_context *duk_create_heap(duk_alloc_function alloc_func,
  2992. duk_realloc_function realloc_func,
  2993. duk_free_function free_func,
  2994. void *heap_udata,
  2995. duk_fatal_function fatal_handler);
  2996. DUK_EXTERNAL_DECL void duk_destroy_heap(duk_context *ctx);
  2997. #define duk_create_heap_default() \
  2998. duk_create_heap(NULL, NULL, NULL, NULL, NULL)
  2999. /*
  3000. * Memory management
  3001. *
  3002. * Raw functions have no side effects (cannot trigger GC).
  3003. */
  3004. DUK_EXTERNAL_DECL void *duk_alloc_raw(duk_context *ctx, duk_size_t size);
  3005. DUK_EXTERNAL_DECL void duk_free_raw(duk_context *ctx, void *ptr);
  3006. DUK_EXTERNAL_DECL void *duk_realloc_raw(duk_context *ctx, void *ptr, duk_size_t size);
  3007. DUK_EXTERNAL_DECL void *duk_alloc(duk_context *ctx, duk_size_t size);
  3008. DUK_EXTERNAL_DECL void duk_free(duk_context *ctx, void *ptr);
  3009. DUK_EXTERNAL_DECL void *duk_realloc(duk_context *ctx, void *ptr, duk_size_t size);
  3010. DUK_EXTERNAL_DECL void duk_get_memory_functions(duk_context *ctx, duk_memory_functions *out_funcs);
  3011. DUK_EXTERNAL_DECL void duk_gc(duk_context *ctx, duk_uint_t flags);
  3012. /*
  3013. * Error handling
  3014. */
  3015. DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_throw(duk_context *ctx));
  3016. DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_fatal(duk_context *ctx, duk_errcode_t err_code, const char *err_msg));
  3017. DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_error_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...));
  3018. #ifdef DUK_API_VARIADIC_MACROS
  3019. #define duk_error(ctx,err_code,...) \
  3020. duk_error_raw((ctx), (duk_errcode_t) (err_code), (const char *) (__FILE__), (duk_int_t) (__LINE__), __VA_ARGS__)
  3021. #else
  3022. DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_error_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...));
  3023. /* One problem with this macro is that expressions like the following fail
  3024. * to compile: "(void) duk_error(...)". But because duk_error() is noreturn,
  3025. * they make little sense anyway.
  3026. */
  3027. #define duk_error \
  3028. (duk_api_global_filename = (const char *) (__FILE__), \
  3029. duk_api_global_line = (duk_int_t) (__LINE__), \
  3030. duk_error_stash) /* last value is func pointer, arguments follow in parens */
  3031. #endif
  3032. DUK_API_NORETURN(DUK_EXTERNAL_DECL void duk_error_va_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap));
  3033. #define duk_error_va(ctx,err_code,fmt,ap) \
  3034. duk_error_va_raw((ctx), (duk_errcode_t) (err_code), (const char *) (__FILE__), (duk_int_t) (__LINE__), (fmt), (ap))
  3035. /*
  3036. * Other state related functions
  3037. */
  3038. DUK_EXTERNAL_DECL duk_bool_t duk_is_strict_call(duk_context *ctx);
  3039. DUK_EXTERNAL_DECL duk_bool_t duk_is_constructor_call(duk_context *ctx);
  3040. /*
  3041. * Stack management
  3042. */
  3043. DUK_EXTERNAL_DECL duk_idx_t duk_normalize_index(duk_context *ctx, duk_idx_t index);
  3044. DUK_EXTERNAL_DECL duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t index);
  3045. DUK_EXTERNAL_DECL duk_bool_t duk_is_valid_index(duk_context *ctx, duk_idx_t index);
  3046. DUK_EXTERNAL_DECL void duk_require_valid_index(duk_context *ctx, duk_idx_t index);
  3047. DUK_EXTERNAL_DECL duk_idx_t duk_get_top(duk_context *ctx);
  3048. DUK_EXTERNAL_DECL void duk_set_top(duk_context *ctx, duk_idx_t index);
  3049. DUK_EXTERNAL_DECL duk_idx_t duk_get_top_index(duk_context *ctx);
  3050. DUK_EXTERNAL_DECL duk_idx_t duk_require_top_index(duk_context *ctx);
  3051. /* Although extra/top could be an unsigned type here, using a signed type
  3052. * makes the API more robust to calling code calculation errors or corner
  3053. * cases (where caller might occasionally come up with negative values).
  3054. * Negative values are treated as zero, which is better than casting them
  3055. * to a large unsigned number. (This principle is used elsewhere in the
  3056. * API too.)
  3057. */
  3058. DUK_EXTERNAL_DECL duk_bool_t duk_check_stack(duk_context *ctx, duk_idx_t extra);
  3059. DUK_EXTERNAL_DECL void duk_require_stack(duk_context *ctx, duk_idx_t extra);
  3060. DUK_EXTERNAL_DECL duk_bool_t duk_check_stack_top(duk_context *ctx, duk_idx_t top);
  3061. DUK_EXTERNAL_DECL void duk_require_stack_top(duk_context *ctx, duk_idx_t top);
  3062. /*
  3063. * Stack manipulation (other than push/pop)
  3064. */
  3065. DUK_EXTERNAL_DECL void duk_swap(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
  3066. DUK_EXTERNAL_DECL void duk_swap_top(duk_context *ctx, duk_idx_t index);
  3067. DUK_EXTERNAL_DECL void duk_dup(duk_context *ctx, duk_idx_t from_index);
  3068. DUK_EXTERNAL_DECL void duk_dup_top(duk_context *ctx);
  3069. DUK_EXTERNAL_DECL void duk_insert(duk_context *ctx, duk_idx_t to_index);
  3070. DUK_EXTERNAL_DECL void duk_replace(duk_context *ctx, duk_idx_t to_index);
  3071. DUK_EXTERNAL_DECL void duk_copy(duk_context *ctx, duk_idx_t from_index, duk_idx_t to_index);
  3072. DUK_EXTERNAL_DECL void duk_remove(duk_context *ctx, duk_idx_t index);
  3073. DUK_EXTERNAL_DECL void duk_xcopymove_raw(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count, duk_bool_t is_copy);
  3074. #define duk_xmove_top(to_ctx,from_ctx,count) \
  3075. duk_xcopymove_raw((to_ctx), (from_ctx), (count), 0 /*is_copy*/)
  3076. #define duk_xcopy_top(to_ctx,from_ctx,count) \
  3077. duk_xcopymove_raw((to_ctx), (from_ctx), (count), 1 /*is_copy*/)
  3078. /*
  3079. * Push operations
  3080. *
  3081. * Push functions return the absolute (relative to bottom of frame)
  3082. * position of the pushed value for convenience.
  3083. *
  3084. * Note: duk_dup() is technically a push.
  3085. */
  3086. DUK_EXTERNAL_DECL void duk_push_undefined(duk_context *ctx);
  3087. DUK_EXTERNAL_DECL void duk_push_null(duk_context *ctx);
  3088. DUK_EXTERNAL_DECL void duk_push_boolean(duk_context *ctx, duk_bool_t val);
  3089. DUK_EXTERNAL_DECL void duk_push_true(duk_context *ctx);
  3090. DUK_EXTERNAL_DECL void duk_push_false(duk_context *ctx);
  3091. DUK_EXTERNAL_DECL void duk_push_number(duk_context *ctx, duk_double_t val);
  3092. DUK_EXTERNAL_DECL void duk_push_nan(duk_context *ctx);
  3093. DUK_EXTERNAL_DECL void duk_push_int(duk_context *ctx, duk_int_t val);
  3094. DUK_EXTERNAL_DECL void duk_push_uint(duk_context *ctx, duk_uint_t val);
  3095. DUK_EXTERNAL_DECL const char *duk_push_string(duk_context *ctx, const char *str);
  3096. DUK_EXTERNAL_DECL const char *duk_push_lstring(duk_context *ctx, const char *str, duk_size_t len);
  3097. DUK_EXTERNAL_DECL void duk_push_pointer(duk_context *ctx, void *p);
  3098. DUK_EXTERNAL_DECL const char *duk_push_sprintf(duk_context *ctx, const char *fmt, ...);
  3099. DUK_EXTERNAL_DECL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va_list ap);
  3100. DUK_EXTERNAL_DECL const char *duk_push_string_file_raw(duk_context *ctx, const char *path, duk_uint_t flags);
  3101. #define duk_push_string_file(ctx,path) \
  3102. duk_push_string_file_raw((ctx), (path), 0)
  3103. DUK_EXTERNAL_DECL void duk_push_this(duk_context *ctx);
  3104. DUK_EXTERNAL_DECL void duk_push_current_function(duk_context *ctx);
  3105. DUK_EXTERNAL_DECL void duk_push_current_thread(duk_context *ctx);
  3106. DUK_EXTERNAL_DECL void duk_push_global_object(duk_context *ctx);
  3107. DUK_EXTERNAL_DECL void duk_push_heap_stash(duk_context *ctx);
  3108. DUK_EXTERNAL_DECL void duk_push_global_stash(duk_context *ctx);
  3109. DUK_EXTERNAL_DECL void duk_push_thread_stash(duk_context *ctx, duk_context *target_ctx);
  3110. DUK_EXTERNAL_DECL duk_idx_t duk_push_object(duk_context *ctx);
  3111. DUK_EXTERNAL_DECL duk_idx_t duk_push_array(duk_context *ctx);
  3112. DUK_EXTERNAL_DECL duk_idx_t duk_push_c_function(duk_context *ctx, duk_c_function func, duk_idx_t nargs);
  3113. DUK_EXTERNAL_DECL duk_idx_t duk_push_c_lightfunc(duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic);
  3114. DUK_EXTERNAL_DECL duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t flags);
  3115. #define duk_push_thread(ctx) \
  3116. duk_push_thread_raw((ctx), 0 /*flags*/)
  3117. #define duk_push_thread_new_globalenv(ctx) \
  3118. duk_push_thread_raw((ctx), DUK_THREAD_NEW_GLOBAL_ENV /*flags*/)
  3119. DUK_EXTERNAL_DECL duk_idx_t duk_push_error_object_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...);
  3120. #ifdef DUK_API_VARIADIC_MACROS
  3121. #define duk_push_error_object(ctx,err_code,...) \
  3122. duk_push_error_object_raw((ctx), (err_code), (const char *) (__FILE__), (duk_int_t) (__LINE__), __VA_ARGS__)
  3123. #else
  3124. DUK_EXTERNAL_DECL duk_idx_t duk_push_error_object_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...);
  3125. /* Note: parentheses are required so that the comma expression works in assignments. */
  3126. #define duk_push_error_object \
  3127. (duk_api_global_filename = (const char *) (__FILE__), \
  3128. duk_api_global_line = (duk_int_t) (__LINE__), \
  3129. duk_push_error_object_stash) /* last value is func pointer, arguments follow in parens */
  3130. #endif
  3131. DUK_EXTERNAL_DECL duk_idx_t duk_push_error_object_va_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap);
  3132. #define duk_push_error_object_va(ctx,err_code,fmt,ap) \
  3133. duk_push_error_object_va_raw((ctx), (err_code), (const char *) (__FILE__), (duk_int_t) (__LINE__), (fmt), (ap))
  3134. #define DUK_BUF_FLAG_DYNAMIC (1 << 0) /* internal flag: dynamic buffer */
  3135. #define DUK_BUF_FLAG_NOZERO (1 << 1) /* internal flag: don't zero allocated buffer */
  3136. DUK_EXTERNAL_DECL void *duk_push_buffer_raw(duk_context *ctx, duk_size_t size, duk_small_uint_t flags);
  3137. #define duk_push_buffer(ctx,size,dynamic) \
  3138. duk_push_buffer_raw((ctx), (size), (dynamic));
  3139. #define duk_push_fixed_buffer(ctx,size) \
  3140. duk_push_buffer_raw((ctx), (size), 0 /*dynamic*/)
  3141. #define duk_push_dynamic_buffer(ctx,size) \
  3142. duk_push_buffer_raw((ctx), (size), 1 /*dynamic*/)
  3143. DUK_EXTERNAL_DECL duk_idx_t duk_push_heapptr(duk_context *ctx, void *ptr);
  3144. /*
  3145. * Pop operations
  3146. */
  3147. DUK_EXTERNAL_DECL void duk_pop(duk_context *ctx);
  3148. DUK_EXTERNAL_DECL void duk_pop_n(duk_context *ctx, duk_idx_t count);
  3149. DUK_EXTERNAL_DECL void duk_pop_2(duk_context *ctx);
  3150. DUK_EXTERNAL_DECL void duk_pop_3(duk_context *ctx);
  3151. /*
  3152. * Type checks
  3153. *
  3154. * duk_is_none(), which would indicate whether index it outside of stack,
  3155. * is not needed; duk_is_valid_index() gives the same information.
  3156. */
  3157. DUK_EXTERNAL_DECL duk_int_t duk_get_type(duk_context *ctx, duk_idx_t index);
  3158. DUK_EXTERNAL_DECL duk_bool_t duk_check_type(duk_context *ctx, duk_idx_t index, duk_int_t type);
  3159. DUK_EXTERNAL_DECL duk_uint_t duk_get_type_mask(duk_context *ctx, duk_idx_t index);
  3160. DUK_EXTERNAL_DECL duk_bool_t duk_check_type_mask(duk_context *ctx, duk_idx_t index, duk_uint_t mask);
  3161. DUK_EXTERNAL_DECL duk_bool_t duk_is_undefined(duk_context *ctx, duk_idx_t index);
  3162. DUK_EXTERNAL_DECL duk_bool_t duk_is_null(duk_context *ctx, duk_idx_t index);
  3163. DUK_EXTERNAL_DECL duk_bool_t duk_is_null_or_undefined(duk_context *ctx, duk_idx_t index);
  3164. DUK_EXTERNAL_DECL duk_bool_t duk_is_boolean(duk_context *ctx, duk_idx_t index);
  3165. DUK_EXTERNAL_DECL duk_bool_t duk_is_number(duk_context *ctx, duk_idx_t index);
  3166. DUK_EXTERNAL_DECL duk_bool_t duk_is_nan(duk_context *ctx, duk_idx_t index);
  3167. DUK_EXTERNAL_DECL duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t index);
  3168. DUK_EXTERNAL_DECL duk_bool_t duk_is_object(duk_context *ctx, duk_idx_t index);
  3169. DUK_EXTERNAL_DECL duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t index);
  3170. DUK_EXTERNAL_DECL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t index);
  3171. DUK_EXTERNAL_DECL duk_bool_t duk_is_lightfunc(duk_context *ctx, duk_idx_t index);
  3172. DUK_EXTERNAL_DECL duk_bool_t duk_is_array(duk_context *ctx, duk_idx_t index);
  3173. DUK_EXTERNAL_DECL duk_bool_t duk_is_function(duk_context *ctx, duk_idx_t index);
  3174. DUK_EXTERNAL_DECL duk_bool_t duk_is_c_function(duk_context *ctx, duk_idx_t index);
  3175. DUK_EXTERNAL_DECL duk_bool_t duk_is_ecmascript_function(duk_context *ctx, duk_idx_t index);
  3176. DUK_EXTERNAL_DECL duk_bool_t duk_is_bound_function(duk_context *ctx, duk_idx_t index);
  3177. DUK_EXTERNAL_DECL duk_bool_t duk_is_thread(duk_context *ctx, duk_idx_t index);
  3178. DUK_EXTERNAL_DECL duk_bool_t duk_is_callable(duk_context *ctx, duk_idx_t index);
  3179. DUK_EXTERNAL_DECL duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t index);
  3180. DUK_EXTERNAL_DECL duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t index);
  3181. DUK_EXTERNAL_DECL duk_bool_t duk_is_primitive(duk_context *ctx, duk_idx_t index);
  3182. #define duk_is_object_coercible(ctx,index) \
  3183. duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_BOOLEAN | \
  3184. DUK_TYPE_MASK_NUMBER | \
  3185. DUK_TYPE_MASK_STRING | \
  3186. DUK_TYPE_MASK_OBJECT | \
  3187. DUK_TYPE_MASK_BUFFER | \
  3188. DUK_TYPE_MASK_POINTER | \
  3189. DUK_TYPE_MASK_LIGHTFUNC)
  3190. DUK_EXTERNAL_DECL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t index);
  3191. #define duk_is_error(ctx,index) \
  3192. (duk_get_error_code((ctx), (index)) != 0)
  3193. /*
  3194. * Get operations: no coercion, returns default value for invalid
  3195. * indices and invalid value types.
  3196. *
  3197. * duk_get_undefined() and duk_get_null() would be pointless and
  3198. * are not included.
  3199. */
  3200. DUK_EXTERNAL_DECL duk_bool_t duk_get_boolean(duk_context *ctx, duk_idx_t index);
  3201. DUK_EXTERNAL_DECL duk_double_t duk_get_number(duk_context *ctx, duk_idx_t index);
  3202. DUK_EXTERNAL_DECL duk_int_t duk_get_int(duk_context *ctx, duk_idx_t index);
  3203. DUK_EXTERNAL_DECL duk_uint_t duk_get_uint(duk_context *ctx, duk_idx_t index);
  3204. DUK_EXTERNAL_DECL const char *duk_get_string(duk_context *ctx, duk_idx_t index);
  3205. DUK_EXTERNAL_DECL const char *duk_get_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
  3206. DUK_EXTERNAL_DECL void *duk_get_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
  3207. DUK_EXTERNAL_DECL void *duk_get_pointer(duk_context *ctx, duk_idx_t index);
  3208. DUK_EXTERNAL_DECL duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t index);
  3209. DUK_EXTERNAL_DECL duk_context *duk_get_context(duk_context *ctx, duk_idx_t index);
  3210. DUK_EXTERNAL_DECL void *duk_get_heapptr(duk_context *ctx, duk_idx_t index);
  3211. DUK_EXTERNAL_DECL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t index);
  3212. /*
  3213. * Require operations: no coercion, throw error if index or type
  3214. * is incorrect. No defaulting.
  3215. */
  3216. #define duk_require_type_mask(ctx,index,mask) \
  3217. ((void) duk_check_type_mask((ctx), (index), (mask) | DUK_TYPE_MASK_THROW))
  3218. DUK_EXTERNAL_DECL void duk_require_undefined(duk_context *ctx, duk_idx_t index);
  3219. DUK_EXTERNAL_DECL void duk_require_null(duk_context *ctx, duk_idx_t index);
  3220. DUK_EXTERNAL_DECL duk_bool_t duk_require_boolean(duk_context *ctx, duk_idx_t index);
  3221. DUK_EXTERNAL_DECL duk_double_t duk_require_number(duk_context *ctx, duk_idx_t index);
  3222. DUK_EXTERNAL_DECL duk_int_t duk_require_int(duk_context *ctx, duk_idx_t index);
  3223. DUK_EXTERNAL_DECL duk_uint_t duk_require_uint(duk_context *ctx, duk_idx_t index);
  3224. DUK_EXTERNAL_DECL const char *duk_require_string(duk_context *ctx, duk_idx_t index);
  3225. DUK_EXTERNAL_DECL const char *duk_require_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
  3226. DUK_EXTERNAL_DECL void *duk_require_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
  3227. DUK_EXTERNAL_DECL void *duk_require_pointer(duk_context *ctx, duk_idx_t index);
  3228. DUK_EXTERNAL_DECL duk_c_function duk_require_c_function(duk_context *ctx, duk_idx_t index);
  3229. DUK_EXTERNAL_DECL duk_context *duk_require_context(duk_context *ctx, duk_idx_t index);
  3230. DUK_EXTERNAL_DECL void *duk_require_heapptr(duk_context *ctx, duk_idx_t index);
  3231. #define duk_require_object_coercible(ctx,index) \
  3232. ((void) duk_check_type_mask((ctx), (index), DUK_TYPE_MASK_BOOLEAN | \
  3233. DUK_TYPE_MASK_NUMBER | \
  3234. DUK_TYPE_MASK_STRING | \
  3235. DUK_TYPE_MASK_OBJECT | \
  3236. DUK_TYPE_MASK_BUFFER | \
  3237. DUK_TYPE_MASK_POINTER | \
  3238. DUK_TYPE_MASK_LIGHTFUNC | \
  3239. DUK_TYPE_MASK_THROW))
  3240. /*
  3241. * Coercion operations: in-place coercion, return coerced value where
  3242. * applicable. If index is invalid, throw error. Some coercions may
  3243. * throw an expected error (e.g. from a toString() or valueOf() call)
  3244. * or an internal error (e.g. from out of memory).
  3245. */
  3246. DUK_EXTERNAL_DECL void duk_to_undefined(duk_context *ctx, duk_idx_t index);
  3247. DUK_EXTERNAL_DECL void duk_to_null(duk_context *ctx, duk_idx_t index);
  3248. DUK_EXTERNAL_DECL duk_bool_t duk_to_boolean(duk_context *ctx, duk_idx_t index);
  3249. DUK_EXTERNAL_DECL duk_double_t duk_to_number(duk_context *ctx, duk_idx_t index);
  3250. DUK_EXTERNAL_DECL duk_int_t duk_to_int(duk_context *ctx, duk_idx_t index);
  3251. DUK_EXTERNAL_DECL duk_uint_t duk_to_uint(duk_context *ctx, duk_idx_t index);
  3252. DUK_EXTERNAL_DECL duk_int32_t duk_to_int32(duk_context *ctx, duk_idx_t index);
  3253. DUK_EXTERNAL_DECL duk_uint32_t duk_to_uint32(duk_context *ctx, duk_idx_t index);
  3254. DUK_EXTERNAL_DECL duk_uint16_t duk_to_uint16(duk_context *ctx, duk_idx_t index);
  3255. DUK_EXTERNAL_DECL const char *duk_to_string(duk_context *ctx, duk_idx_t index);
  3256. DUK_EXTERNAL_DECL const char *duk_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
  3257. DUK_EXTERNAL_DECL void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_uint_t flags);
  3258. DUK_EXTERNAL_DECL void *duk_to_pointer(duk_context *ctx, duk_idx_t index);
  3259. DUK_EXTERNAL_DECL void duk_to_object(duk_context *ctx, duk_idx_t index);
  3260. DUK_EXTERNAL_DECL void duk_to_defaultvalue(duk_context *ctx, duk_idx_t index, duk_int_t hint);
  3261. DUK_EXTERNAL_DECL void duk_to_primitive(duk_context *ctx, duk_idx_t index, duk_int_t hint);
  3262. #define DUK_BUF_MODE_FIXED 0 /* internal: request fixed buffer result */
  3263. #define DUK_BUF_MODE_DYNAMIC 1 /* internal: request dynamic buffer result */
  3264. #define DUK_BUF_MODE_DONTCARE 2 /* internal: don't care about fixed/dynamic nature */
  3265. #define duk_to_buffer(ctx,index,out_size) \
  3266. duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_DONTCARE)
  3267. #define duk_to_fixed_buffer(ctx,index,out_size) \
  3268. duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_FIXED)
  3269. #define duk_to_dynamic_buffer(ctx,index,out_size) \
  3270. duk_to_buffer_raw((ctx), (index), (out_size), DUK_BUF_MODE_DYNAMIC)
  3271. /* safe variants of a few coercion operations */
  3272. DUK_EXTERNAL_DECL const char *duk_safe_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
  3273. #define duk_safe_to_string(ctx,index) \
  3274. duk_safe_to_lstring((ctx), (index), NULL)
  3275. /*
  3276. * Misc conversion
  3277. */
  3278. DUK_EXTERNAL_DECL const char *duk_base64_encode(duk_context *ctx, duk_idx_t index);
  3279. DUK_EXTERNAL_DECL void duk_base64_decode(duk_context *ctx, duk_idx_t index);
  3280. DUK_EXTERNAL_DECL const char *duk_hex_encode(duk_context *ctx, duk_idx_t index);
  3281. DUK_EXTERNAL_DECL void duk_hex_decode(duk_context *ctx, duk_idx_t index);
  3282. DUK_EXTERNAL_DECL const char *duk_json_encode(duk_context *ctx, duk_idx_t index);
  3283. DUK_EXTERNAL_DECL void duk_json_decode(duk_context *ctx, duk_idx_t index);
  3284. /*
  3285. * Buffer
  3286. */
  3287. DUK_EXTERNAL_DECL void *duk_resize_buffer(duk_context *ctx, duk_idx_t index, duk_size_t new_size);
  3288. /*
  3289. * Property access
  3290. *
  3291. * The basic function assumes key is on stack. The _string variant takes
  3292. * a C string as a property name, while the _index variant takes an array
  3293. * index as a property name (e.g. 123 is equivalent to the key "123").
  3294. */
  3295. DUK_EXTERNAL_DECL duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_index);
  3296. DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
  3297. DUK_EXTERNAL_DECL duk_bool_t duk_get_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
  3298. DUK_EXTERNAL_DECL duk_bool_t duk_put_prop(duk_context *ctx, duk_idx_t obj_index);
  3299. DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
  3300. DUK_EXTERNAL_DECL duk_bool_t duk_put_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
  3301. DUK_EXTERNAL_DECL duk_bool_t duk_del_prop(duk_context *ctx, duk_idx_t obj_index);
  3302. DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
  3303. DUK_EXTERNAL_DECL duk_bool_t duk_del_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
  3304. DUK_EXTERNAL_DECL duk_bool_t duk_has_prop(duk_context *ctx, duk_idx_t obj_index);
  3305. DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key);
  3306. DUK_EXTERNAL_DECL duk_bool_t duk_has_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
  3307. DUK_EXTERNAL_DECL void duk_def_prop(duk_context *ctx, duk_idx_t obj_index, duk_uint_t flags);
  3308. DUK_EXTERNAL_DECL duk_bool_t duk_get_global_string(duk_context *ctx, const char *key);
  3309. DUK_EXTERNAL_DECL duk_bool_t duk_put_global_string(duk_context *ctx, const char *key);
  3310. /*
  3311. * Object prototype
  3312. */
  3313. DUK_EXTERNAL_DECL void duk_get_prototype(duk_context *ctx, duk_idx_t index);
  3314. DUK_EXTERNAL_DECL void duk_set_prototype(duk_context *ctx, duk_idx_t index);
  3315. /*
  3316. * Object finalizer
  3317. */
  3318. DUK_EXTERNAL_DECL void duk_get_finalizer(duk_context *ctx, duk_idx_t index);
  3319. DUK_EXTERNAL_DECL void duk_set_finalizer(duk_context *ctx, duk_idx_t index);
  3320. /*
  3321. * Global object
  3322. */
  3323. DUK_EXTERNAL_DECL void duk_set_global_object(duk_context *ctx);
  3324. /*
  3325. * Duktape/C function magic value
  3326. */
  3327. DUK_EXTERNAL_DECL duk_int_t duk_get_magic(duk_context *ctx, duk_idx_t index);
  3328. DUK_EXTERNAL_DECL void duk_set_magic(duk_context *ctx, duk_idx_t index, duk_int_t magic);
  3329. DUK_EXTERNAL_DECL duk_int_t duk_get_current_magic(duk_context *ctx);
  3330. /*
  3331. * Module helpers: put multiple function or constant properties
  3332. */
  3333. DUK_EXTERNAL_DECL void duk_put_function_list(duk_context *ctx, duk_idx_t obj_index, const duk_function_list_entry *funcs);
  3334. DUK_EXTERNAL_DECL void duk_put_number_list(duk_context *ctx, duk_idx_t obj_index, const duk_number_list_entry *numbers);
  3335. /*
  3336. * Variable access
  3337. */
  3338. /* XXX: These calls are incomplete and not usable now. They are not (yet)
  3339. * part of the public API.
  3340. */
  3341. DUK_EXTERNAL_DECL void duk_get_var(duk_context *ctx);
  3342. DUK_EXTERNAL_DECL void duk_put_var(duk_context *ctx);
  3343. DUK_EXTERNAL_DECL duk_bool_t duk_del_var(duk_context *ctx);
  3344. DUK_EXTERNAL_DECL duk_bool_t duk_has_var(duk_context *ctx);
  3345. /*
  3346. * Object operations
  3347. */
  3348. DUK_EXTERNAL_DECL void duk_compact(duk_context *ctx, duk_idx_t obj_index);
  3349. DUK_EXTERNAL_DECL void duk_enum(duk_context *ctx, duk_idx_t obj_index, duk_uint_t enum_flags);
  3350. DUK_EXTERNAL_DECL duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_index, duk_bool_t get_value);
  3351. /*
  3352. * String manipulation
  3353. */
  3354. DUK_EXTERNAL_DECL void duk_concat(duk_context *ctx, duk_idx_t count);
  3355. DUK_EXTERNAL_DECL void duk_join(duk_context *ctx, duk_idx_t count);
  3356. DUK_EXTERNAL_DECL void duk_decode_string(duk_context *ctx, duk_idx_t index, duk_decode_char_function callback, void *udata);
  3357. DUK_EXTERNAL_DECL void duk_map_string(duk_context *ctx, duk_idx_t index, duk_map_char_function callback, void *udata);
  3358. DUK_EXTERNAL_DECL void duk_substring(duk_context *ctx, duk_idx_t index, duk_size_t start_char_offset, duk_size_t end_char_offset);
  3359. DUK_EXTERNAL_DECL void duk_trim(duk_context *ctx, duk_idx_t index);
  3360. DUK_EXTERNAL_DECL duk_codepoint_t duk_char_code_at(duk_context *ctx, duk_idx_t index, duk_size_t char_offset);
  3361. /*
  3362. * Ecmascript operators
  3363. */
  3364. DUK_EXTERNAL_DECL duk_bool_t duk_equals(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
  3365. DUK_EXTERNAL_DECL duk_bool_t duk_strict_equals(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
  3366. /*
  3367. * Function (method) calls
  3368. */
  3369. DUK_EXTERNAL_DECL void duk_call(duk_context *ctx, duk_idx_t nargs);
  3370. DUK_EXTERNAL_DECL void duk_call_method(duk_context *ctx, duk_idx_t nargs);
  3371. DUK_EXTERNAL_DECL void duk_call_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs);
  3372. DUK_EXTERNAL_DECL duk_int_t duk_pcall(duk_context *ctx, duk_idx_t nargs);
  3373. DUK_EXTERNAL_DECL duk_int_t duk_pcall_method(duk_context *ctx, duk_idx_t nargs);
  3374. DUK_EXTERNAL_DECL duk_int_t duk_pcall_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs);
  3375. DUK_EXTERNAL_DECL void duk_new(duk_context *ctx, duk_idx_t nargs);
  3376. DUK_EXTERNAL_DECL duk_int_t duk_safe_call(duk_context *ctx, duk_safe_call_function func, duk_idx_t nargs, duk_idx_t nrets);
  3377. /*
  3378. * Thread management
  3379. */
  3380. /* There are currently no native functions to yield/resume, due to the internal
  3381. * limitations on coroutine handling. These will be added later.
  3382. */
  3383. /*
  3384. * Compilation and evaluation
  3385. */
  3386. DUK_EXTERNAL_DECL duk_int_t duk_eval_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags);
  3387. DUK_EXTERNAL_DECL duk_int_t duk_compile_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags);
  3388. /* plain */
  3389. #define duk_eval(ctx) \
  3390. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3391. (void) duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL))
  3392. #define duk_eval_noresult(ctx) \
  3393. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3394. (void) duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT))
  3395. #define duk_peval(ctx) \
  3396. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3397. duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE))
  3398. #define duk_peval_noresult(ctx) \
  3399. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3400. duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT))
  3401. #define duk_compile(ctx,flags) \
  3402. ((void) duk_compile_raw((ctx), NULL, 0, (flags)))
  3403. #define duk_pcompile(ctx,flags) \
  3404. (duk_compile_raw((ctx), NULL, 0, (flags) | DUK_COMPILE_SAFE))
  3405. /* string */
  3406. #define duk_eval_string(ctx,src) \
  3407. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3408. (void) duk_eval_raw((ctx), (src), 0, DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
  3409. #define duk_eval_string_noresult(ctx,src) \
  3410. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3411. (void) duk_eval_raw((ctx), (src), 0, DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT))
  3412. #define duk_peval_string(ctx,src) \
  3413. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3414. duk_eval_raw((ctx), (src), 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
  3415. #define duk_peval_string_noresult(ctx,src) \
  3416. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3417. duk_eval_raw((ctx), (src), 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NORESULT))
  3418. #define duk_compile_string(ctx,flags,src) \
  3419. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3420. (void) duk_compile_raw((ctx), (src), 0, (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
  3421. #define duk_compile_string_filename(ctx,flags,src) \
  3422. ((void) duk_compile_raw((ctx), (src), 0, (flags) | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
  3423. #define duk_pcompile_string(ctx,flags,src) \
  3424. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3425. duk_compile_raw((ctx), (src), 0, (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
  3426. #define duk_pcompile_string_filename(ctx,flags,src) \
  3427. (duk_compile_raw((ctx), (src), 0, (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN))
  3428. /* lstring */
  3429. #define duk_eval_lstring(ctx,buf,len) \
  3430. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3431. (void) duk_eval_raw((ctx), buf, len, DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE))
  3432. #define duk_eval_lstring_noresult(ctx,buf,len) \
  3433. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3434. (void) duk_eval_raw((ctx), buf, len, DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT))
  3435. #define duk_peval_lstring(ctx,buf,len) \
  3436. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3437. duk_eval_raw((ctx), buf, len, DUK_COMPILE_EVAL | DUK_COMPILE_NOSOURCE | DUK_COMPILE_SAFE))
  3438. #define duk_peval_lstring_noresult(ctx,buf,len) \
  3439. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3440. duk_eval_raw((ctx), buf, len, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_NORESULT))
  3441. #define duk_compile_lstring(ctx,flags,buf,len) \
  3442. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3443. (void) duk_compile_raw((ctx), buf, len, (flags) | DUK_COMPILE_NOSOURCE))
  3444. #define duk_compile_lstring_filename(ctx,flags,buf,len) \
  3445. ((void) duk_compile_raw((ctx), buf, len, (flags) | DUK_COMPILE_NOSOURCE))
  3446. #define duk_pcompile_lstring(ctx,flags,buf,len) \
  3447. ((void) duk_push_string((ctx), (const char *) (__FILE__)), \
  3448. duk_compile_raw((ctx), buf, len, (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE))
  3449. #define duk_pcompile_lstring_filename(ctx,flags,buf,len) \
  3450. (duk_compile_raw((ctx), buf, len, (flags) | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE))
  3451. /* file */
  3452. #define duk_eval_file(ctx,path) \
  3453. ((void) duk_push_string_file_raw((ctx), (path), 0), \
  3454. (void) duk_push_string((ctx), (path)), \
  3455. (void) duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL))
  3456. #define duk_eval_file_noresult(ctx,path) \
  3457. ((void) duk_push_string_file_raw((ctx), (path), 0), \
  3458. (void) duk_push_string((ctx), (path)), \
  3459. (void) duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_NORESULT))
  3460. #define duk_peval_file(ctx,path) \
  3461. ((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
  3462. (void) duk_push_string((ctx), (path)), \
  3463. duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE))
  3464. #define duk_peval_file_noresult(ctx,path) \
  3465. ((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
  3466. (void) duk_push_string((ctx), (path)), \
  3467. duk_eval_raw((ctx), NULL, 0, DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NORESULT))
  3468. #define duk_compile_file(ctx,flags,path) \
  3469. ((void) duk_push_string_file_raw((ctx), (path), 0), \
  3470. (void) duk_push_string((ctx), (path)), \
  3471. (void) duk_compile_raw((ctx), NULL, 0, (flags)))
  3472. #define duk_pcompile_file(ctx,flags,path) \
  3473. ((void) duk_push_string_file_raw((ctx), (path), DUK_STRING_PUSH_SAFE), \
  3474. (void) duk_push_string((ctx), (path)), \
  3475. duk_compile_raw((ctx), NULL, 0, (flags) | DUK_COMPILE_SAFE))
  3476. /*
  3477. * Logging
  3478. */
  3479. DUK_EXTERNAL_DECL void duk_log(duk_context *ctx, duk_int_t level, const char *fmt, ...);
  3480. DUK_EXTERNAL_DECL void duk_log_va(duk_context *ctx, duk_int_t level, const char *fmt, va_list ap);
  3481. /*
  3482. * Debugging
  3483. */
  3484. DUK_EXTERNAL_DECL void duk_push_context_dump(duk_context *ctx);
  3485. #if defined(DUK_USE_FILE_IO)
  3486. /* internal use */
  3487. #define duk_dump_context_filehandle(ctx,fh) \
  3488. (duk_push_context_dump((ctx)), \
  3489. DUK_FPRINTF((fh), "%s\n", duk_safe_to_string(ctx, -1)), \
  3490. duk_pop(ctx))
  3491. /* external use */
  3492. #define duk_dump_context_stdout(ctx) \
  3493. duk_dump_context_filehandle((ctx), DUK_STDOUT)
  3494. #define duk_dump_context_stderr(ctx) \
  3495. duk_dump_context_filehandle((ctx), DUK_STDERR)
  3496. #else /* DUK_USE_FILE_IO */
  3497. #define duk_dump_context_stdout(ctx) ((void) 0)
  3498. #define duk_dump_context_stderr(ctx) ((void) 0)
  3499. #endif /* DUK_USE_FILE_IO */
  3500. /*
  3501. * Debugger (debug protocol)
  3502. */
  3503. DUK_EXTERNAL_DECL void duk_debugger_attach(duk_context *ctx,
  3504. duk_debug_read_function read_cb,
  3505. duk_debug_write_function write_cb,
  3506. duk_debug_peek_function peek_cb,
  3507. duk_debug_read_flush_function read_flush_cb,
  3508. duk_debug_write_flush_function write_flush_cb,
  3509. duk_debug_detached_function detached_cb,
  3510. void *udata);
  3511. DUK_EXTERNAL_DECL void duk_debugger_detach(duk_context *ctx);
  3512. DUK_EXTERNAL_DECL void duk_debugger_cooperate(duk_context *ctx);
  3513. /*
  3514. * C++ name mangling
  3515. */
  3516. #ifdef __cplusplus
  3517. /* end 'extern "C"' wrapper */
  3518. }
  3519. #endif
  3520. #endif /* DUK_API_PUBLIC_H_INCLUDED */
  3521. /*
  3522. * END PUBLIC API
  3523. */
  3524. /*
  3525. * Sanity check for the final effective internal defines. This file also
  3526. * double checks user tweaks made by an optional duk_custom.h header.
  3527. */
  3528. #ifndef DUK_FEATURES_SANITY_H_INCLUDED
  3529. #define DUK_FEATURES_SANITY_H_INCLUDED
  3530. /*
  3531. * Deprecated feature options.
  3532. *
  3533. * Catch so that user more easily notices and updates build.
  3534. */
  3535. #if defined(DUK_OPT_NO_FUNC_STMT)
  3536. #error DUK_OPT_NO_FUNC_STMT is deprecated, use DUK_OPT_NO_NONSTD_FUNC_STMT
  3537. #endif
  3538. #if defined(DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY)
  3539. #error DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY is deprecated, use DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY
  3540. #endif
  3541. #if defined(DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY)
  3542. #error DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY is deprecated, use DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY
  3543. #endif
  3544. #if defined(DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT)
  3545. #error DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT is deprecated, use DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT
  3546. #endif
  3547. #if defined(DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY)
  3548. #error DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY is deprecated, use DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY
  3549. #endif
  3550. #if defined(DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF)
  3551. #error DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF is deprecated, use DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF
  3552. #endif
  3553. #if defined(DUK_OPT_NO_JSONX)
  3554. #error DUK_OPT_NO_JSONX is deprecated, use DUK_OPT_NO_JX
  3555. #endif
  3556. #if defined(DUK_OPT_NO_JSONC)
  3557. #error DUK_OPT_NO_JSONC is deprecated, use DUK_OPT_NO_JC
  3558. #endif
  3559. /*
  3560. * Debug print consistency
  3561. */
  3562. #if defined(DUK_USE_DPRINT) && !defined(DUK_USE_DEBUG)
  3563. #error DUK_USE_DPRINT without DUK_USE_DEBUG
  3564. #endif
  3565. #if defined(DUK_USE_DDPRINT) && !defined(DUK_USE_DEBUG)
  3566. #error DUK_USE_DDPRINT without DUK_USE_DEBUG
  3567. #endif
  3568. #if defined(DUK_USE_DDDPRINT) && !defined(DUK_USE_DEBUG)
  3569. #error DUK_USE_DDDPRINT without DUK_USE_DEBUG
  3570. #endif
  3571. #if defined(DUK_USE_HEAPPTR16) && defined(DUK_USE_DEBUG)
  3572. /* Debug code doesn't have access to 'heap' so it cannot decode pointers. */
  3573. #error debug printing cannot currently be used with heap pointer compression
  3574. #endif
  3575. /*
  3576. * Debugger consistency
  3577. */
  3578. #if defined(DUK_USE_DEBUGGER_SUPPORT)
  3579. #if !defined(DUK_USE_INTERRUPT_COUNTER)
  3580. #error DUK_USE_INTERRUPT_COUNTER is needed when debugger support is enabled
  3581. #endif
  3582. #if !defined(DUK_USE_PC2LINE)
  3583. #error DUK_USE_PC2LINE is needed when debugger support is enabled
  3584. #endif
  3585. #endif
  3586. /*
  3587. * Garbage collection consistency
  3588. */
  3589. #if defined(DUK_USE_REFERENCE_COUNTING) && !defined(DUK_USE_DOUBLE_LINKED_HEAP)
  3590. #error DUK_USE_REFERENCE_COUNTING defined without DUK_USE_DOUBLE_LINKED_HEAP
  3591. #endif
  3592. #if defined(DUK_USE_GC_TORTURE) && !defined(DUK_USE_MARK_AND_SWEEP)
  3593. #error DUK_USE_GC_TORTURE defined without DUK_USE_MARK_AND_SWEEP
  3594. #endif
  3595. /*
  3596. * Low memory feature consistency
  3597. */
  3598. #if defined(DUK_USE_OBJSIZES16)
  3599. #if defined(DUK_USE_HOBJECT_HASH_PART)
  3600. #error DUK_USE_OBJSIZES16 assumes DUK_USE_HOBJECT_HASH_PART is not defined
  3601. #endif
  3602. #endif
  3603. #if defined(DUK_USE_STRTAB_CHAIN) && defined(DUK_USE_STRTAB_PROBE)
  3604. #error both DUK_USE_STRTAB_CHAIN and DUK_USE_STRTAB_PROBE defined
  3605. #endif
  3606. #if !defined(DUK_USE_STRTAB_CHAIN) && !defined(DUK_USE_STRTAB_PROBE)
  3607. #error neither DUK_USE_STRTAB_CHAIN nor DUK_USE_STRTAB_PROBE is defined
  3608. #endif
  3609. #endif /* DUK_FEATURES_SANITY_H_INCLUDED */
  3610. /*
  3611. * Union to access IEEE double memory representation, indexes for double
  3612. * memory representation, and some macros for double manipulation.
  3613. *
  3614. * Also used by packed duk_tval. Use a union for bit manipulation to
  3615. * minimize aliasing issues in practice. The C99 standard does not
  3616. * guarantee that this should work, but it's a very widely supported
  3617. * practice for low level manipulation.
  3618. *
  3619. * IEEE double format summary:
  3620. *
  3621. * seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
  3622. * A B C D E F G H
  3623. *
  3624. * s sign bit
  3625. * eee... exponent field
  3626. * fff... fraction
  3627. *
  3628. * See http://en.wikipedia.org/wiki/Double_precision_floating-point_format.
  3629. *
  3630. * NaNs are represented as exponent 0x7ff and mantissa != 0. The NaN is a
  3631. * signaling NaN when the highest bit of the mantissa is zero, and a quiet
  3632. * NaN when the highest bit is set.
  3633. *
  3634. * At least three memory layouts are relevant here:
  3635. *
  3636. * A B C D E F G H Big endian (e.g. 68k) DUK_USE_DOUBLE_BE
  3637. * H G F E D C B A Little endian (e.g. x86) DUK_USE_DOUBLE_LE
  3638. * D C B A H G F E Mixed/cross endian (e.g. ARM) DUK_USE_DOUBLE_ME
  3639. *
  3640. * ARM is a special case: ARM double values are in mixed/cross endian
  3641. * format while ARM duk_uint64_t values are in standard little endian
  3642. * format (H G F E D C B A). When a double is read as a duk_uint64_t
  3643. * from memory, the register will contain the (logical) value
  3644. * E F G H A B C D. This requires some special handling below.
  3645. *
  3646. * Indexes of various types (8-bit, 16-bit, 32-bit) in memory relative to
  3647. * the logical (big endian) order:
  3648. *
  3649. * byte order duk_uint8_t duk_uint16_t duk_uint32_t
  3650. * BE 01234567 0123 01
  3651. * LE 76543210 3210 10
  3652. * ME (ARM) 32107654 1032 01
  3653. *
  3654. * Some processors may alter NaN values in a floating point load+store.
  3655. * For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
  3656. * quiet one. This is catastrophic when NaN space is used in packed
  3657. * duk_tval values. See: misc/clang_aliasing.c.
  3658. */
  3659. #ifndef DUK_DBLUNION_H_INCLUDED
  3660. #define DUK_DBLUNION_H_INCLUDED
  3661. /*
  3662. * Union for accessing double parts, also serves as packed duk_tval
  3663. */
  3664. union duk_double_union {
  3665. double d;
  3666. #ifdef DUK_USE_64BIT_OPS
  3667. duk_uint64_t ull[1];
  3668. #endif
  3669. duk_uint32_t ui[2];
  3670. duk_uint16_t us[4];
  3671. duk_uint8_t uc[8];
  3672. #ifdef DUK_USE_PACKED_TVAL_POSSIBLE
  3673. void *vp[2]; /* used by packed duk_tval, assumes sizeof(void *) == 4 */
  3674. #endif
  3675. };
  3676. typedef union duk_double_union duk_double_union;
  3677. /*
  3678. * Indexes of various types with respect to big endian (logical) layout
  3679. */
  3680. #if defined(DUK_USE_DOUBLE_LE)
  3681. #ifdef DUK_USE_64BIT_OPS
  3682. #define DUK_DBL_IDX_ULL0 0
  3683. #endif
  3684. #define DUK_DBL_IDX_UI0 1
  3685. #define DUK_DBL_IDX_UI1 0
  3686. #define DUK_DBL_IDX_US0 3
  3687. #define DUK_DBL_IDX_US1 2
  3688. #define DUK_DBL_IDX_US2 1
  3689. #define DUK_DBL_IDX_US3 0
  3690. #define DUK_DBL_IDX_UC0 7
  3691. #define DUK_DBL_IDX_UC1 6
  3692. #define DUK_DBL_IDX_UC2 5
  3693. #define DUK_DBL_IDX_UC3 4
  3694. #define DUK_DBL_IDX_UC4 3
  3695. #define DUK_DBL_IDX_UC5 2
  3696. #define DUK_DBL_IDX_UC6 1
  3697. #define DUK_DBL_IDX_UC7 0
  3698. #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
  3699. #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
  3700. #elif defined(DUK_USE_DOUBLE_BE)
  3701. #ifdef DUK_USE_64BIT_OPS
  3702. #define DUK_DBL_IDX_ULL0 0
  3703. #endif
  3704. #define DUK_DBL_IDX_UI0 0
  3705. #define DUK_DBL_IDX_UI1 1
  3706. #define DUK_DBL_IDX_US0 0
  3707. #define DUK_DBL_IDX_US1 1
  3708. #define DUK_DBL_IDX_US2 2
  3709. #define DUK_DBL_IDX_US3 3
  3710. #define DUK_DBL_IDX_UC0 0
  3711. #define DUK_DBL_IDX_UC1 1
  3712. #define DUK_DBL_IDX_UC2 2
  3713. #define DUK_DBL_IDX_UC3 3
  3714. #define DUK_DBL_IDX_UC4 4
  3715. #define DUK_DBL_IDX_UC5 5
  3716. #define DUK_DBL_IDX_UC6 6
  3717. #define DUK_DBL_IDX_UC7 7
  3718. #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
  3719. #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
  3720. #elif defined(DUK_USE_DOUBLE_ME)
  3721. #ifdef DUK_USE_64BIT_OPS
  3722. #define DUK_DBL_IDX_ULL0 0 /* not directly applicable, byte order differs from a double */
  3723. #endif
  3724. #define DUK_DBL_IDX_UI0 0
  3725. #define DUK_DBL_IDX_UI1 1
  3726. #define DUK_DBL_IDX_US0 1
  3727. #define DUK_DBL_IDX_US1 0
  3728. #define DUK_DBL_IDX_US2 3
  3729. #define DUK_DBL_IDX_US3 2
  3730. #define DUK_DBL_IDX_UC0 3
  3731. #define DUK_DBL_IDX_UC1 2
  3732. #define DUK_DBL_IDX_UC2 1
  3733. #define DUK_DBL_IDX_UC3 0
  3734. #define DUK_DBL_IDX_UC4 7
  3735. #define DUK_DBL_IDX_UC5 6
  3736. #define DUK_DBL_IDX_UC6 5
  3737. #define DUK_DBL_IDX_UC7 4
  3738. #define DUK_DBL_IDX_VP0 DUK_DBL_IDX_UI0 /* packed tval */
  3739. #define DUK_DBL_IDX_VP1 DUK_DBL_IDX_UI1 /* packed tval */
  3740. #else
  3741. #error internal error
  3742. #endif
  3743. /*
  3744. * Helper macros for reading/writing memory representation parts, used
  3745. * by duk_numconv.c and duk_tval.h.
  3746. */
  3747. #define DUK_DBLUNION_SET_DOUBLE(u,v) do { \
  3748. (u)->d = (v); \
  3749. } while (0)
  3750. #define DUK_DBLUNION_SET_HIGH32(u,v) do { \
  3751. (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) (v); \
  3752. } while (0)
  3753. #ifdef DUK_USE_64BIT_OPS
  3754. #ifdef DUK_USE_DOUBLE_ME
  3755. #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
  3756. (u)->ull[DUK_DBL_IDX_ULL0] = (duk_uint64_t) (v); \
  3757. } while (0)
  3758. #else
  3759. #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
  3760. (u)->ull[DUK_DBL_IDX_ULL0] = ((duk_uint64_t) (v)) << 32; \
  3761. } while (0)
  3762. #endif
  3763. #else /* DUK_USE_64BIT_OPS */
  3764. #define DUK_DBLUNION_SET_HIGH32_ZERO_LOW32(u,v) do { \
  3765. (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) (v); \
  3766. (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) 0; \
  3767. } while (0)
  3768. #endif /* DUK_USE_64BIT_OPS */
  3769. #define DUK_DBLUNION_SET_LOW32(u,v) do { \
  3770. (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (v); \
  3771. } while (0)
  3772. #define DUK_DBLUNION_GET_DOUBLE(u) ((u)->d)
  3773. #define DUK_DBLUNION_GET_HIGH32(u) ((u)->ui[DUK_DBL_IDX_UI0])
  3774. #define DUK_DBLUNION_GET_LOW32(u) ((u)->ui[DUK_DBL_IDX_UI1])
  3775. #ifdef DUK_USE_64BIT_OPS
  3776. #ifdef DUK_USE_DOUBLE_ME
  3777. #define DUK_DBLUNION_SET_UINT64(u,v) do { \
  3778. (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) ((v) >> 32); \
  3779. (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) (v); \
  3780. } while (0)
  3781. #define DUK_DBLUNION_GET_UINT64(u) \
  3782. ((((duk_uint64_t) (u)->ui[DUK_DBL_IDX_UI0]) << 32) | \
  3783. ((duk_uint64_t) (u)->ui[DUK_DBL_IDX_UI1]))
  3784. #else
  3785. #define DUK_DBLUNION_SET_UINT64(u,v) do { \
  3786. (u)->ull[DUK_DBL_IDX_ULL0] = (duk_uint64_t) (v); \
  3787. } while (0)
  3788. #define DUK_DBLUNION_GET_UINT64(u) ((u)->ull[DUK_DBL_IDX_ULL0])
  3789. #endif
  3790. #define DUK_DBLUNION_SET_INT64(u,v) DUK_DBLUNION_SET_UINT64((u), (duk_uint64_t) (v))
  3791. #define DUK_DBLUNION_GET_INT64(u) ((duk_int64_t) DUK_DBLUNION_GET_UINT64((u)))
  3792. #endif /* DUK_USE_64BIT_OPS */
  3793. /*
  3794. * Double NaN manipulation macros related to NaN normalization needed when
  3795. * using the packed duk_tval representation. NaN normalization is necessary
  3796. * to keep double values compatible with the duk_tval format.
  3797. *
  3798. * When packed duk_tval is used, the NaN space is used to store pointers
  3799. * and other tagged values in addition to NaNs. Actual NaNs are normalized
  3800. * to a specific format. The macros below are used by the implementation
  3801. * to check and normalize NaN values when they might be created. The macros
  3802. * are essentially NOPs when the non-packed duk_tval representation is used.
  3803. *
  3804. * A FULL check is exact and checks all bits. A NOTFULL check is used by
  3805. * the packed duk_tval and works correctly for all NaNs except those that
  3806. * begin with 0x7ff0. Since the 'normalized NaN' values used with packed
  3807. * duk_tval begin with 0x7ff8, the partial check is reliable when packed
  3808. * duk_tval is used.
  3809. *
  3810. * The ME variant below is specifically for ARM byte order, which has the
  3811. * feature that while doubles have a mixed byte order (32107654), unsigned
  3812. * long long values has a little endian byte order (76543210). When writing
  3813. * a logical double value through a ULL pointer, the 32-bit words need to be
  3814. * swapped; hence the #ifdefs below for ULL writes with DUK_USE_DOUBLE_ME.
  3815. * This is not full ARM support but suffices for some environments.
  3816. */
  3817. #ifdef DUK_USE_64BIT_OPS
  3818. #ifdef DUK_USE_DOUBLE_ME
  3819. #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
  3820. (u)->ull[DUK_DBL_IDX_ULL0] = 0x000000007ff80000ULL; \
  3821. } while (0)
  3822. #else
  3823. #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
  3824. (u)->ull[DUK_DBL_IDX_ULL0] = 0x7ff8000000000000ULL; \
  3825. } while (0)
  3826. #endif
  3827. #else /* DUK_USE_64BIT_OPS */
  3828. #define DUK__DBLUNION_SET_NAN_FULL(u) do { \
  3829. (u)->ui[DUK_DBL_IDX_UI0] = (duk_uint32_t) 0x7ff80000UL; \
  3830. (u)->ui[DUK_DBL_IDX_UI1] = (duk_uint32_t) 0x00000000UL; \
  3831. } while (0)
  3832. #endif /* DUK_USE_64BIT_OPS */
  3833. #define DUK__DBLUNION_SET_NAN_NOTFULL(u) do { \
  3834. (u)->us[DUK_DBL_IDX_US0] = 0x7ff8UL; \
  3835. } while (0)
  3836. #ifdef DUK_USE_64BIT_OPS
  3837. #ifdef DUK_USE_DOUBLE_ME
  3838. #define DUK__DBLUNION_IS_NAN_FULL(u) \
  3839. /* E == 0x7ff, F != 0 => NaN */ \
  3840. ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
  3841. ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0xffffffff000fffffULL) != 0))
  3842. #else
  3843. #define DUK__DBLUNION_IS_NAN_FULL(u) \
  3844. /* E == 0x7ff, F != 0 => NaN */ \
  3845. ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
  3846. ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0x000fffffffffffffULL) != 0))
  3847. #endif
  3848. #else /* DUK_USE_64BIT_OPS */
  3849. #define DUK__DBLUNION_IS_NAN_FULL(u) \
  3850. /* E == 0x7ff, F != 0 => NaN */ \
  3851. ((((u)->ui[DUK_DBL_IDX_UI0] & 0x7ff00000UL) == 0x7ff00000UL) && \
  3852. (((u)->ui[DUK_DBL_IDX_UI0] & 0x000fffffUL) != 0 || \
  3853. (u)->ui[DUK_DBL_IDX_UI1] != 0))
  3854. #endif /* DUK_USE_64BIT_OPS */
  3855. #define DUK__DBLUNION_IS_NAN_NOTFULL(u) \
  3856. /* E == 0x7ff, topmost four bits of F != 0 => assume NaN */ \
  3857. ((((u)->us[DUK_DBL_IDX_US0] & 0x7ff0UL) == 0x7ff0UL) && \
  3858. (((u)->us[DUK_DBL_IDX_US0] & 0x000fUL) != 0x0000UL))
  3859. #ifdef DUK_USE_64BIT_OPS
  3860. #ifdef DUK_USE_DOUBLE_ME
  3861. #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
  3862. ((u)->ull[DUK_DBL_IDX_ULL0] == 0x000000007ff80000ULL)
  3863. #else
  3864. #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
  3865. ((u)->ull[DUK_DBL_IDX_ULL0] == 0x7ff8000000000000ULL)
  3866. #endif
  3867. #else /* DUK_USE_64BIT_OPS */
  3868. #define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
  3869. (((u)->ui[DUK_DBL_IDX_UI0] == 0x7ff80000UL) && \
  3870. ((u)->ui[DUK_DBL_IDX_UI1] == 0x00000000UL))
  3871. #endif /* DUK_USE_64BIT_OPS */
  3872. #define DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL(u) \
  3873. /* E == 0x7ff, F == 8 => normalized NaN */ \
  3874. ((u)->us[DUK_DBL_IDX_US0] == 0x7ff8UL)
  3875. #define DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL(u) do { \
  3876. if (DUK__DBLUNION_IS_NAN_FULL((u))) { \
  3877. DUK__DBLUNION_SET_NAN_FULL((u)); \
  3878. } \
  3879. } while (0)
  3880. #define DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL(u) do { \
  3881. if (DUK__DBLUNION_IS_NAN_NOTFULL((u))) { \
  3882. DUK__DBLUNION_SET_NAN_NOTFULL((u)); \
  3883. } \
  3884. } while (0)
  3885. /* Concrete macros for NaN handling used by the implementation internals.
  3886. * Chosen so that they match the duk_tval representation: with a packed
  3887. * duk_tval, ensure NaNs are properly normalized; with a non-packed duk_tval
  3888. * these are essentially NOPs.
  3889. */
  3890. #if defined(DUK_USE_PACKED_TVAL)
  3891. #if defined(DUK_USE_FULL_TVAL)
  3892. #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_FULL((u))
  3893. #define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_FULL((u))
  3894. #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_FULL((u))
  3895. #define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_FULL((d))
  3896. #else
  3897. #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) DUK__DBLUNION_NORMALIZE_NAN_CHECK_NOTFULL((u))
  3898. #define DUK_DBLUNION_IS_NAN(u) DUK__DBLUNION_IS_NAN_NOTFULL((u))
  3899. #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) DUK__DBLUNION_IS_NORMALIZED_NAN_NOTFULL((u))
  3900. #define DUK_DBLUNION_SET_NAN(d) DUK__DBLUNION_SET_NAN_NOTFULL((d))
  3901. #endif
  3902. #define DUK_DBLUNION_IS_NORMALIZED(u) \
  3903. (!DUK_DBLUNION_IS_NAN((u)) || /* either not a NaN */ \
  3904. DUK_DBLUNION_IS_NORMALIZED_NAN((u))) /* or is a normalized NaN */
  3905. #else /* DUK_USE_PACKED_TVAL */
  3906. #define DUK_DBLUNION_NORMALIZE_NAN_CHECK(u) /* nop: no need to normalize */
  3907. #define DUK_DBLUNION_IS_NAN(u) (DUK_ISNAN((u)->d))
  3908. #define DUK_DBLUNION_IS_NORMALIZED_NAN(u) (DUK_ISNAN((u)->d))
  3909. #define DUK_DBLUNION_IS_NORMALIZED(u) 1 /* all doubles are considered normalized */
  3910. #define DUK_DBLUNION_SET_NAN(u) do { \
  3911. /* in non-packed representation we don't care about which NaN is used */ \
  3912. (u)->d = DUK_DOUBLE_NAN; \
  3913. } while (0)
  3914. #endif /* DUK_USE_PACKED_TVAL */
  3915. /* Byteswap an (aligned) duk_double_union. */
  3916. #if defined(DUK_USE_DOUBLE_LE)
  3917. #define DUK_DBLUNION_BSWAP(u) do { \
  3918. duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
  3919. duk__bswaptmp1 = (u)->ui[0]; \
  3920. duk__bswaptmp2 = (u)->ui[1]; \
  3921. duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
  3922. duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
  3923. (u)->ui[0] = duk__bswaptmp2; \
  3924. (u)->ui[1] = duk__bswaptmp1; \
  3925. } while (0)
  3926. #elif defined(DUK_USE_DOUBLE_ME)
  3927. #define DUK_DBLUNION_BSWAP(u) do { \
  3928. duk_uint32_t duk__bswaptmp1, duk__bswaptmp2; \
  3929. duk__bswaptmp1 = (u)->ui[0]; \
  3930. duk__bswaptmp2 = (u)->ui[1]; \
  3931. duk__bswaptmp1 = DUK_BSWAP32(duk__bswaptmp1); \
  3932. duk__bswaptmp2 = DUK_BSWAP32(duk__bswaptmp2); \
  3933. (u)->ui[0] = duk__bswaptmp1; \
  3934. (u)->ui[1] = duk__bswaptmp2; \
  3935. } while (0)
  3936. #elif defined(DUK_USE_DOUBLE_BE)
  3937. #define DUK_DBLUNION_BSWAP(u) do { } while (0)
  3938. #else
  3939. #error internal error, double endianness insane
  3940. #endif
  3941. #endif /* DUK_DBLUNION_H_INCLUDED */
  3942. #endif /* DUKTAPE_H_INCLUDED */
  3943. // --------------------
  3944. // BEGIN AtomicPlugin.h
  3945. // --------------------
  3946. #ifndef ATOMIC_PLUGIN_H
  3947. #define ATOMIC_PLUGIN_H
  3948. #ifdef _MSC_VER
  3949. #define PLUGIN_EXPORT_API __declspec(dllexport)
  3950. #else
  3951. #define PLUGIN_EXPORT_API
  3952. #endif
  3953. #ifdef ATOMIC_PLUGIN_MAIN
  3954. #define ATOMIC_JSPLUGIN_VERSION 1
  3955. // MUST MATCH JSPlugin.cpp definitions exactly (typedefs and JSVMImports struct)
  3956. extern "C"
  3957. {
  3958. typedef duk_context* (*__duk_create_heap)(duk_alloc_function alloc_func,
  3959. duk_realloc_function realloc_func,
  3960. duk_free_function free_func,
  3961. void *heap_udata,
  3962. duk_fatal_function fatal_handler);
  3963. typedef void(*__duk_destroy_heap)(duk_context *ctx);
  3964. typedef void* (*__duk_alloc_raw)(duk_context *ctx, duk_size_t size);
  3965. typedef void(*__duk_free_raw)(duk_context *ctx, void *ptr);
  3966. typedef void* (*__duk_realloc_raw)(duk_context *ctx, void *ptr, duk_size_t size);
  3967. typedef void* (*__duk_alloc)(duk_context *ctx, duk_size_t size);
  3968. typedef void(*__duk_free)(duk_context *ctx, void *ptr);
  3969. typedef void* (*__duk_realloc)(duk_context *ctx, void *ptr, duk_size_t size);
  3970. typedef void(*__duk_get_memory_functions)(duk_context *ctx, duk_memory_functions *out_funcs);
  3971. typedef void(*__duk_gc)(duk_context *ctx, duk_uint_t flags);
  3972. typedef void(*__duk_throw)(duk_context *ctx);
  3973. typedef void(*__duk_fatal)(duk_context *ctx, duk_errcode_t err_code, const char *err_msg);
  3974. typedef void(*__duk_error_raw)(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...);
  3975. typedef void(*__duk_error_va_raw)(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap);
  3976. typedef duk_bool_t(*__duk_is_strict_call)(duk_context *ctx);
  3977. typedef duk_bool_t(*__duk_is_constructor_call)(duk_context *ctx);
  3978. typedef duk_idx_t(*__duk_normalize_index)(duk_context *ctx, duk_idx_t index);
  3979. typedef duk_idx_t(*__duk_require_normalize_index)(duk_context *ctx, duk_idx_t index);
  3980. typedef duk_bool_t(*__duk_is_valid_index)(duk_context *ctx, duk_idx_t index);
  3981. typedef void(*__duk_require_valid_index)(duk_context *ctx, duk_idx_t index);
  3982. typedef duk_idx_t(*__duk_get_top)(duk_context *ctx);
  3983. typedef void(*__duk_set_top)(duk_context *ctx, duk_idx_t index);
  3984. typedef duk_idx_t(*__duk_get_top_index)(duk_context *ctx);
  3985. typedef duk_idx_t(*__duk_require_top_index)(duk_context *ctx);
  3986. typedef duk_bool_t(*__duk_check_stack)(duk_context *ctx, duk_idx_t extra);
  3987. typedef void(*__duk_require_stack)(duk_context *ctx, duk_idx_t extra);
  3988. typedef duk_bool_t(*__duk_check_stack_top)(duk_context *ctx, duk_idx_t top);
  3989. typedef void(*__duk_require_stack_top)(duk_context *ctx, duk_idx_t top);
  3990. typedef void(*__duk_swap)(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
  3991. typedef void(*__duk_swap_top)(duk_context *ctx, duk_idx_t index);
  3992. typedef void(*__duk_dup)(duk_context *ctx, duk_idx_t from_index);
  3993. typedef void(*__duk_dup_top)(duk_context *ctx);
  3994. typedef void(*__duk_insert)(duk_context *ctx, duk_idx_t to_index);
  3995. typedef void(*__duk_replace)(duk_context *ctx, duk_idx_t to_index);
  3996. typedef void(*__duk_copy)(duk_context *ctx, duk_idx_t from_index, duk_idx_t to_index);
  3997. typedef void(*__duk_remove)(duk_context *ctx, duk_idx_t index);
  3998. typedef void(*__duk_xcopymove_raw)(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count, duk_bool_t is_copy);
  3999. typedef void(*__duk_push_undefined)(duk_context *ctx);
  4000. typedef void(*__duk_push_null)(duk_context *ctx);
  4001. typedef void(*__duk_push_boolean)(duk_context *ctx, duk_bool_t val);
  4002. typedef void(*__duk_push_true)(duk_context *ctx);
  4003. typedef void(*__duk_push_false)(duk_context *ctx);
  4004. typedef void(*__duk_push_number)(duk_context *ctx, duk_double_t val);
  4005. typedef void(*__duk_push_nan)(duk_context *ctx);
  4006. typedef void(*__duk_push_int)(duk_context *ctx, duk_int_t val);
  4007. typedef void(*__duk_push_uint)(duk_context *ctx, duk_uint_t val);
  4008. typedef const char* (*__duk_push_string)(duk_context *ctx, const char *str);
  4009. typedef const char* (*__duk_push_lstring)(duk_context *ctx, const char *str, duk_size_t len);
  4010. typedef void(*__duk_push_pointer)(duk_context *ctx, void *p);
  4011. typedef const char* (*__duk_push_sprintf)(duk_context *ctx, const char *fmt, ...);
  4012. typedef const char* (*__duk_push_vsprintf)(duk_context *ctx, const char *fmt, va_list ap);
  4013. typedef const char* (*__duk_push_string_file_raw)(duk_context *ctx, const char *path, duk_uint_t flags);
  4014. typedef void(*__duk_push_this)(duk_context *ctx);
  4015. typedef void(*__duk_push_current_function)(duk_context *ctx);
  4016. typedef void(*__duk_push_current_thread)(duk_context *ctx);
  4017. typedef void(*__duk_push_global_object)(duk_context *ctx);
  4018. typedef void(*__duk_push_heap_stash)(duk_context *ctx);
  4019. typedef void(*__duk_push_global_stash)(duk_context *ctx);
  4020. typedef void(*__duk_push_thread_stash)(duk_context *ctx, duk_context *target_ctx);
  4021. typedef duk_idx_t(*__duk_push_object)(duk_context *ctx);
  4022. typedef duk_idx_t(*__duk_push_array)(duk_context *ctx);
  4023. typedef duk_idx_t(*__duk_push_c_function)(duk_context *ctx, duk_c_function func, duk_idx_t nargs);
  4024. typedef duk_idx_t(*__duk_push_c_lightfunc)(duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic);
  4025. typedef duk_idx_t(*__duk_push_thread_raw)(duk_context *ctx, duk_uint_t flags);
  4026. typedef duk_idx_t(*__duk_push_error_object_raw)(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...);
  4027. typedef duk_idx_t(*__duk_push_error_object_va_raw)(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap);
  4028. typedef void* (*__duk_push_buffer_raw)(duk_context *ctx, duk_size_t size, duk_small_uint_t flags);
  4029. typedef duk_idx_t(*__duk_push_heapptr)(duk_context *ctx, void *ptr);
  4030. typedef void(*__duk_pop)(duk_context *ctx);
  4031. typedef void(*__duk_pop_n)(duk_context *ctx, duk_idx_t count);
  4032. typedef void(*__duk_pop_2)(duk_context *ctx);
  4033. typedef void(*__duk_pop_3)(duk_context *ctx);
  4034. typedef duk_int_t(*__duk_get_type)(duk_context *ctx, duk_idx_t index);
  4035. typedef duk_bool_t(*__duk_check_type)(duk_context *ctx, duk_idx_t index, duk_int_t type);
  4036. typedef duk_uint_t(*__duk_get_type_mask)(duk_context *ctx, duk_idx_t index);
  4037. typedef duk_bool_t(*__duk_check_type_mask)(duk_context *ctx, duk_idx_t index, duk_uint_t mask);
  4038. typedef duk_bool_t(*__duk_is_undefined)(duk_context *ctx, duk_idx_t index);
  4039. typedef duk_bool_t(*__duk_is_null)(duk_context *ctx, duk_idx_t index);
  4040. typedef duk_bool_t(*__duk_is_null_or_undefined)(duk_context *ctx, duk_idx_t index);
  4041. typedef duk_bool_t(*__duk_is_boolean)(duk_context *ctx, duk_idx_t index);
  4042. typedef duk_bool_t(*__duk_is_number)(duk_context *ctx, duk_idx_t index);
  4043. typedef duk_bool_t(*__duk_is_nan)(duk_context *ctx, duk_idx_t index);
  4044. typedef duk_bool_t(*__duk_is_string)(duk_context *ctx, duk_idx_t index);
  4045. typedef duk_bool_t(*__duk_is_object)(duk_context *ctx, duk_idx_t index);
  4046. typedef duk_bool_t(*__duk_is_buffer)(duk_context *ctx, duk_idx_t index);
  4047. typedef duk_bool_t(*__duk_is_pointer)(duk_context *ctx, duk_idx_t index);
  4048. typedef duk_bool_t(*__duk_is_lightfunc)(duk_context *ctx, duk_idx_t index);
  4049. typedef duk_bool_t(*__duk_is_array)(duk_context *ctx, duk_idx_t index);
  4050. typedef duk_bool_t(*__duk_is_function)(duk_context *ctx, duk_idx_t index);
  4051. typedef duk_bool_t(*__duk_is_c_function)(duk_context *ctx, duk_idx_t index);
  4052. typedef duk_bool_t(*__duk_is_ecmascript_function)(duk_context *ctx, duk_idx_t index);
  4053. typedef duk_bool_t(*__duk_is_bound_function)(duk_context *ctx, duk_idx_t index);
  4054. typedef duk_bool_t(*__duk_is_thread)(duk_context *ctx, duk_idx_t index);
  4055. typedef duk_bool_t(*__duk_is_callable)(duk_context *ctx, duk_idx_t index);
  4056. typedef duk_bool_t(*__duk_is_dynamic_buffer)(duk_context *ctx, duk_idx_t index);
  4057. typedef duk_bool_t(*__duk_is_fixed_buffer)(duk_context *ctx, duk_idx_t index);
  4058. typedef duk_bool_t(*__duk_is_primitive)(duk_context *ctx, duk_idx_t index);
  4059. typedef duk_errcode_t(*__duk_get_error_code)(duk_context *ctx, duk_idx_t index);
  4060. typedef duk_bool_t(*__duk_get_boolean)(duk_context *ctx, duk_idx_t index);
  4061. typedef duk_double_t(*__duk_get_number)(duk_context *ctx, duk_idx_t index);
  4062. typedef duk_int_t(*__duk_get_int)(duk_context *ctx, duk_idx_t index);
  4063. typedef duk_uint_t(*__duk_get_uint)(duk_context *ctx, duk_idx_t index);
  4064. typedef const char *(*__duk_get_string)(duk_context *ctx, duk_idx_t index);
  4065. typedef const char *(*__duk_get_lstring)(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
  4066. typedef void *(*__duk_get_buffer)(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
  4067. typedef void *(*__duk_get_pointer)(duk_context *ctx, duk_idx_t index);
  4068. typedef duk_c_function(*__duk_get_c_function)(duk_context *ctx, duk_idx_t index);
  4069. typedef duk_context *(*__duk_get_context)(duk_context *ctx, duk_idx_t index);
  4070. typedef void *(*__duk_get_heapptr)(duk_context *ctx, duk_idx_t index);
  4071. typedef duk_size_t(*__duk_get_length)(duk_context *ctx, duk_idx_t index);
  4072. typedef void(*__duk_require_undefined)(duk_context *ctx, duk_idx_t index);
  4073. typedef void(*__duk_require_null)(duk_context *ctx, duk_idx_t index);
  4074. typedef duk_bool_t(*__duk_require_boolean)(duk_context *ctx, duk_idx_t index);
  4075. typedef duk_double_t(*__duk_require_number)(duk_context *ctx, duk_idx_t index);
  4076. typedef duk_int_t(*__duk_require_int)(duk_context *ctx, duk_idx_t index);
  4077. typedef duk_uint_t(*__duk_require_uint)(duk_context *ctx, duk_idx_t index);
  4078. typedef const char *(*__duk_require_string)(duk_context *ctx, duk_idx_t index);
  4079. typedef const char *(*__duk_require_lstring)(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
  4080. typedef void *(*__duk_require_buffer)(duk_context *ctx, duk_idx_t index, duk_size_t *out_size);
  4081. typedef void *(*__duk_require_pointer)(duk_context *ctx, duk_idx_t index);
  4082. typedef duk_c_function(*__duk_require_c_function)(duk_context *ctx, duk_idx_t index);
  4083. typedef duk_context *(*__duk_require_context)(duk_context *ctx, duk_idx_t index);
  4084. typedef void *(*__duk_require_heapptr)(duk_context *ctx, duk_idx_t index);
  4085. typedef void(*__duk_to_undefined)(duk_context *ctx, duk_idx_t index);
  4086. typedef void(*__duk_to_null)(duk_context *ctx, duk_idx_t index);
  4087. typedef duk_bool_t(*__duk_to_boolean)(duk_context *ctx, duk_idx_t index);
  4088. typedef duk_double_t(*__duk_to_number)(duk_context *ctx, duk_idx_t index);
  4089. typedef duk_int_t(*__duk_to_int)(duk_context *ctx, duk_idx_t index);
  4090. typedef duk_uint_t(*__duk_to_uint)(duk_context *ctx, duk_idx_t index);
  4091. typedef duk_int32_t(*__duk_to_int32)(duk_context *ctx, duk_idx_t index);
  4092. typedef duk_uint32_t(*__duk_to_uint32)(duk_context *ctx, duk_idx_t index);
  4093. typedef duk_uint16_t(*__duk_to_uint16)(duk_context *ctx, duk_idx_t index);
  4094. typedef const char *(*__duk_to_string)(duk_context *ctx, duk_idx_t index);
  4095. typedef const char *(*__duk_to_lstring)(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
  4096. typedef void *(*__duk_to_buffer_raw)(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_uint_t flags);
  4097. typedef void *(*__duk_to_pointer)(duk_context *ctx, duk_idx_t index);
  4098. typedef void(*__duk_to_object)(duk_context *ctx, duk_idx_t index);
  4099. typedef void(*__duk_to_defaultvalue)(duk_context *ctx, duk_idx_t index, duk_int_t hint);
  4100. typedef void(*__duk_to_primitive)(duk_context *ctx, duk_idx_t index, duk_int_t hint);
  4101. typedef const char *(*__duk_safe_to_lstring)(duk_context *ctx, duk_idx_t index, duk_size_t *out_len);
  4102. typedef const char *(*__duk_base64_encode)(duk_context *ctx, duk_idx_t index);
  4103. typedef void(*__duk_base64_decode)(duk_context *ctx, duk_idx_t index);
  4104. typedef const char *(*__duk_hex_encode)(duk_context *ctx, duk_idx_t index);
  4105. typedef void(*__duk_hex_decode)(duk_context *ctx, duk_idx_t index);
  4106. typedef const char *(*__duk_json_encode)(duk_context *ctx, duk_idx_t index);
  4107. typedef void(*__duk_json_decode)(duk_context *ctx, duk_idx_t index);
  4108. typedef void *(*__duk_resize_buffer)(duk_context *ctx, duk_idx_t index, duk_size_t new_size);
  4109. typedef duk_bool_t(*__duk_get_prop)(duk_context *ctx, duk_idx_t obj_index);
  4110. typedef duk_bool_t(*__duk_get_prop_string)(duk_context *ctx, duk_idx_t obj_index, const char *key);
  4111. typedef duk_bool_t(*__duk_get_prop_index)(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
  4112. typedef duk_bool_t(*__duk_put_prop)(duk_context *ctx, duk_idx_t obj_index);
  4113. typedef duk_bool_t(*__duk_put_prop_string)(duk_context *ctx, duk_idx_t obj_index, const char *key);
  4114. typedef duk_bool_t(*__duk_put_prop_index)(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
  4115. typedef duk_bool_t(*__duk_del_prop)(duk_context *ctx, duk_idx_t obj_index);
  4116. typedef duk_bool_t(*__duk_del_prop_string)(duk_context *ctx, duk_idx_t obj_index, const char *key);
  4117. typedef duk_bool_t(*__duk_del_prop_index)(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
  4118. typedef duk_bool_t(*__duk_has_prop)(duk_context *ctx, duk_idx_t obj_index);
  4119. typedef duk_bool_t(*__duk_has_prop_string)(duk_context *ctx, duk_idx_t obj_index, const char *key);
  4120. typedef duk_bool_t(*__duk_has_prop_index)(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index);
  4121. typedef void(*__duk_def_prop)(duk_context *ctx, duk_idx_t obj_index, duk_uint_t flags);
  4122. typedef duk_bool_t(*__duk_get_global_string)(duk_context *ctx, const char *key);
  4123. typedef duk_bool_t(*__duk_put_global_string)(duk_context *ctx, const char *key);
  4124. typedef void(*__duk_get_prototype)(duk_context *ctx, duk_idx_t index);
  4125. typedef void(*__duk_set_prototype)(duk_context *ctx, duk_idx_t index);
  4126. typedef void(*__duk_get_finalizer)(duk_context *ctx, duk_idx_t index);
  4127. typedef void(*__duk_set_finalizer)(duk_context *ctx, duk_idx_t index);
  4128. typedef void(*__duk_set_global_object)(duk_context *ctx);
  4129. typedef duk_int_t(*__duk_get_magic)(duk_context *ctx, duk_idx_t index);
  4130. typedef void(*__duk_set_magic)(duk_context *ctx, duk_idx_t index, duk_int_t magic);
  4131. typedef duk_int_t(*__duk_get_current_magic)(duk_context *ctx);
  4132. typedef void(*__duk_put_function_list)(duk_context *ctx, duk_idx_t obj_index, const duk_function_list_entry *funcs);
  4133. typedef void(*__duk_put_number_list)(duk_context *ctx, duk_idx_t obj_index, const duk_number_list_entry *numbers);
  4134. typedef void(*__duk_compact)(duk_context *ctx, duk_idx_t obj_index);
  4135. typedef void(*__duk_enum)(duk_context *ctx, duk_idx_t obj_index, duk_uint_t enum_flags);
  4136. typedef duk_bool_t(*__duk_next)(duk_context *ctx, duk_idx_t enum_index, duk_bool_t get_value);
  4137. typedef void(*__duk_concat)(duk_context *ctx, duk_idx_t count);
  4138. typedef void(*__duk_join)(duk_context *ctx, duk_idx_t count);
  4139. typedef void(*__duk_decode_string)(duk_context *ctx, duk_idx_t index, duk_decode_char_function callback, void *udata);
  4140. typedef void(*__duk_map_string)(duk_context *ctx, duk_idx_t index, duk_map_char_function callback, void *udata);
  4141. typedef void(*__duk_substring)(duk_context *ctx, duk_idx_t index, duk_size_t start_char_offset, duk_size_t end_char_offset);
  4142. typedef void(*__duk_trim)(duk_context *ctx, duk_idx_t index);
  4143. typedef duk_codepoint_t(*__duk_char_code_at)(duk_context *ctx, duk_idx_t index, duk_size_t char_offset);
  4144. typedef duk_bool_t(*__duk_equals)(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
  4145. typedef duk_bool_t(*__duk_strict_equals)(duk_context *ctx, duk_idx_t index1, duk_idx_t index2);
  4146. typedef void(*__duk_call)(duk_context *ctx, duk_idx_t nargs);
  4147. typedef void(*__duk_call_method)(duk_context *ctx, duk_idx_t nargs);
  4148. typedef void(*__duk_call_prop)(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs);
  4149. typedef duk_int_t(*__duk_pcall)(duk_context *ctx, duk_idx_t nargs);
  4150. typedef duk_int_t(*__duk_pcall_method)(duk_context *ctx, duk_idx_t nargs);
  4151. typedef duk_int_t(*__duk_pcall_prop)(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs);
  4152. typedef void(*__duk_new)(duk_context *ctx, duk_idx_t nargs);
  4153. typedef duk_int_t(*__duk_safe_call)(duk_context *ctx, duk_safe_call_function func, duk_idx_t nargs, duk_idx_t nrets);
  4154. typedef duk_int_t(*__duk_eval_raw)(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags);
  4155. typedef duk_int_t(*__duk_compile_raw)(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags);
  4156. typedef void(*__duk_log)(duk_context *ctx, duk_int_t level, const char *fmt, ...);
  4157. typedef void(*__duk_log_va)(duk_context *ctx, duk_int_t level, const char *fmt, va_list ap);
  4158. typedef void(*__duk_push_context_dump)(duk_context *ctx);
  4159. typedef void(*__duk_debugger_attach)(duk_context *ctx,
  4160. duk_debug_read_function read_cb,
  4161. duk_debug_write_function write_cb,
  4162. duk_debug_peek_function peek_cb,
  4163. duk_debug_read_flush_function read_flush_cb,
  4164. duk_debug_write_flush_function write_flush_cb,
  4165. duk_debug_detached_function detached_cb,
  4166. void *udata);
  4167. typedef void(*__duk_debugger_detach)(duk_context *ctx);
  4168. typedef void(*__duk_debugger_cooperate)(duk_context *ctx);
  4169. struct JSVMImports
  4170. {
  4171. __duk_create_heap duk_create_heap;
  4172. __duk_destroy_heap duk_destroy_heap;
  4173. __duk_alloc_raw duk_alloc_raw;
  4174. __duk_free_raw duk_free_raw;
  4175. __duk_realloc_raw duk_realloc_raw;
  4176. __duk_alloc duk_alloc;
  4177. __duk_free duk_free;
  4178. __duk_realloc duk_realloc;
  4179. __duk_get_memory_functions duk_get_memory_functions;
  4180. __duk_gc duk_gc;
  4181. __duk_throw duk_throw;
  4182. __duk_fatal duk_fatal;
  4183. __duk_error_raw duk_error_raw;
  4184. __duk_error_va_raw duk_error_va_raw;
  4185. __duk_is_strict_call duk_is_strict_call;
  4186. __duk_is_constructor_call duk_is_constructor_call;
  4187. __duk_normalize_index duk_normalize_index;
  4188. __duk_require_normalize_index duk_require_normalize_index;
  4189. __duk_is_valid_index duk_is_valid_index;
  4190. __duk_require_valid_index duk_require_valid_index;
  4191. __duk_get_top duk_get_top;
  4192. __duk_set_top duk_set_top;
  4193. __duk_get_top_index duk_get_top_index;
  4194. __duk_require_top_index duk_require_top_index;
  4195. __duk_check_stack duk_check_stack;
  4196. __duk_require_stack duk_require_stack;
  4197. __duk_check_stack_top duk_check_stack_top;
  4198. __duk_require_stack_top duk_require_stack_top;
  4199. __duk_swap duk_swap;
  4200. __duk_swap_top duk_swap_top;
  4201. __duk_dup duk_dup;
  4202. __duk_dup_top duk_dup_top;
  4203. __duk_insert duk_insert;
  4204. __duk_replace duk_replace;
  4205. __duk_copy duk_copy;
  4206. __duk_remove duk_remove;
  4207. __duk_xcopymove_raw duk_xcopymove_raw;
  4208. __duk_push_undefined duk_push_undefined;
  4209. __duk_push_null duk_push_null;
  4210. __duk_push_boolean duk_push_boolean;
  4211. __duk_push_true duk_push_true;
  4212. __duk_push_false duk_push_false;
  4213. __duk_push_number duk_push_number;
  4214. __duk_push_nan duk_push_nan;
  4215. __duk_push_int duk_push_int;
  4216. __duk_push_uint duk_push_uint;
  4217. __duk_push_string duk_push_string;
  4218. __duk_push_lstring duk_push_lstring;
  4219. __duk_push_pointer duk_push_pointer;
  4220. __duk_push_sprintf duk_push_sprintf;
  4221. __duk_push_vsprintf duk_push_vsprintf;
  4222. __duk_push_string_file_raw duk_push_string_file_raw;
  4223. __duk_push_this duk_push_this;
  4224. __duk_push_current_function duk_push_current_function;
  4225. __duk_push_current_thread duk_push_current_thread;
  4226. __duk_push_global_object duk_push_global_object;
  4227. __duk_push_heap_stash duk_push_heap_stash;
  4228. __duk_push_global_stash duk_push_global_stash;
  4229. __duk_push_thread_stash duk_push_thread_stash;
  4230. __duk_push_object duk_push_object;
  4231. __duk_push_array duk_push_array;
  4232. __duk_push_c_function duk_push_c_function;
  4233. __duk_push_c_lightfunc duk_push_c_lightfunc;
  4234. __duk_push_thread_raw duk_push_thread_raw;
  4235. __duk_push_error_object_raw duk_push_error_object_raw;
  4236. __duk_push_error_object_va_raw duk_push_error_object_va_raw;
  4237. __duk_push_buffer_raw duk_push_buffer_raw;
  4238. __duk_push_heapptr duk_push_heapptr;
  4239. __duk_pop duk_pop;
  4240. __duk_pop_n duk_pop_n;
  4241. __duk_pop_2 duk_pop_2;
  4242. __duk_pop_3 duk_pop_3;
  4243. __duk_get_type duk_get_type;
  4244. __duk_check_type duk_check_type;
  4245. __duk_get_type_mask duk_get_type_mask;
  4246. __duk_check_type_mask duk_check_type_mask;
  4247. __duk_is_undefined duk_is_undefined;
  4248. __duk_is_null duk_is_null;
  4249. __duk_is_null_or_undefined duk_is_null_or_undefined;
  4250. __duk_is_boolean duk_is_boolean;
  4251. __duk_is_number duk_is_number;
  4252. __duk_is_nan duk_is_nan;
  4253. __duk_is_string duk_is_string;
  4254. __duk_is_object duk_is_object;
  4255. __duk_is_buffer duk_is_buffer;
  4256. __duk_is_pointer duk_is_pointer;
  4257. __duk_is_lightfunc duk_is_lightfunc;
  4258. __duk_is_array duk_is_array;
  4259. __duk_is_function duk_is_function;
  4260. __duk_is_c_function duk_is_c_function;
  4261. __duk_is_ecmascript_function duk_is_ecmascript_function;
  4262. __duk_is_bound_function duk_is_bound_function;
  4263. __duk_is_thread duk_is_thread;
  4264. __duk_is_callable duk_is_callable;
  4265. __duk_is_dynamic_buffer duk_is_dynamic_buffer;
  4266. __duk_is_fixed_buffer duk_is_fixed_buffer;
  4267. __duk_is_primitive duk_is_primitive;
  4268. __duk_get_error_code duk_get_error_code;
  4269. __duk_get_boolean duk_get_boolean;
  4270. __duk_get_number duk_get_number;
  4271. __duk_get_int duk_get_int;
  4272. __duk_get_uint duk_get_uint;
  4273. __duk_get_string duk_get_string;
  4274. __duk_get_lstring duk_get_lstring;
  4275. __duk_get_buffer duk_get_buffer;
  4276. __duk_get_pointer duk_get_pointer;
  4277. __duk_get_c_function duk_get_c_function;
  4278. __duk_get_context duk_get_context;
  4279. __duk_get_heapptr duk_get_heapptr;
  4280. __duk_get_length duk_get_length;
  4281. __duk_require_undefined duk_require_undefined;
  4282. __duk_require_null duk_require_null;
  4283. __duk_require_boolean duk_require_boolean;
  4284. __duk_require_number duk_require_number;
  4285. __duk_require_int duk_require_int;
  4286. __duk_require_uint duk_require_uint;
  4287. __duk_require_string duk_require_string;
  4288. __duk_require_lstring duk_require_lstring;
  4289. __duk_require_buffer duk_require_buffer;
  4290. __duk_require_pointer duk_require_pointer;
  4291. __duk_require_c_function duk_require_c_function;
  4292. __duk_require_context duk_require_context;
  4293. __duk_require_heapptr duk_require_heapptr;
  4294. __duk_to_undefined duk_to_undefined;
  4295. __duk_to_null duk_to_null;
  4296. __duk_to_boolean duk_to_boolean;
  4297. __duk_to_number duk_to_number;
  4298. __duk_to_int duk_to_int;
  4299. __duk_to_uint duk_to_uint;
  4300. __duk_to_int32 duk_to_int32;
  4301. __duk_to_uint32 duk_to_uint32;
  4302. __duk_to_uint16 duk_to_uint16;
  4303. __duk_to_string duk_to_string;
  4304. __duk_to_lstring duk_to_lstring;
  4305. __duk_to_buffer_raw duk_to_buffer_raw;
  4306. __duk_to_pointer duk_to_pointer;
  4307. __duk_to_object duk_to_object;
  4308. __duk_to_defaultvalue duk_to_defaultvalue;
  4309. __duk_to_primitive duk_to_primitive;
  4310. __duk_safe_to_lstring duk_safe_to_lstring;
  4311. __duk_base64_encode duk_base64_encode;
  4312. __duk_base64_decode duk_base64_decode;
  4313. __duk_hex_encode duk_hex_encode;
  4314. __duk_hex_decode duk_hex_decode;
  4315. __duk_json_encode duk_json_encode;
  4316. __duk_json_decode duk_json_decode;
  4317. __duk_resize_buffer duk_resize_buffer;
  4318. __duk_get_prop duk_get_prop;
  4319. __duk_get_prop_string duk_get_prop_string;
  4320. __duk_get_prop_index duk_get_prop_index;
  4321. __duk_put_prop duk_put_prop;
  4322. __duk_put_prop_string duk_put_prop_string;
  4323. __duk_put_prop_index duk_put_prop_index;
  4324. __duk_del_prop duk_del_prop;
  4325. __duk_del_prop_string duk_del_prop_string;
  4326. __duk_del_prop_index duk_del_prop_index;
  4327. __duk_has_prop duk_has_prop;
  4328. __duk_has_prop_string duk_has_prop_string;
  4329. __duk_has_prop_index duk_has_prop_index;
  4330. __duk_def_prop duk_def_prop;
  4331. __duk_get_global_string duk_get_global_string;
  4332. __duk_put_global_string duk_put_global_string;
  4333. __duk_get_prototype duk_get_prototype;
  4334. __duk_set_prototype duk_set_prototype;
  4335. __duk_get_finalizer duk_get_finalizer;
  4336. __duk_set_finalizer duk_set_finalizer;
  4337. __duk_set_global_object duk_set_global_object;
  4338. __duk_get_magic duk_get_magic;
  4339. __duk_set_magic duk_set_magic;
  4340. __duk_get_current_magic duk_get_current_magic;
  4341. __duk_put_function_list duk_put_function_list;
  4342. __duk_put_number_list duk_put_number_list;
  4343. __duk_compact duk_compact;
  4344. __duk_enum duk_enum;
  4345. __duk_next duk_next;
  4346. __duk_concat duk_concat;
  4347. __duk_join duk_join;
  4348. __duk_decode_string duk_decode_string;
  4349. __duk_map_string duk_map_string;
  4350. __duk_substring duk_substring;
  4351. __duk_trim duk_trim;
  4352. __duk_char_code_at duk_char_code_at;
  4353. __duk_equals duk_equals;
  4354. __duk_strict_equals duk_strict_equals;
  4355. __duk_call duk_call;
  4356. __duk_call_method duk_call_method;
  4357. __duk_call_prop duk_call_prop;
  4358. __duk_pcall duk_pcall;
  4359. __duk_pcall_method duk_pcall_method;
  4360. __duk_pcall_prop duk_pcall_prop;
  4361. __duk_new duk_new;
  4362. __duk_safe_call duk_safe_call;
  4363. __duk_eval_raw duk_eval_raw;
  4364. __duk_compile_raw duk_compile_raw;
  4365. __duk_log duk_log;
  4366. __duk_log_va duk_log_va;
  4367. __duk_push_context_dump duk_push_context_dump;
  4368. __duk_debugger_attach duk_debugger_attach;
  4369. __duk_debugger_detach duk_debugger_detach;
  4370. __duk_debugger_cooperate duk_debugger_cooperate;
  4371. JSVMImports()
  4372. {
  4373. memset(this, 0, sizeof(this));
  4374. }
  4375. };
  4376. static JSVMImports gJSVM;
  4377. duk_context *duk_create_heap(duk_alloc_function alloc_func,
  4378. duk_realloc_function realloc_func,
  4379. duk_free_function free_func,
  4380. void *heap_udata,
  4381. duk_fatal_function fatal_handler)
  4382. {
  4383. return gJSVM.duk_create_heap(alloc_func, realloc_func, free_func, heap_udata, fatal_handler);
  4384. }
  4385. void duk_destroy_heap(duk_context *ctx)
  4386. {
  4387. gJSVM.duk_destroy_heap(ctx);
  4388. }
  4389. //----------------------------------------------------------------
  4390. void *duk_alloc_raw(duk_context *ctx, duk_size_t size)
  4391. {
  4392. return gJSVM.duk_alloc_raw(ctx, size);
  4393. }
  4394. void duk_free_raw(duk_context *ctx, void *ptr)
  4395. {
  4396. gJSVM.duk_free_raw(ctx, ptr);
  4397. }
  4398. void *duk_realloc_raw(duk_context *ctx, void *ptr, duk_size_t size)
  4399. {
  4400. return gJSVM.duk_realloc_raw(ctx, ptr, size);
  4401. }
  4402. void *duk_alloc(duk_context *ctx, duk_size_t size)
  4403. {
  4404. return gJSVM.duk_alloc(ctx, size);
  4405. }
  4406. void duk_free(duk_context *ctx, void *ptr)
  4407. {
  4408. gJSVM.duk_free(ctx, ptr);
  4409. }
  4410. void *duk_realloc(duk_context *ctx, void *ptr, duk_size_t size)
  4411. {
  4412. return gJSVM.duk_realloc(ctx, ptr, size);
  4413. }
  4414. void duk_get_memory_functions(duk_context *ctx, duk_memory_functions *out_funcs)
  4415. {
  4416. gJSVM.duk_get_memory_functions(ctx, out_funcs);
  4417. }
  4418. void duk_gc(duk_context *ctx, duk_uint_t flags)
  4419. {
  4420. gJSVM.duk_gc(ctx, flags);
  4421. }
  4422. //----------------------------------------
  4423. void duk_throw(duk_context *ctx)
  4424. {
  4425. gJSVM.duk_throw(ctx);
  4426. }
  4427. void duk_fatal(duk_context *ctx, duk_errcode_t err_code, const char *err_msg)
  4428. {
  4429. gJSVM.duk_fatal(ctx, err_code, err_msg);
  4430. }
  4431. void duk_error_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...)
  4432. {
  4433. va_list arglist;
  4434. va_start(arglist, fmt);
  4435. gJSVM.duk_error_raw(ctx, err_code, filename, line, fmt, arglist);
  4436. va_end(arglist);
  4437. }
  4438. void duk_error_va_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap)
  4439. {
  4440. gJSVM.duk_error_va_raw(ctx, err_code, filename, line, fmt, ap);
  4441. }
  4442. //--------------------------------------------
  4443. duk_bool_t duk_is_strict_call(duk_context *ctx)
  4444. {
  4445. return gJSVM.duk_is_strict_call(ctx);
  4446. }
  4447. duk_bool_t duk_is_constructor_call(duk_context *ctx)
  4448. {
  4449. return gJSVM.duk_is_constructor_call(ctx);
  4450. }
  4451. //--------------------------------------------------------
  4452. duk_idx_t duk_normalize_index(duk_context *ctx, duk_idx_t index)
  4453. {
  4454. return gJSVM.duk_normalize_index(ctx, index);
  4455. }
  4456. duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t index)
  4457. {
  4458. return gJSVM.duk_require_normalize_index(ctx, index);
  4459. }
  4460. duk_bool_t duk_is_valid_index(duk_context *ctx, duk_idx_t index)
  4461. {
  4462. return gJSVM.duk_is_valid_index(ctx, index);
  4463. }
  4464. void duk_require_valid_index(duk_context *ctx, duk_idx_t index)
  4465. {
  4466. gJSVM.duk_require_valid_index(ctx, index);
  4467. }
  4468. duk_idx_t duk_get_top(duk_context *ctx)
  4469. {
  4470. return gJSVM.duk_get_top(ctx);
  4471. }
  4472. void duk_set_top(duk_context *ctx, duk_idx_t index)
  4473. {
  4474. gJSVM.duk_set_top(ctx, index);
  4475. }
  4476. duk_idx_t duk_get_top_index(duk_context *ctx)
  4477. {
  4478. return gJSVM.duk_get_top_index(ctx);
  4479. }
  4480. duk_idx_t duk_require_top_index(duk_context *ctx)
  4481. {
  4482. return gJSVM.duk_require_top_index(ctx);
  4483. }
  4484. duk_bool_t duk_check_stack(duk_context *ctx, duk_idx_t extra)
  4485. {
  4486. return gJSVM.duk_check_stack(ctx, extra);
  4487. }
  4488. void duk_require_stack(duk_context *ctx, duk_idx_t extra)
  4489. {
  4490. gJSVM.duk_require_stack(ctx, extra);
  4491. }
  4492. duk_bool_t duk_check_stack_top(duk_context *ctx, duk_idx_t top)
  4493. {
  4494. return gJSVM.duk_check_stack_top(ctx, top);
  4495. }
  4496. void duk_require_stack_top(duk_context *ctx, duk_idx_t top)
  4497. {
  4498. gJSVM.duk_require_stack_top(ctx, top);
  4499. }
  4500. void duk_swap(duk_context *ctx, duk_idx_t index1, duk_idx_t index2)
  4501. {
  4502. gJSVM.duk_swap(ctx, index1, index2);
  4503. }
  4504. void duk_swap_top(duk_context *ctx, duk_idx_t index)
  4505. {
  4506. gJSVM.duk_swap_top(ctx, index);
  4507. }
  4508. void duk_dup(duk_context *ctx, duk_idx_t from_index)
  4509. {
  4510. gJSVM.duk_dup(ctx, from_index);
  4511. }
  4512. void duk_dup_top(duk_context *ctx)
  4513. {
  4514. gJSVM.duk_dup_top(ctx);
  4515. }
  4516. void duk_insert(duk_context *ctx, duk_idx_t to_index)
  4517. {
  4518. gJSVM.duk_insert(ctx, to_index);
  4519. }
  4520. void duk_replace(duk_context *ctx, duk_idx_t to_index)
  4521. {
  4522. gJSVM.duk_replace(ctx, to_index);
  4523. }
  4524. void duk_copy(duk_context *ctx, duk_idx_t from_index, duk_idx_t to_index)
  4525. {
  4526. gJSVM.duk_copy(ctx, from_index, to_index);
  4527. }
  4528. void duk_remove(duk_context *ctx, duk_idx_t index)
  4529. {
  4530. gJSVM.duk_remove(ctx, index);
  4531. }
  4532. void duk_xcopymove_raw(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count, duk_bool_t is_copy)
  4533. {
  4534. gJSVM.duk_xcopymove_raw(to_ctx, from_ctx, count, is_copy);
  4535. }
  4536. // -------------------------------------------------
  4537. void duk_push_undefined(duk_context *ctx)
  4538. {
  4539. gJSVM.duk_push_undefined(ctx);
  4540. }
  4541. void duk_push_null(duk_context *ctx)
  4542. {
  4543. gJSVM.duk_push_null(ctx);
  4544. }
  4545. void duk_push_boolean(duk_context *ctx, duk_bool_t val)
  4546. {
  4547. gJSVM.duk_push_boolean(ctx, val);
  4548. }
  4549. void duk_push_true(duk_context *ctx)
  4550. {
  4551. gJSVM.duk_push_true(ctx);
  4552. }
  4553. void duk_push_false(duk_context *ctx)
  4554. {
  4555. gJSVM.duk_push_false(ctx);
  4556. }
  4557. void duk_push_number(duk_context *ctx, duk_double_t val)
  4558. {
  4559. gJSVM.duk_push_number(ctx, val);
  4560. }
  4561. void duk_push_nan(duk_context *ctx)
  4562. {
  4563. gJSVM.duk_push_nan(ctx);
  4564. }
  4565. void duk_push_int(duk_context *ctx, duk_int_t val)
  4566. {
  4567. gJSVM.duk_push_int(ctx, val);
  4568. }
  4569. void duk_push_uint(duk_context *ctx, duk_uint_t val)
  4570. {
  4571. gJSVM.duk_push_uint(ctx, val);
  4572. }
  4573. const char *duk_push_string(duk_context *ctx, const char *str)
  4574. {
  4575. return gJSVM.duk_push_string(ctx, str);
  4576. }
  4577. const char *duk_push_lstring(duk_context *ctx, const char *str, duk_size_t len)
  4578. {
  4579. return gJSVM.duk_push_lstring(ctx, str, len);
  4580. }
  4581. void duk_push_pointer(duk_context *ctx, void *p)
  4582. {
  4583. gJSVM.duk_push_pointer(ctx, p);
  4584. }
  4585. const char *duk_push_sprintf(duk_context *ctx, const char *fmt, ...)
  4586. {
  4587. va_list arglist;
  4588. va_start(arglist, fmt);
  4589. const char* returnValue = gJSVM.duk_push_sprintf(ctx, fmt, arglist);
  4590. va_end(arglist);
  4591. return returnValue;
  4592. }
  4593. const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va_list ap)
  4594. {
  4595. return gJSVM.duk_push_vsprintf(ctx, fmt, ap);
  4596. }
  4597. const char *duk_push_string_file_raw(duk_context *ctx, const char *path, duk_uint_t flags)
  4598. {
  4599. return gJSVM.duk_push_string_file_raw(ctx, path, flags);
  4600. }
  4601. void duk_push_this(duk_context *ctx)
  4602. {
  4603. gJSVM.duk_push_this(ctx);
  4604. }
  4605. void duk_push_current_function(duk_context *ctx)
  4606. {
  4607. gJSVM.duk_push_current_function(ctx);
  4608. }
  4609. void duk_push_current_thread(duk_context *ctx)
  4610. {
  4611. gJSVM.duk_push_current_thread(ctx);
  4612. }
  4613. void duk_push_global_object(duk_context *ctx)
  4614. {
  4615. gJSVM.duk_push_global_object(ctx);
  4616. }
  4617. void duk_push_heap_stash(duk_context *ctx)
  4618. {
  4619. gJSVM.duk_push_heap_stash(ctx);
  4620. }
  4621. void duk_push_global_stash(duk_context *ctx)
  4622. {
  4623. gJSVM.duk_push_global_stash(ctx);
  4624. }
  4625. void duk_push_thread_stash(duk_context *ctx, duk_context *target_ctx)
  4626. {
  4627. gJSVM.duk_push_thread_stash(ctx, target_ctx);
  4628. }
  4629. duk_idx_t duk_push_object(duk_context *ctx)
  4630. {
  4631. return gJSVM.duk_push_object(ctx);
  4632. }
  4633. duk_idx_t duk_push_array(duk_context *ctx)
  4634. {
  4635. return gJSVM.duk_push_array(ctx);
  4636. }
  4637. duk_idx_t duk_push_c_function(duk_context *ctx, duk_c_function func, duk_idx_t nargs)
  4638. {
  4639. return gJSVM.duk_push_c_function(ctx, func, nargs);
  4640. }
  4641. duk_idx_t duk_push_c_lightfunc(duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic)
  4642. {
  4643. return gJSVM.duk_push_c_lightfunc(ctx, func, nargs, length, magic);
  4644. }
  4645. duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t flags)
  4646. {
  4647. return gJSVM.duk_push_thread_raw(ctx, flags);
  4648. }
  4649. duk_idx_t duk_push_error_object_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...)
  4650. {
  4651. va_list arglist;
  4652. va_start(arglist, fmt);
  4653. duk_idx_t returnValue = gJSVM.duk_push_error_object_raw(ctx, err_code, filename, line, fmt, arglist);
  4654. va_end(arglist);
  4655. return returnValue;
  4656. }
  4657. duk_idx_t duk_push_error_object_va_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap)
  4658. {
  4659. return gJSVM.duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
  4660. }
  4661. void *duk_push_buffer_raw(duk_context *ctx, duk_size_t size, duk_small_uint_t flags)
  4662. {
  4663. return gJSVM.duk_push_buffer_raw(ctx, size, flags);
  4664. }
  4665. duk_idx_t duk_push_heapptr(duk_context *ctx, void *ptr)
  4666. {
  4667. return gJSVM.duk_push_heapptr(ctx, ptr);
  4668. }
  4669. // --------------------------------
  4670. void duk_pop(duk_context *ctx)
  4671. {
  4672. gJSVM.duk_pop(ctx);
  4673. }
  4674. void duk_pop_n(duk_context *ctx, duk_idx_t count)
  4675. {
  4676. gJSVM.duk_pop_n(ctx, count);
  4677. }
  4678. void duk_pop_2(duk_context *ctx)
  4679. {
  4680. gJSVM.duk_pop_2(ctx);
  4681. }
  4682. void duk_pop_3(duk_context *ctx)
  4683. {
  4684. gJSVM.duk_pop_3(ctx);
  4685. }
  4686. duk_int_t duk_get_type(duk_context *ctx, duk_idx_t index)
  4687. {
  4688. return gJSVM.duk_get_type(ctx, index);
  4689. }
  4690. duk_bool_t duk_check_type(duk_context *ctx, duk_idx_t index, duk_int_t type)
  4691. {
  4692. return gJSVM.duk_check_type(ctx, index, type);
  4693. }
  4694. duk_uint_t duk_get_type_mask(duk_context *ctx, duk_idx_t index)
  4695. {
  4696. return gJSVM.duk_get_type_mask(ctx, index);
  4697. }
  4698. duk_bool_t duk_check_type_mask(duk_context *ctx, duk_idx_t index, duk_uint_t mask)
  4699. {
  4700. return gJSVM.duk_check_type_mask(ctx, index, mask);
  4701. }
  4702. duk_bool_t duk_is_undefined(duk_context *ctx, duk_idx_t index)
  4703. {
  4704. return gJSVM.duk_is_undefined(ctx, index);
  4705. }
  4706. duk_bool_t duk_is_null(duk_context *ctx, duk_idx_t index)
  4707. {
  4708. return gJSVM.duk_is_null(ctx, index);
  4709. }
  4710. duk_bool_t duk_is_null_or_undefined(duk_context *ctx, duk_idx_t index)
  4711. {
  4712. return gJSVM.duk_is_null_or_undefined(ctx, index);
  4713. }
  4714. duk_bool_t duk_is_boolean(duk_context *ctx, duk_idx_t index)
  4715. {
  4716. return gJSVM.duk_is_boolean(ctx, index);
  4717. }
  4718. duk_bool_t duk_is_number(duk_context *ctx, duk_idx_t index)
  4719. {
  4720. return gJSVM.duk_is_number(ctx, index);
  4721. }
  4722. duk_bool_t duk_is_nan(duk_context *ctx, duk_idx_t index)
  4723. {
  4724. return gJSVM.duk_is_nan(ctx, index);
  4725. }
  4726. duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t index)
  4727. {
  4728. return gJSVM.duk_is_string(ctx, index);
  4729. }
  4730. duk_bool_t duk_is_object(duk_context *ctx, duk_idx_t index)
  4731. {
  4732. return gJSVM.duk_is_object(ctx, index);
  4733. }
  4734. duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t index)
  4735. {
  4736. return gJSVM.duk_is_buffer(ctx, index);
  4737. }
  4738. duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t index)
  4739. {
  4740. return gJSVM.duk_is_pointer(ctx, index);
  4741. }
  4742. duk_bool_t duk_is_lightfunc(duk_context *ctx, duk_idx_t index)
  4743. {
  4744. return gJSVM.duk_is_lightfunc(ctx, index);
  4745. }
  4746. duk_bool_t duk_is_array(duk_context *ctx, duk_idx_t index)
  4747. {
  4748. return gJSVM.duk_is_array(ctx, index);
  4749. }
  4750. duk_bool_t duk_is_function(duk_context *ctx, duk_idx_t index)
  4751. {
  4752. return gJSVM.duk_is_function(ctx, index);
  4753. }
  4754. duk_bool_t duk_is_c_function(duk_context *ctx, duk_idx_t index)
  4755. {
  4756. return gJSVM.duk_is_c_function(ctx, index);
  4757. }
  4758. duk_bool_t duk_is_ecmascript_function(duk_context *ctx, duk_idx_t index)
  4759. {
  4760. return gJSVM.duk_is_ecmascript_function(ctx, index);
  4761. }
  4762. duk_bool_t duk_is_bound_function(duk_context *ctx, duk_idx_t index)
  4763. {
  4764. return gJSVM.duk_is_bound_function(ctx, index);
  4765. }
  4766. duk_bool_t duk_is_thread(duk_context *ctx, duk_idx_t index)
  4767. {
  4768. return gJSVM.duk_is_thread(ctx, index);
  4769. }
  4770. duk_bool_t duk_is_callable(duk_context *ctx, duk_idx_t index)
  4771. {
  4772. return gJSVM.duk_is_callable(ctx, index);
  4773. }
  4774. duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t index)
  4775. {
  4776. return gJSVM.duk_is_dynamic_buffer(ctx, index);
  4777. }
  4778. duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t index)
  4779. {
  4780. return gJSVM.duk_is_fixed_buffer(ctx, index);
  4781. }
  4782. duk_bool_t duk_is_primitive(duk_context *ctx, duk_idx_t index)
  4783. {
  4784. return gJSVM.duk_is_primitive(ctx, index);
  4785. }
  4786. duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t index)
  4787. {
  4788. return gJSVM.duk_get_error_code(ctx, index);
  4789. }
  4790. // ---------------------------------------------------------------
  4791. duk_bool_t duk_get_boolean(duk_context *ctx, duk_idx_t index)
  4792. {
  4793. return gJSVM.duk_get_boolean(ctx, index);
  4794. }
  4795. duk_double_t duk_get_number(duk_context *ctx, duk_idx_t index)
  4796. {
  4797. return gJSVM.duk_get_number(ctx, index);
  4798. }
  4799. duk_int_t duk_get_int(duk_context *ctx, duk_idx_t index)
  4800. {
  4801. return gJSVM.duk_get_int(ctx, index);
  4802. }
  4803. duk_uint_t duk_get_uint(duk_context *ctx, duk_idx_t index)
  4804. {
  4805. return gJSVM.duk_get_uint(ctx, index);
  4806. }
  4807. const char *duk_get_string(duk_context *ctx, duk_idx_t index)
  4808. {
  4809. return gJSVM.duk_get_string(ctx, index);
  4810. }
  4811. const char *duk_get_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len)
  4812. {
  4813. return gJSVM.duk_get_lstring(ctx, index, out_len);
  4814. }
  4815. void *duk_get_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size)
  4816. {
  4817. return gJSVM.duk_get_buffer(ctx, index, out_size);
  4818. }
  4819. void *duk_get_pointer(duk_context *ctx, duk_idx_t index)
  4820. {
  4821. return gJSVM.duk_get_pointer(ctx, index);
  4822. }
  4823. duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t index)
  4824. {
  4825. return gJSVM.duk_get_c_function(ctx, index);
  4826. }
  4827. duk_context *duk_get_context(duk_context *ctx, duk_idx_t index)
  4828. {
  4829. return gJSVM.duk_get_context(ctx, index);
  4830. }
  4831. void *duk_get_heapptr(duk_context *ctx, duk_idx_t index)
  4832. {
  4833. return gJSVM.duk_get_heapptr(ctx, index);
  4834. }
  4835. duk_size_t duk_get_length(duk_context *ctx, duk_idx_t index)
  4836. {
  4837. return gJSVM.duk_get_length(ctx, index);
  4838. }
  4839. void duk_require_undefined(duk_context *ctx, duk_idx_t index)
  4840. {
  4841. gJSVM.duk_require_undefined(ctx, index);
  4842. }
  4843. void duk_require_null(duk_context *ctx, duk_idx_t index)
  4844. {
  4845. gJSVM.duk_require_null(ctx, index);
  4846. }
  4847. duk_bool_t duk_require_boolean(duk_context *ctx, duk_idx_t index)
  4848. {
  4849. return gJSVM.duk_require_boolean(ctx, index);
  4850. }
  4851. duk_double_t duk_require_number(duk_context *ctx, duk_idx_t index)
  4852. {
  4853. return gJSVM.duk_require_number(ctx, index);
  4854. }
  4855. duk_int_t duk_require_int(duk_context *ctx, duk_idx_t index)
  4856. {
  4857. return gJSVM.duk_require_int(ctx, index);
  4858. }
  4859. duk_uint_t duk_require_uint(duk_context *ctx, duk_idx_t index)
  4860. {
  4861. return gJSVM.duk_require_uint(ctx, index);
  4862. }
  4863. const char *duk_require_string(duk_context *ctx, duk_idx_t index)
  4864. {
  4865. return gJSVM.duk_require_string(ctx, index);
  4866. }
  4867. const char *duk_require_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len)
  4868. {
  4869. return gJSVM.duk_require_lstring(ctx, index, out_len);
  4870. }
  4871. void *duk_require_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size)
  4872. {
  4873. return gJSVM.duk_require_buffer(ctx, index, out_size);
  4874. }
  4875. void *duk_require_pointer(duk_context *ctx, duk_idx_t index)
  4876. {
  4877. return gJSVM.duk_require_pointer(ctx, index);
  4878. }
  4879. duk_c_function duk_require_c_function(duk_context *ctx, duk_idx_t index)
  4880. {
  4881. return gJSVM.duk_require_c_function(ctx, index);
  4882. }
  4883. duk_context *duk_require_context(duk_context *ctx, duk_idx_t index)
  4884. {
  4885. return gJSVM.duk_require_context(ctx, index);
  4886. }
  4887. void *duk_require_heapptr(duk_context *ctx, duk_idx_t index)
  4888. {
  4889. return gJSVM.duk_require_heapptr(ctx, index);
  4890. }
  4891. void duk_to_undefined(duk_context *ctx, duk_idx_t index)
  4892. {
  4893. gJSVM.duk_to_undefined(ctx, index);
  4894. }
  4895. void duk_to_null(duk_context *ctx, duk_idx_t index)
  4896. {
  4897. gJSVM.duk_to_null(ctx, index);
  4898. }
  4899. duk_bool_t duk_to_boolean(duk_context *ctx, duk_idx_t index)
  4900. {
  4901. return gJSVM.duk_to_boolean(ctx, index);
  4902. }
  4903. duk_double_t duk_to_number(duk_context *ctx, duk_idx_t index)
  4904. {
  4905. return gJSVM.duk_to_number(ctx, index);
  4906. }
  4907. duk_int_t duk_to_int(duk_context *ctx, duk_idx_t index)
  4908. {
  4909. return gJSVM.duk_to_int(ctx, index);
  4910. }
  4911. duk_uint_t duk_to_uint(duk_context *ctx, duk_idx_t index)
  4912. {
  4913. return gJSVM.duk_to_uint(ctx, index);
  4914. }
  4915. duk_int32_t duk_to_int32(duk_context *ctx, duk_idx_t index)
  4916. {
  4917. return gJSVM.duk_to_int32(ctx, index);
  4918. }
  4919. duk_uint32_t duk_to_uint32(duk_context *ctx, duk_idx_t index)
  4920. {
  4921. return gJSVM.duk_to_uint32(ctx, index);
  4922. }
  4923. duk_uint16_t duk_to_uint16(duk_context *ctx, duk_idx_t index)
  4924. {
  4925. return gJSVM.duk_to_uint16(ctx, index);
  4926. }
  4927. const char *duk_to_string(duk_context *ctx, duk_idx_t index)
  4928. {
  4929. return gJSVM.duk_to_string(ctx, index);
  4930. }
  4931. const char *duk_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len)
  4932. {
  4933. return gJSVM.duk_to_lstring(ctx, index, out_len);
  4934. }
  4935. void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t index, duk_size_t *out_size, duk_uint_t flags)
  4936. {
  4937. return gJSVM.duk_to_buffer_raw(ctx, index, out_size, flags);
  4938. }
  4939. void *duk_to_pointer(duk_context *ctx, duk_idx_t index)
  4940. {
  4941. return gJSVM.duk_to_pointer(ctx, index);
  4942. }
  4943. void duk_to_object(duk_context *ctx, duk_idx_t index)
  4944. {
  4945. gJSVM.duk_to_object(ctx, index);
  4946. }
  4947. void duk_to_defaultvalue(duk_context *ctx, duk_idx_t index, duk_int_t hint)
  4948. {
  4949. gJSVM.duk_to_defaultvalue(ctx, index, hint);
  4950. }
  4951. void duk_to_primitive(duk_context *ctx, duk_idx_t index, duk_int_t hint)
  4952. {
  4953. gJSVM.duk_to_primitive(ctx, index, hint);
  4954. }
  4955. const char *duk_safe_to_lstring(duk_context *ctx, duk_idx_t index, duk_size_t *out_len)
  4956. {
  4957. return gJSVM.duk_safe_to_lstring(ctx, index, out_len);
  4958. }
  4959. const char *duk_base64_encode(duk_context *ctx, duk_idx_t index)
  4960. {
  4961. return gJSVM.duk_base64_encode(ctx, index);
  4962. }
  4963. void duk_base64_decode(duk_context *ctx, duk_idx_t index)
  4964. {
  4965. gJSVM.duk_base64_decode(ctx, index);
  4966. }
  4967. const char *duk_hex_encode(duk_context *ctx, duk_idx_t index)
  4968. {
  4969. return gJSVM.duk_hex_encode(ctx, index);
  4970. }
  4971. void duk_hex_decode(duk_context *ctx, duk_idx_t index)
  4972. {
  4973. gJSVM.duk_hex_decode(ctx, index);
  4974. }
  4975. const char *duk_json_encode(duk_context *ctx, duk_idx_t index)
  4976. {
  4977. return gJSVM.duk_json_encode(ctx, index);
  4978. }
  4979. void duk_json_decode(duk_context *ctx, duk_idx_t index)
  4980. {
  4981. gJSVM.duk_json_decode(ctx, index);
  4982. }
  4983. void *duk_resize_buffer(duk_context *ctx, duk_idx_t index, duk_size_t new_size)
  4984. {
  4985. return gJSVM.duk_resize_buffer(ctx, index, new_size);
  4986. }
  4987. duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_index)
  4988. {
  4989. return gJSVM.duk_get_prop(ctx, obj_index);
  4990. }
  4991. duk_bool_t duk_get_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key)
  4992. {
  4993. return gJSVM.duk_get_prop_string(ctx, obj_index, key);
  4994. }
  4995. duk_bool_t duk_get_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index)
  4996. {
  4997. return gJSVM.duk_get_prop_index(ctx, obj_index, arr_index);
  4998. }
  4999. duk_bool_t duk_put_prop(duk_context *ctx, duk_idx_t obj_index)
  5000. {
  5001. return gJSVM.duk_put_prop(ctx, obj_index);
  5002. }
  5003. duk_bool_t duk_put_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key)
  5004. {
  5005. return gJSVM.duk_put_prop_string(ctx, obj_index, key);
  5006. }
  5007. duk_bool_t duk_put_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index)
  5008. {
  5009. return gJSVM.duk_put_prop_index(ctx, obj_index, arr_index);
  5010. }
  5011. duk_bool_t duk_del_prop(duk_context *ctx, duk_idx_t obj_index)
  5012. {
  5013. return gJSVM.duk_del_prop(ctx, obj_index);
  5014. }
  5015. duk_bool_t duk_del_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key)
  5016. {
  5017. return gJSVM.duk_del_prop_string(ctx, obj_index, key);
  5018. }
  5019. duk_bool_t duk_del_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index)
  5020. {
  5021. return gJSVM.duk_del_prop_index(ctx, obj_index, arr_index);
  5022. }
  5023. duk_bool_t duk_has_prop(duk_context *ctx, duk_idx_t obj_index)
  5024. {
  5025. return gJSVM.duk_has_prop(ctx, obj_index);
  5026. }
  5027. duk_bool_t duk_has_prop_string(duk_context *ctx, duk_idx_t obj_index, const char *key)
  5028. {
  5029. return gJSVM.duk_has_prop_string(ctx, obj_index, key);
  5030. }
  5031. duk_bool_t duk_has_prop_index(duk_context *ctx, duk_idx_t obj_index, duk_uarridx_t arr_index)
  5032. {
  5033. return gJSVM.duk_has_prop_index(ctx, obj_index, arr_index);
  5034. }
  5035. void duk_def_prop(duk_context *ctx, duk_idx_t obj_index, duk_uint_t flags)
  5036. {
  5037. gJSVM.duk_def_prop(ctx, obj_index, flags);
  5038. }
  5039. duk_bool_t duk_get_global_string(duk_context *ctx, const char *key)
  5040. {
  5041. return gJSVM.duk_get_global_string(ctx, key);
  5042. }
  5043. duk_bool_t duk_put_global_string(duk_context *ctx, const char *key)
  5044. {
  5045. return gJSVM.duk_put_global_string(ctx, key);
  5046. }
  5047. void duk_get_prototype(duk_context *ctx, duk_idx_t index)
  5048. {
  5049. gJSVM.duk_get_prototype(ctx, index);
  5050. }
  5051. void duk_set_prototype(duk_context *ctx, duk_idx_t index)
  5052. {
  5053. gJSVM.duk_set_prototype(ctx, index);
  5054. }
  5055. void duk_get_finalizer(duk_context *ctx, duk_idx_t index)
  5056. {
  5057. gJSVM.duk_get_finalizer(ctx, index);
  5058. }
  5059. void duk_set_finalizer(duk_context *ctx, duk_idx_t index)
  5060. {
  5061. gJSVM.duk_set_finalizer(ctx, index);
  5062. }
  5063. void duk_set_global_object(duk_context *ctx)
  5064. {
  5065. gJSVM.duk_set_global_object(ctx);
  5066. }
  5067. duk_int_t duk_get_magic(duk_context *ctx, duk_idx_t index)
  5068. {
  5069. return gJSVM.duk_get_magic(ctx, index);
  5070. }
  5071. void duk_set_magic(duk_context *ctx, duk_idx_t index, duk_int_t magic)
  5072. {
  5073. gJSVM.duk_set_magic(ctx, index, magic);
  5074. }
  5075. duk_int_t duk_get_current_magic(duk_context *ctx)
  5076. {
  5077. return gJSVM.duk_get_current_magic(ctx);
  5078. }
  5079. void duk_put_function_list(duk_context *ctx, duk_idx_t obj_index, const duk_function_list_entry *funcs)
  5080. {
  5081. gJSVM.duk_put_function_list(ctx, obj_index, funcs);
  5082. }
  5083. void duk_put_number_list(duk_context *ctx, duk_idx_t obj_index, const duk_number_list_entry *numbers)
  5084. {
  5085. gJSVM.duk_put_number_list(ctx, obj_index, numbers);
  5086. }
  5087. void duk_compact(duk_context *ctx, duk_idx_t obj_index)
  5088. {
  5089. gJSVM.duk_compact(ctx, obj_index);
  5090. }
  5091. void duk_enum(duk_context *ctx, duk_idx_t obj_index, duk_uint_t enum_flags)
  5092. {
  5093. gJSVM.duk_enum(ctx, obj_index, enum_flags);
  5094. }
  5095. duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_index, duk_bool_t get_value)
  5096. {
  5097. return gJSVM.duk_next(ctx, enum_index, get_value);
  5098. }
  5099. void duk_concat(duk_context *ctx, duk_idx_t count)
  5100. {
  5101. gJSVM.duk_concat(ctx, count);
  5102. }
  5103. void duk_join(duk_context *ctx, duk_idx_t count)
  5104. {
  5105. gJSVM.duk_join(ctx, count);
  5106. }
  5107. void duk_decode_string(duk_context *ctx, duk_idx_t index, duk_decode_char_function callback, void *udata)
  5108. {
  5109. gJSVM.duk_decode_string(ctx, index, callback, udata);
  5110. }
  5111. void duk_map_string(duk_context *ctx, duk_idx_t index, duk_map_char_function callback, void *udata)
  5112. {
  5113. gJSVM.duk_map_string(ctx, index, callback, udata);
  5114. }
  5115. void duk_substring(duk_context *ctx, duk_idx_t index, duk_size_t start_char_offset, duk_size_t end_char_offset)
  5116. {
  5117. gJSVM.duk_substring(ctx, index, start_char_offset, end_char_offset);
  5118. }
  5119. void duk_trim(duk_context *ctx, duk_idx_t index)
  5120. {
  5121. gJSVM.duk_trim(ctx, index);
  5122. }
  5123. duk_codepoint_t duk_char_code_at(duk_context *ctx, duk_idx_t index, duk_size_t char_offset)
  5124. {
  5125. return gJSVM.duk_char_code_at(ctx, index, char_offset);
  5126. }
  5127. duk_bool_t duk_equals(duk_context *ctx, duk_idx_t index1, duk_idx_t index2)
  5128. {
  5129. return gJSVM.duk_equals(ctx, index1, index2);
  5130. }
  5131. duk_bool_t duk_strict_equals(duk_context *ctx, duk_idx_t index1, duk_idx_t index2)
  5132. {
  5133. return gJSVM.duk_strict_equals(ctx, index1, index2);
  5134. }
  5135. void duk_call(duk_context *ctx, duk_idx_t nargs)
  5136. {
  5137. gJSVM.duk_call(ctx, nargs);
  5138. }
  5139. void duk_call_method(duk_context *ctx, duk_idx_t nargs)
  5140. {
  5141. gJSVM.duk_call_method(ctx, nargs);
  5142. }
  5143. void duk_call_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs)
  5144. {
  5145. gJSVM.duk_call_prop(ctx, obj_index, nargs);
  5146. }
  5147. duk_int_t duk_pcall(duk_context *ctx, duk_idx_t nargs)
  5148. {
  5149. return gJSVM.duk_pcall(ctx, nargs);
  5150. }
  5151. duk_int_t duk_pcall_method(duk_context *ctx, duk_idx_t nargs)
  5152. {
  5153. return gJSVM.duk_pcall_method(ctx, nargs);
  5154. }
  5155. duk_int_t duk_pcall_prop(duk_context *ctx, duk_idx_t obj_index, duk_idx_t nargs)
  5156. {
  5157. return gJSVM.duk_pcall_prop(ctx, obj_index, nargs);
  5158. }
  5159. void duk_new(duk_context *ctx, duk_idx_t nargs)
  5160. {
  5161. gJSVM.duk_new(ctx, nargs);
  5162. }
  5163. duk_int_t duk_safe_call(duk_context *ctx, duk_safe_call_function func, duk_idx_t nargs, duk_idx_t nrets)
  5164. {
  5165. return gJSVM.duk_safe_call(ctx, func, nargs, nrets);
  5166. }
  5167. duk_int_t duk_eval_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags)
  5168. {
  5169. return gJSVM.duk_eval_raw(ctx, src_buffer, src_length, flags);
  5170. }
  5171. duk_int_t duk_compile_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags)
  5172. {
  5173. return gJSVM.duk_compile_raw(ctx, src_buffer, src_length, flags);
  5174. }
  5175. void duk_log(duk_context *ctx, duk_int_t level, const char *fmt, ...)
  5176. {
  5177. va_list arglist;
  5178. va_start(arglist, fmt);
  5179. gJSVM.duk_log(ctx, level, fmt, arglist);
  5180. va_end(arglist);
  5181. }
  5182. void duk_log_va(duk_context *ctx, duk_int_t level, const char *fmt, va_list ap)
  5183. {
  5184. gJSVM.duk_log_va(ctx, level, fmt, ap);
  5185. }
  5186. void duk_push_context_dump(duk_context *ctx)
  5187. {
  5188. gJSVM.duk_push_context_dump(ctx);
  5189. }
  5190. void duk_debugger_attach(duk_context *ctx,
  5191. duk_debug_read_function read_cb,
  5192. duk_debug_write_function write_cb,
  5193. duk_debug_peek_function peek_cb,
  5194. duk_debug_read_flush_function read_flush_cb,
  5195. duk_debug_write_flush_function write_flush_cb,
  5196. duk_debug_detached_function detached_cb,
  5197. void *udata)
  5198. {
  5199. gJSVM.duk_debugger_attach(ctx, read_cb, write_cb, peek_cb, read_flush_cb, write_flush_cb, detached_cb, udata);
  5200. }
  5201. void duk_debugger_detach(duk_context *ctx)
  5202. {
  5203. gJSVM.duk_debugger_detach(ctx);
  5204. }
  5205. void duk_debugger_cooperate(duk_context *ctx)
  5206. {
  5207. gJSVM.duk_debugger_cooperate(ctx);
  5208. }
  5209. // End Duktape Bindings
  5210. bool PLUGIN_EXPORT_API atomic_plugin_validate(int version, void *jsvmImports, size_t jsvmImportsSize)
  5211. {
  5212. if (version != ATOMIC_JSPLUGIN_VERSION)
  5213. return false;
  5214. if (jsvmImportsSize != sizeof(JSVMImports))
  5215. return false;
  5216. gJSVM = *((JSVMImports*)jsvmImports);
  5217. return true;
  5218. }
  5219. }
  5220. #endif //ATOMIC_PLUGIN_MAIN
  5221. #endif // ATOMIC_PLUGIN_H